sd.c revision bb876bbc87cecdebaea3fff71f5f859148617bdf
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* SCSI disk target driver.
*/
#include <sys/efi_partition.h>
#ifdef __lock_lint
#define _LP64
#define __amd64
#endif
#if (defined(__fibre))
/* Note: is there a leadville version of the following? */
#endif
#include <sys/byteorder.h>
#include "sd_xbuf.h"
/*
* Loadable module info.
*/
#if (defined(__fibre))
#define SD_MODULE_NAME "SCSI SSA/FCAL Disk Driver %I%"
char _depends_on[] = "misc/scsi drv/fcp";
#else
#define SD_MODULE_NAME "SCSI Disk Driver %I%"
char _depends_on[] = "misc/scsi";
#endif
/*
* Define the interconnect type, to allow the driver to distinguish
* between parallel SCSI (sd) and fibre channel (ssd) behaviors.
*
* This is really for backward compatability. In the future, the driver
* should actually check the "interconnect-type" property as reported by
* the HBA; however at present this property is not defined by all HBAs,
* so we will use this #define (1) to permit the driver to run in
* backward-compatability mode; and (2) to print a notification message
* if an FC HBA does not support the "interconnect-type" property. The
* behavior of the driver will be to assume parallel SCSI behaviors unless
* the "interconnect-type" property is defined by the HBA **AND** has a
* value of either INTERCONNECT_FIBRE, INTERCONNECT_SSA, or
* INTERCONNECT_FABRIC, in which case the driver will assume Fibre
* Channel behaviors (as per the old ssd). (Note that the
* INTERCONNECT_1394 and INTERCONNECT_USB types are not supported and
* will result in the driver assuming parallel SCSI behaviors.)
*
* (see common/sys/scsi/impl/services.h)
*
* Note: For ssd semantics, don't use INTERCONNECT_FABRIC as the default
* since some FC HBAs may already support that, and there is some code in
* the driver that already looks for it. Using INTERCONNECT_FABRIC as the
* default would confuse that code, and besides things should work fine
* anyways if the FC HBA already reports INTERCONNECT_FABRIC for the
* "interconnect_type" property.
*
* Notes for off-by-1 workaround:
* -----------------------------
*
* SCSI READ_CAPACITY command returns the LBA number of the
* last logical block, but sd once treated this number as
* disks' capacity on x86 platform. And LBAs are addressed
* based 0. So the last block was lost on x86 platform.
*
* Now, we remove this workaround. In order for present sd
* driver to work with disks which are labeled/partitioned
* via previous sd, we add workaround as follows:
*
* 1) Locate backup EFI label: sd searchs the next to last
* block for backup EFI label if it can't find it on the
* last block;
* 2) Calculate geometry: refer to sd_convert_geometry(), If
* capacity increasing by 1 causes disks' capacity to cross
* over the limits in table CHS_values, geometry info will
* change. This will raise an issue: In case that primary
* VTOC label is destroyed, format commandline can restore
* it via backup VTOC labels. And format locates backup VTOC
* labels by use of geometry from sd driver. So changing
* geometry will prevent format from finding backup VTOC
* labels. To eliminate this side effect for compatibility,
* sd uses (capacity -1) to calculate geometry;
* 3) 1TB disks: VTOC uses 32-bit signed int, thus sd doesn't
* support VTOC for a disk which has more than DK_MAX_BLOCKS
* LBAs. However, for exactly 1TB disk, it was treated as
* (1T - 512)B in the past, and could have VTOC. To overcome
* this, if an exactly 1TB disk has solaris fdisk partition,
* it will be allowed to work with sd.
*/
#if (defined(__fibre))
#else
#endif
/*
* The name of the driver, established from the module name in _init.
*/
/*
* Driver name is unfortunately prefixed on some driver.conf properties.
*/
#if (defined(__fibre))
#define sd_max_xfer_size ssd_max_xfer_size
#define sd_config_list ssd_config_list
static char *sd_max_xfer_size = "ssd_max_xfer_size";
static char *sd_config_list = "ssd-config-list";
#else
static char *sd_max_xfer_size = "sd_max_xfer_size";
static char *sd_config_list = "sd-config-list";
#endif
/*
* Driver global variables
*/
#if (defined(__fibre))
/*
* These #defines are to avoid namespace collisions that occur because this
* code is currently used to compile two seperate driver modules: sd and ssd.
* All global variables need to be treated this way (even if declared static)
* in order to allow the debugger to resolve the names properly.
* It is anticipated that in the near future the ssd module will be obsoleted,
* at which time this namespace issue should go away.
*/
#define sd_io_time ssd_io_time
#define sd_ua_retry_count ssd_ua_retry_count
#define sd_report_pfa ssd_report_pfa
#define sd_max_throttle ssd_max_throttle
#define sd_min_throttle ssd_min_throttle
#define sd_rot_delay ssd_rot_delay
#define sd_retry_on_reservation_conflict \
#define sd_component_mask ssd_component_mask
#define sd_level_mask ssd_level_mask
#define sd_debug_un ssd_debug_un
#define sd_error_level ssd_error_level
#define sd_label_mutex ssd_label_mutex
#define sd_detach_mutex ssd_detach_mutex
#define sd_log_buf ssd_log_buf
#define sd_log_mutex ssd_log_mutex
#define sd_disk_table ssd_disk_table
#define sd_sense_mutex ssd_sense_mutex
#define sd_cdbtab ssd_cdbtab
#define sd_cb_ops ssd_cb_ops
#define sd_minor_data ssd_minor_data
#define sd_minor_data_efi ssd_minor_data_efi
#define sd_wmr_tq ssd_wmr_tq
#define sd_taskq_name ssd_taskq_name
#define sd_wmr_taskq_name ssd_wmr_taskq_name
#define sd_taskq_minalloc ssd_taskq_minalloc
#define sd_taskq_maxalloc ssd_taskq_maxalloc
#define sd_iostart_chain ssd_iostart_chain
#define sd_iodone_chain ssd_iodone_chain
#define sd_pm_idletime ssd_pm_idletime
#endif
#ifdef SDDEBUG
int sd_force_pm_supported = 0;
#endif /* SDDEBUG */
int sd_io_time = SD_IO_TIME;
int sd_failfast_enable = 1;
int sd_report_pfa = 1;
int sd_max_throttle = SD_MAX_THROTTLE;
int sd_min_throttle = SD_MIN_THROTTLE;
int sd_qfull_throttle_enable = TRUE;
int sd_retry_on_reservation_conflict = 1;
static int sd_dtype_optical_bind = -1;
/* Note: the following is not a bug, it really is "sd_" and not "ssd_" */
static char *sd_resv_conflict_name = "sd_retry_on_reservation_conflict";
/*
* Global data for debug logging. To enable debug printing, sd_component_mask
* and sd_level_mask should be set to the desired bit patterns as outlined in
* sddef.h.
*/
/* Note: these may go away in the future... */
/*
* Timer value used to reset the throttle after it has been reduced
* (typically in response to TRAN_BUSY or STATUS_QFULL)
*/
static int sd_reset_throttle_timeout = SD_RESET_THROTTLE_TIMEOUT;
static int sd_qfull_throttle_timeout = SD_QFULL_THROTTLE_TIMEOUT;
/*
* Interval value associated with the media change scsi watch.
*/
static int sd_check_media_time = 3000000;
/*
* Wait value used for in progress operations during a DDI_SUSPEND
*/
static int sd_wait_cmds_complete = SD_WAIT_CMDS_COMPLETE;
/*
* sd_label_mutex protects a static buffer used in the disk label
* component of the driver
*/
static kmutex_t sd_label_mutex;
/*
* sd_detach_mutex protects un_layer_count, un_detach_count, and
* un_opens_in_progress in the sd_lun structure.
*/
static kmutex_t sd_detach_mutex;
/*
* Global buffer and mutex for debug logging
*/
static char sd_log_buf[1024];
static kmutex_t sd_log_mutex;
/*
* "Smart" Probe Caching structs, globals, #defines, etc.
* For parallel scsi and non-self-identify device only.
*/
/*
* The following resources and routines are implemented to support
* "smart" probing, which caches the scsi_probe() results in an array,
* in order to help avoid long probe times.
*/
struct sd_scsi_probe_cache {
struct sd_scsi_probe_cache *next;
int cache[NTARGETS_WIDE];
};
static kmutex_t sd_scsi_probe_cache_mutex;
/*
* Really we only need protection on the head of the linked list, but
* better safe than sorry.
*/
/*
* Vendor specific data name property declarations
*/
static sd_tunables seagate_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables fujitsu_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables ibm_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables purple_properties = {
0,
0,
0,
0,
0
};
static sd_tunables sve_properties = {
0,
0,
0
};
static sd_tunables maserati_properties = {
0,
0,
0,
0,
0,
0,
0,
};
static sd_tunables pirus_properties = {
0,
0,
};
#endif
static sd_tunables elite_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables st31200n_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
#endif /* Fibre or not */
static sd_tunables lsi_properties_scsi = {
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables symbios_properties = {
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables lsi_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
static sd_tunables lsi_oem_properties = {
0,
0,
0,
0,
0,
0,
0,
0
};
#if (defined(SD_PROP_TST))
#define SD_TST_CTYPE_VAL CTYPE_CDROM
#define SD_TST_THROTTLE_VAL 16
#define SD_TST_NOTREADY_VAL 12
#define SD_TST_BUSY_VAL 60
#define SD_TST_RST_RETRY_VAL 36
#define SD_TST_RSV_REL_TIME 60
static sd_tunables tst_properties = {
0,
0,
0
};
#endif
/* This is similiar to the ANSI toupper implementation */
/*
* Static Driver Configuration Table
*
* This is the table of disks which need throttle adjustment (or, perhaps
* something else as defined by the flags at a future time.) device_id
* and revision strings as defined in the scsi_inquiry structure. Offsets of
* the parts of the string are as defined by the sizes in the scsi_inquiry
* structure. Device type is searched as far as the device_id string is
* defined. Flags defines which values are to be set in the driver from the
* properties list.
*
* Entries below which begin and end with a "*" are a special case.
* These do not have a specific vendor, and the string which follows
* can appear anywhere in the 16 byte PID portion of the inquiry data.
*
* Entries below which begin and end with a " " (blank) are a special
* case. The comparison function will treat multiple consecutive blanks
* as equivalent to a single blank. For example, this causes a
* sd_disk_table entry of " NEC CDROM " to match a device's id string
* of "NEC CDROM".
*
* Note: The MD21 controller type has been obsoleted.
* ST318202F is a Legacy device
* MAM3182FC, MAM3364FC, MAM3738FC do not appear to have ever been
* made with an FC connection. The entries here are a legacy.
*/
static sd_disk_config_t sd_disk_table[] = {
{ "SUN T3", SD_CONF_BSET_THROTTLE |
{ "SUN SESS01", SD_CONF_BSET_THROTTLE |
&sve_properties },
{ "SUN T4", SD_CONF_BSET_THROTTLE |
{ "SUN SVE01", SD_CONF_BSET_DISKSORT_DISABLED |
{ "SUN SE6920", SD_CONF_BSET_THROTTLE |
&pirus_properties },
{ "SUN SE6940", SD_CONF_BSET_THROTTLE |
&pirus_properties },
{ "SUN StorageTek 6920", SD_CONF_BSET_THROTTLE |
&pirus_properties },
{ "SUN StorageTek 6940", SD_CONF_BSET_THROTTLE |
&pirus_properties },
{ "SUN PSX1000", SD_CONF_BSET_THROTTLE |
&pirus_properties },
{ "SUN SE6330", SD_CONF_BSET_THROTTLE |
&pirus_properties },
#endif /* fibre or NON-sparc platforms */
{ " NEC CD-ROM DRIVE:260 ", (SD_CONF_BSET_PLAYMSF_BCD
| SD_CONF_BSET_READ_CD_XD4), NULL },
{ " NEC CD-ROM DRIVE:270 ", (SD_CONF_BSET_PLAYMSF_BCD
| SD_CONF_BSET_READ_CD_XD4), NULL },
#endif /* __i386 || __amd64 */
#endif /* sparc NON-fibre or NON-sparc platforms */
#if (defined(SD_PROP_TST))
{ "VENDOR PRODUCT ", (SD_CONF_BSET_THROTTLE
#endif
};
static const int sd_disk_table_size =
sizeof (sd_disk_table)/ sizeof (sd_disk_config_t);
/*
* Return codes of sd_uselabel().
*/
#define SD_LABEL_IS_VALID 0
#define SD_LABEL_IS_INVALID 1
#define SD_INTERCONNECT_PARALLEL 0
#define SD_INTERCONNECT_FABRIC 1
#define SD_INTERCONNECT_FIBRE 2
#define SD_INTERCONNECT_SSA 3
#define SD_INTERCONNECT_SATA 4
#define SD_IS_PARALLEL_SCSI(un) \
#define SD_IS_SERIAL(un) \
/*
* Definitions used by device id registration routines
*/
static kmutex_t sd_sense_mutex = {0};
/*
* Macros for updates of the driver state
*/
#define Restore_state(un) \
static struct sd_cdbinfo sd_cdbtab[] = {
};
/*
* Specifies the number of seconds that must have elapsed since the last
* cmd. has completed for a device to be declared idle to the PM framework.
*/
static int sd_pm_idletime = 1;
/*
* Internal function prototypes
*/
#if (defined(__fibre))
/*
* These #defines are to avoid namespace collisions that occur because this
* code is currently used to compile two seperate driver modules: sd and ssd.
* All function names need to be treated this way (even if declared static)
* in order to allow the debugger to resolve the names properly.
* It is anticipated that in the near future the ssd module will be obsoleted,
* at which time this ugliness should go away.
*/
#define sd_log_trace ssd_log_trace
#define sd_log_info ssd_log_info
#define sd_log_err ssd_log_err
#define sd_prop_op ssd_prop_op
#define sd_spin_up_unit ssd_spin_up_unit
#define sd_set_mmc_caps ssd_set_mmc_caps
#define sd_blank_cmp ssd_blank_cmp
#define sd_chk_vers1_data ssd_chk_vers1_data
#if defined(_SUNOS_VTOC_16)
#endif
#define sd_read_fdisk ssd_read_fdisk
#define sd_swap_efi_gpt ssd_swap_efi_gpt
#define sd_swap_efi_gpe ssd_swap_efi_gpe
#define sd_validate_efi ssd_validate_efi
#define sd_use_efi ssd_use_efi
#define sd_uselabel ssd_uselabel
#define sd_inq_fill ssd_inq_fill
#define sd_register_devid ssd_register_devid
#define sd_get_devid ssd_get_devid
#define sd_create_devid ssd_create_devid
#define sd_write_deviceid ssd_write_deviceid
#define sd_setup_pm ssd_setup_pm
#define sd_ddi_suspend ssd_ddi_suspend
#define sd_ddi_pm_suspend ssd_ddi_pm_suspend
#define sd_ddi_resume ssd_ddi_resume
#define sd_ddi_pm_resume ssd_ddi_pm_resume
#define sd_unit_attach ssd_unit_attach
#define sd_unit_detach ssd_unit_detach
#define sd_set_errstats ssd_set_errstats
#define sd_set_pstats ssd_set_pstats
#define sd_scsi_poll ssd_scsi_poll
#define sd_ddi_scsi_poll ssd_ddi_scsi_poll
#define sd_event_callback ssd_event_callback
#define sd_cache_control ssd_cache_control
#define sd_make_device ssd_make_device
#define sdstrategy ssdstrategy
#define sd_pm_iostart ssd_pm_iostart
#define sd_core_iostart ssd_core_iostart
#define sd_pm_iodone ssd_pm_iodone
#define sd_setup_rw_pkt ssd_setup_rw_pkt
#define sd_buf_iodone ssd_buf_iodone
#define sd_uscsi_strategy ssd_uscsi_strategy
#define sd_uscsi_iodone ssd_uscsi_iodone
#define sd_xbuf_strategy ssd_xbuf_strategy
#define sd_xbuf_init ssd_xbuf_init
#define sd_pm_entry ssd_pm_entry
#define sd_pm_exit ssd_pm_exit
#define sd_start_cmds ssd_start_cmds
#define sd_send_scsi_cmd ssd_send_scsi_cmd
#define sd_bioclone_alloc ssd_bioclone_alloc
#define sd_bioclone_free ssd_bioclone_free
#define sd_print_transport_rejected_message \
#define sd_retry_command ssd_retry_command
#define sd_set_retry_bp ssd_set_retry_bp
#define sd_start_direct_priority_command \
#define sd_return_failed_command_no_restart \
#define sd_return_command ssd_return_command
#define sd_mark_rqs_busy ssd_mark_rqs_busy
#define sd_mark_rqs_idle ssd_mark_rqs_idle
#define sd_pkt_status_reservation_conflict \
#define sd_decode_sense ssd_decode_sense
#define sd_sense_key_medium_or_hardware_error \
#define sd_reset_target ssd_reset_target
#define sd_taskq_create ssd_taskq_create
#define sd_taskq_delete ssd_taskq_delete
#define sd_handle_mchange ssd_handle_mchange
#define sd_send_scsi_feature_GET_CONFIGURATION \
#define sd_send_scsi_PERSISTENT_RESERVE_IN \
#define sd_send_scsi_PERSISTENT_RESERVE_OUT \
#define sd_send_scsi_SYNCHRONIZE_CACHE_biodone \
#define sd_send_scsi_RDWR ssd_send_scsi_RDWR
#define sd_alloc_rqs ssd_alloc_rqs
#define sd_free_rqs ssd_free_rqs
#define sd_dump_memory ssd_dump_memory
#define sd_uscsi_ioctl ssd_uscsi_ioctl
#define sd_get_media_info ssd_get_media_info
#define sd_dkio_ctrl_info ssd_dkio_ctrl_info
#define sd_dkio_partition ssd_dkio_partition
#define sd_dkio_get_vtoc ssd_dkio_get_vtoc
#define sd_dkio_get_efi ssd_dkio_get_efi
#define sd_dkio_set_vtoc ssd_dkio_set_vtoc
#define sd_dkio_set_efi ssd_dkio_set_efi
#define sd_write_label ssd_write_label
#define sd_clear_vtoc ssd_clear_vtoc
#define sd_clear_efi ssd_clear_efi
#define sd_dkio_get_temp ssd_dkio_get_temp
#define sd_dkio_get_mboot ssd_dkio_get_mboot
#define sd_dkio_set_mboot ssd_dkio_set_mboot
#define sd_check_mhd ssd_check_mhd
#define sd_mhd_watch_cb ssd_mhd_watch_cb
#define sd_take_ownership ssd_take_ownership
#define sd_persistent_reservation_in_read_keys \
#define sd_persistent_reservation_in_read_resv \
#define sd_mhdioc_takeown ssd_mhdioc_takeown
#define sd_mhdioc_release ssd_mhdioc_release
#define sd_mhdioc_inkeys ssd_mhdioc_inkeys
#define sd_mhdioc_inresv ssd_mhdioc_inresv
#define sr_change_blkmode ssr_change_blkmode
#define sr_change_speed ssr_change_speed
#define sr_pause_resume ssr_pause_resume
#define sr_play_msf ssr_play_msf
#define sr_play_trkind ssr_play_trkind
#define sr_read_tocentry ssr_read_tocentry
#define sr_read_tochdr ssr_read_tochdr
#define sr_read_cdda ssr_read_cdda
#define sr_read_cdxa ssr_read_cdxa
#define sr_read_mode1 ssr_read_mode1
#define sr_read_mode2 ssr_read_mode2
#define sr_read_cd_mode2 ssr_read_cd_mode2
#define sr_sector_mode ssr_sector_mode
#define sr_ejected ssr_ejected
#define sr_check_wp ssr_check_wp
#define sd_check_media ssd_check_media
#define sd_media_watch_cb ssd_media_watch_cb
#define sr_volume_ctrl ssr_volume_ctrl
#define sd_range_lock ssd_range_lock
#define sd_get_range ssd_get_range
#define sd_range_unlock ssd_range_unlock
#define sd_iostart_chain ssd_iostart_chain
#define sd_iodone_chain ssd_iodone_chain
#define sd_initpkt_map ssd_initpkt_map
#define sd_destroypkt_map ssd_destroypkt_map
#define sd_chain_type_map ssd_chain_type_map
#define sd_is_lsi ssd_is_lsi
#endif /* #if (defined(__fibre)) */
int _init(void);
int _fini(void);
/*PRINTFLIKE3*/
/*PRINTFLIKE3*/
/*PRINTFLIKE3*/
void **result);
/*
* Smart probe for parallel scsi
*/
static void sd_scsi_probe_cache_init(void);
static void sd_scsi_probe_cache_fini(void);
static void sd_scsi_clear_probe_cache(void);
#ifdef _LP64
static void sd_reenable_dsense_task(void *arg);
#endif /* _LP64 */
int list_len, char *dataname_ptr);
#if defined(_SUNOS_VTOC_16)
#endif
int path_flag);
int path_flag);
int lbasize);
static void sd_swap_efi_gpt(efi_gpt_t *);
static int sd_validate_efi(efi_gpt_t *);
static int sd_use_efi(struct sd_lun *, int);
#if defined(_FIRMWARE_NEEDS_FDISK)
#endif
static void sd_inq_fill(char *p, int l, char *s);
int reservation_flag);
#if (defined(__fibre))
/*
* Event callbacks (photon)
*/
#endif
/*
* Defines for sd_cache_control
*/
#define SD_CACHE_ENABLE 1
#define SD_CACHE_DISABLE 0
#define SD_CACHE_NOCHANGE -1
/*
* Driver entry point functions.
*/
/*
* Function prototypes for layering functions in the iostart chain.
*/
/*
* Function prototypes for layering functions in the iodone chain.
*/
/*
* Prototypes for functions to support buf(9S) based IO.
*/
static void sd_destroypkt_for_buf(struct buf *);
#endif /* defined(__i386) || defined(__amd64) */
/*
* Prototypes for functions to support USCSI IO.
*/
static void sd_destroypkt_for_uscsi(struct buf *);
static void sd_pm_idletimeout_handler(void *arg);
/*
* sd_core internal functions (used at the sd_core_io layer).
*/
int path_flag);
int retry_check_flag,
int c),
void (*statp)(kstat_io_t *));
static void sd_start_retry_command(void *arg);
static void sd_start_direct_priority_command(void *arg);
int errcode);
static void sd_restore_throttle(void *arg);
/*
* Error handling functions
*/
static void sd_start_stop_unit_callback(void *arg);
static void sd_start_stop_unit_task(void *arg);
static void sd_taskq_create(void);
static void sd_taskq_delete(void);
static void sd_media_change_task(void *arg);
int path_flag);
struct dk_callback *dkc);
/*
* Disk Ioctl Function Prototypes
*/
int geom_validated);
int geom_validated);
int geom_validated);
#endif
/*
* Multi-host Ioctl Prototypes
*/
static void sd_mhd_resvd_recover(void *arg);
static void sd_resv_reclaim_thread();
/*
* SCSI removable prototypes
*/
static void sd_delayed_cv_broadcast(void *arg);
/*
* Function Prototype for the non-512 support (DVDRAM, MO etc.) functions.
*/
static void sd_read_modify_write_task(void * arg);
static int
/*
* Function prototypes for failfast support.
*/
/*
* Function prototypes to check for lsi devices
*/
/*
* Function prototypes for x86 support
*/
#endif
/*
* Constants for failfast support:
*
* SD_FAILFAST_INACTIVE: Instance is currently in a normal state, with NO
* failfast processing being performed.
*
* SD_FAILFAST_ACTIVE: Instance is in the failfast state and is performing
* failfast processing on all bufs with B_FAILFAST set.
*/
#define SD_FAILFAST_INACTIVE 0
#define SD_FAILFAST_ACTIVE 1
/*
* Bitmask to control behavior of buf(9S) flushes when a transition to
* the failfast state occurs. Optional bits include:
*
* SD_FAILFAST_FLUSH_ALL_BUFS: When set, flush ALL bufs including those that
* do NOT have B_FAILFAST set. When clear, only bufs with B_FAILFAST will
* be flushed.
*
* driver, in addition to the regular wait queue. This includes the xbuf
* queues. When clear, only the driver's wait queue will be flushed.
*/
#define SD_FAILFAST_FLUSH_ALL_BUFS 0x01
#define SD_FAILFAST_FLUSH_ALL_QUEUES 0x02
/*
* The default behavior is to only flush bufs that have B_FAILFAST set, but
* to flush all queues within the driver.
*/
static int sd_failfast_flushctl = SD_FAILFAST_FLUSH_ALL_QUEUES;
/*
* SD Testing Fault Injection
*/
#ifdef SD_FAULT_INJECTION
#endif
/*
* Device driver ops vector
*/
sdopen, /* open */
sdclose, /* close */
sdstrategy, /* strategy */
nodev, /* print */
sddump, /* dump */
sdread, /* read */
sdwrite, /* write */
sdioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
sd_prop_op, /* cb_prop_op */
0, /* streamtab */
CB_REV, /* cb_rev */
sdaread, /* async I/O read entry point */
sdawrite /* async I/O write entry point */
};
DEVO_REV, /* devo_rev, */
0, /* refcnt */
sdinfo, /* info */
nulldev, /* identify */
sdprobe, /* probe */
sdattach, /* attach */
sddetach, /* detach */
nodev, /* reset */
&sd_cb_ops, /* driver operations */
NULL, /* bus operations */
sdpower /* power */
};
/*
* This is the loadable module wrapper.
*/
&mod_driverops, /* Type of module. This one is a driver */
SD_MODULE_NAME, /* Module name. */
&sd_ops /* driver ops */
};
static struct modlinkage modlinkage = {
&modldrv,
};
static struct scsi_asq_key_strings sd_additional_codes[] = {
0x81, 0, "Logical Unit is Reserved",
0x85, 0, "Audio Address Not Valid",
0xb6, 0, "Media Load Mechanism Failed",
0xB9, 0, "Audio Play Operation Aborted",
0xbf, 0, "Buffer Overflow for Read All Subcodes Command",
0x53, 2, "Medium removal prevented",
0x6f, 0, "Authentication failed during key exchange",
0x6f, 1, "Key not present",
0x6f, 2, "Key not established",
0x6f, 3, "Read without proper authentication",
0x6f, 4, "Mismatched region to this logical unit",
0x6f, 5, "Region reset count error",
};
/*
* Struct for passing printing information for sense data messages
*/
struct sd_sense_info {
int ssi_severity;
int ssi_pfa_flag;
};
/*
* Table of function pointers for iostart-side routines. Seperate "chains"
* of layered function calls are formed by placing the function pointers
* sequentially in the desired order. Functions are called according to an
* incrementing table index ordering. The last function in each chain must
* be sd_core_iostart(). The corresponding iodone-side routines are expected
* in the sd_iodone_chain[] array.
*
* Note: It may seem more natural to organize both the iostart and iodone
* functions together, into an array of structures (or some similar
* organization) with a common index, rather than two seperate arrays which
* must be maintained in synchronization. The purpose of this division is
* to achiece improved performance: individual arrays allows for more
* effective cache line utilization on certain platforms.
*/
static sd_chain_t sd_iostart_chain[] = {
/* Chain for buf IO for disk drive targets (PM enabled) */
sd_mapblockaddr_iostart, /* Index: 0 */
sd_pm_iostart, /* Index: 1 */
sd_core_iostart, /* Index: 2 */
/* Chain for buf IO for disk drive targets (PM disabled) */
sd_mapblockaddr_iostart, /* Index: 3 */
sd_core_iostart, /* Index: 4 */
/* Chain for buf IO for removable-media targets (PM enabled) */
sd_mapblockaddr_iostart, /* Index: 5 */
sd_mapblocksize_iostart, /* Index: 6 */
sd_pm_iostart, /* Index: 7 */
sd_core_iostart, /* Index: 8 */
/* Chain for buf IO for removable-media targets (PM disabled) */
sd_mapblockaddr_iostart, /* Index: 9 */
sd_mapblocksize_iostart, /* Index: 10 */
sd_core_iostart, /* Index: 11 */
/* Chain for buf IO for disk drives with checksumming (PM enabled) */
sd_mapblockaddr_iostart, /* Index: 12 */
sd_checksum_iostart, /* Index: 13 */
sd_pm_iostart, /* Index: 14 */
sd_core_iostart, /* Index: 15 */
/* Chain for buf IO for disk drives with checksumming (PM disabled) */
sd_mapblockaddr_iostart, /* Index: 16 */
sd_checksum_iostart, /* Index: 17 */
sd_core_iostart, /* Index: 18 */
/* Chain for USCSI commands (all targets) */
sd_pm_iostart, /* Index: 19 */
sd_core_iostart, /* Index: 20 */
/* Chain for checksumming USCSI commands (all targets) */
sd_checksum_uscsi_iostart, /* Index: 21 */
sd_pm_iostart, /* Index: 22 */
sd_core_iostart, /* Index: 23 */
/* Chain for "direct" USCSI commands (all targets) */
sd_core_iostart, /* Index: 24 */
/* Chain for "direct priority" USCSI commands (all targets) */
sd_core_iostart, /* Index: 25 */
};
/*
* Macros to locate the first function of each iostart chain in the
* sd_iostart_chain[] array. These are located by the index in the array.
*/
#define SD_CHAIN_DISK_IOSTART 0
#define SD_CHAIN_DISK_IOSTART_NO_PM 3
#define SD_CHAIN_RMMEDIA_IOSTART 5
#define SD_CHAIN_RMMEDIA_IOSTART_NO_PM 9
#define SD_CHAIN_CHKSUM_IOSTART 12
#define SD_CHAIN_CHKSUM_IOSTART_NO_PM 16
#define SD_CHAIN_USCSI_CMD_IOSTART 19
#define SD_CHAIN_USCSI_CHKSUM_IOSTART 21
#define SD_CHAIN_DIRECT_CMD_IOSTART 24
#define SD_CHAIN_PRIORITY_CMD_IOSTART 25
/*
* Table of function pointers for the iodone-side routines for the driver-
* internal layering mechanism. The calling sequence for iodone routines
* uses a decrementing table index, so the last routine called in a chain
* must be at the lowest array index location for that chain. The last
* routine for each chain must be either sd_buf_iodone() (for buf(9S) IOs)
* or sd_uscsi_iodone() (for uscsi IOs). Other than this, the ordering
* of the functions in an iodone side chain must correspond to the ordering
* of the iostart routines for that chain. Note that there is no iodone
* side routine that corresponds to sd_core_iostart(), so there is no
* entry in the table for this.
*/
static sd_chain_t sd_iodone_chain[] = {
/* Chain for buf IO for disk drive targets (PM enabled) */
sd_buf_iodone, /* Index: 0 */
sd_mapblockaddr_iodone, /* Index: 1 */
sd_pm_iodone, /* Index: 2 */
/* Chain for buf IO for disk drive targets (PM disabled) */
sd_buf_iodone, /* Index: 3 */
sd_mapblockaddr_iodone, /* Index: 4 */
/* Chain for buf IO for removable-media targets (PM enabled) */
sd_buf_iodone, /* Index: 5 */
sd_mapblockaddr_iodone, /* Index: 6 */
sd_mapblocksize_iodone, /* Index: 7 */
sd_pm_iodone, /* Index: 8 */
/* Chain for buf IO for removable-media targets (PM disabled) */
sd_buf_iodone, /* Index: 9 */
sd_mapblockaddr_iodone, /* Index: 10 */
sd_mapblocksize_iodone, /* Index: 11 */
/* Chain for buf IO for disk drives with checksumming (PM enabled) */
sd_buf_iodone, /* Index: 12 */
sd_mapblockaddr_iodone, /* Index: 13 */
sd_checksum_iodone, /* Index: 14 */
sd_pm_iodone, /* Index: 15 */
/* Chain for buf IO for disk drives with checksumming (PM disabled) */
sd_buf_iodone, /* Index: 16 */
sd_mapblockaddr_iodone, /* Index: 17 */
sd_checksum_iodone, /* Index: 18 */
/* Chain for USCSI commands (non-checksum targets) */
sd_uscsi_iodone, /* Index: 19 */
sd_pm_iodone, /* Index: 20 */
/* Chain for USCSI commands (checksum targets) */
sd_uscsi_iodone, /* Index: 21 */
sd_checksum_uscsi_iodone, /* Index: 22 */
sd_pm_iodone, /* Index: 22 */
/* Chain for "direct" USCSI commands (all targets) */
sd_uscsi_iodone, /* Index: 24 */
/* Chain for "direct priority" USCSI commands (all targets) */
sd_uscsi_iodone, /* Index: 25 */
};
/*
* Macros to locate the "first" function in the sd_iodone_chain[] array for
* each iodone-side chain. These are located by the array index, but as the
* iodone side functions are called in a decrementing-index order, the
* highest index number in each chain must be specified (as these correspond
* to the first function in the iodone chain that will be called by the core
* at IO completion time).
*/
#define SD_CHAIN_DISK_IODONE 2
#define SD_CHAIN_DISK_IODONE_NO_PM 4
#define SD_CHAIN_RMMEDIA_IODONE 8
#define SD_CHAIN_RMMEDIA_IODONE_NO_PM 11
#define SD_CHAIN_CHKSUM_IODONE 15
#define SD_CHAIN_CHKSUM_IODONE_NO_PM 18
#define SD_CHAIN_USCSI_CMD_IODONE 20
#define SD_CHAIN_USCSI_CHKSUM_IODONE 22
#define SD_CHAIN_DIRECT_CMD_IODONE 24
#define SD_CHAIN_PRIORITY_CMD_IODONE 25
/*
* Array to map a layering chain index to the appropriate initpkt routine.
* The redundant entries are present so that the index used for accessing
* the above sd_iostart_chain and sd_iodone_chain tables can be used directly
* with this table as well.
*/
static sd_initpkt_t sd_initpkt_map[] = {
/* Chain for buf IO for disk drive targets (PM enabled) */
sd_initpkt_for_buf, /* Index: 0 */
sd_initpkt_for_buf, /* Index: 1 */
sd_initpkt_for_buf, /* Index: 2 */
/* Chain for buf IO for disk drive targets (PM disabled) */
sd_initpkt_for_buf, /* Index: 3 */
sd_initpkt_for_buf, /* Index: 4 */
/* Chain for buf IO for removable-media targets (PM enabled) */
sd_initpkt_for_buf, /* Index: 5 */
sd_initpkt_for_buf, /* Index: 6 */
sd_initpkt_for_buf, /* Index: 7 */
sd_initpkt_for_buf, /* Index: 8 */
/* Chain for buf IO for removable-media targets (PM disabled) */
sd_initpkt_for_buf, /* Index: 9 */
sd_initpkt_for_buf, /* Index: 10 */
sd_initpkt_for_buf, /* Index: 11 */
/* Chain for buf IO for disk drives with checksumming (PM enabled) */
sd_initpkt_for_buf, /* Index: 12 */
sd_initpkt_for_buf, /* Index: 13 */
sd_initpkt_for_buf, /* Index: 14 */
sd_initpkt_for_buf, /* Index: 15 */
/* Chain for buf IO for disk drives with checksumming (PM disabled) */
sd_initpkt_for_buf, /* Index: 16 */
sd_initpkt_for_buf, /* Index: 17 */
sd_initpkt_for_buf, /* Index: 18 */
/* Chain for USCSI commands (non-checksum targets) */
sd_initpkt_for_uscsi, /* Index: 19 */
sd_initpkt_for_uscsi, /* Index: 20 */
/* Chain for USCSI commands (checksum targets) */
sd_initpkt_for_uscsi, /* Index: 21 */
sd_initpkt_for_uscsi, /* Index: 22 */
sd_initpkt_for_uscsi, /* Index: 22 */
/* Chain for "direct" USCSI commands (all targets) */
sd_initpkt_for_uscsi, /* Index: 24 */
/* Chain for "direct priority" USCSI commands (all targets) */
sd_initpkt_for_uscsi, /* Index: 25 */
};
/*
* Array to map a layering chain index to the appropriate destroypktpkt routine.
* The redundant entries are present so that the index used for accessing
* the above sd_iostart_chain and sd_iodone_chain tables can be used directly
* with this table as well.
*/
typedef void (*sd_destroypkt_t)(struct buf *);
static sd_destroypkt_t sd_destroypkt_map[] = {
/* Chain for buf IO for disk drive targets (PM enabled) */
sd_destroypkt_for_buf, /* Index: 0 */
sd_destroypkt_for_buf, /* Index: 1 */
sd_destroypkt_for_buf, /* Index: 2 */
/* Chain for buf IO for disk drive targets (PM disabled) */
sd_destroypkt_for_buf, /* Index: 3 */
sd_destroypkt_for_buf, /* Index: 4 */
/* Chain for buf IO for removable-media targets (PM enabled) */
sd_destroypkt_for_buf, /* Index: 5 */
sd_destroypkt_for_buf, /* Index: 6 */
sd_destroypkt_for_buf, /* Index: 7 */
sd_destroypkt_for_buf, /* Index: 8 */
/* Chain for buf IO for removable-media targets (PM disabled) */
sd_destroypkt_for_buf, /* Index: 9 */
sd_destroypkt_for_buf, /* Index: 10 */
sd_destroypkt_for_buf, /* Index: 11 */
/* Chain for buf IO for disk drives with checksumming (PM enabled) */
sd_destroypkt_for_buf, /* Index: 12 */
sd_destroypkt_for_buf, /* Index: 13 */
sd_destroypkt_for_buf, /* Index: 14 */
sd_destroypkt_for_buf, /* Index: 15 */
/* Chain for buf IO for disk drives with checksumming (PM disabled) */
sd_destroypkt_for_buf, /* Index: 16 */
sd_destroypkt_for_buf, /* Index: 17 */
sd_destroypkt_for_buf, /* Index: 18 */
/* Chain for USCSI commands (non-checksum targets) */
sd_destroypkt_for_uscsi, /* Index: 19 */
sd_destroypkt_for_uscsi, /* Index: 20 */
/* Chain for USCSI commands (checksum targets) */
sd_destroypkt_for_uscsi, /* Index: 21 */
sd_destroypkt_for_uscsi, /* Index: 22 */
sd_destroypkt_for_uscsi, /* Index: 22 */
/* Chain for "direct" USCSI commands (all targets) */
sd_destroypkt_for_uscsi, /* Index: 24 */
/* Chain for "direct priority" USCSI commands (all targets) */
sd_destroypkt_for_uscsi, /* Index: 25 */
};
/*
* Array to map a layering chain index to the appropriate chain "type".
* The redundant entries are present so that the index used for accessing
* the above sd_iostart_chain and sd_iodone_chain tables can be used directly
* with this table as well.
*/
#define SD_CHAIN_NULL 0 /* for the special RQS cmd */
/* (for error recovery) */
static int sd_chain_type_map[] = {
/* Chain for buf IO for disk drive targets (PM enabled) */
SD_CHAIN_BUFIO, /* Index: 0 */
SD_CHAIN_BUFIO, /* Index: 1 */
SD_CHAIN_BUFIO, /* Index: 2 */
/* Chain for buf IO for disk drive targets (PM disabled) */
SD_CHAIN_BUFIO, /* Index: 3 */
SD_CHAIN_BUFIO, /* Index: 4 */
/* Chain for buf IO for removable-media targets (PM enabled) */
SD_CHAIN_BUFIO, /* Index: 5 */
SD_CHAIN_BUFIO, /* Index: 6 */
SD_CHAIN_BUFIO, /* Index: 7 */
SD_CHAIN_BUFIO, /* Index: 8 */
/* Chain for buf IO for removable-media targets (PM disabled) */
SD_CHAIN_BUFIO, /* Index: 9 */
SD_CHAIN_BUFIO, /* Index: 10 */
SD_CHAIN_BUFIO, /* Index: 11 */
/* Chain for buf IO for disk drives with checksumming (PM enabled) */
SD_CHAIN_BUFIO, /* Index: 12 */
SD_CHAIN_BUFIO, /* Index: 13 */
SD_CHAIN_BUFIO, /* Index: 14 */
SD_CHAIN_BUFIO, /* Index: 15 */
/* Chain for buf IO for disk drives with checksumming (PM disabled) */
SD_CHAIN_BUFIO, /* Index: 16 */
SD_CHAIN_BUFIO, /* Index: 17 */
SD_CHAIN_BUFIO, /* Index: 18 */
/* Chain for USCSI commands (non-checksum targets) */
SD_CHAIN_USCSI, /* Index: 19 */
SD_CHAIN_USCSI, /* Index: 20 */
/* Chain for USCSI commands (checksum targets) */
SD_CHAIN_USCSI, /* Index: 21 */
SD_CHAIN_USCSI, /* Index: 22 */
SD_CHAIN_USCSI, /* Index: 22 */
/* Chain for "direct" USCSI commands (all targets) */
SD_CHAIN_DIRECT, /* Index: 24 */
/* Chain for "direct priority" USCSI commands (all targets) */
SD_CHAIN_DIRECT_PRIORITY, /* Index: 25 */
};
/* Macro to return TRUE if the IO has come from the sd_buf_iostart() chain. */
#define SD_IS_BUFIO(xp) \
/* Macro to return TRUE if the IO has come from the "direct priority" chain. */
#define SD_IS_DIRECT_PRIORITY(xp) \
/*
* Struct, array, and macros to map a specific chain to the appropriate
* layering indexes in the sd_iostart_chain[] and sd_iodone_chain[] arrays.
*
* The sd_chain_index_map[] array is used at attach time to set the various
* un_xxx_chain type members of the sd_lun softstate to the specific layering
* chain to be used with the instance. This allows different instances to use
* different chain for buf IO, uscsi IO, etc.. Also, since the xb_chain_iostart
* and xb_chain_iodone index values in the sd_xbuf are initialized to these
* values at sd_xbuf init time, this allows (1) layering chains may be changed
* dynamically & without the use of locking; and (2) a layer may update the
* xb_chain_io[start|done] member in a given xbuf with its current index value,
* to allow for deferred processing of an IO within the same chain from a
* different execution context.
*/
struct sd_chain_index {
int sci_iostart_index;
int sci_iodone_index;
};
static struct sd_chain_index sd_chain_index_map[] = {
};
/*
* The following are indexes into the sd_chain_index_map[] array.
*/
/* un->un_buf_chain_type must be set to one of these */
#define SD_CHAIN_INFO_DISK 0
#define SD_CHAIN_INFO_DISK_NO_PM 1
#define SD_CHAIN_INFO_RMMEDIA 2
#define SD_CHAIN_INFO_RMMEDIA_NO_PM 3
#define SD_CHAIN_INFO_CHKSUM 4
#define SD_CHAIN_INFO_CHKSUM_NO_PM 5
/* un->un_uscsi_chain_type must be set to one of these */
#define SD_CHAIN_INFO_USCSI_CMD 6
/* USCSI with PM disabled is the same as DIRECT */
#define SD_CHAIN_INFO_USCSI_CMD_NO_PM 8
#define SD_CHAIN_INFO_USCSI_CHKSUM 7
/* un->un_direct_chain_type must be set to one of these */
#define SD_CHAIN_INFO_DIRECT_CMD 8
/* un->un_priority_chain_type must be set to one of these */
#define SD_CHAIN_INFO_PRIORITY_CMD 9
/* size for devid inquiries */
#define MAX_INQUIRY_SIZE 0xF0
/*
* Macros used by functions to pass a given buf(9S) struct along to the
* next function in the layering chain for further processing.
*
* In the following macros, passing more than three arguments to the called
* routines causes the optimizer for the SPARC compiler to stop doing tail
* call elimination which results in significant performance degradation.
*/
/*
* Function: _init
*
* Description: This is the driver _init(9E) entry point.
*
* Return Code: Returns the value from mod_install(9F) or
* ddi_soft_state_init(9F) as appropriate.
*
* Context: Called when driver module loaded.
*/
int
_init(void)
{
int err;
/* establish driver name from module name */
if (err != 0) {
return (err);
}
/*
* it's ok to init here even for fibre device
*/
/*
* Creating taskq before mod_install ensures that all callers (threads)
* that enter the module after a successfull mod_install encounter
* a valid taskq.
*/
if (err != 0) {
/* delete taskq if install fails */
return (err);
}
return (err);
}
/*
* Function: _fini
*
* Description: This is the driver _fini(9E) entry point.
*
* Return Code: Returns the value from mod_remove(9F)
*
* Context: Called when driver module is unloaded.
*/
int
_fini(void)
{
int err;
return (err);
}
return (err);
}
/*
* Function: _info
*
* Description: This is the driver _info(9E) entry point.
*
* Arguments: modinfop - pointer to the driver modinfo structure
*
* Return Code: Returns the value from mod_info(9F).
*
* Context: Kernel thread context
*/
int
{
}
/*
* The following routines implement the driver message logging facility.
* They provide component- and level- based debug output filtering.
* Output may also be restricted to messages for a single instance by
* specifying a soft state pointer in sd_debug_un. If sd_debug_un is set
* to NULL, then messages for all instances are printed.
*
* These routines have been cloned from each other due to the language
* constraints of macros and variable argument list processing.
*/
/*
* Function: sd_log_err
*
* Description: This routine is called by the SD_ERROR macro for debug
* logging of error conditions.
*
* Arguments: comp - driver component being logged
* dev - pointer to driver info structure
* fmt - error string and format to be logged
*/
static void
{
/*
* Filter messages based on the global component and level masks.
* Also print if un matches the value of sd_debug_un, or if
* sd_debug_un is set to NULL.
*/
}
#ifdef SD_FAULT_INJECTION
}
#endif
}
/*
* Function: sd_log_info
*
* Description: This routine is called by the SD_INFO macro for debug
* logging of general purpose informational conditions.
*
* Arguments: comp - driver component being logged
* dev - pointer to driver info structure
* fmt - info string and format to be logged
*/
static void
{
/*
* Filter messages based on the global component and level masks.
* Also print if un matches the value of sd_debug_un, or if
* sd_debug_un is set to NULL.
*/
if ((sd_component_mask & component) &&
(sd_level_mask & SD_LOGMASK_INFO) &&
}
#ifdef SD_FAULT_INJECTION
}
#endif
}
/*
* Function: sd_log_trace
*
* Description: This routine is called by the SD_TRACE macro for debug
*
* Arguments: comp - driver component being logged
* dev - pointer to driver info structure
* fmt - trace string and format to be logged
*/
static void
{
/*
* Filter messages based on the global component and level masks.
* Also print if un matches the value of sd_debug_un, or if
* sd_debug_un is set to NULL.
*/
if ((sd_component_mask & component) &&
(sd_level_mask & SD_LOGMASK_TRACE) &&
}
#ifdef SD_FAULT_INJECTION
}
#endif
}
/*
* Function: sdprobe
*
* Description: This is the driver probe(9e) entry point function.
*
* Arguments: devi - opaque device info handle
*
* Return Code: DDI_PROBE_SUCCESS: If the probe was successful.
* DDI_PROBE_FAILURE: If the probe failed.
* DDI_PROBE_PARTIAL: If the instance is not present now,
* but may be present in the future.
*/
static int
{
struct scsi_device *devp;
int rval;
int instance;
/*
* if it wasn't for pln, sdprobe could actually be nulldev
* in the "__fibre" case.
*/
return (DDI_PROBE_DONTCARE);
}
/* Ooops... nexus driver is mis-configured... */
return (DDI_PROBE_FAILURE);
}
return (DDI_PROBE_PARTIAL);
}
/*
* Call the SCSA utility probe routine to see if we actually
* have a target at this SCSI nexus.
*/
case SCSIPROBE_EXISTS:
case DTYPE_DIRECT:
break;
case DTYPE_RODIRECT:
/* CDs etc. Can be removable media */
break;
case DTYPE_OPTICAL:
/*
* Rewritable optical driver HP115AA
* Can also be removable media
*/
/*
* Do not attempt to bind to DTYPE_OPTICAL if
* pre solaris 9 sparc sd behavior is required
*
* If first time through and sd_dtype_optical_bind
*/
if (sd_dtype_optical_bind < 0) {
(DDI_DEV_T_ANY, devi, 0,
"optical-device-bind", 1);
}
if (sd_dtype_optical_bind == 0) {
} else {
}
break;
case DTYPE_NOTPRESENT:
default:
break;
}
break;
default:
break;
}
/*
* This routine checks for resource allocation prior to freeing,
* so it will take care of the "smart probing" case where a
* scsi_probe() may or may not have been issued and will *not*
* free previously-freed resources.
*/
return (rval);
}
/*
* Function: sdinfo
*
* Description: This is the driver getinfo(9e) entry point function.
* Given the device number, return the devinfo pointer from
* the scsi_device structure or the instance number
* associated with the dev_t.
*
* Arguments: dip - pointer to device info structure
* infocmd - command argument (DDI_INFO_DEVT2DEVINFO,
* DDI_INFO_DEVT2INSTANCE)
* arg - driver dev_t
* resultp - user buffer for request response
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*/
/* ARGSUSED */
static int
{
int instance;
int error;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
return (DDI_FAILURE);
}
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
/*
* Function: sd_prop_op
*
* Description: This is the driver prop_op(9e) entry point function.
* Return the number of blocks for the partition in question
* or forward the request to the property facilities.
*
* Arguments: dev - device number
* dip - pointer to device info structure
* prop_op - property operator
* mod_flags - DDI_PROP_DONTPASS, don't pass to parent
* name - pointer to property name
* valuep - pointer or address of the user buffer
* lengthp - property length
*
* Return Code: DDI_PROP_SUCCESS
* DDI_PROP_NOT_FOUND
* DDI_PROP_UNDEFINED
* DDI_PROP_NO_MEMORY
* DDI_PROP_BUF_TOO_SMALL
*/
static int
{
/*
* Our dynamic properties are all device specific and size oriented.
* Requests issued under conditions where size is valid are passed
* to ddi_prop_op_nblocks with the size information, otherwise the
* request is passed to ddi_prop_op. Size depends on valid geometry.
*/
} else {
/* get nblocks value */
}
}
/*
* The following functions are for smart probing:
* sd_scsi_probe_cache_init()
* sd_scsi_probe_cache_fini()
* sd_scsi_clear_probe_cache()
* sd_scsi_probe_with_cache()
*/
/*
* Function: sd_scsi_probe_cache_init
*
* Description: Initializes the probe response cache mutex and head pointer.
*
* Context: Kernel thread context
*/
static void
sd_scsi_probe_cache_init(void)
{
}
/*
* Function: sd_scsi_probe_cache_fini
*
* Description: Frees all resources associated with the probe response cache.
*
* Context: Kernel thread context
*/
static void
sd_scsi_probe_cache_fini(void)
{
struct sd_scsi_probe_cache *cp;
struct sd_scsi_probe_cache *ncp;
/* Clean up our smart probing linked list */
}
}
/*
* Function: sd_scsi_clear_probe_cache
*
* Description: This routine clears the probe response cache. This is
* done when open() returns ENXIO so that when deferred
* attach is attempted (possibly after a device has been
* turned on) we will retry the probe. Since we don't know
* which target we failed to open, we just clear the
* entire cache.
*
* Context: Kernel thread context
*/
static void
{
struct sd_scsi_probe_cache *cp;
int i;
/*
* Reset all entries to SCSIPROBE_EXISTS. This will
* force probing to be performed the next time
* sd_scsi_probe_with_cache is called.
*/
for (i = 0; i < NTARGETS_WIDE; i++) {
}
}
}
/*
* Function: sd_scsi_probe_with_cache
*
* Description: This routine implements support for a scsi device probe
* with cache. The driver maintains a cache of the target
* responses to scsi probes. If we get no response from a
* target during a probe inquiry, we remember that, and we
* avoid additional calls to scsi_probe on non-zero LUNs
* on the same target until the cache is cleared. By doing
* so we avoid the 1/4 sec selection timeout for nonzero
* LUNs. lun0 of a target is always probed.
*
* Arguments: devp - Pointer to a scsi_device(9S) structure
* waitfunc - indicates what the allocator routines should
* do when resources are not available. This value
* is passed on to scsi_probe() when that routine
* is called.
*
* Return Code: SCSIPROBE_NORESP if a NORESP in probe response cache;
* otherwise the value returned by scsi_probe(9F).
*
* Context: Kernel thread context
*/
static int
{
struct sd_scsi_probe_cache *cp;
SCSI_ADDR_PROP_LUN, 0);
SCSI_ADDR_PROP_TARGET, -1);
/* Make sure caching enabled and target in range */
/* do it the old way (no cache) */
}
/* Find the cache for this scsi bus instance */
break;
}
}
/* If we can't find a cache for this pdip, create one */
int i;
KM_SLEEP);
for (i = 0; i < NTARGETS_WIDE; i++) {
}
}
/* Recompute the cache for this target if LUN zero */
if (lun == 0) {
}
/* Don't probe if cache remembers a NORESP from a previous LUN. */
return (SCSIPROBE_NORESP);
}
/* Do the actual probe; save & return the result */
}
/*
* Function: sd_spin_up_unit
*
* Description: Issues the following commands to spin-up the device:
* START STOP UNIT, and INQUIRY.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: 0 - success
* EIO - failure
* EACCES - reservation conflict
*
* Context: Kernel thread context
*/
static int
{
int has_conflict = FALSE;
/*
* Send a throwaway START UNIT command.
*
* If we fail on this, we don't care presently what precisely
* is wrong. EMC's arrays will also fail this with a check
* condition (0x2/0x4/0x3) if the device is "inactive," but
* we don't want to fail the attach because it may become
* "active" later.
*/
== EACCES)
has_conflict = TRUE;
/*
* Send another INQUIRY command to the target. This is necessary for
* non-removable media direct access devices because their INQUIRY data
* may not be fully qualified until they are spun up (perhaps via the
* START command above). Note: This seems to be needed for some
* legacy devices only.) The INQUIRY command should succeed even if a
* Reservation Conflict is present.
*/
return (EIO);
}
/*
* If we got enough INQUIRY data, copy it over the old INQUIRY data.
* Note that this routine does not return a failure here even if the
* INQUIRY command did not return any data. This is a legacy behavior.
*/
}
/* If we hit a reservation conflict above, tell the caller. */
if (has_conflict == TRUE) {
return (EACCES);
}
return (0);
}
#ifdef _LP64
/*
* Function: sd_enable_descr_sense
*
* Description: This routine attempts to select descriptor sense format
* using the Control mode page. Devices that support 64 bit
* LBAs (for >2TB luns) should also implement descriptor
* sense data so we will call this function whenever we see
* a lun larger than 2TB. If for some reason the device
* supports 64 bit LBAs but doesn't support descriptor sense
* presumably the mode select will fail. Everything will
* continue to work normally except that we will not get
* complete sense data for commands that fail with an LBA
* larger than 32 bits.
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Kernel thread context only
*/
static void
{
struct mode_control_scsi3 *ctrl_bufp;
/*
* Read MODE SENSE page 0xA, Control Mode Page
*/
sizeof (struct mode_control_scsi3);
MODEPAGE_CTRL_MODE, SD_PATH_DIRECT) != 0) {
"sd_enable_descr_sense: mode sense ctrl page failed\n");
goto eds_exit;
}
/*
* Determine size of Block Descriptors in order to locate
* the mode page data. ATAPI devices return 0, SCSI devices
* should return MODE_BLK_DESC_LENGTH.
*/
ctrl_bufp = (struct mode_control_scsi3 *)
/*
* Clear PS bit for MODE SELECT
*/
/*
* Set D_SENSE to enable descriptor sense format.
*/
/*
* Use MODE SELECT to commit the change to the D_SENSE bit
*/
"sd_enable_descr_sense: mode select ctrl page failed\n");
goto eds_exit;
}
}
/*
* Function: sd_reenable_dsense_task
*
* Description: Re-enable descriptor sense after device or bus reset
*
* Context: Executes in a taskq() thread context
*/
static void
sd_reenable_dsense_task(void *arg)
{
}
#endif /* _LP64 */
/*
* Function: sd_set_mmc_caps
*
* Description: This routine determines if the device is MMC compliant and if
* the device supports CDDA via a mode sense of the CDVD
* capabilities mode page. Also checks if the device is a
* dvdram writable device.
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Kernel thread context only
*/
static void
{
struct mode_header_grp2 *sense_mhp;
int bd_len;
int status;
int rtn;
/*
* The flags which will be set in this function are - mmc compliant,
* dvdram writable device, cdda support. Initialize them to FALSE
* and if a capability is detected - it will be set to TRUE.
*/
if (status != 0) {
/* command failed; just return */
return;
}
/*
* If the mode sense request for the CDROM CAPABILITIES
* page (0x2A) succeeds the device is assumed to be MMC.
*/
/* Get to the page data */
if (bd_len > MODE_BLK_DESC_LENGTH) {
/*
* We did not get back the expected block descriptor
* length so we cannot determine if the device supports
* CDDA. However, we still indicate the device is MMC
* according to the successful response to the page
* 0x2A mode sense request.
*/
"sd_set_mmc_caps: Mode Sense returned "
"invalid block descriptor length\n");
return;
}
/* See if read CDDA is supported */
bd_len);
/* See if writing DVD RAM is supported. */
return;
}
/*
* If the device presents DVD or CD capabilities in the mode
* page, we can return here since a RRD will not have
* these capabilities.
*/
return;
}
/*
* If un->un_f_dvdram_writable_device is still FALSE,
* check for a Removable Rigid Disk (RRD). A RRD
* device is identified by the features RANDOM_WRITABLE and
* HARDWARE_DEFECT_MANAGEMENT.
*/
if (rtn != 0) {
return;
}
if (rtn == 0) {
/*
* We have good information, check for random writable
* and hardware defect features.
*/
}
}
}
/*
* Function: sd_check_for_writable_cd
*
* Description: This routine determines if the media in the device is
* writable or not. It uses the get configuration command (0x46)
* to determine if the media is writable
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Never called at interrupt context.
*/
static void
{
int rtn;
struct mode_header_grp2 *sense_mhp;
int bd_len;
int status;
/*
* Initialize the writable media to false, if configuration info.
* tells us otherwise then only we will set it.
*/
if (rtn == 0) {
/*
* We have good information, check for writable DVD.
*/
return;
}
}
/*
* Determine if this is a RRD type device.
*/
if (status != 0) {
/* command failed; just return */
return;
}
/* Get to the page data */
if (bd_len > MODE_BLK_DESC_LENGTH) {
/*
* We did not get back the expected block descriptor length so
* we cannot check the mode page.
*/
"sd_check_for_writable_cd: Mode Sense returned "
"invalid block descriptor length\n");
return;
}
/*
* If the device presents DVD or CD capabilities in the mode
* page, we can return here since a RRD device will not have
* these capabilities.
*/
return;
}
/*
* If un->un_f_mmc_writable_media is still FALSE,
* check for RRD type media. A RRD device is identified
* by the features RANDOM_WRITABLE and HARDWARE_DEFECT_MANAGEMENT.
*/
if (rtn != 0) {
return;
}
if (rtn == 0) {
/*
* We have good information, check for random writable
* and hardware defect features as current.
*/
}
}
}
/*
* Function: sd_read_unit_properties
*
* Description: The following implements a property lookup mechanism.
* Properties for particular disks (keyed on vendor, model
* and rev numbers) are sought in the sd.conf file via
* sd_process_sdconf_file(), and if not found there, are
* looked for in a list hardcoded in this driver via
* sd_process_sdconf_table() Once located the properties
* are used to update the driver unit structure.
*
* Arguments: un - driver soft state (unit) structure
*/
static void
{
/*
* sd_process_sdconf_file returns SD_FAILURE if it cannot find
* the "sd-config-list" property (from the sd.conf file) or if
* occurs the static driver configuration table is searched for
* a match.
*/
}
/* check for LSI device */
}
/*
* Function: sd_process_sdconf_file
*
* Description: Use ddi_getlongprop to obtain the properties from the
* driver's config file (ie, sd.conf) and update the driver
* soft state structure accordingly.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: SD_SUCCESS - The properties were successfully set according
* to the driver configuration file.
* SD_FAILURE - The driver config list was not obtained or
* the static config table should be used.
*
* The config file has a property, "sd-config-list", which consists of
* one or more duplets as follows:
*
* sd-config-list=
* <duplet>,
* [<duplet>,]
* [<duplet>];
*
* The structure of each duplet is as follows:
*
* <duplet>:= <vid+pid>,<data-property-name_list>
*
* The first entry of the duplet is the device ID string (the concatenated
* vid & pid; not to be confused with a device_id). This is defined in
* the same way as in the sd_disk_table.
*
* The second part of the duplet is a string that identifies a
* data-property-name-list. The data-property-name-list is defined as
* follows:
*
* <data-property-name-list>:=<data-property-name> [<data-property-name>]
*
* The syntax of <data-property-name> depends on the <version> field.
*
* If version = SD_CONF_VERSION_1 we have the following syntax:
*
* <data-property-name>:=<version>,<flags>,<prop0>,<prop1>,.....<propN>
*
* where the prop0 value will be used to set prop0 if bit0 set in the
* flags, prop1 if bit1 set, etc. and N = SD_CONF_MAX_ITEMS -1
*
*/
static int
{
char *config_list = NULL;
int config_list_len;
int len;
int dupletlen = 0;
char *vidptr;
int vidlen;
char *dnlist_ptr;
char *dataname_ptr;
int dnlist_len;
int dataname_len;
int *data_list;
int data_list_len;
int rval = SD_FAILURE;
int i;
/* Obtain the configuration list associated with the .conf file */
!= DDI_PROP_SUCCESS) {
return (SD_FAILURE);
}
/*
* Compare vids in each duplet to the inquiry vid - if a match is
* made, get the data value and update the soft state structure
* accordingly.
*
* Note: This algorithm is complex and difficult to maintain. It should
* be replaced with a more robust implementation.
*/
/*
* Note: The assumption here is that each vid entry is on
* a unique line from its associated duplet.
*/
if ((vidlen == 0) ||
dupletlen++;
continue;
}
/*
* dnlist contains 1 or more blank separated
* data-property-name entries
*/
/*
* Set a pointer for the first data-property-name
* entry in the list
*/
dataname_len = 0;
/*
* Loop through all data-property-name entries in the
* data-property-name-list setting the properties for each.
*/
while (dataname_len < dnlist_len) {
int version;
/*
* Determine the length of the current
* data-property-name entry by indexing until a
* blank or NULL is encountered. When the space is
* encountered reset it to a NULL for compliance
* with ddi_getlongprop().
*/
for (i = 0; ((dataname_ptr[i] != ' ') &&
(dataname_ptr[i] != '\0')); i++) {
;
}
dataname_len += i;
/* If not null terminated, Make it so */
if (dataname_ptr[i] == ' ') {
dataname_ptr[i] = '\0';
}
dataname_len++;
"sd_process_sdconf_file: disk:%s, data:%s\n",
/* Get the data list */
!= DDI_PROP_SUCCESS) {
"sd_process_sdconf_file: data property (%s)"
" has no value\n", dataname_ptr);
continue;
}
if (version == SD_CONF_VERSION_1) {
/* Set the properties */
== SD_SUCCESS) {
&values);
rval = SD_SUCCESS;
} else {
rval = SD_FAILURE;
}
} else {
"data property %s version 0x%x is invalid.",
rval = SD_FAILURE;
}
}
}
/* free up the memory allocated by ddi_getlongprop */
if (config_list) {
}
return (rval);
}
/*
* Function: sd_get_tunables_from_conf()
*
*
* This function reads the data list from the sd.conf file and pulls
* the values that can have numeric values as arguments and places
* the values in the apropriate sd_tunables member.
* Since the order of the data list members varies across platforms
* This function reads them from the data list in a platform specific
* order and places them into the correct sd_tunable member that is
* a consistant across all platforms.
*/
static void
{
int i;
int mask;
for (i = 0; i < SD_CONF_MAX_ITEMS; i++) {
mask = 1 << i;
break;
}
case 0: /* This mask bit not set in flags */
continue;
case SD_CONF_BSET_THROTTLE:
"sd_get_tunables_from_conf: throttle = %d\n",
break;
case SD_CONF_BSET_CTYPE:
"sd_get_tunables_from_conf: ctype = %d\n",
break;
case SD_CONF_BSET_NRR_COUNT:
"sd_get_tunables_from_conf: not_rdy_retries = %d\n",
break;
"sd_get_tunables_from_conf: busy_retries = %d\n",
break;
case SD_CONF_BSET_RST_RETRIES:
"sd_get_tunables_from_conf: reset_retries = %d\n",
break;
"sd_get_tunables_from_conf: reserv_rel_time = %d\n",
break;
"sd_get_tunables_from_conf: min_throttle = %d\n",
break;
"sd_get_tunables_from_conf: disk_sort_dis = %d\n",
break;
"sd_get_tunables_from_conf: lun_reset_enable = %d"
break;
}
}
}
/*
* Function: sd_process_sdconf_table
*
* Description: Search the static configuration table for a match on the
* according to the table property values for the device.
*
* The form of a configuration table entry is:
* <vid+pid>,<flags>,<property-data>
* "SEAGATE ST42400N",1,63,0,0 (Fibre)
* "SEAGATE ST42400N",1,63,0,0,0,0 (Sparc)
* "SEAGATE ST42400N",1,63,0,0,0,0,0,0,0,0,0,0 (Intel)
*
* Arguments: un - driver soft state (unit) structure
*/
static void
{
int table_index;
int idlen;
table_index++) {
if (idlen == 0) {
continue;
}
/*
* The static configuration table currently does not
* implement version 10 properties. Additionally,
* multiple data-property-name entries are not
* implemented in the static configuration table.
*/
"sd_process_sdconf_table: disk %s\n", id);
break;
}
}
}
/*
* Function: sd_sdconf_id_match
*
* comparison as well as the boundary cases of wild card and
* multiple blanks.
*
* Note: An implicit assumption made here is that the scsi
* inquiry structure will always keep the vid, pid and
* revision strings in consecutive sequence, so they can be
* read as a single string. If this assumption is not the
* case, a separate string, to be used for the check, needs
* to be built with these strings concatenated.
*
* Arguments: un - driver soft state (unit) structure
*
*/
static int
{
struct scsi_inquiry *sd_inq;
int rval = SD_SUCCESS;
/*
* We use the inq_vid as a pointer to a buffer containing the
* entry for the comparison. This works because the inq_pid
* data member follows inq_vid in the scsi_inquiry structure.
*/
/*
* using a case insensitive comparison and ignoring
* multiple spaces.
*/
if (rval != SD_SUCCESS) {
/*
* User id strings that start and end with a "*"
* are a special case. These do not have a
* specific vendor, and the product string can
* appear anywhere in the 16 byte PID portion of
* the inquiry data. This is a simple strstr()
* type search for the user id in the inquiry data.
*/
int i;
int j;
if (j < 0) {
return (SD_FAILURE);
}
for (i = 0; i < j; i++) {
rval = SD_SUCCESS;
break;
}
}
}
}
}
return (rval);
}
/*
* Function: sd_blank_cmp
*
* Description: If the id string starts and ends with a space, treat
* multiple consecutive spaces as equivalent to a single
* space. For example, this causes a sd_disk_table entry
* of " NEC CDROM " to match a device's id string of
* "NEC CDROM".
*
* Note: The success exit condition for this routine is if
* the pointer to the table entry is '\0' and the cnt of
* the inquiry length is zero. This will happen if the inquiry
* string returned by the device is padded with spaces to be
* exactly 24 bytes in length (8 byte vid + 16 byte pid). The
* SCSI spec states that the inquiry string is to be padded with
* spaces.
*
* Arguments: un - driver soft state (unit) structure
*
*/
static int
{
char *p1;
char *p2;
int cnt;
/*
* Note: string p1 is terminated by a NUL but string p2
* isn't. The end of p2 is determined by cnt.
*/
for (;;) {
/* skip over any extra blanks in both strings */
p1++;
}
p2++;
cnt--;
}
/* compare the two strings */
if ((cnt == 0) ||
break;
}
while ((cnt > 0) &&
p1++;
p2++;
cnt--;
}
}
}
/* return SD_SUCCESS if both strings match */
}
/*
* Function: sd_chk_vers1_data
*
* Description: Verify the version 1 device properties provided by the
* user via the configuration file
*
* Arguments: un - driver soft state (unit) structure
* flags - integer mask indicating properties to be set
* prop_list - integer list of property values
* list_len - length of user provided data
*
* Return Code: SD_SUCCESS - Indicates the user provided data is valid
* SD_FAILURE - Indicates the user provided data is invalid
*/
static int
int list_len, char *dataname_ptr)
{
int i;
int mask = 1;
int index = 0;
/* Check for a NULL property name and list */
if (dataname_ptr == NULL) {
"sd_chk_vers1_data: NULL data property name.");
return (SD_FAILURE);
}
"sd_chk_vers1_data: %s NULL data property list.",
return (SD_FAILURE);
}
/* Display a warning if undefined bits are set in the flags */
if (flags & ~SD_CONF_BIT_MASK) {
"sd_chk_vers1_data: invalid bits 0x%x in data list %s. "
"Properties not set.",
return (SD_FAILURE);
}
/*
* Verify the length of the list by identifying the highest bit set
* in the flags and validating that the property list has a length
* up to the index of this bit.
*/
for (i = 0; i < SD_CONF_MAX_ITEMS; i++) {
index++;
}
mask = 1 << i;
}
"sd_chk_vers1_data: "
"Data property list %s size is incorrect. "
"Properties not set.", dataname_ptr);
"version + 1 flagword + %d properties", SD_CONF_MAX_ITEMS);
return (SD_FAILURE);
}
return (SD_SUCCESS);
}
/*
* Function: sd_set_vers1_properties
*
* Description: Set version 1 device properties based on a property list
* retrieved from the driver configuration file or static
* configuration table. Version 1 properties have the format:
*
* <data-property-name>:=<version>,<flags>,<prop0>,<prop1>,.....<propN>
*
* where the prop0 value will be used to set prop0 if bit0
* is set in the flags
*
* Arguments: un - driver soft state (unit) structure
* flags - integer mask indicating properties to be set
* prop_list - integer list of property values
*/
static void
{
/*
* Set the flag to indicate cache is to be disabled. An attempt
* to disable the cache via sd_cache_control() will be made
* later during attach once the basic initialization is complete.
*/
if (flags & SD_CONF_BSET_NOCACHE) {
"sd_set_vers1_properties: caching disabled flag set\n");
}
/* CD-specific configuration parameters */
if (flags & SD_CONF_BSET_PLAYMSF_BCD) {
"sd_set_vers1_properties: playmsf_bcd set\n");
}
if (flags & SD_CONF_BSET_READSUB_BCD) {
"sd_set_vers1_properties: readsub_bcd set\n");
}
if (flags & SD_CONF_BSET_READ_TOC_TRK_BCD) {
"sd_set_vers1_properties: read_toc_trk_bcd set\n");
}
if (flags & SD_CONF_BSET_READ_TOC_ADDR_BCD) {
"sd_set_vers1_properties: read_toc_addr_bcd set\n");
}
if (flags & SD_CONF_BSET_NO_READ_HEADER) {
"sd_set_vers1_properties: no_read_header set\n");
}
if (flags & SD_CONF_BSET_READ_CD_XD4) {
"sd_set_vers1_properties: read_cd_xd4 set\n");
}
if (flags & SD_CONF_BSET_FAB_DEVID) {
"sd_set_vers1_properties: fab_devid bit set\n");
}
/* Support for user throttle configuration */
if (flags & SD_CONF_BSET_THROTTLE) {
"sd_set_vers1_properties: throttle set to %d\n",
}
/* Set the per disk retry count according to the conf file or table. */
if (flags & SD_CONF_BSET_NRR_COUNT) {
if (prop_list->sdt_not_rdy_retries) {
"sd_set_vers1_properties: not ready retry count"
}
}
/* The controller type is reported for generic disk driver ioctls */
if (flags & SD_CONF_BSET_CTYPE) {
case CTYPE_CDROM:
"sd_set_vers1_properties: ctype set to "
"CTYPE_CDROM\n");
break;
case CTYPE_CCS:
"sd_set_vers1_properties: ctype set to "
"CTYPE_CCS\n");
break;
case CTYPE_ROD: /* RW optical */
"sd_set_vers1_properties: ctype set to "
"CTYPE_ROD\n");
break;
default:
"sd_set_vers1_properties: Could not set "
"invalid ctype value (%d)",
}
}
/* Purple failover timeout */
if (flags & SD_CONF_BSET_BSY_RETRY_COUNT) {
"sd_set_vers1_properties: "
"busy retry count set to %d\n",
}
/* Purple reset retry count */
if (flags & SD_CONF_BSET_RST_RETRIES) {
"sd_set_vers1_properties: "
"reset retry count set to %d\n",
}
/* Purple reservation release timeout */
if (flags & SD_CONF_BSET_RSV_REL_TIME) {
"sd_set_vers1_properties: "
"reservation release timeout set to %d\n",
}
/*
* Driver flag telling the driver to verify that no commands are pending
* for a device before issuing a Test Unit Ready. This is a workaround
* for a firmware bug in some Seagate eliteI drives.
*/
if (flags & SD_CONF_BSET_TUR_CHECK) {
"sd_set_vers1_properties: tur queue check set\n");
}
if (flags & SD_CONF_BSET_MIN_THROTTLE) {
"sd_set_vers1_properties: min throttle set to %d\n",
}
if (flags & SD_CONF_BSET_DISKSORT_DISABLED) {
(prop_list->sdt_disk_sort_dis != 0) ?
"sd_set_vers1_properties: disksort disabled "
"flag set to %d\n",
}
if (flags & SD_CONF_BSET_LUN_RESET_ENABLED) {
(prop_list->sdt_lun_reset_enable != 0) ?
"sd_set_vers1_properties: lun reset enabled "
"flag set to %d\n",
}
/*
* Validate the throttle values.
* If any of the numbers are invalid, set everything to defaults.
*/
}
}
/*
* Function: sd_is_lsi()
*
* Description: Check for lsi devices, step throught the static device
*
* Args: un - ptr to sd_lun
*
* Notes: When creating new LSI property, need to add the new LSI property
* to this function.
*/
static void
{
int table_index;
int idlen;
void *prop;
table_index++) {
if (idlen == 0) {
continue;
}
if (prop == &lsi_properties ||
prop == &lsi_oem_properties ||
prop == &lsi_properties_scsi ||
prop == &symbios_properties) {
}
break;
}
}
}
/*
* The following routines support reading and interpretation of disk labels,
* including Solaris BE (8-slice) vtoc's, Solaris LE (16-slice) vtoc's, and
* fdisk tables.
*/
/*
* Function: sd_validate_geometry
*
* Description: Read the label from the disk (if present). Update the unit's
* geometry and vtoc information from the data in the label.
* Verify that the label is valid.
*
* Arguments: un - driver soft state (unit) structure
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: 0 - Successful completion
* EINVAL - Invalid value in un->un_tgt_blocksize or
* un->un_blockcount; or label on disk is corrupted
* or unreadable.
* EACCES - Reservation conflict at the device.
* ENOMEM - Resource allocation error
* ENOTSUP - geometry not applicable
*
* Context: Kernel thread only (can sleep).
*/
static int
{
static char labelstring[128];
static char buf[256];
int label_error = 0;
int lbasize;
int count;
/*
* If the required values are not valid, then try getting them
* once via read capacity. If that fails, then fail this call.
* This is necessary with the new mpxio failover behavior in
* the T300 where we can get an attach for the inactive path
* before the active path. The inactive path fails commands with
* sense data of 02,04,88 which happens to the read capacity
* before mpxio has had sufficient knowledge to know if it should
* force a fail over or not. (Which it won't do at attach anyhow).
* If the read capacity at attach time fails, un_tgt_blocksize and
* un_blockcount won't be valid.
*/
int rval;
&lbasz, SD_PATH_DIRECT);
if (rval == 0) {
/*
* The following relies on
* sd_send_scsi_READ_CAPACITY never
*/
}
return (EINVAL);
}
}
/*
* Copy the lbasize and capacity so that if they're reset while we're
* not holding the SD_MUTEX, we will continue to use valid values
* after the SD_MUTEX is reacquired. (4119659)
*/
#if defined(_SUNOS_VTOC_16)
/*
* Set up the "whole disk" fdisk partition; this should always
* exist, regardless of whether the disk contains an fdisk table
* or vtoc.
*/
#endif
/*
* Refresh the logical and physical geometry caches.
* and scsi_ifgetcap("geometry").
*/
if (label_error == 0) {
/* found a valid EFI label */
"sd_validate_geometry: found EFI label\n");
un->un_solaris_offset = 0;
return (ENOTSUP);
}
if (label_error == ESRCH) {
/*
* they've configured a LUN over 1TB, but used
* format.dat to restrict format's view of the
* capacity to be under 1TB
*/
"is >1TB and has a VTOC label: use format(1M) to either decrease the");
"size to be < 1TB or relabel the disk with an EFI label");
} else {
/* unlabeled disk over 1TB */
/*
* Refer to comments on off-by-1 at the head of the file
* A 1TB disk was treated as (1T - 512)B in the past,
* thus, it might have valid solaris partition. We
* will return ENOTSUP later only if this disk has no
* valid solaris partition.
*/
#endif
return (ENOTSUP);
}
}
label_error = 0;
/*
* at this point it is either labeled with a VTOC or it is
* under 1TB (<= 1TB actually for off-by-1)
*/
if (un->un_f_vtoc_label_supported) {
int rval;
/*
* Note: This will set up un->un_solaris_size and
* un->un_solaris_offset.
*/
return (EACCES);
case SD_CMD_FAILURE:
return (ENOMEM);
}
/*
* Refer to comments on off-by-1 at the head of the file
* This is for 1TB disk only. Since that there is no
* solaris partitions, return ENOTSUP as we do for
* >1TB disk.
*/
return (ENOTSUP);
#endif
/*
* Found fdisk table but no Solaris partition entry,
* so don't call sd_uselabel() and don't create
* a default label.
*/
label_error = 0;
goto no_solaris_partition;
}
/*
* Refer to comments on off-by-1 at the head of the file
* Now, this 1TB disk has valid solaris partition. It
* must be created by previous sd driver, we have to
* treat it as (1T-512)B.
*/
/*
* Refer to sd_read_fdisk, when there is no
* fdisk partition table, un_solaris_size is
* set to disk's capacity. In this case, we
* need to adjust it
*/
}
#endif
/*
* sys_blocksize != tgt_blocksize, need to re-adjust
* blkno and save the index to beginning of dk_label
*/
sizeof (struct dk_label));
"label_addr: 0x%x allocation size: 0x%x\n",
return (ENOMEM);
}
switch (rval) {
case 0:
/*
* sd_uselabel will establish that the geometry
* is valid.
* For sys_blocksize != tgt_blocksize, need
* to index into the beginning of dk_label
*/
path_flag) != SD_LABEL_IS_VALID) {
}
break;
case EACCES:
break;
default:
break;
}
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#error "No VTOC format defined."
#endif
}
/*
* If a valid label was not found, AND if no reservation conflict
* was detected, then go ahead and create a default label (4069506).
*/
}
label_error = 0;
}
if ((!un->un_f_has_removable_media ||
/*
* Print out a message indicating who and what we are.
* We do this only when we happen to really validate the
* geometry. We may call sd_validate_geometry() at other
* times, e.g., ioctl()'s like Get VTOC in which case we
* don't want to print the label.
* If the geometry is valid, print the label string,
* else print vendor and product info, if available
*/
} else {
&labelstring[64]);
", %llu %u byte blocks\n",
} else {
", (unknown capacity)\n");
}
}
}
#if defined(_SUNOS_VTOC_16)
/*
* If we have valid geometry, set up the remaining fdisk partitions.
* Note that dkl_cylno is not used for the fdisk map entries, so
* we set it to an entirely bogus value.
*/
}
#endif
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#error "No VTOC format defined."
#endif
}
return (label_error);
}
#if defined(_SUNOS_VTOC_16)
/*
* Macro: MAX_BLKS
*
* This macro is used for table entries where we need to have the largest
* possible sector value for that head & SPT (sectors per track)
* combination. Other entries for some smaller disk sizes are set by
* convention to match those used by X86 BIOS usage.
*/
/*
* Function: sd_convert_geometry
*
* Description: Convert physical geometry into a dk_geom structure. In
* other words, make sure we don't wrap 16-bit values.
* e.g. converting from geom_cache to dk_geom
*
* Context: Kernel thread only
*/
static void
{
int i;
static const struct chs_values {
} CHS_values[] = {
{0x00200000, 64, 32}, /* 1GB or smaller disk. */
{0x01000000, 128, 32}, /* 8GB or smaller disk. */
};
/* Unlabeled SCSI floppy device */
if (capacity <= 0x1000) {
return;
}
/*
* For all devices we calculate cylinders using the
* heads and sectors we assign based on capacity of the
* device. The table is designed to be compatible with the
* way other operating systems lay out fdisk tables for X86
* and to insure that the cylinders never exceed 65535 to
* prevent problems with X86 ioctls that report geometry.
* We use SPT that are multiples of 63, since other OSes that
* are not limited to 16-bits for cylinders stop at 63 SPT
* we make do by using multiples of 63 SPT.
*
* Note than capacities greater than or equal to 1TB will simply
* get the largest geometry from the table. This should be okay
* since disks this large shouldn't be using CHS values anyway.
*/
;
}
#endif
/*
* Function: sd_resync_geom_caches
*
* Description: (Re)initialize both geometry caches: the virtual geometry
* information is extracted from the HBA (the "geometry"
* capability), and the physical geometry cache data is
* generated by issuing MODE SENSE commands.
*
* Arguments: un - driver soft state (unit) structure
* capacity - disk capacity in #blocks
* lbasize - disk block size in bytes
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Context: Kernel thread only (can sleep).
*/
static void
int path_flag)
{
struct geom_cache pgeom;
int spc;
unsigned short nhead;
unsigned short nsect;
/*
* Ask the controller for its logical geometry.
* Note: if the HBA does not support scsi_ifgetcap("geometry"),
* then the lgeom cache will be invalid.
*/
/*
* Initialize the pgeom cache from lgeom, so that if MODE SENSE
* doesn't work, DKIOCG_PHYSGEOM can return reasonable values.
*/
/*
* Note: Perhaps this needs to be more adaptive? The rationale
* is that, if there's no HBA geometry from the HBA driver, any
* guess is good, since this is the physical geometry. If MODE
* SENSE fails this gives a max cylinder size for non-LBA access
*/
nhead = 255;
nsect = 63;
} else {
}
} else {
}
/*
* Retrieve fresh geometry data from the hardware, stash it
* here temporarily before we rebuild the incore label.
*
* We want to use the MODE SENSE commands to derive the
* physical geometry of the device, but if either command
* fails, the logical geometry is used as the fallback for
* disk label geometry.
*/
/*
* Now update the real copy while holding the mutex. This
* way the global copy is never in an inconsistent state.
*/
"(cached from lgeom)\n");
" ncyl: %ld; acyl: %d; nhead: %d; nsect: %d\n",
}
/*
* Function: sd_read_fdisk
*
* Description: utility routine to read the fdisk table.
*
* Arguments: un - driver soft state (unit) structure
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: SD_CMD_SUCCESS
* SD_CMD_FAILURE
*
* Context: Kernel thread only (can sleep).
*/
/* ARGSUSED */
static int
{
#if defined(_NO_FDISK_PRESENT)
un->un_solaris_offset = 0;
return (SD_CMD_SUCCESS);
#elif defined(_FIRMWARE_NEEDS_FDISK)
int i;
char sigbuf[2];
int uidx;
int rval;
int lba = 0;
/*
* Start off assuming no fdisk table
*/
solaris_offset = 0;
if (rval != 0) {
"sd_read_fdisk: fdisk read err\n");
return (SD_CMD_FAILURE);
}
/*
* The fdisk table does not begin on a 4-byte boundary within the
* master boot record, so we copy it to an aligned structure to avoid
* alignment exceptions on some processors.
*/
/*
* Check for lba support before verifying sig; sig might not be
* there, say on a blank disk, but the max_chs mark may still
* be present.
*
* Note: LBA support and BEFs are an x86-only concept but this
* code should work OK on SPARC as well.
*/
/*
* First, check for lba-access-ok on root node (or prom root node)
* if present there, don't need to search fdisk table.
*/
"lba-access-ok", 0) != 0) {
/* All drives do LBA; don't search fdisk table */
lba = 1;
} else {
/* Okay, look for mark in fdisk table */
/* accumulate "lba" value from all partitions */
}
}
if (lba != 0) {
"lba-access-ok", 0) == 0) {
/* not found; create it */
"sd_read_fdisk: Can't create lba property "
"for instance %d\n",
}
}
}
/*
* Endian-independent signature check
*/
"sd_read_fdisk: no fdisk\n");
goto done;
}
#ifdef SDDEBUG
if (sd_level_mask & SD_LOGMASK_INFO) {
"numsect sysid bootid\n");
for (i = 0; i < FD_NUMPART; i++, fdp++) {
" %d: %8d %8d 0x%08x 0x%08x\n",
}
}
#endif
/*
* Try to find the unix partition
*/
uidx = -1;
solaris_offset = 0;
solaris_size = 0;
int relsect;
int numsect;
continue;
}
/*
* Data in the fdisk table is little-endian.
*/
continue;
}
/*
* use the last active solaris partition id found
* (there should only be 1 active partition id)
*
* if there are no active solaris partition id
* then use the first inactive solaris partition id
*/
uidx = i;
}
}
done:
/*
* Clear the VTOC info, only if the Solaris partition entry
* has moved, changed size, been deleted, or if the size of
* the partition is too small to even fit the label sector.
*/
solaris_size <= DK_LABEL_LOC) {
}
return (rval);
#else /* #elif defined(_FIRMWARE_NEEDS_FDISK) */
#error "fdisk table presence undetermined for this platform."
#endif /* #if defined(_NO_FDISK_PRESENT) */
}
/*
* Function: sd_get_physical_geometry
*
* Description: Retrieve the MODE SENSE page 3 (Format Device Page) and
* MODE SENSE page 4 (Rigid Disk Drive Geometry Page) from the
* target, and use this information to initialize the physical
* geometry cache specified by pgeom_p.
*
* MODE SENSE is an optional command, so failure in this case
* does not necessarily denote an error. We want to use the
* MODE SENSE commands to derive the physical geometry of the
* device, but if either command fails, the logical geometry is
* used as the fallback for disk label geometry.
*
* This requires that un->un_blockcount and un->un_tgt_blocksize
* have already been initialized for the current target and
* that the current values be passed as args so that we don't
* end up ever trying to use -1 as a valid value. This could
* happen if either value is reset while we're not holding
* the mutex.
*
* Arguments: un - driver soft state (unit) structure
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Context: Kernel thread only (can sleep).
*/
static void
{
struct mode_format *page3p;
struct mode_geometry *page4p;
struct mode_header *headerp;
int sector_size;
int nsect;
int nhead;
int ncyl;
int intrlv;
int spc;
int modesense_capacity;
int rpm;
int bd_len;
int mode_header_length;
int cdbsize;
return;
}
return;
}
if (lbasize == 0) {
lbasize = 2048;
} else {
}
}
/*
* Retrieve MODE SENSE page 3 - Format Device Page
*/
!= 0) {
"sd_get_physical_geometry: mode sense page 3 failed\n");
goto page3_exit;
}
/*
* Determine size of Block Descriptors in order to locate the mode
* page data. ATAPI devices return 0, SCSI devices should return
* MODE_BLK_DESC_LENGTH.
*/
struct mode_header_grp2 *mhp =
(struct mode_header_grp2 *)headerp;
} else {
}
if (bd_len > MODE_BLK_DESC_LENGTH) {
"received unexpected bd_len of %d, page3\n", bd_len);
goto page3_exit;
}
page3p = (struct mode_format *)
"mode sense pg3 code mismatch %d\n",
goto page3_exit;
}
/*
* Use this physical geometry data only if BOTH MODE SENSE commands
* complete successfully; otherwise, revert to the logical geometry.
* So, we need to save everything in temporary variables.
*/
/*
* 1243403: The NEC D38x7 drives do not support MODE SENSE sector size
*/
if (sector_size == 0) {
} else {
}
"sd_get_physical_geometry: Format Parameters (page 3)\n");
" mode page: %d; nsect: %d; sector size: %d;\n",
" interleave: %d; track skew: %d; cylinder skew: %d;\n", intrlv,
/*
* Retrieve MODE SENSE page 4 - Rigid Disk Drive Geometry Page
*/
!= 0) {
"sd_get_physical_geometry: mode sense page 4 failed\n");
goto page4_exit;
}
/*
* Determine size of Block Descriptors in order to locate the mode
* page data. ATAPI devices return 0, SCSI devices should return
* MODE_BLK_DESC_LENGTH.
*/
struct mode_header_grp2 *mhp =
(struct mode_header_grp2 *)headerp;
} else {
}
if (bd_len > MODE_BLK_DESC_LENGTH) {
"received unexpected bd_len of %d, page4\n", bd_len);
goto page4_exit;
}
page4p = (struct mode_geometry *)
"mode sense pg4 code mismatch %d\n",
goto page4_exit;
}
/*
* Stash the data now, after we know that both commands completed.
*/
"sd_get_physical_geometry: Geometry Parameters (page 4)\n");
" computed capacity(h*s*c): %d;\n", modesense_capacity);
/*
* Compensate if the drive's geometry is not rectangular, i.e.,
* the product of C * H * S returned by MODE SENSE >= that returned
* by read capacity. This is an idiosyncrasy of the original x86
* disk subsystem.
*/
if (modesense_capacity >= capacity) {
"sd_get_physical_geometry: adjusting acyl; "
if (sector_size != 0) {
/* 1243403: NEC D38x7 drives don't support sec size */
}
}
"sd_get_physical_geometry: mode sense geometry:\n");
" nsect: %d; sector size: %d; interlv: %d\n",
" nhead: %d; ncyl: %d; rpm: %d; capacity(ms): %d\n",
"sd_get_physical_geometry: (cached)\n");
" ncyl: %ld; acyl: %d; nhead: %d; nsect: %d\n",
" lbasize: %d; capacity: %ld; intrlv: %d; rpm: %d\n",
}
/*
* Function: sd_get_virtual_geometry
*
* Description: Ask the controller to tell us about the target device.
*
* Arguments: un - pointer to softstate
* capacity - disk capacity in #blocks
* lbasize - disk block size in bytes
*
* Context: Kernel thread only
*/
static void
{
int spc;
/* Set sector size, and total number of sectors */
/* Let the HBA tell us its geometry */
/* A value of -1 indicates an undefined "geometry" property */
if (geombuf == (-1)) {
return;
}
/* Initialize the logical geometry cache. */
/*
* Note: The driver originally converted the capacity value from
* target blocks to system blocks. However, the capacity value passed
* to this routine is already in terms of system blocks (this scaling
* is done when the READ CAPACITY command is issued and processed).
* This 'error' may have gone undetected because the usage of g_ncyl
* (which is based upon g_capacity) is very limited within the driver
*/
/*
* Set ncyl to zero if the hba returned a zero nhead or nsect value. The
* hba may return zero values if the device has been removed.
*/
if (spc == 0) {
} else {
}
" ncyl: %ld; acyl: %d; nhead: %d; nsect: %d\n",
}
/*
* Function: sd_update_block_info
*
* Description: Calculate a byte count to sector count bitshift value
* from sector size.
*
* Arguments: un: unit struct.
* lbasize: new target sector size
* capacity: new target capacity, ie. block count
*
* Context: Kernel thread context
*/
static void
{
if (lbasize != 0) {
}
if (capacity != 0) {
}
}
static void
{
_NOTE(ASSUMING_PROTECTED(*e))
}
static void
{
int i;
_NOTE(ASSUMING_PROTECTED(*p))
for (i = 0; i < nparts; i++) {
p[i].efi_gpe_PartitionTypeGUID);
/* PartitionAttrs */
}
}
static int
{
return (EINVAL);
/* at least 96 bytes in this version of the spec. */
return (EINVAL);
/* this should be 128 bytes */
return (EINVAL);
return (0);
}
static int
{
int i;
int rval = 0;
goto done_err;
}
if (rval) {
goto done_err;
}
/* not ours */
goto done_err;
}
if (rval) {
goto done_err;
}
/*
* Couldn't read the primary, try the backup. Our
* capacity at this point could be based on CHS, so
* check what the device reports.
*/
if (rval) {
goto done_err;
}
/*
* The MMC standard allows READ CAPACITY to be
* inaccurate by a bounded amount (in the interest of
* response latency). As a result, failed READs are
* commonplace (due to the reading of metadata and not
* data). Depending on the per-Vendor/drive Sense data,
* the failed READ can cause many (unnecessary) retries.
*/
path_flag)) != 0) {
goto done_err;
}
/*
* Refer to comments related to off-by-1 at the
* header of this file. Search the next to last
* block for backup EFI label.
*/
path_flag)) != 0) {
goto done_err;
}
goto done_err;
}
"primary label corrupt; using backup\n");
}
if (rval) {
goto done_err;
}
}
/* Fill in partition table. */
for (i = 0; i < nparts; i++) {
if (partitions->efi_gpe_StartingLBA != 0 ||
partitions->efi_gpe_EndingLBA != 0) {
}
if (i == WD_NODE) {
/*
* minor number 7 corresponds to the whole disk
*/
}
partitions++;
}
un->un_solaris_offset = 0;
/* clear the vtoc label */
return (0);
/*
* if we didn't find something that could look like a VTOC
* and the disk is over 1TB, we know there isn't a valid label.
* Otherwise let sd_uselabel decide what to do. We only
* want to invalidate this if we're certain the label isn't
* valid because sd_prop_op will now fail, which in turn
* causes things like opens and stats on the partition to fail.
*/
}
return (rval);
}
/*
* Function: sd_uselabel
*
* Description: Validate the disk label and update the relevant data (geometry,
* partition, vtoc, and capacity data) in the sd_lun struct.
* Marks the geometry of the unit as being valid.
*
* Arguments: un: unit struct.
* dk_label: disk label
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: SD_LABEL_IS_VALID: Label read from disk is OK; geometry,
* partition, vtoc, and capacity data are good.
*
* SD_LABEL_IS_INVALID: Magic number or checksum error in the
* label; or computed capacity does not jibe with capacity
* reported from the READ CAPACITY command.
*
* Context: Kernel thread only (can sleep).
*/
static int
{
short *sp;
short sum;
short count;
int label_error = SD_LABEL_IS_VALID;
int i;
int capacity;
int part_end;
int track_capacity;
int err;
#if defined(_SUNOS_VTOC_16)
struct dkl_partition *vpartp;
#endif
/* Validate the magic number of the label. */
#if defined(__sparc)
"Corrupt label; wrong magic number\n");
}
#endif
return (SD_LABEL_IS_INVALID);
}
/* Validate the checksum of the label. */
sum = 0;
while (count--) {
}
if (sum != 0) {
#if defined(_SUNOS_VTOC_16)
#elif defined(_SUNOS_VTOC_8)
#endif
"Corrupt label - label checksum failed\n");
}
return (SD_LABEL_IS_INVALID);
}
/*
* Fill in geometry structure with data from label.
*/
#if defined(_SUNOS_VTOC_8)
#endif
#if defined(_SUNOS_VTOC_16)
#endif
#endif
/*
* Currently we rely on the values in the label being accurate. If
* dlk_rpm or dlk_pcly are zero in the label, use a default value.
*
* Note: In the future a MODE SENSE may be used to retrieve this data,
* although this command is optional in SCSI-2.
*/
/*
* The Read and Write reinstruct values may not be valid
* for older disks.
*/
/* Fill in partition table. */
#if defined(_SUNOS_VTOC_8)
for (i = 0; i < NDKMAP; i++) {
}
#endif
#if defined(_SUNOS_VTOC_16)
/* Prevent divide by zero */
if (track_capacity == 0) {
"Corrupt label - zero nhead or nsect value\n");
return (SD_LABEL_IS_INVALID);
}
}
#endif
/* Fill in VTOC Structure. */
#if defined(_SUNOS_VTOC_8)
/*
* The 8-slice vtoc does not include the ascii label; save it into
* the device's soft state structure here.
*/
#endif
/* Now look for a valid capacity. */
/* we may have > 1 alts cylinder */
#else
#endif
}
/*
* Force check here to ensure the computed capacity is valid.
* If capacity is zero, it indicates an invalid label and
* we should abort updating the relevant data then.
*/
if (capacity == 0) {
"Corrupt label - no valid capacity could be retrieved\n");
return (SD_LABEL_IS_INVALID);
}
/* Mark the geometry as valid. */
/*
* At this point, un->un_blockcount should contain valid data from
* the READ CAPACITY command.
*/
/*
* We have a situation where the target didn't give us a good
* READ CAPACITY value, yet there appears to be a valid label.
* In this case, we'll fake the capacity.
*/
goto done;
}
#if defined(_SUNOS_VTOC_8)
/*
* We can't let this happen on drives that are subdivided
* into logical disks (i.e., that have an fdisk table).
* The un_blockcount field should always hold the full media
* size in sectors, period. This code would overwrite
* un_blockcount with the size of the Solaris fdisk partition.
*/
"sd_uselabel: Label %d blocks; Drive %d blocks\n",
#endif /* defined(_SUNOS_VTOC_8) */
goto done;
}
/* For CDROMs, we trust that the data in the label is OK. */
#if defined(_SUNOS_VTOC_8)
for (i = 0; i < NDKMAP; i++) {
break;
}
}
#endif
#if defined(_SUNOS_VTOC_16)
break;
}
}
#endif
} else {
if (err == 0) {
}
"Corrupt label - bad geometry\n");
"Label says %u blocks; Drive says %llu blocks\n",
}
}
done:
" ncyl: %d; acyl: %d; nhead: %d; nsect: %d\n",
" lbasize: %d; capacity: %d; intrlv: %d; rpm: %d\n",
return (label_error);
}
/*
* Function: sd_build_default_label
*
* Description: Generate a default label for those devices that do not have
* one, e.g., new media, removable cartridges, etc..
*
* Context: Kernel thread only
*/
static void
{
#if defined(_SUNOS_VTOC_16)
#endif
#if defined(_SUNOS_VTOC_8)
/*
* Note: This is a legacy check for non-removable devices on VTOC_8
* only. This may be a valid check for VTOC_16 as well.
* Once we understand why there is this difference between SPARC and
* x86 platform, we could remove this legacy check.
*/
#endif
#if defined(_SUNOS_VTOC_8)
/*
* It's a REMOVABLE media, therefore no label (on sparc, anyway).
* But it is still necessary to set up various geometry information,
* and we are doing this here.
*/
/*
* For the rpm, we use the minimum for the disk. For the head, cyl,
* and number of sector per track, if the capacity <= 1GB, head = 64,
* sect = 32. else head = 255, sect 63 Note: the capacity should be
* equal to C*H*S values. This will cause some truncation of size due
* to round off errors. For CD-ROMs, this truncation can have adverse
* side effects, so returning ncyl and nhead as 1. The nsect will
* overflow for most of CD-ROMs as nsect is of type ushort. (4190569)
*/
/*
* Preserve the old behavior for non-writable
* medias. Since dkg_nsect is a ushort, it
* will lose bits as cdroms have more than
* 65536 sectors. So if we recalculate
* capacity, it will become much shorter.
* But the dkg_* information is not
* used for CDROMs so it is OK. But for
* Writable CDs we need this information
* to be valid (for newfs say). So we
* make nsect and nhead > 1 that way
* nsect can still stay within ushort limit
* without losing any bits.
*/
} else {
}
} else {
/* unlabeled SCSI floppy device */
} else {
}
un->un_blockcount =
}
#elif defined(_SUNOS_VTOC_16)
if (un->un_solaris_size == 0) {
/*
* Got fdisk table but no solaris entry therefore
* don't create a default label
*/
return;
}
/*
* For CDs we continue to use the physical geometry to calculate
* number of cylinders. All other devices must convert the
* physical geometry (geom_cache) to values that will fit
* in a dk_geom structure.
*/
} else {
/* Convert physical geometry to disk geometry */
/*
* Refer to comments related to off-by-1 at the
* header of this file.
* Before caculating geometry, capacity should be
* decreased by 1. That un_f_capacity_adjusted is
* TRUE means that we are treating a 1TB disk as
* (1T - 512)B. And the capacity of disks is already
* decreased by 1.
*/
if (!un->un_f_capacity_adjusted &&
!un->un_f_is_hotpluggable &&
else
}
/*
* CD's don't use the "heads * sectors * cyls"-type of
* geometry, but instead use the entire capacity of the media.
*/
} else {
/*
* Hard disks and removable media cartridges
*/
/* Add boot slice */
}
/* Add backup slice */
#else
#error "No VTOC format defined."
#endif
"sd_build_default_label: Default label created: "
"cyl: %d\tacyl: %d\tnhead: %d\tnsect: %d\tcap: %d\n",
}
#if defined(_FIRMWARE_NEEDS_FDISK)
/*
* Max CHS values, as they are encoded into bytes, for 1022/254/63
*/
#define LBA_MAX_HEAD (254)
/*
* Function: sd_has_max_chs_vals
*
* Description: Return TRUE if Cylinder-Head-Sector values are all at maximum.
*
* Arguments: fdp - ptr to CHS info
*
* Return Code: True or false
*
* Context: Any.
*/
static int
{
}
#endif
/*
* Function: sd_inq_fill
*
* Description: Print a piece of inquiry data, cleaned up for non-printable
* characters and stopping at the first space character after
* the beginning of the passed string;
*
* Arguments: p - source string
* l - maximum length to copy
* s - destination string
*
* Context: Any.
*/
static void
sd_inq_fill(char *p, int l, char *s)
{
unsigned i = 0;
char c;
while (i++ < l) {
if ((c = *p++) < ' ' || c >= 0x7F) {
c = '*';
} else if (i != 1 && c == ' ') {
break;
}
*s++ = c;
}
*s++ = 0;
}
/*
* Function: sd_register_devid
*
* Description: This routine will obtain the device id information from the
* target, obtain the serial number, and register the device
* id with the ddi framework.
*
* Arguments: devi - the system's dev_info_t for the device.
* un - driver soft state (unit) structure
* reservation_flag - indicates if a reservation conflict
* occurred during attach
*
* Context: Kernel Thread
*/
static void
{
int rval = 0;
size_t inq80_resid = 0;
size_t inq83_resid = 0;
/*
* This is the case of antiquated Sun disk drives that have the
* FAB_DEVID property set in the disk_table. These drives
* manage the devid's by storing them in last 2 available sectors
* on the drive and have them fabricated by the ddi layer by calling
* ddi_devid_init and passing the DEVID_FAB flag.
*/
/*
* Depending on EINVAL isn't reliable, since a reserved disk
* may result in invalid geometry, so check to make sure a
* reservation conflict did not occur during attach.
*/
/*
* The devid is invalid AND there is no reservation
* conflict. Fabricate a new devid.
*/
(void) sd_create_devid(un);
}
/* Register the devid if it exists */
"sd_register_devid: Devid Fabricated\n");
}
return;
}
/*
* We check the availibility of the World Wide Name (0x83) and Unit
* Serial Number (0x80) pages in sd_check_vpd_page_support(), and using
* un_vpd_page_mask from them, we decide which way to get the WWN. If
* 0x83 is availible, that is the best choice. Our next choice is
* 0x80. If neither are availible, we munge the devid from the device
* to fabricate a devid for non-Sun qualified disks.
*/
if (sd_check_vpd_page_support(un) == 0) {
/* collect page 80 data if available */
if (rval != 0) {
inq80_len = 0;
}
}
/* collect page 83 data if available */
if (rval != 0) {
inq83_len = 0;
}
}
}
/* encode best devid possible based on data available */
/* devid successfully encoded, register devid */
} else {
/*
* Unable to encode a devid based on data available.
* This is not a Sun qualified disk. Older Sun disk
* drives that have the SD_FAB_DEVID property
* set in the disk_table and non Sun qualified
* disks are treated in the same manner. These
* drives manage the devid's by storing them in
* last 2 available sectors on the drive and
* have them fabricated by the ddi layer by
* calling ddi_devid_init and passing the
* DEVID_FAB flag.
* Create a fabricate devid only if there's no
* fabricate devid existed.
*/
(void) sd_create_devid(un);
}
/* Register the devid if it exists */
"sd_register_devid: devid fabricated using "
"ddi framework\n");
}
}
/* clean up resources */
}
}
}
static daddr_t
{
/* this geometry doesn't allow us to write a devid */
return (-1);
}
/*
* Subtract 2 guarantees that the next to last cylinder
* is used
*/
} else {
} else {
return (-1);
}
}
return (blk);
}
/*
* Function: sd_get_devid
*
* Description: This routine will return 0 if a valid device id has been
* obtained from the target and stored in the soft state. If a
* valid device id has not been previously read and stored, a
* read attempt will be made.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: 0 if we successfully get the device id
*
* Context: Kernel Thread
*/
static int
{
int status;
int chksum;
int i;
un);
return (0);
}
if (blk < 0)
return (EINVAL);
/*
* Read and verify device id, stored in the reserved cylinders at the
* end of the disk. Backup label is on the odd sectors of the last
* track of the last cylinder. Device id will be on track of the next
* to last cylinder.
*/
if (status != 0) {
goto error;
}
/* Validate the revision */
goto error;
}
/* Calculate the checksum */
chksum = 0;
for (i = 0; i < ((un->un_sys_blocksize - sizeof (int))/sizeof (int));
i++) {
}
/* Compare the checksums */
goto error;
}
/* Validate the device id */
goto error;
}
/*
* Store the device id in the driver soft state
*/
return (status);
return (status);
}
/*
* Function: sd_create_devid
*
* Description: This routine will fabricate the device id and write it
* to the disk.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: value of the fabricated device id
*
* Context: Kernel Thread
*/
static ddi_devid_t
{
/* Fabricate the devid */
== DDI_FAILURE) {
return (NULL);
}
/* Write the devid to disk */
if (sd_write_deviceid(un) != 0) {
}
}
/*
* Function: sd_write_deviceid
*
* Description: This routine will write the device id to the disk
* reserved sector.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: EINVAL
* value returned by sd_send_scsi_cmd
*
* Context: Kernel Thread
*/
static int
{
int status;
int i;
if (blk < 0)
return (-1);
/* Allocate the buffer */
/* Fill in the revision */
/* Copy in the device id */
/* Calculate the checksum */
chksum = 0;
for (i = 0; i < ((un->un_sys_blocksize - sizeof (int))/sizeof (int));
i++) {
}
/* Fill-in checksum */
/* Write the reserved sector */
return (status);
}
/*
* Function: sd_check_vpd_page_support
*
* Description: This routine sends an inquiry command with the EVPD bit set and
* a page code of 0x00 to the device. It is used to determine which
* vital product pages are availible to find the devid. We are
* looking for pages 0x83 or 0x80. If we return a negative 1, the
* device does not support that command.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: 0 - success
* 1 - check condition
*
* Context: This routine can sleep.
*/
static int
{
int rval = 0;
int counter;
/*
* We'll set the page length to the maximum to save figuring it out
* with an additional call.
*/
/*
* Now we must validate that the device accepted the command, as some
* drives do not support it. If the drive does support it, we will
* return 0, and the supported pages will be in un_vpd_page_mask. If
* not, we return -1.
*/
/* Loop to find one of the 2 pages we need */
/*
* Pages are returned in ascending order, and 0x83 is what we
* are hoping for.
*/
VPD_HEAD_OFFSET))) {
/*
* Add 3 because page_list[3] is the number of
* pages minus 3
*/
case 0x00:
break;
case 0x80:
break;
case 0x81:
break;
case 0x82:
break;
case 0x83:
break;
}
counter++;
}
} else {
rval = -1;
"sd_check_vpd_page_support: This drive does not implement "
"VPD pages.\n");
}
return (rval);
}
/*
* Function: sd_setup_pm
*
* Description: Initialize Power Management on the device
*
* Context: Kernel Thread
*/
static void
{
int rval;
/*
* Since we are called from attach, holding a mutex for
* un is unnecessary. Because some of the routines called
* from here require SD_MUTEX to not be held, assert this
* right up front.
*/
/*
* Since the sd device does not have the 'reg' property,
* cpr will not call its DDI_SUSPEND/DDI_RESUME entries.
* The following code is to tell cpr that this device
* DOES need to be suspended and resumed.
*/
"pm-hardware-state", "needs-suspend-resume");
/*
* This complies with the new power management framework
* for certain desktop machines. Create the pm_components
* property as a string array property.
*/
if (un->un_f_pm_supported) {
/*
* not all devices have a motor, try it first.
* some devices may return ILLEGAL REQUEST, some
* will hang
* The following START_STOP_UNIT is used to check if target
* device has a motor.
*/
SD_PATH_DIRECT) != 0) {
}
/*
* create pm properties anyways otherwise the parent can't
* go to sleep
*/
return;
}
if (!un->un_f_log_sense_supported) {
return;
}
#ifdef SDDEBUG
if (sd_force_pm_supported) {
/* Force a successful result */
rval = 1;
}
#endif
/*
* If the start-stop cycle counter log page is not supported
* or if the pm-capable property is SD_PM_CAPABLE_FALSE (0)
* then we should not create the pm_components property.
*/
if (rval == -1) {
/*
* Error.
* Reading log sense failed, most likely this is
* an older drive that does not support log sense.
* If this fails auto-pm is not supported.
*/
} else if (rval == 0) {
/*
* Page not found.
* The start stop cycle counter is implemented as page
* START_STOP_CYCLE_PAGE_VU_PAGE (0x31) in older disks. For
* newer disks it is implemented as START_STOP_CYCLE_PAGE (0xE).
*/
/*
* Page found, use this one.
*/
} else {
/*
* Error or page not found.
* auto-pm is not supported for this device.
*/
}
} else {
/*
* Page found, use it.
*/
}
0x01, 0, SD_PATH_DIRECT);
#ifdef SDDEBUG
if (sd_force_pm_supported) {
/* Force a successful result */
rval = 0;
}
#endif
/*
* succeeds, then power managment is supported and we can
* enable auto-pm.
*/
if (rval == 0) {
} else {
}
}
}
/*
* Function: sd_create_pm_components
*
* Description: Initialize PM property.
*
* Context: Kernel thread context
*/
static void
{
/*
* When components are initially created they are idle,
* power up any non-removables.
* Note: the return value of pm_raise_power can't be used
* for determining if PM should be enabled for this device.
* Even if you check the return values and remove this
* property created above, the PM framework will not honor the
* change after the first call to pm_raise_power. Hence,
* removal of that property does not help if pm_raise_power
* will fail if the media is not present.
*/
SD_SPINDLE_ON) == DDI_SUCCESS)) {
/* Set to on and not busy. */
un->un_pm_count = 0;
} else {
/* Set to off. */
}
} else {
}
}
/*
* Function: sd_ddi_suspend
*
* Description: Performs system power-down operations. This includes
* setting the drive state to indicate its suspended so
* that no new commands will be accepted. Also, wait for
* all commands that are in transport or queued to a timer
* for retry to complete. All timeout threads are cancelled.
*
* Return Code: DDI_FAILURE or DDI_SUCCESS
*
* Context: Kernel thread context
*/
static int
{
return (DDI_FAILURE);
}
/* Return success if the device is already suspended. */
"device already suspended, exiting\n");
return (DDI_SUCCESS);
}
/* Return failure if the device is being used by HA */
if (un->un_resvd_status &
"device in use by HA, exiting\n");
return (DDI_FAILURE);
}
/*
* Return failure if the device is in a resource wait
* or power changing state.
*/
"device in resource wait state, exiting\n");
return (DDI_FAILURE);
}
/*
* Wait for all commands that are in transport or queued to a timer
* for retry to complete.
*
* While waiting, no new commands will be accepted or sent because of
* the new state we set above.
*
* Wait till current operation has completed. If we are in the resource
* wait state (with an intr outstanding) then we need to wait till the
* intr completes and starts the next cmd. We want to wait for
* SD_WAIT_CMDS_COMPLETE seconds before failing the DDI_SUSPEND.
*/
while (un->un_ncmds_in_transport != 0) {
/*
* Fail if commands do not finish in the specified time.
*/
wait_cmds_complete) == -1) {
/*
* Undo the state changes made above. Everything
* must go back to it's original value.
*/
/* Wake up any threads that might be waiting. */
"sd_ddi_suspend: failed due to outstanding cmds\n");
return (DDI_FAILURE);
}
}
/*
* Cancel SCSI watch thread and timeouts, if any are active
*/
if (SD_OK_TO_SUSPEND_SCSI_WATCHER(un)) {
}
}
}
} else {
}
}
}
/*
* Remove callbacks for insert and remove events
*/
}
}
}
return (DDI_SUCCESS);
}
/*
* Function: sd_ddi_pm_suspend
*
* Description: Set the drive state to low power.
* Someone else is required to actually change the drive
* power level.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: DDI_FAILURE or DDI_SUCCESS
*
* Context: Kernel thread context
*/
static int
{
/*
* Exit if power management is not enabled for this device, or if
* the device is being used by HA.
*/
return (DDI_SUCCESS);
}
/*
* See if the device is not busy, ie.:
* - we have no commands in the driver for this device
* - not waiting for resources
*/
if ((un->un_ncmds_in_driver == 0) &&
/*
* The device is not busy, so it is OK to go to low power state.
* Indicate low power, but rely on someone else to actually
* change it.
*/
}
return (DDI_SUCCESS);
}
/*
* Function: sd_ddi_resume
*
* Description: Performs system power-up operations..
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
return (DDI_FAILURE);
}
/*
* Restore the state which was saved to give the
* the right state in un_last_state
*/
/*
* Note: throttle comes back at full.
* Also note: this MUST be done before calling pm_raise_power
* otherwise the system can get hung in biowait. The scenario where
* this'll happen is under cpr suspend. Writing of the system
* state goes through sddump, which writes 0 to un_throttle. If
* writing the system state then fails, example if the partition is
* too small, then cpr attempts a resume. If throttle isn't restored
* from the saved value until after calling pm_raise_power then
* cmds sent in sdpower are not transported and sd_send_scsi_cmd hangs
* in biowait.
*/
/*
* The chance of failure is very rare as the only command done in power
* entry point is START command when you transition from 0->1 or
* unknown->1. Put it to SPINDLE ON state irrespective of the state at
* which suspend was done. Ignore the return value as the resume should
* not be failed. In the case of removable media the media need not be
* inserted and hence there is a chance that raise power will fail with
* media not present.
*/
if (un->un_f_attach_spinup) {
}
/*
* Don't broadcast to the suspend cv and therefore possibly
* start I/O until after power has been restored.
*/
/* restart thread */
if (SD_OK_TO_RESUME_SCSI_WATCHER(un)) {
}
#if (defined(__fibre))
/*
* Add callbacks for insert and remove events
*/
}
}
#endif
/*
* Transport any pending commands to the target.
*
* If this is a low-activity device commands in queue will have to wait
* until new commands come in, which may take awhile. Also, we
* specifically don't check un_ncmds_in_transport because we know that
* there really are no commands in progress after the unit was
* suspended and we could have reached the throttle level, been
* suspended, and have no new commands coming in for awhile. Highly
* unlikely, but so is the low-activity disk scenario.
*/
return (DDI_SUCCESS);
}
/*
* Function: sd_ddi_pm_resume
*
* Description: Set the drive state to powered on.
* Someone else is required to actually change the drive
* power level.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: DDI_SUCCESS
*
* Context: Kernel thread context
*/
static int
{
if (SD_DEVICE_IS_IN_LOW_POWER(un)) {
un->un_pm_count++;
/*
* Note: no longer do the cv_broadcast on un_suspend_cv. The
* un_suspend_cv is for a system resume, not a power management
* device resume. (4297749)
* cv_broadcast(&un->un_suspend_cv);
*/
}
return (DDI_SUCCESS);
}
/*
* Function: sd_pm_idletimeout_handler
*
* Description: A timer routine that's active only while a device is busy.
* The purpose is to extend slightly the pm framework's busy
* back-to-back commands. Do this by comparing the current time
* to the time at which the last command completed and when the
* difference is greater than sd_pm_idletime, call
* pm_idle_component. In addition to indicating idle to the pm
* framework, update the chain type to again use the internal pm
* layers of the driver.
*
* Arguments: arg - driver soft state (unit) structure
*
* Context: Executes in a timeout(9F) thread context
*/
static void
sd_pm_idletimeout_handler(void *arg)
{
if (un->un_detach_count != 0) {
/* Abort if the instance is detaching */
return;
}
now = ddi_get_time();
/*
* Grab both mutexes, in the proper order, since we're accessing
* both PM and softstate variables.
*/
/*
* Update the chain types.
* This takes affect on the next new command received.
*/
if (un->un_f_non_devbsize_supported) {
} else {
}
"sd_pm_idletimeout_handler: idling device\n");
} else {
}
}
/*
* Function: sd_pm_timeout_handler
*
* Description: Callback to tell framework we are idle.
*
* Context: timeout(9f) thread context.
*/
static void
sd_pm_timeout_handler(void *arg)
{
}
/*
* Function: sdpower
*
* Description: PM entry point.
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
int instance;
int rval = DDI_SUCCESS;
int log_sense_page;
int medium_present;
struct pm_trans_data sd_pm_tran_data;
int sval;
int got_semaphore_here;
component != 0) {
return (DDI_FAILURE);
}
/*
* Must synchronize power down with close.
* but do NOT wait on it. If it's not greater than zero,
* ie. it can't be decremented without waiting, then
* someone else, either open or close, already has it
* and the try returns 0. Use that knowledge here to determine
* if it's OK to change the device power level.
* Also, only increment it on exit if it was decremented, ie. gotten,
* here.
*/
/*
* If un_ncmds_in_driver is non-zero it indicates commands are
* already being processed in the driver, or if the semaphore was
* not gotten here it indicates an open or close is being processed.
* At the same time somebody is requesting to go low power which
* can't happen, therefore we need to return failure.
*/
if ((level == SD_SPINDLE_OFF) &&
if (got_semaphore_here != 0) {
}
"sdpower: exit, device has queued cmds.\n");
return (DDI_FAILURE);
}
/*
* if it is OFFLINE that means the disk is completely dead
* in our case we have to put the disk in on or off by sending commands
* Of course that will fail anyway so return back here.
*
* Power changes to a device that's OFFLINE or SUSPENDED
* are not allowed.
*/
if (got_semaphore_here != 0) {
}
"sdpower: exit, device is off-line.\n");
return (DDI_FAILURE);
}
/*
* Change the device's state to indicate it's power level
* is being changed. Do this to prevent a power off in the
* middle of commands, which is especially bad on devices
* that are really powered off instead of just spun down.
*/
/*
* If "pm-capable" property is set to TRUE by HBA drivers,
* bypass the following checking, otherwise, check the log
* sense information for this device
*/
/*
* Get the log sense information to understand whether the
* the powercycle counts have gone beyond the threshhold.
*/
#ifdef SDDEBUG
if (sd_force_pm_supported) {
/* Force a successful result */
rval = 0;
}
#endif
if (rval != 0) {
"Log Sense Failed\n");
/* Cannot support power management on those drives */
if (got_semaphore_here != 0) {
}
/*
* On exit put the state back to it's original value
* and broadcast to anyone waiting for the power
* change completion.
*/
"sdpower: exit, Log Sense Failed.\n");
return (DDI_FAILURE);
}
/*
* From the page data - Convert the essential information to
* pm_trans_data
*/
ncycles =
for (i = 0; i < DC_SCSI_MFR_LEN; i++) {
log_page_data[8+i];
}
/*
* Call pm_trans_check routine to get the Ok from
* the global policy
*/
#ifdef SDDEBUG
if (sd_force_pm_supported) {
/* Force a successful result */
rval = 1;
}
#endif
switch (rval) {
case 0:
/*
* Not Ok to Power cycle or error in parameters passed
* Would have given the advised time to consider power
* cycle. Based on the new intvlp parameter we are
* supposed to pretend we are busy so that pm framework
* will never call our power entry point. Because of
* that install a timeout handler and wait for the
* recommended time to elapse so that power management
* can be effective again.
*
* To effect this behavior, call pm_busy_component to
* indicate to the framework this device is busy.
* By not adjusting un_pm_count the rest of PM in
* the driver will function normally, and independant
* of this but because the framework is told the device
* is busy it won't attempt powering down until it gets
* a matching idle. The timeout handler sends this.
* Note: sd_pm_entry can't be called here to do this
* because sdpower may have been called as a result
* of a call to pm_raise_power from within sd_pm_entry.
*
* If a timeout handler is already active then
* don't install another.
*/
un->un_pm_timeid =
} else {
}
if (got_semaphore_here != 0) {
}
/*
* On exit put the state back to it's original value
* and broadcast to anyone waiting for the power
* change completion.
*/
"trans check Failed, not ok to power cycle.\n");
return (DDI_FAILURE);
case -1:
if (got_semaphore_here != 0) {
}
/*
* On exit put the state back to it's original value
* and broadcast to anyone waiting for the power
* change completion.
*/
"sdpower: exit, trans check command Failed.\n");
return (DDI_FAILURE);
}
}
if (level == SD_SPINDLE_OFF) {
/*
* Save the last state... if the STOP FAILS we need it
* for restoring
*/
/*
* There must not be any cmds. getting processed
* in the driver when we get here. Power to the
* device is potentially going off.
*/
/*
* For now suspend the device completely before spindle is
* turned off
*/
if (got_semaphore_here != 0) {
}
/*
* On exit put the state back to it's original value
* and broadcast to anyone waiting for the power
* change completion.
*/
"sdpower: exit, PM suspend Failed.\n");
return (DDI_FAILURE);
}
}
/*
* The transition from SPINDLE_OFF to SPINDLE_ON can happen in open,
* close, or strategy. Dump no long uses this routine, it uses it's
* own code so it can be done in polled mode.
*/
/*
* When powering up, issue a TUR in case the device is at unit
* attention. Don't do retries. Bypass the PM layer, otherwise
* a deadlock on un_pm_busy_cv will occur.
*/
if (level == SD_SPINDLE_ON) {
(void) sd_send_scsi_TEST_UNIT_READY(un,
}
/* Command failed, check for media present. */
}
/*
* The conditions of interest here are:
* if a spindle off with media present fails,
* then restore the state and return an error.
* else if a spindle on fails,
* then return an error (there's no state to restore).
* In all other cases we setup for the new state
* and return success.
*/
switch (level) {
case SD_SPINDLE_OFF:
/* The stop command from above failed */
rval = DDI_FAILURE;
/*
* The stop command failed, and we have media
* present. Put the level back by calling the
* sd_pm_resume() and set the state back to
* it's previous value.
*/
(void) sd_ddi_pm_resume(un);
break;
}
/*
* The stop command from above succeeded.
*/
if (un->un_f_monitor_media_state) {
/*
* Terminate watch thread in case of removable media
* devices going into low power state. This is as per
* the requirements of pm framework, otherwise commands
* will be generated for the device (through watch
* thread), even when the device is in low power state.
*/
} else {
}
}
break;
default: /* The level requested is spindle on... */
/*
* Legacy behavior: return success on a failed spinup
* if there is no media in the drive.
* Do this by looking at medium_present here.
*/
if ((sval != 0) && medium_present) {
/* The start command from above failed */
rval = DDI_FAILURE;
break;
}
/*
* The start command from above succeeded
* Resume the devices now that we have
* started the disks
*/
(void) sd_ddi_pm_resume(un);
/*
* Resume the watch thread since it was suspended
* when the device went into low power mode.
*/
if (un->un_f_monitor_media_state) {
}
}
}
if (got_semaphore_here != 0) {
}
/*
* On exit put the state back to it's original value
* and broadcast to anyone waiting for the power
* change completion.
*/
return (rval);
}
/*
* Function: sdattach
*
* Description: Driver's attach(9e) entry point function.
*
* Arguments: devi - opaque device info handle
* cmd - attach type
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
switch (cmd) {
case DDI_ATTACH:
return (sd_unit_attach(devi));
case DDI_RESUME:
return (sd_ddi_resume(devi));
default:
break;
}
return (DDI_FAILURE);
}
/*
* Function: sddetach
*
* Description: Driver's detach(9E) entry point function.
*
* Arguments: devi - opaque device info handle
* cmd - detach type
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
switch (cmd) {
case DDI_DETACH:
return (sd_unit_detach(devi));
case DDI_SUSPEND:
return (sd_ddi_suspend(devi));
default:
break;
}
return (DDI_FAILURE);
}
/*
* Function: sd_sync_with_callback
*
* Description: Prevents sd_unit_attach or sd_unit_detach from freeing the soft
* state while the callback routine is active.
*
* Arguments: un: softstate structure for the instance
*
* Context: Kernel thread context
*/
static void
{
while (un->un_in_callback > 0) {
delay(2);
}
}
/*
* Function: sd_unit_attach
*
* Description: Performs DDI_ATTACH processing for sdattach(). Allocates
* the soft state structure for the device and performs
* all necessary structure and device initializations.
*
* Arguments: devi: the system's dev_info_t for the device.
*
* Return Code: DDI_SUCCESS if attach is successful.
* DDI_FAILURE if any part of the attach fails.
*
* Context: Called at attach(9e) time for the DDI_ATTACH flag.
* Kernel thread context only. Can sleep.
*/
static int
{
struct scsi_device *devp;
char *variantp;
int instance;
int rval;
int wc_enabled;
/*
* Retrieve the target driver's private data area. This was set
* up by the HBA.
*/
/*
* Since we have no idea what state things were left in by the last
* user of the device, set up some 'default' settings, ie. turn 'em
* off. The scsi_ifsetcap calls force re-negotiations with the drive.
* Do this before the scsi_probe, which sends an inquiry.
* This is a fix for bug (4430280).
* Of special importance is wide-xfer. The drive could have been left
* in wide transfer mode by the last driver to communicate with it,
* this includes us. If that's the case, and if the following is not
* setup properly or we don't re-negotiate with the drive prior to
* data overruns, and unexpected interrupts. This first occurred when
* the fix for bug (4378686) was made.
*/
/*
* Use scsi_probe() to issue an INQUIRY command to the device.
* This call will allocate and fill in the scsi_inquiry structure
* and point the sd_inq member of the scsi_device structure to it.
* If the attach succeeds, then this memory will not be de-allocated
* (via scsi_unprobe()) until the instance is detached.
*/
goto probe_failed;
}
/*
* Check the device type as specified in the inquiry data and
* claim it if it is of a type that we support.
*/
case DTYPE_DIRECT:
break;
case DTYPE_RODIRECT:
break;
case DTYPE_OPTICAL:
break;
case DTYPE_NOTPRESENT:
default:
/* Unsupported device type; fail the attach. */
goto probe_failed;
}
/*
* Allocate the soft state structure for this unit.
*
* We rely upon this memory being set to all zeroes by
* ddi_soft_state_zalloc(). We assume that any member of the
* soft state structure that is not explicitly initialized by
* this routine will have a value of zero.
*/
goto probe_failed;
}
/*
* Retrieve a pointer to the newly-allocated soft state.
*
* This should NEVER fail if the ddi_soft_state_zalloc() call above
* was successful, unless something has gone horribly wrong and the
* ddi's soft state internals are corrupt (in which case it is
* probably better to halt here than just fail the attach....)
*/
panic("sd_unit_attach: NULL soft state on instance:0x%x",
instance);
/*NOTREACHED*/
}
/*
* Link the back ptr of the driver soft state to the scsi_device
* struct for this lun.
* Save a pointer to the softstate in the driver-private area of
* the scsi_device struct.
* Note: We cannot call SD_INFO, SD_TRACE, SD_ERROR, or SD_DIAG until
* we first set un->un_sd below.
*/
/*
* The following must be after devp is stored in the soft state struct.
*/
#ifdef SDDEBUG
"%s_unit_attach: un:0x%p instance:%d\n",
#endif
/*
* Set up the device type and node type (for the minor nodes).
* By default we assume that the device can at least support the
* Common Command Set. Call it a CD-ROM if it reports itself
* as a RODIRECT device.
*/
case DTYPE_RODIRECT:
break;
case DTYPE_OPTICAL:
break;
default:
break;
}
/*
* Try to read the interconnect type from the HBA.
*
* Note: This driver is currently compiled as two binaries, a parallel
* scsi version (sd) and a fibre channel version (ssd). All functional
* differences are determined at compile time. In the future a single
* binary will be provided and the inteconnect type will be used to
* differentiate between fibre and parallel scsi behaviors. At that time
* it will be necessary for all fibre channel HBAs to support this
* property.
*
* set un_f_is_fiber to TRUE ( default fiber )
*/
case INTERCONNECT_SSA:
"sd_unit_attach: un:0x%p SD_INTERCONNECT_SSA\n", un);
break;
case INTERCONNECT_PARALLEL:
"sd_unit_attach: un:0x%p SD_INTERCONNECT_PARALLEL\n", un);
break;
case INTERCONNECT_SATA:
"sd_unit_attach: un:0x%p SD_INTERCONNECT_SATA\n", un);
break;
case INTERCONNECT_FIBRE:
"sd_unit_attach: un:0x%p SD_INTERCONNECT_FIBRE\n", un);
break;
case INTERCONNECT_FABRIC:
"sd_unit_attach: un:0x%p SD_INTERCONNECT_FABRIC\n", un);
break;
default:
#ifdef SD_DEFAULT_INTERCONNECT_TYPE
/*
* The HBA does not support the "interconnect-type" property
* (or did not provide a recognized type).
*
* Note: This will be obsoleted when a single fibre channel
* and parallel scsi driver is delivered. In the meantime the
* interconnect type will be set to the platform default.If that
* type is not parallel SCSI, it means that we should be
* assuming "ssd" semantics. However, here this also means that
* the FC HBA is not supporting the "interconnect-type" property
* like we expect it to, so log this occurrence.
*/
if (!SD_IS_PARALLEL_SCSI(un)) {
"sd_unit_attach: un:0x%p Assuming "
"INTERCONNECT_FIBRE\n", un);
} else {
"sd_unit_attach: un:0x%p Assuming "
"INTERCONNECT_PARALLEL\n", un);
}
#else
/*
* Note: This source will be implemented when a single fibre
* channel and parallel scsi driver is delivered. The default
* will be to assume that if a device does not support the
* "interconnect-type" property it is a parallel SCSI HBA and
* we will set the interconnect type for parallel scsi.
*/
#endif
break;
}
switch (un->un_interconnect_type) {
case SD_INTERCONNECT_FIBRE:
case SD_INTERCONNECT_SSA:
break;
default:
break;
}
}
}
/*
* Initialize the Request Sense command for the target
*/
goto alloc_rqs_failed;
}
/*
* Set un_retry_count with SD_RETRY_COUNT, this is ok for Sparc
* with seperate binary for sd and ssd.
*
* x86 has 1 binary, un_retry_count is set base on connection type.
* The hardcoded values will go away when Sparc uses 1 binary
* for sd and ssd. This hardcoded values need to match
* SD_RETRY_COUNT in sddef.h
* The value used is base on interconnect type.
* fibre = 3, parallel = 5
*/
#else
#endif
/*
* Set the per disk retry count to the default number of retries
* for disks and CDROMs. This value can be overridden by the
* disk property list or an entry in sd.conf.
*/
/*
* Set the busy retry count to the default value of un_retry_count.
* This can be overridden by entries in sd.conf or the device
* config table.
*/
/*
* Init the reset threshold for retries. This number determines
* how many retries must be performed before a reset can be issued
* (for certain error conditions). This can be overridden by entries
* in sd.conf or the device config table.
*/
/*
* Set the victim_retry_count to the default un_retry_count
*/
/*
* Set the reservation release timeout to the default value of
* 5 seconds. This can be overridden by entries in ssd.conf or the
* device config table.
*/
/*
* Set up the default maximum transfer size. Note that this may
* get updated later in the attach, when setting up default wide
* operations for disks.
*/
#else
#endif
/*
* Get "allow bus device reset" property (defaults to "enabled" if
* the property was not defined). This is to disable bus resets for
* certain kinds of error recovery. Note: In the future when a run-time
* fibre check is available the soft state flag should default to
* enabled.
*/
} else {
"allow-bus-device-reset", 1) != 0) {
"sd_unit_attach: un:0x%p Bus device reset enabled\n",
un);
} else {
"sd_unit_attach: un:0x%p Bus device reset disabled\n",
un);
}
}
/*
* Check if this is an ATAPI device. ATAPI devices use Group 1
*
* Note: The "obsolete" way of doing this is to check for the "atapi"
* property. The new "variant" property with a value of "atapi" has been
* introduced so that future 'variants' of standard SCSI behavior (like
* atapi) could be specified by the underlying HBA drivers by supplying
* a new value for the "variant" property, instead of having to define a
* new property.
*/
"sd_unit_attach: un:0x%p Atapi device\n", un);
}
&variantp) == DDI_PROP_SUCCESS) {
"sd_unit_attach: un:0x%p Atapi device\n", un);
}
}
/* Info on current states, statuses, etc. (Updated frequently) */
/* Control & status info for command throttling */
} else {
}
/* Removable media support. */
/* Power management support. */
un->un_f_wcc_inprog = 0;
/*
* in the driver's open & close entry point routines for a given
* instance.
*/
/*
* The conf file entry and softstate variable is a forceful override,
* meaning a non-zero value must be entered to change the default.
*/
/*
* Retrieve the properties from the static driver table or the driver
* configuration file (.conf) for this unit and update the soft state
* for the device as needed for the indicated properties.
* Note: the property configuration needs to occur here as some of the
* following routines may have dependancies on soft state flags set
* as part of the driver property configuration.
*/
"sd_unit_attach: un:0x%p property configuration complete.\n", un);
/*
* Only if a device has "hotpluggable" property, it is
* treated as hotpluggable device. Otherwise, it is
* regarded as non-hotpluggable one.
*/
-1) != -1) {
}
/*
* set unit's attributes(flags) according to "hotpluggable" and
* RMB bit in INQUIRY data.
*/
/*
* By default, we mark the capacity, lbasize, and geometry
* as invalid. Only if we successfully read a valid capacity
* will we update the un_blockcount and un_tgt_blocksize with the
* valid values (the geometry will be validated later).
*/
/*
* Use DEV_BSIZE and DEV_BSHIFT as defaults, until we can determine
* otherwise.
*/
un->un_blockcount = 0;
/*
* Set up the per-instance info needed to determine the correct
* CDBs and other info for issuing commands to the target.
*/
/*
* Set up the IO chains to use, based upon the target type.
*/
if (un->un_f_non_devbsize_supported) {
} else {
}
} else {
}
/*
* Create the kstats here so they can be available for attach-time
* routines that send commands to the unit (either polled or via
* sd_send_scsi_cmd).
*
* Note: This is a critical sequence that needs to be maintained:
* 1) Instantiate the kstats here, before any routines using the
* iopath (i.e. sd_send_scsi_cmd).
* 2) Initialize the error stats (sd_set_errstats) and partition
* stats (sd_set_pstats), following sd_validate_geometry(),
* sd_register_devid(), and sd_cache_control().
*/
}
"sd_unit_attach: un:0x%p un_stats created\n", un);
"sd_unit_attach: un:0x%p errstats created\n", un);
/*
* of the fix for bug (4430280). However with the default setup added
* on entry to this routine, it's no longer absolutely necessary for
* this to be before the call to sd_spin_up_unit.
*/
/*
* If SCSI-2 tagged queueing is supported by the target
* and by the host adapter then we will enable it.
*/
un->un_tagflags = 0;
1, 1) == 1) {
"sd_unit_attach: un:0x%p tag queueing "
"enabled\n", un);
"untagged-qing", 0) == 1) {
} else {
}
/* The Host Adapter supports internal queueing. */
} else {
"sd_unit_attach: un:0x%p no tag queueing\n", un);
}
/*
*/
if (SD_IS_SERIAL(un)) {
"sd_unit_attach: un:0x%p max transfer "
}
/* Setup or tear down default wide operations for disks */
/*
* Note: Legacy: it may be possible for both "sd_max_xfer_size"
* and "ssd_max_xfer_size" to exist simultaneously on the same
* system and be set to different values. In the future this
* code may need to be updated when the ssd module is
* obsoleted and removed from the system. (4299588)
*/
if (SD_IS_PARALLEL_SCSI(un) &&
1, 1) == 1) {
"sd_unit_attach: un:0x%p Wide Transfer "
"enabled\n", un);
}
/*
* If tagged queuing has also been enabled, then
* enable large xfers
*/
"sd_unit_attach: un:0x%p max transfer "
}
} else {
0, 1) == 1) {
"sd_unit_attach: un:0x%p "
"Wide Transfer disabled\n", un);
}
}
} else {
}
/*
* If this target supports LUN reset, try to enable it.
*/
if (un->un_f_lun_reset_enabled) {
"un:0x%p lun_reset capability set\n", un);
} else {
"un:0x%p lun-reset capability not set\n", un);
}
}
/*
* At this point in the attach, we have enough info in the
* soft state to be able to issue commands to the target.
*
* All command paths used below MUST issue their commands as
* SD_PATH_DIRECT. This is important as intermediate layers
* are not all initialized yet (such as PM).
*/
/*
* Send a TEST UNIT READY command to the device. This should clear
* any outstanding UNIT ATTENTION that may be present.
*
* Note: Don't check for success, just track if there is a reservation,
* this is a throw away command to clear any unit attentions.
*
* Note: This MUST be the first command issued to the target during
* attach to ensure power on UNIT ATTENTIONS are cleared.
* Pass in flag SD_DONT_RETRY_TUR to prevent the long delays associated
* with attempts at spinning up a device with no media.
*/
}
/*
* If the device is NOT a removable media device, attempt to spin
* it up (using the START_STOP_UNIT command) and read its capacity
* (using the READ CAPACITY command). Note, however, that either
* of these could fail and in some cases we would continue with
* the attach despite the failure (see below).
*/
if (un->un_f_descr_format_supported) {
switch (sd_spin_up_unit(un)) {
case 0:
/*
* Spin-up was successful; now try to read the
* capacity. If successful then save the results
* and mark the capacity & lbasize as valid.
*/
"sd_unit_attach: un:0x%p spin-up successful\n", un);
&lbasize, SD_PATH_DIRECT)) {
case 0: {
if (capacity > DK_MAX_BLOCKS) {
#ifdef _LP64
if (capacity + 1 >
/*
* Enable descriptor format
* sense data so that we can
* get 64 bit sense data
* fields.
*/
}
#else
/* 32-bit kernels can't handle this */
"disk has %llu blocks, which "
"is too large for a 32-bit "
"kernel", capacity);
/*
* Refer to comments related to off-by-1
* at the header of this file.
* 1TB disk was treated as (1T - 512)B
* in the past, so that it might has
* valid VTOC and solaris partitions,
* we have to allow it to continue to
* work.
*/
#endif
goto spinup_failed;
#endif
}
/*
* Here it's not necessary to check the case:
* the capacity of the device is bigger than
* what the max hba cdb can support. Because
* sd_send_scsi_READ_CAPACITY will retrieve
* the capacity by sending USCSI command, which
* is constrained by the max hba cdb. Actually,
* sd_send_scsi_READ_CAPACITY will return
* EINVAL when using bigger cdb than required
* cdb length. Will handle this case in
* "case EINVAL".
*/
/*
* The following relies on
* sd_send_scsi_READ_CAPACITY never
*/
"sd_unit_attach: un:0x%p capacity = %ld "
"blocks; lbasize= %ld.\n", un,
break;
}
case EINVAL:
/*
* In the case where the max-cdb-length property
* is smaller than the required CDB length for
* a SCSI device, a target driver can fail to
* attach to that device.
*/
"disk capacity is too large "
"for current cdb length");
goto spinup_failed;
case EACCES:
/*
* Should never get here if the spin-up
* succeeded, but code it in anyway.
* From here, just continue with the attach...
*/
"sd_unit_attach: un:0x%p "
"sd_send_scsi_READ_CAPACITY "
"returned reservation conflict\n", un);
break;
default:
/*
* Likewise, should never get here if the
* spin-up succeeded. Just continue with
* the attach...
*/
break;
}
break;
case EACCES:
/*
* Device is reserved by another host. In this case
* we could not spin it up or read the capacity, but
* we continue with the attach anyway.
*/
"sd_unit_attach: un:0x%p spin-up reservation "
"conflict.\n", un);
break;
default:
/* Fail the attach if the spin-up failed. */
"sd_unit_attach: un:0x%p spin-up failed.", un);
goto spinup_failed;
}
}
/*
* Check to see if this is a MMC drive
*/
}
/*
* Create the minor nodes for the device.
* Note: If we want to support fdisk on both sparc and intel, this will
* have to separate out the notion that VTOC8 is always sparc, and
* VTOC16 is always intel (tho these can be the defaults). The vtoc
* type will have to be determined at run-time, and the fdisk
* partitioning will have to have been read & set up before we
* create the minor nodes. (any other inits (such as kstats) that
* also ought to be done before creating the minor nodes?) (Doesn't
* setting up the minor nodes kind of imply that we're ready to
* handle an open from userland?)
*/
}
"sd_unit_attach: un:0x%p minor nodes created\n", un);
/*
* Add a zero-length attribute to tell the world we support
* kernel ioctls (for layered drivers)
*/
DDI_KERNEL_IOCTL, NULL, 0);
/*
* Add a boolean property to tell the world we support
* the B_FAILFAST flag (for layered drivers)
*/
"ddi-failfast-supported", NULL, 0);
/*
* Initialize power management
*/
/*
* For performance, point to a jump table that does
* not include pm.
* The direct and priority chains don't change with PM.
*
* Note: this is currently done based on individual device
* capabilities. When an interface for determining system
* power enabled state becomes available, or when additional
* layers are added to the command chain, these values will
* have to be re-evaluated for correctness.
*/
if (un->un_f_non_devbsize_supported) {
} else {
}
}
/*
* This property is set to 0 by HA software to avoid retries
* on a reserved disk. (The preferred property name is
* "retry-on-reservation-conflict") (1189689)
*
* Note: The use of a global here can have unintended consequences. A
* per instance variable is preferrable to match the capabilities of
* different underlying hba's (4402600)
*/
DDI_PROP_DONTPASS, "retry-on-reservation-conflict",
if (sd_retry_on_reservation_conflict != 0) {
}
/* Set up options for QFULL handling. */
"qfull-retries", -1)) != -1) {
rval, 1);
}
"qfull-retry-interval", -1)) != -1) {
rval, 1);
}
/*
* This just prints a message that announces the existence of the
* device. The message is always printed in the system logfile, but
* only appears on the console if the system is booted with the
* -v (verbose) argument.
*/
/*
* The framework calls driver attach routines single-threaded
* for a given instance. However we still acquire SD_MUTEX here
* because this required for calling the sd_validate_geometry()
* and sd_register_devid() functions.
*/
/*
* Read and validate the device's geometry (ie, disk label)
* A new unformatted drive will not have a valid geometry, but
* the driver needs to successfully attach to this device so
* the drive can be formatted via ioctls.
*/
ENOTSUP)) &&
/*
* We found a small disk with an EFI label on it;
* we need to fix up the minor nodes accordingly.
*/
}
/*
* Refer to comments related to off-by-1 at the
* header of this file.
* Adjust minor node for 1TB disk.
*/
}
#endif
/*
* Read and initialize the devid for the unit.
*/
if (un->un_f_devid_supported) {
}
#if (defined(__fibre))
/*
* Register callbacks for fibre only. You can't do this soley
* on the basis of the devid_type because this is hba specific.
* We need to query our hba capabilities to find out whether to
* register or not.
*/
if (un->un_f_is_fibre) {
"sd_unit_attach: un:0x%p event callbacks inserted", un);
}
}
#endif
/*
* Disable both read cache and write cache. This is
* the historic behavior of the keywords in the config file.
*/
0) {
"sd_unit_attach: un:0x%p Could not disable "
"caching", un);
goto devid_failed;
}
}
/*
* Check the value of the WCE bit now and
* set un_f_write_cache_enabled accordingly.
*/
/*
* Set the pstat and error stat values here, so data obtained during the
* previous attach-time routines is available.
*
* Note: This is a critical sequence that needs to be maintained:
* 1) Instantiate the kstats before any routines using the iopath
* (i.e. sd_send_scsi_cmd).
* 2) Initialize the error stats (sd_set_errstats) and partition
* stats (sd_set_pstats)here, following sd_validate_geometry(),
* sd_register_devid(), and sd_cache_control().
*/
if (un->un_f_pkstats_enabled) {
"sd_unit_attach: un:0x%p pstats created and set\n", un);
}
"sd_unit_attach: un:0x%p errstats set\n", un);
/*
* Find out what type of reservation this disk supports.
*/
case 0:
/*
* SCSI-3 reservations are supported.
*/
"sd_unit_attach: un:0x%p SCSI-3 reservations\n", un);
break;
case ENOTSUP:
/*
* The PERSISTENT RESERVE IN command would not be recognized by
* a SCSI-2 device, so assume the reservation type is SCSI-2.
*/
"sd_unit_attach: un:0x%p SCSI-2 reservations\n", un);
break;
default:
/*
* default to SCSI-3 reservations
*/
"sd_unit_attach: un:0x%p default SCSI3 reservations\n", un);
break;
}
"sd_unit_attach: un:0x%p exit success\n", un);
return (DDI_SUCCESS);
/*
* An error occurred during the attach; clean up & return failure.
*/
/*
* Cleanup from the scsi_ifsetcap() calls (437868)
*/
}
/* Cancel callback for SD_PATH_DIRECT_PRIORITY cmd. restart */
}
}
/* Cancel any pending reset-throttle timeouts */
}
/* Cancel any pending retry timeouts */
}
/* Cancel any pending delayed cv broadcast timeouts */
}
/* There should not be any in-progress I/O so ASSERT this check */
/* Do not free the softstate if the callback routine is active */
/*
* Partition stats apparently are not used with removables. These would
* not have been created during attach, so no need to clean them up...
*/
}
}
/*
* Note: the man pages are unclear as to whether or not doing a
* ddi_soft_state_free(sd_state, instance) is the right way to
* clean up after the ddi_soft_state_zalloc() if the subsequent
* ddi_get_soft_state() fails. The implication seems to be
* that the get_soft_state cannot fail if the zalloc succeeds.
*/
#ifdef SDDEBUG
if ((sd_component_mask & SD_LOG_ATTACH_DETACH) &&
(sd_level_mask & SD_LOGMASK_TRACE)) {
(void *)un);
}
#endif
return (DDI_FAILURE);
}
/*
* Function: sd_unit_detach
*
* Description: Performs DDI_DETACH processing for sddetach().
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
struct scsi_device *devp;
int i;
/*
* Fail the detach for any of the following:
* - Unable to get the sd_lun struct for the instance
* - A layered driver has an outstanding open on the instance
* - Another thread is already detaching this instance
* - Another thread is currently performing an open
*/
return (DDI_FAILURE);
}
/*
* Mark this instance as currently in a detach, to inhibit any
* opens from a layered driver.
*/
un->un_detach_count++;
/*
* Fail the detach if there are any outstanding layered
* opens on this device.
*/
for (i = 0; i < NDKMAP; i++) {
goto err_notclosed;
}
}
/*
* Verify there are NO outstanding commands issued to this device.
* ie, un_ncmds_in_transport == 0.
* It's possible to have outstanding commands through the physio
* code path, even though everything's closed.
*/
"sd_dr_detach: Detach failure due to outstanding cmds\n");
goto err_stillbusy;
}
/*
* If we have the device reserved, release the reservation.
*/
/*
* Note: sd_reserve_release sends a command to the device
* via the sd_ioctlcmd() path, and can sleep.
*/
"sd_dr_detach: Cannot release reservation \n");
}
} else {
}
/*
* Untimeout any reserve recover, throttle reset, restart unit
* and delayed broadcast timeout threads. Protect the timeout pointer
* from getting nulled by their callback functions.
*/
}
}
}
} else {
}
/* Remove any pending reservation reclaim requests for this device */
/* Cancel any pending callbacks for SD_PATH_DIRECT_PRIORITY cmd. */
}
/* Cancel any active multi-host disk watch thread requests */
"sd_dr_detach: Cannot cancel mhd watch request\n");
/*
* Note: We are returning here after having removed
* some driver timeouts above. This is consistent with
* the legacy implementation but perhaps the watch
* terminate call should be made with the wait flag set.
*/
goto err_stillbusy;
}
}
"sd_dr_detach: Cannot cancel swr watch request\n");
/*
* Note: We are returning here after having removed
* some driver timeouts above. This is consistent with
* the legacy implementation but perhaps the watch
* terminate call should be made with the wait flag set.
*/
goto err_stillbusy;
}
}
/*
* Clear any scsi_reset_notifies. We clear the reset notifies
* if we have not registered one.
* Note: The sd_mhd_reset_notify_cb() fn tries to acquire SD_MUTEX!
*/
/*
* protect the timeout pointers from getting nulled by
* their callback functions during the cancellation process.
* In such a scenario untimeout can be invoked with a null value.
*/
/*
* Timeout is active; cancel it.
* Note that it'll never be active on a device
* that does not support PM therefore we don't
* have to check before calling pm_idle_component.
*/
}
/*
* Check whether there is already a timeout scheduled for power
* management. If yes then don't lower the power here, that's.
* the timeout handler's job.
*/
/*
* Timeout is active; cancel it.
* Note that it'll never be active on a device
* that does not support PM therefore we don't
* have to check before calling pm_idle_component.
*/
} else {
DDI_SUCCESS)) {
"sd_dr_detach: Lower power request failed, ignoring.\n");
/*
* Fix for bug: 4297749, item # 13
* The above test now includes a check to see if PM is
* supported by this device before call
* pm_lower_power().
* Note, the following is not dead code. The call to
* pm_lower_power above will generate a call back into
* our sdpower routine which might result in a timeout
* handler getting activated. Therefore the following
* code is valid and necessary.
*/
} else {
}
}
}
/*
* Cleanup from the scsi_ifsetcap() calls (437868)
* Relocated here from above to be after the call to
* pm_lower_power, which was getting errors.
*/
}
/*
* Remove any event callbacks, fibre only
*/
DDI_SUCCESS)) {
/*
* Note: We are returning here after having done
* substantial cleanup above. This is consistent
* with the legacy implementation but this may not
* be the right thing to do.
*/
"sd_dr_detach: Cannot cancel insert event\n");
goto err_remove_event;
}
DDI_SUCCESS)) {
/*
* Note: We are returning here after having done
* substantial cleanup above. This is consistent
* with the legacy implementation but this may not
* be the right thing to do.
*/
"sd_dr_detach: Cannot cancel remove event\n");
goto err_remove_event;
}
}
/* Do not free the softstate if the callback routine is active */
/*
* Hold the detach mutex here, to make sure that no other threads ever
* can access a (partially) freed soft state structure.
*/
/*
* Clean up the soft state struct.
* At this point there should be no competing threads anymore.
*/
/* Unregister and free device id. */
}
/*
* Destroy wmap cache if it exists.
*/
}
/* Remove minor nodes */
/*
* kstat cleanup is done in detach for all device types (4363169).
* We do not want to fail detach if the device kstats are not deleted
* since there is a confusion about the devo_refcnt for the device.
* We just delete the kstats and let detach complete successfully.
*/
}
}
/* Remove partition stats */
if (un->un_f_pkstats_enabled) {
for (i = 0; i < NSDMAP; i++) {
}
}
}
/* Remove xbuf registration */
/* Remove driver properties */
/* Removable media condvar. */
/* Free up soft state */
/* This frees up the INQUIRY data associated with the device. */
return (DDI_SUCCESS);
un->un_detach_count--;
return (DDI_FAILURE);
}
/*
* Driver minor node structure and data table
*/
struct driver_minor_data {
char *name;
int type;
};
static struct driver_minor_data sd_minor_data[] = {
{"a", 0, S_IFBLK},
#if defined(_SUNOS_VTOC_16)
#endif /* defined(_SUNOS_VTOC_16) */
#if defined(_FIRMWARE_NEEDS_FDISK)
#endif /* defined(_FIRMWARE_NEEDS_FDISK) */
{"a,raw", 0, S_IFCHR},
#if defined(_SUNOS_VTOC_16)
#endif /* defined(_SUNOS_VTOC_16) */
#if defined(_FIRMWARE_NEEDS_FDISK)
#endif /* defined(_FIRMWARE_NEEDS_FDISK) */
{0}
};
static struct driver_minor_data sd_minor_data_efi[] = {
{"a", 0, S_IFBLK},
#if defined(_FIRMWARE_NEEDS_FDISK)
#endif /* defined(_FIRMWARE_NEEDS_FDISK) */
{"a,raw", 0, S_IFCHR},
#if defined(_FIRMWARE_NEEDS_FDISK)
#endif /* defined(_FIRMWARE_NEEDS_FDISK) */
{0}
};
/*
* Function: sd_create_minor_nodes
*
* Description: Create the minor device nodes for the instance.
*
* Arguments: un - driver soft state (unit) structure
* devi - pointer to device info structure
*
* Return Code: DDI_SUCCESS
* DDI_FAILURE
*
* Context: Kernel thread context
*/
static int
{
struct driver_minor_data *dmdp;
struct scsi_device *devp;
int instance;
char name[48];
/*
* Create all the minor nodes for this target.
*/
else
/*
* Clean up any nodes that may have been created, in
* case this fails in the middle of the loop.
*/
return (DDI_FAILURE);
}
dmdp++;
}
return (DDI_SUCCESS);
}
/*
* Function: sd_create_errstats
*
* Description: This routine instantiates the device error stats.
*
* Note: During attach the stats are instantiated first so they are
* available for attach-time routines that utilize the driver
* iopath to send commands to the device. The stats are initialized
* separately so data obtained during some attach-time routines is
* available. (4362483)
*
* Arguments: un - driver soft state (unit) structure
* instance - driver instance
*
* Context: Kernel thread context
*/
static void
{
struct sd_errstats *stp;
char kstatmodule_err[KSTAT_STRLEN];
char kstatname[KSTAT_STRLEN];
return;
}
"%serr", sd_label);
"sd_create_errstats: Failed kstat_create\n");
return;
}
}
/*
* Function: sd_set_errstats
*
* Description: This routine sets the value of the vendor id, product id,
* revision, serial number, and capacity device error stats.
*
* Note: During attach the stats are instantiated first so they are
* available for attach-time routines that utilize the driver
* iopath to send commands to the device. The stats are initialized
* separately so data obtained during some attach-time routines is
* available. (4362483)
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Kernel thread context
*/
static void
{
struct sd_errstats *stp;
/*
* so reset all the errstats here in case of the hot
* replacement of disk drives, except for not changed
* Sun qualified drives.
*/
}
/*
* Set the "Serial No" kstat for Sun qualified drives (indicated by
* "SUN" in bytes 25-27 of the inquiry data (bytes 9-11 of the pid)
* (4376302))
*/
}
/*
* Set capacity error stat to 0 for no media. This ensures
* a valid capacity is displayed in response to 'iostat -E'
* when no media is present in the device.
*/
} else {
/*
* Multiply un_blockcount by un->un_sys_blocksize to get
* capacity.
*
* Note: for non-512 blocksize devices "un_blockcount" has been
* "scaled" in sd_send_scsi_READ_CAPACITY by multiplying by
* (un_tgt_blocksize / un->un_sys_blocksize).
*/
}
}
/*
* Function: sd_set_pstats
*
* Description: This routine instantiates and initializes the partition
* stats for each partition with more than zero blocks.
* (4363169)
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Kernel thread context
*/
static void
{
char kstatname[KSTAT_STRLEN];
int instance;
int i;
for (i = 0; i < NSDMAP; i++) {
sd_minor_data[i].name);
}
}
}
}
#if (defined(__fibre))
/*
* Function: sd_init_event_callbacks
*
* Description: This routine initializes the insertion and removal event
* callbacks. (fibre only)
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Kernel thread context
*/
static void
{
/*
* Add the callback for an insertion event
*/
&(un->un_insert_cb_id));
}
/*
* Add the callback for a removal event
*/
&(un->un_remove_cb_id));
}
}
/*
* Function: sd_event_callback
*
* state is changed to OFFLINE which can be used to supress
* error msgs. (fibre only)
*
* Arguments: un - driver soft state (unit) structure
*
* Context: Callout thread context
*/
/* ARGSUSED */
static void
void *bus_impldata)
{
} else {
/*
* we were offline. Restore the last state
*/
}
}
/*
* We need to handle an event callback that occurs during
* the suspend operation, since we don't prevent it.
*/
} else {
}
}
} else {
"!Unknown event\n");
}
}
#endif
/*
* Function: sd_cache_control()
*
* Description: This routine is the driver entry point for setting
* read and write caching by modifying the WCE (write cache
* enable) and RCD (read cache disable) bits of mode
* page 8 (MODEPAGE_CACHING).
*
* Arguments: un - driver soft state (unit) structure
* rcd_flag - flag for controlling the read cache
* wce_flag - flag for controlling the write cache
*
* Return Code: EIO
* code returned by sd_send_scsi_MODE_SENSE and
* sd_send_scsi_MODE_SELECT
*
* Context: Kernel Thread
*/
static int
{
struct mode_caching *mode_caching_page;
int hdrlen;
int bd_len;
int rval = 0;
struct mode_header_grp2 *mhp;
/*
* Do a test unit ready, otherwise a mode sense may not work if this
* is the first command sent to the device after boot.
*/
(void) sd_send_scsi_TEST_UNIT_READY(un, 0);
} else {
}
/*
* Allocate memory for the retrieved mode page and its headers. Set
* a pointer to the page itself. Use mode_cache_scsi3 to insure
* we get all of the mode sense data otherwise, the mode select
* will fail. mode_cache_scsi3 is a superset of mode_caching.
*/
sizeof (struct mode_cache_scsi3);
/* Get the information from the device. */
} else {
}
if (rval != 0) {
"sd_cache_control: Mode Sense Failed\n");
return (rval);
}
/*
* Determine size of Block Descriptors in order to locate
* the mode page data. ATAPI devices return 0, SCSI devices
* should return MODE_BLK_DESC_LENGTH.
*/
} else {
}
if (bd_len > MODE_BLK_DESC_LENGTH) {
"sd_cache_control: Mode Sense returned invalid "
"block descriptor length\n");
return (EIO);
}
/* Check the relevant bits on successful mode sense. */
/*
* Construct select buffer length based on the
* length of the sense data returned.
*/
sizeof (struct mode_page) +
/*
* Set the caching bits as requested.
*/
if (rcd_flag == SD_CACHE_ENABLE)
mode_caching_page->rcd = 0;
else if (rcd_flag == SD_CACHE_DISABLE)
if (wce_flag == SD_CACHE_ENABLE)
else if (wce_flag == SD_CACHE_DISABLE)
mode_caching_page->wce = 0;
/*
* Save the page if the mode sense says the
* drive supports it.
*/
/* Clear reserved bits before mode select. */
/*
* Clear out mode header for mode select.
* The rest of the retrieved page will be reused.
*/
} else {
}
/* Issue mode select to change the cache settings */
} else {
}
}
return (rval);
}
/*
* Function: sd_get_write_cache_enabled()
*
* Description: This routine is the driver entry point for determining if
* write caching is enabled. It examines the WCE (write cache
* enable) bits of mode page 8 (MODEPAGE_CACHING).
*
* Arguments: un - driver soft state (unit) structure
* is_enabled - pointer to int where write cache enabled state
* is returned (non-zero -> write cache enabled)
*
*
* Return Code: EIO
* code returned by sd_send_scsi_MODE_SENSE
*
* Context: Kernel Thread
*
* NOTE: If ioctl is added to disable write cache, this sequence should
* be followed so that no locking is required for accesses to
* un->un_f_write_cache_enabled:
* do mode select to clear wce
* do synchronize cache to flush cache
* set un->un_f_write_cache_enabled = FALSE
*
* Conversely, an ioctl to enable the write cache should be done
* in this order:
* set un->un_f_write_cache_enabled = TRUE
* do mode select to set wce
*/
static int
{
struct mode_caching *mode_caching_page;
int hdrlen;
int bd_len;
int rval = 0;
/* in case of error, flag as enabled */
*is_enabled = TRUE;
/*
* Do a test unit ready, otherwise a mode sense may not work if this
* is the first command sent to the device after boot.
*/
(void) sd_send_scsi_TEST_UNIT_READY(un, 0);
} else {
}
/*
* Allocate memory for the retrieved mode page and its headers. Set
* a pointer to the page itself.
*/
/* Get the information from the device. */
} else {
}
if (rval != 0) {
"sd_get_write_cache_enabled: Mode Sense Failed\n");
return (rval);
}
/*
* Determine size of Block Descriptors in order to locate
* the mode page data. ATAPI devices return 0, SCSI devices
* should return MODE_BLK_DESC_LENGTH.
*/
struct mode_header_grp2 *mhp;
} else {
}
if (bd_len > MODE_BLK_DESC_LENGTH) {
"sd_get_write_cache_enabled: Mode Sense returned invalid "
"block descriptor length\n");
return (EIO);
}
return (0);
}
/*
* Function: sd_make_device
*
* Description: Utility routine to return the Solaris device number from
* the data in the device's dev_info structure.
*
* Return Code: The Solaris device number
*
* Context: Any
*/
static dev_t
{
}
/*
* Function: sd_pm_entry
*
* Description: Called at the start of a new command to manage power
* and busy status of a device. This includes determining whether
* the current power state of the device is sufficient for
* performing the command or whether it must be changed.
* The PM framework is notified appropriately.
* Only with a return status of DDI_SUCCESS will the
* component be busy to the framework.
*
* All callers of sd_pm_entry must check the return status
* and only call sd_pm_exit it it was DDI_SUCCESS. A status
* of DDI_FAILURE indicates the device failed to power up.
* In this case un_pm_count has been adjusted so the result
* on exit is still powered down, ie. count is less than 0.
* Calling sd_pm_exit with this count value hits an ASSERT.
*
* Return Code: DDI_SUCCESS or DDI_FAILURE
*
* Context: Kernel thread context.
*/
static int
{
int return_status = DDI_SUCCESS;
"sd_pm_entry: exiting, PM not enabled\n");
return (return_status);
}
/*
* Just increment a counter if PM is enabled. On the transition from
* 0 ==> 1, mark the device as busy. The iodone side will decrement
* the count with each IO and mark the device as idle when the count
* hits 0.
*
* If the count is less than 0 the device is powered down. If a powered
* down device is successfully powered up then the count must be
* incremented to reflect the power up. Note that it'll get incremented
* a second time to become busy.
*
* Because the following has the potential to change the device state
* and must release the un_pm_mutex to do so, only one thread can be
* allowed through at a time.
*/
}
/*
* Indicate we are now busy so the framework won't attempt to
* power down the device. This call will only fail if either
* we passed a bad component number or the device has no
* components. Neither of these should ever happen.
*/
if (un->un_pm_count < 0) {
"sd_pm_entry: power up component\n");
/*
* pm_raise_power will cause sdpower to be called
* which brings the device power level to the
* desired state, ON in this case. If successful,
* un_pm_count and un_power_level will be updated
* appropriately.
*/
if (return_status != DDI_SUCCESS) {
/*
* Power up failed.
* Idle the device and adjust the count
* so the result on exit is that we're
* still powered down, ie. count is less than 0.
*/
"sd_pm_entry: power up failed,"
" idle the component\n");
un->un_pm_count--;
} else {
/*
* Device is powered up, verify the
* count is non-negative.
* This is debug only.
*/
}
}
if (return_status == DDI_SUCCESS) {
/*
* For performance, now that the device has been tagged
* as busy, and it's known to be powered up, update the
* chain types to use jump tables that do not include
* pm. This significantly lowers the overhead and
* therefore improves performance.
*/
"sd_pm_entry: changing uscsi_chain_type from %d\n",
if (un->un_f_non_devbsize_supported) {
} else {
}
" changed uscsi_chain_type to %d\n",
/* 300 ms. */
/*
* Include an extra call to busy which keeps the
* device busy with-respect-to the PM layer
* until the timer fires, at which time it'll
* get the extra idle call.
*/
}
}
}
/* Next... */
un->un_pm_count++;
return (return_status);
}
/*
* Function: sd_pm_exit
*
* Description: Called at the completion of a command to manage busy
* status for the device. If the device becomes idle the
* PM framework is notified.
*
* Context: Kernel thread context
*/
static void
{
/*
* After attach the following flag is only read, so don't
* take the penalty of acquiring a mutex for it.
*/
un->un_pm_count--;
if (un->un_pm_count == 0) {
"sd_pm_exit: idle component\n");
} else {
}
}
}
/*
* Function: sdopen
*
* Description: Driver's open(9e) entry point function.
*
* Arguments: dev_i - pointer to device number
* flag - how to open file (FEXCL, FNDELAY, FREAD, FWRITE)
* otyp - open type (OTYP_BLK, OTYP_CHR, OTYP_LYR)
* cred_p - user credential pointer
*
* Return Code: EINVAL
* ENXIO
* EIO
* EROFS
* EBUSY
*
* Context: Kernel thread context
*/
/* ARGSUSED */
static int
{
int nodelay;
int part;
int instance;
/* Validate the open type */
return (EINVAL);
}
/*
* Fail the open if there is no softstate for the instance, or
* if another thread somewhere is trying to detach the instance.
*/
(un->un_detach_count != 0)) {
/*
* The probe cache only needs to be cleared when open (9e) fails
* with ENXIO (4238046).
*/
/*
* un-conditionally clearing probe cache is ok with
* x86 platform can be an issue with both parallel
* and fibre in 1 binary
*/
return (ENXIO);
}
/*
* The un_layer_count is to prevent another thread in specfs from
* trying to detach the instance, which can happen when we are
* called from a higher-layer driver instead of thru specfs.
* This will not be needed when DDI provides a layered driver
* interface that allows specfs to know that an instance is in
* use by a layered driver & should not be detached.
*
* Note: the semantics for layered driver opens are exactly one
* close for every open.
*/
un->un_layer_count++;
}
/*
* Keep a count of the current # of opens in progress. This is because
* some layered drivers try to call us as a regular open. This can
* cause problems that we cannot prevent, however by keeping this count
* we can at least keep our open and detach routines from racing against
* each other under such conditions.
*/
/*
* We use a semaphore here in order to serialize
* open and close requests on the device.
*/
/*
* All device accesses go thru sdstrategy() where we check
* on suspend status but there could be a scsi_poll command,
* which bypasses sdstrategy(), so we need to check pm
* status.
*/
if (!nodelay) {
}
"sdopen: sd_pm_entry failed\n");
goto open_failed_with_pm;
}
}
/* check for previous exclusive open */
"sdopen: exclopen=%x, flag=%x, regopen=%x\n",
goto excl_open_fail;
}
int i;
goto excl_open_fail;
}
for (i = 0; i < (OTYPCNT - 1); i++) {
goto excl_open_fail;
}
}
}
/*
* Check the write permission if this is a removable media device,
* NDELAY has not been set, and writable permission is requested.
*
* Note: If NDELAY was set and this is write-protected media the WRITE
* attempt will fail with EIO as part of the I/O processing. This is a
* more permissive implementation that allows the open to succeed and
* WRITE attempts to fail when appropriate.
*/
if (un->un_f_chk_wp_open) {
/*
* Defer the check for write permission on writable
* DVD drive till sdstrategy and will not fail open even
* if FWRITE is set as the device can be writable
* depending upon the media and the media can change
* after the call to open().
*/
"write to cd or write protected media\n");
goto open_fail;
}
}
}
}
/*
* Check if disk is ready and has a valid geometry later.
*/
if (!nodelay) {
/*
* Fail if device is not ready or if the number of disk
* blocks is zero or negative for non CD devices.
*/
if ((rval != SD_READY_VALID) ||
"device not ready or invalid disk block value\n");
goto open_fail;
}
} else {
/*
* x86 requires special nodelay handling, so that p0 is
* always defined and accessible.
* Invalidate geometry only if device is not already open.
*/
break;
}
cp++;
}
}
#endif
}
} else {
}
/* Set up open and exclusive open flags */
}
if (!nodelay) {
sd_pm_exit(un);
}
return (DDI_SUCCESS);
/*
* On a failed open we must exit the pm management.
*/
if (!nodelay) {
sd_pm_exit(un);
}
un->un_layer_count--;
}
return (rval);
}
/*
* Function: sdclose
*
* Description: Driver's close(9e) entry point function.
*
* Arguments: dev - device number
* flag - file status flag, informational only
* otyp - close type (OTYP_BLK, OTYP_CHR, OTYP_LYR)
* cred_p - user credential pointer
*
* Return Code: ENXIO
*
* Context: Kernel thread context
*/
/* ARGSUSED */
static int
{
int part;
int nodelay;
int rval = 0;
/* Validate the open type */
return (ENXIO);
}
return (ENXIO);
}
/*
* We use a semaphore here in order to serialize
* open and close requests on the device.
*/
/* Don't proceed if power is being changed. */
}
}
/* Update the open partition map */
} else {
}
break;
}
cp++;
}
/*
* We avoid persistance upon the last close, and set
* the throttle back to the maximum.
*/
CE_WARN, "offline\n");
}
} else {
/*
* Flush any outstanding writes in NVRAM cache.
* Note: SYNCHRONIZE CACHE is an optional SCSI-2
* cmd, it may not work for non-Pluto devices.
* SYNCHRONIZE CACHE is not required for removables,
* except DVD-RAM drives.
*
* Also note: because SYNCHRONIZE CACHE is currently
* the only command issued here that requires the
* drive be powered up, only do the power up before
* sending the Sync Cache command. If additional
* commands are added which require a powered up
* drive, the following sequence may have to change.
*
* And finally, note that parallel SCSI on SPARC
* only issues a Sync Cache to DVD-RAM, a newly
* supported device.
*/
if (un->un_f_sync_cache_supported ||
#else
#endif
rval =
NULL);
/* ignore error if not supported */
rval = 0;
} else if (rval != 0) {
}
sd_pm_exit(un);
} else {
}
}
/*
* For devices which supports DOOR_LOCK, send an ALLOW
* MEDIA REMOVAL command, but don't get upset if it
* fails. We need to raise the power of the drive before
* we can call sd_send_scsi_DOORLOCK()
*/
if (un->un_f_doorlock_supported) {
sd_pm_exit(un);
(nodelay != 0)) {
}
} else {
}
}
/*
* If a device has removable media, invalidate all
* parameters related to media, such as geometry,
* blocksize, and blockcount.
*/
if (un->un_f_has_removable_media) {
sr_ejected(un);
}
/*
* Destroy the cache (if it exists) which was
* allocated for the write maps since this is
* the last close for this media.
*/
if (un->un_wm_cache) {
/*
* Check if there are pending commands.
* and if there are give a warning and
* do not destroy the cache.
*/
if (un->un_ncmds_in_driver > 0) {
"Unable to clean up memory "
"because of pending I/O\n");
} else {
un->un_wm_cache);
}
}
}
}
/*
* The detach routine may run when the layer count
* drops to zero.
*/
un->un_layer_count--;
}
return (rval);
}
/*
* Function: sd_ready_and_valid
*
* Description: Test if device is ready and has a valid geometry.
*
* Arguments: dev - device number
* un - driver soft state (unit) structure
*
* Return Code: SD_READY_VALID ready and valid label
* SD_READY_NOT_VALID ready, geom ops never applicable
* SD_NOT_READY_VALID not ready, no label
*
* Context: Never called at interrupt context.
*/
static int
{
struct sd_errstats *stp;
int rval = SD_READY_VALID;
char name_str[48];
/*
* If a device has removable media, we must check if media is
* ready when checking if this device is ready and valid.
*/
if (un->un_f_has_removable_media) {
if (sd_send_scsi_TEST_UNIT_READY(un, 0) != 0) {
goto done;
}
/* capacity has to be read every open. */
&lbasize, SD_PATH_DIRECT) != 0) {
goto done;
} else {
}
}
/*
* Check if the media in the device is writable or not.
*/
}
} else {
/*
* Do a test unit ready to clear any unit attention from non-cd
* devices.
*/
(void) sd_send_scsi_TEST_UNIT_READY(un, 0);
}
/*
* If this is a non 512 block device, allocate space for
* the wmap cache. This is being done here since every time
* a media is changed this routine will be called and the
* block size is a function of media rather than device.
*/
if (!(un->un_wm_cache)) {
"%s%d_cache",
if (!(un->un_wm_cache)) {
goto done;
}
}
}
/*
* If the target is not yet ready here (defined by a TUR
* failure), invalidate the geometry and print an 'offline'
* message. This is a legacy message, as the state of the
* target is not actually changed to SD_STATE_OFFLINE.
*
* If the TUR fails for EACCES (Reservation Conflict), it
* means there actually is nothing wrong with the target that
* would require invalidating the geometry, so continue in
* that case as if the TUR was successful.
*/
int err;
"offline\n");
goto done;
}
}
/*
* Note: sd_validate_geometry may return TRUE, but that does
* not necessarily mean un_f_geometry_is_valid == TRUE!
*/
rval = 0;
else {
goto done;
}
}
if (rval != 0) {
/*
* We don't check the validity of geometry for
* CDROMs. Also we assume we have a good label
* even if sd_validate_geometry returned ENOMEM.
*/
goto done;
}
}
}
/*
* If this device supports DOOR_LOCK command, try and send
* this command to PREVENT MEDIA REMOVAL, but don't get upset
* if it fails. For a CD, however, it is an error
*/
if (un->un_f_doorlock_supported) {
goto done;
}
}
/* The state has changed, inform the media watch routines */
done:
/*
* Initialize the capacity kstat value, if no media previously
* (capacity kstat is 0) and a media has been inserted
* (un_blockcount > 0).
*/
}
}
return (rval);
}
/*
* Function: sdmin
*
* Description: Routine to limit the size of a data transfer. Used in
* conjunction with physio(9F).
*
* Arguments: bp - pointer to the indicated buf(9S) struct.
*
* Context: Kernel thread context.
*/
static void
{
int instance;
}
}
/*
* Function: sdread
*
* Description: Driver's read(9e) entry point function.
*
* Arguments: dev - device number
* uio - structure pointer describing where data is to be stored
* in user's space
* cred_p - user credential pointer
*
* Return Code: ENXIO
* EIO
* EINVAL
* value returned by physio
*
* Context: Kernel thread context.
*/
/* ARGSUSED */
static int
{
int secmask;
int err;
return (ENXIO);
}
/*
* Because the call to sd_ready_and_valid will issue I/O we
* must wait here if either the device is suspended or
* if it's power level is changing.
*/
}
un->un_ncmds_in_driver++;
un->un_ncmds_in_driver--;
return (EIO);
}
un->un_ncmds_in_driver--;
}
/*
* Read requests are restricted to multiples of the system block size.
*/
"sdread: file offset not modulo %d\n",
"sdread: transfer length not modulo %d\n",
} else {
}
return (err);
}
/*
* Function: sdwrite
*
* Description: Driver's write(9e) entry point function.
*
* Arguments: dev - device number
* uio - structure pointer describing where data is stored in
* user's space
* cred_p - user credential pointer
*
* Return Code: ENXIO
* EIO
* EINVAL
* value returned by physio
*
* Context: Kernel thread context.
*/
/* ARGSUSED */
static int
{
int secmask;
int err;
return (ENXIO);
}
/*
* Because the call to sd_ready_and_valid will issue I/O we
* must wait here if either the device is suspended or
* if it's power level is changing.
*/
}
un->un_ncmds_in_driver++;
un->un_ncmds_in_driver--;
return (EIO);
}
un->un_ncmds_in_driver--;
}
/*
* Write requests are restricted to multiples of the system block size.
*/
"sdwrite: file offset not modulo %d\n",
"sdwrite: transfer length not modulo %d\n",
} else {
}
return (err);
}
/*
* Function: sdaread
*
* Description: Driver's aread(9e) entry point function.
*
* Arguments: dev - device number
* aio - structure pointer describing where data is to be stored
* cred_p - user credential pointer
*
* Return Code: ENXIO
* EIO
* EINVAL
* value returned by aphysio
*
* Context: Kernel thread context.
*/
/* ARGSUSED */
static int
{
int secmask;
int err;
return (ENXIO);
}
/*
* Because the call to sd_ready_and_valid will issue I/O we
* must wait here if either the device is suspended or
* if it's power level is changing.
*/
}
un->un_ncmds_in_driver++;
un->un_ncmds_in_driver--;
return (EIO);
}
un->un_ncmds_in_driver--;
}
/*
* Read requests are restricted to multiples of the system block size.
*/
"sdaread: file offset not modulo %d\n",
"sdaread: transfer length not modulo %d\n",
} else {
}
return (err);
}
/*
* Function: sdawrite
*
* Description: Driver's awrite(9e) entry point function.
*
* Arguments: dev - device number
* aio - structure pointer describing where data is stored
* cred_p - user credential pointer
*
* Return Code: ENXIO
* EIO
* EINVAL
* value returned by aphysio
*
* Context: Kernel thread context.
*/
/* ARGSUSED */
static int
{
int secmask;
int err;
return (ENXIO);
}
/*
* Because the call to sd_ready_and_valid will issue I/O we
* must wait here if either the device is suspended or
* if it's power level is changing.
*/
}
un->un_ncmds_in_driver++;
un->un_ncmds_in_driver--;
return (EIO);
}
un->un_ncmds_in_driver--;
}
/*
* Write requests are restricted to multiples of the system block size.
*/
"sdawrite: file offset not modulo %d\n",
"sdawrite: transfer length not modulo %d\n",
} else {
}
return (err);
}
/*
* Driver IO processing follows the following sequence:
*
* sdioctl(9E) sdstrategy(9E) biodone(9F)
* | | ^
* v v |
* sd_send_scsi_cmd() ddi_xbuf_qstrategy() +-------------------+
* | | | |
* v | | |
* sd_uscsi_strategy() sd_xbuf_strategy() sd_buf_iodone() sd_uscsi_iodone()
* | | ^ ^
* v v | |
* SD_BEGIN_IOSTART() SD_BEGIN_IOSTART() | |
* | | | |
* +---+ | +------------+ +-------+
* | | | |
* | SD_NEXT_IOSTART()| SD_NEXT_IODONE()| |
* | v | |
* | sd_mapblockaddr_iostart() sd_mapblockaddr_iodone() |
* | | ^ |
* | SD_NEXT_IOSTART()| SD_NEXT_IODONE()| |
* | v | |
* | sd_mapblocksize_iostart() sd_mapblocksize_iodone() |
* | | ^ |
* | SD_NEXT_IOSTART()| SD_NEXT_IODONE()| |
* | v | |
* | sd_checksum_iostart() sd_checksum_iodone() |
* | | ^ |
* +-> SD_NEXT_IOSTART()| SD_NEXT_IODONE()+------------->+
* | v | |
* | sd_pm_iostart() sd_pm_iodone() |
* | | ^ |
* | | | |
* +-> SD_NEXT_IOSTART()| SD_BEGIN_IODONE()--+--------------+
* | ^
* v |
* sd_core_iostart() |
* | |
* | +------>(*destroypkt)()
* +-> sd_start_cmds() <-+ | |
* | | | v
* | | | scsi_destroy_pkt(9F)
* | | |
* +->(*initpkt)() +- sdintr()
* | | | |
* | +-> scsi_init_pkt(9F) | +-> sd_handle_xxx()
* | +-> scsi_setup_cdb(9F) |
* | |
* +--> scsi_transport(9F) |
* | |
* +----> SCSA ---->+
*
*
* This code is based upon the following presumtions:
*
* - iostart and iodone functions operate on buf(9S) structures. These
* functions perform the necessary operations on the buf(9S) and pass
* them along to the next function in the chain by using the macros
* SD_NEXT_IOSTART() (for iostart side functions) and SD_NEXT_IODONE()
* (for iodone side functions).
*
* - The iostart side functions may sleep. The iodone side functions
* are called under interrupt context and may NOT sleep. Therefore
* iodone side functions also may not call iostart side functions.
* (NOTE: iostart side functions should NOT sleep for memory, as
* this could result in deadlock.)
*
* - An iostart side function may call its corresponding iodone side
* function directly (if necessary).
*
* - In the event of an error, an iostart side function can return a buf(9S)
* to its caller by calling SD_BEGIN_IODONE() (after setting B_ERROR and
* b_error in the usual way of course).
*
* - The taskq mechanism may be used by the iodone side functions to dispatch
* requests to the iostart side functions. The iostart side functions in
* this case would be called under the context of a taskq thread, so it's
*
* - iostart side functions may allocate "shadow" buf(9S) structs and
* pass them along to the next function in the chain. The corresponding
* iodone side functions must coalesce the "shadow" bufs and return
* the "original" buf to the next higher layer.
*
* - The b_private field of the buf(9S) struct holds a pointer to
* an sd_xbuf struct, which contains information needed to
* construct the scsi_pkt for the command.
*
* - The SD_MUTEX(un) is NOT held across calls to the next layer. Each
* layer must acquire & release the SD_MUTEX(un) as needed.
*/
/*
* Create taskq for all targets in the system. This is created at
* _init(9E) and destroyed at _fini(9E).
*
* Note: here we set the minalloc to a reasonably high number to ensure that
* we will have an adequate supply of task entries available at interrupt time.
* This is used in conjunction with the TASKQ_PREPOPULATE flag in
* sd_create_taskq(). Since we do not want to sleep for allocations at
* interrupt time, set maxalloc equal to minalloc. That way we will just fail
* the command if we ever try to dispatch more than SD_TASKQ_MAXALLOC taskq
* requests any one instant in time.
*/
#define SD_TASKQ_NUMTHREADS 8
#define SD_TASKQ_MINALLOC 256
#define SD_TASKQ_MAXALLOC 256
static int sd_taskq_minalloc = SD_TASKQ_MINALLOC;
static int sd_taskq_maxalloc = SD_TASKQ_MAXALLOC;
/*
* The following task queue is being created for the write part of
* read-modify-write of non-512 block size devices.
* Limit the number of threads to 1 for now. This number has been choosen
* currently. Performance for which is not main criteria at this stage.
* Note: It needs to be explored if we can use a single taskq in future
*/
#define SD_WMR_TASKQ_NUMTHREADS 1
/*
* Function: sd_taskq_create
*
* Description: Create taskq thread(s) and preallocate task entries
*
* Return Code: Returns a pointer to the allocated taskq_t.
*
* Context: Can sleep. Requires blockable context.
*
* Notes: - The taskq() facility currently is NOT part of the DDI.
* (definitely NOT recommeded for 3rd-party drivers!) :-)
* - taskq_create() will block for memory, also it will panic
* if it cannot create the requested number of threads.
* - Currently taskq_create() creates threads that cannot be
* swapped.
* - We use TASKQ_PREPOPULATE to ensure we have an adequate
* supply of taskq entries at interrupt time (ie, so that we
* do not have to sleep for memory)
*/
static void
sd_taskq_create(void)
{
char taskq_name[TASKQ_NAMELEN];
"%s_drv_taskq", sd_label);
"%s_rmw_taskq", sd_label);
}
/*
* Function: sd_taskq_delete
*
* Description: Complementary cleanup routine for sd_taskq_create().
*
* Context: Kernel thread context.
*/
static void
sd_taskq_delete(void)
{
}
/*
* Function: sdstrategy
*
* Description: Driver's strategy (9E) entry point function.
*
* Arguments: bp - pointer to buf(9S)
*
* Return Code: Always returns zero
*
* Context: Kernel thread context.
*/
static int
{
return (0);
}
/* As was done in the past, fail new cmds. if state is dumping. */
return (0);
}
/*
* Commands may sneak in while we released the mutex in
* DDI_SUSPEND, we should block new commands. However, old
* commands that are still in the driver at this point should
* still be allowed to drain.
*/
/*
* Must wait here if either the device is suspended or
* if it's power level is changing.
*/
}
un->un_ncmds_in_driver++;
/*
* atapi: Since we are running the CD for now in PIO mode we need to
* call bp_mapin here to avoid bp_mapin called interrupt context under
* the HBA's init_pkt routine.
*/
}
/*
* This will (eventually) allocate the sd_xbuf area and
* call sd_xbuf_strategy(). We just want to return the
* result of ddi_xbuf_qstrategy so that we have an opt-
* imized tail call which saves us a stack frame.
*/
}
/*
* Function: sd_xbuf_strategy
*
* Description: Function for initiating IO operations via the
* ddi_xbuf_qstrategy() mechanism.
*
* Context: Kernel thread context.
*/
static void
{
/*
* Initialize the fields in the xbuf and save a pointer to the
* xbuf in bp->b_private.
*/
/* Send the buf down the iostart chain */
}
/*
* Function: sd_xbuf_init
*
* Description: Prepare the given sd_xbuf struct for use.
*
* Arguments: un - ptr to softstate
* bp - ptr to associated buf(9S)
* xp - ptr to associated sd_xbuf
* chain_type - IO chain type to use:
* SD_CHAIN_NULL
* SD_CHAIN_BUFIO
* SD_CHAIN_USCSI
* SD_CHAIN_DIRECT
* SD_CHAIN_DIRECT_PRIORITY
* pktinfop - ptr to private data struct for scsi_pkt(9S)
* initialization; may be NULL if none.
*
* Context: Kernel thread context
*/
static void
{
int index;
bp, chain_type);
/*
* Set up the iostart and iodone chain indexes in the xbuf, based
* upon the specified chain type to use.
*/
switch (chain_type) {
case SD_CHAIN_NULL:
/*
* Fall thru to just use the values for the buf type, even
* tho for the NULL chain these values will never be used.
*/
/* FALLTHRU */
case SD_CHAIN_BUFIO:
break;
case SD_CHAIN_USCSI:
break;
case SD_CHAIN_DIRECT:
break;
case SD_CHAIN_DIRECT_PRIORITY:
break;
default:
/* We're really broken if we ever get here... */
panic("sd_xbuf_init: illegal chain type!");
/*NOTREACHED*/
}
/*
* It might be a bit easier to simply bzero the entire xbuf above,
* but it turns out that since we init a fair number of members anyway,
* we save a fair number cycles by doing explicit assignment of zero.
*/
xp->xb_pkt_flags = 0;
xp->xb_dma_resid = 0;
xp->xb_retry_count = 0;
xp->xb_victim_retry_count = 0;
xp->xb_ua_retry_count = 0;
xp->xb_sense_status = 0;
xp->xb_sense_state = 0;
xp->xb_sense_resid = 0;
}
/*
* Function: sd_uscsi_strategy
*
* Description: Wrapper for calling into the USCSI chain via physio(9F)
*
* Arguments: bp - buf struct ptr
*
* Return Code: Always returns 0
*
* Context: Kernel thread context
*/
static int
{
struct sd_uscsi_info *uip;
return (0);
}
/*
* atapi: Since we are running the CD for now in PIO mode we need to
* call bp_mapin here to avoid bp_mapin called interrupt context under
* the HBA's init_pkt routine.
*/
}
un->un_ncmds_in_driver++;
/*
* A pointer to a struct sd_uscsi_info is expected in bp->b_private
*/
case SD_PATH_DIRECT:
break;
case SD_PATH_DIRECT_PRIORITY:
break;
default:
break;
}
/* Use the index obtained within xbuf_init */
return (0);
}
/*
* These routines perform raw i/o operations.
*/
/*ARGSUSED*/
static void
{
/*
* do not break up because the CDB count would then
* be incorrect and data underruns would result (incomplete
* sdintr().
*/
}
/*
* Function: sd_send_scsi_cmd
*
* Description: Runs a USCSI command for user (when called thru sdioctl),
* or for the driver
*
* Arguments: dev - the dev_t for the device
* incmd - ptr to a valid uscsi_cmd struct
* cdbspace - UIO_USERSPACE or UIO_SYSSPACE
* dataspace - UIO_USERSPACE or UIO_SYSSPACE
* rqbufspace - UIO_USERSPACE or UIO_SYSSPACE
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: 0 - successful completion of the given command
* EIO - scsi_reset() failed, or see biowait()/physio() codes.
* ENXIO - soft state not found for specified dev
* EINVAL
* return code of biowait(9F) or physio(9F):
* EIO - IO error, caller may check incmd->uscsi_status
* ENXIO
* EACCES - reservation conflict
*
* Context: Waits for command to complete. Can sleep.
*/
static int
int path_flag)
{
struct sd_uscsi_info *uip;
int rval;
int flags;
return (ENXIO);
}
#ifdef SDDEBUG
switch (dataspace) {
case UIO_USERSPACE:
"sd_send_scsi_cmd: entry: un:0x%p UIO_USERSPACE\n", un);
break;
case UIO_SYSSPACE:
"sd_send_scsi_cmd: entry: un:0x%p UIO_SYSSPACE\n", un);
break;
default:
"sd_send_scsi_cmd: entry: un:0x%p UNEXPECTED SPACE\n", un);
break;
}
#endif
/*
* Perform resets directly; no need to generate a command to do it.
*/
/* Reset attempt was unsuccessful */
"sd_send_scsi_cmd: reset: failure\n");
return (EIO);
}
return (0);
}
/* Perfunctory sanity check... */
if (incmd->uscsi_cdblen <= 0) {
"invalid uscsi_cdblen, returning EINVAL\n");
return (EINVAL);
"unsupported uscsi_cdblen, returning EINVAL\n");
return (EINVAL);
}
/*
* In order to not worry about where the uscsi structure came from
* (or where the cdb it points to came from) we're going to make
* kmem_alloc'd copies of them here. This will also allow reference
* to the data they contain long after this process has gone to
* sleep and its kernel stack has been unmapped, etc.
*
* First get some memory for the uscsi_cmd struct and copy the
* contents of the given uscsi_cmd struct into it.
*/
/*
* Now get some space for the CDB, and copy the given CDB into
* it. Use ddi_copyin() in case the data is in user space.
*/
return (EFAULT);
}
/*
* Allocate an sd_uscsi_info struct and fill it with the info
* needed by sd_initpkt_for_uscsi(). Then put the pointer into
* b_private in the buf for sd_initpkt_for_uscsi(). Note that
* since we allocate the buf here in this function, we do not
* need to preserve the prior contents of b_private.
* The sd_uscsi_info struct is also used by sd_uscsi_strategy()
*/
/*
* Initialize Request Sense buffering, if requested.
*/
/*
* Here uscmd->uscsi_rqbuf currently points to the caller's
* buffer, but we replace this with a kernel buffer that
* we allocate to use with the sense data. The sense data
* (if present) gets copied into this new buffer before the
* command is completed. Then we copy the sense data from
* our allocated buf into the caller's buffer below. Note
* that incmd->uscsi_rqbuf and incmd->uscsi_rqlen are used
* below to perform the copy back to the caller's buf.
*/
if (rqbufspace == UIO_USERSPACE) {
} else {
}
} else {
uscmd->uscsi_rqlen = 0;
uscmd->uscsi_rqresid = 0;
}
/*
* Force asynchronous mode, if necessary. Doing this here
* has the unfortunate effect of running other queued
* commands async also, but since the main purpose of this
* capability is downloading new drive firmware, we can
* probably live with it.
*/
== 1) {
"synchronous", 0, 1) == 1) {
"sd_send_scsi_cmd: forced async ok\n");
} else {
"sd_send_scsi_cmd:\
forced async failed\n");
goto done;
}
}
}
/*
* Re-enable synchronous mode, if requested
*/
== 0) {
"synchronous", 1, 1);
"re-enabled sync %s\n",
(i == 1) ? "ok" : "failed");
}
}
}
/*
* Commands sent with priority are intended for error recovery
* situations, and do not have retries performed.
*/
if (path_flag == SD_PATH_DIRECT_PRIORITY) {
}
/*
* If we're going to do actual I/O, let physio do all the right things
*/
if (uscmd->uscsi_buflen != 0) {
/*
* physio() will block here until the command completes....
*/
sduscsimin, uio);
"returned from physio with 0x%x\n", rval);
} else {
/*
* We have to mimic what physio would do here! Argh!
*/
"sd_send_scsi_cmd: calling sd_uscsi_strategy...\n");
(void) sd_uscsi_strategy(bp);
"returned from biowait with 0x%x\n", rval);
}
done:
#ifdef SDDEBUG
"uscsi_status: 0x%02x uscsi_resid:0x%x\n",
"uscmd->uscsi_bufaddr: 0x%p uscmd->uscsi_buflen:%d\n",
if (dataspace == UIO_SYSSPACE) {
}
}
#endif
/*
* Get the status and residual to return to the caller.
*/
/*
* If the caller wants sense data, copy back whatever sense data
* we may have gotten, and update the relevant rqsense info.
*/
/* Update the Request Sense status and resid */
"uscsi_rqstatus: 0x%02x uscsi_rqresid:0x%x\n",
/* Copy out the sense data for user processes */
int flags =
}
/*
* Note: Can't touch incmd->uscsi_rqbuf so use
* uscmd->uscsi_rqbuf instead. They're the same.
*/
"incmd->uscsi_rqbuf: 0x%p rqlen:%d\n",
}
}
/*
* Free allocated resources and return; mapout the buf in case it was
* mapped in by a lower layer.
*/
}
return (rval);
}
/*
* Function: sd_buf_iodone
*
* Description: Frees the sd_xbuf & returns the buf to its originator.
*
* Context: May be called from interrupt context.
*/
/* ARGSUSED */
static void
{
/*
* Grab time when the cmd completed.
* This is used for determining if the system has been
* idle long enough to make it idle to the PM framework.
* This is for lowering the overhead, and therefore improving
* performance per I/O operation.
*/
un->un_ncmds_in_driver--;
}
/*
* Function: sd_uscsi_iodone
*
* Description: Frees the sd_xbuf & returns the buf to its originator.
*
* Context: May be called from interrupt context.
*/
/* ARGSUSED */
static void
{
/*
* Grab time when the cmd completed.
* This is used for determining if the system has been
* idle long enough to make it idle to the PM framework.
* This is for lowering the overhead, and therefore improving
* performance per I/O operation.
*/
un->un_ncmds_in_driver--;
}
/*
* Function: sd_mapblockaddr_iostart
*
* Description: Verify request lies withing the partition limits for
* the indicated minor device. Issue "overrun" buf if
* request would exceed partition range. Converts
* partition-relative block address to absolute.
*
* Context: Can sleep
*
* Issues: This follows what the old code did, in terms of accessing
* some of the partition info in the unit struct without holding
* the mutext. This is a general issue, if the partition info
* can be altered while IO is in progress... as soon as we send
* a buf, its partitioning can be invalid before it gets to the
* device. Probably the right fix is to move partitioning out
* of the driver entirely.
*/
static void
{
int partition;
"sd_mapblockaddr_iostart: entry: buf:0x%p\n", bp);
/*
* If the geometry is not indicated as valid, attempt to access
* removable-media devices, of if the device was opened in
*/
/*
* For removable devices it is possible to start an I/O
* without a media by opening the device in nodelay mode.
* Also for writable CDs there can be many scenarios where
* there is no geometry yet but volume manager is trying to
* issue a read() just because it can see TOC on the CD. So
* do not print a message for removables.
*/
if (!un->un_f_has_removable_media) {
"i/o to invalid geometry\n");
}
return;
}
/* #blocks in partition */
/* Use of a local variable potentially improves performance slightly */
/*
* blocknum is the starting block number of the request. At this
* point it is still relative to the start of the minor device.
*/
/*
* Legacy: If the starting block number is one past the last block
* in the partition, do not set B_ERROR in the buf.
*/
goto error_exit;
}
/*
* Confirm that the first block of the request lies within the
* partition limits. Also the requested number of bytes must be
* a multiple of the system block size.
*/
goto error_exit;
}
/*
* If the requsted # blocks exceeds the available # blocks, that
* is an overrun of the partition.
*/
if (requested_nblocks > available_nblocks) {
/*
* Allocate an "overrun" buf to allow the request to proceed
* for the amount of space available in the partition. The
* amount not transferred will be added into the b_resid
* when the operation is complete. The overrun buf
* replaces the original buf here, and the original buf
* is saved inside the overrun buf, for later use.
*/
/*
* Note: count is an unsigned entity thus it'll NEVER
* be less than 0 so ASSERT the original values are
* correct.
*/
(int (*)(struct buf *)) sd_mapblockaddr_iodone);
}
/* At this point there should be no residual for this buf. */
/* Convert the block number to an absolute address. */
"sd_mapblockaddr_iostart: exit 0: buf:0x%p\n", bp);
return;
"sd_mapblockaddr_iostart: exit 1: buf:0x%p\n", bp);
}
/*
* Function: sd_mapblockaddr_iodone
*
* Description: Completion-side processing for partition management.
*
* Context: May be called under interrupt context
*/
static void
{
/* int partition; */ /* Not used, see below. */
"sd_mapblockaddr_iodone: entry: buf:0x%p\n", bp);
/*
* We have an "overrun" buf to deal with...
*/
/* Retrieve the pointer to the original buf */
/*
* Get back the original buf.
* Note that since the restoration of xb_blkno below
* was removed, the sd_xbuf is not needed.
*/
/*
* xp = SD_GET_XBUF(bp);
* ASSERT(xp != NULL);
*/
}
/*
* Convert sd->xb_blkno back to a minor-device relative value.
* Note: this has been commented out, as it is not needed in the
* current implementation of the driver (ie, since this function
* is at the top of the layering chains, so the info will be
* discarded) and it is in the "hot" IO path.
*
* partition = getminor(bp->b_edev) & SDPART_MASK;
* xp->xb_blkno -= un->un_offset[partition];
*/
"sd_mapblockaddr_iodone: exit: buf:0x%p\n", bp);
}
/*
* Function: sd_mapblocksize_iostart
*
* Description: Convert between system block size (un->un_sys_blocksize)
* and target block size (un->un_tgt_blocksize).
*
* Context: Can sleep to allocate resources.
*
* Assumptions: A higher layer has already performed any partition validation,
* and converted the xp->xb_blkno to an absolute value relative
* to the start of the device.
*
* It is also assumed that the higher layer has implemented
* an "overrun" mechanism for the case where the request would
* assume (and ASSERT) that bp->b_resid == 0.
*
* Note: The implementation for this routine assumes the target
* block size remains constant between allocation and transport.
*/
static void
{
struct sd_mapblocksize_info *bsp;
"sd_mapblocksize_iostart: entry: buf:0x%p\n", bp);
/*
* For a non-writable CD, a write request is an error
*/
return;
}
/*
* We do not need a shadow buf if the device is using
* un->un_sys_blocksize as its block size or if bcount == 0.
* In this case there is no layer-private data block allocated.
*/
goto done;
}
/* We do not support non-block-aligned transfers for ROD devices */
#endif
"tgt_blocksize:0x%x sys_blocksize: 0x%x\n",
/*
* Allocate the layer-private data area for the mapblocksize layer.
* Layers are allowed to use the xp_private member of the sd_xbuf
* struct to store the pointer to their layer-private data block, but
* each layer also has the responsibility of restoring the prior
* higher layer that sent it.
*
* Here we save the prior contents of xp->xb_private into the
* bsp->mbs_oprivate field of our layer-private data area. This value
* is restored by sd_mapblocksize_iodone() just prior to freeing up
* that sent it.
*
* Note that here we use kmem_zalloc for the allocation as there are
* parts of the mapblocksize code that expect certain fields to be
* zero unless explicitly set to a required value.
*/
/*
* This treats the data on the disk (target) as an array of bytes.
* first_byte is the byte offset, from the beginning of the device,
* to the location of the request. This is converted from a
* un->un_sys_blocksize block address to a byte offset, and then back
* to a block address based upon a un->un_tgt_blocksize block size.
*
* xp->xb_blkno should be absolute upon entry into this function,
* but, but it is based upon partitions that use the "system"
* block size. It must be adjusted to reflect the block size of
* the target.
*
* Note that end_block is actually the block that follows the last
* block of the request, but that's what is needed for the computation.
*/
/* request_bytes is rounded up to a multiple of the target block size */
/*
* See if the starting address of the request and the request
* length are aligned on a un->un_tgt_blocksize boundary. If aligned
* then we do not need to allocate a shadow buf to handle the request.
*/
is_aligned = TRUE;
}
/*
* Lock the range for a write operation. An aligned request is
* considered a simple write; otherwise the request must be a
* read-modify-write.
*/
}
/*
* Alloc a shadow buf if the request is not aligned. Also, this is
* where the READ command is generated for a read-modify-write. (The
* write phase is deferred until after the read completes.)
*/
if (is_aligned == FALSE) {
struct sd_mapblocksize_info *shadow_bsp;
/*
* Allocate the shadow buf and it associated xbuf. Note that
* after this call the xb_blkno value in both the original
* buf's sd_xbuf _and_ the shadow buf's sd_xbuf will be the
* same: absolute relative to the start of the device, and
* adjusted for the target block size. The b_blkno in the
* shadow buf will also be set to this value. We should never
* change b_blkno in the original bp however.
*
* Note also that the shadow buf will always need to be a
* READ command, regardless of whether the incoming command
* is a READ or a WRITE.
*/
(int (*)(struct buf *)) sd_mapblocksize_iodone);
/*
* Allocate the layer-private data for the shadow buf.
* (No need to preserve xb_private in the shadow xbuf.)
*/
/*
* bsp->mbs_copy_offset is used later by sd_mapblocksize_iodone
* to figure out where the start of the user data is (based upon
* the system block size) in the data returned by the READ
* command (which will be based upon the target blocksize). Note
* that this is only really used if the request is unaligned.
*/
/* Transfer the wmap (if any) to the shadow buf */
/*
* The shadow buf goes on from here in place of the
* original buf.
*/
}
"sd_mapblocksize_iostart: tgt request len:0x%x\n",
"sd_mapblocksize_iostart: shadow buf:0x%x\n", bp);
done:
"sd_mapblocksize_iostart: exit: buf:0x%p\n", bp);
}
/*
* Function: sd_mapblocksize_iodone
*
* Description: Completion side processing for block-size mapping.
*
* Context: May be called under interrupt context
*/
static void
{
struct sd_mapblocksize_info *bsp;
"sd_mapblocksize_iodone: entry: buf:0x%p\n", bp);
/*
* There is no shadow buf or layer-private data if the target is
* using un->un_sys_blocksize as its block size or if bcount == 0.
*/
goto exit;
}
/* Retrieve the pointer to the layer-private data area from the xbuf. */
if (is_write) {
/*
* For a WRITE request we must free up the block range that
* we have locked up. This holds regardless of whether this is
* an aligned write request or a read-modify-write request.
*/
}
/*
* An aligned read or write command will have no shadow buf;
* there is not much else to do with it.
*/
goto done;
}
/*
* A READ with a wmap means this is the READ phase of a
* read-modify-write. If an error occurred on the READ then
* we do not proceed with the WRITE phase or copy any data.
* Just release the write maps and return with an error.
*/
goto freebuf_done;
}
}
/*
* Here is where we set up to copy the data from the shadow buf
* into the space associated with the original buf.
*
* To deal with the conversion between block sizes, these
* computations treat the data as an array of bytes, with the
* first byte (byte 0) corresponding to the first byte in the
* first block on the disk.
*/
/*
* shadow_start and shadow_len indicate the location and size of
* the data returned with the shadow IO request.
*/
/*
* copy_offset gives the offset (in bytes) from the start of the first
* block of the READ request to the beginning of the data. We retrieve
* this value from xb_pktp in the ORIGINAL xbuf, as it has been saved
* there by sd_mapblockize_iostart(). copy_length gives the amount of
* data to be copied (in bytes).
*/
/*
* Set up the resid and error fields of orig_bp as appropriate.
*/
if (shadow_end >= request_end) {
/* We got all the requested data; set resid to zero */
} else {
/*
* We failed to get enough data to fully satisfy the original
* request. Just copy back whatever data we got and set
* up the residual and error code as required.
*
* 'shortfall' is the amount by which the data received with the
* shadow buf has "fallen short" of the requested amount.
*/
/*
* We did not get enough data to even partially
* fulfill the original request. The residual is
* equal to the amount requested.
*/
} else {
/*
* We did not get all the data that we requested
* from the device, but we will try to return what
* portion we did get.
*/
}
}
/* Propagate the error code from the shadow buf to the original buf */
if (is_write) {
goto freebuf_done; /* No data copying for a WRITE */
}
if (has_wmap) {
/*
* This is a READ command from the READ phase of a
* read-modify-write request. We have to copy the data given
* by the user OVER the data returned by the READ command,
* then convert the command from a READ to a WRITE and send
* it back to the target.
*/
/*
* Dispatch the WRITE command to the taskq thread, which
* will in turn send the command to the target. When the
* WRITE command completes, we (sd_mapblocksize_iodone())
* will get called again as part of the iodone chain
* processing for it. Note that we will still be dealing
* with the shadow buf at that point.
*/
KM_NOSLEEP) != 0) {
/*
* Dispatch was successful so we are done. Return
* without going any higher up the iodone chain. Do
* not free up any layer-private data until after the
* WRITE completes.
*/
return;
}
/*
* Dispatch of the WRITE command failed; set up the error
* condition and send this IO back up the iodone chain.
*/
} else {
/*
* This is a regular READ request (ie, not a RMW). Copy the
* data from the shadow buf into the original buf. The
* copy_offset compensates for any "misalignment" between the
* shadow buf (with its un->un_tgt_blocksize blocks) and the
* original buf (with its un->un_sys_blocksize blocks).
*/
}
/*
* At this point we still have both the shadow buf AND the original
* buf to deal with, as well as the layer-private data area in each.
* Local variables are as follows:
*
* bp -- points to shadow buf
* xp -- points to xbuf of shadow buf
* bsp -- points to layer-private data area of shadow buf
* orig_bp -- points to original buf
*
* First free the shadow buf and its associated xbuf, then free the
* layer-private data area from the shadow buf. There is no need to
* restore xb_private in the shadow xbuf.
*/
/*
* Now update the local variables to point to the original buf, xbuf,
* and layer-private area.
*/
done:
/*
* Restore xb_private to whatever it was set to by the next higher
* layer in the chain, then free the layer-private data area.
*/
exit:
"sd_mapblocksize_iodone: calling SD_NEXT_IODONE: buf:0x%p\n", bp);
}
/*
* Function: sd_checksum_iostart
*
* Description: A stub function for a layer that's currently not used.
* For now just a placeholder.
*
* Context: Kernel thread context
*/
static void
{
}
/*
* Function: sd_checksum_iodone
*
* Description: A stub function for a layer that's currently not used.
* For now just a placeholder.
*
* Context: May be called under interrupt context
*/
static void
{
}
/*
* Function: sd_checksum_uscsi_iostart
*
* Description: A stub function for a layer that's currently not used.
* For now just a placeholder.
*
* Context: Kernel thread context
*/
static void
{
}
/*
* Function: sd_checksum_uscsi_iodone
*
* Description: A stub function for a layer that's currently not used.
* For now just a placeholder.
*
* Context: May be called under interrupt context
*/
static void
{
}
/*
* Function: sd_pm_iostart
*
* Description: iostart-side routine for Power mangement.
*
* Context: Kernel thread context
*/
static void
{
/*
* Set up to return the failed buf back up the 'iodone'
* side of the calling chain.
*/
return;
}
}
/*
* Function: sd_pm_iodone
*
* Description: iodone-side routine for power mangement.
*
* Context: may be called from interrupt context
*/
static void
{
/*
* After attach the following flag is only read, so don't
* take the penalty of acquiring a mutex for it.
*/
sd_pm_exit(un);
}
}
/*
* Function: sd_core_iostart
*
* Description: Primary driver function for enqueuing buf(9S) structs from
* the system and initiating IO to the target device
*
* Context: Kernel thread context. Can sleep.
*
* Assumptions: - The given xp->xb_blkno is absolute
* (ie, relative to the start of the device).
* - The IO is to be done using the native blocksize of
* the device, as specified in un->un_tgt_blocksize.
*/
/* ARGSUSED */
static void
{
/*
* If we are currently in the failfast state, fail any new IO
* that has B_FAILFAST set, then return.
*/
return;
}
if (SD_IS_DIRECT_PRIORITY(xp)) {
/*
* Priority command -- transport it immediately.
*
* Note: We may want to assert that USCSI_DIAGNOSE is set,
* because all direct priority commands should be associated
* with error recovery actions which we don't want to retry.
*/
} else {
/*
* Normal command -- add it to the wait queue, then start
* transporting commands from the wait queue.
*/
}
}
/*
* Function: sd_init_cdb_limits
*
* Description: This is to handle scsi_pkt initialization differences
* between the driver platforms.
*
* Legacy behaviors:
*
* If the block number or the sector count exceeds the
* capabilities of a Group 0 command, shift over to a
* Group 1 command. We don't blindly use Group 1
* commands because a) some drives (CDC Wren IVs) get a
* bit confused, and b) there is probably a fair amount
* of speed difference for a target to receive and decode
* a 10 byte command instead of a 6 byte command.
*
* The xfer time difference of 6 vs 10 byte CDBs is
* still significant so this code is still worthwhile.
* 10 byte CDBs are very inefficient with the fas HBA driver
* and older disks. Each CDB byte took 1 usec with some
* popular disks.
*
* Context: Must be called at attach time
*/
static void
{
int hba_cdb_limit;
/*
* Use CDB_GROUP1 commands for most devices except for
* parallel SCSI fixed drives in which case we get better
* performance using CDB_GROUP0 commands (where applicable).
*/
#if !defined(__fibre)
}
#endif
/*
* Try to read the max-cdb-length supported by HBA.
*/
if (0 >= un->un_max_hba_cdb) {
} else if (0 < un->un_max_hba_cdb &&
} else {
}
/*
* Use CDB_GROUP5 commands for removable devices. Use CDB_GROUP4
* commands for fixed disks unless we are building for a 32 bit
* kernel.
*/
#ifdef _LP64
#else
#endif
/*
* x86 systems require the PKT_DMA_PARTIAL flag
*/
#if defined(__x86)
#else
un->un_pkt_flags = 0;
#endif
? sizeof (struct scsi_arq_status) : 1);
}
/*
* Function: sd_initpkt_for_buf
*
* Description: Allocate and initialize for transport a scsi_pkt struct,
* based upon the info specified in the given buf struct.
*
* Assumes the xb_blkno in the request is absolute (ie,
* relative to the start of the device (NOT partition!).
* Also assumes that the request is using the native block
* size of the device (as returned by the READ CAPACITY
* command).
*
* Return Code: SD_PKT_ALLOC_SUCCESS
* SD_PKT_ALLOC_FAILURE
* SD_PKT_ALLOC_FAILURE_NO_DMA
* SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL
*
* Context: Kernel thread and may be called from software interrupt context
* as part of a sdrunout callback. This function may not block or
* call routines that block
*/
static int
{
int rval;
int cmd_flags;
"sd_initpkt_for_buf: entry: buf:0x%p\n", bp);
/*
* Already have a scsi_pkt -- just need DMA resources.
* We must recompute the CDB in case the mapping returns
* a nonzero pkt_resid.
* Note: if this is a portion of a PKT_DMA_PARTIAL transfer
* will result in the entire transfer starting over again
* from the very first block.
*/
} else {
}
#endif /* __i386 || __amd64 */
#else
#endif
/*
* sd_setup_rw_pkt will determine the appropriate CDB group to use,
* call scsi_init_pkt, and build the CDB.
*/
if (rval == 0) {
/*
* Success.
*
* If partial DMA is being used and required for this transfer.
* set it up here.
*/
/*
* Save the CDB length and pkt_resid for the
* next xfer
*/
/* rezero resid */
} else {
xp->xb_dma_resid = 0;
}
"sd_initpkt_for_buf: exit: buf:0x%p\n", bp);
#endif
return (SD_PKT_ALLOC_SUCCESS);
}
/*
* SD_PKT_ALLOC_FAILURE is the only expected failure code
* from sd_setup_rw_pkt.
*/
if (rval == SD_PKT_ALLOC_FAILURE) {
/*
* Set the driver state to RWAIT to indicate the driver
* is waiting on resource allocations. The driver will not
* suspend, pm_suspend, or detatch while the state is RWAIT.
*/
"sd_initpkt_for_buf: No pktp. exit bp:0x%p\n", bp);
return (SD_PKT_ALLOC_FAILURE_NO_DMA);
}
return (SD_PKT_ALLOC_FAILURE);
} else {
/*
* PKT_ALLOC_FAILURE_CDB_TOO_SMALL
*
* This should never happen. Maybe someone messed with the
* kernel's minphys?
*/
"Request rejected: too large for CDB: "
"sd_initpkt_for_buf: No cp. exit bp:0x%p\n", bp);
return (SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL);
}
}
/*
* Function: sd_destroypkt_for_buf
*
* Description: Free the scsi_pkt(9S) for the given bp (buf IO processing).
*
* Context: Kernel thread or interrupt context
*/
static void
{
"sd_destroypkt_for_buf: entry: buf:0x%p\n", bp);
"sd_destroypkt_for_buf: exit: buf:0x%p\n", bp);
}
/*
* Function: sd_setup_rw_pkt
*
* Description: Determines appropriate CDB group for the requested LBA
* and transfer length, calls scsi_init_pkt, and builds
* the CDB. Do not use for partial DMA transfers except
* for the initial transfer since the CDB size must
* remain constant.
*
* Context: Kernel thread and may be called from software interrupt
* context as part of a sdrunout callback. This function may not
* block or call routines that block
*/
int
{
struct scsi_pkt *return_pktp;
int i;
/*
* See which size CDB to use, based upon the request.
*/
/*
* Check lba and block count against sd_cdbtab limits.
* In the partial DMA case, we have to use the same size
* CDB for all the transfers. Check lba + blockcount
* against the max LBA so we know that segment of the
* transfer can use the CDB we select.
*/
/*
* The command will fit into the CDB type
* specified by sd_cdbtab[i].
*/
/*
* Call scsi_init_pkt so we can fill in the
* CDB.
*/
if (return_pktp != NULL) {
/*
* Return new value of pkt
*/
*pktpp = return_pktp;
/*
* To be safe, zero the CDB insuring there is
* no leftover data from a previous command.
*/
/*
* Handle partial DMA mapping
*/
if (return_pktp->pkt_resid != 0) {
/*
* Not going to xfer as many blocks as
* originally expected
*/
blockcount -=
}
/*
* Set command byte based on the CDB
* type we matched.
*/
SCMD_READ : SCMD_WRITE);
/*
* Fill in LBA and length
*/
return (0);
return (0);
return (0);
return (0);
}
/*
* It should be impossible to not match one
* of the CDB types above, so we should never
* reach this point. Set the CDB command byte
* to test-unit-ready to avoid writing
* to somewhere we don't intend.
*/
return (SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL);
} else {
/*
* Couldn't get scsi_pkt
*/
return (SD_PKT_ALLOC_FAILURE);
}
}
}
/*
* None of the available CDB types were suitable. This really
* should never happen: on a 64 bit system we support
* and on a 32 bit system we will refuse to bind to a device
* larger than 2TB so addresses will never be larger than 32 bits.
*/
return (SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL);
}
/*
* Function: sd_setup_next_rw_pkt
*
* Description: Setup packet for partial DMA transfers, except for the
* initial transfer. sd_setup_rw_pkt should be used for
* the initial transfer.
*
* Context: Kernel thread and may be called from interrupt context.
*/
int
{
(cdb_group_id == CDB_GROUPID_1) ||
(cdb_group_id == CDB_GROUPID_4) ||
(cdb_group_id == CDB_GROUPID_5));
/*
* Move pkt to the next portion of the xfer.
* func is NULL_FUNC so we do not have to release
* the disk mutex here.
*/
/* Success. Handle partial DMA */
blockcount -=
}
if (cdb_group_id == CDB_GROUPID_1) {
return (0);
} else if (cdb_group_id == CDB_GROUPID_4) {
return (0);
} else if (cdb_group_id == CDB_GROUPID_0) {
return (0);
} else if (cdb_group_id == CDB_GROUPID_5) {
return (0);
}
/* Unreachable */
return (SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL);
}
/*
* Error setting up next portion of cmd transfer.
* Something is definitely very wrong and this
* should not happen.
*/
return (SD_PKT_ALLOC_FAILURE);
}
#endif /* defined(__i386) || defined(__amd64) */
/*
* Function: sd_initpkt_for_uscsi
*
* Description: Allocate and initialize for transport a scsi_pkt struct,
* based upon the info specified in the given uscsi_cmd struct.
*
* Return Code: SD_PKT_ALLOC_SUCCESS
* SD_PKT_ALLOC_FAILURE
* SD_PKT_ALLOC_FAILURE_NO_DMA
* SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL
*
* Context: Kernel thread and may be called from software interrupt context
* as part of a sdrunout callback. This function may not block or
* call routines that block
*/
static int
{
/* The pointer to the uscsi_cmd struct is expected in xb_pktinfo */
"sd_initpkt_for_uscsi: entry: buf:0x%p\n", bp);
/*
* Allocate the scsi_pkt for the command.
* Note: If PKT_DMA_PARTIAL flag is set, scsi_vhci binds a path
* during scsi_init_pkt time and will continue to use the
* same path as long as the same scsi_pkt is used without
* intervening scsi_dma_free(). Since uscsi command does
* not call scsi_dmafree() before retry failed command, it
* is necessary to make sure PKT_DMA_PARTIAL flag is NOT
* set such that scsi_vhci can use other available path for
* retry. Besides, ucsci command does not allow DMA breakup,
* so there is no need to set PKT_DMA_PARTIAL flag.
*/
sizeof (struct scsi_arq_status), 0,
/*
* Set the driver state to RWAIT to indicate the driver
* is waiting on resource allocations. The driver will not
* suspend, pm_suspend, or detatch while the state is RWAIT.
*/
"sd_initpkt_for_uscsi: No pktp. exit bp:0x%p\n", bp);
return (SD_PKT_ALLOC_FAILURE_NO_DMA);
}
return (SD_PKT_ALLOC_FAILURE);
}
/*
* We do not do DMA breakup for USCSI commands, so return failure
* here if all the needed DMA resources were not allocated.
*/
"No partial DMA for USCSI. exit: buf:0x%p\n", bp);
return (SD_PKT_ALLOC_FAILURE_PKT_TOO_SMALL);
}
/* Init the cdb from the given uscsi struct */
/*
* Set up the optional USCSI flags. See the uscsi (7I) man page
* for listing of the supported flags.
*/
flags |= FLAG_SILENT;
}
flags |= FLAG_DIAGNOSE;
}
flags |= FLAG_ISOLATE;
}
}
}
/*
* Set the pkt flags here so we save time later.
* Note: These flags are NOT in the uscsi man page!!!
*/
}
flags |= FLAG_NOINTR;
}
/*
* For tagged queueing, things get a bit complicated.
* Check first for head of queue and last for ordered queue.
* If neither head nor order, use the default driver tag flags.
*/
} else {
}
}
}
/* Copy the caller's CDB into the pkt... */
if (uscmd->uscsi_timeout == 0) {
} else {
}
/* need it later to identify USCSI request in sdintr */
"sd_initpkt_for_uscsi: exit: buf:0x%p\n", bp);
return (SD_PKT_ALLOC_SUCCESS);
}
/*
* Function: sd_destroypkt_for_uscsi
*
* Description: Free the scsi_pkt(9S) struct for the given bp, for uscsi
* IOs.. Also saves relevant info into the associated uscsi_cmd
* struct.
*
* Context: May be called under interrupt context
*/
static void
{
"sd_destroypkt_for_uscsi: entry: buf:0x%p\n", bp);
/* The pointer to the uscsi_cmd struct is expected in xb_pktinfo */
/* Save the status and the residual into the uscsi_cmd struct */
/*
* If enabled, copy any saved sense data into the area specified
* by the uscsi command.
*/
/*
* Note: uscmd->uscsi_rqbuf should always point to a buffer
* at least SENSE_LENGTH bytes in size (see sd_send_scsi_cmd())
*/
}
/* We are done with the scsi_pkt; free it now */
"sd_destroypkt_for_uscsi: exit: buf:0x%p\n", bp);
}
/*
* Function: sd_bioclone_alloc
*
* Description: Allocate a buf(9S) and init it as per the given buf
* and the various arguments. The associated sd_xbuf
* struct is (nearly) duplicated. The struct buf *bp
* argument is saved in new_xp->xb_private.
*
* Arguments: bp - ptr the the buf(9S) to be "shadowed"
* datalen - size of data area for the shadow bp
* blkno - starting LBA
* func - function pointer for b_iodone in the shadow buf. (May
* be NULL if none.)
*
* Return Code: Pointer to allocates buf(9S) struct
*
* Context: Can sleep.
*/
static struct buf *
{
/*
* Allocate an xbuf for the shadow bp and copy the contents of the
* original xbuf into it.
*/
/*
* The given bp is automatically saved in the xb_private member
* of the new xbuf. Callers are allowed to depend on this.
*/
return (new_bp);
}
/*
* Function: sd_shadow_buf_alloc
*
* Description: Allocate a buf(9S) and init it as per the given buf
* and the various arguments. The associated sd_xbuf
* struct is (nearly) duplicated. The struct buf *bp
* argument is saved in new_xp->xb_private.
*
* Arguments: bp - ptr the the buf(9S) to be "shadowed"
* datalen - size of data area for the shadow bp
* bflags - B_READ or B_WRITE (pseudo flag)
* blkno - starting LBA
* func - function pointer for b_iodone in the shadow buf. (May
* be NULL if none.)
*
* Return Code: Pointer to allocates buf(9S) struct
*
* Context: Can sleep.
*/
static struct buf *
{
}
#else
#endif
/* We need to preserve the B_FAILFAST flag */
}
/*
* Allocate an xbuf for the shadow bp and copy the contents of the
* original xbuf into it.
*/
/* Need later to copy data between the shadow buf & original buf! */
/*
* The given bp is automatically saved in the xb_private member
* of the new xbuf. Callers are allowed to depend on this.
*/
return (new_bp);
}
/*
* Function: sd_bioclone_free
*
* Description: Deallocate a buf(9S) that was used for 'shadow' IO operations
* in the larger than partition operation.
*
* Context: May be called under interrupt context
*/
static void
{
/*
* Call bp_mapout() before freeing the buf, in case a lower
* layer or HBA had done a bp_mapin(). we must do this here
* as we are the "originator" of the shadow buf.
*/
/*
* Null out b_iodone before freeing the bp, to ensure that the driver
* never gets confused by a stale value in this field. (Just a little
* extra defensiveness here.)
*/
}
/*
* Function: sd_shadow_buf_free
*
* Description: Deallocate a buf(9S) that was used for 'shadow' IO operations.
*
* Context: May be called under interrupt context
*/
static void
{
#if defined(__sparc)
/*
* Call bp_mapout() before freeing the buf, in case a lower
* layer or HBA had done a bp_mapin(). we must do this here
* as we are the "originator" of the shadow buf.
*/
#endif
/*
* Null out b_iodone before freeing the bp, to ensure that the driver
* never gets confused by a stale value in this field. (Just a little
* extra defensiveness here.)
*/
#else
#endif
}
/*
* Function: sd_print_transport_rejected_message
*
* Description: This implements the ludicrously complex rules for printing
* a "transport rejected" message. This is to address the
* specific problem of having a flood of this error message
* produced when a failover occurs.
*
* Context: Any.
*/
static void
int code)
{
/*
* Print the "transport rejected" message under the following
* conditions:
*
* - Whenever the SD_LOGMASK_DIAG bit of sd_level_mask is set
* - The error code from scsi_transport() is NOT a TRAN_FATAL_ERROR.
* - If the error code IS a TRAN_FATAL_ERROR, then the message is
* printed the FIRST time a TRAN_FATAL_ERROR is returned from
* scsi_transport(9F) (which indicates that the target might have
* gone off-line). This uses the un->un_tran_fatal_count
* count, which is incremented whenever a TRAN_FATAL_ERROR is
* received, and reset to zero whenver a TRAN_ACCEPT is returned
* from scsi_transport().
*
* The FLAG_SILENT in the scsi_pkt must be CLEARED in ALL of
* the preceeding cases in order for the message to be printed.
*/
if ((sd_level_mask & SD_LOGMASK_DIAG) ||
(code != TRAN_FATAL_ERROR) ||
switch (code) {
case TRAN_BADPKT:
"transport rejected bad packet\n");
break;
case TRAN_FATAL_ERROR:
"transport rejected fatal error\n");
break;
default:
"transport rejected (%d)\n", code);
break;
}
}
}
}
/*
* Function: sd_add_buf_to_waitq
*
* Description: Add the given buf(9S) struct to the wait queue for the
* instance. If sorting is enabled, then the buf is added
* to the queue via an elevator sort algorithm (a la
* disksort(9F)). The SD_GET_BLKNO(bp) is used as the sort key.
* If sorting is not enabled, then the buf is just added
* to the end of the wait queue.
*
* Return Code: void
*
* from any context. However if sorting is enabled then the
* execution time is indeterminate, and may take long if
* the wait queue grows large.
*/
static void
{
/* If the queue is empty, add the buf as the only entry & return. */
return;
}
/*
* If sorting is disabled, just add the buf to the tail end of
* the wait queue and return.
*/
if (un->un_f_disksort_disabled) {
return;
}
/*
* Sort thru the list of requests currently on the wait queue
* and add the new buf request at the appropriate position.
*
* The un->un_waitq_headp is an activity chain pointer on which
* we keep two queues, sorted in ascending SD_GET_BLKNO() order. The
* first queue holds those requests which are positioned after
* the current SD_GET_BLKNO() (in the first request); the second holds
* requests which came in after their SD_GET_BLKNO() number was passed.
* Thus we implement a one way scan, retracting after reaching
* the end of the drive to the first request on the second
* queue, at which time it becomes the first queue.
* A one-way scan is natural because of the way UNIX read-ahead
* blocks are allocated.
*
* If we lie after the first request, then we must locate the
* second request list and add ourselves to it.
*/
/*
* Look for an "inversion" in the (normally
* ascending) block numbers. This indicates
* the start of the second request list.
*/
/*
* Search the second request list for the
* first request at a larger block number.
* We go before that; however if there is
* no such request, we go at the end.
*/
do {
if (SD_GET_BLKNO(bp) <
goto insert;
}
goto insert; /* after last */
}
}
/*
* No inversions... we will go after the last, and
* be the first request in the second request list.
*/
goto insert;
}
/*
* sort in the first request list.
*/
/*
* We want to go after the current request (1) if
* there is an inversion after it (i.e. it is the end
* of the first request list), or (2) if the next
* request is a larger block no. than our request.
*/
goto insert;
}
}
/*
* Neither a second list nor a larger request, therefore
* we go at the end of the first list (which is the same
* as the end of the whole schebang).
*/
/*
* If we inserted onto the tail end of the waitq, make sure the
* tail pointer is updated.
*/
}
}
/*
* Function: sd_start_cmds
*
* Description: Remove and transport cmds from the driver queues.
*
* Arguments: un - pointer to the unit (soft state) struct for the target.
*
* immed_bp - ptr to a buf to be transported immediately. Only
* the immed_bp is transported; bufs on the waitq are not
* processed and the un_retry_bp is not checked. If immed_bp is
* NULL, then normal queue processing is performed.
*
* Context: May be called from kernel thread context, interrupt context,
* or runout callback context. This function may not block or
* call routines that block.
*/
static void
{
void (*statp)(kstat_io_t *);
void (*saved_statp)(kstat_io_t *);
#endif
int rval;
do {
saved_statp = NULL;
#endif
/*
* If we are syncing or dumping, fail the command to
* avoid recursively calling back into scsi_transport().
* The dump I/O itself uses a separate code path so this
* only prevents non-dump I/O from being sent while dumping.
* File system sync takes place before dumping begins.
* During panic, filesystem I/O is allowed provided
* un_in_callback is <= 1. This is to prevent recursion
* such as sd_start_cmds -> scsi_transport -> sdintr ->
* sd_start_cmds and so on. See panic.c for more information
* about the states the system can be in during panic.
*/
"sd_start_cmds: panicking\n");
goto exit;
}
/*
* We have a bp that must be transported immediately.
* It's OK to transport the immed_bp here without doing
* the throttle limit check because the immed_bp is
* that we know we are not at the throttle limit by
* virtue of the fact that to get here we must have
* already gotten a command back via sdintr(). This also
* relies on (1) the command on un_retry_bp preventing
* further commands from the waitq from being issued;
* and (2) the code in sd_retry_command checking the
* throttle limit before issuing a delayed or immediate
* retry. This holds even if the throttle limit is
* currently ratcheted down from its maximum value.
*/
(un->un_retry_statp ==
/*
* If the waitq kstat was incremented when
* sd_set_retry_bp() queued this bp for a retry,
* then we must set up statp so that the waitq
* count will get decremented correctly below.
* Also we must clear un->un_retry_statp to
* ensure that we do not act on a stale value
* in this field.
*/
(un->un_retry_statp ==
}
#endif
"sd_start_cmds: un:0x%p: GOT retry_bp:0x%p "
"un_throttle:%d un_ncmds_in_transport:%d\n",
} else {
"processing priority bp:0x%p\n", bp);
}
/*
* A command on the waitq is ready to go, but do not
* send it if:
*
* (1) the throttle limit has been reached, or
* (2) a retry is pending, or
* (3) a START_STOP_UNIT callback pending, or
* (4) a callback for a SD_PATH_DIRECT_PRIORITY
* command is pending.
*
* For all of these conditions, IO processing will
* restart after the condition is cleared.
*/
"sd_start_cmds: exiting, "
"throttle limit reached!\n");
goto exit;
}
"sd_start_cmds: exiting, retry pending!\n");
goto exit;
}
"sd_start_cmds: exiting, "
"START_STOP pending!\n");
goto exit;
}
"sd_start_cmds: exiting, "
"SD_PATH_DIRECT_PRIORITY cmd. pending!\n");
goto exit;
}
/* Dequeue the command */
}
"sd_start_cmds: processing waitq bp:0x%p\n", bp);
} else {
/* No work to do so bail out now */
"sd_start_cmds: no more work, exiting!\n");
goto exit;
}
/*
* Reset the state to normal. This is the mechanism by which
* the state transitions from either SD_STATE_RWAIT or
* SD_STATE_OFFLINE to SD_STATE_NORMAL.
* If state is SD_STATE_PM_CHANGING then this command is
* part of the device power control and the state must
* not be put back to normal. Doing so would would
* allow new commands to proceed when they shouldn't,
* the device may be going off.
*/
}
/*
* Allocate the scsi_pkt if we need one, or attach DMA
* resources if we have a scsi_pkt that needs them. The
* latter should only occur for commands that are being
* retried.
*/
#else
#endif
/*
* There is no scsi_pkt allocated for this buf. Call
* the initpkt function to allocate & init one.
*
* The scsi_init_pkt runout callback functionality is
* implemented as follows:
*
* 1) The initpkt function always calls
* scsi_init_pkt(9F) with sdrunout specified as the
* callback routine.
* 2) A successful packet allocation is initialized and
* the I/O is transported.
* 3) The I/O associated with an allocation resource
* failure is left on its queue to be retried via
* runout or the next I/O.
* 4) The I/O associated with a DMA error is removed
* from the queue and failed with EIO. Processing of
* the transport queues is also halted to be
* restarted via runout or the next I/O.
* 5) The I/O associated with a CDB size or packet
* size error is removed from the queue and failed
* with EIO. Processing of the transport queues is
* continued.
*
* Note: there is no interface for canceling a runout
* callback. To prevent the driver from detaching or
* suspending while a runout is pending the driver
* state is set to SD_STATE_RWAIT
*
* Note: using the scsi_init_pkt callback facility can
* result in an I/O request persisting at the head of
* the list which cannot be satisfied even after
* multiple retries. In the future the driver may
* implement some kind of maximum runout count before
* failing an I/O.
*
* Note: the use of funcp below may seem superfluous,
* but it helps warlock figure out the correct
* initpkt function calls (see [s]sd.wlcmd).
*/
case SD_PKT_ALLOC_SUCCESS:
"sd_start_cmd: SD_PKT_ALLOC_SUCCESS 0x%p\n",
pktp);
goto got_pkt;
case SD_PKT_ALLOC_FAILURE:
/*
* Temporary (hopefully) resource depletion.
* Since retries and RQS commands always have a
* scsi_pkt allocated, these cases should never
* get here. So the only cases this needs to
* handle is a bp from the waitq (which we put
* back onto the waitq for sdrunout), or a bp
* sent as an immed_bp (which we just fail).
*/
"sd_start_cmds: SD_PKT_ALLOC_FAILURE\n");
/*
* If SD_XB_DMA_FREED is clear, then
* this is a failure to allocate a
* scsi_pkt, and we must fail the
* command.
*/
if ((xp->xb_pkt_flags &
SD_XB_DMA_FREED) == 0) {
break;
}
/*
* If this immediate command is NOT our
* un_retry_bp, then we must fail it.
*/
break;
}
/*
* We get here if this cmd is our
* un_retry_bp that was DMAFREED, but
* scsi_init_pkt() failed to reallocate
* DMA resources when we attempted to
* retry it. This can happen when an
* mpxio failover is in progress, but
* we don't want to just fail the
* command in this case.
*
* Use timeout(9F) to restart it after
* a 100ms delay. We don't want to
* let sdrunout() restart it, because
* sdrunout() is just supposed to start
* commands that are sitting on the
* wait queue. The un_retry_bp stays
* set until the command completes, but
* sdrunout can be called many times
* before that happens. Since sdrunout
* cannot tell if the un_retry_bp is
* already in the transport, it could
* end up calling scsi_transport() for
* the un_retry_bp multiple times.
*
* Also: don't schedule the callback
* if some other callback is already
* pending.
*/
/*
* restore the kstat pointer to
* keep kstat counts coherent
* when we do retry the command.
*/
un->un_retry_statp =
}
NULL)) {
}
goto exit;
}
#else
break; /* Just fail the command */
}
#endif
/* Add the buf back to the head of the waitq */
}
goto exit;
/*
* HBA DMA resource failure. Fail the command
* and continue processing of the queues.
*/
"sd_start_cmds: "
"SD_PKT_ALLOC_FAILURE_NO_DMA\n");
break;
/*
* Note:x86: Partial DMA mapping not supported
* for USCSI commands, and all the needed DMA
* resources were not allocated.
*/
"sd_start_cmds: "
"SD_PKT_ALLOC_FAILURE_PKT_TOO_SMALL\n");
break;
/*
* Note:x86: Request cannot fit into CDB based
* on lba and len.
*/
"sd_start_cmds: "
"SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL\n");
break;
default:
/* Should NEVER get here! */
panic("scsi_initpkt error");
/*NOTREACHED*/
}
/*
* Fatal error in allocating a scsi_pkt for this buf.
* Update kstats & return the buf with an error code.
* We must use sd_return_failed_command_no_restart() to
* avoid a recursive call back into sd_start_cmds().
* However this also means that we must keep processing
* the waitq here in order to avoid stalling.
*/
if (statp == kstat_waitq_to_runq) {
}
/* immed_bp is gone by now, so clear this */
}
continue;
}
/* goto the head of the class.... */
}
/*
* Call scsi_transport() to send the command to the target.
* According to SCSA architecture, we must drop the mutex here
* before calling scsi_transport() in order to avoid deadlock.
* Note that the scsi_pkt's completion routine can be executed
* (from interrupt context) even before the call to
* scsi_transport() returns.
*/
"sd_start_cmds: calling scsi_transport()\n");
"sd_start_cmds: scsi_transport() returned %d\n", rval);
switch (rval) {
case TRAN_ACCEPT:
/* Clear this with every pkt accepted by the HBA */
un->un_tran_fatal_count = 0;
break; /* Success; try the next cmd (if any) */
case TRAN_BUSY:
/*
* Don't retry request sense, the sense data
* is lost when another request is sent.
* Free up the rqs buf and retry
* the original failed cmd. Update kstat.
*/
goto exit;
}
/*
* Free the DMA resources for the scsi_pkt. This will
* allow mpxio to select another path the next time
* we call scsi_transport() with this scsi_pkt.
* See sdintr() for the rationalization behind this.
*/
}
#endif
/*
* Commands that are SD_PATH_DIRECT_PRIORITY
* are for error recovery situations. These do
* not use the normal command waitq, so if they
* get a TRAN_BUSY we cannot put them back onto
* the waitq for later retry. One possible
* problem is that there could already be some
* other command on un_retry_bp that is waiting
* for this one to complete, so we would be
* deadlocked if we put this command back onto
* the waitq for later retry (since un_retry_bp
* must complete before the driver gets back to
* commands on the waitq).
*
* To avoid deadlock we must schedule a callback
* that will restart this command after a set
* interval. This should keep retrying for as
* long as the underlying transport keeps
* returning TRAN_BUSY (just like for other
* commands). Use the same timeout interval as
* for the ordinary TRAN_BUSY retry.
*/
"sd_start_cmds: scsi_transport() returned "
"TRAN_BUSY for DIRECT_PRIORITY cmd!\n");
goto exit;
}
/*
* For TRAN_BUSY, we want to reduce the throttle value,
* unless we are retrying a command.
*/
}
/*
* Set up the bp to be tried again 10 ms later.
* Note:x86: Is there a timeout value in the sd_lun
* for this condition?
*/
goto exit;
case TRAN_FATAL_ERROR:
/* FALLTHRU */
case TRAN_BADPKT:
default:
/*
* If this is our REQUEST SENSE command with a
* transport error, we must get back the pointers
* to the original buf, and mark the REQUEST
* SENSE command as "available".
*/
} else {
/*
* Legacy behavior: do not update transport
* error count for request sense commands.
*/
}
/*
* We must use sd_return_failed_command_no_restart() to
* avoid a recursive call back into sd_start_cmds().
* However this also means that we must keep processing
* the waitq here in order to avoid stalling.
*/
/*
* Notify any threads waiting in sd_ddi_suspend() that
* a command completion has occurred.
*/
}
/* immed_bp is gone by now, so clear this */
}
break;
}
exit:
}
/*
* Function: sd_return_command
*
* Description: Returns a command to its originator (with or without an
* error). Also starts commands waiting to be transported
* to the target.
*
* Context: May be called from interrupt, kernel, or timeout context
*/
static void
{
#endif
#endif
/*
* Note:x86: check for the "sdrestart failed" case.
*/
/*
* Successfully set up next portion of cmd
* transfer, try sending it
*/
return; /* Note:x86: need a return here? */
}
}
#endif
/*
* If this is the failfast bp, clear it from un_failfast_bp. This
* can happen if upon being re-tried the failfast bp either
* succeeded or encountered another error (possibly even a different
* error than the one that precipitated the failfast state, but in
* that case it would have had to exhaust retries as well). Regardless,
* this should not occur whenever the instance is in the active
* failfast state.
*/
}
/*
* Clear the failfast state upon successful completion of ANY cmd.
*/
}
/*
* This is used if the command was retried one or more times. Show that
* we are done with it, and allow processing of the waitq to resume.
*/
"sd_return_command: un:0x%p: "
}
case SD_STATE_SUSPENDED:
/*
* Notify any threads waiting in sd_ddi_suspend() that
* a command completion has occurred.
*/
break;
default:
break;
}
/* Return this command up the iodone chain to its originator. */
}
/*
* Function: sd_return_failed_command
*
* Description: Command completion when an error occurred.
*
* Context: May be called from interrupt context
*/
static void
{
"sd_return_failed_command: entry\n");
/*
* b_resid could already be nonzero due to a partial data
* transfer, so do not change it here.
*/
"sd_return_failed_command: exit\n");
}
/*
* Function: sd_return_failed_command_no_restart
*
* Description: Same as sd_return_failed_command, but ensures that no
* call back into sd_start_cmds will be issued.
*
* Context: May be called from interrupt context
*/
static void
int errcode)
{
"sd_return_failed_command_no_restart: entry\n");
/*
* b_resid could already be nonzero due to a partial data
* transfer, so do not change it here.
*/
/*
* If this is the failfast bp, clear it. This can happen if the
* failfast bp encounterd a fatal error when we attempted to
* re-try it (such as a scsi_transport(9F) failure). However
* we should NOT be in an active failfast state if the failfast
* bp is not NULL.
*/
}
/*
* This command was retried one or more times. Show that we are
* done with it, and allow processing of the waitq to resume.
*/
"sd_return_failed_command_no_restart: "
}
}
"sd_return_failed_command_no_restart: exit\n");
}
/*
* Function: sd_retry_command
*
* Description: queue up a command for retry, or (optionally) fail it
* if retry counts are exhausted.
*
* Arguments: un - Pointer to the sd_lun struct for the target.
*
* bp - Pointer to the buf for the command to be retried.
*
* retry_check_flag - Flag to see which (if any) of the retry
* counts should be decremented/checked. If the indicated
* retry count is exhausted, then the command will not be
* retried; it will be failed instead. This should use a
* value equal to one of the following:
*
* SD_RETRIES_NOCHECK
* SD_RESD_RETRIES_STANDARD
* SD_RETRIES_VICTIM
*
* Optionally may be bitwise-OR'ed with SD_RETRIES_ISOLATE
* if the check should be made to see of FLAG_ISOLATE is set
* in the pkt. If FLAG_ISOLATE is set, then the command is
* not retried, it is simply failed.
*
* user_funcp - Ptr to function to call before dispatching the
* command. May be NULL if no action needs to be performed.
* (Primarily intended for printing messages.)
*
* user_arg - Optional argument to be passed along to
* the user_funcp call.
*
* failure_code - errno return code to set in the bp if the
* command is going to be failed.
*
* retry_delay - Retry delay interval in (clock_t) units. May
* be zero which indicates that the retry should be retried
* immediately (ie, without an intervening delay).
*
* statp - Ptr to kstat function to be updated if the command
* is queued for a delayed retry. May be NULL if no kstat
* update is desired.
*
* Context: May be called from interupt context.
*/
static void
void (*statp)(kstat_io_t *))
{
/*
* If we are syncing or dumping, fail the command to avoid
* recursively calling back into scsi_transport().
*/
if (ddi_in_panic()) {
goto fail_command_no_log;
}
/*
* We should never be be retrying a command with FLAG_DIAGNOSE set, so
* log an error and fail the command.
*/
"ERROR, retrying FLAG_DIAGNOSE command.\n");
goto fail_command;
}
/*
* If we are suspended, then put the command onto head of the
* wait queue since we don't want to start more commands.
*/
case SD_STATE_SUSPENDED:
case SD_STATE_DUMPING:
}
return;
default:
break;
}
/*
* If the caller wants us to check FLAG_ISOLATE, then see if that
* is set; if it is then we do not want to retry the command.
* Normally, FLAG_ISOLATE is only used with USCSI cmds.
*/
if ((retry_check_flag & SD_RETRIES_ISOLATE) != 0) {
goto fail_command;
}
}
/*
* If SD_RETRIES_FAILFAST is set, it indicates that either a
* command timeout or a selection timeout has occurred. This means
* that we were unable to establish an kind of communication with
* to encounter similar results and take a long time to complete.
*
* If this is a failfast error condition, we need to update the
* failfast state, even if this bp does not have B_FAILFAST set.
*/
if (retry_check_flag & SD_RETRIES_FAILFAST) {
/*
* If we are already in the active failfast state, and
* another failfast error condition has been detected,
* then fail this command if it has B_FAILFAST set.
* If B_FAILFAST is clear, then maintain the legacy
* behavior of retrying heroically, even tho this will
* take a lot more time to fail the command.
*/
goto fail_command;
}
} else {
/*
* We're not in the active failfast state, but we
* have a failfast error condition, so we must begin
* transition to the next state. We do this regardless
* of whether or not this bp has B_FAILFAST set.
*/
/*
* This is the first bp to meet a failfast
* condition so save it on un_failfast_bp &
* do normal retry processing. Do not enter
* active failfast state yet. This marks
* entry into the "failfast pending" state.
*/
/*
* This is the second time *this* bp has
* encountered a failfast error condition,
* so enter active failfast state & flush
* queues as appropriate.
*/
/*
* Fail this bp now if B_FAILFAST set;
* otherwise continue with retries. (It would
* be pretty ironic if this bp succeeded on a
* subsequent retry after we just flushed all
* the queues).
*/
goto fail_command;
}
} else {
/*
* If neither of the preceeding conditionals
* was true, it means that there is some
* *other* bp that has met an inital failfast
* condition and is currently either being
* retried or is waiting to be retried. In
* that case we should perform normal retry
* processing on *this* bp, since there is a
* chance that the current failfast condition
* is transient and recoverable. If that does
* not turn out to be the case, then retries
* will be cleared when the wait queue is
* flushed anyway.
*/
#endif
}
}
} else {
/*
* SD_RETRIES_FAILFAST is clear, which indicates that we
* likely were able to at least establish some level of
* communication with the target and subsequent commands
* In this case we want to be aggressive about clearing
* the failfast state. Note that this does not affect
* the "failfast pending" condition.
*/
}
/*
* Check the specified retry count to see if we can still do
* any retries with this pkt before we should fail it.
*/
switch (retry_check_flag & SD_RETRIES_MASK) {
case SD_RETRIES_VICTIM:
/*
* Check the victim retry count. If exhausted, then fall
* thru & check against the standard retry count.
*/
/* Increment count & proceed with the retry */
break;
}
/* Victim retries exhausted, fall back to std. retries... */
/* FALLTHRU */
case SD_RETRIES_STANDARD:
/* Retries exhausted, fail the command */
"sd_retry_command: retries exhausted!\n");
/*
* update b_resid for failed SCMD_READ & SCMD_WRITE
* commands with nonzero pkt_resid.
*/
}
}
goto fail_command;
}
xp->xb_retry_count++;
break;
case SD_RETRIES_UA:
/* Retries exhausted, fail the command */
"Unit Attention retries exhausted. "
"Check the target.\n");
goto fail_command;
}
xp->xb_ua_retry_count++;
"sd_retry_command: retry count:%d\n",
break;
case SD_RETRIES_BUSY:
/* Retries exhausted, fail the command */
"sd_retry_command: retries exhausted!\n");
goto fail_command;
}
xp->xb_retry_count++;
break;
case SD_RETRIES_NOCHECK:
default:
/* No retry count to check. Just proceed with the retry */
break;
}
/*
* If we were given a zero timeout, we must attempt to retry the
* command immediately (ie, without a delay).
*/
if (retry_delay == 0) {
/*
* Check some limiting conditions to see if we can actually
* do the immediate retry. If we cannot, then we must
* fall back to queueing up a delayed retry.
*/
/*
* We are at the throttle limit for the target,
* fall back to delayed retry.
*/
"sd_retry_command: immed. retry hit "
"throttle!\n");
} else {
/*
* We're clear to proceed with the immediate retry.
* First call the user-provided function (if any)
*/
if (user_funcp != NULL) {
#ifdef __lock_lint
#endif
}
"sd_retry_command: issuing immediate retry\n");
/*
* Call sd_start_cmds() to transport the command to
* the target.
*/
"sd_retry_command exit\n");
return;
}
}
/*
* Set up to retry the command after a delay.
* First call the user-provided function (if any)
*/
if (user_funcp != NULL) {
}
return;
if (user_funcp != NULL) {
}
"sd_retry_command: returning failed command\n");
}
/*
* Function: sd_set_retry_bp
*
* Description: Set up the given bp for retry.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* retry_delay - time interval before issuing retry (may be 0)
* statp - optional pointer to kstat function
*
* Context: May be called under interrupt context
*/
static void
void (*statp)(kstat_io_t *))
{
/*
* Indicate that the command is being retried. This will not allow any
* other commands on the wait queue to be transported to the target
* until this command has been completed (success or failure). The
* "retry command" is not transported to the target until the given
* time delay expires, unless the user specified a 0 retry_delay.
*
* Note: the timeout(9F) callback routine is what actually calls
* sd_start_cmds() to transport the command, with the exception of a
* zero retry_delay. The only current implementor of a zero retry delay
* is the case where a START_STOP_UNIT is sent to spin-up a device.
*/
/*
* If the user has not specified a delay the command should
* be queued and no timeout should be scheduled.
*/
if (retry_delay == 0) {
/*
* Save the kstat pointer that will be used in the
* call to SD_UPDATE_KSTATS() below, so that
* sd_start_cmds() can correctly decrement the waitq
* count when it is time to transport this command.
*/
goto done;
}
}
/*
* Save the kstat pointer that will be used in the call to
* SD_UPDATE_KSTATS() below, so that sd_start_cmds() can
* correctly decrement the waitq count when it is time to
* transport this command.
*/
/*
* Schedule a timeout if:
* 1) The user has specified a delay.
* 2) There is not a START_STOP_UNIT callback pending.
*
* If no delay has been specified, then it is up to the caller
* to ensure that IO processing continues without stalling.
* Effectively, this means that the caller will issue the
* required call to sd_start_cmds(). The START_STOP_UNIT
* callback does this after the START STOP UNIT command has
* completed. In either of these cases we should not schedule
* a timeout callback here. Also don't schedule the timeout if
* an SD_PATH_DIRECT_PRIORITY command is waiting to restart.
*/
"sd_set_retry_bp: setting timeout: un: 0x%p"
" bp:0x%p un_retry_timeid:0x%p\n",
}
} else {
/*
* We only get in here if there is already another command
* waiting to be retried. In this case, we just put the
* given command onto the wait queue, so it can be transported
* after the current retry command has completed.
*
* Also we have to make sure that if the command at the head
* of the wait queue is the un_failfast_bp, that we do not
* put ahead of it any other commands that are to be retried.
*/
/*
* Enqueue this command AFTER the first command on
* the wait queue (which is also un_failfast_bp).
*/
}
} else {
/* Enqueue this command at the head of the waitq. */
}
}
}
"sd_set_retry_bp: un:0x%p already delayed retry\n", un);
}
done:
}
"sd_set_retry_bp: exit un:0x%p\n", un);
}
/*
* Function: sd_start_retry_command
*
* Description: Start the command that has been waiting on the target's
* retry queue. Called from timeout(9F) context after the
* retry delay interval has expired.
*
* Arguments: arg - pointer to associated softstate for the device.
*
* Context: timeout(9F) thread context. May not sleep.
*/
static void
sd_start_retry_command(void *arg)
{
"sd_start_retry_command: entry\n");
"sd_start_retry_command: un:0x%p STARTING bp:0x%p\n",
}
"sd_start_retry_command: exit\n");
}
/*
* Function: sd_start_direct_priority_command
*
* Description: Used to re-start an SD_PATH_DIRECT_PRIORITY command that had
* received TRAN_BUSY when we called scsi_transport() to send it
* to the underlying HBA. This function is called from timeout(9F)
* context after the delay interval has expired.
*
* Arguments: arg - pointer to associated buf(9S) to be restarted.
*
* Context: timeout(9F) thread context. May not sleep.
*/
static void
{
"sd_start_direct_priority_command: entry\n");
"sd_start_direct_priority_command: exit\n");
}
/*
* Function: sd_send_request_sense_command
*
* Description: Sends a REQUEST SENSE command to the target
*
* Context: May be called from interrupt context.
*/
static void
{
"entry: buf:0x%p\n", bp);
/*
* If we are syncing or dumping, then fail the command to avoid a
* recursive callback into scsi_transport(). Also fail the command
* if we are suspended (legacy behavior).
*/
return;
}
/*
* Retry the failed command and don't issue the request sense if:
* 1) the sense buf is busy
* 2) we have 1 or more outstanding commands on the target
* (the sense data will be cleared or invalidated any way)
*
* Note: There could be an issue with not checking a retry limit here,
* the problem is determining which retry limit to check.
*/
/* Don't retry if the command is flagged as non-retryable */
"sd_send_request_sense_command: "
"at full throttle, retrying exit\n");
} else {
"sd_send_request_sense_command: "
"at full throttle, non-retryable exit\n");
}
return;
}
"sd_send_request_sense_command: exit\n");
}
/*
* Function: sd_mark_rqs_busy
*
* Description: Indicate that the request sense bp for this instance is
* in use.
*
* Context: May be called under interrupt context
*/
static void
{
"sd_mark_rqs_busy: entry: sense_xp:0x%p\n", sense_xp);
== (FLAG_SENSING | FLAG_HEAD));
/* So we can get back the bp at interrupt time! */
/*
* Mark this buf as awaiting sense data. (This is already set in
* the pkt_flags for the RQS packet.)
*/
sense_xp->xb_retry_count = 0;
sense_xp->xb_ua_retry_count = 0;
sense_xp->xb_dma_resid = 0;
/* Clean up the fields for auto-request sense */
sense_xp->xb_sense_status = 0;
sense_xp->xb_sense_state = 0;
sense_xp->xb_sense_resid = 0;
}
/*
* Function: sd_mark_rqs_idle
*
* Description: SD_MUTEX must be held continuously through this routine
* to prevent reuse of the rqs struct before the caller can
* complete it's processing.
*
* Return Code: Pointer to the RQS buf
*
* Context: May be called under interrupt context
*/
static struct buf *
{
un->un_sense_isbusy = 0;
/* This pkt is no longer interested in getting sense data */
return (bp);
}
/*
* Function: sd_alloc_rqs
*
* Description: Set up the unit to receive auto request sense data
*
* Return Code: DDI_SUCCESS or DDI_FAILURE
*
* Context: Called under attach(9E) context
*/
static int
{
/*
* First allocate the required buf and scsi_pkt structs, then set up
* the CDB in the scsi_pkt for a REQUEST SENSE command.
*/
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/* Set up the CDB in the scsi_pkt for a REQUEST SENSE command. */
SCMD_REQUEST_SENSE, 0, SENSE_LENGTH, 0);
/* Set up the other needed members in the ARQ scsi_pkt. */
/*
* Allocate & init the sd_xbuf struct for the RQS command. Do not
* provide any intpkt, destroypkt routines as we take care of
* scsi_pkt allocation/freeing here and in sd_free_rqs().
*/
"sd_alloc_rqs: un 0x%p, rqs xp 0x%p, pkt 0x%p, buf 0x%p\n",
/*
* Save the pointer to the request sense private bp so it can
* be retrieved in sdintr.
*/
/*
* See if the HBA supports auto-request sense for the specified
* enabled).
*
* Note: For some HBAs (ifp & sf), scsi_ifsetcap will always return
* failure, while for other HBAs (pln) scsi_ifsetcap will always
* return success. However, in both of these cases ARQ is always
* enabled and scsi_ifgetcap will always return true. The best approach
* is to issue the scsi_ifgetcap() first, then try the scsi_ifsetcap().
*
* The 3rd case is the HBA (adp) always return enabled on
* scsi_ifgetgetcap even when it's not enable, the best approach
* is issue a scsi_ifsetcap then a scsi_ifgetcap
* Note: this case is to circumvent the Adaptec bug. (x86 only)
*/
} else {
/*
* Circumvent the Adaptec bug, remove this code when
* the bug is fixed
*/
#endif
case 0:
"sd_alloc_rqs: HBA supports ARQ\n");
/*
* ARQ is supported by this HBA but currently is not
* enabled. Attempt to enable it and if successful then
* mark this instance as ARQ enabled.
*/
== 1) {
/* Successfully enabled ARQ in the HBA */
"sd_alloc_rqs: ARQ enabled\n");
} else {
/* Could not enable ARQ in the HBA */
"sd_alloc_rqs: failed ARQ enable\n");
}
break;
case 1:
/*
* ARQ is supported by this HBA and is already enabled.
* Just mark ARQ as enabled for this instance.
*/
"sd_alloc_rqs: ARQ already enabled\n");
break;
default:
/*
* ARQ is not supported by this HBA; disable it for this
* instance.
*/
"sd_alloc_rqs: HBA does not support ARQ\n");
break;
}
}
return (DDI_SUCCESS);
}
/*
* Function: sd_free_rqs
*
* Description: Cleanup for the pre-instance RQS command.
*
* Context: Kernel thread context
*/
static void
{
/*
* If consistent memory is bound to a scsi_pkt, the pkt
* has to be destroyed *before* freeing the consistent memory.
* Don't change the sequence of this operations.
* scsi_destroy_pkt() might access memory, which isn't allowed,
* after it was freed in scsi_free_consistent_buf().
*/
}
}
}
/*
* Function: sd_reduce_throttle
*
* Description: Reduces the maximun # of outstanding commands on a
* target to the current number of outstanding commands.
* Queues a tiemout(9F) callback to restore the limit
* after a specified interval has elapsed.
* Typically used when we get a TRAN_BUSY return code
* back from scsi_transport().
*
* Arguments: un - ptr to the sd_lun softstate struct
* throttle_type: SD_THROTTLE_TRAN_BUSY or SD_THROTTLE_QFULL
*
* Context: May be called from interrupt context
*/
static void
{
"entry: un:0x%p un_throttle:%d un_ncmds_in_transport:%d\n",
switch (throttle_type) {
case SD_THROTTLE_TRAN_BUSY:
if (un->un_busy_throttle == 0) {
}
break;
case SD_THROTTLE_QFULL:
un->un_busy_throttle = 0;
break;
default:
}
if (un->un_ncmds_in_transport > 0) {
}
} else {
if (un->un_ncmds_in_transport == 0) {
} else {
}
}
}
/* Reschedule the timeout if none is currently active */
"sd_reduce_throttle: timeout scheduled!\n");
}
}
/*
* Function: sd_restore_throttle
*
* Description: Callback function for timeout(9F). Resets the current
* value of un->un_throttle to its default.
*
* Arguments: arg - pointer to associated softstate for the device.
*
* Context: May be called from interrupt context
*/
static void
sd_restore_throttle(void *arg)
{
/*
* If un_busy_throttle is nonzero, then it contains the
* value that un_throttle was when we got a TRAN_BUSY back
* from scsi_transport(). We want to revert back to this
* value.
*
* In the QFULL case, the throttle limit will incrementally
* increase until it reaches max throttle.
*/
if (un->un_busy_throttle > 0) {
un->un_busy_throttle = 0;
} else {
/*
* increase throttle by 10% open gate slowly, schedule
* another restore if saved throttle has not been
* reached
*/
short throttle;
if (sd_qfull_throttle_enable) {
un->un_throttle =
}
}
}
/*
* If un_throttle has fallen below the low-water mark, we
* restore the maximum value here (and allow it to ratchet
* down again if necessary).
*/
}
} else {
"restoring limit from 0x%x to 0x%x\n",
}
"sd_restore_throttle: calling sd_start_cmds!\n");
"sd_restore_throttle: exit: un:0x%p un_throttle:%d\n",
}
/*
* Function: sdrunout
*
* Description: Callback routine for scsi_init_pkt when a resource allocation
* fails.
*
* Arguments: arg - a pointer to the sd_lun unit struct for the particular
* soft state instance.
*
* Return Code: The scsi_init_pkt routine allows for the callback function to
* return a 0 indicating the callback should be rescheduled or a 1
* indicating not to reschedule. This routine always returns 1
* because the driver always provides a callback function to
* scsi_init_pkt. This results in a callback always being scheduled
* (via the scsi_init_pkt callback implementation) if a resource
* failure occurs.
*
* Context: This callback function may not block or call routines that block
*
* Note: Using the scsi_init_pkt callback facility can result in an I/O
* request persisting at the head of the list which cannot be
* satisfied even after multiple retries. In the future the driver
* may implement some time of maximum runout count before failing
* an I/O.
*/
static int
{
/*
* This callback routine always returns 1 (i.e. do not reschedule)
* because we always specify sdrunout as the callback handler for
* scsi_init_pkt inside the call to sd_start_cmds.
*/
return (1);
}
/*
* Function: sdintr
*
* Description: Completion callback routine for scsi_pkt(9S) structs
* sent to the HBA driver via scsi_transport(9F).
*
* Context: Interrupt context
*/
static void
{
#ifdef SD_FAULT_INJECTION
/* SD FaultInjection */
#endif /* SD_FAULT_INJECTION */
/* Reduce the count of the #commands currently in transport */
/* Increment counter to indicate that the callback routine is active */
un->un_in_callback++;
#ifdef SDDEBUG
"un:0x%p: GOT retry_bp:0x%p un_ncmds_in_transport:%d\n",
}
#endif
/*
* If pkt_reason is CMD_DEV_GONE, just fail the command
*/
"Device is gone\n");
goto exit;
}
/*
* First see if the pkt has auto-request sense data with it....
* Look at the packet state first so we don't take a performance
* hit looking at the arq enabled flag unless absolutely necessary.
*/
/*
* The HBA did an auto request sense for this command so check
* for FLAG_DIAGNOSE. If set this indicates a uscsi or internal
* driver command that should not be retried.
*/
/*
* Save the relevant sense info into the xp for the
* original cmd.
*/
struct scsi_arq_status *asp;
min(sizeof (struct scsi_extended_sense),
SENSE_LENGTH));
/* fail the command */
"sdintr: arq done and FLAG_DIAGNOSE set\n");
goto exit;
}
/*
* We want to either retry or fail this command, so free
* the DMA resources here. If we retry the command then
* the DMA resources will be reallocated in sd_start_cmds().
* Note that when PKT_DMA_PARTIAL is used, this reallocation
* causes the *entire* transfer to start over again from the
* beginning of the request, even for PARTIAL chunks that
* have already transferred successfully.
*/
}
#endif
"sdintr: arq done, sd_handle_auto_request_sense\n");
goto exit;
}
/* Next see if this is the REQUEST SENSE pkt for the instance */
/* This pktp is from the unit's REQUEST_SENSE command */
"sdintr: sd_handle_request_sense\n");
goto exit;
}
/*
* Check to see if the command successfully completed as requested;
* this is the most common case (and also the hot performance path).
*
* Requirements for successful completion are:
* pkt_reason is CMD_CMPLT and packet status is status good.
* In addition:
* - A residual of zero indicates successful completion no matter what
* the command is.
* - If the residual is not zero and the command is not a read or
* write, then it's still defined as successful completion. In other
* words, if the command is a read or write the residual must be
* zero for successful completion.
* - If the residual is not zero and the command is a read or
* write, and it's a USCSICMD, then it's still defined as
* successful completion.
*/
/*
* Since this command is returned with a good status, we
* can reset the count for Sonoma failover.
*/
un->un_sonoma_failure_count = 0;
/*
* Return all USCSI commands on good status
*/
"sdintr: returning command for resid == 0\n");
"sdintr: returning command for resid != 0\n");
"sdintr: returning uscsi command\n");
} else {
goto not_successful;
}
/*
* Decrement counter to indicate that the callback routine
* is done.
*/
un->un_in_callback--;
return;
}
/*
* The following is based upon knowledge of the underlying transport
* and its use of DMA resources. This code should be removed when
* PKT_DMA_PARTIAL support is taken out of the disk driver in favor
* of the new PKT_CMD_BREAKUP protocol. See also sd_initpkt_for_buf()
* and sd_start_cmds().
*
* Free any DMA resources associated with this command if there
* is a chance it could be retried or enqueued for later retry.
* If we keep the DMA binding then mpxio cannot reissue the
* command on another path whenever a path failure occurs.
*
* Note that when PKT_DMA_PARTIAL is used, free/reallocation
* causes the *entire* transfer to start over again from the
* beginning of the request, even for PARTIAL chunks that
* have already transferred successfully.
*
* This is only done for non-uscsi commands (and also skipped for the
* driver's internal RQS command). Also just do this for Fibre Channel
* devices as these are the only ones that support mpxio.
*/
}
#endif
/*
* The command did not successfully complete as requested so check
* for FLAG_DIAGNOSE. If set this indicates a uscsi or internal
* driver command that should not be retried so just return. If
* FLAG_DIAGNOSE is not set the error will be processed below.
*/
"sdintr: FLAG_DIAGNOSE: sd_return_failed_command\n");
/*
* Issue a request sense if a check condition caused the error
* (we handle the auto request sense case above), otherwise
* just fail the command.
*/
} else {
}
goto exit;
}
/*
* The command did not successfully complete as requested so process
*/
switch (pktp->pkt_reason) {
case CMD_CMPLT:
switch (SD_GET_PKT_STATUS(pktp)) {
case STATUS_GOOD:
/*
* The command completed successfully with a non-zero
* residual
*/
"sdintr: STATUS_GOOD \n");
break;
case STATUS_CHECK:
case STATUS_TERMINATED:
"sdintr: STATUS_TERMINATED | STATUS_CHECK\n");
break;
case STATUS_BUSY:
"sdintr: STATUS_BUSY\n");
break;
"sdintr: STATUS_RESERVATION_CONFLICT\n");
break;
case STATUS_QFULL:
"sdintr: STATUS_QFULL\n");
break;
case STATUS_MET:
case STATUS_INTERMEDIATE:
case STATUS_SCSI2:
case STATUS_INTERMEDIATE_MET:
case STATUS_ACA_ACTIVE:
"Unexpected SCSI status received: 0x%x\n",
break;
default:
"Invalid SCSI status received: 0x%x\n",
break;
}
break;
case CMD_INCOMPLETE:
"sdintr: CMD_INCOMPLETE\n");
break;
case CMD_TRAN_ERR:
"sdintr: CMD_TRAN_ERR\n");
break;
case CMD_RESET:
"sdintr: CMD_RESET \n");
break;
case CMD_ABORTED:
"sdintr: CMD_ABORTED \n");
break;
case CMD_TIMEOUT:
"sdintr: CMD_TIMEOUT\n");
break;
case CMD_UNX_BUS_FREE:
"sdintr: CMD_UNX_BUS_FREE \n");
break;
case CMD_TAG_REJECT:
"sdintr: CMD_TAG_REJECT\n");
break;
default:
"sdintr: default\n");
break;
}
exit:
/* Decrement counter to indicate that the callback routine is done. */
un->un_in_callback--;
/*
* At this point, the pkt has been dispatched, ie, it is either
* being re-tried or has been returned to its caller and should
* not be referenced.
*/
}
/*
* Function: sd_print_incomplete_msg
*
* Description: Prints the error message for a CMD_INCOMPLETE error.
*
* Arguments: un - ptr to associated softstate for the device.
* bp - ptr to the buf(9S) for the command.
* arg - message string ptr
* code - SD_DELAYED_RETRY_ISSUED, SD_IMMEDIATE_RETRY_ISSUED,
* or SD_NO_RETRY_ISSUED.
*
* Context: May be called under interrupt context
*/
static void
{
char *msgp;
switch (code) {
case SD_DELAYED_RETRY_ISSUED:
msgp = "retrying";
break;
case SD_NO_RETRY_ISSUED:
default:
msgp = "giving up";
break;
}
}
}
/*
* Function: sd_pkt_status_good
*
* Description: Processing for a STATUS_GOOD code in pkt_status.
*
* Context: May be called under interrupt context
*/
static void
{
char *cmdp;
case SCMD_READ:
cmdp = "read";
break;
case SCMD_WRITE:
cmdp = "write";
break;
default:
return;
}
/*
* If retries are exhaused, then sd_retry_command() will update
* the b_resid count.
*/
}
/*
* Function: sd_handle_request_sense
*
* Description: Processing for non-auto Request Sense command.
*
* Arguments: un - ptr to associated softstate
* sense_bp - ptr to buf(9S) for the RQS command
* sense_xp - ptr to the sd_xbuf for the RQS command
* sense_pktp - ptr to the scsi_pkt(9S) for the RQS command
*
* Context: May be called under interrupt context
*/
static void
{
/*
* Note the sense_bp, sense_xp, and sense_pktp here are for the
* RQS command and not the original command.
*/
(FLAG_SENSING | FLAG_HEAD));
FLAG_SENSING) == FLAG_SENSING);
/* These are the bp, xp, and pktp for the original command */
/*
* The REQUEST SENSE command failed. Release the REQUEST
* SENSE command for re-use, get back the bp for the original
* command, and attempt to re-try the original command if
* FLAG_DIAGNOSE is not set in the original packet.
*/
return;
}
}
/*
* Save the relevant sense info into the xp for the original cmd.
*
* Note: if the request sense failed the state info will be zero
* as set in sd_mark_rqs_busy()
*/
/*
* Free up the RQS command....
* NOTE:
* Must do this BEFORE calling sd_validate_sense_data!
* sd_validate_sense_data may return the original command in
* which case the pkt will be freed and the flags can no
* longer be touched.
* SD_MUTEX is held through this process until the command
* is dispatched based upon the sense data, so there are
* no race conditions.
*/
/*
* For a retryable command see if we have valid sense data, if so then
* turn it over to sd_decode_sense() to figure out the right course of
* action. Just fail a non-retryable command.
*/
}
} else {
}
}
/*
* Function: sd_handle_auto_request_sense
*
* Description: Processing for auto-request sense information.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* xp - ptr to the sd_xbuf for the command
* pktp - ptr to the scsi_pkt(9S) for the command
*
* Context: May be called under interrupt context
*/
static void
{
struct scsi_arq_status *asp;
/*
* For auto-request sense, we get a scsi_arq_status back from
* the HBA, with the sense data in the sts_sensedata member.
* The pkt_scbp of the packet points to this scsi_arq_status.
*/
/*
* The auto REQUEST SENSE failed; see if we can re-try
* the original command.
*/
"auto request sense failed (reason=%s)\n",
return;
}
/* Save the relevant sense info into the xp for the original cmd. */
/*
* See if we have valid sense data, if so then turn it over to
* sd_decode_sense() to figure out the right course of action.
*/
}
}
/*
* Function: sd_print_sense_failed_msg
*
* Description: Print log message when RQS has failed.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* arg - generic message string ptr
* code - SD_IMMEDIATE_RETRY_ISSUED, SD_DELAYED_RETRY_ISSUED,
* or SD_NO_RETRY_ISSUED
*
* Context: May be called from interrupt context
*/
static void
int code)
{
}
}
/*
* Function: sd_validate_sense_data
*
* Description: Check the given sense data for validity.
* If the sense data is not valid, the command will
* be either failed or retried!
*
* Return Code: SD_SENSE_DATA_IS_INVALID
* SD_SENSE_DATA_IS_VALID
*
* Context: May be called from interrupt context
*/
static int
{
struct scsi_extended_sense *esp;
/*
* Check the status of the RQS command (auto or manual).
*/
case STATUS_GOOD:
break;
return (SD_SENSE_DATA_IS_INVALID);
case STATUS_BUSY:
"Busy Status on REQUEST SENSE\n");
return (SD_SENSE_DATA_IS_INVALID);
case STATUS_QFULL:
"QFULL Status on REQUEST SENSE\n");
return (SD_SENSE_DATA_IS_INVALID);
case STATUS_CHECK:
case STATUS_TERMINATED:
msgp = "Check Condition on REQUEST SENSE\n";
goto sense_failed;
default:
msgp = "Not STATUS_GOOD on REQUEST_SENSE\n";
goto sense_failed;
}
/*
* See if we got the minimum required amount of sense data.
* Note: We are assuming the returned sense data is SENSE_LENGTH bytes
* or less.
*/
(actual_len == 0)) {
msgp = "Request Sense couldn't get sense data\n";
goto sense_failed;
}
if (actual_len < SUN_MIN_SENSE_LENGTH) {
msgp = "Not enough sense information\n";
goto sense_failed;
}
/*
* We require the extended sense data
*/
static char tmp[8];
static char buf[148];
char *p = (char *)(xp->xb_sense_data);
int i;
for (i = 0; i < actual_len; i++) {
}
}
/* Note: Legacy behavior, fail the command with no retry */
return (SD_SENSE_DATA_IS_INVALID);
}
/*
* Check that es_code is valid (es_class concatenated with es_code
* make up the "response code" field. es_class will always be 7, so
* make sure es_code is 0, 1, 2, 3 or 0xf. es_code will indicate the
* format.
*/
goto sense_failed;
}
return (SD_SENSE_DATA_IS_VALID);
/*
* If the request sense failed (for whatever reason), attempt
* to retry the original command.
*/
/*
* SD_RETRY_DELAY is conditionally compile (#if fibre) in
* sddef.h for Sparc platform, and x86 uses 1 binary
* The SD_RETRY_DELAY value need to be adjusted here
* when SD_RETRY_DELAY change in sddef.h
*/
#else
#endif
return (SD_SENSE_DATA_IS_INVALID);
}
/*
* Function: sd_decode_sense
*
* Description: Take recovery action(s) when SCSI Sense Data is received.
*
* Context: Interrupt context.
*/
static void
{
switch (sense_key) {
case KEY_NO_SENSE:
break;
case KEY_RECOVERABLE_ERROR:
break;
case KEY_NOT_READY:
break;
case KEY_MEDIUM_ERROR:
case KEY_HARDWARE_ERROR:
break;
case KEY_ILLEGAL_REQUEST:
break;
case KEY_UNIT_ATTENTION:
break;
case KEY_WRITE_PROTECT:
case KEY_VOLUME_OVERFLOW:
case KEY_MISCOMPARE:
break;
case KEY_BLANK_CHECK:
break;
case KEY_ABORTED_COMMAND:
break;
case KEY_VENDOR_UNIQUE:
case KEY_COPY_ABORTED:
case KEY_EQUAL:
case KEY_RESERVED:
default:
break;
}
}
/*
* Function: sd_dump_memory
*
* Description: Debug logging routine to print the contents of a user provided
* buffer. The output of the buffer is broken up into 256 byte
* segments due to a size constraint of the scsi_log.
* implementation.
*
* Arguments: un - ptr to softstate
* comp - component mask
* title - "title" string to preceed data when printed
* data - ptr to data block to be printed
* len - size of data block to be printed
* fmt - SD_LOG_HEX (use 0x%02x format) or SD_LOG_CHAR (use %c)
*
* Context: May be called from interrupt context
*/
#define SD_DUMP_MEMORY_BUF_SIZE 256
static char *sd_dump_format_string[] = {
" 0x%02x",
" %c"
};
static void
{
int i, j;
int avail_count;
int start_offset;
int end_offset;
char *bufp;
char *local_buf;
char *format_string;
/*
* In the debug version of the driver, this function is called from a
* number of places which are NOPs in the release driver.
* The debug driver therefore has additional methods of filtering
* debug output.
*/
#ifdef SDDEBUG
/*
* In the debug version of the driver we can reduce the amount of debug
* messages by setting sd_error_level to something other than
* SCSI_ERR_ALL and clearing bits in sd_level_mask and
* sd_component_mask.
*/
(sd_error_level != SCSI_ERR_ALL)) {
return;
}
if (((sd_component_mask & comp) == 0) ||
(sd_error_level != SCSI_ERR_ALL)) {
return;
}
#else
if (sd_error_level != SCSI_ERR_ALL) {
return;
}
#endif
/*
* Available length is the length of local_buf[], minus the
* length of the title string, minus one for the ":", minus
* one for the newline, minus one for the NULL terminator.
* This gives the #bytes available for holding the printed
* values from the given data buffer.
*/
if (fmt == SD_LOG_HEX) {
} else /* SD_LOG_CHAR */ {
}
/*
* Available count is the number of elements from the given
* data buffer that we can fit into the available length.
* This is based upon the size of the format string used.
* Make one entry and find it's size.
*/
j = 0;
while (j < len) {
start_offset = j;
i++, j++) {
}
}
}
/*
* Function: sd_print_sense_msg
*
* Description: Log a message based upon the given sense data.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* arg - ptr to associate sd_sense_info struct
* code - SD_IMMEDIATE_RETRY_ISSUED, SD_DELAYED_RETRY_ISSUED,
* or SD_NO_RETRY_ISSUED
*
* Context: May be called from interrupt context
*/
static void
{
int severity;
int pfa_flag;
extern struct scsi_key_strings scsi_cmds[];
if ((code == SD_DELAYED_RETRY_ISSUED) ||
(code == SD_IMMEDIATE_RETRY_ISSUED)) {
}
/* Use absolute block number for the request block number */
/*
* Now try to get the error block number from the sense data
*/
/*
* We retrieved the error block number from the information
* portion of the sense data.
*
* For USCSI commands we are better off using the error
* block no. as the requested block no. (This is the best
* we can estimate.)
*/
}
} else {
/*
* Without the es_valid bit set (for fixed format) or an
* information descriptor (for descriptor format) we cannot
* be certain of the error blkno, so just use the
* request_blkno.
*/
}
/*
* The following will log the buffer contents for the release driver
* if the SD_LOGMASK_DIAG bit of sd_level_mask is set, or the error
* level is set to verbose.
*/
/* This is normally only set for USCSI */
return;
}
(((sd_level_mask & SD_LOGMASK_DIAG) == 0) &&
(severity < sd_error_level))) {
return;
}
}
/*
* Check for Sonoma Failover and keep a count of how many failed I/O's
*/
return;
}
}
(struct scsi_extended_sense *)sensep,
}
/*
* Function: sd_sense_key_no_sense
*
* Description: Recovery action when sense data was not received.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
}
/*
* Function: sd_sense_key_recoverable_error
*
* Description: Recovery actions for a SCSI "Recovered Error" sense key.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/*
* 0x5D: FAILURE PREDICTION THRESHOLD EXCEEDED
*/
} else {
}
return;
}
}
/*
* Function: sd_sense_key_not_ready
*
* Description: Recovery actions for a SCSI "Not Ready" sense key.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/*
* Update error stats after first NOT READY error. Disks may have
* been powered down and may need to be restarted. For CDROMs,
* report NOT READY errors only if media is present.
*/
(xp->xb_retry_count > 0)) {
}
/*
* Just fail if the "not ready" retry limit has been reached.
*/
/* Special check for error message printing for removables. */
(ascq >= 0x04)) {
}
goto fail_command;
}
/*
* Check the ASC and ASCQ in the sense data as needed, to determine
* what to do.
*/
switch (asc) {
case 0x04: /* LOGICAL UNIT NOT READY */
/*
* disk drives that don't spin up result in a very long delay
* in format without warning messages. We will log a message
* if the error level is set to verbose.
*/
if (sd_error_level < SCSI_ERR_RETRYABLE) {
"logical unit not ready, resetting disk\n");
}
/*
* There are different requirements for CDROMs and disks for
* the number of retries. If a CD-ROM is giving this, it is
* probably reading TOC and is in the process of getting
* ready, so we should keep on trying for a long time to make
* sure that all types of media are taken in account (for
* some media the drive takes a long time to read TOC). For
* disks we do not want to retry this too many times as this
* can cause a long hang in format when the drive refuses to
* spin up (a very common failure).
*/
switch (ascq) {
case 0x00: /* LUN NOT READY, CAUSE NOT REPORTABLE */
/*
* Disk drives frequently refuse to spin up which
* results in a very long hang in format without
* warning messages.
*
* Note: This code preserves the legacy behavior of
* comparing xb_retry_count against zero for fibre
* channel targets instead of comparing against the
* un_reset_retry_count value. The reason for this
* discrepancy has been so utterly lost beneath the
* Sands of Time that even Indiana Jones could not
* find it.
*/
if (((sd_level_mask & SD_LOGMASK_DIAG) ||
(xp->xb_retry_count > 0)) &&
CE_WARN, "logical unit not ready, "
"resetting disk\n");
}
} else {
if (((sd_level_mask & SD_LOGMASK_DIAG) ||
(xp->xb_retry_count >
un->un_reset_retry_count)) &&
CE_WARN, "logical unit not ready, "
"resetting disk\n");
}
}
break;
case 0x01: /* LUN IS IN PROCESS OF BECOMING READY */
/*
* If the target is in the process of becoming
* ready, just proceed with the retry. This can
* happen with CD-ROMs that take a long time to
* read TOC after a power cycle or reset.
*/
goto do_retry;
case 0x02: /* LUN NOT READY, INITITIALIZING CMD REQUIRED */
break;
case 0x03: /* LUN NOT READY, MANUAL INTERVENTION REQUIRED */
/*
* Retries cannot help here so just fail right away.
*/
goto fail_command;
case 0x88:
/*
* path problem in a mutipathed config, but as far as
* the target driver is concerned it equates to a fatal
* error, so we should just fail the command right away
* (without printing anything to the console). If this
* action.
*/
return;
}
/* FALLTHRU */
case 0x04: /* LUN NOT READY, FORMAT IN PROGRESS */
case 0x05: /* LUN NOT READY, REBUILD IN PROGRESS */
case 0x06: /* LUN NOT READY, RECALCULATION IN PROGRESS */
case 0x07: /* LUN NOT READY, OPERATION IN PROGRESS */
case 0x08: /* LUN NOT READY, LONG WRITE IN PROGRESS */
default: /* Possible future codes in SCSI spec? */
/*
* For removable-media devices, do not retry if
* ASCQ > 2 as these result mostly from USCSI commands
* on MMC devices issued to check status of an
* operation initiated in immediate mode. Also for
* ASCQ >= 4 do not print console messages as these
* mainly represent a user-initiated operation
* instead of a system failure.
*/
if (un->un_f_has_removable_media) {
goto fail_command;
}
break;
}
/*
* As part of our recovery attempt for the NOT READY
* condition, we issue a START STOP UNIT command. However
* we want to wait for a short delay before attempting this
* as there may still be more commands coming back from the
* target with the check condition. To do this we use
* timeout(9F) to call sd_start_stop_unit_callback() after
* the delay interval expires. (sd_start_stop_unit_callback()
* dispatches sd_start_stop_unit_task(), which will issue
* the actual START STOP UNIT command. The delay interval
* is one-half of the delay that we will use to retry the
* command that generated the NOT READY condition.
*
* Note that we could just dispatch sd_start_stop_unit_task()
* from here and allow it to sleep for the delay interval,
* but then we would be tying up the taskq thread
* uncesessarily for the duration of the delay.
*
* Do not issue the START STOP UNIT if the current command
* is already a START STOP UNIT.
*/
break;
}
/*
* Do not schedule the timeout if one is already pending.
*/
"sd_sense_key_not_ready: restart already issued to"
break;
}
/*
* Schedule the START STOP UNIT command, then queue the command
* for a retry.
*
* Note: A timeout is not scheduled for this retry because we
* want the retry to be serial with the START_STOP_UNIT. The
* retry will be started when the START_STOP_UNIT is completed
* in sd_start_stop_unit_task.
*/
xp->xb_retry_count++;
return;
case 0x05: /* LOGICAL UNIT DOES NOT RESPOND TO SELECTION */
if (sd_error_level < SCSI_ERR_RETRYABLE) {
"unit does not respond to selection\n");
}
break;
case 0x3A: /* MEDIUM NOT PRESENT */
if (sd_error_level >= SCSI_ERR_FATAL) {
"Caddy not inserted in drive\n");
}
sr_ejected(un);
/* The state has changed, inform the media watch routines */
/* Just fail if no media is present in the drive. */
goto fail_command;
default:
if (sd_error_level < SCSI_ERR_RETRYABLE) {
"Unit not Ready. Additional sense code 0x%x\n",
asc);
}
break;
}
/*
* Retry the command, as some targets may report NOT READY for
* several seconds after being reset.
*/
xp->xb_retry_count++;
return;
}
/*
* Function: sd_sense_key_medium_or_hardware_error
*
* Description: Recovery actions for a SCSI "Medium Error" or "Hardware Error"
* sense key.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
if (sense_key == KEY_MEDIUM_ERROR) {
}
if ((un->un_reset_retry_count != 0) &&
/* Do NOT do a RESET_ALL here: too intrusive. (4112858) */
/*
* We need to be able to handle specific ASC when we are
* handling a KEY_HARDWARE_ERROR. In particular
* taking the default action of resetting the target may
* not be the appropriate way to attempt recovery.
* Resetting a target because of a single LUN failure
* victimizes all LUNs on that target.
*
* This is true for the LSI arrays, if an LSI
* array controller returns an ASC of 0x84 (LUN Dead) we
* should trust it.
*/
if (sense_key == KEY_HARDWARE_ERROR) {
switch (asc) {
case 0x84:
}
break;
default:
break;
}
}
if (try_resetting_target == B_TRUE) {
int reset_retval = 0;
"sd_sense_key_medium_or_hardware_"
"error: issuing RESET_LUN\n");
}
if (reset_retval == 0) {
"sd_sense_key_medium_or_hardware_"
"error: issuing RESET_TARGET\n");
}
}
}
}
/*
* This really ought to be a fatal error, but we will retry anyway
* as some drives report this as a spurious error.
*/
}
/*
* Function: sd_sense_key_illegal_request
*
* Description: Recovery actions for a SCSI "Illegal Request" sense key.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/* Pointless to retry if the target thinks it's an illegal request */
}
/*
* Function: sd_sense_key_unit_attention
*
* Description: Recovery actions for a SCSI "Unit Attention" sense key.
*
* Context: May be called from interrupt context
*/
static void
{
/*
* For UNIT ATTENTION we allow retries for one minute. Devices
* like Sonoma can return UNIT ATTENTION close to a minute
* under certain conditions.
*/
int retry_check_flag = SD_RETRIES_UA;
struct sd_sense_info si;
switch (asc) {
case 0x5D: /* FAILURE PREDICTION THRESHOLD EXCEEDED */
if (sd_report_pfa != 0) {
goto do_retry;
}
break;
case 0x29: /* POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */
un->un_resvd_status |=
}
#ifdef _LP64
un, KM_NOSLEEP) == 0) {
/*
* If we can't dispatch the task we'll just
* live without descriptor sense. We can
* try again on the next "unit attention"
*/
"sd_sense_key_unit_attention: "
"Could not dispatch "
"sd_reenable_dsense_task\n");
}
}
#endif /* _LP64 */
/* FALLTHRU */
case 0x28: /* NOT READY TO READY CHANGE, MEDIUM MAY HAVE CHANGED */
if (!un->un_f_has_removable_media) {
break;
}
/*
* When we get a unit attention from a removable-media device,
* it may be in a state that will take a long time to recover
* (e.g., from a reset). Since we are executing in interrupt
* context here, we cannot wait around for the device to come
* back. So hand this command off to sd_media_change_task()
* for deferred processing under taskq thread context. (Note
* that the command still may be failed if a problem is
* encountered at a later time.)
*/
KM_NOSLEEP) == 0) {
/*
* Cannot dispatch the request so fail the command.
*/
}
/*
* If failed to dispatch sd_media_change_task(), we already
* updated kstat. If succeed to dispatch sd_media_change_task(),
* we should update kstat later if it encounters an error. So,
* we update kstat_updated flag here.
*/
/*
* Either the command has been successfully dispatched to a
* task Q for retrying, or the dispatch failed. In either case
* do NOT retry again by calling sd_retry_command. This sets up
* two retries of the same command and when one completes and
* frees the resources the other will access freed memory,
* a bad thing.
*/
return;
default:
break;
}
/*
* Update kstat if we haven't done that.
*/
if (!kstat_updated) {
}
}
/*
* Function: sd_sense_key_fail_command
*
* Description: Use to fail a command when we don't like the sense key that
* was returned.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
}
/*
* Function: sd_sense_key_blank_check
*
* Description: Recovery actions for a SCSI "Blank Check" sense key.
* Has no monetary connotation.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/*
* Blank check is not fatal for removable devices, therefore
* it does not require a console message.
*/
}
/*
* Function: sd_sense_key_aborted_command
*
* Description: Recovery actions for a SCSI "Aborted Command" sense key.
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/*
* This really ought to be a fatal error, but we will retry anyway
* as some drives report this as a spurious error.
*/
}
/*
* Function: sd_sense_key_default
*
* Description: Default recovery action for several SCSI sense keys (basically
* attempts a retry).
*
* Context: May be called from interrupt context
*/
static void
{
struct sd_sense_info si;
/*
* Undecoded sense key. Attempt retries and hope that will fix
* the problem. Otherwise, we're dead.
*/
}
}
/*
* Function: sd_print_retry_msg
*
* Description: Print a message indicating the retry action being taken.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* arg - not used.
* flag - SD_IMMEDIATE_RETRY_ISSUED, SD_DELAYED_RETRY_ISSUED,
* or SD_NO_RETRY_ISSUED
*
* Context: May be called from interrupt context
*/
/* ARGSUSED */
static void
{
char *reasonp;
char *msgp;
(SD_DEVICE_IS_IN_LOW_POWER(un)) ||
goto update_pkt_reason;
}
/*
* Suppress messages if they are all the same pkt_reason; with
* TQ, many (up to 256) are returned with the same pkt_reason.
* If we are in panic, then suppress the retry messages.
*/
switch (flag) {
case SD_NO_RETRY_ISSUED:
msgp = "giving up";
break;
case SD_DELAYED_RETRY_ISSUED:
(sd_error_level != SCSI_ERR_ALL))) {
return;
}
msgp = "retrying command";
break;
default:
goto update_pkt_reason;
}
/*
* Update un->un_last_pkt_reason with the value in pktp->pkt_reason.
* This is to prevent multiple console messages for the same failure
* condition. Note that un->un_last_pkt_reason is NOT restored if &
* when the command is retried successfully because there still may be
* more commands coming back with the same value of pktp->pkt_reason.
*/
}
}
/*
* Function: sd_print_cmd_incomplete_msg
*
* Description: Message logging fn. for a SCSA "CMD_INCOMPLETE" pkt_reason.
*
* Arguments: un - ptr to associated softstate
* bp - ptr to buf(9S) for the command
* arg - passed to sd_print_retry_msg()
* code - SD_IMMEDIATE_RETRY_ISSUED, SD_DELAYED_RETRY_ISSUED,
* or SD_NO_RETRY_ISSUED
*
* Context: May be called from interrupt context
*/
static void
int code)
{
switch (code) {
case SD_NO_RETRY_ISSUED:
/* Command was failed. Someone turned off this target? */
/*
* Suppress message if we are detaching and
* device has been disconnected
* Note that DEVI_IS_DEVICE_REMOVED is a consolidation
* private interface and not part of the DDI
*/
if (!(DEVI_IS_DETACHING(dip) &&
"disk not responding to selection\n");
}
}
break;
case SD_DELAYED_RETRY_ISSUED:
default:
/* Command was successfully queued for retry */
break;
}
}
/*
* Function: sd_pkt_reason_cmd_incomplete
*
* Description: Recovery actions for a SCSA "CMD_INCOMPLETE" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
/* Do not do a reset if selection did not complete */
/* Note: Should this not just check the bit? */
}
/*
* If the target was not successfully selected, then set
* SD_RETRIES_FAILFAST to indicate that we lost communication
* likely to take a long time.
*/
}
}
/*
* Function: sd_pkt_reason_cmd_tran_err
*
* Description: Recovery actions for a SCSA "CMD_TRAN_ERR" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
/*
* Do not reset if we got a parity error, or if
* selection did not complete.
*/
/* Note: Should this not just check the bit for pkt_state? */
}
}
/*
* Function: sd_pkt_reason_cmd_reset
*
* Description: Recovery actions for a SCSA "CMD_RESET" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
/* The target may still be running the command, so try to reset. */
/*
* If pkt_reason is CMD_RESET chances are that this pkt got
* reset because another target on this bus caused it. The target
* that caused it should get CMD_TIMEOUT with pkt_statistics
* of STAT_TIMEOUT/STAT_DEV_RESET.
*/
}
/*
* Function: sd_pkt_reason_cmd_aborted
*
* Description: Recovery actions for a SCSA "CMD_ABORTED" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
/* The target may still be running the command, so try to reset. */
/*
* If pkt_reason is CMD_ABORTED chances are that this pkt got
* aborted because another target on this bus caused it. The target
* that caused it should get CMD_TIMEOUT with pkt_statistics
* of STAT_TIMEOUT/STAT_DEV_RESET.
*/
}
/*
* Function: sd_pkt_reason_cmd_timeout
*
* Description: Recovery actions for a SCSA "CMD_TIMEOUT" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
/*
* A command timeout indicates that we could not establish
* communication with the target, so set SD_RETRIES_FAILFAST
*/
}
/*
* Function: sd_pkt_reason_cmd_unx_bus_free
*
* Description: Recovery actions for a SCSA "CMD_UNX_BUS_FREE" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
}
/*
* Function: sd_pkt_reason_cmd_tag_reject
*
* Description: Recovery actions for a SCSA "CMD_TAG_REJECT" pkt_reason.
*
* Context: May be called from interrupt context
*/
static void
{
un->un_tagflags = 0;
} else {
}
/* Legacy behavior not to check retry counts here. */
}
/*
* Function: sd_pkt_reason_default
*
* Description: Default recovery actions for SCSA pkt_reason values that
* do not have more explicit recovery actions.
*
* Context: May be called from interrupt context
*/
static void
{
}
/*
* Function: sd_pkt_status_check_condition
*
* Description: Recovery actions for a "STATUS_CHECK" SCSI command status.
*
* Context: May be called from interrupt context
*/
static void
{
/*
* If ARQ is NOT enabled, then issue a REQUEST SENSE command (the
* command will be retried after the request sense). Otherwise, retry
* the command. Note: we are issuing the request sense even though the
* retry limit may have been reached for the failed command.
*/
"no ARQ, sending request sense command\n");
} else {
"ARQ,retrying request sense command\n");
/*
* The SD_RETRY_DELAY value need to be adjusted here
* when SD_RETRY_DELAY change in sddef.h
*/
NULL);
#else
#endif
}
}
/*
* Function: sd_pkt_status_busy
*
* Description: Recovery actions for a "STATUS_BUSY" SCSI command status.
*
* Context: May be called from interrupt context
*/
static void
{
"sd_pkt_status_busy: entry\n");
/* If retries are exhausted, just fail the command. */
"device busy too long\n");
"sd_pkt_status_busy: exit\n");
return;
}
xp->xb_retry_count++;
/*
* Try to reset the target. However, we do not want to perform
* more than one reset if the device continues to fail. The reset
* will be performed when the retry count reaches the reset
* threshold. This threshold should be set such that at least
* one retry is issued before the reset is performed.
*/
if (xp->xb_retry_count ==
int rval = 0;
/*
* First try to reset the LUN; if we cannot then
* try to reset the target.
*/
"sd_pkt_status_busy: RESET_LUN\n");
}
if (rval == 0) {
"sd_pkt_status_busy: RESET_TARGET\n");
}
}
if (rval == 0) {
/*
* try RESET_ALL
*/
"sd_pkt_status_busy: RESET_ALL\n");
}
if (rval == 0) {
/*
* At this point we give up & fail the command.
*/
"sd_pkt_status_busy: exit (failed cmd)\n");
return;
}
}
/*
* Retry the command. Be sure to specify SD_RETRIES_NOCHECK as
* we have already checked the retry counts above.
*/
"sd_pkt_status_busy: exit\n");
}
/*
* Function: sd_pkt_status_reservation_conflict
*
* Description: Recovery actions for a "STATUS_RESERVATION_CONFLICT" SCSI
* command status.
*
* Context: May be called from interrupt context
*/
static void
{
/*
* If the command was PERSISTENT_RESERVATION_[IN|OUT] then reservation
* conflict could be due to various reasons like incorrect keys, not
* registered or not reserved etc. So, we return EACCES to the caller.
*/
if ((cmd == SCMD_PERSISTENT_RESERVE_IN) ||
(cmd == SCMD_PERSISTENT_RESERVE_OUT)) {
return;
}
}
if (sd_failfast_enable != 0) {
/* By definition, we must panic here.... */
/*NOTREACHED*/
}
"sd_handle_resv_conflict: Disk Reserved\n");
return;
}
/*
* 1147670: retry only if sd_retry_on_reservation_conflict
* property is set (default is 1). Retries will not succeed
* on a disk reserved by another initiator. HA systems
* may reset this via sd.conf to avoid these retries.
*
* Note: The legacy return code for this failure is EIO, however EACCES
* seems more appropriate for a reservation conflict.
*/
if (sd_retry_on_reservation_conflict == 0) {
"sd_handle_resv_conflict: Device Reserved\n");
return;
}
/*
* Retry the command if we can.
*
* Note: The legacy return code for this failure is EIO, however EACCES
* seems more appropriate for a reservation conflict.
*/
}
/*
* Function: sd_pkt_status_qfull
*
* Description: Handle a QUEUE FULL condition from the target. This can
* occur if the HBA does not handle the queue full condition.
* (Basically this means third-party HBAs as Sun HBAs will
* handle the queue full condition.) Note that if there are
* some commands already in the transport, then the queue full
* has occurred because the queue for this nexus is actually
* full. If there are no commands in the transport, then the
* queue full is resulting from some other initiator or lun
* consuming all the resources at the target.
*
* Context: May be called from interrupt context
*/
static void
{
"sd_pkt_status_qfull: entry\n");
/*
* Just lower the QFULL throttle and retry the command. Note that
* we do not limit the number of retries here.
*/
"sd_pkt_status_qfull: exit\n");
}
/*
* Function: sd_reset_target
*
* Description: Issue a scsi_reset(9F), with either RESET_LUN,
* RESET_TARGET, or RESET_ALL.
*
* Context: May be called under interrupt context.
*/
static void
{
int rval = 0;
/*
* No need to reset if the transport layer has already done so.
*/
if ((pktp->pkt_statistics &
"sd_reset_target: no reset\n");
return;
}
"sd_reset_target: RESET_LUN\n");
}
if (rval == 0) {
"sd_reset_target: RESET_TARGET\n");
}
}
if (rval == 0) {
"sd_reset_target: RESET_ALL\n");
}
}
/*
* Function: sd_media_change_task
*
* Description: Recovery action for CDROM to become available.
*
* Context: Executes in a taskq() thread context
*/
static void
sd_media_change_task(void *arg)
{
int err = 0;
int retry_count = 0;
struct sd_sense_info si;
/*
* When a reset is issued on a CDROM, it takes a long time to
* recover. First few attempts to read capacity and other things
* related to handling unit attention fail (with a ASC 0x4 and
* ASCQ 0x1). In that case we want to do enough retries and we want
* to limit the retries in other cases of genuine failures like
* no media in drive.
*/
while (retry_count++ < retry_limit) {
break;
}
}
/* Sleep for 0.5 sec. & try again */
}
/*
* Dispatch (retry or fail) the original command here,
* along with appropriate console messages....
*
* Must grab the mutex before calling sd_retry_command,
* sd_print_sense_msg and sd_return_failed_command.
*/
if (err != SD_CMD_SUCCESS) {
} else {
}
}
/*
* Function: sd_handle_mchange
*
* Description: Perform geometry validation & other recovery when CDROM
* has been removed from drive.
*
* Return Code: 0 for success
* errno-type return code of either sd_send_scsi_DOORLOCK() or
* sd_send_scsi_READ_CAPACITY()
*
* Context: Executes in a taskq() thread context
*/
static int
{
int rval;
SD_PATH_DIRECT_PRIORITY)) != 0) {
return (rval);
}
struct sd_errstats *stp =
}
/*
* Note: Maybe let the strategy/partitioning chain worry about getting
* valid geometry.
*/
return (EIO);
}
/*
* Try to lock the door
*/
}
/*
* Function: sd_send_scsi_DOORLOCK
*
* Description: Issue the scsi DOOR LOCK command
*
* Arguments: un - pointer to driver soft state (unit) structure for
* this target.
* flag - SD_REMOVAL_ALLOW
* SD_REMOVAL_PREVENT
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq. SD_PATH_DIRECT_PRIORITY is used when this
* command is issued as part of an error recovery action.
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
/* already determined doorlock is not supported, fake success */
return (0);
}
ucmd_buf.uscsi_buflen = 0;
"sd_send_scsi_DOORLOCK: returning sd_send_scsi_cmd()\n");
/* fake success and skip subsequent doorlock commands */
return (0);
}
return (status);
}
/*
* Function: sd_send_scsi_READ_CAPACITY
*
* Description: This routine uses the scsi READ CAPACITY command to determine
* the device capacity in number of blocks and the device native
* block size. If this function returns a failure, then the
* values in *capp and *lbap are undefined. If the capacity
* returned is 0xffffffff then the lun is too large for a
* normal READ CAPACITY command and the results of a
* READ CAPACITY 16 will be used instead.
*
* Arguments: un - ptr to soft state struct for the target
* capp - ptr to unsigned 64-bit variable to receive the
* capacity value from the command.
* lbap - ptr to unsigned 32-bit varaible to receive the
* block size value from the command
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq. SD_PATH_DIRECT_PRIORITY is used when this
* command is issued as part of an error recovery action.
*
* Return Code: 0 - Success
* EIO - IO error
* EACCES - Reservation conflict detected
* EAGAIN - Device is becoming ready
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Blocks until command completes.
*/
#define SD_CAPACITY_SIZE sizeof (struct scsi_capacity)
static int
int path_flag)
{
struct scsi_extended_sense sense_buf;
int status;
"sd_send_scsi_READ_CAPACITY: entry: un:0x%p\n", un);
/*
* First send a READ_CAPACITY command to the target.
* (This command is mandatory under SCSI-2.)
*
* Set up the CDB for the READ_CAPACITY command. The Partial
* Medium Indicator bit is cleared. The address field must be
* zero if the PMI bit is zero.
*/
switch (status) {
case 0:
/* Return failure if we did not get valid capacity data. */
if (ucmd_buf.uscsi_resid != 0) {
return (EIO);
}
/*
* Read capacity and block size from the READ CAPACITY 10 data.
* This data may be adjusted later due to device specific
* issues.
*
* According to the SCSI spec, the READ CAPACITY 10
* command returns the following:
*
* bytes 0-3: Maximum logical block address available.
* (MSB in byte:0 & LSB in byte:3)
*
* bytes 4-7: Block length in bytes
* (MSB in byte:4 & LSB in byte:7)
*
*/
/*
* Done with capacity_buf
*/
/*
* if the reported capacity is set to all 0xf's, then
* this disk is too large and requires SBC-2 commands.
* Reissue the request using READ CAPACITY 16.
*/
if (capacity == 0xffffffff) {
if (status != 0) {
return (status);
}
}
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
/*
* (LOGICAL UNIT IS IN PROCESS OF BECOMING READY)
*/
return (EAGAIN);
}
break;
default:
break;
}
/* FALLTHRU */
default:
return (status);
}
/*
* Some ATAPI CD-ROM drives report inaccurate LBA size values
* (2352 and 0 are common) so for these devices always force the value
* to 2048 as required by the ATAPI specs.
*/
lbasize = 2048;
}
/*
* Get the maximum LBA value from the READ CAPACITY data.
* Here we assume that the Partial Medium Indicator (PMI) bit
* was cleared when issuing the command. This means that the LBA
* returned from the device is the LBA of the last logical block
* on the logical unit. The actual logical block count will be
* this value plus one.
*
* Currently the capacity is saved in terms of un->un_sys_blocksize,
* so scale the capacity value to reflect this.
*/
/*
* Refer to comments related to off-by-1 at the
* header of this file.
* Treat 1TB disk as (1T - 512)B.
*/
#endif
/*
* Copy the values from the READ CAPACITY command into the space
* provided by the caller.
*/
/*
* Both the lbasize and capacity from the device must be nonzero,
* otherwise we assume that the values are not valid and return
* failure to the caller. (4203735)
*/
return (EIO);
}
return (0);
}
/*
* Function: sd_send_scsi_READ_CAPACITY_16
*
* Description: This routine uses the scsi READ CAPACITY 16 command to
* determine the device capacity in number of blocks and the
* device native block size. If this function returns a failure,
* then the values in *capp and *lbap are undefined.
* This routine should always be called by
* sd_send_scsi_READ_CAPACITY which will appy any device
* specific adjustments to capacity and lbasize.
*
* Arguments: un - ptr to soft state struct for the target
* capp - ptr to unsigned 64-bit variable to receive the
* capacity value from the command.
* lbap - ptr to unsigned 32-bit varaible to receive the
* block size value from the command
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq. SD_PATH_DIRECT_PRIORITY is used when
* this command is issued as part of an error recovery
* action.
*
* Return Code: 0 - Success
* EIO - IO error
* EACCES - Reservation conflict detected
* EAGAIN - Device is becoming ready
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Blocks until command completes.
*/
#define SD_CAPACITY_16_SIZE sizeof (struct scsi_capacity_16)
static int
{
struct scsi_extended_sense sense_buf;
int status;
"sd_send_scsi_READ_CAPACITY: entry: un:0x%p\n", un);
/*
* First send a READ_CAPACITY_16 command to the target.
*
* Set up the CDB for the READ_CAPACITY_16 command. The Partial
* Medium Indicator bit is cleared. The address field must be
* zero if the PMI bit is zero.
*/
/*
* Read Capacity (16) is a Service Action In command. One
* command byte (0x9E) is overloaded for multiple operations,
* with the second CDB byte specifying the desired operation
*/
/*
* Fill in allocation length field
*/
switch (status) {
case 0:
/* Return failure if we did not get valid capacity data. */
return (EIO);
}
/*
* Read capacity and block size from the READ CAPACITY 10 data.
* This data may be adjusted later due to device specific
* issues.
*
* According to the SCSI spec, the READ CAPACITY 10
* command returns the following:
*
* bytes 0-7: Maximum logical block address available.
* (MSB in byte:0 & LSB in byte:7)
*
* bytes 8-11: Block length in bytes
* (MSB in byte:8 & LSB in byte:11)
*
*/
/*
* Done with capacity16_buf
*/
/*
* if the reported capacity is set to all 0xf's, then
* this disk is too large. This could only happen with
* a device that supports LBAs larger than 64 bits which
* are not defined by any current T10 standards.
*/
if (capacity == 0xffffffffffffffff) {
return (EIO);
}
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
/*
* (LOGICAL UNIT IS IN PROCESS OF BECOMING READY)
*/
return (EAGAIN);
}
break;
default:
break;
}
/* FALLTHRU */
default:
return (status);
}
return (0);
}
/*
* Function: sd_send_scsi_START_STOP_UNIT
*
* Description: Issue a scsi START STOP UNIT command to the target.
*
* Arguments: un - pointer to driver soft state (unit) structure for
* this target.
* flag - SD_TARGET_START
* SD_TARGET_STOP
* SD_TARGET_EJECT
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq. SD_PATH_DIRECT_PRIORITY is used when this
* command is issued as part of an error recovery action.
*
* Return Code: 0 - Success
* EIO - IO error
* EACCES - Reservation conflict detected
* ENXIO - Not Ready, medium not present
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
"sd_send_scsi_START_STOP_UNIT: entry: un:0x%p\n", un);
if (un->un_f_check_start_stop &&
return (0);
}
ucmd_buf.uscsi_buflen = 0;
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
switch (scsi_sense_key(
case KEY_ILLEGAL_REQUEST:
break;
case KEY_NOT_READY:
if (scsi_sense_asc(
== 0x3A) {
}
break;
default:
break;
}
}
break;
default:
break;
}
break;
default:
break;
}
return (status);
}
/*
* Function: sd_start_stop_unit_callback
*
* Description: timeout(9F) callback to begin recovery process for a
* device that has spun down.
*
* Arguments: arg - pointer to associated softstate struct.
*
* Context: Executes in a timeout(9F) thread context
*/
static void
sd_start_stop_unit_callback(void *arg)
{
}
/*
* Function: sd_start_stop_unit_task
*
* Description: Recovery procedure when a drive is spun down.
*
* Arguments: arg - pointer to associated softstate struct.
*
* Context: Executes in a taskq() thread context
*/
static void
sd_start_stop_unit_task(void *arg)
{
/*
* Some unformatted drives report not ready error, no need to
* restart if format has been initiated.
*/
return;
}
/*
* When a START STOP command is issued from here, it is part of a
* failure recovery operation and must be issued before any other
* commands, including any pending retries. Thus it must be sent
* using SD_PATH_DIRECT_PRIORITY. It doesn't matter if the spin up
* succeeds or not, we will start I/O after the attempt.
*/
/*
* The above call blocks until the START_STOP_UNIT command completes.
* Now that it has completed, we must re-try the original IO that
* received the NOT READY condition in the first place. There are
* three possible conditions here:
*
* (1) The original IO is on un_retry_bp.
* (2) The original IO is on the regular wait queue, and un_retry_bp
* is NULL.
* (3) The original IO is on the regular wait queue, and un_retry_bp
* points to some other, unrelated bp.
*
* For each case, we must call sd_start_cmds() with un_retry_bp
* as the argument. If un_retry_bp is NULL, this will initiate
* processing of the regular wait queue. If un_retry_bp is not NULL,
* then this will process the bp on un_retry_bp. That may or may not
* be the original IO, but that does not matter: the important thing
* is to keep the IO processing going at this point.
*
* Note: This is a very specific error recovery sequence associated
* with a drive that is not spun up. We attempt a START_STOP_UNIT and
* serialize the I/O with completion of the spin-up.
*/
"sd_start_stop_unit_task: un:0x%p starting bp:0x%p\n",
}
/*
* Function: sd_send_scsi_INQUIRY
*
* Description: Issue the scsi INQUIRY command.
*
* Arguments: un
* bufaddr
* buflen
* evpd
* page_code
* page_length
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
int status;
ucmd_buf.uscsi_rqlen = 0;
}
return (status);
}
/*
* Function: sd_send_scsi_TEST_UNIT_READY
*
* Description: Issue the scsi TEST UNIT READY command.
* This routine can be told to set the flag USCSI_DIAGNOSE to
* prevent retrying failed commands. Use this when the intent
* is either to check for device readiness, to clear a Unit
* Attention, or to clear any outstanding sense data.
* However under specific conditions the expected behavior
* is for retries to bring a device ready, so use the flag
* with caution.
*
* Arguments: un
* flag: SD_CHECK_FOR_MEDIA: return ENXIO if no media present
* SD_DONT_RETRY_TUR: include uscsi flag USCSI_DIAGNOSE.
* 0: dont check for media present, do retries on cmd.
*
* Return Code: 0 - Success
* EIO - IO error
* EACCES - Reservation conflict detected
* ENXIO - Not Ready, medium not present
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
"sd_send_scsi_TEST_UNIT_READY: entry: un:0x%p\n", un);
/*
* Some Seagate elite1 TQ devices get hung with disconnect/reconnect
* timeouts when they receive a TUR and the queue is not empty. Check
* the configuration flag set during attach (indicating the drive has
* this firmware bug) and un_ncmds_in_transport before issuing the
* TUR. If there are
* pending commands return success, this is a bit arbitrary but is ok
* for non-removables (i.e. the eliteI disks) and non-clustering
* configurations.
*/
if (un->un_ncmds_in_transport != 0) {
return (0);
}
}
ucmd_buf.uscsi_buflen = 0;
/* Use flag USCSI_DIAGNOSE to prevent retries if it fails. */
if ((flag & SD_DONT_RETRY_TUR) != 0) {
}
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
if ((flag & SD_CHECK_FOR_MEDIA) == 0) {
break;
}
KEY_NOT_READY) &&
}
break;
default:
break;
}
break;
default:
break;
}
return (status);
}
/*
* Function: sd_send_scsi_PERSISTENT_RESERVE_IN
*
* Description: Issue the scsi PERSISTENT RESERVE IN command.
*
* Arguments: un
*
* Return Code: 0 - Success
* EACCES
* ENOTSUP
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
int no_caller_buf = FALSE;
"sd_send_scsi_PERSISTENT_RESERVE_IN: entry: un:0x%p\n", un);
/* Allocate a default buf if the caller did not give one */
}
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
}
break;
default:
break;
}
break;
default:
break;
}
if (no_caller_buf == TRUE) {
}
return (status);
}
/*
* Function: sd_send_scsi_PERSISTENT_RESERVE_OUT
*
* Description: This routine is the driver entry point for handling CD-ROM
* multi-host persistent reservation requests (MHIOCGRP_INKEYS,
* MHIOCGRP_INRESV) by sending the SCSI-3 PROUT commands to the
* device.
*
* Arguments: un - Pointer to soft state struct for the target.
* usr_cmd SCSI-3 reservation facility command (one of
* SD_SCSI3_REGISTER, SD_SCSI3_RESERVE, SD_SCSI3_RELEASE,
* SD_SCSI3_PREEMPTANDABORT)
* usr_bufp - user provided pointer register, reserve descriptor or
* preempt and abort structure (mhioc_register_t,
* mhioc_resv_desc_t, mhioc_preemptandabort_t)
*
* Return Code: 0 - Success
* EACCES
* ENOTSUP
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
"sd_send_scsi_PERSISTENT_RESERVE_OUT: entry: un:0x%p\n", un);
return (EINVAL);
}
switch (usr_cmd) {
case SD_SCSI3_REGISTER: {
break;
}
case SD_SCSI3_RESERVE:
case SD_SCSI3_RELEASE: {
break;
}
case SD_SCSI3_PREEMPTANDABORT: {
break;
}
{
break;
}
default:
break;
}
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
}
break;
default:
break;
}
break;
default:
break;
}
return (status);
}
/*
* Function: sd_send_scsi_SYNCHRONIZE_CACHE
*
* Description: Issues a scsi SYNCHRONIZE CACHE command to the target
*
* Arguments: un - pointer to the target's soft state struct
*
* Return Code: 0 - success
* errno-type error code
*
* Context: kernel thread context only.
*/
static int
{
struct sd_uscsi_info *uip;
int rval = 0;
"sd_send_scsi_SYNCHRONIZE_CACHE: entry: un:0x%p\n", un);
/*
* First get some memory for the uscsi_cmd struct and cdb
* and initialize for SYNCHRONIZE_CACHE cmd.
*/
uscmd->uscsi_buflen = 0;
/*
* Allocate an sd_uscsi_info struct and fill it with the info
* needed by sd_initpkt_for_uscsi(). Then put the pointer into
* b_private in the buf for sd_initpkt_for_uscsi(). Note that
* since we allocate the buf here in this function, we do not
* need to preserve the prior contents of b_private.
* The sd_uscsi_info struct is also used by sd_uscsi_strategy()
*/
/*
* Setup buffer to carry uscsi request.
*/
}
(void) sd_uscsi_strategy(bp);
/*
* If synchronous request, wait for completion
* If async just return and let b_iodone callback
* cleanup.
* NOTE: On return, u_ncmds_in_driver will be decremented,
* but it was also incremented in sd_uscsi_strategy(), so
* we should be ok.
*/
}
return (rval);
}
static int
{
struct sd_uscsi_info *uip;
int status;
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (uscmd->uscsi_status) {
/* Ignore reservation conflict */
status = 0;
goto done;
case STATUS_CHECK:
(scsi_sense_key(sense_buf) ==
/* Ignore Illegal Request error */
goto done;
}
break;
default:
break;
}
/* FALLTHRU */
default:
/* Ignore error if the media is not present */
if (sd_send_scsi_TEST_UNIT_READY(un, 0) != 0) {
status = 0;
goto done;
}
/* If we reach this, we had an error */
"SYNCHRONIZE CACHE command failed (%d)\n", status);
break;
}
done:
}
return (status);
}
/*
* Function: sd_send_scsi_GET_CONFIGURATION
*
* Description: Issues the get configuration command to the device.
* Called from sd_check_for_writable_cd & sd_get_media_info
* caller needs to ensure that buflen = SD_PROFILE_HEADER_LEN
* Arguments: un
* ucmdbuf
* rqbuf
* rqbuflen
* bufaddr
* buflen
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*
*/
static int
{
char cdb[CDB_GROUP1];
int status;
"sd_send_scsi_GET_CONFIGURATION: entry: un:0x%p\n", un);
/*
* Set up cdb field for the get configuration command.
*/
cdb[0] = SCMD_GET_CONFIGURATION;
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmdbuf->uscsi_status) {
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
"sd_send_scsi_GET_CONFIGURATION: data",
}
"sd_send_scsi_GET_CONFIGURATION: exit\n");
return (status);
}
/*
* Function: sd_send_scsi_feature_GET_CONFIGURATION
*
* Description: Issues the get configuration command to the device to
* retrieve a specfic feature. Called from
* sd_check_for_writable_cd & sd_set_mmc_caps.
* Arguments: un
* ucmdbuf
* rqbuf
* rqbuflen
* bufaddr
* buflen
* feature
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*
*/
static int
{
char cdb[CDB_GROUP1];
int status;
"sd_send_scsi_feature_GET_CONFIGURATION: entry: un:0x%p\n", un);
/*
* Set up cdb field for the get configuration command.
*/
cdb[0] = SCMD_GET_CONFIGURATION;
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmdbuf->uscsi_status) {
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
"sd_send_scsi_feature_GET_CONFIGURATION: data",
}
"sd_send_scsi_feature_GET_CONFIGURATION: exit\n");
return (status);
}
/*
* Function: sd_send_scsi_MODE_SENSE
*
* Description: Utility function for issuing a scsi MODE SENSE command.
* Note: This routine uses a consistent implementation for Group0,
* Group1, and Group2 commands across all platforms. ATAPI devices
*
* Arguments: un - pointer to the softstate struct for the target.
* cdbsize - size CDB to be used (CDB_GROUP0 (6 byte), or
* CDB_GROUP[1|2] (10 byte).
* bufaddr - buffer for page data retrieved from the target.
* buflen - size of page to be retrieved.
* page_code - page code of data to be retrieved from the target.
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
int headlen;
(cdbsize == CDB_GROUP2));
"sd_send_scsi_MODE_SENSE: entry: un:0x%p\n", un);
if (cdbsize == CDB_GROUP0) {
} else {
}
switch (status) {
case 0:
/*
* sr_check_wp() uses 0x3f page code and check the header of
* mode page to determine if target device is write-protected.
* But some USB devices return 0 bytes for 0x3f page code. For
* this case, make sure that mode page header is returned at
* least.
*/
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
}
return (status);
}
/*
* Function: sd_send_scsi_MODE_SELECT
*
* Description: Utility function for issuing a scsi MODE SELECT command.
* Note: This routine uses a consistent implementation for Group0,
* Group1, and Group2 commands across all platforms. ATAPI devices
*
* Arguments: un - pointer to the softstate struct for the target.
* cdbsize - size CDB to be used (CDB_GROUP0 (6 byte), or
* CDB_GROUP[1|2] (10 byte).
* bufaddr - buffer for page data retrieved from the target.
* buflen - size of page to be retrieved.
* save_page - boolean to determin if SP bit should be set.
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
(cdbsize == CDB_GROUP2));
"sd_send_scsi_MODE_SELECT: entry: un:0x%p\n", un);
/* Set the PF bit for many third party drives */
/* Set the savepage(SP) bit if given */
if (save_page == SD_SAVE_PAGE) {
}
if (cdbsize == CDB_GROUP0) {
} else {
}
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
}
return (status);
}
/*
* Function: sd_send_scsi_RDWR
*
* Description: Issue a scsi READ or WRITE command with the given parameters.
*
* Arguments: un: Pointer to the sd_lun struct for the target.
* cmd: SCMD_READ or SCMD_WRITE
* bufaddr: Address of caller's buffer to receive the RDWR data
* buflen: Length of caller's buffer receive the RDWR data.
* start_block: Block number for the start of the RDWR operation.
* (Assumes target-native block size.)
* residp: Pointer to variable to receive the redisual of the
* RDWR operation (may be NULL of no residual requested).
* path_flag - SD_PATH_DIRECT to use the USCSI "direct" chain and
* the normal command waitq, or SD_PATH_DIRECT_PRIORITY
* to use the USCSI "direct" chain and bypass the normal
* command waitq.
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
struct scsi_extended_sense sense_buf;
int status;
int cdbsize;
return (EINVAL);
}
"bufaddr:0x%p buflen:0x%x start_block:0x%p block_count:0x%x\n",
/* Compute CDB size to use */
if (start_block > 0xffffffff)
else if ((start_block & 0xFFE00000) ||
else
switch (cdbsize) {
case CDB_GROUP0: /* 6-byte CDBs */
break;
case CDB_GROUP1: /* 10-byte CDBs */
break;
case CDB_GROUP4: /* 16-byte CDBs */
break;
case CDB_GROUP5: /* 12-byte CDBs (currently unsupported) */
default:
/* All others reserved */
return (EINVAL);
}
/* Set LUN bit(s) in CDB if this is a SCSI-1 device */
switch (status) {
case 0:
break; /* Success! */
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
}
return (status);
}
/*
* Function: sd_send_scsi_LOG_SENSE
*
* Description: Issue a scsi LOG_SENSE command with the given parameters.
*
* Arguments: un: Pointer to the sd_lun struct for the target.
*
* Return Code: 0 - Success
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
int path_flag)
{
struct scsi_extended_sense sense_buf;
int status;
switch (status) {
case 0:
break;
case EIO:
switch (ucmd_buf.uscsi_status) {
break;
case STATUS_CHECK:
/*
* ASC 0x24: INVALID FIELD IN CDB
*/
switch (page_code) {
case START_STOP_CYCLE_PAGE:
/*
* The start stop cycle counter is
* implemented as page 0x31 in earlier
* generation disks. In new generation
* disks the start stop cycle counter is
* implemented as page 0xE. To properly
* handle this case if an attempt for
* log page 0xE is made and fails we
* will try again using page 0x31.
*
* Network storage BU committed to
* maintain the page 0x31 for this
* purpose and will not have any other
* page implemented with page code 0x31
* until all disks transition to the
* standard page.
*/
(char)(page_control << 6) |
break;
case TEMPERATURE_PAGE:
break;
default:
break;
}
}
break;
default:
break;
}
break;
default:
break;
}
if (status == 0) {
}
return (status);
}
/*
* Function: sdioctl
*
* Description: Driver's ioctl(9e) entry point function.
*
* Arguments: dev - device number
* cmd - ioctl operation to be performed
* arg - user argument, contains data to be set or reference
* parameter for get
* flag - bit flag, indicating open settings, 32/64 bit type
* cred_p - user credential pointer
* rval_p - calling process return value (OPT)
*
* Return Code: EINVAL
* ENOTTY
* ENXIO
* EIO
* EFAULT
* ENOTSUP
* EPERM
*
* Context: Called from the device switch at normal priority.
*/
static int
{
int geom_validated = FALSE;
int err = 0;
int i = 0;
/*
* All device accesses go thru sdstrategy where we check on suspend
* status
*/
return (ENXIO);
}
/*
* Moved this wait from sd_uscsi_strategy to here for
* reasons of deadlock prevention. Internal driver commands,
* specifically those to change a devices power level, result
* in a call to sd_uscsi_strategy.
*/
}
/*
* Twiddling the counter here protects commands from now
* through to the top of sd_uscsi_strategy. Without the
* counter inc. a power down, for example, could get in
* after the above check for state is made and before
* execution gets to the top of sd_uscsi_strategy.
* That would cause problems.
*/
un->un_ncmds_in_driver++;
switch (cmd) {
case CDROMPAUSE:
case CDROMRESUME:
case CDROMPLAYMSF:
case CDROMPLAYTRKIND:
case CDROMREADTOCHDR:
case CDROMREADTOCENTRY:
case CDROMSTOP:
case CDROMSTART:
case CDROMVOLCTRL:
case CDROMSUBCHNL:
case CDROMREADMODE2:
case CDROMREADMODE1:
case CDROMREADOFFSET:
case CDROMSBLKMODE:
case CDROMGBLKMODE:
case CDROMGDRVSPEED:
case CDROMSDRVSPEED:
case CDROMCDDA:
case CDROMCDXA:
case CDROMSUBCODE:
un->un_ncmds_in_driver--;
return (ENOTTY);
}
break;
case FDEJECT:
case DKIOCEJECT:
case CDROMEJECT:
if (!un->un_f_eject_media_supported) {
un->un_ncmds_in_driver--;
return (ENOTTY);
}
break;
case DKIOCSVTOC:
case DKIOCSETEFI:
case DKIOCSMBOOT:
case DKIOCFLUSHWRITECACHE:
if (err != 0) {
un->un_ncmds_in_driver--;
return (EIO);
}
/* FALLTHROUGH */
case DKIOCREMOVABLE:
case DKIOCHOTPLUGGABLE:
case DKIOCINFO:
case DKIOCGMEDIAINFO:
case MHIOCENFAILFAST:
case MHIOCSTATUS:
case MHIOCTKOWN:
case MHIOCRELEASE:
case MHIOCGRP_INKEYS:
case MHIOCGRP_INRESV:
case MHIOCGRP_REGISTER:
case MHIOCGRP_RESERVE:
case MHIOCGRP_PREEMPTANDABORT:
case CDROMCLOSETRAY:
case USCSICMD:
goto skip_ready_valid;
default:
break;
}
if (err == SD_READY_NOT_VALID) {
switch (cmd) {
case DKIOCGAPART:
case DKIOCGGEOM:
case DKIOCSGEOM:
case DKIOCGVTOC:
case DKIOCSVTOC:
case DKIOCSAPART:
case DKIOCG_PHYGEOM:
case DKIOCG_VIRTGEOM:
un->un_ncmds_in_driver--;
return (err);
}
}
if (err != SD_READY_VALID) {
switch (cmd) {
case DKIOCSTATE:
case CDROMGDRVSPEED:
case CDROMSDRVSPEED:
case FDEJECT: /* for eject command */
case DKIOCEJECT:
case CDROMEJECT:
case DKIOCGETEFI:
case DKIOCSGEOM:
case DKIOCREMOVABLE:
case DKIOCHOTPLUGGABLE:
case DKIOCSAPART:
case DKIOCSETEFI:
break;
default:
if (un->un_f_has_removable_media) {
} else {
/* Do not map EACCES to EIO */
}
un->un_ncmds_in_driver--;
return (err);
}
}
}
(un->un_solaris_size > 0)) {
/*
* the "geometry_is_valid" flag could be true if we
* have an fdisk table but no Solaris partition
*/
/* it is EFI, so return ENOTSUP for these */
switch (cmd) {
case DKIOCGAPART:
case DKIOCGGEOM:
case DKIOCGVTOC:
case DKIOCSVTOC:
case DKIOCSAPART:
un->un_ncmds_in_driver--;
return (err);
}
}
}
switch (cmd) {
case DKIOCINFO:
break;
case DKIOCGMEDIAINFO:
break;
case DKIOCGGEOM:
break;
case DKIOCSGEOM:
break;
case DKIOCGAPART:
break;
case DKIOCSAPART:
break;
case DKIOCGVTOC:
break;
case DKIOCGETEFI:
break;
case DKIOCPARTITION:
break;
case DKIOCSVTOC:
break;
case DKIOCSETEFI:
break;
case DKIOCGMBOOT:
break;
case DKIOCSMBOOT:
break;
case DKIOCLOCK:
break;
case DKIOCUNLOCK:
break;
case DKIOCSTATE: {
enum dkio_state state;
} else {
if (err == 0) {
sizeof (int), flag) != 0)
}
}
break;
}
case DKIOCREMOVABLE:
/*
* At present, vold only does automount for removable-media
* devices, in order not to break current applications, we
* still let hopluggable devices pretend to be removable media
* devices for vold. In the near future, once vold is EOL'ed,
* we should remove this workaround.
*/
i = 1;
} else {
i = 0;
}
} else {
err = 0;
}
break;
case DKIOCHOTPLUGGABLE:
if (un->un_f_is_hotpluggable) {
i = 1;
} else {
i = 0;
}
} else {
err = 0;
}
break;
case DKIOCGTEMPERATURE:
break;
case MHIOCENFAILFAST:
}
break;
case MHIOCTKOWN:
}
break;
case MHIOCRELEASE:
}
break;
case MHIOCSTATUS:
switch (sd_send_scsi_TEST_UNIT_READY(un, 0)) {
case 0:
err = 0;
break;
case EACCES:
*rval_p = 1;
err = 0;
break;
default:
break;
}
}
break;
case MHIOCQRESERVE:
}
break;
case MHIOCREREGISTERDEVID:
} else if (!un->un_f_devid_supported) {
} else {
}
break;
case MHIOCGRP_INKEYS:
} else {
flag);
}
}
break;
case MHIOCGRP_INRESV:
} else {
}
}
break;
case MHIOCGRP_REGISTER:
sizeof (mhioc_register_t), flag) != 0) {
} else {
err =
}
}
}
break;
case MHIOCGRP_RESERVE:
sizeof (mhioc_resv_desc_t), flag) != 0) {
} else {
err =
}
}
}
break;
case MHIOCGRP_PREEMPTANDABORT:
sizeof (mhioc_preemptandabort_t),
flag) != 0) {
} else {
err =
(uchar_t *)&preempt_abort);
}
}
}
break;
sizeof (mhioc_registerandignorekey_t),
flag) != 0) {
} else {
err =
}
}
}
break;
case USCSICMD:
cr = ddi_get_cred();
} else {
}
break;
case CDROMPAUSE:
case CDROMRESUME:
} else {
}
break;
case CDROMPLAYMSF:
} else {
}
break;
case CDROMPLAYTRKIND:
/*
* not supported on ATAPI CD drives, use CDROMPLAYMSF instead
*/
#else
#endif
} else {
}
break;
case CDROMREADTOCHDR:
} else {
}
break;
case CDROMREADTOCENTRY:
} else {
}
break;
case CDROMSTOP:
} else {
}
break;
case CDROMSTART:
} else {
}
break;
case CDROMCLOSETRAY:
} else {
}
break;
case FDEJECT: /* for eject command */
case DKIOCEJECT:
case CDROMEJECT:
if (!un->un_f_eject_media_supported) {
} else {
}
break;
case CDROMVOLCTRL:
} else {
}
break;
case CDROMSUBCHNL:
} else {
}
break;
case CDROMREADMODE2:
/*
* If the drive supports READ CD, use that instead of
* switching the LBA size via a MODE SELECT
* Block Descriptor
*/
} else {
}
break;
case CDROMREADMODE1:
} else {
}
break;
case CDROMREADOFFSET:
} else {
flag);
}
break;
case CDROMSBLKMODE:
/*
* There is no means of changing block size in case of atapi
* drives, thus return ENOTTY if drive type is atapi
*/
/*
* MMC Devices do not support changing the
* logical block size
*
* Note: EINVAL is being returned instead of ENOTTY to
* maintain consistancy with the original mmc
* driver update.
*/
} else {
(un->un_ncmds_in_transport > 0)) {
} else {
}
}
break;
case CDROMGBLKMODE:
/*
* Drive is an ATAPI drive so return target block
* size for ATAPI drives since we cannot change the
* blocksize on ATAPI drives. Used primarily to detect
* if an ATAPI cdrom is present.
*/
sizeof (int), flag) != 0) {
} else {
err = 0;
}
} else {
/*
* Drive supports changing block sizes via a Mode
* Select.
*/
}
break;
case CDROMGDRVSPEED:
case CDROMSDRVSPEED:
/*
* Note: In the future the driver implementation
* for getting and
* setting cd speed should entail:
* 1) If non-mmc try the Toshiba mode page
* (sr_change_speed)
* 2) If mmc but no support for Real Time Streaming try
* the SET CD SPEED (0xBB) command
* (sr_atapi_change_speed)
* 3) If mmc and support for Real Time Streaming
* try the GET PERFORMANCE and SET STREAMING
* commands (not yet implemented, 4380808)
*/
/*
* As per recent MMC spec, CD-ROM speed is variable
* and changes with LBA. Since there is no such
* things as drive speed now, fail this ioctl.
*
* Note: EINVAL is returned for consistancy of original
* implementation which included support for getting
* the drive speed of mmc devices but not setting
* the drive speed. Thus EINVAL would be returned
* if a set request was made for an mmc device.
* We no longer support get or set speed for
* mmc but need to remain consistant with regard
* to the error code returned.
*/
} else {
}
break;
case CDROMCDDA:
} else {
}
break;
case CDROMCDXA:
} else {
}
break;
case CDROMSUBCODE:
} else {
}
break;
case DKIOCPARTINFO: {
/*
* Return parameters describing the selected disk slice.
* Note: this ioctl is for the intel platform only
*/
int part;
/* don't check un_solaris_size for pN */
} else {
struct part_info p;
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
{
struct part_info32 p32;
break;
}
case DDI_MODEL_NONE:
{
if (ddi_copyout(&p, (void *)arg, sizeof (p),
flag))
break;
}
}
#else /* ! _MULTI_DATAMODEL */
#endif /* _MULTI_DATAMODEL */
}
#else
#endif
break;
}
case DKIOCG_PHYGEOM: {
/* Return the driver's notion of the media physical geometry */
/*
* We succeeded in getting a geometry, but
* right now it is being reported as just the
* Solaris fdisk partition, just like for
* DKIOCGGEOM. We need to change that to be
* correct for the entire disk now.
*/
} else {
/*
* This disk does not have a Solaris VTOC
* so we must present a physical geometry
* that will remain consistent regardless
* of how the disk is used. This will ensure
* that the geometry does not change regardless
* of the fdisk partition type (ie. EFI, FAT32,
* Solaris, etc).
*/
} else {
/*
* Invalid un_blockcount can generate invalid
* dk_geom and may result in division by zero
* system failure. Should make sure blockcount
* is valid before using it here.
*/
break;
}
/*
* Refer to comments related to off-by-1 at the
* header of this file
*/
if (!un->un_f_capacity_adjusted &&
!un->un_f_is_hotpluggable &&
(un->un_tgt_blocksize ==
else
}
}
} else {
err = 0;
}
#else
#endif
break;
}
case DKIOCG_VIRTGEOM: {
/* Return the driver's notion of the media's logical geometry */
/*
* If there is no HBA geometry available, or
* if the HBA returned us something that doesn't
* really fit into an Int 13/function 8 geometry
* result, just fail the ioctl. See PSARC 1998/313.
*/
} else {
} else {
err = 0;
}
}
#else
#endif
break;
}
#ifdef SDDEBUG
case DKIOCRESET: {
int reset_level;
} else {
"reset_level = 0x%lx\n", reset_level);
err = 0;
} else {
}
}
break;
}
case DKIOCABORT:
err = 0;
} else {
}
break;
#endif
#ifdef SD_FAULT_INJECTION
/* SDIOC FaultInjection testing ioctls */
case SDIOCSTART:
case SDIOCSTOP:
case SDIOCINSERTPKT:
case SDIOCINSERTXB:
case SDIOCINSERTUN:
case SDIOCINSERTARQ:
case SDIOCPUSH:
case SDIOCRETRIEVE:
case SDIOCRUN:
"SDIOC detected cmd:0x%X:\n", cmd);
/* call error generator */
err = 0;
break;
#endif /* SD_FAULT_INJECTION */
case DKIOCFLUSHWRITECACHE:
{
if (!un->un_f_sync_cache_supported ||
0 : ENOTSUP;
err);
/*
* Did callback and reported error.
* Since we did a callback, ioctl
* should return 0.
*/
err = 0;
}
break;
}
/* async SYNC CACHE request */
} else {
/* synchronous SYNC CACHE request */
}
}
break;
case DKIOCGETWCE: {
int wce;
break;
}
}
break;
}
case DKIOCSETWCE: {
int wce, sync_supported;
break;
}
/*
* Synchronize multiple threads trying to enable
* or disable the cache via the un_f_wcc_cv
* condition variable.
*/
/*
* Don't allow the cache to be enabled if the
* config file has it disabled.
*/
break;
}
/*
* Wait for write cache change in progress
* bit to be clear before proceeding.
*/
while (un->un_f_wcc_inprog)
/*
* Disable the write cache. Don't clear
* un_f_write_cache_enabled until after
* the mode select and flush are complete.
*/
SD_CACHE_DISABLE)) == 0 && sync_supported) {
}
if (err == 0) {
un->un_f_write_cache_enabled = 0;
}
/*
* Set un_f_write_cache_enabled first, so there is
* no window where the cache is enabled, but the
* bit says it isn't.
*/
if (err) {
un->un_f_write_cache_enabled = 0;
}
}
un->un_f_wcc_inprog = 0;
break;
}
default:
break;
}
un->un_ncmds_in_driver--;
return (err);
}
/*
* Function: sd_uscsi_ioctl
*
* Description: This routine is the driver entry point for handling USCSI ioctl
* requests (USCSICMD).
*
* Arguments: dev - the device number
* arg - user provided scsi command
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: code returned by sd_send_scsi_cmd
* ENXIO
* EFAULT
* EAGAIN
*/
static int
{
#ifdef _MULTI_DATAMODEL
/*
* For use when a 32 bit app makes a call into a
* 64 bit ioctl
*/
struct uscsi_cmd32 uscsi_cmd_32_for_64;
#endif /* _MULTI_DATAMODEL */
char cdb[CDB_GROUP0];
int rval = 0;
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
{
goto done;
}
/*
* Convert the ILP32 uscsi data from the
* application to LP64 for internal use.
*/
break;
}
case DDI_MODEL_NONE:
goto done;
}
break;
}
#else /* ! _MULTI_DATAMODEL */
goto done;
}
#endif /* _MULTI_DATAMODEL */
goto done;
}
/*
* Gotta do the ddi_copyin() here on the uscsi_cdb so that
* we will have a valid cdb[0] to test.
*/
(cdb[0] == SCMD_FORMAT)) {
"sd_uscsi_ioctl: scmd->uscsi_cdb 0x%x\n", cdb[0]);
} else {
"sd_uscsi_ioctl: scmd->uscsi_cdb 0x%x\n", cdb[0]);
/*
* It's OK to fall into here even if the ddi_copyin()
* on the uscsi_cdb above fails, because sd_send_scsi_cmd()
* does this same copyin and will return the EFAULT
* if it fails.
*/
}
#ifdef _MULTI_DATAMODEL
switch (model) {
case DDI_MODEL_ILP32:
/*
* Convert back to ILP32 before copyout to the
* application
*/
if (rval != 0) {
}
}
break;
case DDI_MODEL_NONE:
if (rval != 0) {
}
}
break;
}
#else /* ! _MULTI_DATAMODE */
if (rval != 0) {
}
}
#endif /* _MULTI_DATAMODE */
done:
return (rval);
}
/*
* Function: sd_dkio_ctrl_info
*
* Description: This routine is the driver entry point for handling controller
* information ioctl requests (DKIOCINFO).
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_cinfo structure
* specifying the controller type and attributes.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
*/
static int
{
return (ENXIO);
}
case CTYPE_CDROM:
break;
default:
break;
}
} else {
DK_DEVLEN - 1);
}
/* Unit Information */
DK_DEVLEN - 1);
/* Max Transfer size of this device in blocks */
return (EFAULT);
} else {
return (0);
}
}
/*
* Function: sd_get_media_info
*
* Description: This routine is the driver entry point for handling ioctl
* requests for the media type or command set profile used by the
* drive to operate on the media (DKIOCGMEDIAINFO).
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_minfo structure
* specifying the media type, logical block size and
* drive capacity.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EACCESS
* EFAULT
* ENXIO
* EIO
*/
static int
{
struct scsi_inquiry *sinq;
struct dk_minfo media_info;
int rval = 0;
int rtn;
return (ENXIO);
}
/* Issue a TUR to determine if the drive is ready with media present */
goto done;
}
/* Now get configuration data */
/* Allow SCMD_GET_CONFIGURATION to MMC devices only */
if (rtn) {
/*
* Failed for other than an illegal request
* or command not supported
*/
goto done;
}
}
} else {
/*
* The GET CONFIGURATION command succeeded
* so set the media type according to the
* returned data
*/
}
}
} else {
/*
* The profile list is not available, so we attempt to identify
* the media type based on the inquiry data
*/
/* This is a direct access device */
} else if (
}
}
} else {
/* Not a CD or direct access so return unknown media */
}
}
/* Now read the capacity so we can provide the lbasize and capacity */
SD_PATH_DIRECT)) {
case 0:
break;
case EACCES:
goto done;
default:
goto done;
}
/*
* sd_send_scsi_READ_CAPACITY() reports capacity in
* un->un_sys_blocksize chunks. So we need to convert it into
* cap.lbasize chunks.
*/
/* Put goto. Anybody might add some code below in future */
goto done;
}
done:
return (rval);
}
/*
* Function: sd_dkio_get_geometry
*
* Description: This routine is the driver entry point for handling user
* requests to get the device geometry (DKIOCGGEOM).
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_geom structure specifying
* the controller's notion of the current geometry.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
* geom_validated - flag indicating if the device geometry has been
* previously validated in the sdioctl routine.
*
* Return Code: 0
* EFAULT
* ENXIO
* EIO
*/
static int
{
int rval = 0;
return (ENXIO);
}
if (geom_validated == FALSE) {
/*
* sd_validate_geometry does not spin a disk up
* if it was spun down. We need to make sure it
* is ready.
*/
return (rval);
}
}
if (rval)
return (rval);
/*
* It is possible that un_solaris_size is 0(uninitialized)
* after sd_unit_attach. Reservation conflict may cause the
* above situation. Thus, the zero check of un_solaris_size
* should occur after the sd_validate_geometry() call.
*/
if (un->un_solaris_size == 0) {
return (EIO);
}
#endif
/*
* Make a local copy of the soft state geometry to avoid some potential
* race conditions associated with holding the mutex and updating the
* write_reinstruct value
*/
if (tmp_geom->dkg_write_reinstruct == 0) {
sd_rot_delay) / (int)60000);
}
flag);
if (rval != 0) {
}
return (rval);
}
/*
* Function: sd_dkio_set_geometry
*
* Description: This routine is the driver entry point for handling user
* requests to set the device geometry (DKIOCSGEOM). The actual
* device geometry is not updated, just the driver "notion" of it.
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_geom structure used to set
* the controller's notion of the current geometry.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
* EIO
*/
static int
{
int rval = 0;
int i;
return (ENXIO);
}
/*
* Make sure there is no reservation conflict on the lun.
*/
return (EACCES);
}
if (un->un_solaris_size == 0) {
return (EIO);
}
#endif
/*
* We need to copy the user specified geometry into local
* storage and then update the softstate. We don't want to hold
* the mutex and copyin directly from the user to the soft state
*/
if (rval != 0) {
return (EFAULT);
}
for (i = 0; i < NDKMAP; i++) {
#endif
}
return (rval);
}
/*
* Function: sd_dkio_get_partition
*
* Description: This routine is the driver entry point for handling user
* requests to get the partition table (DKIOCGAPART).
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_allmap structure specifying
* the controller's notion of the current partition table.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
* geom_validated - flag indicating if the device geometry has been
* previously validated in the sdioctl routine.
*
* Return Code: 0
* EFAULT
* ENXIO
* EIO
*/
static int
{
int rval = 0;
int size;
return (ENXIO);
}
/*
* Make sure the geometry is valid before getting the partition
* information.
*/
if (geom_validated == FALSE) {
/*
* sd_validate_geometry does not spin a disk up
* if it was spun down. We need to make sure it
* is ready before validating the geometry.
*/
return (rval);
}
return (rval);
}
}
/*
* It is possible that un_solaris_size is 0(uninitialized)
* after sd_unit_attach. Reservation conflict may cause the
* above situation. Thus, the zero check of un_solaris_size
* should occur after the sd_validate_geometry() call.
*/
if (un->un_solaris_size == 0) {
return (EIO);
}
#endif
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
int i;
for (i = 0; i < NDKMAP; i++) {
}
if (rval != 0) {
}
break;
}
case DDI_MODEL_NONE:
if (rval != 0) {
}
break;
}
#else /* ! _MULTI_DATAMODEL */
if (rval != 0) {
}
#endif /* _MULTI_DATAMODEL */
return (rval);
}
/*
* Function: sd_dkio_set_partition
*
* Description: This routine is the driver entry point for handling user
* requests to set the partition table (DKIOCSAPART). The actual
* device partition is not updated.
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_allmap structure used to set
* the controller's notion of the partition table.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EINVAL
* EFAULT
* ENXIO
* EIO
*/
static int
{
int rval = 0;
int size;
int i;
#if defined(_SUNOS_VTOC_16)
struct dkl_partition *vp;
#endif
return (ENXIO);
}
/*
* Set the map for all logical partitions. We lock
* the priority just to make sure an interrupt doesn't
* come in while the map is half updated.
*/
return (ENOTSUP);
}
/*
* Make sure there is no reservation conflict on the lun.
*/
return (EACCES);
}
if (un->un_solaris_size == 0) {
return (EIO);
}
#endif
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
if (rval != 0) {
return (EFAULT);
}
for (i = 0; i < NDKMAP; i++) {
}
break;
}
case DDI_MODEL_NONE:
if (rval != 0) {
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
if (rval != 0) {
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/* Note: The size used in this bcopy is set based upon the data model */
#if defined(_SUNOS_VTOC_16)
#endif /* defined(_SUNOS_VTOC_16) */
for (i = 0; i < NDKMAP; i++) {
#if defined(_SUNOS_VTOC_16)
vp++;
#endif /* defined(_SUNOS_VTOC_16) */
#endif
}
return (rval);
}
/*
* Function: sd_dkio_get_vtoc
*
* Description: This routine is the driver entry point for handling user
* requests to get the current volume table of contents
* (DKIOCGVTOC).
*
* Arguments: dev - the device number
* arg - pointer to user provided vtoc structure specifying
* the current vtoc.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
* geom_validated - flag indicating if the device geometry has been
* previously validated in the sdioctl routine.
*
* Return Code: 0
* EFAULT
* ENXIO
* EIO
*/
static int
{
#if defined(_SUNOS_VTOC_8)
#endif /* defined(_SUNOS_VTOC_8) */
int rval = 0;
return (ENXIO);
}
if (geom_validated == FALSE) {
/*
* sd_validate_geometry does not spin a disk up
* if it was spun down. We need to make sure it
* is ready.
*/
return (rval);
}
return (rval);
}
}
#if defined(_SUNOS_VTOC_8)
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
struct vtoc32 user_vtoc32;
return (EFAULT);
}
break;
}
case DDI_MODEL_NONE:
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
#elif defined(_SUNOS_VTOC_16)
#ifdef _MULTI_DATAMODEL
/*
* The un_vtoc structure is a "struct dk_vtoc" which is always
* 32-bit to maintain compatibility with existing on-disk
* structures. Thus, we need to convert the structure when copying
* it out to a datamodel-dependent "struct vtoc" in a 64-bit
* program. If the target is a 32-bit program, then no conversion
* is necessary.
*/
/* LINTED: logical expression always true: op "||" */
case DDI_MODEL_ILP32:
return (EFAULT);
}
break;
case DDI_MODEL_NONE: {
return (EFAULT);
}
break;
}
}
#else /* ! _MULTI_DATAMODEL */
flag)) {
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
#else
#error "No VTOC format defined."
#endif
return (rval);
}
static int
{
int rval = 0;
void *buffer;
return (ENXIO);
return (EFAULT);
return (EINVAL);
return (rval);
}
/*
* Function: sd_build_user_vtoc
*
* Description: This routine populates a pass by reference variable with the
* current volume table of contents.
*
* Arguments: un - driver soft state (unit) structure
* user_vtoc - pointer to vtoc structure to be populated
*/
static void
{
int nblks;
int i;
/*
* Return vtoc structure fields in the provided VTOC area, addressed
* by *vtoc.
*/
/*
* Convert partitioning information.
*
* Note the conversion from starting cylinder number
* to starting sector number.
*/
for (i = 0; i < V_NUMPAR; i++) {
lmap++;
lpart++;
vpart++;
/* (4364927) */
}
}
static int
{
struct partition64 p64;
int rval = 0;
return (ENXIO);
}
sizeof (struct partition64), flag)) {
return (EFAULT);
}
1, SD_PATH_DIRECT);
if (rval != 0)
goto done_error;
goto done_error;
/* couldn't find it */
goto done_error;
}
/*
* if we're dealing with a partition that's out of the normal
* 16K block, adjust accordingly
*/
if (rval) {
goto done_error;
}
sizeof (struct uuid));
return (rval);
}
/*
* Function: sd_dkio_set_vtoc
*
* Description: This routine is the driver entry point for handling user
* requests to set the current volume table of contents
* (DKIOCSVTOC).
*
* Arguments: dev - the device number
* arg - pointer to user provided vtoc structure used to set the
* current vtoc.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
* EINVAL
* ENOTSUP
*/
static int
{
int rval = 0;
return (ENXIO);
}
return (EINVAL);
}
#endif
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
struct vtoc32 user_vtoc32;
return (EFAULT);
}
break;
}
case DDI_MODEL_NONE:
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
return (ENOTSUP);
}
return (EINVAL);
}
!= 0) {
"sd_dkio_set_vtoc: "
"Failed validate geometry\n");
}
}
}
/*
* If sd_build_label_vtoc, or sd_write_label failed above write the
* devid anyway, what can it hurt? Also preserve the device id by
* writing to the disk acyl for the case where a devid has been
* fabricated.
*/
if (un->un_f_devid_supported &&
} else {
/*
* The device id for this disk has been
* fabricated. Fabricated device id's are
* managed by storing them in the last 2
* available sectors on the drive. The device
* id must be preserved by writing it back out
* to this location.
*/
if (sd_write_deviceid(un) != 0) {
}
}
}
return (rval);
}
/*
* Function: sd_build_label_vtoc
*
* Description: This routine updates the driver soft state current volume table
* of contents based on a user specified vtoc.
*
* Arguments: un - driver soft state (unit) structure
* user_vtoc - pointer to vtoc structure specifying vtoc to be used
* to update the driver soft state.
*
* Return Code: 0
* EINVAL
*/
static int
{
int nblks;
#if defined(_SUNOS_VTOC_8)
int ncyl;
#endif /* defined(_SUNOS_VTOC_8) */
int i;
/* Sanity-check the vtoc */
return (EINVAL);
}
if (nblks == 0) {
return (EINVAL);
}
#if defined(_SUNOS_VTOC_8)
for (i = 0; i < V_NUMPAR; i++) {
return (EINVAL);
}
ncyl++;
}
return (EINVAL);
}
vpart++;
}
#endif /* defined(_SUNOS_VTOC_8) */
/* Put appropriate vtoc structure fields into the disk label */
#if defined(_SUNOS_VTOC_16)
/*
* The vtoc is always a 32bit data structure to maintain the
* on-disk format. Convert "in place" instead of bcopying it.
*/
/*
* in the 16-slice vtoc, starting sectors are expressed in
* numbers *relative* to the start of the Solaris fdisk partition.
*/
}
#elif defined(_SUNOS_VTOC_8)
/*
* Note the conversion from starting sector number
* to starting cylinder number.
* Return error if division results in a remainder.
*/
lmap++;
lpart++;
vpart++;
/* (4387723) */
#ifdef _LP64
} else {
}
#else
#endif
}
#else
#error "No VTOC format defined."
#endif
return (0);
}
/*
* Function: sd_clear_efi
*
* Description: This routine clears all EFI labels.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: void
*/
static void
{
int rval;
goto done;
}
if (rval == 0) {
/* clear primary */
SD_PATH_DIRECT))) {
"sd_clear_efi: clear primary label failed\n");
}
}
/* the backup */
if (rval) {
goto done;
}
/*
* The MMC standard allows READ CAPACITY to be
* inaccurate by a bounded amount (in the interest of
* response latency). As a result, failed READs are
* commonplace (due to the reading of metadata and not
* data). Depending on the per-Vendor/drive Sense data,
* the failed READ can cause many (unnecessary) retries.
*/
SD_PATH_DIRECT)) != 0) {
goto done;
}
if (rval == 0) {
/* clear backup */
cap-1);
"sd_clear_efi: clear backup label failed\n");
}
} else {
/*
* Refer to comments related to off-by-1 at the
* header of this file
*/
SD_PATH_DIRECT)) != 0) {
goto done;
}
if (rval == 0) {
/* clear legacy backup EFI label */
un, "sd_clear_efi: "
" clear legacy backup label failed\n");
}
}
}
done:
}
/*
* Function: sd_set_vtoc
*
* Description: This routine writes data to the appropriate positions
*
* Arguments: un - driver soft state (unit) structure
* dkl - the data to be written
*
* Return: void
*/
static int
{
void *shadow_buf;
int sec;
int blk;
int head;
int cyl;
int rval;
#else
/* Write the primary label at block 0 of the solaris partition. */
label_addr = 0;
#endif
if (NOT_DEVBSIZE(un)) {
/*
* Read the target's first block.
*/
SD_PATH_STANDARD)) != 0) {
goto exit;
}
/*
* Copy the contents of the label into the shadow buffer
* which is of the size of target block size.
*/
}
/* Write the primary label */
if (NOT_DEVBSIZE(un)) {
} else {
}
if (rval != 0) {
return (rval);
}
/*
* Calculate where the backup labels go. They are always on
* the last alternate cylinder, but some older drives put them
* on head 2 instead of the last head. They are always on the
* first 5 odd sectors of the appropriate track.
*
* We have no choice at this point, but to believe that the
* disk label is valid. Use the geometry of the disk
* as described in the label.
*/
/*
* Write and verify the backup labels. Make sure we don't try to
* write past the last cylinder.
*/
#endif
if (NOT_DEVBSIZE(un)) {
/*
* Need to read the block first for read modify write.
*/
SD_PATH_STANDARD)) != 0) {
goto exit;
}
/*
* Modify the shadow buffer with the label.
*/
} else {
"sd_set_vtoc: wrote backup label %d\n", blk);
}
if (rval != 0) {
goto exit;
}
}
exit:
if (NOT_DEVBSIZE(un)) {
}
return (rval);
}
/*
* Function: sd_clear_vtoc
*
* Description: This routine clears out the VTOC labels.
*
* Arguments: un - driver soft state (unit) structure
*
* Return: void
*/
static void
{
/*
* sd_set_vtoc uses these fields in order to figure out
* where to overwrite the backup labels
*/
}
/*
* Function: sd_write_label
*
* Description: This routine will validate and write the driver soft state vtoc
* contents to the device.
*
* Arguments: dev - the device number
*
* Return Code: the code returned by sd_send_scsi_cmd()
* 0
* EINVAL
* ENXIO
* ENOMEM
*/
static int
{
short sum;
short *sp;
int i;
int rval;
return (ENXIO);
}
#if defined(_SUNOS_VTOC_8)
for (i = 0; i < NDKMAP; i++) {
}
#elif defined(_SUNOS_VTOC_16)
#else
#error "No VTOC format defined."
#endif
/* Construct checksum for the new disk label */
sum = 0;
i = sizeof (struct dk_label) / sizeof (short);
while (i--) {
}
exit:
return (rval);
}
static int
{
int rval = 0;
void *buffer;
return (ENXIO);
return (EFAULT);
return (EINVAL);
} else {
/*
* let's clear the vtoc labels and clear the softstate
* vtoc.
*/
"sd_dkio_set_efi: CLEAR VTOC\n");
} else
if (rval == 0) {
}
}
return (rval);
}
/*
* Function: sd_dkio_get_mboot
*
* Description: This routine is the driver entry point for handling user
* requests to get the current device mboot (DKIOCGMBOOT)
*
* Arguments: dev - the device number
* arg - pointer to user provided mboot structure specifying
* the current mboot.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EINVAL
* EFAULT
* ENXIO
*/
static int
{
int rval;
return (ENXIO);
}
return (EINVAL);
}
/*
* Read the mboot block, located at absolute block 0 on the target.
*/
"sd_dkio_get_mboot: allocation size: 0x%x\n", buffer_size);
SD_PATH_STANDARD)) == 0) {
}
}
return (rval);
}
/*
* Function: sd_dkio_set_mboot
*
* Description: This routine is the driver entry point for handling user
* requests to validate and set the device master boot
* (DKIOCSMBOOT).
*
* Arguments: dev - the device number
* arg - pointer to user provided mboot structure used to set the
* master boot.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EINVAL
* EFAULT
* ENXIO
*/
static int
{
int rval;
return (ENXIO);
}
if (!un->un_f_mboot_supported) {
return (EINVAL);
}
return (EINVAL);
}
return (EFAULT);
}
/* Is this really a master boot record? */
return (EINVAL);
}
if (rval == 0) {
/*
* mboot has been written successfully.
* update the fdisk and vtoc tables in memory
*/
return (rval);
}
}
/*
* If the mboot write fails, write the devid anyway, what can it hurt?
* Also preserve the device id by writing to the disk acyl for the case
* where a devid has been fabricated.
*/
} else {
/*
* The device id for this disk has been
* fabricated. Fabricated device id's are
* managed by storing them in the last 2
* available sectors on the drive. The device
* id must be preserved by writing it back out
* to this location.
*/
if (sd_write_deviceid(un) != 0) {
}
}
}
#ifdef __lock_lint
#endif
#else
if (rval == 0) {
/*
* mboot has been written successfully.
* set up the default geometry and VTOC
*/
}
#endif
return (rval);
}
/*
* Function: sd_setup_default_geometry
*
* Description: This local utility routine sets the default geometry as part of
* setting the device mboot.
*
* Arguments: un - driver soft state (unit) structure
*
* Note: This may be redundant with sd_build_default_label.
*/
static void
{
/* zero out the soft state geometry and partition table. */
/*
* For the rpm, we use the minimum for the disk.
* For the head, cyl and number of sector per track,
* if the capacity <= 1GB, head = 64, sect = 32.
* else head = 255, sect 63
* Note: the capacity should be equal to C*H*S values.
* This will cause some truncation of size due to
* round off errors. For CD-ROMs, this truncation can
* have adverse side effects, so returning ncyl and
* nhead as 1. The nsect will overflow for most of
* CD-ROMs as nsect is of type ushort.
*/
} else {
/* Needed for unlabeled SCSI floppies. */
} else {
}
}
}
}
/*
* Function: sd_update_fdisk_and_vtoc
*
* Description: This local utility routine updates the device fdisk and vtoc
* as part of setting the device mboot.
*
* Arguments: un - driver soft state (unit) structure
*
* Return Code: 0 for success or errno-type return code.
*
* Note:x86: This looks like a duplicate of sd_validate_geometry(), but
* these did exist seperately in x86 sd.c!!!
*/
static int
{
static char labelstring[128];
static char buf[256];
char *label = 0;
int count;
int label_rc = 0;
int fdisk_rval;
int lbasize;
int capacity;
return (EINVAL);
}
return (EINVAL);
}
#if defined(_SUNOS_VTOC_16)
/*
* Set up the "whole disk" fdisk partition; this should always
* exist, regardless of whether the disk contains an fdisk table
* or vtoc.
*/
#endif /* defined(_SUNOS_VTOC_16) */
/*
* copy the lbasize and capacity so that if they're
* reset while we're not holding the SD_MUTEX(un), we will
* continue to use valid values after the SD_MUTEX(un) is
* reacquired.
*/
/*
* refresh the logical and physical geometry caches.
* and scsi_ifgetcap("geometry").
*/
/*
* Only DIRECT ACCESS devices will have Sun labels.
* CD's supposedly have a Sun label, too
*/
if (un->un_f_vtoc_label_supported) {
if (fdisk_rval == SD_CMD_FAILURE) {
return (EIO);
}
if (fdisk_rval == SD_CMD_RESERVATION_CONFLICT) {
return (EACCES);
}
/*
* Found fdisk table but no Solaris partition entry,
* so don't call sd_uselabel() and don't create
* a default label.
*/
label_rc = 0;
goto no_solaris_partition;
}
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#error "No VTOC format defined."
#endif
} else if (capacity < 0) {
return (EINVAL);
}
/*
* For Removable media We reach here if we have found a
* SOLARIS PARTITION.
* If un_f_geometry_is_valid is FALSE it indicates that the SOLARIS
* PARTITION has changed from the previous one, hence we will setup a
* default VTOC in this case.
*/
label_rc = 0;
}
if ((!un->un_f_has_removable_media ||
/*
* Print out a message indicating who and what we are.
* We do this only when we happen to really validate the
* geometry. We may call sd_validate_geometry() at other
* times, ioctl()'s like Get VTOC in which case we
* don't want to print the label.
* If the geometry is valid, print the label string,
* else print vendor and product info, if available
*/
} else {
&labelstring[64]);
} else {
", (unknown capacity)\n");
}
}
}
#if defined(_SUNOS_VTOC_16)
/*
* If we have valid geometry, set up the remaining fdisk partitions.
* Note that dkl_cylno is not used for the fdisk map entries, so
* we set it to an entirely bogus value.
*/
}
#endif
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#error "No VTOC format defined."
#endif
}
return (label_rc);
}
#endif
/*
* Function: sd_check_media
*
* Description: This utility routine implements the functionality for the
* DKIOCSTATE ioctl. This ioctl blocks the user thread until the
* driver state changes from that specified by the user
* (inserted or ejected). For example, if the user specifies
* DKIO_EJECTED and the current media state is inserted this
* routine will immediately return DKIO_INSERTED. However, if the
* current media state is not inserted the user thread will be
* blocked until the drive state changes. If DKIO_NONE is specified
* the user thread will block until a drive state change occurs.
*
* Arguments: dev - the device number
* state - user pointer to a dkio_state, updated with the current
* drive state at return.
*
* Return Code: ENXIO
* EIO
* EAGAIN
* EINTR
*/
static int
{
enum dkio_state prev_state;
int rval = 0;
return (ENXIO);
}
/* is there anything to do? */
/*
* submit the request to the scsi_watch service;
* scsi_media_watch_cb() does the real work
*/
/*
* This change handles the case where a scsi watch request is
* added to a device that is powered down. To accomplish this
* we power up the device before adding the scsi watch request,
* since the scsi watch sends a TUR directly to the device
* which the device cannot handle if it is powered down.
*/
goto done;
}
sd_pm_exit(un);
goto done;
}
/*
* This is a special case IOCTL that doesn't return
* until the media state changes. Routine sdpower
* knows about and handles this so don't count it
* as an active cmd in the driver, which would
* keep the device busy to the pm framework.
* If the count isn't decremented the device can't
* be powered down.
*/
un->un_ncmds_in_driver--;
/*
* if a prior request had been made, this will be the same
* token, as scsi_watch was designed that way.
*/
/*
* now wait for media change
* we will not be signalled unless mediastate == state but it is
* still better to test for this condition, since there is a
* 2 sec cv_broadcast delay when mediastate == DKIO_INSERTED
*/
"sd_check_media: waiting for media state change\n");
"sd_check_media: waiting for media state "
"was interrupted\n");
un->un_ncmds_in_driver++;
goto done;
}
"sd_check_media: received signal, state=%x\n",
un->un_mediastate);
}
/*
* Inc the counter to indicate the device once again
* has an active outstanding cmd.
*/
un->un_ncmds_in_driver++;
}
/* invalidate geometry */
sr_ejected(un);
}
/*
* Since the following routines use SD_PATH_DIRECT, we must
* call PM directly before the upcoming disk accesses. This
*/
&capacity,
if (rval != 0) {
sd_pm_exit(un);
goto done;
}
} else {
goto done;
}
sd_pm_exit(un);
}
done:
if (un->un_swr_token) {
/*
* Use of this local token and the mutex ensures that we avoid
* some race conditions associated with terminating the
* scsi watch.
*/
(void) scsi_watch_request_terminate(token,
}
/*
* Update the capacity kstat value, if no media previously
* (capacity kstat is 0) and a media has been inserted
* (un_f_blockcount_is_valid == TRUE)
*/
if (un->un_errstats) {
}
}
return (rval);
}
/*
* Function: sd_delayed_cv_broadcast
*
* Description: Delayed cv_broadcast to allow for target to recover from media
* insertion.
*
* Arguments: arg - driver soft state (unit) structure
*/
static void
sd_delayed_cv_broadcast(void *arg)
{
}
/*
* Function: sd_media_watch_cb
*
* Description: Callback routine used for support of the DKIOCSTATE ioctl. This
* routine processes the TUR sense data and updates the driver
* state if a transition has occurred. The user thread
* (sd_check_media) is then signalled.
*
* Arguments: arg - the device 'dev_t' is used for context to discriminate
* among multiple watches that share this callback function
* resultp - scsi watch facility result packet containing scsi
* packet, status byte and sense data
*
* Return Code: 0 for success, -1 for failure
*/
static int
{
return (-1);
}
"sd_media_watch_cb: status=%x, sensep=%p, len=%x\n",
return (0);
}
/*
* If there was a check condition then sensep points to valid sense data
* If status was not a check condition but a reservation or busy status
* then the new state is DKIO_NONE
*/
"sd_media_watch_cb: sense KEY=%x, ASC=%x, ASCQ=%x\n",
/* This routine only uses up to 13 bytes of sense data. */
if (actual_sense_length >= 13) {
if (skey == KEY_UNIT_ATTENTION) {
if (asc == 0x28) {
}
} else {
/*
* if 02/04/02 means that the host
* should send start command. Explicitly
* leave the media state as is
* (inserted) as the media is inserted
* and host has stopped device for PM
* to this media will bring the
* device to the right state good for
* media access.
*/
if ((skey == KEY_NOT_READY) &&
(asc == 0x3a)) {
}
/*
* If the drivge is busy with an operation
* or long write, keep the media in an
* inserted state.
*/
if ((skey == KEY_NOT_READY) &&
(asc == 0x04) &&
((ascq == 0x02) ||
(ascq == 0x07) ||
(ascq == 0x08))) {
}
}
}
} else if ((*((char *)statusp) == STATUS_GOOD) &&
}
"sd_media_watch_cb: state=%x, specified=%x\n",
/*
* now signal the waiting thread if this is *not* the specified state;
* delay the signal if the state is DKIO_INSERTED to allow the target
* to recover
*/
if (state == DKIO_INSERTED) {
/*
* delay the signal to give the drive a chance
* to do what it apparently needs to do
*/
"sd_media_watch_cb: delayed cv_broadcast\n");
un->un_dcvb_timeid =
}
} else {
"sd_media_watch_cb: immediate cv_broadcast\n");
}
}
return (0);
}
/*
* Function: sd_dkio_get_temp
*
* Description: This routine is the driver entry point for handling ioctl
* requests to get the disk temperature.
*
* Arguments: dev - the device number
* arg - pointer to user provided dk_temperature structure.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
* EAGAIN
*/
static int
{
int rval = 0;
int path_flag = SD_PATH_STANDARD;
return (ENXIO);
}
/* copyin the disk temp argument to get the user flags */
sizeof (struct dk_temperature), flag) != 0) {
goto done;
}
/* Initialize the temperature to invalid. */
/*
* Note: Investigate removing the "bypass pm" semantic.
* Can we just bypass PM always?
*/
if (SD_DEVICE_IS_IN_LOW_POWER(un)) {
/*
* If DKT_BYPASS_PM is set, and the drive happens to be
* in low power mode, we can not wake it up, Need to
* return EAGAIN.
*/
goto done;
} else {
/*
* Indicate to PM the device is busy. This is required
* to avoid a race - i.e. the ioctl is issuing a
* command and the pm framework brings down the device
* to low power mode (possible power cut-off on some
* platforms).
*/
goto done;
}
}
}
goto done2;
}
/*
* For the current temperature verify that the parameter length is 0x02
* and the parameter code is 0x00
*/
} else {
}
}
/*
* For the reference temperature verify that the parameter
* length is 0x02 and the parameter code is 0x01
*/
} else {
}
}
/* Do the copyout regardless of the temperature commands status. */
flag) != 0) {
}
if (path_flag == SD_PATH_DIRECT) {
sd_pm_exit(un);
}
done:
}
return (rval);
}
/*
* Function: sd_log_page_supported
*
* Description: This routine uses sd_send_scsi_LOG_SENSE to find the list of
* supported log pages.
*
* Arguments: un -
* log_page -
*
* Return Code: -1 - on error (log sense is optional and may not be supported).
* 0 - log page not found.
* 1 - log page found.
*/
static int
{
int i;
int match = 0;
int log_size;
SD_PATH_DIRECT) != 0) {
"sd_log_page_supported: failed log page retrieval\n");
return (-1);
}
/*
* The list of supported log pages start from the fourth byte. Check
* until we run out of log pages or a match is found.
*/
if (log_page_data[i] == log_page) {
match++;
}
}
return (match);
}
/*
* Function: sd_mhdioc_failfast
*
* Description: This routine is the driver entry point for handling ioctl
* (MHIOCENFAILFAST)
*
* Arguments: dev - the device number
* arg - user specified probing interval.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
*/
static int
{
int mh_time;
int rval = 0;
return (ENXIO);
}
return (EFAULT);
if (mh_time) {
/*
* If mh_time is INT_MAX, then this ioctl is being used for
* SCSI-3 PGR purposes, and we don't need to spawn watch thread.
*/
}
} else {
(void) sd_check_mhd(dev, 0);
}
return (rval);
}
/*
* Function: sd_mhdioc_takeown
*
* Description: This routine is the driver entry point for handling ioctl
* requests to forcefully acquire exclusive access rights to the
* multihost disk (MHIOCTKOWN).
*
* Arguments: dev - the device number
* arg - user provided structure specifying the delay
* parameters in milliseconds
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0
* EFAULT
* ENXIO
*/
static int
{
int rval = 0;
return (ENXIO);
}
tkown = (struct mhioctkown *)
if (rval != 0) {
goto error;
}
}
if (rval == 0) {
} else {
}
/*
* Give the scsi_watch routine interval set by
* the MHIOCENFAILFAST ioctl precedence here.
*/
"sd_mhdioc_takeown : %d\n",
} else {
}
} else {
}
}
return (rval);
}
/*
* Function: sd_mhdioc_release
*
* Description: This routine is the driver entry point for handling ioctl
* requests to release exclusive access rights to the multihost
* disk (MHIOCRELEASE).
*
* Arguments: dev - the device number
*
* Return Code: 0
* ENXIO
*/
static int
{
int resvd_status_save;
int rval = 0;
return (ENXIO);
}
un->un_resvd_status &=
if (un->un_resvd_timeid) {
(void) untimeout(resvd_timeid_save);
} else {
}
/*
* destroy any pending timeout thread that may be attempting to
* reinstate reservation on this device.
*/
if ((un->un_mhd_token) &&
(void) sd_check_mhd(dev, 0);
} else {
}
} else {
/*
* sd_mhd_watch_cb will restart the resvd recover timeout thread
*/
}
return (rval);
}
/*
* Function: sd_mhdioc_register_devid
*
* Description: This routine is the driver entry point for handling ioctl
* requests to register the device id (MHIOCREREGISTERDEVID).
*
* Note: The implementation for this ioctl has been updated to
* be consistent with the original PSARC case (1999/357)
* (4375899, 4241671, 4220005)
*
* Arguments: dev - the device number
*
* Return Code: 0
* ENXIO
*/
static int
{
int rval = 0;
return (ENXIO);
}
/* If a devid already exists, de-register it */
/*
* After unregister devid, needs to free devid memory
*/
}
/* Check for reservation conflict */
switch (rval) {
case 0:
break;
case EACCES:
break;
default:
}
return (rval);
}
/*
* Function: sd_mhdioc_inkeys
*
* Description: This routine is the driver entry point for handling ioctl
* requests to issue the SCSI-3 Persistent In Read Keys command
* to the device (MHIOCGRP_INKEYS).
*
* Arguments: dev - the device number
* arg - user provided in_keys structure
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: code returned by sd_persistent_reservation_in_read_keys()
* ENXIO
* EFAULT
*/
static int
{
int rval = 0;
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
struct mhioc_inkeys32 inkeys32;
sizeof (struct mhioc_inkeys32), flag) != 0) {
return (EFAULT);
}
return (rval);
}
flag) != 0) {
return (EFAULT);
}
break;
}
case DDI_MODEL_NONE:
flag) != 0) {
return (EFAULT);
}
return (rval);
}
flag) != 0) {
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
if (rval != 0) {
return (rval);
}
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
return (rval);
}
/*
* Function: sd_mhdioc_inresv
*
* Description: This routine is the driver entry point for handling ioctl
* requests to issue the SCSI-3 Persistent In Read Reservations
* command to the device (MHIOCGRP_INKEYS).
*
* Arguments: dev - the device number
* arg - user provided in_resv structure
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: code returned by sd_persistent_reservation_in_read_resv()
* ENXIO
* EFAULT
*/
static int
{
int rval = 0;
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32: {
struct mhioc_inresvs32 inresvs32;
sizeof (struct mhioc_inresvs32), flag) != 0) {
return (EFAULT);
}
return (rval);
}
sizeof (struct mhioc_inresvs32), flag) != 0) {
return (EFAULT);
}
break;
}
case DDI_MODEL_NONE:
sizeof (mhioc_inresvs_t), flag) != 0) {
return (EFAULT);
}
return (rval);
}
sizeof (mhioc_inresvs_t), flag) != 0) {
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
if (rval != 0) {
return (rval);
}
return (EFAULT);
}
#endif /* ! _MULTI_DATAMODEL */
return (rval);
}
/*
* The following routines support the clustering functionality described below
* and implement lost reservation reclaim functionality.
*
* Clustering
* ----------
* The clustering code uses two different, independent forms of SCSI
* Persistent Group Reservations. For any particular disk, it will use either
* SCSI-2 or SCSI-3 PGR but never both at the same time for the same disk.
*
* SCSI-2
* The cluster software takes ownership of a multi-hosted disk by issuing the
* MHIOCTKOWN ioctl to the disk driver. It releases ownership by issuing the
* MHIOCRELEASE ioctl.Closely related is the MHIOCENFAILFAST ioctl -- a cluster,
* just after taking ownership of the disk with the MHIOCTKOWN ioctl then issues
* the MHIOCENFAILFAST ioctl. This ioctl "enables failfast" in the driver. The
* meaning of failfast is that if the driver (on this host) ever encounters the
* scsi error return code RESERVATION_CONFLICT from the device, it should
* immediately panic the host. The motivation for this ioctl is that if this
* host does encounter reservation conflict, the underlying cause is that some
* other host of the cluster has decided that this host is no longer in the
* cluster and has seized control of the disks for itself. Since this host is no
* longer in the cluster, it ought to panic itself. The MHIOCENFAILFAST ioctl
* does two things:
* (a) it sets a flag that will cause any returned RESERVATION_CONFLICT
* error to panic the host
* (b) it sets up a periodic timer to test whether this host still has
* "access" (in that no other host has reserved the device): if the
* periodic timer gets RESERVATION_CONFLICT, the host is panicked. The
* purpose of that periodic timer is to handle scenarios where the host is
* otherwise temporarily quiescent, temporarily doing no real i/o.
* The MHIOCTKOWN ioctl will "break" a reservation that is held by another host,
* by issuing a SCSI Bus Device Reset. It will then issue a SCSI Reserve for
* the device itself.
*
* SCSI-3 PGR
* A direct semantic implementation of the SCSI-3 Persistent Reservation
* facility is supported through the shared multihost disk ioctls
* (MHIOCGRP_INKEYS, MHIOCGRP_INRESV, MHIOCGRP_REGISTER, MHIOCGRP_RESERVE,
* MHIOCGRP_PREEMPTANDABORT)
*
* Reservation Reclaim:
* --------------------
* To support the lost reservation reclaim operations this driver creates a
* single thread to handle reinstating reservations on all devices that have
* lost reservations sd_resv_reclaim_requests are logged for all devices that
* have LOST RESERVATIONS when the scsi watch facility callsback sd_mhd_watch_cb
* and the reservation reclaim thread loops through the requests to regain the
* lost reservations.
*/
/*
* Function: sd_check_mhd()
*
* Description: This function sets up and submits a scsi watch request or
* terminates an existing watch request. This routine is used in
* support of reservation reclaim.
*
* Arguments: dev - the device 'dev_t' is used for context to discriminate
* among multiple watches that share the callback function
* interval - the number of microseconds specifying the watch
* interval for issuing TEST UNIT READY commands. If
* set to 0 the watch should be terminated. If the
* interval is set to 0 and if the device is required
* to hold reservation while disabling failfast, the
* watch is restarted with an interval of
* reinstate_resv_delay.
*
* ENXIO - Indicates an invalid device was specified
* EAGAIN - Unable to submit the scsi watch request
*/
static int
{
return (ENXIO);
}
/* is this a watch termination request? */
if (interval == 0) {
/* if there is an existing watch task then terminate it */
if (un->un_mhd_token) {
(void) scsi_watch_request_terminate(token,
} else {
/*
* Note: If we return here we don't check for the
* failfast case. This is the original legacy
* implementation but perhaps we should be checking
* the failfast case.
*/
return (0);
}
/*
* If the device is required to hold reservation while
* disabling failfast, we need to restart the scsi_watch
* routine with an interval of reinstate_resv_delay.
*/
} else {
/* no failfast so bail */
return (0);
}
}
/*
* adjust minimum time interval to 1 second,
* and convert from msecs to usecs
*/
interval = 1000;
}
interval *= 1000;
/*
* submit the request to the scsi_watch service
*/
return (EAGAIN);
}
/*
* save token for termination later on
*/
return (0);
}
/*
* Function: sd_mhd_watch_cb()
*
* Description: This function is the call back function used by the scsi watch
* facility. The scsi watch facility sends the "Test Unit Ready"
* and processes the status. If applicable (i.e. a "Unit Attention"
* status and automatic "Request Sense" not used) the scsi watch
* facility will send a "Request Sense" and retrieve the sense data
* to be passed to this callback function. In either case the
* automatic "Request Sense" or the facility submitting one, this
* callback is passed the status and sense data.
*
* Arguments: arg - the device 'dev_t' is used for context to discriminate
* among multiple watches that share this callback function
* resultp - scsi watch facility result packet containing scsi
* packet, status byte and sense data
*
* Return Code: 0 - continue the watch task
* non-zero - terminate the watch task
*/
static int
{
struct scsi_status *statusp;
return (ENXIO);
}
"sd_mhd_watch_cb: reason '%s', status '%s'\n",
/* Handle the incomplete packet */
return (0);
} else if (*((unsigned char *)statusp) != STATUS_GOOD) {
if (*((unsigned char *)statusp)
/*
* Handle a reservation conflict by panicking if
* configured for failfast or by logging the conflict
* and updating the reservation status
*/
(sd_failfast_enable)) {
/*NOTREACHED*/
}
"sd_mhd_watch_cb: Reservation Conflict\n");
}
}
if ((scsi_sense_asc(sensep) ==
/*
* The additional sense code indicates a power
* on or bus device reset has occurred; update
* the reservation status.
*/
un->un_resvd_status |=
"sd_mhd_watch_cb: Lost Reservation\n");
}
} else {
return (0);
}
} else {
}
/*
* A reset occurred in between the last probe and this
* one so if a timeout is pending cancel it.
*/
if (un->un_resvd_timeid) {
}
}
if (un->un_resvd_timeid == 0) {
/* Schedule a timeout to handle the lost reservation */
(void *)dev,
}
}
return (0);
}
/*
* Function: sd_mhd_watch_incomplete()
*
* Description: This function is used to find out why a scsi pkt sent by the
* scsi watch facility was not completed. Under some scenarios this
* routine will return. Otherwise it will send a bus reset to see
* if the drive is still online.
*
* Arguments: un - driver soft state (unit) structure
* pkt - incomplete scsi pkt
*/
static void
{
int be_chatty;
int perr;
return;
}
switch (pkt->pkt_reason) {
case CMD_UNX_BUS_FREE:
/*
* If we had a parity error that caused the target to drop BSY*,
* don't be chatty about it.
*/
be_chatty = 0;
}
break;
case CMD_TAG_REJECT:
/*
* The SCSI-2 spec states that a tag reject will be sent by the
* target if tagged queuing is not supported. A tag reject may
* also be sent during certain initialization periods or to
* control internal resources. For the latter case the target
* may also return Queue Full.
*
* If this driver receives a tag reject from a target that is
* going through an init period or controlling internal
* resources tagged queuing will be disabled. This is a less
* than optimal behavior but the driver is unable to determine
* the target state and assumes tagged queueing is not supported
*/
un->un_tagflags = 0;
} else {
}
break;
case CMD_INCOMPLETE:
/*
* The transport stopped with an abnormal state, fallthrough and
* (indicated by STATE_GOT_BUS) in which case we don't want to
*/
break;
}
/*FALLTHROUGH*/
case CMD_TIMEOUT:
default:
/*
* The lun may still be running the command, so a lun reset
* should be attempted. If the lun reset fails or cannot be
* issued, than try a target reset. Lastly try a bus reset.
*/
if ((pkt->pkt_statistics &
int reset_retval = 0;
}
if (reset_retval == 0) {
}
}
if (reset_retval == 0) {
}
}
break;
}
(STAT_BUS_RESET | STAT_DEV_RESET))) {
un->un_resvd_status |=
"sd_mhd_watch_incomplete: Lost Reservation\n");
}
}
/*
* The disk has been turned off; Update the device state.
*
* Note: Should we be offlining the disk here?
*/
"Disk not responding to selection\n");
}
} else if (be_chatty) {
/*
* suppress messages if they are all the same pkt reason;
* with TQ, many (up to 256) are returned with the same
* pkt_reason
*/
"sd_mhd_watch_incomplete: "
"SCSI transport failed: reason '%s'\n",
}
}
}
/*
* Function: sd_sname()
*
* Description: This is a simple little routine to return a string containing
* a printable description of command status byte for use in
* logging.
*
* Arguments: status - pointer to a status byte
*
* Return Code: char * - string containing status description.
*/
static char *
{
switch (status & STATUS_MASK) {
case STATUS_GOOD:
return ("good status");
case STATUS_CHECK:
return ("check condition");
case STATUS_MET:
return ("condition met");
case STATUS_BUSY:
return ("busy");
case STATUS_INTERMEDIATE:
return ("intermediate");
case STATUS_INTERMEDIATE_MET:
return ("intermediate - condition met");
return ("reservation_conflict");
case STATUS_TERMINATED:
return ("command terminated");
case STATUS_QFULL:
return ("queue full");
default:
return ("<unknown status>");
}
}
/*
* Function: sd_mhd_resvd_recover()
*
* Description: This function adds a reservation entry to the
* sd_resv_reclaim_request list and signals the reservation
* reclaim thread that there is work pending. If the reservation
* reclaim thread has not been previously created this function
* will kick it off.
*
* Arguments: arg - the device 'dev_t' is used for context to discriminate
* among multiple watches that share this callback function
*
* Context: This routine is called by timeout() and is run in interrupt
* context. It must not sleep or call other functions which may
* sleep.
*/
static void
sd_mhd_resvd_recover(void *arg)
{
int already_there = 0;
return;
}
/*
* There was a reset so don't issue the reserve, allow the
* sd_mhd_watch_cb callback function to notice this and
* reschedule the timeout for reservation.
*/
return;
}
/*
* Add this device to the sd_resv_reclaim_request list and the
* sd_resv_reclaim_thread should take care of the rest.
*
* Note: We can't sleep in this context so if the memory allocation
* fails allow the sd_mhd_watch_cb callback function to notice this and
* reschedule the timeout for reservation. (4378460)
*/
sd_treq = (struct sd_thr_request *)
return;
}
} else {
/*
* already in Queue so don't log
* another request for the device
*/
already_there = 1;
break;
}
}
if (!already_there) {
"logging request for %lx\n", dev);
} else {
}
}
/*
* Create a kernel thread to do the reservation reclaim and free up this
* thread. We cannot block this thread while we go away to do the
* reservation reclaim
*/
/* Tell the reservation reclaim thread that it has work to do */
}
/*
* Function: sd_resv_reclaim_thread()
*
* Description: This function implements the reservation reclaim operations
*
* Arguments: arg - the device 'dev_t' is used for context to discriminate
* among multiple watches that share this callback function
*/
static void
{
struct sd_thr_request *sd_mhreq;
/* Wait for work */
}
/* Loop while we have work */
/*
* softstate structure is NULL so just
* dequeue the request and continue
*/
sizeof (struct sd_thr_request));
continue;
}
/* dequeue the request */
/*
* Reclaim reservation only if SD_RESERVE is still set. There
* may have been a call to MHIOCRELEASE before we got here.
*/
/*
* Note: The SD_LOST_RESERVE flag is cleared before
* reclaiming the reservation. If this is done after the
* call to sd_reserve_release a reservation loss in the
* window between pkt completion of reserve cmd and
* mutex_enter below may not be recognized
*/
SD_RESERVE) == 0) {
"sd_resv_reclaim_thread: "
"Reservation Recovered\n");
} else {
"sd_resv_reclaim_thread: Failed "
"Reservation Recovery\n");
}
} else {
}
/*
* wakeup the destroy thread if anyone is waiting on
* us to complete.
*/
"sd_resv_reclaim_thread: cv_signalling current request \n");
}
/*
* cleanup the sd_tr structure now that this thread will not exist
*/
thread_exit();
}
/*
* Function: sd_rmv_resv_reclaim_req()
*
* Description: This function removes any pending reservation reclaim requests
* for the specified device.
*
* Arguments: dev - the device 'dev_t'
*/
static void
{
struct sd_thr_request *sd_mhreq;
struct sd_thr_request *sd_prev;
/* Remove a reservation reclaim request from the list */
/*
* We are attempting to reinstate reservation for
* this device. We wait for sd_reserve_release()
* to return before we return.
*/
} else {
return;
}
break;
}
}
}
}
}
/*
* Function: sd_mhd_reset_notify_cb()
*
* Description: This is a call back function for scsi_reset_notify. This
* function updates the softstate reserved status and logs the
* reset. The driver scsi watch facility callback function
* (sd_mhd_watch_cb) and reservation reclaim thread functionality
* will reclaim the reservation.
*
* Arguments: arg - driver soft state (unit) structure
*/
static void
{
"sd_mhd_reset_notify_cb: Lost Reservation\n");
}
}
/*
* Function: sd_take_ownership()
*
* Description: This routine implements an algorithm to achieve a stable
* reservation on disks which don't implement priority reserve,
* and makes sure that other host lose re-reservation attempts.
* This algorithm contains of a loop that keeps issuing the RESERVE
* for some period of time (min_ownership_delay, default 6 seconds)
* During that loop, it looks to see if there has been a bus device
* reset or bus reset (both of which cause an existing reservation
* to be lost). If the reservation is lost issue RESERVE until a
* period of min_ownership_delay with no resets has gone by, or
* until max_ownership_delay has expired. This loop ensures that
* the host really did manage to reserve the device, in spite of
* resets. The looping for min_ownership_delay (default six
* seconds) is important to early generation clustering products,
* Solstice HA 1.x and Sun Cluster 2.x. Those products use an
* MHIOCENFAILFAST periodic timer of two seconds. By having
* MHIOCTKOWN issue Reserves in a loop for six seconds, and having
* MHIOCENFAILFAST poll every two seconds, the idea is that by the
* time the MHIOCTKOWN ioctl returns, the other host (if any) will
* have already noticed, via the MHIOCENFAILFAST polling, that it
* no longer "owns" the disk and will have panicked itself. Thus,
* the host issuing the MHIOCTKOWN is assured (with timing
* dependencies) that by the time it actually starts to use the
* disk for real work, the old owner is no longer accessing it.
*
* min_ownership_delay is the minimum amount of time for which the
* disk must be reserved continuously devoid of resets before the
* MHIOCTKOWN ioctl will return success.
*
* max_ownership_delay indicates the amount of time by which the
* take ownership should succeed or timeout with an error.
*
* Arguments: dev - the device 'dev_t'
* *p - struct containing timing info.
*
* Return Code: 0 for success or error code
*/
static int
{
int rval;
int err;
int reservation_count = 0;
return (ENXIO);
}
/*
* Attempt a device reservation. A priority reservation is requested.
*/
!= SD_SUCCESS) {
"sd_take_ownership: return(1)=%d\n", rval);
return (rval);
}
/* Update the softstate reserved status to indicate the reservation */
un->un_resvd_status &=
if (p != NULL) {
if (p->min_ownership_delay != 0) {
}
if (p->max_ownership_delay != 0) {
}
}
"sd_take_ownership: min, max delays: %d, %d\n",
start_time = ddi_get_lbolt();
while (current_time - end_time < 0) {
break;
}
}
ownership_time = ddi_get_lbolt() +
reservation_count = 0;
} else {
}
"sd_take_ownership: ticks for loop iteration=%ld, "
if (current_time - ownership_time >= 0 &&
reservation_count >= 4) {
rval = 0; /* Achieved a stable ownership */
break;
}
if (current_time - end_time >= 0) {
break;
}
}
"sd_take_ownership: return(2)=%d\n", rval);
return (rval);
}
/*
* Function: sd_reserve_release()
*
* Description: This function builds and sends scsi RESERVE, RELEASE, and
* PRIORITY RESERVE commands based on a user specified command type
*
* Arguments: dev - the device 'dev_t'
* cmd - user specified command type; one of SD_PRIORITY_RESERVE,
* SD_RESERVE, SD_RELEASE
*
* Return Code: 0 or Error Code
*/
static int
{
char cdb[CDB_GROUP0];
int rval;
(cmd == SD_PRIORITY_RESERVE));
return (ENXIO);
}
/* instantiate and initialize the command and cdb */
if (cmd == SD_RELEASE) {
cdb[0] = SCMD_RELEASE;
} else {
cdb[0] = SCMD_RESERVE;
}
/* Send the command. */
/*
* "break" a reservation that is held by another host, by issuing a
* reset if priority reserve is desired, and we could not get the
* device.
*/
if ((cmd == SD_PRIORITY_RESERVE) &&
/*
* First try to reset the LUN. If we cannot, then try a target
* reset, followed by a bus reset if the target reset fails.
*/
int reset_retval = 0;
}
if (reset_retval == 0) {
/* The LUN reset either failed or was not issued */
}
if ((reset_retval == 0) &&
return (rval);
}
/*
* Reissue the last reserve command, this time without request
* sense. Assume that it is just a regular reserve command.
*/
}
/* Return an error if still getting a reservation conflict. */
}
return (rval);
}
#define SD_NDUMP_RETRIES 12
/*
* System Crash Dump routine
*/
static int
{
int instance;
int partition;
int i;
int err;
int rval;
#endif
return (ENXIO);
}
/* Validate blocks to dump at against partition size. */
"sddump: dump range larger than partition: "
"blkno = 0x%x, nblk = 0x%x, dkl_nblk = 0x%x\n",
return (EINVAL);
}
if (SD_DEVICE_IS_IN_LOW_POWER(un)) {
struct scsi_pkt *start_pktp;
/*
* use pm framework to power on HBA 1st
*/
/*
* Dump no long uses sdpower to power on a device, it's
* in-line here so it can be done in polled mode.
*/
if (start_pktp == NULL) {
/* We were not given a SCSI packet, fail. */
return (EIO);
}
/*
* Scsi_poll returns 0 (success) if the command completes and
* the status block is STATUS_GOOD.
*/
return (EIO);
}
(void) sd_ddi_pm_resume(un);
} else {
}
un->un_throttle = 0;
/*
* The first time through, reset the specific target device.
* However, when cpr calls sddump we know that sd is in a
* a good state so no bus reset is required.
* Clear sense data via Request Sense cmd.
* In sddump we don't care about allow_bus_device_reset anymore
*/
/*
* Attempt a bus reset for parallel scsi.
*
* Note: A bus reset is required because on some host
* systems (i.e. E420R) a bus device reset is
* insufficient to reset the state of the target.
*
* Note: Don't issue the reset for fibre-channel,
* because this tends to hang the bus (loop) for
* too long while everyone is logging out and in
* and the deadman timer for dumping will fire
* before the dump is complete.
*/
return (EIO);
}
/* Delay to give the device some recovery time. */
drv_usecwait(10000);
"sddump: sd_send_polled_RQS failed\n");
}
}
}
/*
* Convert the partition-relative block number to a
* disk physical block number.
*/
/*
* Check if the device has a non-512 block size.
*/
if (NOT_DEVBSIZE(un)) {
/*
* Calculate the block number and number of block
* in terms of the media block size.
*/
tgt_nblk =
/*
* Invoke the routine which is going to do read part
* of read-modify-write.
* Note that this routine returns a pointer to
* a valid bp in wr_bp.
*/
&wr_bp);
if (err) {
return (err);
}
/*
* Offset is being calculated as -
* (original block # * system block size) -
* (new block # * target block size)
*/
ASSERT((io_start_offset >= 0) &&
/*
* Do the modify portion of read modify write.
*/
} else {
}
/* Convert blkno and nblk to target blocks */
} else {
}
/*
* Obtain a SCSI packet for the write command.
* It should be safe to call the allocator here without
* worrying about being locked for DVMA mapping because
* the address we're passed is already a DVMA mapping
*
* We are also not going to worry about semaphore ownership
* in the dump buffer. Dumping is single threaded at present.
*/
while (dma_resid != 0) {
#endif
for (i = 0; i < SD_NDUMP_RETRIES; i++) {
if (wr_pktp) {
/* Partial DMA transfers after initial transfer */
} else {
/* Initial transfer */
}
#else
#endif
if (rval == 0) {
/* We were given a SCSI packet, continue. */
break;
}
if (i == 0) {
"no resources for dumping; "
"error code: 0x%x, retrying",
} else {
"no resources for dumping; retrying");
}
} else if (i != (SD_NDUMP_RETRIES - 1)) {
"no resources for dumping; error code: "
}
} else {
"no resources for dumping; "
"error code: 0x%x, retries failed, "
} else {
"no resources for dumping; "
"retries failed, giving up.\n");
}
} else {
}
return (EIO);
}
drv_usecwait(10000);
}
/*
* save the resid from PARTIAL_DMA
*/
if (dma_resid != 0)
#endif
/* SunBug 1222170 */
for (i = 0; i < SD_NDUMP_RETRIES; i++) {
/*
* Scsi_poll returns 0 (success) if the command completes and
* the status block is STATUS_GOOD. We should only check
* errors if this condition is not true. Even then we should
* send our own request sense packet only if we have a check
* condition and auto request sense has not been performed by
* the hba.
*/
err = SD_SUCCESS;
break;
}
/*
* Check CMD_DEV_GONE 1st, give up if device is gone.
*/
"Device is gone\n");
break;
}
"sddump: write failed with CHECK, try # %d\n", i);
(void) sd_send_polled_RQS(un);
}
continue;
}
int reset_retval = 0;
"sddump: write failed with BUSY, try # %d\n", i);
}
if (reset_retval == 0) {
}
(void) sd_send_polled_RQS(un);
} else {
"sddump: write failed with 0x%x, try # %d\n",
SD_GET_PKT_STATUS(wr_pktp), i);
}
/*
* let's reset the bus.
*/
if (i == SD_NDUMP_RETRIES/2) {
(void) sd_send_polled_RQS(un);
}
}
} /* dma_resid */
#endif
} else {
}
return (err);
}
/*
* Function: sd_scsi_poll()
*
* Description: This is a wrapper for the scsi_poll call.
*
* Arguments: sd_lun - The unit structure
* scsi_pkt - The scsi packet being sent to the device.
*
* Return Code: 0 - Command completed successfully with good status
* -1 - Command failed. This could indicate a check condition
* or other status value requiring recovery action.
*
*/
static int
{
int status;
status = SD_SUCCESS;
}
/*
* Scsi_poll returns 0 (success) if the command completes and the
* status block is STATUS_GOOD. We should only check errors if this
* condition is not true. Even then we should send our own request
* sense packet only if we have a check condition and auto
* request sense has not been performed by the hba.
* Don't get RQS data if pkt_reason is CMD_DEV_GONE.
*/
if ((status != SD_SUCCESS) &&
(void) sd_send_polled_RQS(un);
return (status);
}
/*
* Function: sd_send_polled_RQS()
*
* Description: This sends the request sense command to a device.
*
* Arguments: sd_lun - The unit structure
*
* Return Code: 0 - Command completed successfully with good status
* -1 - Command failed.
*
*/
static int
{
int ret_val;
if (un->un_sense_isbusy) {
return (ret_val);
}
/*
* If the request sense buffer (and packet) is not in use,
* let's set the un_sense_isbusy and send our packet
*/
rqs_pktp->pkt_reason = 0;
/*
* Can't send this to sd_scsi_poll, we wrap ourselves around the
* axle - it has a call into us!
*/
"sd_send_polled_RQS: RQS failed\n");
}
un->un_sense_isbusy = 0;
return (ret_val);
}
/*
* Defines needed for localized version of the scsi_poll routine.
*/
/*
* Function: sd_ddi_scsi_poll()
*
* Description: Localized version of the scsi_poll routine. The purpose is to
* send a scsi_pkt to a device as a polled command. This version
* is to ensure more robust handling of transport errors.
* Specifically this routine cures not ready, coming ready
* transition for power up and reset of sonoma's. This can take
* up to 45 seconds for power-on and 20 seconds for reset of a
* sonoma lun.
*
* Arguments: scsi_pkt - The scsi_pkt being sent to a device
*
* Return Code: 0 - Command completed successfully with good status
* -1 - Command failed.
*
*/
static int
{
int busy_count;
int timeout;
int rval = SD_FAILURE;
int savef;
long savet;
void (*savec)();
/*
* The following is defined in machdep.c and is used in determining if
* the scsi transport system will do polled I/O instead of interrupt
* I/O when called from xx_dump().
*/
extern int do_polled_io;
/*
* save old flags in pkt, to restore at end
*/
/*
* XXX there is nothing in the SCSA spec that states that we should not
* do a callback for polled cmds; however, removing this will break sd
* and probably other target drivers
*/
/*
* we don't like a polled command without timeout.
* 60 seconds seems long enough.
*/
}
/*
* Send polled cmd.
*
* We do some error recovery for various errors. Tran_busy,
* queue full, and non-dispatched commands are retried every 10 msec.
* as they are typically transient failures. Busy status and Not
* Ready are retried every second as this status takes a while to
* change. Unit attention is retried for pkt_time (60) times
* with no delay.
*/
int rc;
int poll_delay;
/*
* Initialize pkt status variables.
*/
/* Transport failed - give up. */
break;
} else {
/* Transport busy - try again. */
}
} else {
/*
* Transport accepted - check pkt status.
*/
rc == STATUS_CHECK &&
struct scsi_arq_status *arqstat =
} else {
}
(rc == STATUS_GOOD)) {
/* No error - we're done */
rval = SD_SUCCESS;
break;
/* Lost connection - give up */
break;
/* Pkt not dispatched - try again. */
(rc == STATUS_QFULL)) {
/* Queue full - try again. */
(rc == STATUS_BUSY)) {
/* Busy - try again. */
(scsi_sense_key(sensep) ==
/* Unit Attention - try again */
continue;
/* Not ready -> ready - try again. */
} else {
/* BAD status - give up. */
break;
}
}
!do_polled_io) {
} else {
/* we busy wait during cpr_dump or interrupt threads */
}
}
return (rval);
}
/*
* Function: sd_persistent_reservation_in_read_keys
*
* Description: This routine is the driver entry point for handling CD-ROM
* multi-host persistent reservation requests (MHIOCGRP_INKEYS)
* by sending the SCSI-3 PRIN commands to the device.
* Processes the read keys command response by copying the
* reservation key information into the user provided buffer.
* Support for the 32/64 bit _MULTI_DATAMODEL is implemented.
*
* Arguments: un - Pointer to soft state struct for the target.
* usrp - user provided pointer to multihost Persistent In Read
* Keys structure (mhioc_inkeys_t)
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0 - Success
* EACCES
* ENOTSUP
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
#ifdef _MULTI_DATAMODEL
struct mhioc_key_list32 li32;
#endif
int data_len;
int rval;
return (EINVAL);
}
/*
* Get the listsize from user
*/
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
copysz = sizeof (struct mhioc_key_list32);
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyin: mhioc_key_list32_t\n");
goto done;
}
break;
case DDI_MODEL_NONE:
copysz = sizeof (mhioc_key_list_t);
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyin: mhioc_key_list_t\n");
goto done;
}
break;
}
#else /* ! _MULTI_DATAMODEL */
copysz = sizeof (mhioc_key_list_t);
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyin: mhioc_key_list_t\n");
goto done;
}
#endif
goto done;
}
/*
* Return the min(listsize, listlen) keys
*/
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyout: mhioc_key_list32_t\n");
goto done;
}
break;
case DDI_MODEL_NONE:
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyout: mhioc_key_list_t\n");
goto done;
}
break;
}
#else /* ! _MULTI_DATAMODEL */
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyout: mhioc_key_list_t\n");
goto done;
}
#endif /* _MULTI_DATAMODEL */
"sd_persistent_reservation_in_read_keys: "
"failed ddi_copyout: keylist\n");
}
done:
return (rval);
}
/*
* Function: sd_persistent_reservation_in_read_resv
*
* Description: This routine is the driver entry point for handling CD-ROM
* multi-host persistent reservation requests (MHIOCGRP_INRESV)
* by sending the SCSI-3 PRIN commands to the device.
* Process the read persistent reservations command response by
* copying the reservation information into the user provided
* buffer. Support for the 32/64 _MULTI_DATAMODEL is implemented.
*
* Arguments: un - Pointer to soft state struct for the target.
* usrp - user provided pointer to multihost Persistent In Read
* Keys structure (mhioc_inkeys_t)
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: 0 - Success
* EACCES
* ENOTSUP
* errno return code from sd_send_scsi_cmd()
*
* Context: Can sleep. Does not return until command is completed.
*/
static int
{
#ifdef _MULTI_DATAMODEL
struct mhioc_resv_desc_list32 resvlist32;
#endif
int data_len;
int rval;
int i;
return (EINVAL);
}
/*
* Get the listsize from user
*/
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
copysz = sizeof (struct mhioc_resv_desc_list32);
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyin: mhioc_resv_desc_list_t\n");
goto done;
}
break;
case DDI_MODEL_NONE:
copysz = sizeof (mhioc_resv_desc_list_t);
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyin: mhioc_resv_desc_list_t\n");
goto done;
}
break;
}
#else /* ! _MULTI_DATAMODEL */
copysz = sizeof (mhioc_resv_desc_list_t);
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyin: mhioc_resv_desc_list_t\n");
goto done;
}
#endif /* ! _MULTI_DATAMODEL */
goto done;
}
/*
* Return the min(listsize, listlen( keys
*/
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyout: mhioc_resv_desc_list_t\n");
goto done;
}
break;
case DDI_MODEL_NONE:
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyout: mhioc_resv_desc_list_t\n");
goto done;
}
break;
}
#else /* ! _MULTI_DATAMODEL */
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyout: mhioc_resv_desc_list_t\n");
goto done;
}
#endif /* ! _MULTI_DATAMODEL */
copysz = sizeof (mhioc_resv_desc_t);
i++, readresv_ptr++, bufp++) {
"sd_persistent_reservation_in_read_resv: "
"failed ddi_copyout: resvlist\n");
goto done;
}
}
done:
return (rval);
}
/*
* Function: sr_change_blkmode()
*
* Description: This routine is the driver entry point for handling CD-ROM
* block mode ioctl requests. Support for returning and changing
* the current block size in use by the device is implemented. The
* LBA size is changed via a MODE SELECT Block Descriptor.
*
* This routine issues a mode sense with an allocation length of
* 12 bytes for the mode page header and a single block descriptor.
*
* Arguments: dev - the device 'dev_t'
* cmd - the request type; one of CDROMGBLKMODE (get) or
* CDROMSBLKMODE (set)
* data - current block size or requested block size
* flag - this argument is a pass through to ddi_copyxxx() directly
* from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EINVAL if invalid arguments are provided
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EIO if invalid mode sense block descriptor length
*
*/
static int
{
int current_bsize;
return (ENXIO);
}
/*
* The block length is changed via the Mode Select block descriptor, the
* required as part of this routine. Therefore the mode sense allocation
* length is specified to be the length of a mode page header and a
* block descriptor.
*/
"sr_change_blkmode: Mode Sense Failed\n");
return (rval);
}
/* Check the block descriptor len to handle only 1 block descriptor */
if ((sense_mhp->bdesc_length == 0) ||
"sr_change_blkmode: Mode Sense returned invalid block"
" descriptor length\n");
return (EIO);
}
/* Process command */
switch (cmd) {
case CDROMGBLKMODE:
/* Return the block size obtained during the mode sense */
sizeof (int), flag) != 0)
break;
case CDROMSBLKMODE:
/* Validate the requested block size */
switch (data) {
case CDROM_BLK_512:
case CDROM_BLK_1024:
case CDROM_BLK_2048:
case CDROM_BLK_2056:
case CDROM_BLK_2336:
case CDROM_BLK_2340:
case CDROM_BLK_2352:
case CDROM_BLK_2368:
case CDROM_BLK_2448:
case CDROM_BLK_2646:
case CDROM_BLK_2647:
break;
default:
"sr_change_blkmode: "
"Block Size '%ld' Not Supported\n", data);
return (EINVAL);
}
/*
* The current block size matches the requested block size so
* there is no need to send the mode select to change the size
*/
if (current_bsize == data) {
break;
}
/* Build the select data for the requested block size */
/*
* The LBA size is changed via the block descriptor, so the
* descriptor is built according to the user data
*/
/* Send the mode select for the requested block size */
SD_PATH_STANDARD)) != 0) {
"sr_change_blkmode: Mode Select Failed\n");
/*
* The mode select failed for the requested block size,
* so reset the data for the original block size and
* send it to the target. The error is indicated by the
* return value for the failed mode select.
*/
} else {
}
break;
default:
/* should not reach here, but check anyway */
"sr_change_blkmode: Command '%x' Not Supported\n", cmd);
break;
}
if (select) {
}
if (sense) {
}
return (rval);
}
/*
* Note: The following sr_change_speed() and sr_atapi_change_speed() routines
* implement driver support for getting and setting the CD speed. The command
* set used will be based on the device type. If the device has not been
* identified as MMC the Toshiba vendor specific mode page will be used. If
* the device is MMC but does not support the Real Time Streaming feature
* the SET CD SPEED command will be used to set speed and mode page 0x2A will
* be used to read the speed.
*/
/*
* Function: sr_change_speed()
*
* Description: This routine is the driver entry point for handling CD-ROM
* drive speed ioctl requests for devices supporting the Toshiba
* vendor specific drive speed mode page. Support for returning
* and changing the current drive speed in use by the device is
* implemented.
*
* Arguments: dev - the device 'dev_t'
* cmd - the request type; one of CDROMGDRVSPEED (get) or
* CDROMSDRVSPEED (set)
* data - current drive speed or requested drive speed
* flag - this argument is a pass through to ddi_copyxxx() directly
* from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EINVAL if invalid arguments are provided
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EIO if invalid mode sense block descriptor length
*/
static int
{
int current_speed;
int bd_len;
return (ENXIO);
}
/*
* Note: The drive speed is being modified here according to a Toshiba
* vendor specific mode page (0x31).
*/
SD_PATH_STANDARD)) != 0) {
"sr_change_speed: Mode Sense Failed\n");
return (rval);
}
/* Check the block descriptor len to handle only 1 block descriptor */
if (bd_len > MODE_BLK_DESC_LENGTH) {
"sr_change_speed: Mode Sense returned invalid block "
"descriptor length\n");
return (EIO);
}
sense_page = (struct mode_speed *)
/* Process command */
switch (cmd) {
case CDROMGDRVSPEED:
/* Return the drive speed obtained during the mode sense */
if (current_speed == 0x2) {
}
sizeof (int), flag) != 0) {
}
break;
case CDROMSDRVSPEED:
/* Validate the requested drive speed */
case CDROM_TWELVE_SPEED:
data = 0x2;
/*FALLTHROUGH*/
case CDROM_NORMAL_SPEED:
case CDROM_DOUBLE_SPEED:
case CDROM_QUAD_SPEED:
case CDROM_MAXIMUM_SPEED:
break;
default:
"sr_change_speed: "
return (EINVAL);
}
/*
* The current drive speed matches the requested drive speed so
* there is no need to send the mode select to change the speed
*/
if (current_speed == data) {
break;
}
/* Build the select data for the requested drive speed */
select_mhp->bdesc_length = 0;
/* Send the mode select for the requested block size */
SD_DONTSAVE_PAGE, SD_PATH_STANDARD)) != 0) {
/*
* The mode select failed for the requested drive speed,
* so reset the data for the original drive speed and
* send it to the target. The error is indicated by the
* return value for the failed mode select.
*/
"sr_drive_speed: Mode Select Failed\n");
}
break;
default:
/* should not reach here, but check anyway */
"sr_change_speed: Command '%x' Not Supported\n", cmd);
break;
}
if (select) {
}
if (sense) {
}
return (rval);
}
/*
* Function: sr_atapi_change_speed()
*
* Description: This routine is the driver entry point for handling CD-ROM
* drive speed ioctl requests for MMC devices that do not support
* the Real Time Streaming feature (0x107).
*
* Note: This routine will use the SET SPEED command which may not
* be supported by all devices.
*
* Arguments: dev- the device 'dev_t'
* cmd- the request type; one of CDROMGDRVSPEED (get) or
* CDROMSDRVSPEED (set)
* data- current drive speed or requested drive speed
* flag- this argument is a pass through to ddi_copyxxx() directly
* from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EINVAL if invalid arguments are provided
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EIO if invalid mode sense block descriptor length
*/
static int
{
struct mode_header_grp2 *sense_mhp;
char cdb[CDB_GROUP5];
int bd_len;
int current_speed = 0;
int max_speed = 0;
int rval;
return (ENXIO);
}
SD_PATH_STANDARD)) != 0) {
"sr_atapi_change_speed: Mode Sense Failed\n");
return (rval);
}
/* Check the block descriptor len to handle only 1 block descriptor */
if (bd_len > MODE_BLK_DESC_LENGTH) {
"sr_atapi_change_speed: Mode Sense returned invalid "
"block descriptor length\n");
return (EIO);
}
/* Calculate the current and maximum drive speeds */
/* Process the command */
switch (cmd) {
case CDROMGDRVSPEED:
sizeof (int), flag) != 0)
break;
case CDROMSDRVSPEED:
case CDROM_NORMAL_SPEED:
break;
case CDROM_DOUBLE_SPEED:
break;
case CDROM_QUAD_SPEED:
break;
case CDROM_TWELVE_SPEED:
break;
case CDROM_MAXIMUM_SPEED:
current_speed = 0xffff;
break;
default:
"sr_atapi_change_speed: invalid drive speed %d\n",
return (EINVAL);
}
/* Check the request against the drive's max speed. */
if (current_speed != 0xffff) {
if (current_speed > max_speed) {
return (EINVAL);
}
}
/*
* Build and send the SET SPEED command
*
* Note: The SET SPEED (0xBB) command used in this routine is
* obsolete per the SCSI MMC spec but still supported in the
* MT FUJI vendor spec. Most equipment is adhereing to MT FUJI
* therefore the command is still implemented in this routine.
*/
cdb[0] = (char)SCMD_SET_CDROM_SPEED;
com->uscsi_buflen = 0;
break;
default:
"sr_atapi_change_speed: Command '%x' Not Supported\n", cmd);
}
if (sense) {
}
if (com) {
}
return (rval);
}
/*
* Function: sr_pause_resume()
*
* Description: This routine is the driver entry point for handling CD-ROM
* operation.
*
* Arguments: dev - the device 'dev_t'
* cmd - the request type; one of CDROMPAUSE or CDROMRESUME, used
* for setting the resume bit of the cdb.
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EINVAL if invalid mode specified
*
*/
static int
{
char cdb[CDB_GROUP1];
int rval;
return (ENXIO);
}
cdb[0] = SCMD_PAUSE_RESUME;
switch (cmd) {
case CDROMRESUME:
break;
case CDROMPAUSE:
cdb[8] = 0;
break;
default:
" Command '%x' Not Supported\n", cmd);
goto done;
}
done:
return (rval);
}
/*
* Function: sr_play_msf()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to output the audio signals at the specified
* starting address and continue the audio play until the specified
* ending address (CDROMPLAYMSF) The address is in Minute Second
* Frame (MSF) format.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided audio msf structure,
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_msf msf_struct;
char cdb[CDB_GROUP1];
int rval;
return (EINVAL);
}
return (ENXIO);
}
return (EFAULT);
}
cdb[0] = SCMD_PLAYAUDIO_MSF;
} else {
}
return (rval);
}
/*
* Function: sr_play_trkind()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to output the audio signals at the specified
* starting address and continue the audio play until the specified
* ending address (CDROMPLAYTRKIND). The address is in Track Index
* format.
*
* Arguments: dev - the device 'dev_t'
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
char cdb[CDB_GROUP1];
int rval;
return (EINVAL);
}
return (EFAULT);
}
cdb[0] = SCMD_PLAYAUDIO_TI;
return (rval);
}
/*
* Function: sr_read_all_subcodes()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to return raw subcode data while the target is
* playing audio (CDROMSUBCODE).
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided cdrom subcode structure,
* specifying the transfer length and address.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
int rval;
char cdb[CDB_GROUP5];
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_subcode32 cdrom_subcode32;
#endif
return (EINVAL);
}
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
"sr_read_all_subcodes: ddi_copyin Failed\n");
return (EFAULT);
}
/* Convert the ILP32 uscsi data from the application to LP64 */
break;
case DDI_MODEL_NONE:
sizeof (struct cdrom_subcode), flag)) {
"sr_read_all_subcodes: ddi_copyin Failed\n");
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
"sr_read_all_subcodes: ddi_copyin Failed\n");
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/*
* Since MMC-2 expects max 3 bytes for length, check if the
* length input is greater than 3 bytes
*/
"sr_read_all_subcodes: "
"cdrom transfer length too large: %d (limit %d)\n",
return (EINVAL);
}
cdb[0] = (char)SCMD_READ_CD;
} else {
/*
* Note: A vendor specific command (0xDF) is being used her to
* request a read of all subcodes.
*/
cdb[0] = (char)SCMD_READ_ALL_SUBCODES;
}
return (rval);
}
/*
* Function: sr_read_subchannel()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to return the Q sub-channel data of the CD
* current position block. (CDROMSUBCHNL) The data includes the
* track number, index number, absolute CD-ROM address (LBA or MSF
* format per the user) , track relative CD-ROM address (LBA or MSF
* format per the user), control data and audio status.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided cdrom sub-channel structure
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_subchnl subchanel;
char cdb[CDB_GROUP1];
int rval;
return (EINVAL);
}
return (ENXIO);
}
return (EFAULT);
}
cdb[0] = SCMD_READ_SUBCHANNEL;
/* Set the MSF bit based on the user requested address format */
/*
* Set the Q bit in byte 2 to indicate that Q sub-channel data be
* returned
*/
/*
* Set byte 3 to specify the return data format. A value of 0x01
* indicates that the CD-ROM current position should be returned.
*/
if (rval != 0) {
return (rval);
}
/* Process the returned Q sub-channel data */
} else {
}
!= 0) {
return (EFAULT);
}
return (rval);
}
/*
* Function: sr_read_tocentry()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to read from the Table of Contents (TOC)
* (CDROMREADTOCENTRY). This routine provides the ADR and CTRL
* fields, the starting address (LBA or MSF format per the user)
* and the data mode if the user specified track is a data track.
*
* Note: The READ HEADER (0x44) command used in this routine is
* obsolete per the SCSI MMC spec but still supported in the
* MT FUJI vendor spec. Most equipment is adhereing to MT FUJI
* therefore the command is still implemented in this routine.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided toc entry structure,
* specifying the track # and the address format
* (LBA or MSF).
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_tocentry toc_entry;
int rval;
char cdb[CDB_GROUP1];
return (EINVAL);
}
return (ENXIO);
}
return (EFAULT);
}
/* Validate the requested track and address format */
return (EINVAL);
}
if (entry->cdte_track == 0) {
return (EINVAL);
}
cdb[0] = SCMD_READ_TOC;
/* Set the MSF bit based on the user requested address format */
} else {
}
/*
* Bytes 7 & 8 are the 12 byte allocation length for a single entry.
* (4 byte TOC response header + 8 byte track descriptor)
*/
if (rval != 0) {
return (rval);
}
/* Process the toc entry */
/*
* Send a READ TOC command using the LBA address format to get
* the LBA for the track requested so it can be used in the
* READ HEADER request
*
* Note: The MSF bit of the READ HEADER command specifies the
* output format. The block address specified in that command
* must be in LBA format.
*/
cdb[1] = 0;
if (rval != 0) {
return (rval);
}
} else {
/*
* Send a READ TOC command using the LBA address format to get
* the LBA for the track requested so it can be used in the
* READ HEADER request
*
* Note: The MSF bit of the READ HEADER command specifies the
* output format. The block address specified in that command
* must be in LBA format.
*/
cdb[1] = 0;
if (rval != 0) {
return (rval);
}
}
/*
* Build and send the READ HEADER command to determine the data mode of
* the user specified track.
*/
cdb[0] = SCMD_READ_HEADER;
if (rval == 0) {
} else {
/*
* READ HEADER command failed, since this is
* obsoleted in one spec, its better to return
* -1 for an invlid track so that we can still
* recieve the rest of the TOC data.
*/
}
} else {
}
return (EFAULT);
return (rval);
}
/*
* Function: sr_read_tochdr()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to read the Table of Contents (TOC) header
* (CDROMREADTOHDR). The TOC header consists of the disk starting
* and ending track numbers
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided toc header structure,
* specifying the starting and ending track numbers.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_tochdr toc_header;
char cdb[CDB_GROUP1];
int rval;
return (EINVAL);
}
return (ENXIO);
}
cdb[0] = SCMD_READ_TOC;
/*
* Specifying a track number of 0x00 in the READ TOC command indicates
* that the TOC header should be returned
*/
/*
* Bytes 7 & 8 are the 4 byte allocation length for TOC header.
* (2 byte data len + 1 byte starting track # + 1 byte ending track #)
*/
} else {
}
return (EFAULT);
}
return (rval);
}
/*
* Note: The following sr_read_mode1(), sr_read_cd_mode2(), sr_read_mode2(),
* sr_read_cdda(), sr_read_cdxa(), routines implement driver support for
* handling CDROMREAD ioctl requests for mode 1 user data, mode 2 user data,
* digital audio and extended architecture digital audio. These modes are
* defined in the IEC908 (Red Book), ISO10149 (Yellow Book), and the SCSI3
* MMC specs.
*
* In addition to support for the various data formats these routines also
* include support for devices that implement only the direct access READ
* commands (0x08, 0x28), devices that implement the READ_CD commands
* (0xBE, 0xD4), and devices that implement the vendor unique READ CDDA and
* READ CDXA commands (0xD8, 0xDB)
*/
/*
* Function: sr_read_mode1()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl read mode1 requests (CDROMREADMODE1).
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided cd read structure specifying
* the lba buffer address and length.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_read mode1_struct;
int rval;
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_read32 cdrom_read32;
#endif /* _MULTI_DATAMODEL */
return (EINVAL);
}
return (ENXIO);
}
"sd_read_mode1: entry: un:0x%p\n", un);
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
return (EFAULT);
}
/* Convert the ILP32 uscsi data from the application to LP64 */
break;
case DDI_MODEL_NONE:
return (EFAULT);
}
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
"sd_read_mode1: exit: un:0x%p\n", un);
return (rval);
}
/*
* Function: sr_read_cd_mode2()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl read mode2 requests (CDROMREADMODE2) for devices that
* support the READ CD (0xBE) command or the 1st generation
* READ CD (0xD4) command.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided cd read structure specifying
* the lba buffer address and length.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_read mode2_struct;
int nblocks;
int rval;
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_read32 cdrom_read32;
#endif /* _MULTI_DATAMODEL */
return (EINVAL);
}
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
return (EFAULT);
}
/* Convert the ILP32 uscsi data from the application to LP64 */
break;
case DDI_MODEL_NONE:
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/* Read command supported by 1st generation atapi drives */
cdb[0] = SCMD_READ_CDD4;
} else {
/* Universal CD Access Command */
cdb[0] = SCMD_READ_CD;
}
/*
* Set expected sector type to: 2336s byte, Mode 2 Yellow Book
*/
/* set the start address */
/* set the transfer length */
/* set the filter bits */
return (rval);
}
/*
* Function: sr_read_mode2()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl read mode2 requests (CDROMREADMODE2) for devices that
* do not support the READ CD (0xBE) command.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided cd read structure specifying
* the lba buffer address and length.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
* EIO if fail to reset block size
* EAGAIN if commands are in progress in the driver
*/
static int
{
struct cdrom_read mode2_struct;
int rval;
int nblocks;
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_read32 cdrom_read32;
#endif /* _MULTI_DATAMODEL */
return (EINVAL);
}
return (ENXIO);
}
/*
* Because this routine will update the device and driver block size
* being used we want to make sure there are no commands in progress.
* If commands are in progress the user will have to try again.
*
* We check for 1 instead of 0 because we increment un_ncmds_in_driver
* in sdioctl to protect commands from sdioctl through to the top of
* sd_uscsi_strategy. See sdioctl for details.
*/
return (EAGAIN);
}
"sd_read_mode2: entry: un:0x%p\n", un);
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
return (EFAULT);
}
/* Convert the ILP32 uscsi data from the application to LP64 */
break;
case DDI_MODEL_NONE:
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/* Store the current target block size for restoration later */
/* Change the device and soft state target block size to 2336 */
goto done;
}
/* set READ operation */
/* adjust lba for 2kbyte blocks from 512 byte blocks */
/* set the start address */
/* set the transfer length */
/* build command */
/*
* Issue SCSI command with user space address for read buffer.
*
* This sends the command through main channel in the driver.
*
* Since this is accessed via an IOCTL call, we go through the
* standard path, so that if the device was powered down, then
* it would be 'awakened' to handle the command.
*/
/* Restore the device and soft state target block size */
"can't do switch back to mode 1\n");
/*
* If sd_send_scsi_READ succeeded we still need to report
* an error because we failed to reset the block size
*/
if (rval == 0) {
}
}
done:
"sd_read_mode2: exit: un:0x%p\n", un);
return (rval);
}
/*
* Function: sr_sector_mode()
*
* Description: This utility function is used by sr_read_mode2 to set the target
* block size based on the user specified size. This is a legacy
* implementation based upon a vendor specific mode page
*
* Arguments: dev - the device 'dev_t'
* data - flag indicating if block size is being set to 2336 or
* 512.
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
int rval;
return (ENXIO);
}
/* Note: This is a vendor specific mode page (0x81) */
SD_PATH_STANDARD)) != 0) {
"sr_sector_mode: Mode Sense failed\n");
return (rval);
}
if (blksize == SD_MODE2_BLKSIZE) {
}
SD_DONTSAVE_PAGE, SD_PATH_STANDARD)) != 0) {
"sr_sector_mode: Mode Select failed\n");
} else {
/*
* Only update the softstate block size if we successfully
* changed the device block mode.
*/
}
return (rval);
}
/*
* Function: sr_read_cdda()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to return CD-DA or subcode data. (CDROMCDDA) If
* the target supports CDDA these requests are handled via a vendor
* specific command (0xD8) If the target does not support CDDA
* these requests are handled via the READ CD command (0xBE).
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided CD-DA structure specifying
* the track starting address, transfer length, and
* subcode options.
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if invalid arguments are provided
* ENOTTY
*/
static int
{
struct cdrom_cdda *cdda;
int rval;
char cdb[CDB_GROUP5];
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_cdda32 cdrom_cdda32;
#endif /* _MULTI_DATAMODEL */
return (EINVAL);
}
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
"sr_read_cdda: ddi_copyin Failed\n");
return (EFAULT);
}
/* Convert the ILP32 uscsi data from the application to LP64 */
break;
case DDI_MODEL_NONE:
"sr_read_cdda: ddi_copyin Failed\n");
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
"sr_read_cdda: ddi_copyin Failed\n");
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/*
* Since MMC-2 expects max 3 bytes for length, check if the
* length input is greater than 3 bytes
*/
"cdrom transfer length too large: %d (limit %d)\n",
return (EINVAL);
}
switch (cdda->cdda_subcode) {
case CDROM_DA_NO_SUBCODE:
break;
case CDROM_DA_SUBQ:
break;
case CDROM_DA_ALL_SUBCODE:
break;
case CDROM_DA_SUBCODE_ONLY:
break;
default:
"sr_read_cdda: Subcode '0x%x' Not Supported\n",
cdda->cdda_subcode);
return (EINVAL);
}
/* Build and send the command */
cdb[0] = (char)SCMD_READ_CD;
switch (cdda->cdda_subcode) {
case CDROM_DA_NO_SUBCODE :
break;
case CDROM_DA_SUBQ :
break;
case CDROM_DA_ALL_SUBCODE :
break;
case CDROM_DA_SUBCODE_ONLY :
/* FALLTHROUGH */
default :
return (ENOTTY);
}
} else {
cdb[0] = (char)SCMD_READ_CDDA;
}
return (rval);
}
/*
* Function: sr_read_cdxa()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests to return CD-XA (Extended Architecture) data.
* (CDROMCDXA).
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user provided CD-XA structure specifying
* the data starting address, transfer length, and format
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
struct cdrom_cdxa *cdxa;
int rval;
char cdb[CDB_GROUP5];
#ifdef _MULTI_DATAMODEL
/* To support ILP32 applications in an LP64 world */
struct cdrom_cdxa32 cdrom_cdxa32;
#endif /* _MULTI_DATAMODEL */
return (EINVAL);
}
return (ENXIO);
}
#ifdef _MULTI_DATAMODEL
case DDI_MODEL_ILP32:
return (EFAULT);
}
/*
* Convert the ILP32 uscsi data from the
* application to LP64 for internal use.
*/
break;
case DDI_MODEL_NONE:
return (EFAULT);
}
break;
}
#else /* ! _MULTI_DATAMODEL */
return (EFAULT);
}
#endif /* _MULTI_DATAMODEL */
/*
* Since MMC-2 expects max 3 bytes for length, check if the
* length input is greater than 3 bytes
*/
"cdrom transfer length too large: %d (limit %d)\n",
return (EINVAL);
}
switch (cdxa->cdxa_format) {
case CDROM_XA_DATA:
read_flags = 0x10;
break;
case CDROM_XA_SECTOR_DATA:
read_flags = 0xf8;
break;
case CDROM_XA_DATA_W_ERROR:
read_flags = 0xfc;
break;
default:
"sr_read_cdxa: Format '0x%x' Not Supported\n",
cdxa->cdxa_format);
return (EINVAL);
}
cdb[0] = (char)SCMD_READ_CD;
} else {
/*
* Note: A vendor specific command (0xDB) is being used her to
* request a read of all subcodes.
*/
cdb[0] = (char)SCMD_READ_CDXA;
}
return (rval);
}
/*
* Function: sr_eject()
*
* Description: This routine is the driver entry point for handling CD-ROM
* eject ioctl requests (FDEJECT, DKIOCEJECT, CDROMEJECT)
*
* Arguments: dev - the device 'dev_t'
*
* Return Code: the code returned by sd_send_scsi_cmd()
*/
static int
{
int rval;
return (ENXIO);
}
SD_PATH_STANDARD)) != 0) {
return (rval);
}
if (rval == 0) {
sr_ejected(un);
}
return (rval);
}
/*
* Function: sr_ejected()
*
* Description: This routine updates the soft state structure to invalidate the
* geometry information after the media has been ejected or a
* media eject has been detected.
*
* Arguments: un - driver soft state (unit) structure
*/
static void
{
struct sd_errstats *stp;
}
}
/*
* Function: sr_check_wp()
*
* Description: This routine checks the write protection of a removable
* media disk and hotpluggable devices via the write protect bit of
* the Mode Page Header device specific field. Some devices choke
* on unsupported mode page. In order to workaround this issue,
* this routine has been implemented to use 0x3f mode page(request
* for all pages) for all device types.
*
* Arguments: dev - the device 'dev_t'
*
* Return Code: int indicating if the device is write protected (1) or not (0)
*
* Context: Kernel thread.
*
*/
static int
{
int hdrlen;
/*
* Note: The return codes for this routine should be reworked to
* properly handle the case of a NULL softstate.
*/
return (FALSE);
}
/*
* The mode page contents are not required; set the allocation
* length for the mode page header only
*/
MODEPAGE_ALLPAGES, SD_PATH_STANDARD) != 0)
goto err_exit;
} else {
MODEPAGE_ALLPAGES, SD_PATH_STANDARD) != 0)
goto err_exit;
}
/*
* Write protect mode sense failed; not all disks
* understand this query. Return FALSE assuming that
* these devices are not writable.
*/
if (device_specific & WRITE_PROTECT) {
}
return (rval);
}
/*
* Function: sr_volume_ctrl()
*
* Description: This routine is the driver entry point for handling CD-ROM
* audio output volume ioctl requests. (CDROMVOLCTRL)
*
* Arguments: dev - the device 'dev_t'
* data - pointer to user audio volume control structure
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*
*/
static int
{
struct cdrom_volctrl volume;
int sense_buflen;
int select_buflen;
int rval;
return (EINVAL);
}
return (ENXIO);
}
return (EFAULT);
}
struct mode_header_grp2 *sense_mhp;
struct mode_header_grp2 *select_mhp;
int bd_len;
SD_PATH_STANDARD)) != 0) {
"sr_volume_ctrl: Mode Sense Failed\n");
return (rval);
}
if (bd_len > MODE_BLK_DESC_LENGTH) {
"sr_volume_ctrl: Mode Sense returned invalid "
"block descriptor length\n");
return (EIO);
}
sense_page = (uchar_t *)
select_mhp->length_msb = 0;
select_mhp->length_lsb = 0;
select_mhp->bdesc_length_hi = 0;
select_mhp->bdesc_length_lo = 0;
} else {
SD_PATH_STANDARD)) != 0) {
"sr_volume_ctrl: Mode Sense Failed\n");
return (rval);
}
"sr_volume_ctrl: Mode Sense returned invalid "
"block descriptor length\n");
return (EIO);
}
sense_page = (uchar_t *)
select_mhp->length = 0;
select_mhp->bdesc_length = 0;
}
/*
* Note: An audio control data structure could be created and overlayed
* on the following in place of the array indexing method implemented.
*/
/* Build the select data for the user volume data */
/* Set the immediate bit */
/* Zero out reserved fields */
/* Return sense data for fields not to be modified */
/* Set the user specified volume levels for channel 0 and 1 */
/* Channel 2 and 3 are currently unsupported so return the sense data */
} else {
}
return (rval);
}
/*
* Function: sr_read_sony_session_offset()
*
* Description: This routine is the driver entry point for handling CD-ROM
* ioctl requests for session offset information. (CDROMREADOFFSET)
* The address of the first track in the last session of a
* multi-session CD-ROM is returned
*
* Note: This routine uses a vendor specific key value in the
* command control field without implementing any vendor check here
* or in the ioctl routine.
*
* Arguments: dev - the device 'dev_t'
* data - pointer to an int to hold the requested address
* flag - this argument is a pass through to ddi_copyxxx()
* directly from the mode argument of ioctl().
*
* Return Code: the code returned by sd_send_scsi_cmd()
* EFAULT if ddi_copyxxx() fails
* ENXIO if fail ddi_get_soft_state
* EINVAL if data pointer is NULL
*/
static int
{
char cdb[CDB_GROUP1];
int session_offset = 0;
int rval;
return (EINVAL);
}
return (ENXIO);
}
cdb[0] = SCMD_READ_TOC;
/*
* Bytes 7 & 8 are the 12 byte allocation length for a single entry.
* (4 byte TOC response header + 8 byte response data)
*/
/* Byte 9 is the control byte. A vendor specific value is used */
if (rval != 0) {
return (rval);
}
/*
* Offset returned offset in current lbasize block's. Convert to
* 2k block's to return to the user
*/
session_offset >>= 2;
session_offset >>= 1;
}
}
}
return (rval);
}
/*
* Function: sd_wm_cache_constructor()
*
* devices.
*
* Arguments: wm - A pointer to the sd_w_map to be initialized.
* un - sd_lun structure for the device.
* flag - the km flags passed to constructor
*
* Return Code: 0 on success.
* -1 on failure.
*/
/*ARGSUSED*/
static int
{
return (0);
}
/*
* Function: sd_wm_cache_destructor()
*
* devices.
*
* Arguments: wm - A pointer to the sd_w_map to be initialized.
* un - sd_lun structure for the device.
*/
/*ARGSUSED*/
static void
{
}
/*
* Function: sd_range_lock()
*
* Description: Lock the range of blocks specified as parameter to ensure
* that read, modify write is atomic and no other i/o writes
* to the same location. The range is specified in terms
* of start and end blocks. Block numbers are the actual
* media block numbers and not system.
*
* Arguments: un - sd_lun structure for the device.
* startb - The starting block number
* endb - The end block number
* typ - type of i/o - simple/read_modify_write
*
* Return Code: wm - pointer to the wmap structure.
*
* Context: This routine can sleep.
*/
static struct sd_w_map *
{
while (state != SD_WM_DONE) {
switch (state) {
case SD_WM_CHK_LIST:
/*
* This is the starting state. Check the wmap list
* to see if the range is currently available.
*/
/*
* If this is a simple write and no rmw
* i/o is pending then try to lock the
* range as the range should be available.
*/
} else {
/*
* Should not keep onlist wmps
* while waiting this macro
* will also do wmp = NULL;
*/
}
/*
* sl_wmp is the wmap on which wait
* is done, since the tmp_wmp points
* to the inuse wmap, set sl_wmp to
* tmp_wmp and change the state to sleep
*/
} else {
}
}
break;
case SD_WM_LOCK_RANGE:
/*
* The range need to be locked, try to get a wmap.
* First attempt it with NO_SLEEP, want to avoid a sleep
* if possible as we will have to release the sd mutex
* if we have to sleep.
*/
(sd_lun::un_wm_cache))
KM_SLEEP);
/*
* we released the mutex so recheck and go to
* check list state.
*/
} else {
/*
* We exit out of state machine since we
* have the wmap. Do the housekeeping first.
* place the wmap on the wmap list if it is not
* on it already and then set the state to done.
*/
if (typ & SD_WTYPE_RMW) {
un->un_rmw_count++;
}
/*
* If not already on the list then link
*/
}
state = SD_WM_DONE;
}
break;
case SD_WM_WAIT_MAP:
/*
* Wait is done on sl_wmp, which is set in the
* check_list state.
*/
/*
* We can reuse the memory from the completed sl_wmp
* lock range for our new lock, but only if noone is
* waiting for it.
*/
if (sl_wmp->wm_wanted_count == 0) {
}
/*
* After waking up, need to recheck for availability of
* range.
*/
break;
default:
panic("sd_range_lock: "
"Unknown state %d in sd_range_lock", state);
/*NOTREACHED*/
} /* switch(state) */
} /* while(state != SD_WM_DONE) */
return (wmp);
}
/*
* Function: sd_get_range()
*
* Description: Find if there any overlapping I/O to this one
* Returns the write-map of 1st such I/O, NULL otherwise.
*
* Arguments: un - sd_lun structure for the device.
* startb - The starting block number
* endb - The end block number
*
* Return Code: wm - pointer to the wmap structure.
*/
static struct sd_w_map *
{
continue;
}
break;
}
break;
}
}
return (wmp);
}
/*
* Function: sd_free_inlist_wmap()
*
* Description: Unlink and free a write map struct.
*
* Arguments: un - sd_lun structure for the device.
* wmp - sd_w_map which needs to be unlinked.
*/
static void
{
} else {
}
}
}
/*
* Function: sd_range_unlock()
*
* Description: Unlock the range locked by wm.
* Free write map if nobody else is waiting on it.
*
* Arguments: un - sd_lun structure for the device.
* wmp - sd_w_map which needs to be unlinked.
*/
static void
{
un->un_rmw_count--;
}
if (wm->wm_wanted_count) {
/*
* Broadcast that the wmap is available now.
*/
} else {
/*
* If no one is waiting on the map, it should be free'ed.
*/
}
}
/*
* Function: sd_read_modify_write_task
*
* Description: Called from a taskq thread to initiate the write phase of
* a read-modify-write request. This is used for targets where
* un->un_sys_blocksize != un->un_tgt_blocksize.
*
* Arguments: arg - a pointer to the buf(9S) struct for the write command.
*
* Context: Called under taskq thread context.
*/
static void
sd_read_modify_write_task(void *arg)
{
struct sd_mapblocksize_info *bsp;
/* Get the pointer to the layer-private data struct */
"sd_read_modify_write_task: entry: buf:0x%p\n", bp);
/*
* This is the write phase of a read-modify-write request, called
* under the context of a taskq thread in response to the completion
* of the read portion of the rmw request completing under interrupt
* context. The write request must be sent from here down the iostart
* chain as if it were being sent from sd_mapblocksize_iostart(), so
* we use the layer index saved in the layer-private data area.
*/
"sd_read_modify_write_task: exit: buf:0x%p\n", bp);
}
/*
* Function: sddump_do_read_of_rmw()
*
* Description: This routine will be called from sddump, If sddump is called
* with an I/O which not aligned on device blocksize boundary
* then the write has to be converted to read-modify-write.
* Do the read part here in order to keep sddump simple.
* Note - That the sd_mutex is held across the call to this
* routine.
*
* Arguments: un - sd_lun
* blkno - block number in terms of media block size.
* nblk - number of blocks.
* bpp - pointer to pointer to the buf structure. On return
* from this function, *bpp points to the valid buffer
* to which the write has to be done.
*
* Return Code: 0 for success or errno-type return code
*/
static int
{
int err;
int i;
int rval;
"no resources for dumping; giving up");
goto done;
}
if (rval != 0) {
"no resources for dumping; giving up");
goto done;
}
for (i = 0; i < SD_NDUMP_RETRIES; i++) {
/*
* Scsi_poll returns 0 (success) if the command completes and
* the status block is STATUS_GOOD. We should only check
* errors if this condition is not true. Even then we should
* send our own request sense packet only if we have a check
* condition and auto request sense has not been performed by
* the hba.
*/
err = 0;
break;
}
/*
* Check CMD_DEV_GONE 1st, give up if device is gone,
* no need to read RQS data.
*/
"Device is gone\n");
break;
}
"sddump: read failed with CHECK, try # %d\n", i);
(void) sd_send_polled_RQS(un);
}
continue;
}
int reset_retval = 0;
"sddump: read failed with BUSY, try # %d\n", i);
}
if (reset_retval == 0) {
}
(void) sd_send_polled_RQS(un);
} else {
"sddump: read failed with 0x%x, try # %d\n",
SD_GET_PKT_STATUS(pkt), i);
}
/*
* let's reset the bus.
*/
if (i > SD_NDUMP_RETRIES/2) {
(void) sd_send_polled_RQS(un);
}
}
if (err != 0) {
} else {
}
done:
return (err);
}
/*
* Function: sd_failfast_flushq
*
* Description: Take all bp's on the wait queue that have B_FAILFAST set
* in b_flags and move them onto the failfast queue, then kick
* off a thread to return all bp's on the failfast queue to
* their owners with an error set.
*
* Arguments: un - pointer to the soft state struct for the instance.
*
* Context: may execute in interrupt context.
*/
static void
{
struct buf *next_waitq_bp;
"sd_failfast_flushq: entry: un:0x%p\n", un);
/*
* Check if we should flush all bufs when entering failfast state, or
* just those with B_FAILFAST set.
*/
/*
* Move *all* bp's on the wait queue to the failfast flush
* queue, including those that do NOT have B_FAILFAST set.
*/
} else {
}
/* update kstat for each bp moved out of the waitq */
}
/* empty the waitq */
} else {
/*
* Go thru the wait queue, pick off all entries with
* B_FAILFAST set, and move these onto the failfast queue.
*/
/*
* Save the pointer to the next bp on the wait queue,
* so we get to it on the next iteration of this loop.
*/
/*
* If this bp from the wait queue does NOT have
* B_FAILFAST set, just move on to the next element
* in the wait queue. Note, this is the only place
* where it is correct to set prev_waitq_bp.
*/
prev_waitq_bp = bp;
continue;
}
/*
* Remove the bp from the wait queue.
*/
/* The bp is the first element of the waitq. */
/* The wait queue is now empty */
}
} else {
/*
* The bp is either somewhere in the middle
* or at the end of the wait queue.
*/
== 0);
/* bp is the last entry on the waitq. */
}
}
/*
* update kstat since the bp is moved out of
* the waitq
*/
/*
* Now put the bp onto the failfast queue.
*/
/* failfast queue is currently empty */
} else {
/* Add the bp to the end of the failfast q */
}
}
}
/*
* Now return all bp's on the failfast queue to their owners.
*/
}
/*
* We want to return the bp with a failure error code, but
* we do not want a call to sd_start_cmds() to occur here,
* so use sd_return_failed_command_no_restart() instead of
* sd_return_failed_command().
*/
}
/* Flush the xbuf queues if required. */
}
"sd_failfast_flushq: exit: un:0x%p\n", un);
}
/*
* Function: sd_failfast_flushq_callback
*
* Description: Return TRUE if the given bp meets the criteria for failfast
* flushing. Used with ddi_xbuf_flushq(9F).
*
* Arguments: bp - ptr to buf struct to be examined.
*
* Context: Any
*/
static int
{
/*
* Return TRUE if (1) we want to flush ALL bufs when the failfast
* state is entered; OR (2) the given bp has B_FAILFAST set.
*/
return (((sd_failfast_flushctl & SD_FAILFAST_FLUSH_ALL_BUFS) ||
}
/*
* Function: sd_setup_next_xfer
*
* Description: Prepare next I/O operation using DMA_PARTIAL
*
*/
static int
{
int rval;
/*
* Calculate next block number and amount to be transferred.
*
* How much data NOT transfered to the HBA yet.
*/
/*
* figure how many blocks NOT transfered to the HBA yet.
*/
/*
* set starting block number to the end of what WAS transfered.
*/
/*
* Move pkt to the next portion of the xfer. sd_setup_next_rw_pkt
* will call scsi_initpkt with NULL_FUNC so we do not have to release
* the disk mutex here.
*/
if (rval == 0) {
/*
* Success.
*
* Adjust things if there are still more blocks to be
* transfered.
*/
return (1);
}
/*
* There's really only one possible return value from
* sd_setup_next_rw_pkt which occurs when scsi_init_pkt
* returns NULL.
*/
"Error setting up next portion of DMA transfer\n");
return (0);
}
#endif
/*
* Function: sd_panic_for_res_conflict
*
* Description: Call panic with a string formated with "Reservation Conflict"
* and a human readable identifier indicating the SD instance
* that experienced the reservation conflict.
*
* Arguments: un - pointer to the soft state struct for the instance.
*
* Context: may execute in interrupt context.
*/
#define SD_RESV_CONFLICT_FMT_LEN 40
void
{
char path_str[MAXPATHLEN];
"Reservation Conflict\nDisk: %s",
}
/*
* Note: The following sd_faultinjection_ioctl( ) routines implement
* driver support for handling fault injection for error analysis
* causing faults in multiple layers of the driver.
*
*/
#ifdef SD_FAULT_INJECTION
static uint_t sd_fault_injection_on = 0;
/*
* Function: sd_faultinjection_ioctl()
*
* Description: This routine is the driver entry point for handling
* faultinjection ioctls to inject errors into the
* layer model
*
* Arguments: cmd - the ioctl cmd recieved
* arg - the arguments from user and returns
*/
static void
uint_t i;
switch (cmd) {
case SDIOCRUN:
/* Allow pushed faults to be injected */
"sd_faultinjection_ioctl: Injecting Fault Run\n");
"sd_faultinjection_ioctl: run finished\n");
break;
case SDIOCSTART:
/* Start Injection Session */
"sd_faultinjection_ioctl: Injecting Fault Start\n");
for (i = 0; i < SD_FI_MAX_ERROR; i++) {
}
un->sd_fi_fifo_start = 0;
un->sd_fi_fifo_end = 0;
un->sd_fi_buf_len = 0;
"sd_faultinjection_ioctl: start finished\n");
break;
case SDIOCSTOP:
/* Stop Injection Session */
"sd_faultinjection_ioctl: Injecting Fault Stop\n");
/* Empty stray or unuseds structs from fifo */
for (i = 0; i < SD_FI_MAX_ERROR; i++) {
sizeof (struct sd_fi_pkt));
}
sizeof (struct sd_fi_xb));
}
sizeof (struct sd_fi_un));
}
sizeof (struct sd_fi_arq));
}
}
un->sd_fi_fifo_start = 0;
un->sd_fi_fifo_end = 0;
"sd_faultinjection_ioctl: stop finished\n");
break;
case SDIOCINSERTPKT:
/* Store a packet struct to be pushed onto fifo */
"sd_faultinjection_ioctl: Injecting Fault Insert Pkt\n");
/* No more that SD_FI_MAX_ERROR allowed in Queue */
sizeof (struct sd_fi_pkt));
}
un->sd_fi_fifo_pkt[i] =
/* Alloc failed don't store anything */
break;
}
sizeof (struct sd_fi_pkt), 0);
if (rval == -1) {
sizeof (struct sd_fi_pkt));
}
} else {
"sd_faultinjection_ioctl: pkt null\n");
}
break;
case SDIOCINSERTXB:
/* Store a xb struct to be pushed onto fifo */
"sd_faultinjection_ioctl: Injecting Fault Insert XB\n");
sizeof (struct sd_fi_xb));
}
un->sd_fi_fifo_xb[i] =
/* Alloc failed don't store anything */
break;
}
sizeof (struct sd_fi_xb), 0);
if (rval == -1) {
sizeof (struct sd_fi_xb));
}
} else {
"sd_faultinjection_ioctl: xb null\n");
}
break;
case SDIOCINSERTUN:
/* Store a un struct to be pushed onto fifo */
"sd_faultinjection_ioctl: Injecting Fault Insert UN\n");
sizeof (struct sd_fi_un));
}
un->sd_fi_fifo_un[i] =
/* Alloc failed don't store anything */
break;
}
sizeof (struct sd_fi_un), 0);
if (rval == -1) {
sizeof (struct sd_fi_un));
}
} else {
"sd_faultinjection_ioctl: un null\n");
}
break;
case SDIOCINSERTARQ:
/* Store a arq struct to be pushed onto fifo */
"sd_faultinjection_ioctl: Injecting Fault Insert ARQ\n");
sizeof (struct sd_fi_arq));
}
un->sd_fi_fifo_arq[i] =
/* Alloc failed don't store anything */
break;
}
sizeof (struct sd_fi_arq), 0);
if (rval == -1) {
sizeof (struct sd_fi_arq));
}
} else {
"sd_faultinjection_ioctl: arq null\n");
}
break;
case SDIOCPUSH:
/* Push stored xb, pkt, un, and arq onto fifo */
if (rval != -1 &&
un->sd_fi_fifo_end += i;
}
} else {
"sd_faultinjection_ioctl: push arg null\n");
un->sd_fi_fifo_end++;
}
}
"sd_faultinjection_ioctl: push to end=%d\n",
un->sd_fi_fifo_end);
break;
case SDIOCRETRIEVE:
/* Return buffer of log from Injection session */
"sd_faultinjection_ioctl: Injecting Fault Retreive");
if (rval == -1) {
/*
* arg is possibly invalid setting
* it to NULL for return
*/
}
break;
}
" exit\n");
}
/*
* Function: sd_injection_log()
*
* Description: This routine adds buff to the already existing injection log
* for retrieval via faultinjection_ioctl for use in fault
* detection and recovery
*
* Arguments: buf - the string to add to the log
*/
static void
{
/* Add logged value to Injection log to be returned later */
int i;
for (i = 0; i < len; i++) {
}
}
}
/*
* Function: sd_faultinjection()
*
* Description: This routine takes the pkt and changes its
* content based on error injection scenerio.
*
* Arguments: pktp - packet to be changed
*/
static void
{
uint_t i;
/* pull bp xb and un from pktp */
"sd_faultinjection: entry Injection from sdintr\n");
/* if injection is off return */
if (sd_fault_injection_on == 0 ||
return;
}
/* take next set off fifo */
/* set variables accordingly */
/* set pkt if it was on fifo */
}
/* set xb if it was on fifo */
"xb_victim_retry_count");
/* copy in block data from sense */
}
/* copy in extended sense codes */
"es_code");
"es_key");
"es_add_code");
es_qual_code, "es_qual_code");
}
/* set un if it was on fifo */
"un_reset_retry_count");
"un_f_geometry_is_valid");
"un_f_allow_bus_device_reset");
}
/* copy in auto request sense if it was on fifo */
}
/* free structs */
}
}
}
}
/*
* kmem_free does not gurantee to set to NULL
* since we uses these to determine if we set
* values or not lets confirm they are always
* NULL after free
*/
un->sd_fi_fifo_start++;
}
#endif /* SD_FAULT_INJECTION */
/*
* This routine is invoked in sd_unit_attach(). Before calling it, the
* properties in conf file should be processed already, and "hotpluggable"
* property was processed also.
*
* The sd driver distinguishes 3 different type of devices: removable media,
* non-removable media, and hotpluggable. Below the differences are defined:
*
* 1. Device ID
*
* The device ID of a device is used to identify this device. Refer to
* ddi_devid_register(9F).
*
* For a non-removable media disk device which can provide 0x80 or 0x83
* VPD page (refer to INQUIRY command of SCSI SPC specification), a unique
* device ID is created to identify this device. For other non-removable
* media devices, a default device ID is created only if this device has
* at least 2 alter cylinders. Otherwise, this device has no devid.
*
* -------------------------------------------------------
* removable media hotpluggable | Can Have Device ID
* -------------------------------------------------------
* false false | Yes
* false true | Yes
* true x | No
* ------------------------------------------------------
*
*
* 2. SCSI group 4 commands
*
* In SCSI specs, only some commands in group 4 command set can use
* 8-byte addresses that can be used to access >2TB storage spaces.
* Other commands have no such capability. Without supporting group4,
* it is impossible to make full use of storage spaces of a disk with
* capacity larger than 2TB.
*
* -----------------------------------------------
* removable media hotpluggable LP64 | Group
* -----------------------------------------------
* false false false | 1
* false false true | 4
* false true false | 1
* false true true | 4
* true x x | 5
* -----------------------------------------------
*
*
* 3. Check for VTOC Label
*
* If a direct-access disk has no EFI label, sd will check if it has a
* valid VTOC label. Now, sd also does that check for removable media
* and hotpluggable devices.
*
* --------------------------------------------------------------
* Direct-Access removable media hotpluggable | Check Label
* -------------------------------------------------------------
* false false false | No
* false false true | No
* false true false | Yes
* false true true | Yes
* true x x | Yes
* --------------------------------------------------------------
*
*
* 4. Building default VTOC label
*
* As section 3 says, sd checks if some kinds of devices have VTOC label.
* If those devices have no valid VTOC label, sd(7d) will attempt to
* create default VTOC for them. Currently sd creates default VTOC label
* for all devices on x86 platform (VTOC_16), but only for removable
* media devices on SPARC (VTOC_8).
*
* -----------------------------------------------------------
* removable media hotpluggable platform | Default Label
* -----------------------------------------------------------
* false false sparc | No
* false true x86 | Yes
* false true sparc | Yes
* true x x | Yes
* ----------------------------------------------------------
*
*
* 5. Supported blocksizes of target devices
*
* Sd supports non-512-byte blocksize for removable media devices only.
* For other devices, only 512-byte blocksize is supported. This may be
* changed in near future because some RAID devices require non-512-byte
* blocksize
*
* -----------------------------------------------------------
* removable media hotpluggable | non-512-byte blocksize
* -----------------------------------------------------------
* false false | No
* false true | No
* true x | Yes
* -----------------------------------------------------------
*
*
* 6. Automatic mount & unmount (i.e. vold)
*
* Sd(7d) driver provides DKIOCREMOVABLE ioctl. This ioctl is used to query
* if a device is removable media device. It return 1 for removable media
* devices, and 0 for others.
*
* Vold treats a device as removable one only if DKIOREMOVABLE returns 1.
* And it does automounting only for removable media devices. In order to
* preserve users' experience and let vold continue to do automounting for
* USB disk devices, DKIOCREMOVABLE ioctl still returns 1 for USB/1394 disk
* devices.
*
* ------------------------------------------------------
* removable media hotpluggable | automatic mount
* ------------------------------------------------------
* false false | No
* false true | Yes
* true x | Yes
* ------------------------------------------------------
*
*
* 7. fdisk partition management
*
* Fdisk is traditional partition method on x86 platform. Sd(7d) driver
* just supports fdisk partitions on x86 platform. On sparc platform, sd
* doesn't support fdisk partitions at all. Note: pcfs(7fs) can recognize
* fdisk partitions on both x86 and SPARC platform.
*
* -----------------------------------------------------------
* platform removable media USB/1394 | fdisk supported
* -----------------------------------------------------------
* x86 X X | true
* ------------------------------------------------------------
* sparc X X | false
* ------------------------------------------------------------
*
*
*
* Although sd(7d) doesn't support fdisk on SPARC platform, it does support
*
* -----------------------------------------------------------
* platform removable media USB/1394 | mboot supported
* -----------------------------------------------------------
* x86 X X | true
* ------------------------------------------------------------
* sparc false false | false
* sparc false true | true
* sparc true false | true
* sparc true true | true
* ------------------------------------------------------------
*
*
* 9. error handling during opening device
*
* If failed to open a disk device, an errno is returned. For some kinds
* of errors, different errno is returned depending on if this device is
* a removable media device. This brings USB/1394 hard disks in line with
* expected hard disk behavior. It is not expected that this breaks any
* application.
*
* ------------------------------------------------------
* removable media hotpluggable | errno
* ------------------------------------------------------
* false false | EIO
* false true | EIO
* true x | ENXIO
* ------------------------------------------------------
*
*
* 11. ioctls: DKIOCEJECT, CDROMEJECT
*
* These IOCTLs are applicable only to removable media devices.
*
* -----------------------------------------------------------
* removable media hotpluggable |DKIOCEJECT, CDROMEJECT
* -----------------------------------------------------------
* false false | No
* false true | No
* true x | Yes
* -----------------------------------------------------------
*
*
* 12. Kstats for partitions
*
* sd creates partition kstat for non-removable media devices. USB and
* Firewire hard disks now have partition kstats
*
* ------------------------------------------------------
* removable media hotplugable | kstat
* ------------------------------------------------------
* false false | Yes
* false true | Yes
* true x | No
* ------------------------------------------------------
*
*
* 13. Removable media & hotpluggable properties
*
* Sd driver creates a "removable-media" property for removable media
* devices. Parent nexus drivers create a "hotpluggable" property if
* it supports hotplugging.
*
* ---------------------------------------------------------------------
* removable media hotpluggable | "removable-media" " hotpluggable"
* ---------------------------------------------------------------------
* false false | No No
* false true | No Yes
* true false | Yes No
* true true | Yes Yes
* ---------------------------------------------------------------------
*
*
* 14. Power Management
*
* sd only power manages removable media devices or devices that support
* LOG_SENSE or have a "pm-capable" property (PSARC/2002/250)
*
* A parent nexus that supports hotplugging can also set "pm-capable"
* if the disk can be power managed.
*
* ------------------------------------------------------------
* removable media hotpluggable pm-capable | power manage
* ------------------------------------------------------------
* false false false | No
* false false true | Yes
* false true false | No
* false true true | Yes
* true x x | Yes
* ------------------------------------------------------------
*
* USB and firewire hard disks can now be power managed independently
* of the framebuffer
*
*
* 15. Support for USB disks with capacity larger than 1TB
*
* Currently, sd doesn't permit a fixed disk device with capacity
* larger than 1TB to be used in a 32-bit operating system environment.
* However, sd doesn't do that for removable media devices. Instead, it
* assumes that removable media devices cannot have a capacity larger
* than 1TB. Therefore, using those devices on 32-bit system is partially
* supported, which can cause some unexpected results.
*
* ---------------------------------------------------------------------
* removable media USB/1394 | Capacity > 1TB | Used in 32-bit env
* ---------------------------------------------------------------------
* false false | true | no
* false true | true | no
* true false | true | Yes
* true true | true | Yes
* ---------------------------------------------------------------------
*
*
* 16. Check write-protection at open time
*
* When a removable media device is being opened for writing without NDELAY
* flag, sd will check if this device is writable. If attempting to open
* without NDELAY flag a write-protected device, this operation will abort.
*
* ------------------------------------------------------------
* removable media USB/1394 | WP Check
* ------------------------------------------------------------
* false false | No
* false true | No
* true false | Yes
* true true | Yes
* ------------------------------------------------------------
*
*
* 17. syslog when corrupted VTOC is encountered
*
* Currently, if an invalid VTOC is encountered, sd only print syslog
* for fixed SCSI disks.
* ------------------------------------------------------------
* removable media USB/1394 | print syslog
* ------------------------------------------------------------
* false false | Yes
* false true | No
* true false | No
* true true | No
* ------------------------------------------------------------
*/
static void
{
int pm_capable_prop;
#if defined(_SUNOS_VTOC_16)
/*
* For VTOC_16 devices, the default label will be created for all
* devices. (see sd_build_default_label)
*/
#endif
/*
* The media of this device is removable. And for this kind
* of devices, it is possible to change medium after openning
* devices. Thus we should support this operation.
*/
#if defined(_SUNOS_VTOC_8)
/*
* Note: currently, for VTOC_8 devices, default label is
* created for removable and hotpluggable devices only.
*/
#endif
/*
* support non-512-byte blocksize of removable media devices
*/
/*
* Assume that all removable media devices support DOOR_LOCK
*/
/*
* For a removable media device, it is possible to be opened
* with NDELAY flag when there is no media in drive, in this
* case we don't care if device is writable. But if without
* NDELAY flag, we need to check if media is write-protected.
*/
/*
* need to start a SCSI watch thread to monitor media state,
* when media is being inserted or ejected, notify syseventd.
*/
/*
* Some devices don't support START_STOP_UNIT command.
* Therefore, we'd better check if a device supports it
* before sending it.
*/
/*
* support eject media ioctl:
* FDEJECT, DKIOCEJECT, CDROMEJECT
*/
/*
* Because many removable-media devices don't support
* LOG_SENSE, we couldn't use this command to check if
* a removable media device support power-management.
* We assume that they support power-management via
* START_STOP_UNIT command and can be spun up and down
* without limitations.
*/
/*
* Need to create a zero length (Boolean) property
* removable-media for the removable media devices.
* Note that the return value of the property is not being
* checked, since if unable to create the property
* then do not want the attach to fail altogether. Consistent
* with other property creation in attach.
*/
} else {
/*
* create device ID for device
*/
/*
* Spin up non-removable-media devices once it is attached
*/
/*
* According to SCSI specification, Sense data has two kinds of
* format: fixed format, and descriptor format. At present, we
* don't support descriptor format sense data for removable
* media.
*/
}
/*
* kstats are created only for non-removable media devices.
*
* Set this in sd.conf to 0 in order to disable kstats. The
* default is 1, so they are enabled by default.
*/
"enable-partition-kstats", 1));
/*
* Check if HBA has set the "pm-capable" property.
* If "pm-capable" exists and is non-zero then we can
* cycle count log sense page.
*
* If "pm-capable" exists and is SD_PM_CAPABLE_FALSE (0)
* then we should not power manage the device.
*
* If "pm-capable" doesn't exist then pm_capable_prop will
* be set to SD_PM_CAPABLE_UNDEFINED (-1). In this case,
* and power manage the device if the cycle count limit has
* not been exceeded.
*/
if (pm_capable_prop == SD_PM_CAPABLE_UNDEFINED) {
} else {
/*
* pm-capable property exists.
*
* Convert "TRUE" values for pm_capable_prop to
* SD_PM_CAPABLE_TRUE (1) to make it easier to check
* later. "TRUE" values are any values except
* SD_PM_CAPABLE_FALSE (0) and
* SD_PM_CAPABLE_UNDEFINED (-1)
*/
if (pm_capable_prop == SD_PM_CAPABLE_FALSE) {
} else {
}
"sd_unit_attach: un:0x%p pm-capable "
}
}
if (un->un_f_is_hotpluggable) {
#if defined(_SUNOS_VTOC_8)
/*
* Note: currently, for VTOC_8 devices, default label is
* created for removable and hotpluggable devices only.
*/
#endif
/*
* Temporarily, let hotpluggable devices pretend to be
* removable-media devices for vold.
*/
}
/*
* By default, only DIRECT ACCESS devices and CDs will have Sun
* labels.
*/
/*
* Direct access devices have disk label
*/
}
/*
* Fdisk partitions are supported for all direct access devices on
* x86 platform, and just for removable media and hotpluggable
* devices on SPARC platform. Later, we will set the following flag
* to FALSE if current device is not removable media or hotpluggable
* device and if sd works on SAPRC platform.
*/
}
if (!un->un_f_is_hotpluggable &&
#if defined(_SUNOS_VTOC_8)
/*
* Don't support fdisk on fixed disk
*/
#endif
/*
* Fixed disk support SYNC CACHE
*/
/*
* For fixed disk, if its VTOC is not valid, we will write
* errlog into system log
*/
if (un->un_f_vtoc_label_supported)
}
}