1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright Siemens 1999
  29  * All rights reserved.
  30  */
  31 
  32 #ifndef _SYS_SCSI_TARGETS_SGENDEF_H
  33 #define _SYS_SCSI_TARGETS_SGENDEF_H
  34 
  35 #pragma ident   "%Z%%M% %I%     %E% SMI"
  36 
  37 #include <sys/types.h>
  38 #include <sys/kstat.h>
  39 #include <sys/condvar.h>
  40 #include <sys/mutex.h>
  41 #include <sys/buf.h>
  42 #include <sys/scsi/scsi.h>
  43 
  44 #ifdef  __cplusplus
  45 extern "C" {
  46 #endif
  47 
  48 #define SGEN_IOC                (('S' << 16) | ('G' << 8))
  49 #define SGEN_IOC_READY          (SGEN_IOC | 0x01)
  50 #define SGEN_IOC_DIAG           (SGEN_IOC | 0x02)
  51 
  52 #if defined(_KERNEL)
  53 
  54 #define SGEN_DIAG1              ((1 << 8) | CE_CONT)
  55 #define SGEN_DIAG2              ((2 << 8) | CE_CONT)
  56 #define SGEN_DIAG3              ((3 << 8) | CE_CONT)
  57 
  58 struct sgen_errstats {
  59         kstat_named_t sgen_trans_err;   /* error trying to transport pkt */
  60         kstat_named_t sgen_restart;     /* command restart attempted */
  61         kstat_named_t sgen_incmp_err;   /* command failed to complete */
  62         kstat_named_t sgen_autosen_rcv; /* autosense occurred */
  63         kstat_named_t sgen_autosen_bad; /* autosense data looks malformed */
  64         kstat_named_t sgen_sense_rcv;   /* sense fetch occurred */
  65         kstat_named_t sgen_sense_bad;   /* sense data looks malformed */
  66         kstat_named_t sgen_recov_err;   /* sense key is KEY_RECOVERABLE */
  67         kstat_named_t sgen_nosen_err;   /* sense key is KEY_NO_SENSE */
  68         kstat_named_t sgen_unrecov_err; /* sense key indicates other err */
  69 };
  70 
  71 typedef struct sgen_state {
  72         struct scsi_device *sgen_scsidev;       /* pointer to scsi_device */
  73         struct uscsi_cmd *sgen_ucmd;            /* uscsi command struct */
  74         struct buf *sgen_cmdbuf;                /* xfer buffer */
  75         struct scsi_pkt *sgen_cmdpkt;           /* scsi packet for command */
  76         kcondvar_t sgen_cmdbuf_cv;              /* cv for cmdbuf */
  77         int sgen_flags;                         /* see SGEN_FL_* */
  78         struct scsi_pkt *sgen_rqspkt;           /* request sense packet */
  79         struct buf *sgen_rqsbuf;                /* request sense xfer buffer */
  80         char *sgen_rqs_sen;                     /* sense buffer */
  81         int sgen_arq_enabled;                   /* auto request sense enabled */
  82         int sgen_diag;                          /* diagnostic output level */
  83         timeout_id_t sgen_restart_timeid;       /* timeout for sgen_restart */
  84         kstat_t *sgen_kstats;                   /* for error statistics */
  85 } sgen_state_t;
  86 
  87 /*
  88  * Convenience accessors for sgen_state_t.
  89  */
  90 #define sgen_mutex sgen_scsidev->sd_mutex
  91 #define sgen_devinfo sgen_scsidev->sd_dev
  92 #define sgen_scsiaddr sgen_scsidev->sd_address
  93 #define sgen_sense sgen_scsidev->sd_sense
  94 
  95 /*
  96  * sgen_flags accessors/mutators
  97  */
  98 #define SGEN_FL_OPEN    0x01    /* instance is open */
  99 #define SGEN_FL_SUSP    0x02    /* instance suspended */
 100 #define SGEN_FL_BUSY    0x04    /* command buffer busy */
 101 #define SGEN_FL_EXCL    0x08    /* exclusive open */
 102 
 103 #define SGEN_SET_OPEN(stp) \
 104         (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_OPEN)
 105 #define SGEN_CLR_OPEN(stp) \
 106         (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_OPEN)
 107 #define SGEN_IS_OPEN(stp) \
 108         ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_OPEN) == SGEN_FL_OPEN)
 109 
 110 #define SGEN_SET_SUSP(stp) \
 111         (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_SUSP)
 112 #define SGEN_CLR_SUSP(stp) \
 113         (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_SUSP)
 114 #define SGEN_IS_SUSP(stp) \
 115         ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_SUSP) == SGEN_FL_SUSP)
 116 
 117 #define SGEN_SET_BUSY(stp) \
 118         (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_BUSY)
 119 #define SGEN_CLR_BUSY(stp) \
 120         (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_BUSY)
 121 #define SGEN_IS_BUSY(stp) \
 122         ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_BUSY) == SGEN_FL_BUSY)
 123 
 124 #define SGEN_SET_EXCL(stp) \
 125         (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_EXCL)
 126 #define SGEN_CLR_EXCL(stp) \
 127         (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_EXCL)
 128 #define SGEN_IS_EXCL(stp) \
 129         ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_EXCL) == SGEN_FL_EXCL)
 130 
 131 /*
 132  * These structures form the driver's database of binding information.
 133  * Inquiry strings and device types from the inquiry-config-list and
 134  * device-type-config-list properties are stored.
 135  */
 136 typedef struct sgen_inq_node {
 137         char *node_vendor;                      /* up to 8 character vendor */
 138         char *node_product;                     /* up to 16 character product */
 139         struct sgen_inq_node *node_next;
 140 } sgen_inq_node_t;
 141 
 142 typedef struct sgen_type_node {
 143         uchar_t node_type;                      /* SCSI device type */
 144         struct sgen_type_node *node_next;
 145 } sgen_type_node_t;
 146 
 147 struct sgen_binddb {
 148         int sdb_init;                           /* has this been initialized? */
 149         kmutex_t sdb_lock;                      /* protects this structure */
 150         sgen_inq_node_t *sdb_inq_nodes;         /* inquiry binding nodes */
 151         sgen_type_node_t *sdb_type_nodes;       /* dev-type binding nodes */
 152 };
 153 
 154 #define SGEN_ESTIMATED_NUM_DEVS 4               /* for soft-state allocation */
 155 
 156 /*
 157  * Time to wait before a retry for commands returning Busy Status
 158  */
 159 #define SGEN_BSY_TIMEOUT        (drv_usectohz(5 * 1000000))
 160 #define SGEN_IO_TIME            60              /* seconds */
 161 
 162 /*
 163  * sgen_callback action codes
 164  */
 165 #define COMMAND_DONE            0       /* command completed, biodone it */
 166 #define COMMAND_DONE_ERROR      1       /* command completed, indicate error */
 167 #define FETCH_SENSE             2       /* CHECK CONDITION, so initiate sense */
 168                                         /* fetch */
 169 
 170 #define SET_BP_ERROR(bp, err)   bioerror(bp, err);
 171 
 172 #endif /* defined(_KERNEL) */
 173 
 174 #ifdef  __cplusplus
 175 }
 176 #endif
 177 
 178 #endif  /* _SYS_SCSI_TARGETS_SGENDEF_H */