2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A/*
2N/A *
2N/A * This module is part of the photon Command Line
2N/A * Interface program.
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * I18N message number ranges
2N/A * This file: 11500 - 11999
2N/A * Shared common messages: 1 - 1999
2N/A */
2N/A
2N/A/* #define _POSIX_SOURCE 1 */
2N/A
2N/A/* Includes */
2N/A#include <stdlib.h>
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <sys/file.h>
2N/A#include <sys/types.h>
2N/A#include <fcntl.h>
2N/A#include <sys/sunddi.h>
2N/A#include <sys/systm.h>
2N/A#include <sys/scsi/scsi.h>
2N/A#include <nl_types.h>
2N/A#include <unistd.h>
2N/A#include <l_common.h>
2N/A#include <stgcom.h>
2N/A#include <l_error.h>
2N/A#include <g_state.h>
2N/A#include <errno.h>
2N/A#include <devid.h>
2N/A#include <libdevinfo.h>
2N/A
2N/A
2N/A/* Defines */
2N/A/* Because of a bug in Unisys Envsen card, Bug ID:1266986. */
2N/A#define SCSI_ESI_PCV 0x01 /* Page Code Valid */
2N/A#define SCSI_ESI_PF 0x10 /* Page Format */
2N/A#define ACTION_MASK 0x1f /* Persistent Reserve In command */
2N/A#define IMMED 1 /* make the stop immediate */
2N/A#define DAK_PROD_STR "SUNWGS INT FCBPL"
2N/A#define DAK_BOXNAME_LEN 16 /* The length of the daktari boxname */
2N/A#define DAK_BOXNAME_OFF 36 /* The offset of the daktari boxname */
2N/A
2N/A
2N/A
2N/A/* Global variables */
2N/Aextern nl_catd l_catd;
2N/A
2N/A
2N/A/* Forward declarations */
2N/Astatic int scsi_read_capacity_16_cmd(int, struct scsi_capacity_16 *, int);
2N/A
2N/A
2N/A/* External functions */
2N/A
2N/A
2N/Aint
2N/Ag_scsi_persistent_reserve_in_cmd(int fd, uchar_t *buf_ptr,
2N/A int buf_len, uchar_t action)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_PERS_RESERV_IN, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.byte1 = action & ACTION_MASK;
2N/A cdb.byte7 = (buf_len>>8) & 0xff;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A
2N/A if (buf_len & 0x03) {
2N/A return (L_PR_INVLD_TRNSFR_LEN);
2N/A }
2N/A /* Do in SILENT mode as cmd may not be supported. */
2N/A return (cmd(fd, &ucmd, USCSI_READ | USCSI_SILENT));
2N/A}
2N/A/*
2N/A * Send Diagnostic command
2N/A *
2N/A * NOTE: This function includes a delay.
2N/A */
2N/Aint
2N/Ag_scsi_send_diag_cmd(int fd, uchar_t *buf_ptr, int buf_len)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Auchar_t cdb[] = {SCMD_SDIAG, SCSI_ESI_PF, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/Aint err;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb[3] = (buf_len>>8) & 0xff;
2N/A cdb[4] = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A
2N/A if (err = cmd(fd, &ucmd, USCSI_WRITE)) {
2N/A return (err);
2N/A }
2N/A /*
2N/A * Allow time for things to stabilize.
2N/A */
2N/A sleep(5);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Internal routine to allow manipulation of the cdb[1] byte
2N/A * in receive diag.
2N/A */
2N/Astatic int
2N/Arec_diag_cmd(int fd, uchar_t *buf_ptr, int buf_len, uchar_t page_code,
2N/A uchar_t cdb_one)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Auchar_t cdb[] = {SCMD_GDIAG, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb[1] = cdb_one;
2N/A cdb[2] = page_code;
2N/A cdb[3] = (buf_len>>8) & 0xff;
2N/A cdb[4] = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A return (cmd(fd, &ucmd, USCSI_READ));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Receive Diagnostic command
2N/A */
2N/Aint
2N/Ag_scsi_rec_diag_cmd(int fd, uchar_t *buf_ptr, int buf_len, uchar_t page_code)
2N/A{
2N/Aint status;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A if (buf_len & 0x03) {
2N/A return (L_RD_INVLD_TRNSFR_LEN);
2N/A }
2N/A
2N/A /*
2N/A * The a5k and newer enclosures abide by the SCSI spec
2N/A * (SPC-2: 7.15) but the SSA does not. It requires
2N/A * 0x10 to be present in cdb[1].
2N/A *
2N/A * For enclosures that abide by the spec, the first call
2N/A * will work. For SSAs the first call will fail, at which
2N/A * point we try again with the SSA specific value.
2N/A */
2N/A status = rec_diag_cmd(fd, buf_ptr, buf_len, page_code, SCSI_ESI_PCV);
2N/A if (status != 0) {
2N/A status = rec_diag_cmd(fd, buf_ptr, buf_len, page_code, SCSI_ESI_PF);
2N/A }
2N/A return (status);
2N/A}
2N/A
2N/A/*
2N/A * Write buffer command set up to download firmware
2N/A */
2N/Aint
2N/Ag_scsi_writebuffer_cmd(int fd, int off, uchar_t *buf_ptr, int buf_len,
2N/A int sp, int bid)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_WRITE_BUFFER, 0x4, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.byte1 |= sp; /* set the save bit */
2N/A cdb.byte2 = (char)(bid & 0xff);
2N/A cdb.byte3 = off>>16; /* bytes 3-5 contain file offset */
2N/A cdb.byte4 = (off>>8) & 0xff;
2N/A cdb.byte5 = off & 0xff;
2N/A cdb.byte6 = buf_len>>16; /* bytes 6-8 contain file length */
2N/A cdb.byte7 = (buf_len>>8) & 0xff;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 240; /* long timeout required */
2N/A
2N/A return (cmd(fd, &ucmd, USCSI_WRITE));
2N/A}
2N/A
2N/A/*
2N/A * Read buffer command set up to upload firmware
2N/A * Reads from code image starting at offset
2N/A * "code_off" for "buf_len" bytes.
2N/A */
2N/Aint
2N/Ag_scsi_readbuffer_cmd(int fd, uchar_t *buf_ptr, int buf_len, int code_off)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_READ_BUFFER, 0x5, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.byte3 = (code_off >> 16) & 0xff;
2N/A cdb.byte4 = (code_off >> 8) & 0xff;
2N/A cdb.byte5 = code_off & 0xff;
2N/A cdb.byte6 = buf_len>>16; /* bytes 6-8 contain file length */
2N/A cdb.byte7 = (buf_len>>8) & 0xff;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 120;
2N/A
2N/A return (cmd(fd, &ucmd, USCSI_READ));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_inquiry_cmd(int fd, uchar_t *buf_ptr, int buf_len)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g0 cdb = {SCMD_INQUIRY, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/Aint myreturn;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.count = (uchar_t)buf_len;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A
2N/A myreturn = cmd(fd, &ucmd, USCSI_READ | USCSI_SILENT);
2N/A if (myreturn) {
2N/A return (myreturn); /* != 0, error just return */
2N/A }
2N/A
2N/A /*
2N/A * This is a work around for the format of Daktari's
2N/A * SCSI inquiry page information. The name of the enclosure
2N/A * is not in the same place that products like the a5000 place it
2N/A * so we have to copy the string to the expected location.
2N/A */
2N/A if (strncmp((char *)&buf_ptr[16], DAK_PROD_STR,
2N/A strlen(DAK_PROD_STR)) == 0) {
2N/A strncpy((char *)&buf_ptr[96], (char *)&buf_ptr[DAK_BOXNAME_OFF],
2N/A DAK_BOXNAME_LEN);
2N/A }
2N/A
2N/A return (myreturn);
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_log_sense_cmd(int fd, uchar_t *buf_ptr, int buf_len, uchar_t page_code)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_LOG_SENSE, 0, 0x40, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A /* clear buffers on cmds that read data */
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.byte2 |= page_code; /* requested page */
2N/A cdb.byte7 = buf_len>>8;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 120;
2N/A return (cmd(fd, &ucmd, USCSI_READ));
2N/A}
2N/A
2N/A/*
2N/A * MODE SELECT
2N/A *
2N/A * MODE SELECT USCSI command
2N/A *
2N/A * sp is the save pages bit - Must be bit 0 -
2N/A *
2N/A */
2N/Aint
2N/Ag_scsi_mode_select_cmd(int fd, uchar_t *buf_ptr, int buf_len, uchar_t sp)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/A/* 10 byte Mode Select cmd */
2N/Amy_cdb_g1 cdb = {SCMD_MODE_SELECT_G1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A cdb.byte1 = (sp & 1) | 0x10; /* 0x10 is the PF bit */
2N/A cdb.byte7 = buf_len>>8;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 120;
2N/A
2N/A return (cmd(fd, &ucmd, USCSI_WRITE));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * MODE SENSE USCSI command
2N/A *
2N/A *
2N/A * pc = page control field
2N/A * page_code = Pages to return
2N/A */
2N/Aint
2N/Ag_scsi_mode_sense_cmd(int fd,
2N/A uchar_t *buf_ptr,
2N/A int buf_len,
2N/A uchar_t pc,
2N/A uchar_t page_code)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/A/* 10 byte Mode Select cmd */
2N/Amy_cdb_g1 cdb = {SCMD_MODE_SENSE_G1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/Aint status;
2N/Astatic int uscsi_count;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A /* Just for me - a sanity check */
2N/A if ((page_code > MODEPAGE_ALLPAGES) || (pc > 3) ||
2N/A (buf_len > MAX_MODE_SENSE_LEN)) {
2N/A return (L_ILLEGAL_MODE_SENSE_PAGE);
2N/A }
2N/A cdb.byte2 = (pc << 6) + page_code;
2N/A cdb.byte7 = buf_len>>8;
2N/A cdb.byte8 = buf_len & 0xff;
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 120;
2N/A
2N/A status = cmd(fd, &ucmd, USCSI_READ);
2N/A /* Bytes actually transfered */
2N/A if (status == 0) {
2N/A uscsi_count = buf_len - ucmd.uscsi_resid;
2N/A S_DPRINTF(" Number of bytes read on "
2N/A "Mode Sense 0x%x\n", uscsi_count);
2N/A if (getenv("_LUX_D_DEBUG") != NULL) {
2N/A (void) g_dump(" Mode Sense data: ", buf_ptr,
2N/A uscsi_count, HEX_ASCII);
2N/A }
2N/A }
2N/A return (status);
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_read_capacity_cmd(int fd, uchar_t *buf_ptr, int buf_len)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A /* clear buffers on on cmds that read data */
2N/A (void) memset(buf_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A return (cmd(fd, &ucmd, USCSI_READ));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_read_capacity_1016_cmd(int fd,
2N/A struct scsi_capacity_16 *cap_ptr, int buf_len)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g1 cdb = {SCMD_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/Astruct scsi_capacity cap_old;
2N/Aint ret;
2N/A
2N/A if ((fd < 0) || (cap_ptr == NULL) ||
2N/A (buf_len < sizeof (struct scsi_capacity_16))) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A /* clear buffers on on cmds that read data */
2N/A (void) memset((char *)&cap_old, 0, sizeof (cap_old));
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP1;
2N/A ucmd.uscsi_bufaddr = (caddr_t)&cap_old;
2N/A ucmd.uscsi_buflen = sizeof (cap_old);
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A
2N/A ret = cmd(fd, &ucmd, USCSI_READ);
2N/A if (cap_old.capacity == 0xffffffff) {
2N/A /*
2N/A * A capacity of 0xffffffff in response to a
2N/A * READ CAPACITY 10 indicates that the lun
2N/A * is too large to report the size in a 32 bit
2N/A * value, and a READ CAPACITY 16 is required
2N/A * to get the correct size.
2N/A */
2N/A ret = scsi_read_capacity_16_cmd(fd, cap_ptr, buf_len);
2N/A } else {
2N/A cap_ptr->sc_capacity = cap_old.capacity;
2N/A cap_ptr->sc_lbasize = cap_old.lbasize;
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/Astatic int
2N/Ascsi_read_capacity_16_cmd(int fd,
2N/A struct scsi_capacity_16 *cap_ptr, int buf_len)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Aunion scsi_cdb cdb;
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if ((fd < 0) || (cap_ptr == NULL) ||
2N/A (buf_len < sizeof (struct scsi_capacity_16))) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A /* clear buffers on on cmds that read data */
2N/A (void) memset((char *)cap_ptr, 0, buf_len);
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A (void) memset((char *)&cdb, 0, sizeof (union scsi_cdb));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP4;
2N/A ucmd.uscsi_bufaddr = (caddr_t)cap_ptr;
2N/A ucmd.uscsi_buflen = buf_len;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A
2N/A /*
2N/A * Read Capacity (16) is a Service Action In command. One
2N/A * command byte (0x9E) is overloaded for multiple operations,
2N/A * with the second CDB byte specifying the desired operation
2N/A */
2N/A cdb.scc_cmd = SCMD_SVC_ACTION_IN_G4;
2N/A cdb.cdb_opaque[1] = SSVC_ACTION_READ_CAPACITY_G4;
2N/A
2N/A /*
2N/A * Fill in allocation length field
2N/A */
2N/A cdb.cdb_opaque[10] =
2N/A (uchar_t)((ucmd.uscsi_buflen & 0xff000000) >> 24);
2N/A cdb.cdb_opaque[11] =
2N/A (uchar_t)((ucmd.uscsi_buflen & 0x00ff0000) >> 16);
2N/A cdb.cdb_opaque[12] =
2N/A (uchar_t)((ucmd.uscsi_buflen & 0x0000ff00) >> 8);
2N/A cdb.cdb_opaque[13] =
2N/A (uchar_t)(ucmd.uscsi_buflen & 0x000000ff);
2N/A
2N/A return (cmd(fd, &ucmd, USCSI_READ));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_release_cmd(int fd)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Aconst my_cdb_g0 cdb = {SCMD_RELEASE, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = 0;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A return (cmd(fd, &ucmd, 0));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_reserve_cmd(int fd)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Aconst my_cdb_g0 cdb = {SCMD_RESERVE, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = 0;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A return (cmd(fd, &ucmd, 0));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_start_cmd(int fd)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/A/*
2N/A * Use this to induce a SCSI error
2N/A * const my_cdb_g0 cdb = {SCMD_START_STOP, 0, 0xff, 0, 1, 0};
2N/A */
2N/Aconst my_cdb_g0 cdb = {SCMD_START_STOP, 0, 0, 0, 1, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = 0;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 240; /* takes a while to start all */
2N/A return (cmd(fd, &ucmd, 0));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_stop_cmd(int fd, int immediate_flag)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Amy_cdb_g0 cdb = {SCMD_START_STOP, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A if (immediate_flag) {
2N/A cdb.lba_msb = IMMED;
2N/A }
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = 0;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 120;
2N/A return (cmd(fd, &ucmd, 0));
2N/A}
2N/A
2N/Aint
2N/Ag_scsi_tur(int fd)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Aconst my_cdb_g0 cdb = {SCMD_TEST_UNIT_READY, 0, 0, 0, 0, 0};
2N/Astruct scsi_extended_sense sense;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = (caddr_t)&cdb;
2N/A ucmd.uscsi_cdblen = CDB_GROUP0;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = NULL;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A return (cmd(fd, &ucmd, 0));
2N/A}
2N/A
2N/A/*
2N/A * NOTE: This function includes a delay.
2N/A */
2N/Aint
2N/Ag_scsi_reset(int fd)
2N/A{
2N/Astruct uscsi_cmd ucmd;
2N/Astruct scsi_extended_sense sense;
2N/Aint err;
2N/A
2N/A if (fd < 0) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A (void) memset((char *)&ucmd, 0, sizeof (ucmd));
2N/A
2N/A ucmd.uscsi_cdb = NULL;
2N/A ucmd.uscsi_cdblen = NULL;
2N/A ucmd.uscsi_bufaddr = NULL;
2N/A ucmd.uscsi_buflen = NULL;
2N/A ucmd.uscsi_rqbuf = (caddr_t)&sense;
2N/A ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
2N/A ucmd.uscsi_timeout = 60;
2N/A if (err = cmd(fd, &ucmd, USCSI_RESET)) {
2N/A return (err);
2N/A }
2N/A /*
2N/A * Allow time for things to stabilize.
2N/A */
2N/A sleep(20);
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Description:
2N/A * Retrieves a devid from a device path.
2N/A *
2N/A * Input Values:
2N/A *
2N/A * devpath: Valid block device path.
2N/A * Example:/devices/scsi_vhci/ssd@g280000602200416d6257333030303353:c,raw
2N/A *
2N/A * devid: ptr to ddi_devid_t struct
2N/A * root: root handle to device tree snapshot
2N/A * drvr_name: driver name to start the node tree search
2N/A * On success, devid points to device tree handle to devid
2N/A * di_fini on root will invalidate devid pointer
2N/A *
2N/A * Return Value:
2N/A * 0 on success
2N/A * non-zero on failure
2N/A */
2N/Aint
2N/Ag_devid_get(char *devpath, ddi_devid_t *devid, di_node_t root,
2N/A const char *drvr_name)
2N/A{
2N/Achar *cptr;
2N/Achar rootpath[MAXPATHLEN];
2N/Adi_node_t node;
2N/Achar *devfs_path = NULL;
2N/Ahrtime_t start_time, end_time;
2N/Achar *env = NULL;
2N/A
2N/A if (devpath == NULL || devid == NULL || drvr_name == NULL) {
2N/A return (L_INVALID_ARG);
2N/A }
2N/A
2N/A if ((env = getenv("_LUX_T_DEBUG")) != NULL) {
2N/A start_time = gethrtime();
2N/A }
2N/A
2N/A *devid = NULL;
2N/A rootpath[0] = '\0';
2N/A
2N/A /*
2N/A * Form a valid root path by stripping off the /devices/ mount point
2N/A * prefix and the minor name (:a[,raw]).
2N/A */
2N/A if (strstr(devpath, DEV_PREFIX)) {
2N/A strcat(rootpath, devpath + strlen(DEV_PREFIX) - 1);
2N/A if (strchr(devpath, ':')) {
2N/A cptr = strrchr(rootpath, ':');
2N/A *cptr = '\0';
2N/A } else {
2N/A return (L_INVALID_PATH);
2N/A }
2N/A } else {
2N/A return (L_INVALID_PATH);
2N/A }
2N/A
2N/A /* point to first node which matches portdrvr */
2N/A node = di_drv_first_node(drvr_name, root);
2N/A if (node == DI_NODE_NIL) {
2N/A /*
2N/A * Could not find driver node
2N/A */
2N/A return (L_NO_DEVID);
2N/A }
2N/A
2N/A while (node != DI_NODE_NIL) {
2N/A if ((devfs_path = di_devfs_path(node)) != NULL) {
2N/A if (strcmp(rootpath, devfs_path) == 0) {
2N/A *devid = di_devid(node);
2N/A di_devfs_path_free(devfs_path);
2N/A break;
2N/A }
2N/A di_devfs_path_free(devfs_path);
2N/A }
2N/A node = di_drv_next_node(node);
2N/A }
2N/A
2N/A if (env != NULL) {
2N/A end_time = gethrtime();
2N/A (void) fprintf(stdout,
2N/A " g_devid_get: "
2N/A "\t\tTime = %lld millisec\n",
2N/A (end_time - start_time)/1000000);
2N/A }
2N/A /* Did we get back a handle? */
2N/A if (*devid != NULL) {
2N/A return (0);
2N/A } else { /* Couldn't get a devid. */
2N/A return (L_NO_DEVID);
2N/A }
2N/A}