scsi_hba.c revision ed141cfca535fc26451c4bd9a2cfb6172af449c2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Generic SCSI Host Bus Adapter interface implementation
*/
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
/*
* 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 */
/*
* Prototypes for static 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_info(
void *arg,
void **result);
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);
/* busops 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)() */
};
/*
* 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,
* the others are associated with increasing levels diagnostic/debug output.
* 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, might be:
*
*/
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 */
/* ^==0x5e, !==0x21, ?==0x3F */
/* 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*/
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];
else if (scsi_hba_log_fcif)
*f++ = (char)scsi_hba_log_fcif; /* add global fcif */
if (align)
else
if (func)
else
}
/*
* Called from _init() when loading "scsi" module
*/
void
{
}
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 structure. An HBA
* driver will then initialize the structure and then call
* scsi_hba_attach_setup.
*/
/*ARGSUSED*/
int flags)
{
/* allocate SCSA flavors for self */
if (tran) {
}
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
{
}
}
/*
* 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 DR handler once DR handler detects a new port added.
* 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-iport" 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++) {
return (DDI_SUCCESS);
}
}
}
for (i = 0; i < ports; i++) {
}
ports++;
rval = 1;
"Failed to establish scsi-iport %s", port));
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 is with scsi-iport under it
*/
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);
}
/*
* Common nexus teardown code: used by both scsi_hba_detach() on SCSA HBA node
* and iport_devctl_uninitchild() on a SCSA HBA iport node (and for failure
* cleanup). Undo scsa_nexus_setup in reverse order.
*/
static void
{
return;
/* Teardown FMA. */
}
}
/*
* Common nexus setup code: used by both scsi_hba_attach_setup() on SCSA HBA
* node and iport_devctl_initchild() 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 usiung 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 in any reason, SKIP.
*/
}
/* If SCSA responsible for for minor nodes, create :devctl minor. */
scsi_hba_open) ? 1 : 0;
DDI_SUCCESS))) {
"can't create devctl minor nodes"));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* Common tran teardown code: used by iport_devctl_uninitchild() 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.
*/
/*ARGSUSED*/
static void
{
return;
/*
* In the future, if PHCI was registered in the SCSA
* scsa_tran_teardown is able to unregiter PHCI
*/
}
static int
{
int scsa_minor;
int id;
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 nodes"));
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).
*/
#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)); \
}
/*
* Attach scsi configuration property parameters not already defined
* via driver.conf to this instance of the HBA using global variable
* value. Pulling things down from above us to use
* "DDI_PROP_NOTPROM | DDI_PROP_DONTPASS" for faster access.
*/
/*
* cache the scsi-initiator-id as an property defined further up
* the tree or defined by OBP on the HBA node so can use
* "DDI_PROP_NOTPROM | DDI_PROP_DONTPASS" during enumeration.
* We perform the same type of operation that an HBA driver would
* use to obtain the 'initiator-id' capability.
*/
if (id == -1)
"scsi-initiator-id", -1);
if (id != -1)
/* Establish 'initiator-interconnect-type' */
(tran->tran_interconnect_type > 0) &&
"initiator-interconnect-type",
!= DDI_PROP_SUCCESS) {
"failed to establish "
"'initiator-interconnect-type'"));
return (DDI_FAILURE);
}
}
/*
* In the future SCSA v3, PHCI could be registered in the SCSA
* here.
*/
return (DDI_SUCCESS);
fail:
return (DDI_FAILURE);
}
/*
* 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)
{
}
/*
* Called by an HBA to attach an instance of the driver.
*/
int
int flags)
{
/* Verify that we are a driver */
return (DDI_FAILURE);
return (DDI_FAILURE);
return (DDI_FAILURE);
/*
* Verify correct scsi_hba_tran_t form:
* o both or none of tran_get_name/tran_get_addr.
*/
return (DDI_FAILURE);
}
/*
* Save all the important HBA information that must be accessed
* later by scsi_hba_bus_ctl(), and scsi_hba_map().
*/
/* 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 kmem_cache, if needed */
if (tran->tran_setup_pkt) {
char tmp[96];
int hbalen;
int cmdlen = 0;
int statuslen = 0;
if (flags & SCSI_HBA_TRAN_CDB)
if (flags & SCSI_HBA_TRAN_SCB)
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.
*/
goto fail;
return (DDI_SUCCESS);
fail:
(void) scsi_hba_detach(self);
return (DDI_FAILURE);
}
/*
* Called by an HBA to detach an instance of the driver
*/
int
{
return (DDI_FAILURE);
return (DDI_FAILURE);
if (tran->tran_open_flag)
return (DDI_FAILURE);
/*
* XXX - scsi_transport.h states that these data fields should not be
* referenced by the HBA. However, to be consistent with
* scsi_hba_attach(), they are being reset.
*/
tran->tran_hba_flags = 0;
}
/* 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
*/
/*ARGSUSED*/
int flags)
{
/* allocate SCSA flavors for self */
}
void
{
}
int
{
return (DDI_FAILURE);
/*
* The owner of the this devinfo_t was responsible
* for informing the framework already about
* additional flavors.
*/
return (DDI_SUCCESS);
}
int
{
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*
* SMP child flavored functions
*/
static int
{
char *smp_wwn;
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
{
struct smp_device *smp;
char addr[SCSI_MAXNAMELEN];
return (DDI_FAILURE);
goto failure;
}
goto failure;
}
/* Prevent duplicate nodes. */
goto failure;
}
return (DDI_SUCCESS);
if (smp_wwn) {
}
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*
* Wrapper to scsi_get_name which takes a devinfo argument instead of a
* scsi_device structure.
*/
static int
{
/* nodes are named by tran_get_name or default "tgt,lun" */
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
static int
{
char ua[SCSI_MAXNAMELEN];
char ba[SCSI_MAXNAMELEN];
return (DDI_FAILURE);
/* get the unit_address and bus_addr information */
return (DDI_FAILURE);
}
else
"?%s%d at %s%d: unit-address %s: %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.
* 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
* o a dynamic SID mscsi 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_hba_name_child -> scsi_get_name -> tran_get_name: there is no
* requiremnt for the property names to be well-known.
*/
static int
{
struct scsi_device *sd;
int tgt = 0;
int lun = 0;
int sfunc = 0;
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.
*
* XXX need ndi_devi_has_properties(dip) type interface?
*
* XXX 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.
*/
if (ndi_dev_is_persistent_node(child) == 0) {
"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_hba_name_child and scsi_get_name) to
* produce the "@addr" name from addressing properties. Allocate and
* initialize scsi device structure.
*/
/*
* 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
* (accessable 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
/*
* binding_set. If spi this is based on scsi_options WIDE
* NLUNS some forms of lun limitation are based on the
* device @lun 0
*/
/*
* 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.
*/
/* 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;
}
/* set the node @addr string */
/* prevent sibling duplicates */
"init failed: detected duplicate %p", (void *)dup));
goto failure;
}
/* call HBA's target init entry point if it exists */
if ((*tran->tran_tgt_init)
"init failed: tran_tgt_init failed"));
goto failure;
}
}
return (DDI_SUCCESS);
if (tran_clone)
return (err); /* remove the node */
}
static int
{
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.
*/
if (tran->tran_tgt_free)
/*
* 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 (common/io/dktp/controller/ata/ata_disk.c) to deal
* with deallocation in its tran_tgt_free (setting sd_inq back
* to NULL) without upsetting the framework.
*/
}
if (tran_clone)
return (DDI_SUCCESS);
}
static int
{
char *iport;
return (DDI_FAILURE);
iport));
return (DDI_SUCCESS);
}
/* uninitchild SCSA iport 'child' node */
static int
{
return (DDI_SUCCESS);
}
/* initchild SCSA iport 'child' node */
static int
{
char addr[SCSI_MAXNAMELEN];
char *iport;
return (DDI_NOT_WELL_FORMED);
}
/* set the node @addr string */
/* Prevent duplicate nodes. */
return (DDI_FAILURE);
}
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.
*
* NOTE: Given our past history with SCSI_HBA_TRAN_CLONE (structure-copy tran
* per scsi_device), using structure-copy of tran at the iport level should
* not be a problem (the most risky thing is likely tran_hba_dip).
*/
static void
{
/* parent HBA node scsi_device tran is required */
return;
/* Allocate iport child's scsi_device transport vector */
return;
/* 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;
/* Clear SCSI_HBA_SCSA flags (except TA) */
/* 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: smp .vs. scsi */
switch (op) {
case DDI_CTLOPS_INITCHILD:
switch (child_flavor) {
case SCSA_FLAVOR_IPORT:
return (iport_busctl_initchild(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_initchild(child));
default:
return (scsi_busctl_initchild(child));
}
case DDI_CTLOPS_UNINITCHILD:
switch (child_flavor) {
case SCSA_FLAVOR_IPORT:
return (iport_busctl_uninitchild(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_uninitchild(child));
default:
return (scsi_busctl_uninitchild(child));
}
case DDI_CTLOPS_REPORTDEV:
switch (child_flavor) {
case SCSA_FLAVOR_IPORT:
return (iport_busctl_reportdev(child));
case SCSA_FLAVOR_SMP:
return (smp_busctl_reportdev(child));
default:
return (scsi_busctl_reportdev(child));
}
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) ?
/* XXX these should be handled */
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:
}
}
/*
* 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;
goto out;
}
goto out;
}
/* Ioctls for which the generic implementation suffices. */
switch (cmd) {
case DEVCTL_DEVICE_GETSTATE:
case DEVCTL_DEVICE_ONLINE:
case DEVCTL_DEVICE_OFFLINE:
case DEVCTL_DEVICE_REMOVE:
case DEVCTL_BUS_GETSTATE:
goto out;
}
/* read devctl ioctl data */
goto out;
}
/* Ioctls that require child identification */
switch (cmd) {
case DEVCTL_DEVICE_RESET:
/* child identification from unit-address */
goto out;
}
goto out;
}
break;
case DEVCTL_BUS_RESETALL:
/*
* Find a child's scsi_address so we can invoke tran_reset
* below.
*
* XXX If no child exists, one may to able to fake a child.
* This will be a enhancement for the future.
* For now, we fall back to BUS_RESET.
* XXX We sould be looking at node state to get one
* that is initialized...
*/
while (child) {
/* XXX verify scsi_device 'flavor' of child */
break;
}
}
break;
}
switch (cmd) {
case DEVCTL_DEVICE_RESET:
else {
/* XXX verify scsi_device 'flavor' of child */
RESET_TARGET) != 1))
}
break;
case DEVCTL_BUS_QUIESCE:
(bus_state == BUS_QUIESCED))
else
break;
case DEVCTL_BUS_UNQUIESCE:
(bus_state == BUS_ACTIVE))
else
break;
case DEVCTL_BUS_RESET:
break;
case DEVCTL_BUS_RESETALL:
} else {
if (sd) {
if ((*tran->tran_reset)
} else {
((*tran->tran_bus_reset)
}
}
break;
case DEVCTL_BUS_CONFIGURE:
}
break;
case DEVCTL_BUS_UNCONFIGURE:
if (ndi_devi_unconfig(self,
}
break;
default:
}
if (dcp)
if (self)
return (rv);
}
/*ARGSUSED*/
static int
{
}
static int
{
}
}
/*
* Return the lun from an address string. Either the lun is after the
* first ',' or the entire addr is the lun. Return SCSI_LUN64_ILLEGAL
* if the format is incorrect.
*
* If the addr specified has incorrect syntax (busconfig one of
* bogus /devices path) then scsi_addr_to_lun64 can return SCSI_LUN64_ILLEGAL.
*/
scsi_addr_to_lun64(char *addr)
{
char *s;
int i;
if (addr) {
if (s)
s++; /* skip ',' */
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 != ',')) /* addr,lun[,sfunc] is OK */
} else
if (lun64 == SCSI_LUN64_ILLEGAL)
"addr_to_lun64 %s lun %" PRIlun64,
return (lun64);
}
/*
* 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 embedded
* function command set.
*
* EE Same encoding used for DD. This form is
* only generated on secondary function
* nodes. The DD 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.
*
* 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 gf[sizeof ("R\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 */
#ifdef notdef
/*
* The following binding-set specific mappings are not being
* delivered at this time, but are listed here as an examples of
* the type of mappings needed.
*/
/* # 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"},
#endif /* notdef */
/*
* 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;
(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, carefull
* 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.
*/
i = 0;
(dtype_device == DTYPE_WORM) ||
(dtype_device == DTYPE_RODIRECT) ||
(dtype_device == DTYPE_OPTICAL)))
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;
}
}
}
/*
* If no nodename_aliases mapping exists then use the
* driver_aliases specified driver binding as a nodename.
* Determine the driver 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. 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()
*/
continue;
break;
}
}
/* 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;
}
}
*compatiblep = compatp;
*ncompatiblep = ncompat;
}
void
{
}
/*
* Free allocations associated with scsi_hba_nodename_compatible_get or
* scsi_hba_identity_nodename_compatible_get use.
*/
void
{
if (nodename)
if (compatible)
(NCOMPAT * COMPAT_LONGEST));
}
/* scsi_device property interfaces */
#define _TYPE_DEFINED(flags) \
/* return the unit_address associated with a scsi_device */
char *
{
return (NULL);
if (pip)
return (mdi_pi_get_addr(pip));
else
}
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
}
/*ARGSUSED*/
/*
*/
static dev_info_t *
{
char *mcompatible, *addr;
/*
* See if the iport node already exists.
*/
return (child);
}
/* allocate and initialize a new "iport" node */
/*
* Set the flavor of the child to be IPORT flavored
*/
/*
* Add the "scsi-iport" 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.
*
* 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.
*/
"scsi_hba_bus_config_port:%s failed dynamic decoration",
nameaddr));
(void) ddi_remove_child(child, 0);
} else {
(void) ndi_devi_free(child);
}
}
return (child);
}
#ifdef sparc
/* 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@%x"
* XXX use atoi (hex)
*/
/* 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 */
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);
}
/*ARGSUSED*/
static int
{
#ifdef sparc
switch (op) {
case BUS_CONFIG_ONE:
return (NDI_FAILURE);
break;
}
/*
* If this operation is not against an iport node, it's
* possible the operation is requested to configure
* root disk by OBP. Unfortunately, prom path is without
* iport string in the boot path.
*/
return (scsi_hba_bus_config_prom_node(self,
}
break;
default:
break;
}
#endif
/*
* The request is to configure multi-port HBA.
* Now start to configure iports, for the end
* devices attached to iport, should be configured
* by bus_configure routine of iport
*/
childp));
}
#ifdef sparc
if (scsi_hba_iport_unit_address(self)) {
flag &= (~NDI_PROMNAME);
}
#endif
}
/*
* 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.
*/
}
static int
void *arg)
{
}
}
void
{
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.
*/
}
}