fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*LINTLIBRARY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This module is part of the photon Command Line
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Interface program.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I18N message number ranges
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This file: 9500 - 9999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shared common messages: 1 - 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Includes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/scsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nl_types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <l_common.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stgcom.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <l_error.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <g_state.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Defines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAXLEN 1000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Global variables */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nl_catd l_catd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* External functions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int rand_r(unsigned int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewait_random_time(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetime_t timeval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct tm *tmbuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct timeval tval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteunsigned int seed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint random;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepid_t pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the system time and use "system seconds"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as 'seed' to generate a random number. Then,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait between 1/10 - 1/2 seconds before retry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the current process id and ex-or it with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the seed so that the random number is always
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * different even in case of multiple processes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * generate a random number at the same time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((timeval = time(NULL)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tmbuf = localtime(&timeval)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOCALTIME_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid = getpid();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get a random number. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seed = (unsigned int) tmbuf->tm_sec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seed ^= pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte random = rand_r(&seed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte random = ((random % 500) + 100) * MILLISEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tval.tv_sec = random / MICROSEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tval.tv_usec = random % MICROSEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (select(0, NULL, NULL, NULL, &tval) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_SELECT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Execute a command and determine the result.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecmd(int file, struct uscsi_cmd *command, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct scsi_extended_sense *rqbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint status, i, retry_cnt = 0, err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar errorMsg[MAXLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set function flags for driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set Automatic request sense enable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_flags = USCSI_RQENABLE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_flags |= flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* intialize error message array */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errorMsg[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* print command for debug */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_S_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_cdb == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (flag & USCSI_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (flag & USCSI_RESET_ALL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & USCSI_RESET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing a SCSI Reset.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & USCSI_RESET_ALL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing a SCSI Reset All.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing the following "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SCSI command: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_scsi_find_command_name(command->uscsi_cdb[0]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" fd=0x%x cdb=", file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < (int)command->uscsi_cdblen; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%x ", *(command->uscsi_cdb + i));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\n\tlen=0x%x bufaddr=0x%x buflen=0x%x"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " flags=0x%x\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_cdblen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_bufaddr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_buflen, command->uscsi_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_buflen > 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((flag & USCSI_READ) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_dump(" Buffer data: ",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)command->uscsi_bufaddr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MIN(command->uscsi_buflen, 512), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fflush(stdout);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Default command timeout in case command left it 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (command->uscsi_timeout == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Issue command - finally */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = ioctl(file, USCSICMD, command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == 0 && command->uscsi_status == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_S_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_buflen > 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (flag & USCSI_READ)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_dump("\tData read:",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)command->uscsi_bufaddr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MIN(command->uscsi_buflen, 512), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status != 0) && (command->uscsi_status == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_S_DEBUG") != NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (getenv("_LUX_ER_DEBUG") != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("Unexpected USCSICMD ioctl error: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just a SCSI error, create error message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retry once for Unit Attention,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Not Ready, and Aborted Command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_rqbuf != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((char)command->uscsi_rqlen - (char)command->uscsi_rqresid) > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rqbuf = (struct scsi_extended_sense *)command->uscsi_rqbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (rqbuf->es_key) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NOT_READY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF("Note: Device Not Ready."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_UNIT_ATTENTION:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF(" cmd():"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " UNIT_ATTENTION: Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ABORTED_COMMAND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF("Note: Command is aborted."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_S_DEBUG") != NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (getenv("_LUX_ER_DEBUG") != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_scsi_printerr(command,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (struct scsi_extended_sense *)command->uscsi_rqbuf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (command->uscsi_rqlen - command->uscsi_rqresid),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errorMsg, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retry 5 times in case of BUSY, and only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * once for Reservation-conflict, Command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Termination and Queue Full. Wait for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * random amount of time (between 1/10 - 1/2 secs.)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * between each retry. This random wait is to avoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the multiple threads being executed at the same time
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and also the constraint in Photon IB, where the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * command queue has a depth of one command.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch ((uchar_t)command->uscsi_status & STATUS_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF(" cmd(): No. of retries %d."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " STATUS_BUSY: Retrying...\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retry_cnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_RESERVATION_CONFLICT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF(" cmd():"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " RESERVATION_CONFLICT:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_TERMINATED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF("Note: Command Terminated."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_QFULL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF("Note: Command Queue is full."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((getenv("_LUX_S_DEBUG") != NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (getenv("_LUX_ER_DEBUG") != NULL)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (errorMsg[0] != '\0')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " %s\n", errorMsg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_SCSI_ERROR | command->uscsi_status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}