devid_scsi.c revision f01c928d74ee0424b9f24da9c5d5b12d3bff6fbe
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* These functions are used to encode SCSI INQUIRY data into
* Solaris devid / guid values.
*/
#include <sys/isa_defs.h>
#include <sys/dditypes.h>
#include <sys/ddi_impldefs.h>
#include "devid_impl.h"
#define SCSI_INQUIRY_VID_POS 9
#define SCSI_INQUIRY_VID_SUN "SUN"
#define SCSI_INQUIRY_VID_SUN_LEN 3
#define SCSI_INQUIRY_VID_HITACHI "HITACHI"
#define SCSI_INQUIRY_VID_HITACHI_LEN 7
#define SCSI_INQUIRY_PID_HITACHI_OPEN "OPEN-"
#define SCSI_INQUIRY_PID_HITACHI_OPEN_LEN 5
#define SCSI_INQUIRY_VID_EMC "EMC "
#define SCSI_INQUIRY_VID_EMC_LEN 8
#define SCSI_INQUIRY_PID_EMC_SYMMETRIX "SYMMETRIX "
#define SCSI_INQUIRY_PID_EMC_SYMMETRIX_LEN 16
#define MSG_NOT_STANDARDS_COMPLIANT "!Page83 data not standards compliant "
#define MSG_NOT_STANDARDS_COMPLIANT_SIZE ( \
sizeof (MSG_NOT_STANDARDS_COMPLIANT) + \
(type == DEVID_SCSI_SERIAL))
/*
* The max inquiry page 83 size as expected in the code today
* is 0xf0 bytes. Defining a constant to make it easy incase
* this needs to be changed at a later time.
*/
#define SCMD_MAX_INQUIRY_PAGE83_SIZE 0xFF
#define SCMD_MIN_INQUIRY_PAGE83_SIZE 0x08
#define SCMD_INQUIRY_PAGE83_HDR_SIZE 4
#define SCSI_INQUIRY_PAGE83_EMC_SYMMETRIX_ID_LEN 16
#define SCMD_MAX_INQUIRY_PAGE80_SIZE 0xFF
#define SCMD_MIN_INQUIRY_PAGE80_SIZE 0x04
#define SCMD_MIN_STANDARD_INQUIRY_SIZE 0x04
#define SCMD_INQUIRY_PAGE83_IDENT_DESC_HDR_SIZE 4
#define SCMD_INQUIRY_VPD_TYPE_T10 0x01
#define SCMD_INQUIRY_VPD_TYPE_EUI 0x02
#define SCMD_INQUIRY_VPD_TYPE_NAA 0x03
#define SCMD_INQUIRY_VPD_TYPE_RTP 0x04
#define SCMD_INQUIRY_VPD_TYPE_TPG 0x05
#define SCMD_INQUIRY_VPD_TYPE_LUG 0x06
#define SCMD_INQUIRY_VPD_TYPE_MD5 0x07
#define SCMD_INQUIRY_VPD_TYPE_SSN 0x08
static int devid_scsi_init(char *driver_name,
/*
* Function: ddi_/devid_scsi_encode
*
* Description: This routine finds and encodes a unique devid
*
* Arguments: version - id encode algorithm version
* driver_name - binding driver name (if ! known use NULL)
* inq - standard inquiry buffer
* inq_len - standard inquiry buffer length
* inq80 - serial number inquiry buffer
* inq80_len - serial number inquiry buffer length
* inq83 - vpd inquiry buffer
* inq83_len - vpd inquiry buffer length
* devid - id returned
*
* Return Code: DEVID_SUCCESS - success
* DEVID_FAILURE - failure
* DEVID_RETRY - LUN is in a transitional state. A delay should
* occur and then this inquiry data should be re-acquired and
* this function should be called again.
*/
int
#ifdef _KERNEL
#else /* ! _KERNEL */
#endif /* _KERNEL */
int version, /* IN */
char *driver_name, /* IN */
{
int rval = DEVID_FAILURE;
#ifdef _KERNEL
#endif /* _KERNEL */
/* verify valid version */
if (version > DEVID_SCSI_ENCODE_VERSION_LATEST) {
return (rval);
}
/* make sure minimum inquiry bytes are available */
if (inq_len < SCMD_MIN_STANDARD_INQUIRY_SIZE) {
return (rval);
}
/*
* If 0x83 is availible, that is the best choice. Our next choice is
* 0x80. If neither are availible, we leave it to the caller to
* determine possible alternate ID, although discouraged. In the
* case of the target drivers they create a fabricated id which is
* stored in the acyl. The HBA drivers should avoid using an
* alternate id. Although has already created a hack of using the
* node wwn in some cases. Which needs to be carried forward for
* legacy reasons.
*/
/*
* Perform page 83 validation tests and report offenders.
* We cannot enforce the page 83 specification because
* many Sun partners (ex. HDS) do not conform to the
* standards yet.
*/
/*
* invalid page 83 data. bug 4939576 introduced
* handling for EMC non-standard data.
*/
SCSI_INQUIRY_VID_EMC_LEN) == 0) &&
SCSI_INQUIRY_PID_EMC_SYMMETRIX_LEN) == 0)) {
}
#ifdef _KERNEL
/*
* invalid page 83 data. Special hack for HDS
* specific device, to suppress the warning msg.
*/
SCSI_INQUIRY_VID_HITACHI_LEN) != 0) ||
SCSI_INQUIRY_PID_HITACHI_OPEN_LEN) != 0)) {
/*
* report the page 0x83 standards violation.
*/
msg = kmem_alloc(
KM_SLEEP);
sizeof (inq_std->inq_revision));
}
#endif /* _KERNEL */
}
if (id_type == DEVID_NONE) {
}
}
/*
* If no vpd page is available at this point then we
* attempt to use a SCSI serial number from page 0x80.
*/
if ((id_type == DEVID_NONE) &&
}
}
/*
* If no vpd page or serial is available at this point and
* it's a SUN disk it conforms to the disk qual. 850 specifications
* and we can fabricate a serial number id based on the standard
* inquiry page.
*/
if ((id_type == DEVID_NONE) &&
}
if (id_type != DEVID_NONE) {
} else {
rval = DEVID_RETRY;
}
}
return (rval);
}
/*
* Function: is_page83_data_valid
*
* Description: This routine is used to validate the page 0x83 data
* passed in valid based on the standards specification.
*
* Arguments: inq83 -
* inq83_len -
*
* Return Code: DEVID_RET_VALID
* DEVID_RET_INVALID
*
*/
static int
{
int covered_desc_len = 0;
int dlen = 0;
/* if not large enough fail */
return (DEVID_RET_INVALID);
/*
* Ensuring that the Peripheral device type(bits 0 - 4) has
* the valid settings - the value 0x1f indicates no device type.
* Only this value can be validated since all other fields are
* either used or reserved.
*/
/* failed-peripheral devtype */
return (DEVID_RET_INVALID);
}
/*
* Ensure that the page length field - third and 4th bytes
* contain a non zero length value. Our implementation
* does not seem to expect more that 255 bytes of data...
* what is to be done if the reported size is > 255 bytes?
* Yes the device will return only 255 bytes as we provide
* buffer to house only that much data but the standards
* prevent the targets from reporting the truncated size
* in this field.
*
* Currently reporting sizes more than 255 as failure.
*
*/
/* length field is 0! */
return (DEVID_RET_INVALID);
}
/* length field exceeds expected size of 255 bytes */
return (DEVID_RET_INVALID);
}
/*
* Validation of individual descriptor blocks are done in the
* following while loop. It is possible to have multiple
* descriptor blocks.
* the 'dblk' pointer will be pointing to the start of
* each entry of the descriptor block.
*/
covered_desc_len = 0;
/*
* Ensure that the length field is non zero
* Further length validations will be done
* along with the 'identifier type' as some of
* the lengths are dependent on it.
*/
if (dlen == 0) {
/* descr length is 0 */
return (DEVID_RET_INVALID);
}
/*
* ensure that the size of the descriptor block does
* not claim to be larger than the entire page83
* data that has been received.
*/
/* failed-descr length */
return (DEVID_RET_INVALID);
}
/*
* The spec says that if the PIV field is 0 OR the
* association field contains value other than 1 and 2,
* then the protocol identifier field should be ignored.
* If association field contains a value of 1 or 2
* and the PIV field is set, then the protocol identifier
* field has to be validated.
* The protocol identifier values 0 - f are either assigned
* or reserved. Nothing to validate here, hence skipping
* over to the next check.
*/
/*
* Check for valid code set values.
* All possible values are reserved or assigned. Nothing
* to validate - skipping over.
*/
/*
* Identifier Type validation
* All SPC3rev22 identified types and the expected lengths
* are validated.
*/
case SCMD_INQUIRY_VPD_TYPE_T10: /* T10 vendor Id */
/* No specific length validation required */
break;
case SCMD_INQUIRY_VPD_TYPE_EUI: /* EUI 64 ID */
/* EUI-64: size is expected to be 8, 12, or 16 bytes */
/* page83 validation failed-EIU64 */
return (DEVID_RET_INVALID);
}
break;
case SCMD_INQUIRY_VPD_TYPE_NAA: /* NAA Id type */
/*
* the size for this varies -
* IEEE extended/registered is 8 bytes
* IEEE Registered extended is 16 bytes
*/
case 0x20: /* IEEE Ext */
case 0x50: /* IEEE Reg */
if (dlen != 8) {
/* failed-IEE E/R len */
return (DEVID_RET_INVALID);
}
/*
* the codeSet for this MUST
* be set to 1
*/
/*
* failed-IEEE E/R
* codeSet != 1.
*/
return (DEVID_RET_INVALID);
}
break;
case 0x60: /* IEEE EXT REG */
if (dlen != 16) {
/* failed-IEEE ER len */
return (DEVID_RET_INVALID);
}
/*
* the codeSet for this MUST
* be set to 1
*/
/*
* failed-IEEE ER
* codeSet != 1.
*/
return (DEVID_RET_INVALID);
}
break;
default:
/* reserved values */
break;
}
break;
case SCMD_INQUIRY_VPD_TYPE_RTP: /* Relative Target port */
if (dlen != 4) {
/* failed-Rel target Port length */
return (DEVID_RET_INVALID);
}
break;
case SCMD_INQUIRY_VPD_TYPE_TPG: /* Target port group */
if (dlen != 4) {
/* failed-target Port group length */
return (DEVID_RET_INVALID);
}
break;
case SCMD_INQUIRY_VPD_TYPE_LUG: /* Logical unit group */
if (dlen != 4) {
/* failed-Logical Unit group length */
return (DEVID_RET_INVALID);
}
break;
case SCMD_INQUIRY_VPD_TYPE_MD5: /* MD5 unit group */
if (dlen != 16) {
/* failed-MD5 Unit grp */
return (DEVID_RET_INVALID);
}
break;
default:
break;
}
/*
* Now lets advance to the next descriptor block
* and validate it.
* the descriptor block size is <descr Header> + <descr Data>
* <descr Header> is equal to 4 bytes
* <descr Data> is available in dlen or dblk[3].
*/
/*
* update the covered_desc_len so that we can ensure that
* the 'while' loop terminates.
*/
}
return (DEVID_RET_VALID);
}
/*
* Function: is_initialized_id
*
* Description: Routine to ensure that the ID calculated is not a
* space or zero filled ID. Returning a space / zero
* filled ID when the luns on the target are not fully
* initialized is a valid response from the target as
* found its information needs to be polled again
* after sometime time to see if the luns are fully
* initialized to return a valid guid information.
*
* Arguments: id - raw id
* id_len - raw id len
*
* DEVID_INVALID - indicates id contains uninitialized data
* and suggests retry of the collection commands.
*/
static int
{
int idx;
(id_len == 0)) {
/* got id length as 0 fetch info again */
return (DEVID_RET_INVALID);
}
/* First lets check if the guid is filled with spaces */
break;
}
}
/*
* Lets exit if we find that it contains ALL spaces
* saying that it has an uninitialized guid
*/
/* guid filled with spaces found */
return (DEVID_RET_INVALID);
}
/*
* Since we have found that it is not filled with spaces
* now lets ensure that the guid is not filled with only
* zeros.
*/
return (DEVID_RET_VALID);
}
}
/* guid filled with zeros found */
return (DEVID_RET_INVALID);
}
/*
* Function: is_page80_data_valid
*
* Description: This routine is used to validate the page 0x80 data
* passed in valid based on the standards specification.
*
* Arguments: inq80 -
* inq80_len -
*
* Return Code: DEVID_RET_VALID
* DEVID_RET_INVALID
*
*/
/* ARGSUSED */
static int
{
/* if not large enough fail */
if (inq80_len < SCMD_MIN_INQUIRY_PAGE80_SIZE) {
return (DEVID_RET_INVALID);
}
/*
* (inq80_len - 4) is the size of the buffer space available
* for the product serial number. So inq80[3] (ie. product
* serial number) should be <= (inq80_len -4).
*/
return (DEVID_RET_INVALID);
}
return (DEVID_RET_VALID);
}
/*
* Function: encode_devid_page
*
* Description: This routine finds the unique devid if available and
* fills the devid and length parameters.
*
* Arguments: version - encode version
* inq83 - driver soft state (unit) structure
* inq83_len - length of raw inq83 data
* id - raw id
* id_len - len of raw id
* id_type - type of id
*
* Note: DEVID_NONE is returned in the id_type field
* if no supported page 83 id is found.
*/
static void
{
int idx = 0;
/* inq83 length was already validate in is_page83_valid */
/* preset defaults */
*id_len = 0;
*id_type = DEVID_NONE;
/* verify we have enough memory for a ident header */
if (inq83_len < SCMD_INQUIRY_PAGE83_HDR_SIZE) {
return;
}
/*
* Attempt to validate the page data. Once validated, we'll walk
* the descriptors, looking for certain identifier types that will
* for what we really want to receive.
*/
/*
* The format of the inq83 data (Device Identification VPD page) is
* a header (containing the total length of the page, from which
* descriptor_bytes_left is calculated), followed by a list of
* identification descriptors. Each identifcation descriptor has a
* header which includes the length of the individual identification
* descriptor).
*
* Set the offset to the beginning byte of the first identification
* descriptor. We'll index everything from there.
*/
/*
* If the raw data states that the data is larger
* than what is actually received abort encode.
* Otherwise we will run off into unknown memory
* on the decode.
*/
return;
}
/* Zero out our offset array */
/*
* According to the scsi spec 8.4.3 SPC-2, there could be several
* descriptors associated with each lun. Some we care about and some
* we don't. This loop is set up to iterate through the descriptors.
* We want the 0x03 case which represents an FC-PH, FC-PH3 or FC-FS
* Name_Identifier. The spec mentions nothing about ordering, so we
* don't assume any.
*
* We need to check if we've finished walking the list of descriptors,
* we also perform additional checks to be sure the newly calculated
* offset is within the bounds of the buffer, and the identifier length
* (as calculated by the length field in the header) is valid. This is
* done to protect against devices which return bad page83 data.
*/
/*
* Inspect the Identification descriptor list. Store the
* offsets in the devid page separately for 0x03, 0x01 and
* 0x02. Identifiers 0x00 and 0x04 are not useful as they
* don't represent unique identifiers for a lun. We also
* check the association by masking with 0x3f because we want
* an association of 0x0 - indicating the identifier field is
* associated with the addressed physical or logical device
* and not the port.
*/
break;
break;
break;
default:
/* Devid page undesired id type */
break;
}
/*
* Calculate the descriptor bytes left and move to
* the beginning byte of the next id descriptor.
*/
}
offset = 0;
/*
* We can't depend on an order from a device by identifier type, but
* once we have them, we'll walk them in the same order to prevent a
* firmware upgrade from breaking our algorithm. Start with the one
* we want the most: id_offset_type[3].
*/
if (offset_id_type[idx] > 0) {
break;
}
}
/*
* We have a valid Device ID page, set the length of the
* identifier and copy the value into the wwn.
*/
if (offset > 0) {
*id_len = 0;
return;
}
/* set devid type */
switch (version) {
/* In version 1 all page 83 types were grouped */
break;
/* In version 2 we break page 83 apart to be unique */
switch (idx) {
case 3:
break;
case 2:
break;
case 1:
break;
default:
*id_len = 0;
break;
}
break;
default:
*id_len = 0;
break;
}
}
}
/*
* Function: encode_scsi3_page83_emc
*
* Description: Routine to handle proprietary page 83 of EMC Symmetrix
* device. Called by ssfcp_handle_page83()
*
* Arguments: version - encode version
* inq83 - scsi page 83 buffer
* inq83_len - scsi page 83 buffer size
* id - raw emc id
* id_len - len of raw emc id
* id_type - type of emc id
*/
static void
{
/* preset defaults */
*id_len = 0;
*id_type = DEVID_NONE;
/* The initial devid algorithm didn't use EMC page 83 data */
if (version == DEVID_SCSI_ENCODE_VERSION1) {
return;
}
/* EMC page 83 requires atleast 20 bytes */
if (inq83_len < (SCMD_INQUIRY_PAGE83_HDR_SIZE +
return;
}
/*
* The 4th byte in the page 83 info returned is most likely
* indicating the length of the id - which 0x10(16 bytes)
* and the 5th byte is indicating that the id is of
* IEEE Registered Extended Name format(6). Validate
* these code prints before proceeding further as the
* following proprietary approach is tied to the specific
* device type and incase the EMC firmware changes, we will
* have to validate for the changed device before we start
* supporting such a device.
*/
/* unsupported emc symtx device type */
return;
} else {
/*
* The GUID returned by the EMC device is
* in the IEEE Registered Extended Name format(6)
* as a result it is of 16 bytes in length.
* An IEEE Registered Name format(5) will be of
* 8 bytes which is NOT what is being returned
* by the device type for which we are providing
* the support.
*/
*id_len = 0;
return;
}
/* emc id matches type 3 */
}
}
/*
* Function: encode_serialnum
*
* Description: This routine finds the unique devid from the inquiry page
* 0x80, serial number page. If available and fills the wwn
* and length parameters.
*
* Arguments: version - encode version
* inq - standard inquiry data
* inq80 - serial inquiry data
* inq80_len - serial inquiry data len
* id - raw id
* id_len - raw id len
* id_type - raw id type
*/
/* ARGSUSED */
static void
{
int idx = 0;
/* preset defaults */
*id_len = 0;
*id_type = DEVID_NONE;
/* verify inq80 buffer is large enough for a header */
if (inq80_len < SCMD_MIN_INQUIRY_PAGE80_SIZE) {
return;
}
/*
* Attempt to validate the page data. Once validated, we'll check
* the serial number.
*/
/* verify buffer is large enough for serial number */
return;
}
/*
* Device returns ASCII space (20h) in all the bytes of successful data
* transfer, if the product serial number is not available. So we end
* up having to check all the bytes for a space until we reach
* something else.
*/
continue;
}
/*
* The serial number is valid, but since this is only vendor
* unique, we'll combine the inquiry vid and pid with the
* serial number.
*/
*id_len = 0;
return;
}
break;
}
/*
* The spec suggests that the command could succeed but return all
* spaces if the product serial number is not available. In this case
* we need to fail this routine. To accomplish this, we compare our
* length to the serial number length. If they are the same, then we
* never copied in the vid and updated the length. That being the case,
* we must not have found a valid serial number.
*/
/* empty unit serial number */
}
*id_len = 0;
}
}
/*
* Function: encode_sun_serialnum
*
* Description: This routine finds the unique devid from the inquiry page
* 0x80, serial number page. If available and fills the wwn
* and length parameters.
*
* Arguments: version - encode version
* inq - standard inquiry data
* inq_len - standard inquiry data len
* id - raw id
* id_len - raw id len
* id_type - raw id type
*
* Return Code: DEVID_SUCCESS
* DEVID_FAILURE
*/
/* ARGSUSED */
static void
{
/* verify enough buffer is available */
if (inq_len < SCMD_MIN_STANDARD_INQUIRY_SIZE) {
return;
}
/* sun qual drive */
SCSI_INQUIRY_VID_SUN, SCSI_INQUIRY_VID_SUN_LEN) == 0)) {
/*
* VPD pages 0x83 and 0x80 are unavailable. This
* is a Sun qualified disks as indicated by
* "SUN" in bytes 25-27 of the inquiry data
* (bytes 9-11 of the pid). Devid's are created
* for Sun qualified disks by combining the
* vendor id with the product id with the serial
* number located in bytes 36-47 of the inquiry data.
*/
/* get data size */
sizeof (inq_std->inq_serial);
*id_len = 0;
return;
}
/* copy the vid at the beginning */
/* copy the pid after the vid */
/* copy the serial number after the vid and pid */
sizeof (inq_std->inq_serial));
/* devid formed from inquiry data */
}
}
/*
* Function: devid_scsi_init
*
* Description: This routine is used to create a devid for a scsi
* devid type.
*
* Arguments: hint - driver soft state (unit) structure
* raw_id - pass by reference variable to hold wwn
* raw_id_len - wwn length
* raw_id_type -
* ret_devid -
*
* Return Code: DEVID_SUCCESS
* DEVID_FAILURE
*
*/
static int
char *driver_name,
{
int i_devid_len = 0;
int driver_name_len = 0;
ushort_t u_raw_id_len = 0;
if (!IS_DEVID_SCSI_TYPE(raw_id_type)) {
return (DEVID_FAILURE);
}
return (DEVID_FAILURE);
}
/* Fill in driver name hint */
if (driver_name != NULL) {
if (driver_name_len > DEVID_HINT_SIZE) {
/* Pick up last four characters of driver name */
}
} else {
}
/* return device id */
return (DEVID_SUCCESS);
}
/*
* Function: devid_to_guid
*
* Description: This routine extracts a guid string form a devid.
* The common use of this guid is for a HBA driver
* to pass into mdi_pi_alloc().
*
* Arguments: devid - devid to extract guid from
*
* Return Code: guid string - success
* NULL - failure
*/
char *
#ifdef _KERNEL
#else /* !_KERNEL */
#endif /* _KERNEL */
{
int len = 0;
int idx = 0;
int num = 0;
/* NULL devid -> NULL guid */
return (NULL);
return (NULL);
/* guid is always converted to ascii, append NULL */
/* allocate guid string */
return (NULL);
/* perform encode of id to hex string */
}
*ptr = 0;
return (guid);
}
/*
* Function: devid_free_guid
*
* Description: This routine frees a guid allocated by
* devid_to_guid().
*
* Arguments: guid - guid to free
*/
void
#ifdef _KERNEL
ddi_devid_free_guid(char *guid)
#else /* !_KERNEL */
devid_free_guid(char *guid)
#endif /* _KERNEL */
{
}
}