scsi_hba.c revision 4f1e984d138bad36944f2e8fea0b9860ac603f61
/*
* 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
*/
/*
*/
/*
* Generic SCSI Host Bus Adapter interface implementation
*/
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
#include <sys/mdi_impldefs.h>
extern int modrootloaded;
/*
* Round up all allocations so that we can guarantee
* long-long alignment. This is the same alignment
* provided by kmem_alloc().
*/
/* Magic number to track correct allocations in wrappers */
/* asynchronous probe barrier deletion data structures */
static kmutex_t scsi_hba_barrier_mutex;
static kcondvar_t scsi_hba_barrier_cv;
static struct scsi_hba_barrier {
struct scsi_hba_barrier *barrier_next;
static void scsi_hba_barrier_daemon(void *arg);
static kmutex_t scsi_lunchg1_mutex;
static kcondvar_t scsi_lunchg1_cv;
static struct scsi_pkt *scsi_lunchg1_list;
static void scsi_lunchg1_daemon(void *arg);
static kmutex_t scsi_lunchg2_mutex;
static kcondvar_t scsi_lunchg2_cv;
static struct scsi_lunchg2 {
struct scsi_lunchg2 *lunchg2_next;
char *lunchg2_path;
static void scsi_lunchg2_daemon(void *arg);
/* return value defines for scsi_findchild */
#define CHILD_TYPE_NONE 0
#define CHILD_TYPE_DEVINFO 1
#define CHILD_TYPE_PATHINFO 2
/*
* Enumeration code path currently being followed. SE_BUSCONFIG results in
* DEVI_SID_NODEID, and SE_HP (hotplug) results in DEVI_SID_HP_NODEID.
*
* Since hotplug enumeration is based on information obtained from hardware
* (tgtmap/report_lun) the type/severity of enumeration error messages is
* sometimes based SE_HP (indirectly via ndi_dev_is_hotplug_node()). By
* convention, these messages are all produced by scsi_enumeration_failed().
*/
/* compatible properties of driver to use during probe/enumeration operations */
static char *compatible_probe = "scsa,probe";
static char *compatible_nodev = "scsa,nodev";
static char *scsi_probe_ascii[] = SCSIPROBE_ASCII;
/* number of LUNs we attempt to get on the first SCMD_REPORT_LUNS command */
int scsi_lunrpt_default_max = 256;
/*
* Only enumerate one lun if reportluns fails on a SCSI_VERSION_3 device
* (tunable based on calling context).
*/
/* 'scsi-binding-set' value for legacy enumerated 'spi' transports */
char *scsi_binding_set_spi = "spi";
/* enable NDI_DEVI_DEBUG for bus_[un]config operations */
int scsi_hba_busconfig_debug = 0;
/* number of probe serilization messages */
int scsi_hba_wait_msg = 5;
/*
* Establish the timeout used to cache (in the probe node) the fact that the
* device does not exist. This replaces the target specific probe cache.
*/
/*
* Structure for scsi_hba_tgtmap_* implementation.
*
* Every call to scsi_hba_tgtmap_set_begin will increment tgtmap_reports,
* and a call to scsi_hba_tgtmap_set_end will reset tgtmap_reports to zero.
* If, in scsi_hba_tgtmap_set_begin, we detect a tgtmap_reports value of
* scsi_hba_tgtmap_reports_max we produce a message to indicate that
* the caller is never completing an observation (i.e. we are not making
* any forward progress). If this message occurs, it indicates that the
* solaris hotplug ramifications at the target and lun level are no longer
* tracking.
*
* NOTE: LUNMAPSIZE OK for now, but should be dynamic in reportlun code.
*/
typedef struct impl_scsi_tgtmap {
int tgtmap_reports; /* _begin without _end */
int tgtmap_noisy;
void *tgtmap_mappriv;
/* Produce warning if number of begins without an end exceed this value */
int scsi_hba_tgtmap_reports_max = 256;
/* Prototype for static dev_ops devo_*() functions */
static int scsi_hba_info(
void *arg,
void **result);
/* Prototypes for static bus_ops bus_*() functions */
static int scsi_hba_bus_ctl(
void *arg,
void *result);
static int scsi_hba_map_fault(
static int scsi_hba_get_eventcookie(
char *name,
static int scsi_hba_add_eventcall(
void (*callback)(
void *arg,
void *bus_impldata),
void *arg,
static int scsi_hba_remove_eventcall(
static int scsi_hba_post_event(
void *bus_impldata);
static int scsi_hba_bus_config(
void *arg,
dev_info_t **childp);
static int scsi_hba_bus_unconfig(
void *arg);
static int scsi_hba_fm_init_child(
int cap,
static int scsi_hba_bus_power(
void *impl_arg,
void *arg,
void *result);
/* bus_ops vector for SCSI HBA's. */
static struct bus_ops scsi_hba_busops = {
nullbusmap, /* bus_map */
NULL, /* bus_get_intrspec */
NULL, /* bus_add_intrspec */
NULL, /* bus_remove_intrspec */
scsi_hba_map_fault, /* bus_map_fault */
ddi_dma_map, /* bus_dma_map */
ddi_dma_allochdl, /* bus_dma_allochdl */
ddi_dma_freehdl, /* bus_dma_freehdl */
ddi_dma_bindhdl, /* bus_dma_bindhdl */
ddi_dma_unbindhdl, /* bus_unbindhdl */
ddi_dma_flush, /* bus_dma_flush */
ddi_dma_win, /* bus_dma_win */
ddi_dma_mctl, /* bus_dma_ctl */
scsi_hba_bus_ctl, /* bus_ctl */
ddi_bus_prop_op, /* bus_prop_op */
scsi_hba_get_eventcookie, /* bus_get_eventcookie */
scsi_hba_add_eventcall, /* bus_add_eventcall */
scsi_hba_remove_eventcall, /* bus_remove_eventcall */
scsi_hba_post_event, /* bus_post_event */
NULL, /* bus_intr_ctl */
scsi_hba_bus_config, /* bus_config */
scsi_hba_bus_unconfig, /* bus_unconfig */
scsi_hba_fm_init_child, /* bus_fm_init */
NULL, /* bus_fm_fini */
NULL, /* bus_fm_access_enter */
NULL, /* bus_fm_access_exit */
scsi_hba_bus_power /* bus_power */
};
/* cb_ops for hotplug :devctl and :scsi support */
static struct cb_ops scsi_hba_cbops = {
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
scsi_hba_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* stream */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
/* Prototypes for static scsi_hba.c/SCSA private lunmap interfaces */
static int scsi_lunmap_create(
char *tgt_addr);
static void scsi_lunmap_destroy(
char *tgt_addr);
static void scsi_lunmap_set_begin(
static int scsi_lunmap_set_add(
char *taddr,
int lun_sfunc);
static void scsi_lunmap_set_end(
/* Prototypes for static misc. scsi_hba.c private bus_config interfaces */
#ifdef sparc
#endif /* sparc */
/*
* SCSI_HBA_LOG is used for all messages. A logging level is specified when
* generating a message. Some levels correspond directly to cmn_err levels,
* some are associated with increasing levels diagnostic/debug output (LOG1-4),
* and others are associated with specific levels of interface (LOGMAP).
* For _LOG() messages, a __func__ prefix will identify the function origin
* of the message. For _LOG_NF messages, there is no function prefix or
* level, but messages with cmn_err logging level and messages generated
* generated with _LOG_NF() are never filtered.
*
* For debugging, more complete information can be displayed with each message
* (full device path and pointer values) by adjusting scsi_hba_log_info.
*/
/* logging levels */
#define SCSI_HBA_LOGCONT CE_CONT
#define SCSI_HBA_LOGNOTE CE_NOTE
#define SCSI_HBA_LOGWARN CE_WARN
#define SCSI_HBA_LOGPANIC CE_PANIC
#define SCSI_HBA_LOGIGNORE CE_IGNORE
#endif
/*
* Tunable log message augmentation and filters: filters do not apply to
* SCSI_HBA_LOG_CE_MASK level messages or LOG_NF() messages.
*
* driver called "pmcs", including "scsi_vhci" operation, by capturing
* log information in the system log might be:
*
*
* To capture information on just HBA-SCSAv3 *map operation, use
*
* For debugging an HBA driver, you may also want to set:
*
*/
0;
char *scsi_hba_log_filter_phci = "\0\0\0\0\0\0\0\0\0\0\0\0";
char *scsi_hba_log_filter_vhci = "\0\0\0\0\0\0\0\0\0\0\0\0";
int scsi_hba_log_align = 0; /* NOTE: will not cause truncation */
/* NOTE: iff level > SCSI_HBA_LOG1 */
/* '\0'0x00 -> console and system log */
/* '^' 0x5e -> console_only */
/* '!' 0x21 -> system log only */
/* '?' 0x2F -> See cmn_err(9F) */
int scsi_hba_log_info = /* augmentation: extra info output */
(0 << 0) | /* 0x0001: process information */
(0 << 1) | /* 0x0002: full /devices path */
(0 << 2); /* 0x0004: devinfo pointer */
int scsi_hba_log_mt_disable =
/* SCSI_ENUMERATION_MT_LUN_DISABLE | (ie 0x02) */
/* SCSI_ENUMERATION_MT_TARGET_DISABLE | (ie 0x04) */
0;
/* static data for HBA logging subsystem */
static kmutex_t scsi_hba_log_mutex;
static char scsi_hba_log_i[512];
static char scsi_hba_log_buf[512];
static char scsi_hba_fmt[512];
/* Macros to use in scsi_hba.c source code below */
#define SCSI_HBA_LOG(x) scsi_hba_log x
/*PRINTFLIKE5*/
static void
const char *fmt, ...)
{
int clevel;
int align;
char *info;
char *f;
char *ua;
/* derive self from child's parent */
/* no filtering of SCSI_HBA_LOG_CE_MASK or LOG_NF messages */
/* scsi_hba_log_filter_level: filter on level as bitmask */
if ((level & scsi_hba_log_filter_level) == 0)
return;
/* scsi_hba_log_filter_phci/vhci: on name of driver */
if (*scsi_hba_log_filter_phci &&
/* does not match pHCI, check vHCI */
if (*scsi_hba_log_filter_vhci &&
/* does not match vHCI */
return;
}
}
/* passed filters, determine align */
/* shorten func for filtered output */
func += 9;
func += 5;
} else {
/* don't align output that is never filtered */
align = 0;
}
/* determine the cmn_err form from the level */
/* protect common buffers used to format output */
/* skip special first characters, we add them back below */
f = (char *)fmt;
if (*f && strchr("^!?", *f))
f++;
/* augment message with 'information' */
*info = '\0';
}
if (self) {
}
if (scsi_hba_log_info & 0x0002) {
}
/* always provide 'default' information about self &child */
if (child) {
}
}
/* turn off alignment if truncation would occur */
align = 0;
/* adjust for aligned output */
if (align) {
func = "";
/* remove trailing blank with align output */
}
/* special "first character in format" must be in format itself */
f = scsi_hba_fmt;
*f++ = fmt[0];
*f++ = (char)scsi_hba_log_fcif; /* add global fcif */
if (align)
else
if (func)
else
}
static int scsi_enumeration_failed_panic = 0;
static int scsi_enumeration_failed_hotplug = 1;
static void
{
/* If 'se' is -1 the 'se' value comes from child. */
if (se == -1) {
}
/* set scsi_enumeration_failed_panic to debug */
"%s%senumeration failed during %s",
/* set scsi_enumeration_failed_hotplug for console messages */
"%s%senumeration failed during %s",
} else {
/* default */
"%s%senumeration failed during %s",
}
}
/*
* scsi_hba version of [nm]di_devi_enter/[nm]di_devi_exit that detects if HBA
*/
static void
{
else
}
static int
{
else
}
static void
{
else
}
static void
{
}
static void
{
}
static int
{
/*
* Use ndi_dev_is_persistent_node instead of ddi_dev_is_sid to avoid
* any possible locking issues in mixed nexus devctl code (like usb).
*/
return (ndi_dev_is_persistent_node(child));
}
/*
* Called from _init() when loading "scsi" module
*/
void
{
/* We need "scsiprobe" and "scsinodev" as an alias or a driver. */
"driver alias, defaulting to 'nulldriver'",
/* If no "nulldriver" driver nothing will work... */
compatible_probe = "nulldriver";
"system misconfigured", compatible_probe));
}
"driver alias, defaulting to 'nulldriver'",
/* If no "nulldriver" driver nothing will work... */
compatible_nodev = "nulldriver";
"system misconfigured", compatible_nodev));
}
/*
* Verify our special node name "probe" will not be used in other ways.
* Don't expect things to work if they are.
*/
"driver already using special node name 'probe'"));
/* initialize the asynchronous barrier deletion daemon */
(void) thread_create(NULL, 0,
(void (*)())scsi_hba_barrier_daemon, NULL,
(void) thread_create(NULL, 0,
(void (*)())scsi_lunchg1_daemon, NULL,
(void) thread_create(NULL, 0,
(void (*)())scsi_lunchg2_daemon, NULL,
}
int
{
struct scsi_pkt_cache_wrapper *pktw;
int pkt_len;
char *ptr;
/*
* allocate a chunk of memory for the following:
* scsi_pkt
* pcw_* fields
* pkt_ha_private
* pkt_cdbp, if needed
* (pkt_private always null)
* pkt_scbp, if needed
*/
ptr += sizeof (struct scsi_pkt_cache_wrapper);
/*
* keep track of the granularity at the time this handle was
* allocated
*/
return (-1);
}
ptr += DEFAULT_CDBLEN;
}
if (tran->tran_pkt_constructor)
else
return (0);
}
void
{
if (tran->tran_pkt_destructor)
/* make sure nobody messed with our pointers */
sizeof (struct scsi_pkt_cache_wrapper)));
tran->tran_hba_len +
0 : DEFAULT_CDBLEN) +
DEFAULT_PRIVLEN + sizeof (struct scsi_pkt_cache_wrapper))));
tran->tran_hba_len +
sizeof (struct scsi_pkt_cache_wrapper))));
pkt->pkt_numcookies = 0;
pktw->pcw_total_xfer = 0;
pktw->pcw_totalwin = 0;
pktw->pcw_curwin = 0;
}
/*
* Called by an HBA from _init() to plumb in common SCSA bus_ops and
* cb_ops for the HBA's :devctl and :scsi minor nodes.
*/
int
{
struct dev_ops *hba_dev_ops;
/*
* Get a pointer to the dev_ops structure of the HBA and plumb our
* bus_ops vector into the HBA's dev_ops structure.
*/
/*
* Plumb our cb_ops vector into the HBA's dev_ops structure to
* provide getinfo and hotplugging ioctl support if the HBA driver
* does not already provide this support.
*/
}
}
return (0);
}
/*
* Called by an HBA attach(9E) to allocate a scsi_hba_tran(9S) structure. An
* HBA driver will then initialize the structure and then call
* scsi_hba_attach_setup(9F).
*/
/*ARGSUSED*/
int flags)
{
/* allocate SCSA flavors for self */
if (tran) {
/*
* HBA driver called scsi_hba_tran_alloc(), so tran structure
*
* NOTE: We use SCSA_HBA_SCSA_TA as an obtuse form of
* versioning to detect old HBA drivers that do not use
* scsi_hba_tran_alloc, and would present garbage data
*/
}
return (tran);
}
/*
* Called by an HBA to free a scsi_hba_tran structure
*/
void
{
}
int
int flags)
{
void *tran_ext;
int ret = DDI_FAILURE;
ret = DDI_SUCCESS;
}
return (ret);
}
void
{
}
}
/*
* Obsolete: Called by an HBA to attach an instance of the driver
* Implement this older interface in terms of the new.
*/
/*ARGSUSED*/
int
int flags,
void *hba_options)
{
}
/*
* Common nexus teardown code: used by both scsi_hba_detach() on SCSA HBA node
* and iport_postdetach_tran_scsi_device() on a SCSA HBA iport node (and for
* failure cleanup). Undo scsa_nexus_setup in reverse order.
*
* NOTE: Since we are in the Solaris IO framework, we can depend on
* undocumented cleanup operations performed by other parts of the framework:
* like detach_node() calling ddi_prop_remove_all() and
* ddi_remove_minor_node(,NULL).
*/
static void
{
/* Teardown FMA. */
}
}
/*
* Common nexus setup code: used by both scsi_hba_attach_setup() on SCSA HBA
* node and iport_preattach_tran_scsi_device() on a SCSA HBA iport node.
*
* This code makes no assumptions about tran use by scsi_device children.
*/
static int
{
int capable;
int scsa_minor;
/*
* NOTE: SCSA maintains an 'fm-capable' domain, in tran_fm_capable,
* that is not dependent (limited by) the capabilities of its parents.
* For example a devinfo node in a branch that is not
* DDI_FM_EREPORT_CAPABLE may report as capable, via tran_fm_capable,
* to its scsi_device children.
*
* Get 'fm-capable' property from driver.conf, if present. If not
* present, default to the scsi_fm_capable global (which has
* DDI_FM_EREPORT_CAPABLE set by default).
*/
"fm-capable", scsi_fm_capable);
/*
* If an HBA is *not* doing its own fma support by calling
* ddi_fm_init() prior to scsi_hba_attach_setup(), we provide a minimal
* common SCSA implementation so that scsi_device children can generate
* ereports via scsi_fm_ereport_post(). We use ddi_fm_capable() to
* detect an HBA calling ddi_fm_init() prior to scsi_hba_attach_setup().
*/
if (tran->tran_fm_capable &&
/*
* We are capable of something, pass our capabilities up the
* tree, but use a local variable so our parent can't limit
* our capabilities (we don't want our parent to clear
* DDI_FM_EREPORT_CAPABLE).
*
* NOTE: iblock cookies are not important because scsi HBAs
* always interrupt below LOCK_LEVEL.
*/
/*
* Set SCSI_HBA_SCSA_FM bit to mark us as using the common
* minimal SCSA fm implementation - we called ddi_fm_init(),
* so we are responsible for calling ddi_fm_fini() in
* scsi_hba_detach().
*
* NOTE: if ddi_fm_init fails to establish handle, SKIP cleanup.
*/
}
/* If SCSA responsible for for minor nodes, create :devctl minor. */
scsi_hba_open) ? 1 : 0;
DDI_SUCCESS))) {
"can't create :devctl minor node"));
goto fail;
}
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* Common tran teardown code: used by iport_postdetach_tran_scsi_device() on a
* SCSA HBA iport node and (possibly) by scsi_hba_detach() on SCSA HBA node
* (and for failure cleanup). Undo scsa_tran_setup in reverse order.
*
* NOTE: Since we are in the Solaris IO framework, we can depend on
* undocumented cleanup operations performed by other parts of the framework:
* like detach_node() calling ddi_prop_remove_all() and
* ddi_remove_minor_node(,NULL).
*/
static void
{
/* Teardown pHCI registration */
(void) mdi_phci_unregister(self, 0);
}
}
/*
* Common tran setup code: used by iport_preattach_tran_scsi_device() on a
* SCSA HBA iport node and (possibly) by scsi_hba_attach_setup() on SCSA HBA
* node.
*/
static int
{
int scsa_minor;
int id;
char *scsi_binding_set;
static const char *interconnect[] = INTERCONNECT_TYPE_ASCII;
/* If SCSA responsible for for minor nodes, create ":scsi" */
scsi_hba_open) ? 1 : 0;
DDI_NT_SCSI_ATTACHMENT_POINT, 0) != DDI_SUCCESS)) {
"can't create :scsi minor node"));
goto fail;
}
/*
* If the property does not already exist on self then see if we can
* pull it from further up the tree and define it on self. If the
* property does not exist above (including options.conf) then use the
* default value specified (global variable). We pull things down from
* above for faster "DDI_PROP_NOTPROM | DDI_PROP_DONTPASS" runtime
* access.
*
* Future: Should we avoid creating properties when value == global?
*/
#define CONFIG_INT_PROP(s, p, dv) { \
if ((ddi_prop_exists(DDI_DEV_T_ANY, s, \
DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, p) == 0) && \
(ndi_prop_update_int(DDI_DEV_T_NONE, s, p, \
"can't create property '%s'", p)); \
}
/* Decorate with scsi configuration properties */
/*
* Pull down the scsi-initiator-id from further up the tree, or as
* defined by OBP. Place on node for faster access. NOTE: there is
* some confusion about what the name of the property should be.
*/
if (id == -1)
"scsi-initiator-id", -1);
if (id != -1)
/*
* If we are responsible for tran allocation, establish
* 'initiator-interconnect-type'.
*/
(tran->tran_interconnect_type > 0) &&
"initiator-interconnect-type",
!= DDI_PROP_SUCCESS) {
"failed to establish "
"'initiator-interconnect-type'"));
goto fail;
}
}
/*
* The 'scsi-binding-set' property can be defined in driver.conf
* files of legacy drivers on an as-needed basis. If 'scsi-binding-set'
* is not driver.conf defined, and the HBA is not implementing its own
* private bus_config, we define scsi-binding-set to the default
* 'spi' legacy value.
*
* NOTE: This default 'spi' value will be deleted if an HBA driver
* ends up using the scsi_hba_tgtmap_create() enumeration services.
*
* NOTE: If we were ever to decide to derive 'scsi-binding-set' from
* the IEEE-1275 'device_type' property then this is where that code
* should go - there is not enough consistency in 'device_type' to do
* this correctly at this point in time.
*/
&scsi_binding_set) == DDI_PROP_SUCCESS) {
"external 'scsi-binding-set' \"%s\"", scsi_binding_set));
} else if (scsi_binding_set_spi &&
"scsi-binding-set", scsi_binding_set_spi) !=
"failed to establish 'scsi_binding_set' default"));
goto fail;
}
"default 'scsi-binding-set' \"%s\"", scsi_binding_set_spi));
} else
"no 'scsi-binding-set'"));
/*
* If SCSI_HBA_TRAN_PHCI is set, take care of pHCI registration of the
* initiator.
*/
/* NOTE: tran_hba_dip is for DMA operation at the HBA node level */
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* Called by a SCSA HBA driver to attach an instance of the driver to
* SCSA HBA node enumerated by PCI.
*/
int
int flags)
{
int len;
char cache_name[96];
/*
* Verify that we are a driver so other code does not need to
* check for NULL ddi_get_driver() result.
*/
return (DDI_FAILURE);
/*
* Verify that we are called on a SCSA HBA node (function enumerated
* by PCI), not on an iport node.
*/
return (DDI_FAILURE); /* self can't be an iport */
/* Caller must provide the tran. */
return (DDI_FAILURE);
/*
* Verify correct scsi_hba_tran_t form:
*
* o Both or none of tran_get_name/tran_get_addr.
* NOTE: Older SCSA HBA drivers for SCSI transports with addressing
* that did not fit the SPI "struct scsi_address" model were required
* to implement tran_get_name and tran_get_addr. This is no longer
* true - modern transport drivers should now use common SCSA
* enumeration services. The SCSA enumeration code will represent
* the unit-address using well-known address properties
* (SCSI_ADDR_PROP_TARGET_PORT, SCSI_ADDR_PROP_LUN64) during
* using scsi_device_prop_lookup_*() from its tran_tgt_init(9E).
*
*/
"should support both or neither: "
"tran_get_name, tran_get_bus_addr"));
return (DDI_FAILURE);
}
/*
* Establish the devinfo context of this tran structure, preserving
* knowledge of how the tran was allocated.
*/
/* Establish flavor of transport (and ddi_get_driver_private()) */
/*
* Note: We only need dma_attr_minxfer and dma_attr_burstsizes
* from the DMA attributes. scsi_hba_attach(9f) only guarantees
* that these two fields are initialized properly. If this
* changes, be sure to revisit the implementation of
* scsi_hba_attach(9F).
*/
sizeof (ddi_dma_attr_t));
/* Create tran_setup_pkt(9E) kmem_cache. */
if (tran->tran_setup_pkt) {
goto fail;
len = sizeof (struct scsi_pkt_cache_wrapper);
}
/* Perform node setup independent of initiator role */
goto fail;
/*
* The SCSI_HBA_HBA flag is passed to scsi_hba_attach_setup when the
* HBA driver knows that *all* children of the SCSA HBA node will be
* 'iports'. If the SCSA HBA node can have iport children and also
* function as an initiator for xxx_device children then it should
* not specify SCSI_HBA_HBA in its scsi_hba_attach_setup call. An
* HBA driver that does not manage iports should not set SCSA_HBA_HBA.
*/
/*
* Set the 'ddi-config-driver-node' property on the nexus
* node that notify attach_driver_nodes() to configure all
* immediate children so that nodes which bind to the
* same driver as parent are able to be added into per-driver
* list.
*/
goto fail;
} else {
goto fail;
}
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* Called by an HBA to detach an instance of the driver. This may be called
* for SCSA HBA nodes and for SCSA iport nodes.
*/
int
{
return (DDI_FAILURE); /* self can't be an iport */
/* Check all error return conditions upfront */
return (DDI_FAILURE);
if (tran->tran_open_flag)
return (DDI_FAILURE);
/* Teardown tran_setup_pkt(9E) kmem_cache. */
if (tran->tran_pkt_cache_ptr) {
}
/* Teardown flavor of transport (and ddi_get_driver_private()) */
return (DDI_SUCCESS);
}
/*
* Called by an HBA from _fini()
*/
void
{
struct dev_ops *hba_dev_ops;
/* Get the devops structure of this module and clear bus_ops vector. */
}
/*
* SAS specific functions
*/
{
/* allocate SCSA flavors for self */
}
void
{
}
int
{
return (DDI_FAILURE); /* self can't be an iport */
/*
* The owner of the this devinfo_t was responsible
* for informing the framework already about
* additional flavors.
*/
return (DDI_SUCCESS);
}
int
{
return (DDI_FAILURE); /* self can't be an iport */
return (DDI_SUCCESS);
}
/*
* SMP child flavored functions
*/
static int
{
char *tport;
char *wwn;
/* limit ndi_devi_findchild_by_callback to expected flavor */
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*
* NOTE: the following code should be deleted when mpt is changed to
* use SCSI_ADDR_PROP_TARGET_PORT instead of SMP_WWN.
*/
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
static int
{
char *tport;
char *wwn;
return (DDI_SUCCESS);
}
/*
* NOTE: the following code should be deleted when mpt is changed to
* use SCSI_ADDR_PROP_TARGET_PORT instead of SMP_WWN.
*/
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
static int
{
char addr[SCSI_MAXNAMELEN];
struct smp_device *smp_sd;
return (DDI_FAILURE);
return (DDI_NOT_WELL_FORMED);
return (DDI_NOT_WELL_FORMED);
/* Prevent duplicate nodes. */
if (dup) {
"init failed: %s@%s: not SMP flavored",
return (DDI_FAILURE);
}
"init failed: %s@%s: detected duplicate %p",
return (DDI_FAILURE);
}
}
/* set the node @addr string */
/* Allocate and initialize smp_device. */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (DDI_FAILURE);
if (tran->smp_tran_free)
return (DDI_SUCCESS);
}
/* Find an "smp" child at the specified address. */
static dev_info_t *
{
/* Search "smp" devinfo child at specified address. */
/* skip non-"smp" nodes */
continue;
/* Attempt initchild to establish unit-address */
/* Verify state and non-NULL unit-address. */
continue;
/* Return "smp" child if unit-address matches. */
return (child);
}
return (NULL);
}
/*
* Search for "smp" child of self at the specified address. If found, online
* and return with a hold. Unlike general SCSI configuration, we can assume
* the the device is actually there when we are called (i.e., device is
* created by hotplug, not by bus_config).
*/
int
{
int circ;
/* Search for "smp" child. */
return (NDI_FAILURE);
}
/* Attempt online. */
return (NDI_FAILURE);
}
/* On success, return with active hold. */
return (NDI_SUCCESS);
}
/* Create "smp" child devinfo node at specified unit-address. */
int
{
int circ;
/*
* NOTE: If we ever uses a generic node name (.vs. a driver name)
* or define a 'compatible' property, this code will need to use
* a 'probe' node (ala scsi_device support) to obtain identity
* information from the device.
*/
/* Search for "smp" child. */
if (child) {
/* Child exists, note if this was a new reinsert. */
if (ndi_devi_device_insert(child))
"devinfo smp@%s device_reinsert", addr));
return (NDI_SUCCESS);
}
/* Allocate "smp" child devinfo node and establish flavor of child. */
/* Add unit-address property to child. */
(void) ndi_devi_free(child);
return (NDI_FAILURE);
}
/* Attempt to online the new "smp" node. */
(void) ndi_devi_online(child, 0);
return (NDI_SUCCESS);
}
/*
* Wrapper to scsi_ua_get which takes a devinfo argument instead of a
* scsi_device structure.
*/
static int
{
struct scsi_device *sd;
/* limit ndi_devi_findchild_by_callback to expected flavor */
return (DDI_FAILURE);
/* nodes are named by tran_get_name or default "tgt,lun" */
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
static int
{
char ua[SCSI_MAXNAMELEN];
char ra[SCSI_MAXNAMELEN];
return (DDI_FAILURE);
/* get the unit_address and bus_addr information */
return (DDI_FAILURE);
}
else if (*ra)
"?%s%d at %s%d: unit-address %s: %s",
else
"?%s%d at %s%d: unit-address %s",
return (DDI_SUCCESS);
}
/*
* scsi_busctl_initchild is called to initialize the SCSA transport for
* communication with a particular child scsi target device. Successful
* initialization requires properties on the node which describe the address
* of the target device. If the address of the target device can't be
* determined from properties then DDI_NOT_WELL_FORMED is returned. Nodes that
* are DDI_NOT_WELL_FORMED are considered an implementation artifact and
* are hidden from devinfo snapshots by calling ndi_devi_set_hidden().
* The child may be one of the following types of devinfo nodes:
*
* OBP node:
* OBP does not enumerate target devices attached a SCSI bus. These
* driver loading methods. Since they have no properties,
* DDI_NOT_WELL_FORMED will be returned.
*
* SID node:
* The node may be either a:
* o a dynamic SID target node
*
* driver.conf node: The situation for this nexus is different than most.
* Typically a driver.conf node definition is used to either define a
* new child devinfo node or to further decorate (via merge) a SID
* child with properties. In our case we use the nodes for *both*
* purposes.
*
* In both the SID node and driver.conf node cases we must form the nodes
* "@addr" from the well-known scsi(9P) device unit-address properties on
* the node.
*
* For HBA drivers that implement the deprecated tran_get_name interface,
* "@addr" construction involves having that driver interpret properties via
* scsi_busctl_ua -> scsi_ua_get -> tran_get_name: there is no
* requirement for the property names to be well-known.
*
* NOTE: We don't currently support "merge". When this support is added a
* specific property, like "unit-address", should *always* identify a
* driver.conf node that needs to be merged into a specific SID node. When
* enumeration is enabled, a .conf node without the "unit-address" property
* should be ignored. The best way to establish the "unit-address" property
* would be to have the system assign parent= and unit-address= from an
* instance=# driver.conf entry (by using the instance tree).
*/
static int
{
struct scsi_device *sd;
char *class;
int tgt;
int lun;
int sfunc;
int err = DDI_FAILURE;
char addr[SCSI_MAXNAMELEN];
/*
* For a driver like fp with multiple upper-layer-protocols
* it is possible for scsi_hba_init in _init to plumb SCSA
* and have the load of fcp (which does scsi_hba_attach_setup)
* to fail. In this case we may get here with a NULL hba.
*/
return (DDI_NOT_WELL_FORMED);
/*
* loading methods. These nodes have no properties, so we lack the
* addressing properties to initchild them. Hide the node and return
* DDI_NOT_WELL_FORMED.
*
*
* NOTE: It would be nice if we could delete these ill formed nodes by
* implementing a DDI_NOT_WELL_FORMED_DELETE return code. This can't
* be done until leadville debug code removes its dependencies
* on the devinfo still being present after a failed ndi_devi_online.
*/
"init failed: no properties"));
return (DDI_NOT_WELL_FORMED);
}
/* get legacy SPI addressing properties */
tgt = 0;
/*
* A driver.conf node for merging always has a target= property,
* even if it is just a dummy that does not contain the real
* target address. However drivers that register devids may
* create stub driver.conf nodes without a target= property so
* that pathological devid resolution works. Hide the stub
* node and return DDI_NOT_WELL_FORMED.
*/
if (!scsi_hba_dev_is_sid(child)) {
"init failed: stub .conf node"));
return (DDI_NOT_WELL_FORMED);
}
}
/*
* The scsi_address structure may not specify all the addressing
* information. For an old HBA that doesn't support tran_get_name
* (most pre-SCSI-3 HBAs) the scsi_address structure is still used,
* so the target property must exist and the LUN must be < 256.
*/
return (DDI_NOT_WELL_FORMED);
}
/*
* We need to initialize a fair amount of our environment to invoke
* tran_get_name (via scsi_busctl_ua and scsi_ua_get) to
* produce the "@addr" name from addressing properties. Allocate and
* initialize scsi device structure.
*/
sd->sd_uninit_prevent = 0;
/*
* For a SCSI_HBA_ADDR_COMPLEX transport we store a pointer to
* scsi_device in the scsi_address structure. This allows an
* HBA driver to find its per-scsi_device private data
* (accessible to the HBA given just the scsi_address by using
* scsi_address_device(9F)/scsi_device_hba_private_get(9F)).
*/
tran_clone = NULL;
} else {
/*
* Initialize the scsi_address so that a SCSI-2 target driver
* talking to a SCSI-2 device on a SCSI-3 bus (spi) continues
* to work. We skew the secondary function value so that we
* can tell from the address structure if we are processing
* a secondary function request.
*/
if (sfunc == -1)
else
/*
* NOTE: Don't limit LUNs to scsi_options value because a
* scsi_device discovered via SPI dynamic enumeration might
* still support SCMD_REPORT_LUNS.
*/
/*
* Deprecated: Use SCSI_HBA_ADDR_COMPLEX:
* Clone transport structure if requested. Cloning allows
* an HBA to maintain target-specific information if
* necessary, such as target addressing information that
* does not adhere to the scsi_address structure format.
*/
sizeof (scsi_hba_tran_t), KM_SLEEP);
tran = tran_clone;
} else {
tran_clone = NULL;
}
}
/* establish scsi_address pointer to the HBA's tran structure */
/*
* This is a grotty hack that allows direct-access (non-scsa) drivers
* (like chs, ata, and mlx which all make cmdk children) to put its
* own vector in the 'a_hba_tran' field. When all the drivers that do
* this are fixed, please remove this hack.
*
* NOTE: This hack is also shows up in the DEVP_TO_TRAN implementation
* in scsi_confsubr.c.
*/
/*
* If the class property is not already established, set it to "scsi".
* This is done so that parent= driver.conf nodes have class.
*/
&class) == DDI_PROP_SUCCESS) {
goto failure;
}
/* Establish the @addr name of the child. */
*addr = '\0';
/*
* Some driver.conf files add bogus target properties (relative
* to their nexus representation of target) to their stub
* nodes, causing the check above to not filter them.
*/
"init failed: scsi_busctl_ua call"));
goto failure;
}
if (*addr == '\0') {
goto failure;
}
/* Prevent duplicate nodes. */
if (dup) {
"init failed: %s@%s: not SCSI_DEVICE flavored",
goto failure;
}
"init failed: %s@%s: detected duplicate %p",
goto failure;
}
}
/* set the node @addr string */
/* call HBA's target init entry point if it exists */
sd->sd_tran_tgt_free_done = 0;
if ((*tran->tran_tgt_init)
"tran_tgt_init");
goto failure;
}
}
return (DDI_SUCCESS);
if (tran_clone)
return (err); /* remove the node */
}
static int
{
return (DDI_FAILURE);
/*
* attached we can't prevent their state demotion via ndi_hold_devi.
*/
if (sd->sd_uninit_prevent) {
return (DDI_FAILURE);
}
/*
* Don't uninitialize a client node if it still has paths.
*/
"uninit prevented, client has paths"));
return (DDI_FAILURE);
}
/* ... grotty hack, involving sd_tran_safe, continued. */
#ifdef DEBUG
/*
* Complain so things get fixed and hack can, at
* some point in time, be removed.
*/
#endif /* DEBUG */
}
tran = tran_clone;
} else {
tran_clone = NULL;
}
/*
* To simplify host adapter drivers we guarantee that multiple
* tran_tgt_init(9E) calls of the same unit address are never
* active at the same time. This requires that we always call
* uninitchild.
*
* NOTE: To correctly support SCSI_HBA_TRAN_CLONE, we must use
* the (possibly cloned) hba_tran pointer from the scsi_device
* instead of hba_tran.
*/
if (tran->tran_tgt_free) {
if (!sd->sd_tran_tgt_free_done) {
"uninit tran_tgt_free"));
} else {
"uninit tran_tgt_free already done"));
}
}
/*
* If a inquiry data is still allocated (by scsi_probe()) we
* free the allocation here. This keeps scsi_inq valid for the
* same duration as the corresponding inquiry properties. It
* also allows a tran_tgt_init() implementation that establishes
* sd_inq to deal with deallocation in its tran_tgt_free
* (setting sd_inq back to NULL) without upsetting the
* framework. Moving the inquiry free here also allows setting
* of sd_uninit_prevent to preserve the data for lun0 based
* scsi_get_device_type_scsi_options() calls.
*/
}
if (tran_clone)
return (DDI_SUCCESS);
}
static int
{
char *iport_ua;
/* limit ndi_devi_findchild_by_callback to expected flavor */
return (DDI_FAILURE);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
{
char *iport_ua;
char *initiator_port = NULL;
return (DDI_FAILURE);
if (initiator_port) {
"?%s%d at %s%d: %s %s %s %s",
} else {
}
return (DDI_SUCCESS);
}
/* initchild SCSA iport 'child' node */
static int
{
char addr[SCSI_MAXNAMELEN];
return (DDI_NOT_WELL_FORMED);
/* Prevent duplicate nodes. */
if (dup) {
"init failed: %s@%s: not IPORT flavored",
return (DDI_FAILURE);
}
"init failed: %s@%s: detected duplicate %p",
return (DDI_FAILURE);
}
}
/* set the node @addr string */
return (DDI_SUCCESS);
}
/* uninitchild SCSA iport 'child' node */
static int
{
return (DDI_SUCCESS);
}
/* Uninitialize scsi_device flavor of transport on SCSA iport 'child' node. */
static void
{
return;
}
/* Initialize scsi_device flavor of transport on SCSA iport 'child' node. */
static void
{
/* parent HBA node scsi_device tran is required */
/* Allocate iport child's scsi_device transport vector */
/* Structure-copy scsi_device transport of HBA to iport. */
/*
* Reset scsi_device transport fields not shared with the
* parent, and not established below.
*/
tran->tran_open_flag = 0;
/* Establish the devinfo context of this tran structure. */
/* Clear SCSI_HBA_SCSA flags (except TA) */
tran->tran_hba_flags &=
/* Establish flavor of transport (and ddi_get_driver_private()) */
/* Setup iport node */
}
/* Uninitialize smp_device flavor of transport on SCSA iport 'child' node. */
static void
{
return;
}
/* Initialize smp_device flavor of transport on SCSA iport 'child' node. */
static void
{
/* parent HBA node smp_device tran is optional */
return;
}
/* Allocate iport child's smp_device transport vector */
/* Structure-copy smp_device transport of HBA to iport. */
/* Establish flavor of transport */
}
/*
* Generic bus_ctl operations for SCSI HBA's,
* hiding the busctl interface from the HBA.
*/
/*ARGSUSED*/
static int
void *arg,
void *result)
{
int child_flavor = 0;
int val;
struct attachspec *as;
struct detachspec *ds;
/* For some ops, child is 'arg'. */
/* Determine the flavor of the child: scsi, smp, iport */
switch (op) {
case DDI_CTLOPS_INITCHILD:
switch (child_flavor) {
case SCSA_FLAVOR_SCSI_DEVICE:
return (scsi_busctl_initchild(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_initchild(child));
case SCSA_FLAVOR_IPORT:
return (iport_busctl_initchild(child));
default:
return (DDI_FAILURE);
}
/* NOTREACHED */
case DDI_CTLOPS_UNINITCHILD:
switch (child_flavor) {
case SCSA_FLAVOR_SCSI_DEVICE:
return (scsi_busctl_uninitchild(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_uninitchild(child));
case SCSA_FLAVOR_IPORT:
return (iport_busctl_uninitchild(child));
default:
return (DDI_FAILURE);
}
/* NOTREACHED */
case DDI_CTLOPS_REPORTDEV:
switch (child_flavor) {
case SCSA_FLAVOR_SCSI_DEVICE:
return (scsi_busctl_reportdev(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_reportdev(child));
case SCSA_FLAVOR_IPORT:
return (iport_busctl_reportdev(child));
default:
return (DDI_FAILURE);
}
/* NOTREACHED */
case DDI_CTLOPS_ATTACH:
if (child_flavor != SCSA_FLAVOR_IPORT)
return (DDI_SUCCESS);
/* iport processing */
/* setup pre attach(9E) */
/* cleanup if attach(9E) failed */
}
return (DDI_SUCCESS);
case DDI_CTLOPS_DETACH:
if (child_flavor != SCSA_FLAVOR_IPORT)
return (DDI_SUCCESS);
/* iport processing */
/* cleanup if detach(9E) was successful */
}
return (DDI_SUCCESS);
case DDI_CTLOPS_IOMIN:
return (DDI_FAILURE);
/*
* The 'arg' value of nonzero indicates 'streaming'
* mode. If in streaming mode, pick the largest
* of our burstsizes available and say that that
* is our minimum value (modulo what minxfer is).
*/
case DDI_CTLOPS_SIDDEV:
return (ndi_dev_is_persistent_node(child) ?
case DDI_CTLOPS_POWER:
return (DDI_SUCCESS);
/*
* These ops correspond to functions that "shouldn't" be called
* by a SCSI target driver. So we whine when we're called.
*/
case DDI_CTLOPS_DMAPMAPC:
case DDI_CTLOPS_REPORTINT:
case DDI_CTLOPS_REGSIZE:
case DDI_CTLOPS_NREGS:
case DDI_CTLOPS_SLAVEONLY:
case DDI_CTLOPS_AFFINITY:
case DDI_CTLOPS_POKE:
case DDI_CTLOPS_PEEK:
return (DDI_FAILURE);
/* Everything else we pass up */
case DDI_CTLOPS_PTOB:
case DDI_CTLOPS_BTOP:
case DDI_CTLOPS_BTOPR:
case DDI_CTLOPS_DVMAPAGESIZE:
default:
}
/* NOTREACHED */
}
/*
* Private wrapper for scsi_pkt's allocated via scsi_hba_pkt_alloc()
*/
struct scsi_pkt_wrapper {
int pkt_wrapper_magic;
int pkt_wrapper_len;
};
#if !defined(lint)
#endif
/*
* Called by an HBA to allocate a scsi_pkt
*/
/*ARGSUSED*/
struct scsi_pkt *
struct scsi_address *ap,
int cmdlen,
int statuslen,
int tgtlen,
int hbalen,
{
struct scsi_pkt_wrapper *hba_pkt;
caddr_t p;
int pktlen;
/* Sanity check */
"callback must be SLEEP_FUNC or NULL_FUNC"));
/*
* Round up so everything gets allocated on long-word boundaries
*/
pktlen = sizeof (struct scsi_pkt_wrapper) +
return (NULL);
}
/*
* Set up our private info on this pkt
*/
/*
* Set up pointers to private data areas, cdb, and status.
*/
if (hbalen > 0) {
p += ahbalen;
}
if (tgtlen > 0) {
p += atgtlen;
}
if (statuslen > 0) {
p += astatuslen;
}
if (cmdlen > 0) {
}
/*
* Initialize the pkt's scsi_address
*/
/*
* NB: It may not be safe for drivers, esp target drivers, to depend
* on the following fields being set until all the scsi_pkt
* allocation violations discussed in scsi_pkt.h are all resolved.
*/
return (pkt);
}
/*
* Called by an HBA to free a scsi_pkt
*/
/*ARGSUSED*/
void
struct scsi_address *ap,
{
}
/*
* Return 1 if the scsi_pkt used a proper allocator.
*
* The DDI does not allow a driver to allocate it's own scsi_pkt(9S), a
* driver should not have *any* compiled in dependencies on "sizeof (struct
* scsi_pkt)". While this has been the case for many years, a number of
* drivers have still not been fixed. This function can be used to detect
* improperly allocated scsi_pkt structures, and produce messages identifying
* drivers that need to be fixed.
*
* While drivers in violation are being fixed, this function can also
* be used by the framework to detect packets that violated allocation
* rules.
*
* NB: It is possible, but very unlikely, for this code to return a false
* positive (finding correct magic, but for wrong reasons). Careful
* consideration is needed for callers using this interface to condition
* access to newer scsi_pkt fields (those after pkt_reason).
*
* NB: As an aid to minimizing the amount of work involved in 'fixing' legacy
* drivers that violate scsi_*(9S) allocation rules, private
* scsi_pkt_size()/scsi_size_clean() functions are available (see their
* implementation for details).
*
* *** Non-legacy use of scsi_pkt_size() is discouraged. ***
*
* NB: When supporting broken HBA drivers is not longer a concern, this
* code should be removed.
*/
int
{
int magic;
#ifdef DEBUG
/*
* We are getting scsi packets from two 'correct' wrapper schemes,
* make sure we are looking at the same place in both to detect
* proper allocation.
*/
#endif /* DEBUG */
/*
* Check to see if driver is scsi_size_clean(), assume it
* is using the scsi_pkt_size() interface everywhere it needs to
* if the driver indicates it is scsi_size_clean().
*/
return (1); /* ok */
/*
* Special case crossing a page boundary. If the scsi_pkt was not
* allocated correctly, then across a page boundary we have a
* fault hazard.
*/
/* fastpath, no cross-page hazard */
} else {
/* add protection for cross-page hazard */
return (0); /* violation */
}
}
/* properly allocated packet always has correct magic */
}
/*
* Private interfaces to simplify conversion of legacy drivers so they don't
* depend on scsi_*(9S) size. Instead of using these private interface, HBA
* drivers should use DDI sanctioned allocation methods:
*
* scsi_pkt Use scsi_hba_pkt_alloc(9F), or implement
* tran_setup_pkt(9E).
*
* structure should only be allocated by scsi_hba.c
* initchild code or scsi_vhci.c code.
*
* scsi_hba_tran Use scsi_hba_tran_alloc(9F).
*/
{
return (sizeof (struct scsi_pkt));
}
{
return (sizeof (scsi_hba_tran_t));
}
{
return (sizeof (struct scsi_device));
}
/*
* Legacy compliance to scsi_pkt(9S) allocation rules through use of
* scsi_pkt_size() is detected by the 'scsi-size-clean' driver.conf property
* or an HBA driver calling to scsi_size_clean() from attach(9E). A driver
* developer should only indicate that a legacy driver is clean after using
* SCSI_SIZE_CLEAN_VERIFY to ensure compliance (see scsi_pkt.h).
*/
void
{
"scsi_pkt_size: bogus major: %d", major));
return;
}
/* Set DN_SCSI_SIZE_CLEAN flag in dn_flags. */
}
}
/*
* Called by an HBA to map strings to capability indices
*/
int
char *capstr)
{
/*
* Capability strings: only add entries to mask the legacy
* '_' vs. '-' misery. All new capabilities should use '-',
* and be captured be added to SCSI_CAP_ASCII.
*/
static struct cap_strings {
char *cap_string;
int cap_index;
} cap_strings[] = {
{ "dma_max", SCSI_CAP_DMA_MAX },
{ "msg_out", SCSI_CAP_MSG_OUT },
{ "wide_xfer", SCSI_CAP_WIDE_XFER },
{ NULL, 0 }
};
static char *cap_ascii[] = SCSI_CAP_ASCII;
char **cap;
int i;
struct cap_strings *cp;
return (i);
return (-1);
}
/*
* Called by an HBA to determine if the system is in 'panic' state.
*/
int
{
}
/*
* If a SCSI target driver attempts to mmap memory,
* the buck stops here.
*/
/*ARGSUSED*/
static int
{
return (DDI_FAILURE);
}
static int
char *name,
{
if (tran->tran_get_eventcookie &&
return (DDI_SUCCESS);
}
}
static int
void (*callback)(
void *arg,
void *bus_impldata),
void *arg,
{
if (tran->tran_add_eventcall &&
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
static int
{
if (tran->tran_remove_eventcall &&
((*tran->tran_remove_eventcall)(
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
static int
void *bus_impldata)
{
if (tran->tran_post_event &&
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*
* Default getinfo(9e) for scsi_hba
*/
/* ARGSUSED */
static int
void **result)
{
int error = DDI_SUCCESS;
switch (infocmd) {
case DDI_INFO_DEVT2INSTANCE:
break;
default:
error = DDI_FAILURE;
}
return (error);
}
/*
* Default open and close routine for scsi_hba
*/
/* ARGSUSED */
int
{
int rv = 0;
return (EINVAL);
return (ENXIO);
return (ENXIO);
}
/*
* tran_open_flag bit field:
* 0: closed
* 1: shared open by minor at bit position
* 1 at 31st bit: exclusive open
*/
if (tran->tran_open_flag != 0) {
} else {
}
} else {
} else {
/*
* Ensure that the last framework reserved minor
* is unused. Otherwise, the exclusive open
* mechanism may break.
*/
}
}
return (rv);
}
/* ARGSUSED */
int
{
return (EINVAL);
return (ENXIO);
return (ENXIO);
}
tran->tran_open_flag = 0;
} else {
}
return (0);
}
/*
* standard ioctl commands for SCSI hotplugging
*/
/* ARGSUSED */
int
int *rvalp)
{
struct scsi_device *sd;
int rv = 0;
int circ;
char *name;
char *addr;
goto out;
}
goto out;
}
/* Ioctls for which the generic implementation suffices. */
switch (cmd) {
case DEVCTL_BUS_GETSTATE:
goto out;
}
/* read devctl ioctl data */
goto out;
}
/* Ioctls that require child identification */
switch (cmd) {
case DEVCTL_DEVICE_GETSTATE:
case DEVCTL_DEVICE_ONLINE:
case DEVCTL_DEVICE_OFFLINE:
case DEVCTL_DEVICE_REMOVE:
case DEVCTL_DEVICE_RESET:
goto out;
}
/*
* Find child with name@addr - might find a devinfo
* child (child), a pathinfo child (path), or nothing.
*/
if (path) {
/* Found a pathinfo */
} else if (child) {
/* Found a devinfo */
/* verify scsi_device of child */
else
} else {
goto out;
}
break;
case DEVCTL_BUS_RESETALL: /* ioctl that operate on any child */
/*
* Find a child's scsi_address so we can invoke tran_reset.
*
* Future: If no child exists, we could fake a child. This will
* be a enhancement for the future - for now, we fall back to
* BUS_RESET.
*/
while (child) {
/* verify scsi_device of child */
/*
* NOTE: node has a scsi_device structure, so
* it must be initialized.
*/
break;
}
}
break;
}
switch (cmd) {
case DEVCTL_DEVICE_GETSTATE:
if (path) {
} else if (child) {
} else {
}
break;
case DEVCTL_DEVICE_RESET:
break;
}
break;
}
/* Start with the small stick */
break; /* LUN reset worked */
break;
case DEVCTL_BUS_QUIESCE:
(bus_state == BUS_QUIESCED))
break;
case DEVCTL_BUS_UNQUIESCE:
(bus_state == BUS_ACTIVE))
break;
case DEVCTL_BUS_RESET:
break;
case DEVCTL_BUS_RESETALL:
break; /* reset all worked */
}
break;
}
break;
case DEVCTL_BUS_CONFIGURE:
NDI_CONFIG_REPROBE) != NDI_SUCCESS) {
}
break;
case DEVCTL_BUS_UNCONFIGURE:
if (ndi_devi_unconfig(self,
}
break;
case DEVCTL_DEVICE_ONLINE:
if (path) {
} else {
}
break;
case DEVCTL_DEVICE_OFFLINE:
if (path) {
} else {
if (ndi_devi_offline(child,
}
break;
case DEVCTL_DEVICE_REMOVE:
if (path) {
/* NOTE: don't pass NDI_DEVI_REMOVE to mdi_pi_offline */
/* ... here is the DEVICE_REMOVE part. */
(void) mdi_pi_free(path, 0);
} else {
}
} else {
if (ndi_devi_offline(child,
}
break;
default:
break;
}
/* all done -- clean up and return */
out:
/* release hold on what we found */
if (path) {
}
if (dcp)
if (self)
return (rv);
}
/*ARGSUSED*/
static int
{
}
static int
{
}
}
/*
* Return the lun64 value from a address string: "addr,lun[,sfunc]". Either
* the lun is after the first ',' or the entire address string is the lun.
* Return SCSI_LUN64_ILLEGAL if the format is incorrect. A lun64 is at most
* 16 hex digits long.
*
* If the address string specified has incorrect syntax (busconfig one of
* bogus /devices path) then scsi_addr_to_lun64 can return SCSI_LUN64_ILLEGAL.
*/
static scsi_lun64_t
scsi_addr_to_lun64(char *addr)
{
char *s;
int i;
if (addr) {
if (s)
s++; /* skip ',', at lun */
else
s = addr; /* "lun" */
for (lun64 = 0, i = 0; *s && (i < 16); s++, i++) {
if (*s >= '0' && *s <= '9')
else if (*s >= 'A' && *s <= 'F')
else if (*s >= 'a' && *s <= 'f')
else
break;
}
if (*s && (*s != ',')) /* [,sfunc] is OK */
} else
if (lun64 == SCSI_LUN64_ILLEGAL)
"addr_to_lun64 %s lun %" PRIlun64,
return (lun64);
}
/*
* Return the sfunc value from a address string: "addr,lun[,sfunc]". Either the
* sfunc is after the second ',' or the entire address string is the sfunc.
* Return -1 if there is only one ',' in the address string or the string is
* invalid. An sfunc is at most two hex digits long.
*/
static int
scsi_addr_to_sfunc(char *addr)
{
int sfunc;
char *s;
int i;
if (addr) {
if (s) {
s++; /* skip ',', at lun */
if (s == NULL)
return (-1); /* no ",sfunc" */
s++; /* skip ',', at sfunc */
} else
s = addr; /* "sfunc" */
for (sfunc = 0, i = 0; *s && (i < 2); s++, i++) {
if (*s >= '0' && *s <= '9')
else if (*s >= 'A' && *s <= 'F')
else if (*s >= 'a' && *s <= 'f')
else
break;
}
if (*s)
} else
sfunc = -1;
return (sfunc);
}
/*
* Convert scsi ascii string data to NULL terminated (semi) legal IEEE 1275
* "compatible" (name) property form.
*
* For ASCII INQUIRY data, a one-way conversion algorithm is needed to take
* SCSI_ASCII (20h - 7Eh) to a 1275-like compatible form. The 1275 spec allows
* letters, digits, one ",", and ". _ + -", all limited by a maximum 31
* character length. Since ", ." are used as separators in the compatible
* string itself, they are converted to "_". All SCSI_ASCII characters that
* are illegal in 1275, as well as any illegal SCSI_ASCII characters
* encountered, are converted to "_". To reduce length, trailing blanks are
* trimmed from SCSI_ASCII fields prior to conversion.
*
* Example: SCSI_ASCII "ST32550W SUN2.1G" -> "ST32550W_SUN2_1G"
*
* NOTE: the 1275 string form is always less than or equal to the scsi form.
*/
static char *
{
while (len >= 0) {
else
break;
}
while (len >= 0) {
len--; /* legal 1275 */
else
}
return (s_1275);
}
/*
* Given the inquiry data, binding_set, and dtype_node for a scsi device,
* return the nodename and compatible property for the device. The "compatible"
* concept comes from IEEE-1275. The compatible information is returned is in
* the correct form for direct use defining the "compatible" string array
* property. Internally, "compatible" is also used to determine the nodename
* to return.
*
* This function is provided as a separate entry point for use by drivers that
* currently issue their own non-SCSA inquiry command and perform their own
* node creation based their own private compiled in tables. Converting these
* drivers to use this interface provides a quick easy way of obtaining
* consistency as well as the flexibility associated with the 1275 techniques.
*
* The dtype_node is passed as a separate argument (instead of having the
* implementation use inq_dtype). It indicates that information about
* a secondary function embedded service should be produced.
*
* Callers must always use scsi_hba_nodename_compatible_free, even if
* *nodenamep is null, to free the nodename and compatible information
* when done.
*
* If a nodename can't be determined then **compatiblep will point to a
* diagnostic string containing all the compatible forms.
*
* NOTE: some compatible strings may violate the 31 character restriction
* imposed by IEEE-1275. This is not a problem because Solaris does not care
* about this 31 character limit.
*
* Each compatible form belongs to a form-group. The form-groups currently
* defined are generic ("scsiclass"), binding-set ("scsa.b"), and failover
* ("scsa.f").
*
* The following compatible forms, in high to low precedence
* order, are defined for SCSI target device nodes.
*
* scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (1 *1&2)
* scsiclass,DDEE.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (2 *1)
* scsiclass,DDFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (3 *2)
* scsiclass,DD.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR (4)
* scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP (5 *1&2)
* scsiclass,DDEE.vVVVVVVVV.pPPPPPPPPPPPPPPPP (6 *1)
* scsiclass,DDFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP (7 *2)
* scsiclass,DD.vVVVVVVVV.pPPPPPPPPPPPPPPPP (8)
* scsa,DD.bBBBBBBBB (8.5 *3)
* scsiclass,DDEEFFF (9 *1&2)
* scsiclass,DDEE (10 *1)
* scsiclass,DDFFF (11 *2)
* scsiclass,DD (12)
* scsa.fFFF (12.5 *4)
* scsiclass (13)
*
* *1 only produced on a secondary function node
* *2 only produced when generic form-group flags exist.
* *3 only produced when binding-set form-group legacy support is needed
* *4 only produced when failover form-group flags exist.
*
* where:
*
* v is the letter 'v'. Denotest the
* beginning of VVVVVVVV.
*
* VVVVVVVV Translated scsi_vendor.
*
* p is the letter 'p'. Denotes the
* beginning of PPPPPPPPPPPPPPPP.
*
* PPPPPPPPPPPPPPPP Translated scsi_product.
*
* r is the letter 'r'. Denotes the
* beginning of RRRR.
*
* RRRR Translated scsi_revision.
*
* DD is a two digit ASCII hexadecimal
* number. The value of the two digits is
* based one the SCSI "Peripheral device
* type" command set associated with the
* node. On a primary node this is the
* scsi_dtype of the primary command set,
* on a secondary node this is the
* scsi_dtype associated with the secondary
* function embedded command set.
*
* EE Same encoding used for DD. This form is
* only generated on secondary function
* nodes. The DD secondary function is embedded
* in an EE device.
*
* FFF Concatenation, in alphabetical order,
* of the flag characters within a form-group.
* For a given form-group, the following
* flags are defined.
*
* scsiclass: (generic form-group):
* R Removable_Media: Used when
* inq_rmb is set.
* S SAF-TE device: Used when
* inquiry information indicates
* SAF-TE devices.
*
* scsa.f: (failover form-group):
* E Explicit Target_Port_Group: Used
* when inq_tpgse is set and 'G' is
* alse present.
* G GUID: Used when a GUID can be
* generated for the device.
* I Implicit Target_Port_Group: Used
* when inq_tpgs is set and 'G' is
* also present.
*
* Forms using FFF are only be generated
* if there are applicable flag
* characters.
*
* b is the letter 'b'. Denotes the
* beginning of BBBBBBBB.
*
* BBBBBBBB Binding-set. Operating System Specific:
* scsi-binding-set property of HBA.
*/
#define COMPAT_LONGEST (strlen( \
"scsiclass,DDEEFFF.vVVVVVVVV.pPPPPPPPPPPPPPPPP.rRRRR" + 1))
/*
* Private version with extra device 'identity' arguments to allow code
* to determine GUID FFF support.
*/
static void
char **nodenamep, char **drivernamep,
char ***compatiblep, int *ncompatiblep)
{
char gf[sizeof ("RS\0")];
char ff[sizeof ("EGI\0")];
int dtype_device;
int ncompat; /* number of compatible */
char **compatp; /* compatible ptrs */
int i;
char *nname; /* nodename */
char *dname; /* driver name */
char **csp;
char *p;
int tlen;
int len;
char *guid;
/*
* Nodename_aliases: This table was originally designed to be
* implemented via a new nodename_aliases file - a peer to the
* driver_aliases that selects a nodename based on compatible
* forms in much the same say driver_aliases is used to select
* driver bindings from compatible forms. Each compatible form
* is an 'alias'. Until a more general need for a
* nodename_aliases file exists, which may never occur, the
* scsi mappings are described here via a compiled in table.
*
* This table contains nodename mappings for self-identifying
* scsi devices enumerated by the Solaris kernel. For a given
* device, the highest precedence "compatible" form with a
* mapping is used to select the nodename for the device. This
* will typically be a generic nodename, however in some legacy
* compatibility cases a driver nodename mapping may be selected.
*
* Because of possible breakage associated with switching SCSI
* target devices from driver nodenames to generic nodenames,
* we are currently unable to support generic nodenames for all
* SCSI devices (binding-sets). Although /devices paths are
* defined as unstable, avoiding possible breakage is
* important. Some of the newer SCSI transports (USB) already
* use generic nodenames. All new SCSI transports and target
* devices should use generic nodenames. At times this decision
* may be architecture dependent (sparc .vs. intel) based on when
* a transport was supported on a particular architecture.
*
* We provide a base set of generic nodename mappings based on
* scsiclass dtype and higher-precedence driver nodename
* mappings based on scsa "binding-set" to cover legacy
* issues. The binding-set is typically associated with
* "scsi-binding-set" property value of the HBA. The legacy
* mappings are provided independent of whether the driver they
* refer to is installed. This allows a correctly named node
* an add_drv of the legacy driver occurs.
*
* We also have mappings for legacy SUN hardware that
* misidentifies itself (enclosure services which identify
* themselves as processors). All future hardware should use
* the correct dtype.
*
* As SCSI HBAs are modified to use the SCSA interfaces for
* self-identifying SCSI target devices (PSARC/2004/116) the
* nodename_aliases table (PSARC/2004/420) should be augmented
* with legacy mappings in order to maintain compatibility with
* existing /devices paths, especially for devices that house
* an OS. Failure to do this may cause upgrade problems.
* Additions for new target devices or transports should not
* add scsa binding-set compatible mappings.
*/
static struct nodename_aliases {
char *na_nodename; /* nodename */
char *na_alias; /* compatible form match */
} na[] = {
/* # mapping to generic nodenames based on scsi dtype */
{"disk", "scsiclass,00"},
{"tape", "scsiclass,01"},
{"printer", "scsiclass,02"},
{"processor", "scsiclass,03"},
{"worm", "scsiclass,04"},
{"cdrom", "scsiclass,05"},
{"scanner", "scsiclass,06"},
{"optical-disk", "scsiclass,07"},
{"medium-changer", "scsiclass,08"},
{"obsolete", "scsiclass,09"},
{"prepress-a", "scsiclass,0a"},
{"prepress-b", "scsiclass,0b"},
{"array-controller", "scsiclass,0c"},
{"enclosure", "scsiclass,0d"},
{"disk", "scsiclass,0e"},
{"card-reader", "scsiclass,0f"},
{"bridge", "scsiclass,10"},
{"object-store", "scsiclass,11"},
{"reserved", "scsiclass,12"},
{"reserved", "scsiclass,13"},
{"reserved", "scsiclass,14"},
{"reserved", "scsiclass,15"},
{"reserved", "scsiclass,16"},
{"reserved", "scsiclass,17"},
{"reserved", "scsiclass,18"},
{"reserved", "scsiclass,19"},
{"reserved", "scsiclass,1a"},
{"reserved", "scsiclass,1b"},
{"reserved", "scsiclass,1c"},
{"reserved", "scsiclass,1d"},
{"well-known-lun", "scsiclass,1e"},
{"unknown", "scsiclass,1f"},
#ifdef sparc
/* # legacy mapping to driver nodenames for fcp binding-set */
{"ssd", "scsa,00.bfcp"},
{"st", "scsa,01.bfcp"},
{"sgen", "scsa,08.bfcp"},
{"ses", "scsa,0d.bfcp"},
/* # legacy mapping to driver nodenames for vhci binding-set */
{"ssd", "scsa,00.bvhci"},
{"st", "scsa,01.bvhci"},
{"sgen", "scsa,08.bvhci"},
{"ses", "scsa,0d.bvhci"},
#else /* sparc */
/* # for x86 fcp and vhci use generic nodenames */
#endif /* sparc */
/* # legacy mapping to driver nodenames for spi binding-set */
{"sd", "scsa,00.bspi"},
{"sd", "scsa,05.bspi"},
{"sd", "scsa,07.bspi"},
{"st", "scsa,01.bspi"},
{"ses", "scsa,0d.bspi"},
/* # SUN misidentified spi hardware */
{"ses", "scsiclass,03.vSUN.pD2"},
{"ses", "scsiclass,03.vSYMBIOS.pD1000"},
/* # legacy mapping to driver nodenames for atapi binding-set */
{"sd", "scsa,00.batapi"},
{"sd", "scsa,05.batapi"},
{"sd", "scsa,07.batapi"},
{"st", "scsa,01.batapi"},
{"unknown", "scsa,0d.batapi"},
/* # legacy mapping to generic nodenames for usb binding-set */
{"disk", "scsa,05.busb"},
{"disk", "scsa,07.busb"},
{"changer", "scsa,08.busb"},
{"comm", "scsa,09.busb"},
{"array_ctlr", "scsa,0c.busb"},
{"esi", "scsa,0d.busb"},
/*
* mapping nodenames for mpt based on scsi dtype
* for being compatible with the original node names
* under mpt controller
*/
{"sd", "scsa,00.bmpt"},
{"sd", "scsa,05.bmpt"},
{"sd", "scsa,07.bmpt"},
{"st", "scsa,01.bmpt"},
{"ses", "scsa,0d.bmpt"},
{"sgen", "scsa,08.bmpt"},
};
struct nodename_aliases *nap;
/* NOTE: drivernamep can be NULL */
(ncompatiblep == NULL))
return;
/*
* In order to reduce runtime we allocate one block of memory that
* contains both the NULL terminated array of pointers to compatible
* forms and the individual compatible strings. This block is
* somewhat larger than needed, but is short lived - it only exists
* until the caller can transfer the information into the "compatible"
* string array property and call scsi_hba_nodename_compatible_free.
*/
/* convert inquiry data from SCSI ASCII to 1275 string */
sizeof (inq->inq_revision));
/*
* Form flags in ***ALPHABETICAL*** order within form-group:
*
* NOTE: When adding a new flag to an existing form-group, careful
* consideration must be given to not breaking existing bindings
* based on that form-group.
*/
/*
* generic form-group flags
* R removable:
* Set when inq_rmb is set and for well known scsi dtypes. For a
* bus where the entire device is removable (like USB), we expect
* the HBA to intercept the inquiry data and set inq_rmb.
* Since OBP does not distinguish removable media in its generic
* name selection we avoid setting the 'R' flag if the root is not
* yet mounted.
* S SAF-TE device
* Set when the device type is SAT-TE.
*/
i = 0;
(dtype_device == DTYPE_WORM) ||
(dtype_device == DTYPE_RODIRECT) ||
(dtype_device == DTYPE_OPTICAL)))
gf[i] = '\0';
if (modrootloaded &&
(dtype_device == DTYPE_PROCESSOR) &&
gf[i++] = 'S';
gf[i] = '\0';
/*
* failover form-group flags
* E Explicit Target_Port_Group_Supported:
* Set for a device that has a GUID if inq_tpgse also set.
* G GUID:
* Set when we have identity information, can determine a devid
* from the identity information, and can generate a guid from
* that devid.
* I Implicit Target_Port_Group_Supported:
* Set for a device that has a GUID if inq_tpgs also set.
*/
i = 0;
&devid) == DDI_SUCCESS)) {
} else
if (guid)
ff[i] = '\0';
if (guid)
/*
* Construct all applicable compatible forms. See comment at the
* head of the function for a description of the compatible forms.
*/
/* ( 0) driver (optional, not documented in scsi(4)) */
if (compat0) {
*csp++ = p;
p += len;
}
/* ( 1) scsiclass,DDEEFFF.vV.pP.rR */
*csp++ = p;
p += len;
}
/* ( 2) scsiclass,DDEE.vV.pP.rR */
*csp++ = p;
p += len;
}
/* ( 3) scsiclass,DDFFF.vV.pP.rR */
*csp++ = p;
p += len;
}
/* ( 4) scsiclass,DD.vV.pP.rR */
*csp++ = p;
p += len;
}
/* ( 5) scsiclass,DDEEFFF.vV.pP */
*csp++ = p;
p += len;
}
/* ( 6) scsiclass,DDEE.vV.pP */
*csp++ = p;
p += len;
}
/* ( 7) scsiclass,DDFFF.vV.pP */
*csp++ = p;
p += len;
}
/* ( 8) scsiclass,DD.vV.pP */
*csp++ = p;
p += len;
}
/* (8.5) scsa,DD.bB (not documented in scsi(4)) */
if (binding_set) {
*csp++ = p;
p += len;
}
/* ( 9) scsiclass,DDEEFFF */
*csp++ = p;
p += len;
}
/* (10) scsiclass,DDEE */
if (dtype_device != dtype_node) {
*csp++ = p;
p += len;
}
/* (11) scsiclass,DDFFF */
if (*gf) {
*csp++ = p;
dtype_node, gf);
p += len;
}
/* (12) scsiclass,DD */
*csp++ = p;
p += len;
/* (12.5) scsa.fFFF */
if (*ff) {
*csp++ = p;
p += len;
}
/* (13) scsiclass */
*csp++ = p;
p += len;
/*
* When determining a nodename, a nodename_aliases specified
* mapping has precedence over using a driver_aliases specified
* driver binding as a nodename.
*
* See if any of the compatible forms have a nodename_aliases
* specified nodename. These mappings are described by
* nodename_aliases entries like:
*
* disk "scsiclass,00"
* enclosure "scsiclass,03.vSYMBIOS.pD1000"
* ssd "scsa,00.bfcp"
*
* All nodename_aliases mappings should idealy be to generic
* names, however a higher precedence legacy mapping to a
* driver name may exist. The highest precedence mapping
* provides the nodename, so legacy driver nodename mappings
* (if they exist) take precedence over generic nodename
* mappings.
*/
break;
}
}
}
/*
* Determine the driver name based on compatible (which may
* have the passed in compat0 as the first item). The driver_aliases
* file has entries like
*
* sd "scsiclass,00"
*
* that map compatible forms to specific drivers. These entries are
* established by add_drv/update_drv. We use the most specific
* driver binding as the nodename. This matches the eventual
* ddi_driver_compatible_major() binding that will be
* established by bind_node()
*/
if ((major == DDI_MAJOR_T_NONE) ||
continue;
break;
}
/*
* If no nodename_aliases mapping exists then use the
* driver_aliases specified driver binding as a nodename.
*/
/* return results */
if (nname) {
} else {
/*
* If no nodename could be determined return a special
* 'compatible' to be used for a diagnostic message. This
* compatible contains all compatible forms concatenated
* into a single string pointed to by the first element.
*/
ncompat = 1;
}
if (drivernamep) {
if (dname) {
} else
*drivernamep = NULL;
}
*compatiblep = compatp;
*ncompatiblep = ncompat;
}
/*
* Free allocations associated with scsi_hba_ident_nodename_compatible_get.
*/
static void
char **compatible)
{
if (nodename)
if (drivername)
if (compatible)
(NCOMPAT * COMPAT_LONGEST));
}
void
{
}
void
{
}
/* return the unit_address associated with a scsi_device */
char *
{
return (NULL);
if (pip)
return (mdi_pi_get_addr(pip));
else
}
/* scsi_device property interfaces */
#define _TYPE_DEFINED(flags) \
int
{
int v = defval;
int data;
int rv;
return (v);
if (pip) {
if (rv == DDI_PROP_SUCCESS)
v = data;
} else
return (v);
}
{
int rv;
return (v);
if (pip) {
if (rv == DDI_PROP_SUCCESS)
v = data;
} else
return (v);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
if (pip)
else
return (rv);
}
void
{
return;
if (pip)
(void) mdi_prop_free(data);
else
}
/* SMP device property interfaces */
int
{
int v = defval;
return (v);
return (v);
}
{
return (v);
return (v);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
char **data)
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
int
{
int rv;
return (DDI_PROP_INVAL_ARG);
return (rv);
}
void
{
return;
}
/*
* scsi_hba_ua_set: given "unit-address" string, set properties.
*
* Function to set the properties on a devinfo or pathinfo node from
* the "unit-address" part of a "name@unit-address" /devices path 'name'
* string.
*
* This function works in conjunction with scsi_ua_get()/scsi_hba_ua_get()
* (and possibly with an HBA driver's tran_tgt_init() implementation).
*/
static int
{
char *p;
int tgt;
char *tgt_port_end;
char *tgt_port;
int tgt_port_len;
int sfunc;
/* Caller must choose to decorate devinfo *or* pathinfo */
return (0);
/*
* generic implementation based on "tgt,lun[,sfunc]" address form.
* parse hex "tgt" part of "tgt,lun[,sfunc]"
*/
p = ua;
tgt_port_end = NULL;
for (tgt = 0; *p && *p != ','; p++) {
if (*p >= '0' && *p <= '9')
else if (*p >= 'a' && *p <= 'f')
else
/*
* if non-numeric or our of range set tgt to -1 and
* skip forward
*/
if (tgt < 0) {
tgt = -1;
for (; *p && *p != ','; p++)
;
break;
}
}
tgt_port_end = p;
/* parse hex ",lun" part of "tgt,lun[,sfunc]" */
if (*p)
p++;
for (lun64 = 0; *p && *p != ','; p++) {
if (*p >= '0' && *p <= '9')
else if (*p >= 'a' && *p <= 'f')
else
return (0);
}
/* parse hex ",sfunc" part of "tgt,lun[,sfunc]" */
if (*p) {
p++;
for (sfunc = 0; *p; p++) {
if (*p >= '0' && *p <= '9')
else if (*p >= 'a' && *p <= 'f')
else
return (0);
}
} else
sfunc = -1;
if (dchild) {
/*
* Decorate a devinfo node with unit address properties.
* This adds the the addressing properties needed to
* DDI_CTLOPS_UNINITCHILD the devinfo node (i.e. perform
* the reverse operation - form unit address from properties).
*/
return (0);
if (tgt_port_end) {
return (0);
}
}
/* Set the appropriate lun properties. */
if (lun64 < SCSI_32LUNS_PER_TARGET) {
return (0);
}
return (0);
/* Set the sfunc property */
if ((sfunc != -1) &&
return (0);
} else if (pchild) {
/*
* Decorate a pathinfo node with unit address properties.
*/
return (0);
if (tgt_port_end) {
return (0);
}
}
/* Set the appropriate lun properties */
if (lun64 < SCSI_32LUNS_PER_TARGET) {
(int)lun64) != DDI_PROP_SUCCESS)
return (0);
}
lun64) != DDI_PROP_SUCCESS)
return (0);
/* Set the sfunc property */
if ((sfunc != -1) &&
return (0);
}
return (1);
}
/*
* Private ndi_devi_find/mdi_pi_find implementation - find the child
* We have our own implementation because we need to search with both
* forms of sibling lists (dev_info and path_info) and we need to be able
* to search with a NULL name in order to find siblings already associated
* with a given unit-address (same @addr). NOTE: NULL name search will never
* return probe node.
*
* If pchildp is NULL and we find a pathinfo child, we return the client
* devinfo node in *dchildp.
*
* The init flag argument should be clear when called from places where
* recursion could occur (like scsi_busctl_initchild) and when the caller
* has already performed a search for name@addr with init set (performance).
*
* Future: Integrate ndi_devi_findchild_by_callback into scsi_findchild.
*/
static int
{
int found = CHILD_TYPE_NONE;
char *daddr;
return (CHILD_TYPE_NONE);
if (pchildp)
if (ppi)
*ppi = 0;
/* Walk devinfo child list to find a match */
continue;
/*
* If we are asked to find "anything" at a given
* unit-address (name == NULL), we don't realy want
* to find the 'probe' node. The existance of
* a probe node on a 'name == NULL' search should
* fail. This will trigger slow-path code where
* we explicity look for, and synchronize against,
* a node named "probe" at the unit-address.
*/
"%s@%s 'probe' devinfo found, skip",
continue;
}
/* We have found a match. */
break;
}
}
/*
* Walk pathinfo child list to find a match.
*
* NOTE: Unlike devinfo nodes, pathinfo nodes have a string searchable
* unit-address from creation - so there is no need for an 'init'
* search block of code for pathinfo nodes below.
*/
if (pchild) {
/*
* NOTE: If name specified and we match a pathinfo unit
* address, we don't check the client node name.
*/
if (ppi)
if (pchildp) {
/*
* Did not find a devinfo node, found a pathinfo node,
* but caller did not ask us to return a pathinfo node:
* we return the 'client' devinfo node instead (but
* with CHILD_TYPE_PATHINFO 'found' return value).
*/
"%s pathinfo found, client switch",
/*
* A pathinfo node always has a 'client' devinfo node,
* but we need to ensure that the 'client' is
* initialized and has a scsi_device structure too.
*/
"%s found client, initchild",
dchild);
}
/* client found and initialized */
} else {
"%s found client, but failed initchild",
}
}
}
/* Try devinfo again with initchild of uninitialized nodes */
/* skip if checked above */
continue;
/* attempt initchild to establish unit-address */
continue;
if (daddr &&
"%s@%s devinfo found post initchild",
break; /* node found */
}
}
}
/*
* We should never find devinfo and pathinfo at the same
* unit-address.
*/
}
return (found);
}
/*
* Given information about a child device (contained on probe node) construct
* and return a pointer to the dynamic SID devinfo node associated with the
* device. In the creation of this SID node a compatible property for the
* device is formed and used to establish a nodename (via
* /etc/nodename_aliases) and to bind a driver (via /etc/driver_aliases).
*
* If this routine is called then we got a response from a device and
* obtained the inquiry data from the device. Some inquiry results indicate
* that the specific LUN we addressed does not exist, and we don't want to
* bind a standard target driver to the node we create. Even though the
* specific LUN is not usable, the framework may still want to bind a
* target driver to the device for internal communication with the device -
* an example would be issuing a report_lun to enumerate other LUNs under a
* DPQ_NEVER LUN0. Another example would be wanting to known that the
* DPQ_NEVER LUN0 device exists in BUS_CONFIG_ONE for non-existent LUN
* caching optimizations. To support this we let the caller specify a
* compatible property (or driver). If LUN0 inquiry data indicates that the
* LUN does not exist then we establish compat0 as the highest precedence(0)
* compatible form. If used, this compat0 driver will never be called on to
* issue external commands to the device.
*
* If no driver binds to the device using driver_alias we establish the driver
* passed in as the node name.
*/
static int
{
int dtype;
int dpq;
int dpq_vu;
int dtype_node;
int lunexists;
char *compat0;
char *nname;
int ncompat;
char *binding_set = NULL;
int have_devid = 0;
int have_cdevid = 0;
char *devid_str;
/*
* Determine the lun and whether the lun exists. We may need to create
* a node for LUN0 (with compat0 driver binding) even if the lun does
* not exist - so we can run report_lun to find additional LUNs.
*/
if (dtype_node == -1)
if (dtype == DTYPE_UNKNOWN)
lunexists = 0;
"@%s dtype %x %x dpq_vu %d dpq %x: %d",
/* A non-existent LUN0 uses compatible_nodev. */
if (lunexists) {
} else if (lun64 == 0) {
} else
goto out; /* no node created */
/* Obtain identity information from probe node. */
/* Get "scsi-binding-set" property (if there is one). */
"binding_set '%s'", binding_set));
/* determine the node name and compatible information */
/*
* We will not be able to create a node because we could not
* determine a node name. Print out a NODRIVER level warning
* message with the compatible forms for the device. Note that
* there may be a driver.conf node that attaches to the device,
* which is why we only produce this warning message for debug
* kernels.
*/
"no node_name for device @%s:\n compatible: %s",
goto out;
}
/*
* FUTURE: some day we may want an accurate "compatible" on the probe
* node so that vhci_is_dev_supported() in scsi_vhci could, at
*
* if (ndi_prop_update_string_array(DDI_DEV_T_NONE, probe,
* "compatible", compat, ncompat) != DDI_PROP_SUCCESS) {
* SCSI_HBA_LOG((_LOG(3), self, NULL,
* "%s@%s failed probe compatible decoration",
* nname, addr));
* goto out;
* }
*/
/* Encode devid from identity information. */
&devid) == DDI_SUCCESS) {
have_devid = 1;
/* Attempt to form guid from devid. */
/* Produce string devid for debug. */
}
/*
* Determine if the device should be enumerated as under the vHCI
* (client node) or under the pHCI. By convention scsi_vhci expects
* the "cinfo" argument identity information to be represented as a
* devinfo node with the needed information (i.e. the pHCI probe node).
*/
MDI_SUCCESS)) {
/*
* Enumerate under pHCI:
*
* Create dynamic SID dchild node. No attempt is made to
* transfer information (except the addressing and identity
* information) from the probe node to the dynamic node since
* there may be HBA specific side effects that the framework
* does not known how to transfer.
*/
&dchild);
/*
* Decorate new node with addressing properties (via
* scsi_hba_ua_set()), compatible, identity information, and
* class.
*/
DDI_PROP_SUCCESS)) ||
DDI_PROP_SUCCESS)) ||
"devinfo @%s failed decoration", addr));
(void) scsi_hba_remove_node(dchild);
goto out;
}
/* Bind the driver */
/* need to bind in order to register a devid */
"devinfo @%s created, no driver-> "
"no devid_register", addr));
goto out;
}
/* Register devid */
if (have_devid) {
"devinfo @%s created, "
"devid register failed", addr));
else
"devinfo @%s created with devid", addr));
} else
"devinfo @%s created, no devid", addr));
} else {
/*
* Enumerate under vHCI:
*
* Create a pathinfo pchild node.
*/
"pathinfo alloc failed"));
goto out;
}
/*
* Decorate new node with addressing properties via
* scsi_hba_ua_set().
*/
"pathinfo %s decoration failed",
(void) mdi_pi_free(pchild, 0);
goto out;
}
/* Bind the driver */
/* need to bind in order to register a devid */
"pathinfo %s created, no client driver-> "
goto out;
}
/* Watch out for inconsistancies in devids. */
have_cdevid = 1;
if (have_devid && !have_cdevid) {
/* Client does not yet have devid, register ours. */
"pathinfo %s created, "
"devid register failed",
else
"pathinfo %s created with devid",
} else if (have_devid && have_cdevid) {
/*
* We have devid and client already has devid:
* they must be the same.
*/
"mismatched devid on path %s",
}
} else if (!have_devid && have_cdevid) {
/*
* Client already has a devid, but we don't:
* we should not have missing devids.
*/
"missing devid on path %s",
} else if (!have_cdevid && !have_devid) {
/* devid not supported */
"pathinfo %s created, no devid",
}
}
/* free the node name and compatible information */
out: if (have_devid)
if (have_cdevid)
if (guid)
if (compat)
if (inq80)
if (inq83)
if (binding_set)
/* return child_type results */
if (pchild) {
return (CHILD_TYPE_PATHINFO);
} else if (dchild) {
return (CHILD_TYPE_DEVINFO);
}
return (CHILD_TYPE_NONE);
}
/*
* Call scsi_device_createchild and then initchild the new node.
*/
static dev_info_t *
{
int child_type;
int rval;
if (ppi)
*ppi = 0;
/*
* Prevent multiple initialized (tran_tgt_init) nodes associated with
* the same @addr at the same time by calling tran_tgt_free() on the
* probe node prior to promotion of the 'real' node. After the call
* to scsi_hba_barrier_tran_tgt_free(), the HBA no longer has any
* probe node context.
*/
switch (child_type) {
case CHILD_TYPE_NONE:
break;
case CHILD_TYPE_PATHINFO:
/*
* Online pathinfo: Hold the path and exit the pHCI while
* calling mdi_pi_online() to avoid deadlock with power
* management of pHCI.
*/
if (rval != MDI_SUCCESS) {
/* pathinfo form of "failed during tran_tgt_init" */
(void) mdi_pi_free(pchild, 0);
return (NULL);
}
/*
* Return the path_instance of the pathinfo node.
*
* NOTE: We assume that sd_inq is not path-specific.
*/
if (ppi)
/*
* Fallthrough into CHILD_TYPE_DEVINFO code to promote
* the 'client' devinfo node as a dchild.
*/
"pathinfo online successful"));
/* FALLTHROUGH */
case CHILD_TYPE_DEVINFO:
/*
* For now, we ndi_devi_online() the child because some other
* parts of the IO framework, like degenerate devid code,
* depend on bus_config driving nodes to DS_ATTACHED. At some
* point in the future, to keep things light-weight, we would
* like to change the ndi_devi_online call below to be
*
* if (ddi_initchild(self, dchild) != DDI_SUCCESS)
*
* This would promote the node so that framework code could
* find the child with an @addr search, but does not incur
* attach(9E) overhead for BUS_CONFIG_ALL cases where the
* framework is not interested in attach of the node.
*
* NOTE: If the addr specified has incorrect syntax (busconfig
* one of bogus /devices path) then call below can fail.
*/
"devinfo online failed"));
/* failed online does not remove the node */
(void) scsi_hba_remove_node(dchild);
return (NULL);
}
"devinfo initchild successful"));
break;
}
return (child);
}
void
{
/*
* Catch second call on the same packet before doing anything else.
*/
#ifdef DEBUG
#else
#endif
"%s duplicate scsi_hba_pkt_comp(9F) on same scsi_pkt(9S)",
mod_containing_pc(caller()));
}
return;
/*
* For HBA drivers that implement tran_setup_pkt(9E), if we are
* completing a 'consistent' mode DMA operation then we must
* perform dma_sync prior to calling pkt_comp to ensure that
* the target driver sees the correct data in memory.
*/
}
/*
* If the HBA driver is using SCSAv3 scsi_hba_tgtmap_create enumeration
* that the lun configuration of a target has changed. Since we need to
* be determine scsi_device given scsi_address enbedded in
* scsi_pkt (via scsi_address_device(9F)), we also require use of
* SCSI_HBA_ADDR_COMPLEX.
*/
goto comp; /* not using tgtmap */
/*
* Check for lun-change notification and queue the scsi_pkt for
* lunchg1 processing. The 'pkt_comp' call to the target driver
* is part of lunchg1 processing.
*/
/*
* The host adaptor is done with the packet, we use
* pkt_stmp stage-temporary to link the packet for
* lunchg1 processing.
*
* NOTE: pkt_ha_private is not available since its use
* extends to tran_teardown_pkt.
*/
(void) cv_signal(&scsi_lunchg1_cv);
return;
}
}
}
/*
*/
static int
{
return (1);
return (0);
}
/*
* A host adapter driver is easier to write if we prevent multiple initialized
* (tran_tgt_init) scsi_device structures to the same unit-address at the same
* node to real child hand-off by calling scsi_hba_barrier_tran_tgt_free
* on the probe node prior to ddi_inichild of the 'real' node. As part of
* this early tran_tgt_free implementation, we must also call this function
* as we put a probe node on the scsi_hba_barrier_list.
*/
static void
{
struct scsi_device *sdprobe;
/* Return if we never called tran_tgt_init(9E). */
return;
if (tran->tran_tgt_free) {
/*
* To correctly support TRAN_CLONE, we need to use the same
* cloned scsi_hba_tran(9S) structure for both tran_tgt_init(9E)
* and tran_tgt_free(9E).
*/
if (!sdprobe->sd_tran_tgt_free_done) {
"tran_tgt_free EARLY"));
} else {
"tran_tgt_free EARLY already done"));
}
}
}
/*
* Add an entry to the list of barrier nodes to be asynchronously deleted by
* the scsi_hba_barrier_daemon after the specified timeout. Nodes on
* the barrier list are used to implement the bus_config probe cache
* of non-existent devices. The nodes are at DS_INITIALIZED, so their
* @addr is established for searching. Since devi_ref of a DS_INITIALIZED
* node will *not* prevent demotion, demotion is prevented by setting
* sd_uninit_prevent. Devinfo snapshots attempt to attach probe cache
* nodes, and on failure attempt to demote the node (without the participation
* of bus_unconfig) to DS_BOUND - this demotion is prevented via
* sd_uninit_prevent causing any attempted DDI_CTLOPS_UNINITCHILD to fail.
* Probe nodes are bound to nulldriver. The list is sorted by
* expiration time.
*
* NOTE: If we drove a probe node to DS_ATTACHED, we could use ndi_hold_devi()
* to prevent demotion (instead of sd_uninit_prevent).
*/
static void
{
struct scsi_hba_barrier *nb;
struct scsi_hba_barrier *b;
struct scsi_hba_barrier **bp;
/* HBA is no longer responsible for nodes on the barrier list. */
bp = &b->barrier_next)
if (b->barrier_endtime > endtime)
break;
if (bp == &scsi_hba_barrier_list)
(void) cv_signal(&scsi_hba_barrier_cv);
}
/*
* Attempt to remove devinfo node node, return 1 if removed. We
* don't try to remove barrier nodes that have sd_uninit_prevent set
* (even though they should fail device_uninitchild).
*/
static int
{
struct scsi_device *sd;
int circ;
int remove = 1;
int ret = 0;
char na[SCSI_MAXNAMELEN];
/* Honor sd_uninit_prevent on barrier nodes */
if (scsi_hba_devi_is_barrier(child)) {
remove = 0;
}
if (remove) {
"remove_node failed"));
} else {
ret = 1;
}
} else {
}
return (ret);
}
/*
* The asynchronous barrier deletion daemon. Waits for a barrier timeout
* to expire, then deletes the barrier (removes it as a child).
*/
/*ARGSUSED*/
static void
scsi_hba_barrier_daemon(void *arg)
{
struct scsi_hba_barrier *b;
int circ;
callb_generic_cpr, "scsi_hba_barrier_daemon");
for (;;) {
if (b == NULL) {
/* all barriers expired, wait for barrier_add */
(void) cv_wait(&scsi_hba_barrier_cv,
} else {
if (ddi_get_lbolt() >= b->barrier_endtime) {
/*
* Drop and retry if ordering issue. Do this
* before calling scsi_hba_remove_node() and
* deadlocking.
*/
probe = b->barrier_probe;
delay_random(5);
goto again;
}
/* process expired barrier */
if (!scsi_hba_remove_node(probe)) {
/* remove failed, delay and retry */
"delay expire"));
goto delay;
}
kmem_free(b, sizeof (struct scsi_hba_barrier));
} else {
/* establish timeout for next barrier expire */
(void) cv_timedwait(&scsi_hba_barrier_cv,
b->barrier_endtime);
}
}
}
}
/*
* Remove all barriers associated with the specified HBA. This is called
* from from the bus_unconfig implementation to remove probe nodes associated
* with the specified HBA (self) so that probe nodes that have not expired
* will not prevent DR of the HBA.
*/
static void
{
struct scsi_hba_barrier **bp;
struct scsi_hba_barrier *b;
if (scsi_hba_remove_node(b->barrier_probe)) {
*bp = b->barrier_next;
kmem_free(b, sizeof (struct scsi_hba_barrier));
} else {
"skip purge"));
}
} else
bp = &b->barrier_next;
}
}
/*
* LUN-change processing daemons: processing occurs in two stages:
*
* Stage 1: Daemon waits for a lunchg1 queued scsi_pkt, dequeues the pkt,
* forms the path, completes the scsi_pkt (pkt_comp), and
* queues the path for stage 2 processing. The use of stage 1
* avoids issues related to memory allocation in interrupt context
* (scsi_hba_pkt_comp()). We delay the pkt_comp completion until
* after lunchg1 processing forms the path for stage 2 - this is
* done to prevent the target driver from detaching until the
* path formation is complete (driver with outstanding commands
* should not detach).
*
* Stage 2: Daemon waits for a lunchg2 queued request, dequeues the
* request, and opens the path using ldi_open_by_name(). The
* path opened uses a special "@taddr,*" unit address that will
* trigger lun enumeration in scsi_hba_bus_configone(). We
* trigger lun enumeration in stage 2 to avoid problems when
*/
/*ARGSUSED*/
static void
scsi_lunchg1_daemon(void *arg)
{
struct scsi_device *sd;
char *ua, *p;
char taddr[SCSI_MAXNAMELEN];
char path[MAXPATHLEN];
struct scsi_lunchg2 *lunchg2;
callb_generic_cpr, "scsi_lunchg1_daemon");
for (;;) {
/* All lunchg1 processing requests serviced, wait. */
(void) cv_wait(&scsi_lunchg1_cv,
continue;
}
/* Unlink and perform lunchg1 processing on pkt. */
/* Determine initiator port (self) from the pkt_address. */
/*
* Determine scsi_devie from pkt_address (depends on
* SCSI_HBA_ADDR_COMPLEX).
*/
continue;
}
/* Determine unit-address from scsi_device. */
/* Extract taddr from the unit-address. */
*p++ = *ua++;
*p = '\0'; /* NULL terminate taddr */
/*
* Form path using special "@taddr,*" notation to trigger
* lun enumeration.
*/
/*
* Now that we have the path, complete the pkt that
* triggered lunchg1 processing.
*/
/* Allocate element for stage2 processing queue. */
/* Queue and dispatch to stage 2. */
(void) cv_signal(&scsi_lunchg2_cv);
}
}
/*ARGSUSED*/
static void
scsi_lunchg2_daemon(void *arg)
{
struct scsi_lunchg2 *lunchg2;
callb_generic_cpr, "scsi_lunchg2_daemon");
li = ldi_ident_from_anon();
for (;;) {
/* All lunchg2 processing requests serviced, wait. */
(void) cv_wait(&scsi_lunchg2_cv,
continue;
}
/* Unlink and perform lunchg2 processing on pkt. */
/*
* Open and close the path to trigger lun enumeration. We
* don't expect the open to succeed, but we do expect code in
* scsi_hba_bus_configone() to trigger lun enumeration.
*/
/* Free path and linked element. */
}
}
/*
* Enumerate a child at the specified @addr. If a device exists @addr then
* ensure that we have the appropriately named devinfo node for it. Name is
* NULL in the bus_config_all case. This routine has no knowledge of the
* format of an @addr string or associated addressing properties.
*
* The caller must guarantee that there is an open scsi_hba_devi_enter on the
* parent. We return the scsi_device structure for the child device. This
* scsi_device structure is valid until the caller scsi_hba_devi_exit the
* parent. The caller can add do ndi_hold_devi of the child prior to the
* scsi_hba_devi_exit to extend the validity of the child.
*
* In some cases the returned scsi_device structure may be used to drive
* additional SCMD_REPORT_LUNS operations by bus_config_all callers.
*
* The first operation performed is to see if there is a dynamic SID nodes
* already attached at the specified "name@addr". This is the fastpath
* case for resolving a reference to a node that has already been created.
* All other references are serialized for a given @addr prior to probing
* to determine the type of device, if any, at the specified @addr.
* If no device is present then NDI_FAILURE is returned. The fact that a
* minimizing the probes of non-existent devices.
*
* When there is a device present the dynamic SID node is created based on
* the device found. If a driver.conf node exists for the same @addr it
* will either merge into the dynamic SID node (if the SID node bound to
* that driver), or exist independently. To prevent the actions of one driver
* causing side effects in another, code prevents multiple SID nodes from
* binding to the same "@addr" at the same time. There is autodetach code
* to allow one device to be replaced with another at the same @addr for
* slot addressed SCSI bus implementations (SPI). For compatibility with
* legacy driver.conf behavior, the code does not prevent multiple driver.conf
* nodes from attaching to the same @addr at the same time.
*
* This routine may have the side effect of creating nodes for devices other
* than the one being sought. It is possible that there is a different type of
* It is the caller's responsibility to determine whether the device we found,
* if any, at the specified address, is the one it really wanted.
*/
static struct scsi_device *
{
struct scsi_device *sdchild;
struct scsi_device *sdprobe;
int sp;
int pi = 0;
int wait_msg = scsi_hba_wait_msg;
int chg;
/* playing with "probe" node name is dangerous */
return (NULL);
/*
* NOTE: use 'goto done;' or 'goto fail;'. There should only be one
* 'return' statement from here to the end of the function - the one
* on the last line of the function.
*/
/*
* Fastpath: search to see if we are requesting a named SID node that
* already exists (we already created) - probe node does not count.
* scsi_findchild() does not hold the returned devinfo node, but
* this is OK since the caller has a scsi_hba_devi_enter on the
* attached parent HBA (self). The caller is responsible for attaching
* and placing a hold on the child (directly via ndi_hold_devi or
* indirectly via ndi_busop_bus_config) before doing an
* scsi_hba_devi_exit on the parent.
*
* NOTE: This fastpath prevents detecting a driver binding change
* (autodetach) if the same nodename is used for old and new binding.
*/
/* first call is with init set */
goto done;
}
/*
* Create a barrier devinfo node used to "probe" the device with. We
* need to drive this node to DS_INITIALIZED so that the
* DDI_CTLOPS_INITCHILD has occurred, bringing the SCSA transport to
* a state useable state for issuing our "probe" commands. We establish
* this barrier node with a node name of "probe" and compatible
* property of "scsiprobe". The compatible property must be associated
* in /etc/driver_aliases with a scsi target driver available in the
* root file system (sd).
*
* The "probe" that we perform on the barrier node, after it is
* DS_INITIALIZED, is used to find the information needed to create a
* dynamic devinfo (SID) node. This "probe" is separate from the
* probe(9E) call associated with the transition of a node from
* DS_INITIALIZED to DS_PROBED. The probe(9E) call that eventually
* occurs against the created SID node should find ddi_dev_is_sid and
* just return DDI_PROBE_DONTCARE.
*
* Trying to avoid the use of a barrier node is not a good idea
* because we may have an HBA driver that uses generic bus_config
* (this code) but implements its own DDI_CTLOPS_INITCHILD with side
* effects that we can't duplicate (such as the ATA nexus driver).
*
* The objective is to single thread probes of the same device (same
* @addr) while allowing parallelism for probes of different devices
* with the same parent. At this point we are serialized on our self.
* For parallelism we will need to release our self. Prior to release
* we construct a barrier for probes of the same device to serialize
* against. The "probe@addr" node acts as this barrier. An entering
* thread must wait until the probe node does not exist - it can then
* create and link the probe node - dropping the HBA (self) lock after
* the node is linked and visible (after ddi_initchild). A side effect
* of this is that transports should not "go over the wire" (i.e. do
* things that incur significant delays) until after tran_target_init.
* This means that the first "over the wire" operation should occur
* at tran_target_probe time - when things are running in parallel
* again.
*
* If the probe node exists then another probe with the same @addr is
* in progress, we must wait until there is no probe in progress
* before proceeding, and when we proceed we must continue to hold the
* HBA (self) until we have linked a new probe node as a barrier.
*
* marked with DEVICE_REMOVED with node deletion scheduled for some
* future time (seconds). This asynchronous deletion allows the
* framework to detect repeated requests to the same non-existent
* device and avoid overhead associated with contacting a non-existent
* device again and again.
*/
for (;;) {
/*
* Search for probe node - they should only exist as devinfo
* nodes.
*/
if (psearch)
"???? @%s 'probe' search found "
break;
}
/*
* The barrier node may cache the non-existence of a device
* by leaving the barrier node in place (with
* DEVI_DEVICE_REMOVED flag set ) for some amount of time after
* the failure of a probe. This flag is used to fail
* additional probes until the barrier probe node is deleted,
* which will occur from a timeout some time after a failed
* probe. The failed probe will use DEVI_SET_DEVICE_REMOVED
* and schedule probe node deletion from a timeout. The callers
* scsi_hba_devi_exit on the way out of the first failure will
* do the cv_broadcast associated with the cv_wait below - this
* handles threads that wait prior to DEVI_DEVICE_REMOVED being
* set.
*/
if (DEVI_IS_DEVICE_REMOVED(probe)) {
"detected probe DEVICE_REMOVED"));
goto fail;
}
/*
* Drop the lock on the HBA (self) and wait until the probe in
* progress has completed. A changes in the sibling list from
* removing the probe node will cause cv_wait to return
* (scsi_hba_devi_exit does the cv_broadcast).
*/
if (wait_msg) {
wait_msg--;
"exists, probe already in progress: %s", wait_msg ?
"waiting..." : "last msg, but still waiting..."));
}
/*
* NOTE: we could avoid rare case of one second delay by
* implementing scsi_hba_devi_exit_and_wait based on
* ndi/mdi_devi_exit_and_wait (and consider switching devcfg.c
*/
}
/*
* Search to see if we are requesting a SID node that already exists.
* We hold the HBA (self) and there is not another probe in progress at
* the same @addr. scsi_findchild() does not hold the returned
* devinfo node but this is OK since we hold the HBA (self).
*/
if (name) {
"%s@%s probe devinfo fastpath",
goto done;
}
}
/*
* We are looking for a SID node that does not exist or a driver.conf
* node.
*
* To avoid probe side effects, before we probe the device at the
* specified address we need to check to see if there is already an
* initialized child "@addr".
*
* o If we find an initialized SID child and name is NULL or matches
* the name or the name of the attached driver then we return the
* existing node.
*
* o If we find a non-matching SID node, we will attempt to autodetach
* and remove the node in preference to our new node.
*
* o If SID node found does not match and can't be autodetached, we
* fail: we only allow one SID node at an address.
*
* NOTE: This code depends on SID nodes showing up prior to
* driver.conf nodes in the sibling list.
*/
for (;;) {
/* first NULL name call is with init set */
break;
/*
* To detect changes in driver binding that should attempt
* autodetach we determine the major number of the driver
* that should currently be associated with the device based
* on the compatible property.
*/
if (scsi_hba_dev_is_sid(dsearch))
if ((scsi_hba_dev_is_sid(dsearch) ||
"already attached @addr"));
goto done;
}
if (!scsi_hba_dev_is_sid(dsearch))
break; /* driver.conf node */
/*
* Implement autodetach of SID node for situations like a
* previously "scsinodev" LUN0 coming into existence (or a
* powered on at the same time). Try to autodetach the existing
* SID node @addr. If that works, search again - otherwise fail.
*/
"looking for %s@%s: SID @addr exists, autodetach",
if (!scsi_hba_remove_node(dsearch)) {
"autodetach @%s failed: fail %s@%s",
goto fail;
}
}
/*
* We will be creating a new SID node, allocate probe node
* used to find out information about the device located @addr.
* The probe node also acts as a barrier against additional
* configuration at the same address, and in the case of non-existent
* devices it will (for some amount of time) avoid re-learning that
* the device does not exist on every reference. Once the probe
* node is DS_LINKED we can drop the HBA (self).
*
* The probe node is allocated as a hidden node so that it does not
* show up in devinfo snapshots.
*/
&probe);
/*
* Decorate the probe node with the property representation of @addr
* unit-address string prior to initchild so that initchild can
* construct the name of the node from properties and tran_tgt_init
* implementation can determine what LUN is being referenced.
*
* If the addr specified has incorrect syntax (busconfig one of bogus
* /devices path) then scsi_hba_ua_set can fail. If the address
* is not understood by the SCSA HBA driver then this operation will
* work, but tran_tgt_init may still fail (for example the HBA
* driver may not support secondary functions).
*/
"@%s failed scsi_hba_ua_set", addr));
goto fail;
}
/*
* Set the class property to "scsi". This is sufficient to distinguish
* the node for HBAs that have multiple classes of children (like uata
* - which has "dada" class for ATA children and "scsi" class for
* ATAPI children) and may not use our scsi_busctl_initchild()
* implementation. We also add a "compatible" property of "scsiprobe"
* to select the probe driver.
*/
"@%s failed node decoration", addr));
goto fail;
}
/*
* Promote probe node to DS_INITIALIZED so that transport can be used
* for scsi_probe. After this the node is linked and visible as a
* barrier for serialization of other @addr operations.
*
* NOTE: If we attached the probe node, we could get rid of
* uninit_prevent.
*/
"@%s failed initchild", addr));
/* probe node will be removed in fail exit path */
goto fail;
}
/* get the scsi_device structure of the probe node */
/*
* Do scsi_probe. The probe node is linked and visible as a barrier.
* We prevent uninitialization of the probe node and drop our HBA (self)
* while we run scsi_probe() of this "@addr". This allows the framework
* to support multiple scsi_probes for different devices attached to
* the same HBA (self) in parallel. We prevent node demotion of the
* probe node from DS_INITIALIZED by setting sd_uninit_prevent. The
* probe node can not be successfully demoted below DS_INITIALIZED
* (scsi_busctl_uninitchild will fail) until we zero sd_uninit_prevent
* as we are freeing the node via scsi_hba_remove_node(probe).
*/
/* Introduce a small delay here to increase parallelism. */
delay_random(5);
if (sp == SCSIPROBE_EXISTS) {
/*
* For a device that exists, while still running in parallel,
* also get identity information from device. This is done
* separate from scsi_probe/tran_tgt_probe/scsi_hba_probe
* since the probe code path may still be used for HBAs
* that don't use common bus_config services (we don't want
* to expose that code path to a behavior change). This
* operation is called 'identity' to avoid confusion with
* deprecated identify(9E).
*
* Future: We may eventually want to allow HBA customization via
* scsi_identity/tran_tgt_identity/scsi_device_identity, but for
* now we just scsi_device_identity.
*
* The identity operation will establish additional properties
* on the probe node related to device identity:
*
* "inquiry-page-80" byte array of SCSI page 80
* "inquiry-page-83" byte array of SCSI page 83
*
* These properties will be used to generate a devid
* (ddi_devid_scsi_encode) and guid - and to register
* (ddi_devid_register) a devid for the device.
*
* If identify fails (non-zero return), the we had allocation
* problems or the device returned inconsistent results then
* we pretend that device does not exist.
*/
}
/*
* Future: Is there anything more we can do here to help avoid
* serialization on iport parent during scsi_device attach(9E)?
*/
}
if (sp != SCSIPROBE_EXISTS) {
/*
* Target does not exist. Mark the barrier probe node
* as DEVICE_REMOVED and schedule an asynchronous
* deletion of the node in scsi_hba_barrier_timeout
* seconds. We keep our hold on the probe node
* until we are ready perform the asynchronous node
* deletion.
*/
"set probe DEVICE_REMOVED"));
}
goto fail;
}
/* Create the child node from the inquiry data in the probe node. */
/*
* This may fail because there was no driver binding identified
* via driver_alias. We may still have a conf node.
*/
if (name) {
if (child)
"using driver.conf driver binding"));
}
"device not configured"));
goto fail;
}
}
/*
* Transfer the inquiry data from the probe node to the child
* SID node to avoid an extra scsi_probe. Callers depend on
* established inquiry data for the returned scsi_device.
*/
}
/*
* If we are doing a bus_configone and the node we created has the
* wrong node and driver name then switch the return result to a
* driver.conf node with the correct name - if such a node exists.
*/
/*
* We can't remove when modrootloaded == 0 in case
* boot-device a uses generic name and
* scsi_hba_nodename_compatible_get() returned a
* legacy binding-set driver oriented name.
*/
if (modrootloaded) {
(void) scsi_hba_remove_node(child);
goto fail;
}
} else {
"device configured, but switching to driver.conf"));
}
}
/* get the scsi_device structure from the node */
if (child) {
/*
* We may have ended up here after promotion of a previously
* demoted node, where demotion deleted sd_inq data in
* scsi_busctl_uninitchild. We redo the scsi_probe() to
* reestablish sd_inq. We also want to redo the scsi_probe
* for devices are currently device_isremove in order to
* detect new device_insert.
*/
/* hotplug_node can only be revived via hotplug. */
"scsi_probe() demoted devinfo"));
if (sp == SCSIPROBE_EXISTS) {
/*
* Devinfo child exists and we are
* talking to the device, report
* reinsert and note if this was a
* new reinsert.
*/
"devinfo %s@%s device_reinsert%s",
} else {
NULL, "reprobe");
"%s device_remove%s",
(sp > (sizeof (scsi_probe_ascii) /
sizeof (scsi_probe_ascii[0]))) ?
}
} else {
"no reprobe"));
}
}
} else {
}
if (probe) {
/*
* Clean up probe node, destroying node if uninit_prevent
* it is going to zero. Destroying the probe node (deleting
* from the sibling list) will wake up any people waiting on
* the probe node barrier.
*/
if (!scsi_hba_remove_node(probe)) {
/*
* Probe node removal should not fail, but if it
* does we hand that responsibility over to the
* async barrier deletion thread - other references
* to the same unit-address can hang until the
* probe node delete completes.
*/
"remove probe failed, go async"));
}
}
/*
* If we successfully resolved via a pathinfo node, we need to find
* the pathinfo node and ensure that it is online (if possible). This
* is done for the case where the device was open when
* scsi_device_unconfig occurred, so mdi_pi_free did not occur. If the
* device has now been reinserted, we want the path back online.
* NOTE: This needs to occur after destruction of the probe node to
* avoid ASSERT related to two nodes at the same unit-address.
*/
/*
* Verify that we can talk to the device, and if
* so note if this is a new device_insert.
*
* NOTE: We depend on mdi_path_select(), when given
* a specific path_instance, to select that path
* even if the path is offline.
*
* NOTE: A Client node is not ndi_dev_is_hotplug_node().
*/
"%s scsi_probe() demoted pathinfo",
if (sp == SCSIPROBE_EXISTS) {
/*
* Pathinfo child exists and we are
* talking to the device, report
* reinsert and note if this
* was a new reinsert.
*/
"pathinfo %s device_reinsert%s",
if (chg)
(void) mdi_pi_online(psearch,
0);
} else {
"reprobe");
}
} else {
"%s no reprobe",
}
}
}
/* If asked for path_instance, return it. */
if (ppi)
return (sdchild);
}
static void
{
char *spathname;
int rval;
/*
* We have a catch-22. We may have a demoted node that we need to find
* use scsi_findchild. If it's demoted, we then use
* ndi_devi_findchild_by_callback.
*/
if (child) {
"devinfo %s@%s found by callback",
"devinfo %s@%s not SCSI_DEVICE flavored",
}
}
}
if (child) {
/* Don't unconfig probe nodes. */
if (scsi_hba_devi_is_barrier(child)) {
"devinfo %s@%s is_barrier, skip",
return;
}
if (ndi_devi_offline(child,
"devinfo %s@%s offlined and removed",
} else if (ndi_devi_device_remove(child)) {
"devinfo %s@%s offline failed, device_remove",
}
} else if (path) {
/*
*
* NOTE: mdi_pi_offline of last path will fail if the
* device is open (i.e. the client can't be offlined).
*
* NOTE: For mdi there is no REMOVE flag for mdi_pi_offline().
* When mdi_pi_offline returns MDI_SUCCESS, we are responsible
* for remove via mdi_pi_free().
*/
if (rval == MDI_SUCCESS) {
"pathinfo %s offlined and removed", spathname));
} else if (mdi_pi_device_remove(path)) {
"pathinfo %s offline failed, "
"device_remove", spathname));
}
if ((rval == MDI_SUCCESS) &&
"pathinfo %s mdi_pi_free failed, "
"device_remove", spathname));
(void) mdi_pi_device_remove(path);
}
} else {
}
}
/*
* configure the device at the specified "@addr" address.
*/
static struct scsi_device *
{
int circ;
struct scsi_device *sd;
return (sd);
}
/*
* unconfigure the device at the specified "@addr" address.
*/
static void
{
int circ;
}
/*
* The bus_config_all operations are multi-threaded for performance. A
* separate thread per target and per LUN is used. The config handle is used
* to coordinate all the threads at a given level and the config thread data
* contains the required information for a specific thread to identify what it
* is processing and the handle under which this is being processed.
*/
/* multi-threaded config handle */
struct scsi_hba_mte_h {
int h_thr_count;
};
/* target of 'self' config thread data */
struct scsi_hba_mte_td {
struct scsi_hba_mte_h *td_h;
char *td_taddr; /* target port */
int td_mt;
};
/* Invoke callback on a vector of taddrs from multiple threads */
static void
{
struct scsi_hba_mte_h *h; /* HBA header */
char **taddr;
/* allocate and initialize the handle */
h = kmem_zalloc(sizeof (*h), KM_SLEEP);
/* loop over all the targets */
/* allocate a thread data structure for target */
/* process the target */
mutex_enter(&h->h_lock);
h->h_thr_count++;
mutex_exit(&h->h_lock);
else
}
/* wait for all the target threads to complete */
mutex_enter(&h->h_lock);
while (h->h_thr_count > 0)
mutex_exit(&h->h_lock);
/* free the handle */
cv_destroy(&h->h_cv);
mutex_destroy(&h->h_lock);
kmem_free(h, sizeof (*h));
}
struct scsi_hba_mte_ld {
struct scsi_hba_mte_h *ld_h;
char *ld_taddr; /* target port */
int ld_sfunc; /* secondary function */
};
/*
* Enumerate the LUNs and secondary functions of the specified target. The
* target portion of the "@addr" is already represented as a string in the
* thread data, we add a ",lun" representation to this and perform a
* bus_configone byte of enumeration on that "@addr".
*/
static void
scsi_hba_enum_lsf_of_tgt_thr(void *arg)
{
char addr[SCSI_MAXNAMELEN];
/* make string form of "@taddr,lun[,sfunc]" and see if it exists */
else
/* configure device at that unit-address address */
/* signal completion of this LUN thread to the target */
mutex_enter(&h->h_lock);
if (--h->h_thr_count == 0)
cv_broadcast(&h->h_cv);
mutex_exit(&h->h_lock);
/* free config thread data */
}
/* Format of SCSI REPORT_LUNS report */
typedef struct scsi_lunrpt {
/*
* scsi_device_reportluns()
*
* Callers of this routine should ensure that the 'sd0' scsi_device structure
* and 'pi' path_instance specified are associated with a responding LUN0.
* This should not be called for SCSI-1 devices.
*
* To get a LUN report, we must allocate a buffer. To know how big to make the
* buffer, we must know the number of LUNs. To know the number of LUNs, we must
* get a LUN report. We first issue a SCMD_REPORT_LUNS command using a
* reasonably sized buffer that's big enough to report all LUNs for most
* typical devices. If it turns out that we needed a bigger buffer, we attempt
* to allocate a buffer of sufficient size, and reissue the command. If the
* first command succeeds, but the second fails, we return whatever we were
* able to get the first time. We return enough information for the caller to
* tell whether he got all the LUNs or only a subset.
*
* If successful, we allocate an array of scsi_lun_t to hold the results. The
* caller must kmem_free(*lunarrayp, *sizep) when finished with it. Upon
* successful return return value is NDI_SUCCESS and:
*
* *lunarrayp points to the allocated array,
* *nlunsp is the number of valid LUN entries in the array,
* *tlunsp is the total number of LUNs in the target,
* *sizep is the size of the lunarrayp array, which must be freed.
*
* If the *nlunsp is less than *tlunsp, then we were only able to retrieve a
* subset of the total set of LUNs in the target.
*/
static int
{
struct scsi_pkt *lunrpt_pkt;
/*
* NOTE: child should only be used in SCSI_HBA_LOG context since with
* vHCI enumeration it may be the vHCI 'client' devinfo child instead
* of a child of the 'self' pHCI we are enumerating.
*/
/* first try, look for up to scsi_lunrpt_default_max LUNs */
return (NDI_NOMEM);
}
sizeof (struct scsi_arq_status), 0, PKT_CONSISTENT,
SLEEP_FUNC, NULL);
if (lunrpt_pkt == NULL) {
return (NDI_NOMEM);
}
SCMD_REPORT_LUNS, 0, bsize, 0);
/*
* When sd0 is a vHCI scsi device, we need reportlun to be issued
* against a specific LUN0 path_instance that we are enumerating.
*/
/*
* NOTE: scsi_poll may not allow HBA specific recovery from TRAN_BUSY.
*/
if (scsi_poll(lunrpt_pkt) < 0) {
return (NDI_FAILURE);
}
/* Compute the total number of LUNs in the target */
if (tluns == 0) {
/* Illegal response -- this target is broken */
return (DDI_NOT_WELL_FORMED);
}
/* have more than we allocated space for */
if (nluns == default_maxluns) {
/* first time around, reallocate larger */
goto again;
}
/* uh oh, we got a different tluns the second time! */
} else
/*
* Now we have:
* lunrpt_bp is the buffer we're using;
* tluns is the total number of LUNs the target says it has;
* nluns is the number of LUNs we were able to get into the buffer.
*
* Copy the data out of scarce iopb memory into regular kmem.
* The caller must kmem_free(*lunarrayp, *sizep) when finished with it.
*/
return (NDI_NOMEM);
}
return (NDI_SUCCESS);
}
/*
* Enumerate all the LUNs and secondary functions of the specified 'taddr'
* target port as accessed via 'self' pHCI. Note that sd0 may be associated
* with a child of the vHCI instead of 'self' - in this case the 'pi'
* path_instance is used to ensure that the SCMD_REPORT_LUNS command is issued
* through the 'self' pHCI path.
*
* We multi-thread across all the LUNs and secondary functions and enumerate
* them. Which LUNs exist is based on SCMD_REPORT_LUNS data.
*
* The scsi_device we are called with should be for LUN0 and has been probed.
*
* This function is structured so that an HBA that has a different target
* addressing structure can still use this function to enumerate the its
* LUNs if it uses "taddr,lun" for its LUN space.
*
* We make assumptions about other LUNs associated with the target:
*
* For SCSI-2 and SCSI-3 target we will issue the SCSI report_luns
* command. If this fails or we have a SCSI-1 then the number of
* LUNs is determined based on SCSI_OPTIONS_NLUNS. For a SCSI-1
* target we never probe above LUN 8, even if SCSI_OPTIONS_NLUNS
* indicates we should.
*
* HBA drivers wanting a different set of assumptions should implement their
* own LUN enumeration code.
*/
static int
{
struct scsi_hba_mte_h *h;
struct scsi_hba_mte_ld *ld;
int aver;
int lun;
int maxluns;
/*
* If LUN0 failed then we have no other LUNs.
*
* NOTE: We need sd_inq to be valid to check ansi version. Since
* scsi_unprobe is now a noop (sd_inq freeded in
* scsi_busctl_uninitchild) sd_inq remains valid even if a target
* driver detach(9E) occurs, resulting in a scsi_unprobe call
* (sd_uninit_prevent keeps sd_inq valid by failing any
* device_uninitchild attempts).
*/
"not setup correctly:%s%s%s",
return (DDI_FAILURE);
}
/*
* NOTE: child should only be used in SCSI_HBA_LOG context since with
* vHCI enumeration it may be the vHCI 'client' devinfo child instead
* of a child of the 'self' pHCI we are enumerating.
*/
/* Determine if we are reporting lun observations into lunmap. */
if (tgtmap) {
}
}
if (lundam) {
/* If using lunmap, start the observation */
} else {
/* allocate and initialize the LUN handle */
h = kmem_zalloc(sizeof (*h), KM_SLEEP);
}
/* See if SCMD_REPORT_LUNS works for SCSI-2 and beyond */
/* loop over the reported LUNs */
if (lundam) {
}
} else {
if (lun64 == 0)
continue;
/* allocate a thread data structure for LUN */
/* process the LUN */
mutex_enter(&h->h_lock);
h->h_thr_count++;
mutex_exit(&h->h_lock);
(void *)ld);
else
(void) thread_create(NULL, 0,
}
}
/* free the LUN array allocated by scsi_device_reportluns */
} else {
/* Determine the number of LUNs to enumerate. */
/* Couldn't get SCMD_REPORT_LUNS data */
if (aver >= SCSI_VERSION_3) {
/*
* Based on calling context tunable, only enumerate one
* lun (lun0) if scsi_device_reportluns() fails on a
* SCSI_VERSION_3 or greater device.
*/
maxluns = 1;
}
/* loop over possible LUNs, skipping LUN0 */
if (maxluns > 1)
maxluns - 1));
else
if (lundam) {
}
} else {
if (lun64 == 0)
continue;
/* allocate a thread data structure for LUN */
/* process the LUN */
mutex_enter(&h->h_lock);
h->h_thr_count++;
mutex_exit(&h->h_lock);
(void *)ld);
else
(void) thread_create(NULL, 0,
}
}
}
/*
* If we have an embedded service as a secondary function on LUN0 and
* the primary LUN0 function is different than the secondary function
* then enumerate the secondary function. The sfunc value is the dtype
* associated with the embedded service.
*
* inq_encserv: enclosure service and our dtype is not DTYPE_ESI
* or DTYPE_UNKNOWN then create a separate DTYPE_ESI node for
* enclosure service access.
*/
if (lundam) {
"@%s,0,%x failed to create",
}
} else {
/* allocate a thread data structure for sfunc */
/* process the LUN */
mutex_enter(&h->h_lock);
h->h_thr_count++;
mutex_exit(&h->h_lock);
scsi_hba_enum_lsf_of_tgt_thr((void *)ld);
else
(void) thread_create(NULL, 0,
scsi_hba_enum_lsf_of_tgt_thr, (void *)ld,
}
}
/*
* Future: Add secondary function support for:
* inq_mchngr (DTYPE_CHANGER)
* inq_sccs (DTYPE_ARRAY_CTRL)
*/
if (lundam) {
/* If using lunmap, end the observation */
} else {
/* wait for all the LUN threads of this target to complete */
mutex_enter(&h->h_lock);
while (h->h_thr_count > 0)
mutex_exit(&h->h_lock);
/* free the target handle */
cv_destroy(&h->h_cv);
mutex_destroy(&h->h_lock);
kmem_free(h, sizeof (*h));
}
return (DDI_SUCCESS);
}
/*
* Enumerate LUN0 and all other LUNs and secondary functions associated with
* the specified target address.
*
* Return NDI_SUCCESS if we might have created a new node.
* Return NDI_FAILURE if we definitely did not create a new node.
*/
static int
{
char addr[SCSI_MAXNAMELEN];
struct scsi_device *sd;
int circ;
int ret;
int pi;
/* See if LUN0 of the specified target exists. */
if (sd) {
/*
* LUN0 exists, enumerate all the other LUNs.
*
* With vHCI enumeration, when 'self' is a pHCI the sd
* scsi_device may be associated with the vHCI 'client'.
* In this case 'pi' is the path_instance needed to
* continue enumeration communication LUN0 via 'self'
* pHCI and specific 'taddr' target address.
*
* We prevent the removal of LUN0 until we are done with
* multi-threaded scsi_hba_enum_lsf_of_t().
*
* NOTE: scsi_unprobe is a noop, sd->sd_inq is valid until
* device_uninitchild - so sd_uninit_prevent keeps sd_inq valid
* by failing any device_uninitchild attempts.
*/
ret = NDI_SUCCESS;
sd->sd_uninit_prevent++;
sd->sd_uninit_prevent--;
} else
ret = NDI_FAILURE;
return (ret);
}
/* Config callout from scsi_hba_thread_taddrs */
static void
scsi_hba_taddr_config_thr(void *arg)
{
/* signal completion of this target thread to the HBA */
mutex_enter(&h->h_lock);
if (--h->h_thr_count == 0)
cv_broadcast(&h->h_cv);
mutex_exit(&h->h_lock);
/* free config thread data */
}
/*
* Enumerate all the children of the specified SCSI parallel interface (spi).
* An HBA associated with a non-parallel scsi bus should be using another bus
* level enumeration implementation (possibly their own) and calling
* scsi_hba_bus_config_taddr to do enumeration of devices associated with a
* particular target address.
*
* On an spi bus the targets are sequentially enumerated based on the
* width of the bus. We also take care to try to skip the HBAs own initiator
* id. See scsi_hba_enum_lsf_of_t() for LUN and secondary function enumeration.
*
* Return NDI_SUCCESS if we might have created a new node.
* Return NDI_FAILURE if we definitely did not create a new node.
*
* Note: At some point we may want to expose this interface in transport.h
* if we find an hba that implements bus_config but still uses spi-like target
* addresses.
*/
static int
{
int options;
int ntargets;
int id;
int tgt;
char **taddrs;
char **taddr;
char *tbuf;
/*
* Find the number of targets supported on the bus. Look at the per
* bus scsi-options property on the HBA node and check its
* SCSI_OPTIONS_WIDE setting.
*/
else
/*
* Find the initiator-id for the HBA so we can skip that. We get the
* cached value on the HBA node, established in scsi_hba_attach_setup.
* If we were unable to determine the id then we rely on the HBA to
* fail gracefully when asked to enumerate itself.
*/
"'scsi-initiator-id' bogus for %d target bus: %d",
id = -1;
}
/* form vector of target addresses */
/* skip initiator */
continue;
/* convert to string and enumerate the target address */
}
/* null terminate vector of target addresses */
/* configure vector of target addresses */
/* free vector of target addresses */
return (NDI_SUCCESS);
}
/*
* Transport independent bus_configone BUS_CONFIG_ONE implementation. Takes
* same arguments, minus op, as scsi_hba_bus_config(), tran_bus_config(),
* and scsi_hba_bus_config_spi().
*/
int
dev_info_t **childp)
{
int ret;
int circ;
char *lcp;
char nameaddr[SCSI_MAXNAMELEN];
int mt;
/* parse_name modifies arg1, we must duplicate "name@addr" */
/* verify the form of the node - we need an @addr */
/*
* nodes (no @addr) for legacy driver loading methods -
* ignore them.
*/
return (NDI_FAILURE);
}
/*
* Check to see if this is a non-scsi flavor configuration operation.
*/
/*
* Configure the child, and if we're successful return with
* active hold.
*/
}
/*
* The framework does not ensure the creation of driver.conf
* nodes prior to calling a nexus bus_config. For legacy
* support of driver.conf file nodes we want to create our
* driver.conf file children now so that we can detect if we
* are being asked to bus_configone one of these nodes.
*
* Needing driver.conf file nodes prior to bus config is unique
* to scsi_enumeration mixed mode (legacy driver.conf and
* dynamic SID node) support. There is no general need for the
* framework to make driver.conf children prior to bus_config.
*
* We enter our HBA (self) prior to scsi_device_config, and
* pass it our circ. The scsi_device_config may exit the
* HBA around scsi_probe() operations to allow for parallelism.
* This is done after the probe node "@addr" is available as a
* barrier to prevent parallel probes of the same device. The
* probe node is also configured in a way that it can't be
* removed by the framework until we are done with it.
*
* NOTE: The framework is currently preventing many parallel
* sibling operations (such as attaches), so the parallelism
* we are providing is of marginal use until that is improved.
* The most logical way to solve this would be to have separate
* target and lun nodes. This would be a large change in the
* format of /devices paths and is not being pursued at this
* time. The need for parallelism will become more of an issue
* We may want to eventually want a dual mode implementation,
* where the HBA determines if we should construct separate
* target and lun devinfo nodes.
*/
/*
* For bus_configone, we make sure that we can find LUN0
* non-existent LUN0 (if enabled in scsi_device_config) to
* cover all LUNs on the target. This is done to minimize the
* number of independent target selection timeouts that occur
* when a target with many LUNs is no longer accessible
* (powered off). This removes the need for target driver
* probe cache implementations.
*
* This optimization may not be desirable in a pure bridge
* environment where targets on the other side of the bridge
* show up as LUNs to the host. If we ever need to support
* such a configuration then we should consider implementing a
* SCSI_OPTIONS_ILUN0 bit.
*
* NOTE: we are *not* applying any target limitation filtering
* to bus_configone, which means that we are relying on the
* HBA tran_tgt_init entry point invoked by scsi_busctl_initchild
* to fail.
*/
if (lcp) {
/*
* With "tgt,lun[,sfunc]" addressing, multiple addressing levels
* have been compressed into single devinfo node unit-address.
* This presents a mismatch - there is no bus_config to discover
* LUNs below a specific target, the only choice is to
* BUS_CONFIG_ALL the HBA. To support BUS_CONFIG_ALL_LUNS below
* a specific target, a bus_configone with lun address of "*"
* triggers lun discovery below a target.
*/
"scsi-enumeration", scsi_enumeration);
mt, SE_BUSCONFIG);
return (NDI_FAILURE);
}
/* convert hex lun number from ascii */
/*
* configure ",0" lun first, saving off
* original lun characters.
*/
/* restore original lun */
/*
* Apply maxlun filtering.
*
* Future: We still have the kludged
* scsi_check_ss2_LUN_limit() filtering off
* scsi_probe() to catch bogus driver.conf
* entries.
*/
} else
}
}
/*
* configure the requested device if LUN0 exists or we were
* unable to determine the lun format to determine if LUN0
* exists.
*/
if (sd0) {
} else {
}
/*
* We know what we found, to reduce overhead we finish BUS_CONFIG_ONE
* processing without calling back to the frameworks
* ndi_busop_bus_config (unless we goto framework below).
*
* If the reference is to a driver name and we created a generic name
* (bound to that driver) we will still succeed. This is important
* for correctly resolving old drivername references to device that now
* uses a generic names across the transition to generic naming. This
* is effectively an internal implementation of the NDI_DRIVERNAME flag.
*
* We also need to special case the resolve_pathname OBP boot-device
* case (modrootloaded == 0) where reference is to a generic name but
* we created a legacy driver name node by returning just returning
* the node created.
*/
(modrootloaded == 0)) &&
/* device attached, return devinfo node with hold */
ret = NDI_SUCCESS;
} else {
/*
* In the process of failing we may have added nodes to the HBA
* (self), clearing DEVI_MADE_CHILDREN. To reduce the overhead
* associated with the frameworks reaction to this we clear the
* flag here.
*/
ret = NDI_FAILURE;
/*
* The framework may still be able to succeed with
* with its GENERIC_PROP code.
*/
if (flags & NDI_DRV_CONF_REPROBE)
}
return (ret);
}
/*
* Perform SCSI Parallel Interconnect bus_config
*/
static int
{
int ret;
int mt;
/*
* Enumerate scsi target devices: See if we are doing generic dynamic
* enumeration: if driver.conf has not specified the 'scsi-enumeration'
* knob then use the global scsi_enumeration knob.
*/
"scsi-enumeration", scsi_enumeration);
if ((mt & SCSI_ENUMERATION_ENABLE) == 0) {
/*
* Static driver.conf file enumeration:
*
* Force reprobe for BUS_CONFIG_ONE or when manually
* reconfiguring via devfsadm(1m) to emulate deferred attach.
* Reprobe only discovers driver.conf enumerated nodes, more
* dynamic implementations probably require their own
* bus_config.
*/
}
flags |= NDI_DEVI_DEBUG;
/*
* Generic spi dynamic bus config enumeration to discover and enumerate
* the target device nodes we are looking for.
*/
switch (op) {
case BUS_CONFIG_ONE: /* enumerate the named child */
break;
case BUS_CONFIG_ALL: /* enumerate all children on the bus */
case BUS_CONFIG_DRIVER: /* enumerate all children that bind to driver */
"BUS_CONFIG_%s mt %x",
/*
* Enumerate targets on SCSI parallel interconnect and let the
* framework finish the operation (attach the nodes).
*/
break;
default:
ret = NDI_FAILURE;
break;
}
return (ret);
}
/*
* Perform SCSI Parallel Interconnect bus_unconfig
*/
static int
{
int mt;
int circ;
int ret;
/*
* See if we are doing generic dynamic enumeration: if driver.conf has
* not specified the 'scsi-enumeration' knob then use the global
* scsi_enumeration knob.
*/
"scsi-enumeration", scsi_enumeration);
if ((mt & SCSI_ENUMERATION_ENABLE) == 0)
flags |= NDI_DEVI_DEBUG;
switch (op) {
case BUS_UNCONFIG_ONE:
"unconfig one: %s", (char *)arg));
ret = NDI_SUCCESS;
break;
case BUS_UNCONFIG_ALL:
case BUS_UNCONFIG_DRIVER:
ret = NDI_SUCCESS;
break;
default:
ret = NDI_FAILURE;
break;
}
/* Perform the generic default bus unconfig */
if (ret == NDI_SUCCESS)
return (ret);
}
static int
{
int ret = NDI_FAILURE;
switch (op) {
case BUS_CONFIG_ONE:
break;
case BUS_CONFIG_ALL:
case BUS_CONFIG_DRIVER:
break;
default:
break;
}
return (ret);
}
static int
{
int ret = NDI_FAILURE;
switch (op) {
case BUS_UNCONFIG_ONE:
case BUS_UNCONFIG_DRIVER:
case BUS_UNCONFIG_ALL:
ret = NDI_SUCCESS;
break;
default:
break;
}
if (ret == NDI_SUCCESS) {
flags &= ~NDI_DEVI_REMOVE;
}
return (ret);
}
static int
{
int circ;
int ret = NDI_FAILURE;
/*
* MPXIO is never a sure thing (and we have mixed children), so
* set NDI_NDI_FALLBACK so that ndi_busop_bus_config will
* search for both devinfo and pathinfo children.
*
* Future: Remove NDI_MDI_FALLBACK since devcfg.c now looks for
* looking for one form of child and then doing "fallback" to
* look for other form of child).
*/
switch (op) {
case BUS_CONFIG_ONE:
/* create the iport node child */
SE_BUSCONFIG)) != NULL) {
if (childp) {
}
ret = NDI_SUCCESS;
}
break;
case BUS_CONFIG_ALL:
case BUS_CONFIG_DRIVER:
break;
default:
break;
}
return (ret);
}
static int
{
flags &= ~NDI_DEVI_REMOVE;
}
/*
* SCSI HBA bus config enumeration entry point. Called via the bus_ops
* bus_config entry point for all SCSA HBA drivers.
*
* o If an HBA implements its own bus_config via tran_bus_config then we
* invoke it. An HBA that implements its own tran_bus_config entry point
* may still call back into common SCSA code bus_config code for:
*
* o SPI bus_config (scsi_hba_bus_spi)
* o LUN and secondary function enumeration (scsi_hba_enum_lsf_of_t()).
* o configuration of a specific device (scsi_device_config).
* o determining 1275 SCSI nodename and compatible property
* (scsi_hba_nodename_compatible_get/_free).
*
* o Otherwise we implement a SCSI parallel interface (spi) bus config.
*
* Return NDI_SUCCESS if we might have created a new node.
* Return NDI_FAILURE if we definitely did not create a new node.
*/
static int
{
int ret;
/* make sure that we will not disappear */
/* NULL tran driver.conf config (used by cmdk). */
}
/* Check if self is HBA-only node. */
/* The bus_config request is to configure iports below HBA. */
#ifdef sparc
/*
* Sparc's 'boot-device' OBP property value lacks an /iport@X/
* component. Prior to the mount of root, we drive a disk@
* BUS_CONFIG_ONE operatino down a level to resolve an
* OBP 'boot-device' path.
*
* Future: Add (modrootloaded == 0) below, and insure that
* all attempts bus_conf of 'bo_name' (in OBP form) occur
* prior to 'modrootloaded = 1;' assignment in vfs_mountroot.
*/
if ((op == BUS_CONFIG_ONE) &&
return (scsi_hba_bus_config_prom_node(self,
}
#endif /* sparc */
if (tran->tran_iportmap) {
/* config based on scsi_hba_iportmap API */
} else {
/* config based on 'iport_register' API */
}
return (ret);
}
if (tran->tran_bus_config) {
/* HBA config based on Sun-private/legacy tran_bus_config */
} else if (tran->tran_tgtmap) {
/* SCSAv3 config based on scsi_hba_tgtmap_*() API */
} else {
/* SCSA config based on SCSI Parallel Interconnect */
}
return (ret);
}
/*
* Called via the bus_ops bus_unconfig entry point for SCSI HBA drivers.
*/
static int
{
int circ;
int ret;
/* NULL tran driver.conf unconfig (used by cmdk). */
}
/*
* tran_bus_unconfig in case the unconfig implementation calls back
* into the common code at a different enumeration level, such a
*/
/* Check if self is HBA-only node. */
/* The bus_config request is to unconfigure iports below HBA. */
if (tran->tran_iportmap) {
/* unconfig based on scsi_hba_iportmap API */
}
return (ret);
}
if (tran->tran_bus_unconfig) {
/* HBA unconfig based on Sun-private/legacy tran_bus_unconfig */
} else if (tran->tran_tgtmap) {
/* SCSAv3 unconfig based on scsi_hba_tgtmap_*() API */
} else {
/* SCSA unconfig based on SCSI Parallel Interconnect */
}
return (ret);
}
static int
{
char *tgtaddr;
int cfg_status, mt;
"failed to create lunmap for %s", tgtaddr));
}
if (cfg_status != NDI_SUCCESS) {
return (DAM_FAILURE);
}
return (DAM_SUCCESS);
}
static int
{
char *tgt_addr;
tgt_addr));
return (DAM_SUCCESS);
}
static int
{
char *addr;
}
static int
{
char *addr;
char nameaddr[SCSI_MAXNAMELEN];
int circ;
return (DAM_SUCCESS);
}
if (ndi_devi_offline(child,
"devinfo smp@%s offlined and removed", addr));
} else if (ndi_devi_device_remove(child)) {
"devinfo smp@%s offline failed, device_remove",
addr));
}
return (DAM_SUCCESS);
}
/* ARGSUSED1 */
static void
void **tgt_privp)
{
if (tgtmap->tgtmap_activate_cb) {
tgt_addr));
}
}
/* ARGSUSED1 */
static void
{
if (tgtmap->tgtmap_deactivate_cb) {
if (damap_rsn == DAMAP_DEACT_RSN_GONE)
else if (damap_rsn == DAMAP_DEACT_RSN_CFG_FAIL)
else if (damap_rsn == DAMAP_DEACT_RSN_UNSTBL)
else {
"%s @%s deactivated with unknown rsn",
tgt_addr));
return;
}
if ((tgtmap_rsn == SCSI_TGT_DEACT_RSN_CFG_FAIL) &&
(tgtmap_rereport == B_FALSE)) {
"%s enumeration failed, no more retries until "
"config change occurs", tgt_addr));
}
}
}
/* ARGSUSED1 */
static void
void **tgt_privp)
{
if (tgtmap->tgtmap_activate_cb) {
tgt_addr));
}
}
/* ARGSUSED1 */
static void
{
if (tgtmap->tgtmap_deactivate_cb) {
if (damap_rsn == DAMAP_DEACT_RSN_GONE)
else if (damap_rsn == DAMAP_DEACT_RSN_CFG_FAIL)
else if (damap_rsn == DAMAP_DEACT_RSN_UNSTBL)
else {
"%s @%s deactivated with unknown rsn", damap_name(
tgt_addr));
return;
}
if ((tgtmap_rsn == SCSI_TGT_DEACT_RSN_CFG_FAIL) &&
(tgtmap_rereport == B_FALSE)) {
"%s enumeration failed, no more retries until "
"config change occurs", tgt_addr));
}
}
}
int
{
char context[64];
char *scsi_binding_set;
int optflags;
return (DDI_FAILURE);
return (DDI_FAILURE);
switch (mode) {
case SCSI_TM_FULLSET:
break;
case SCSI_TM_PERADDR:
break;
default:
return (DDI_FAILURE);
}
return (DDI_FAILURE);
&mapp) != DAM_SUCCESS) {
return (DDI_FAILURE);
}
&mapp) != DAM_SUCCESS) {
return (DDI_FAILURE);
}
/*
* We have now set tran_tgtmap, marking the tran as using tgtmap
* enumeration services. To prevent the generation of legacy spi
* 'binding-set' compatible forms, remove the 'scsi-binding-set'
* property.
*/
&scsi_binding_set) == DDI_PROP_SUCCESS) {
"scsi-binding-set");
}
return (DDI_SUCCESS);
}
void
{
int i;
for (i = 0; i < SCSI_TGT_NTYPES; i++) {
if (tgtmap->tgtmap_dam[i]) {
}
}
}
static int
{
int empty = 1;
int i;
for (i = 0; i < SCSI_TGT_NTYPES; i++) {
if (tgtmap->tgtmap_dam[i]) {
/* return 1 if all maps ended up empty */
}
}
return (empty);
}
static int
{
char *context;
int rv = DAM_SUCCESS;
int i;
for (i = 0; i < SCSI_TGT_NTYPES; i++) {
continue;
}
if (i == SCSI_TGT_SCSI_DEVICE) {
/*
* In scsi_device context, so we have the
* 'context' string, diagnose the case where
* the tgtmap caller is failing to make
* forward progress, i.e. the caller is never
* completing an observation, and calling
* scsi_hbg_tgtmap_set_end. If this occurs,
* of sync with hardware.
*/
if (tgtmap->tgtmap_reports++ >=
tgtmap->tgtmap_noisy++;
NULL, "%s: failing a tgtmap"
" observation", context));
}
}
}
} else {
}
if (rv != DAM_SUCCESS) {
} else {
}
}
}
int
{
}
int
{
}
int
{
return (DDI_FAILURE);
}
/*ARGSUSED*/
int
{
char *context;
int rv = DDI_SUCCESS;
int i;
for (i = 0; i < SCSI_TGT_NTYPES; i++) {
continue;
if (damap_addrset_end(
rv = DDI_FAILURE;
continue;
}
}
return (rv);
}
int
{
return (DDI_FAILURE);
}
int
{
return (DDI_FAILURE);
}
int
{
int i;
for (i = 0; i < SCSI_TGT_NTYPES; i++) {
*r_type = i;
"%s @%s found: type %d",
return (DDI_SUCCESS);
}
}
"%s%d.tgtmap @%s not found",
return (DDI_FAILURE);
}
/*
* Return the unit-address of an 'iport' node, or NULL for non-iport node.
*/
char *
{
/*
* NOTE: Since 'self' could be a SCSA iport node or a SCSA HBA node,
* we can't use SCSA flavors: the flavor of a SCSA HBA node is not
* established/owned by SCSA, it is established by the nexus that
* created the SCSA HBA node (PCI) as a child.
*
* NOTE: If we want to support a node_name other than "iport" for
* an iport node then we can add support for a "scsa-iport-node-name"
* property on the SCSA HBA node. A SCSA HBA driver would set this
* property on the SCSA HBA node prior to using the iport API.
*/
return (ddi_get_name_addr(self));
else
return (NULL);
}
/*
* support multiple SCSI ports, but only has a single HBA devinfo node. This
* function should be called from the HBA's attach(9E) implementation (when
* processing the HBA devinfo node attach) after the number of SCSI ports on
* the card is known or when the HBA driver DR handler detects a new port.
* The function returns 0 on failure and 1 on success.
*
* The implementation will add the port value into the "scsi-iports" property
* value maintained on the HBA node as. These properties are used by the generic
* scsi bus_config implementation to dynamicaly enumerate the specified iport
* children. The enumeration code will, on demand, create the appropriate
* iport children with a SCSI_ADDR_PROP_IPORTUA unit address. This node will
* bind to the same driver as the HBA node itself. This means that an HBA
* driver that uses iports should expect probe(9E), attach(9E), and detach(9E)
* calls on the iport children of the HBA. If configuration for all ports was
* already done during HBA node attach, the driver should just return
* DDI_SUCCESS when confronted with an iport node.
*
* A maximum of 32 iport ports are supported per HBA devinfo node.
*
* A NULL "port" can be used to indicate that the framework should enumerate
* target children on the HBA node itself, in addition to enumerating target
* children on any iport nodes declared. There are two reasons that an HBA may
* wish to have target children enumerated on both the HBA node and iport
* node(s):
*
* o If, in the past, HBA hardware had only a single physical port but now
* supports multiple physical ports, the updated driver that supports
* multiple physical ports may want to avoid /devices path upgrade issues
* by enumerating the first physical port under the HBA instead of as a
* iport.
*
* o Some hardware RAID HBA controllers (mlx, chs, etc) support multiple
* SCSI physical ports configured so that various physical devices on
* the physical ports are amalgamated into virtual devices on a virtual
* port. Amalgamated physical devices no longer appear to the host OS
* on the physical ports, but other non-amalgamated devices may still be
* visible on the physical ports. These drivers use a model where the
* physical ports are iport nodes and the HBA node is the virtual port to
* the configured virtual devices.
*/
int
{
unsigned int ports = 0;
int rval, i;
return (DDI_FAILURE);
&ports);
if (ports >= SCSI_HBA_MAX_IPORTS) {
return (DDI_FAILURE);
}
if (rval == DDI_PROP_SUCCESS) {
for (i = 0; i < ports; i++) {
/* iport already registered */
return (DDI_SUCCESS);
}
}
}
for (i = 0; i < ports; i++) {
}
ports++;
"failed to establish %s %s",
rval = DDI_FAILURE;
} else {
rval = DDI_SUCCESS;
}
/* If there is iport exist, free property */
if (ports > 1)
for (i = 0; i < ports; i++) {
}
return (rval);
}
/*
* Check if the HBA has any scsi_hba_iport_register()ed children.
*/
int
{
unsigned int ports = 0;
char **iports;
int rval;
&ports);
if (rval != DDI_PROP_SUCCESS)
return (0);
/* If there is now at least 1 iport, then iports is valid */
if (ports > 0) {
rval = 1;
} else
rval = 0;
return (rval);
}
{
char **iports;
unsigned int num_iports = 0;
int rval = DDI_FAILURE;
int i = 0;
/* check to see if this is an HBA that defined scsi iports */
&num_iports);
if (rval != DDI_SUCCESS) {
return (NULL);
}
ASSERT(num_iports > 0);
/* check to see if this port was registered */
for (i = 0; i < num_iports; i++) {
break;
}
if (i == num_iports) {
goto out;
}
if (rval != DDI_SUCCESS) {
}
out:
return (child);
}
/*
*/
static dev_info_t *
{
char *addr;
char *compat;
/*
* See if the iport node already exists.
*/
if (ndi_devi_device_isremoved(child)) {
if (ndi_devi_device_insert(child))
"devinfo iport@%s device_reinsert",
addr));
} else
return (NULL);
}
return (child);
}
/*
* If config based on scsi_hba_iportmap API, only allow create
* from hotplug.
*/
return (NULL);
/* allocate and initialize a new "iport" node */
&child);
/*
* Set the flavor of the child to be IPORT flavored
*/
/*
* Add the SCSI_ADDR_PROP_IPORTUA addressing property for this child.
* This property is used to identify a iport node, and to represent the
* nodes @addr form via node properties.
*
* Add "compatible" property to the "scsi-iport" node to cause it bind
* to the same driver as the HBA driver. Use the "driver" name
* instead of the "binding name" to distinguish from hw node.
*
* Give the HBA a chance, via tran_set_name_prop, to set additional
* iport node properties or to change the "compatible" binding
* prior to init_child.
*
* NOTE: the order of these operations is important so that
* scsi_hba_iport works when called.
*/
nameaddr));
(void) ddi_remove_child(child, 0);
} else {
/*
* create public names.
*/
(void) ndi_devi_free(child);
} else
}
return (child);
}
#ifdef sparc
/*
* Future: When iportmap boot support is added, consider rewriting this to
* perform a scsi_hba_bus_config(BUS_CONFIG_ALL) on self (HBA) followed by
* a scsi_hba_bus_config(BUS_CONFIG_ONE) on each child of self (each iport).
*/
/* ARGSUSED */
static int
{
char **iports;
int circ, i;
int ret = NDI_FAILURE;
unsigned int num_iports = 0;
/* check to see if this is an HBA that defined scsi iports */
&num_iports);
if (ret != DDI_SUCCESS) {
return (ret);
}
ASSERT(num_iports > 0);
ret = NDI_FAILURE;
for (i = 0; i < num_iports; i++) {
/* Prepend the iport name */
iports[i]);
NDI_SUCCESS) {
continue;
}
/*
* Try to configure child under iport see wehter
* request node is the child of the iport node
*/
NDI_NO_EVENT) == NDI_SUCCESS) {
ret = NDI_SUCCESS;
break;
}
}
}
return (ret);
}
#endif
/*
*/
static int
{
char **iports;
int circ, i;
int ret = NDI_FAILURE;
unsigned int num_iports = 0;
/* check to see if this is an HBA that defined scsi iports */
&num_iports);
if (ret != DDI_SUCCESS) {
return (ret);
}
ASSERT(num_iports > 0);
switch (op) {
case BUS_CONFIG_ONE:
/* return if this operation is not against an iport node */
ret = NDI_FAILURE;
return (ret);
}
/* parse the port number from "iport@%s" */
/* check to see if this port was registered */
for (i = 0; i < num_iports; i++) {
break;
}
if (i == num_iports) {
ret = NDI_FAILURE;
break;
}
/* create the iport node child */
ret = NDI_SUCCESS;
}
break;
case BUS_CONFIG_ALL:
case BUS_CONFIG_DRIVER:
for (i = 0; i < num_iports; i++) {
/* Prepend the iport name */
iports[i]);
}
ret = NDI_SUCCESS;
break;
}
if (ret == NDI_SUCCESS) {
#ifdef sparc
/*
* Mask NDI_PROMNAME since PROM doesn't have iport
* node at all.
*/
flags &= (~NDI_PROMNAME);
#endif
}
return (ret);
}
typedef struct impl_scsi_iportmap {
static int
{
int circ;
char nameaddr[SCSI_MAXNAMELEN];
char *iport_addr;
}
static int
{
char *addr;
char nameaddr[SCSI_MAXNAMELEN];
return (DAM_FAILURE);
}
/*
* tgtmap will trigger unconfigure of all
* targets on the iport.
*
* Future: This bit of code only works if the
* target map reporting style is are full
* reports and not per-address. Maybe we
* should plan on handling this by
* auto-unconfiguration when destroying the
* target map(s).
*/
/* wait for unconfigure */
if (empty) {
if (ndi_devi_offline(childp,
"devinfo iport@%s offlined and removed",
addr));
} else if (ndi_devi_device_remove(childp)) {
"devinfo iport@%s offline failed, "
"device_remove", addr));
}
}
}
int
{
char context[64];
return (DDI_FAILURE);
return (DDI_FAILURE);
return (DDI_FAILURE);
DAM_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
void
{
}
int
char *iport_addr, void *iport_priv)
{
}
int
char *iport_addr)
{
}
int
char *iport_addr)
{
"%s @%s found",
return (DDI_SUCCESS);
}
"%s @%s not found",
return (DDI_FAILURE);
}
static int
{
char *addr;
return (DAM_SUCCESS);
else
return (DAM_FAILURE);
}
static int
{
char *addr;
addr));
return (DAM_SUCCESS);
}
static int
{
char context[64];
int optflags;
"target %s not found", context));
return (DDI_FAILURE);
}
if (lundam) {
"lunmap %s already created", context));
return (DDI_FAILURE);
}
/* create lundam */
&lundam) != DAM_SUCCESS) {
"%s create failed, id %d ref %d",
return (DDI_FAILURE);
}
/*
* account for damap_id_prv_set below.
*/
return (DDI_SUCCESS);
}
static void
{
char context[64];
"target %s not found", context));
return;
}
"lunmap %s already destroyed", context));
return;
}
/*
* unconfigure of all LUNs on the target.
*/
/* release hold established by damap_lookup above */
/* release hold established since scsi_lunmap_create() */
}
static void
{
(void) damap_addrset_begin(lundam);
}
static int
{
char ua[SCSI_MAXNAMELEN];
/* make unit address string form of "@taddr,lun[,sfunc]" */
if (sfunc == -1)
else
}
static void
{
(void) damap_addrset_end(lundam, 0);
}
int
{
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*
* phymap implementation
*
* We manage the timed aggregation of phys into a phy map * by creating a
* SAS port construct (based upon 'name' of "local,remote" SAS addresses)
* upon the first link up. As time goes on additional phys may join that port.
* After an appropriate amount of settle time, we trigger the activation
* callback which will then take the resultant bit mask of phys (phymask) in
* the SAS port and use that to call back to the callback function
* provided by the additional caller.
*
* We cross check to make sure that phys only exist in one SAS port at a
* time by having soft state for each phy point back to the created
* SAS port.
*
* NOTE: Make SAS_PHY_UA_LEN max(SAS_PHY_PHYMASK_LEN, SAS_PHY_NAME_LEN)
* so we have enough space if sas_phymap_bitset2phymaskua phymask address
* is already in use, and we end up using port name as unit address.
*/
#if (SAS_PHY_PHYMASK_LEN > SAS_PHY_NAME_LEN)
#define SAS_PHY_UA_LEN SAS_PHY_PHYMASK_LEN
#else
#define SAS_PHY_UA_LEN SAS_PHY_NAME_LEN
#endif
typedef struct impl_sas_phymap {
void *phymap_phy2name;
/* Noisy phy information - ensure forward progress for noisy phys */
int phymap_phy_max; /* max phy# */
int phymap_reports; /* per period */
int phymap_reports_max; /* scales */
int phymap_phys_noisy; /* detected */
/* These are for callbacks to the consumer. */
void *phymap_private;
/* Detect noisy phy: max changes per stabilization period per phy. */
static int sas_phymap_phy_max_factor = 16;
/*
* Convert bitset into a unit-address string. The maximum string length would
* be the maximum number of phys, rounded up by 4 and divided by 4.
*/
static void
{
char *ptr;
int grp;
int cur;
grp = 4;
cur = 0;
do {
bit -= 1;
grp -= 1;
}
if (grp == 0) {
grp = 4;
*ptr = 0;
}
cur = 0;
}
} while (bit != 0);
*ptr++ = '0';
*ptr = 0;
}
}
static int
{
char *damn;
char *name;
char *ua;
void *ua_priv;
/* Get the name ("local,remote" address string) from damap. */
/* Get the bitset of phys currently forming the port. */
return (DAM_FAILURE);
}
/* allocate, get, and initialize name index of name2ua map */
DDI_SUCCESS) {
return (DAM_FAILURE);
}
return (DAM_FAILURE);
}
/* see if phymask ua index already allocated in ua2name map */
/*
* The 'phymask' sas_phymap_bitset2phymaskua ua is
* already in use. This means that original phys have
* formed into a new port, and that the original port
* still exists (it has migrated to some completely
* different set of phys). In this corner-case we use
* "local,remote" name as a 'temporary' unit address.
* Reset ua in name2ua map.
*/
if (name) {
/* The "local,remote" ua should be new... */
"%s: %s ua already configured",
return (DAM_SUCCESS);
}
}
/* allocate, get, and init ua index of ua2name map */
DDI_SUCCESS) {
return (DAM_FAILURE);
}
return (DAM_FAILURE);
}
/* set name in ua2name map */
if (phymap->phymap_acp) {
/*
* drop our lock and invoke the activation callback
*/
}
return (DAM_SUCCESS);
}
/*ARGSUSED*/
static int
{
char *damn;
char *ua;
void *ua_priv;
/* Get the name ("local,remote" address string) from damap. */
return (DAM_FAILURE);
}
if (phymap->phymap_dcp) {
}
/* delete ua<->name mappings */
return (DAM_SUCCESS);
}
int
{
char context[64];
return (DDI_FAILURE);
if (mode != PHYMAP_MODE_SIMPLE)
return (DDI_FAILURE);
goto fail;
SAS_PHY_NAME_LEN, SAS_PHY_NPHY) != 0)
goto fail;
sizeof (bitset_t), SAS_PHY_NPHY) != 0)
goto fail;
SAS_PHY_UA_LEN, SAS_PHY_NPHY) != 0)
goto fail;
SAS_PHY_NAME_LEN, SAS_PHY_NPHY) != 0)
goto fail;
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
void
{
char *context;
if (phymap->phymap_ua2name)
if (phymap->phymap_name2ua)
if (phymap->phymap_name2phys)
if (phymap->phymap_phy2name)
if (phymap->phymap_dam)
}
int
{
char port[SAS_PHY_NAME_LEN];
char *name;
int phy2name_allocated = 0;
int name2phys_allocated = 0;
int rv;
/* Create the SAS port name from the local and remote addresses. */
/* Check for conflict in phy2name map */
if (name) {
else
return (DDI_FAILURE);
}
/* allocate, get, and initialize phy index of phy2name map */
goto fail;
}
goto fail;
}
phy2name_allocated = 1;
name) != DDI_SUCCESS) {
goto fail;
}
goto fail;
}
name2phys_allocated = 1;
/* Initialize bitset of phys */
/* NOTE: no bitset_fini of phys needed */
}
/* Reflect 'add' in phys bitset. */
/* It is an error if the phy was already recorded. */
goto fail;
}
/*
* Check to see if we have a new phy_max for this map, and if so
* scale phymap_reports_max to the new number of phys.
*/
}
/*
* ever exceeds phymap_reports_max due to noisy phys, then report the
* noise and force stabilization by stopping reports into the damap.
*
* phymap->phymap_reports.
*/
rv = DDI_SUCCESS;
} else {
rv = DDI_FAILURE;
}
} else {
}
return (rv);
fail: if (phy2name_allocated)
if (name2phys_allocated)
return (DDI_FAILURE);
}
int
{
char *name;
int rv = DDI_FAILURE;
phymap->phymap_reports++;
/* Find and free phy index of phy2name map */
goto fail;
}
/* NOTE: always free phy index of phy2name map before return... */
/* Get bitset of phys currently associated with named port. */
goto fail;
}
/* Reflect 'rem' in phys bitset. */
/* It is an error if the phy wasn't one of the port's phys. */
goto fail;
}
/* If this was the last phy in the port, start the deactivate timer. */
if (bitset_is_null(phys) &&
} else {
goto fail;
}
}
rv = DDI_SUCCESS;
/* free phy index of phy2name map */
return (rv);
}
char *
{
char name[SAS_PHY_NAME_LEN];
char *ua;
return (ua);
}
void *
{
char *name;
if (name) {
}
}
return (ua_priv);
}
int
{
char *name;
int n = 0;
if (name) {
if (phys)
}
return (n);
}
{
char *name;
goto fail;
goto fail;
/* dup the phys and return */
return ((sas_phymap_phys_t *)cphys);
}
int
{
int phy;
if (phy != -1)
return (phy);
}
void
{
if (cphys) {
}
}
char *
{
char *name;
char *ua;
goto fail;
goto fail;
/* dup the ua and return */
return (rua);
}
void
sas_phymap_ua_free(char *ua)
{
if (ua)
}