scsi_serial.c revision ab261e1226efac3d47b2dc4a0e0165aeb8bb528e
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Copyright (C) IBM Corp. 2003
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Author: Patrick Mansfield<patmans@us.ibm.com>
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * This program is free software: you can redistribute it and/or modify
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * it under the terms of the GNU General Public License as published by
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * the Free Software Foundation, either version 2 of the License, or
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * (at your option) any later version.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * This program is distributed in the hope that it will be useful,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * but WITHOUT ANY WARRANTY; without even the implied warranty of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * GNU General Public License for more details.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * You should have received a copy of the GNU General Public License
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * along with this program. If not, see <http://www.gnu.org/licenses/>.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * A priority based list of id, naa, and binary/ascii for the identifier
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * descriptor in VPD page 0x83.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Brute force search for a match starting with the first value in the
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * following id_search_list. This is not a performance issue, since there
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * is normally one or some small number of descriptors.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic const struct scsi_id_search_values id_search_list[] = {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_TGTGROUP, SCSI_ID_NAA_DONT_CARE, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_IEEE_REG_EXTENDED, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_IEEE_REG_EXTENDED, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_IEEE_REG, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_IEEE_REG, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Devices already exist using NAA values that are now marked
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * reserved. These should not conflict with other values, or it is
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * a bug in the device. As long as we find the IEEE extended one
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * first, we really don't care what other ones are used. Using
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * don't care here means that a device that returns multiple
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * non-IEEE descriptors in a random order will get different
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_DONT_CARE, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_NAA, SCSI_ID_NAA_DONT_CARE, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_EUI_64, SCSI_ID_NAA_DONT_CARE, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_EUI_64, SCSI_ID_NAA_DONT_CARE, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_T10_VENDOR, SCSI_ID_NAA_DONT_CARE, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_T10_VENDOR, SCSI_ID_NAA_DONT_CARE, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_VENDOR_SPECIFIC, SCSI_ID_NAA_DONT_CARE, SCSI_ID_BINARY },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen { SCSI_ID_VENDOR_SPECIFIC, SCSI_ID_NAA_DONT_CARE, SCSI_ID_ASCII },
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic const char hex_str[]="0123456789abcdef";
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Values returned in the result/status, only the ones used by the code
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * are used here.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define DID_NO_CONNECT 0x01 /* Unable to connect before timeout */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define DID_BUS_BUSY 0x02 /* Bus remain busy until timeout */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define DID_TIME_OUT 0x03 /* Timed out for some other reason */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define DRIVER_SENSE 0x08 /* Sense_buffer has been set */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/* The following "category" function returns one of the following */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_CLEAN 0 /* No errors or other information */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_MEDIA_CHANGED 1 /* interpreted from sense buffer */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_RESET 2 /* interpreted from sense buffer */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_RECOVERED 4 /* Successful command after recovered err */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_NOTSUPPORTED 5 /* Illegal / unsupported command */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_SENSE 98 /* Something else in the sense buffer */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#define SG_ERR_CAT_OTHER 99 /* Some other error/warning */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int do_scsi_page80_inquiry(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *serial, char *serial_short, int max_len);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int sg_err_category_new(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * XXX change to return only two values - failed or OK.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!scsi_status && !host_status && !driver_status)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned char asc;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int sg_err_category3(struct udev *udev, struct sg_io_hdr *hp)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int sg_err_category4(struct udev *udev, struct sg_io_v4 *hp)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return sg_err_category_new(udev, hp->device_status, 0,
52d629010db73a9466c359201916494bd55186d1Tom Gundersen * Figure out and print the sense key, asc and ascq.
52d629010db73a9466c359201916494bd55186d1Tom Gundersen * If you want to suppress these for a particular drive model, add
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * a black list entry in the scsi_id config file.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * XXX We probably need to: lookup the sense/asc/ascq in a retry
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * table, and if found return 1 (after dumping the sense, asc, and
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * ascq). So, if/when we get something like a power on/reset,
52d629010db73a9466c359201916494bd55186d1Tom Gundersen * we'll retry the command.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense buffer empty\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * extended sense data.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (s < 14) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense result too" " small %d bytes\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: old sense key: 0x%x\n", dev_scsi->kernel, sense_buffer[0] & 0x0f);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_scsi->kernel, sense_buffer[0], sense_buffer[2]);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: non-extended sense class %d code 0x%0x\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for (i = 0, j = 0; (i < s) && (j < 254); i++) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen out_buffer[j++] = hex_str[(sense_buffer[i] & 0xf0) >> 4];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen out_buffer[j++] = hex_str[sense_buffer[i] & 0x0f];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sense dump:\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: %s\n", dev_scsi->kernel, out_buffer);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen struct scsi_id_device *dev_scsi, struct sg_io_hdr *io)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!io->status && !io->host_status && !io->msg_status &&
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Impossible, should not be called.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: called with no error\n", __FUNCTION__);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_scsi->kernel, io->driver_status, io->host_status, io->msg_status, io->status);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return scsi_dump_sense(udev, dev_scsi, io->sbp, io->sb_len_wr);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen struct scsi_id_device *dev_scsi, struct sg_io_v4 *io)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!io->device_status && !io->transport_status &&
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Impossible, should not be called.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: called with no error\n", __FUNCTION__);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_scsi->kernel, io->driver_status, io->transport_status,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (io->device_status == SCSI_CHECK_CONDITION)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return scsi_dump_sense(udev, dev_scsi, (unsigned char *)(uintptr_t)io->response,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if ((errno == EINVAL || errno == ENOSYS) && dev_scsi->use_sg == 4) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* Fallthrough */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = scsi_dump_v4(udev, dev_scsi, io_buf);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen } else if (retval > 0) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/* Get list of supported EVPD pages */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int do_scsi_page0_inquiry(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = scsi_inquiry(udev, dev_scsi, fd, 1, 0x0, buffer, len);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: page 0 not available.\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: page 0 buffer too long %d\n", dev_scsi->kernel, buffer[3]);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Following check is based on code once included in the 2.5.x
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Some ill behaved devices return the standard inquiry here
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * rather than the evpd data, snoop the data to verify.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * If the vendor id appears in the page assume the page is
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!strncmp((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: invalid page0 data\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * The caller checks that serial is long enough to include the vendor +
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int prepend_vendor_model(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen struct scsi_id_device *dev_scsi, char *serial)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen strncpy(serial, dev_scsi->vendor, VENDOR_LENGTH);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen strncat(serial, dev_scsi->model, MODEL_LENGTH);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * This is not a complete check, since we are using strncat/cpy
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * above, ind will never be too large.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: expected length %d, got length %d\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * check_fill_0x83_id - check the page 0x83 id, if OK allocate and fill
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * serial number.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int check_fill_0x83_id(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned char *page_83,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen int i, j, s, len;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * ASSOCIATION must be with the device (value 0)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * or with the target port for SCSI_ID_TGTPORT
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if ((page_83[1] & 0x0f) != id_search->id_type)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Possibly check NAA sub-type.
7141e4f62c3f220872df3114c42d9e4b9525e43eTom Gundersen if ((id_search->naa_type != SCSI_ID_NAA_DONT_CARE) &&
7141e4f62c3f220872df3114c42d9e4b9525e43eTom Gundersen (id_search->naa_type != (page_83[4] & 0xf0) >> 4))
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Check for matching code set - ASCII or BINARY.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if ((page_83[0] & 0x0f) != id_search->code_set)
bba061662b0f759abb43bad60c9733305c191045Tom Gundersen * page_83[3]: identifier length
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * If not ASCII, use two bytes for each binary value.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Add one byte for the NUL termination, and one for the id_type.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: length %d too short - need %d\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (id_search->id_type == SCSI_ID_TGTGROUP && tgpt_group != NULL) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned int group;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen group = ((unsigned int)page_83[6] << 8) | page_83[7];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * For SCSI_ID_VENDOR_SPECIFIC prepend the vendor and model before
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * the id since it is not unique across all vendors and models,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * this differs from SCSI_ID_T10_VENDOR, where the vendor is
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * included in the identifier.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen i = 4; /* offset to the start of the identifier */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * ASCII descriptor.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Binary descriptor, convert to ASCII, using two bytes of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * ASCII for each byte in the page_83.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen serial[j++] = hex_str[(page_83[i] & 0xf0) >> 4];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen strncpy(wwn_vendor_extension, &serial[s + 16], 16);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/* Extract the raw binary from VPD 0x83 pre-SPC devices */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int check_fill_0x83_prespc3(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned char *page_83,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen *id_search, char *serial, char *serial_short, int max_len)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* serial has been memset to zero before */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for (i = 0; (i < page_83[3]) && (j < max_len-3); ++i) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen serial[j++] = hex_str[(page_83[4+i] & 0xf0) >> 4];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/* Get device identification VPD page */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int do_scsi_page83_inquiry(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned int id_ind, j;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* also pick up the page 80 serial number */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen do_scsi_page80_inquiry(udev, dev_scsi, fd, NULL, unit_serial_number, MAX_SERIAL_LEN);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_83, page_83,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * XXX Some devices (IBM 3542) return all spaces for an identifier if
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * the LUN is not actually configured. This leads to identifiers of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * the form: "1 ".
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Model 4, 5, and (some) model 6 EMC Symmetrix devices return
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * a page 83 reply according to SCSI-2 format instead of SPC-2/3.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * The SCSI-2 page 83 format returns an IEEE WWN in binary
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * encoded hexi-decimal in the 16 bytes following the initial
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * 4-byte page 83 reply header.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Both the SPC-2 and SPC-3 formats return an IEEE WWN as part
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * of an Identification descriptor. The 3rd byte of the first
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Identification descriptor is a reserved (BSZ) byte field.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Reference the 7th byte of the page 83 reply to determine
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * whether the reply is compliant with SCSI-2 or SPC-2/3
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * specifications. A zero value in the 7th byte indicates
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * an SPC-2/3 conformant reply, (i.e., the reserved field of the
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * first Identification descriptor). This byte will be non-zero
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * for a SCSI-2 conformant page 83 reply from these EMC
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Symmetrix models since the 7th byte of the reply corresponds
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * to the 4th and 5th nibbles of the 6-byte OUI for EMC, that is,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Search for a match in the prioritized id_search_list - since WWN ids
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * come first we can pick up the WWN in check_fill_0x83_id().
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen id_ind < sizeof(id_search_list)/sizeof(id_search_list[0]);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Examine each descriptor returned. There is normally only
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * one or a small number of descriptors.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for (j = 4; j <= (unsigned int)page_83[3] + 3; j += page_83[j + 3] + 4) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen else if (retval < 0)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Get device identification VPD page for older SCSI-2 device which is not
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * compliant with either SPC-2 or SPC-3 format.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Return the hard coded error code value 2 if the page 83 reply is not
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * conformant to the SCSI-2 format.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int do_scsi_page83_prespc3_inquiry(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_83, page_83, SCSI_INQ_BUFF_LEN);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Model 4, 5, and (some) model 6 EMC Symmetrix devices return
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * a page 83 reply according to SCSI-2 format instead of SPC-2/3.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * The SCSI-2 page 83 format returns an IEEE WWN in binary
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * encoded hexi-decimal in the 16 bytes following the initial
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * 4-byte page 83 reply header.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Both the SPC-2 and SPC-3 formats return an IEEE WWN as part
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * of an Identification descriptor. The 3rd byte of the first
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Identification descriptor is a reserved (BSZ) byte field.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Reference the 7th byte of the page 83 reply to determine
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * whether the reply is compliant with SCSI-2 or SPC-2/3
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * specifications. A zero value in the 7th byte indicates
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * an SPC-2/3 conformant reply, (i.e., the reserved field of the
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * first Identification descriptor). This byte will be non-zero
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * for a SCSI-2 conformant page 83 reply from these EMC
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Symmetrix models since the 7th byte of the reply corresponds
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * to the 4th and 5th nibbles of the 6-byte OUI for EMC, that is,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen serial[0] = hex_str[id_search_list[0].id_type];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * The first four bytes contain data, not a descriptor.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Binary descriptor, convert to ASCII,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * using two bytes of ASCII for each byte
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * in the page_83.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen serial[j++] = hex_str[(page_83[i] & 0xf0) >> 4];
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/* Get unit serial number VPD page */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int do_scsi_page80_inquiry(struct udev *udev,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *serial, char *serial_short, int max_len)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = scsi_inquiry(udev, dev_scsi, fd, 1, PAGE_80, buf, SCSI_INQ_BUFF_LEN);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: Invalid page 0x80\n", dev_scsi->kernel);
85091685af65831f379580c75b40776c20e245eeTom Gundersen len = 1 + VENDOR_LENGTH + MODEL_LENGTH + buf[3];
4189708ad0cde8e211e38d27de943579772f8869Tom Gundersen log_debug("%s: length %d too short - need %d\n",
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Prepend 'S' to avoid unlikely collision with page 0x83 vendor
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * specific type where we prepend '0' + vendor + model.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ser_ind = prepend_vendor_model(udev, dev_scsi, &serial[1]);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen struct scsi_id_device *dev_scsi, const char *devname)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen sprintf(dev_scsi->kernel,"%d:%d", major(statbuf.st_rdev),
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen err = scsi_inquiry(udev, dev_scsi, fd, 0, 0, buf, SCSI_INQ_BUFF_LEN);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen struct scsi_id_device *dev_scsi, const char *devname,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen duration.tv_nsec = (200 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (do_scsi_page80_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (do_scsi_page83_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen retval = do_scsi_page83_prespc3_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Fallback to servicing a SPC-2/3 compliant page 83
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * inquiry if the page 83 reply format does not
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * conform to pre-SPC3 expectations.
7283a80d10217b929acf58899f016ca06dacdc53Tom Gundersen if (do_scsi_page83_inquiry(udev, dev_scsi, fd, dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("%s: unsupported page code 0x%d\n", dev_scsi->kernel, page_code);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Get page 0, the page of the pages. By default, try from best to
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * worst of supported pages: 0x83 then 0x80.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (do_scsi_page0_inquiry(udev, dev_scsi, fd, page0, SCSI_INQ_BUFF_LEN)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * Don't try anything else. Black list if a specific page
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * should be used for this vendor+model, or maybe have an
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen * optional fall-back to page 0x80 or page 0x83.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!do_scsi_page83_inquiry(udev, dev_scsi, fd,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_scsi->serial, dev_scsi->serial_short, len, dev_scsi->unit_serial_number, dev_scsi->wwn, dev_scsi->wwn_vendor_extension, dev_scsi->tgpt_group)) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (!do_scsi_page80_inquiry(udev, dev_scsi, fd,