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 #include <sys/types.h> 36 #include <sys/kstat.h> 37 #include <sys/condvar.h> 38 #include <sys/mutex.h> 39 #include <sys/buf.h> 40 #include <sys/scsi/scsi.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 #define SGEN_IOC (('S' << 16) | ('G' << 8)) 47 #define SGEN_IOC_READY (SGEN_IOC | 0x01) 48 #define SGEN_IOC_DIAG (SGEN_IOC | 0x02) 49 50 #if defined(_KERNEL) 51 52 #define SGEN_DIAG1 ((1 << 8) | CE_CONT) 53 #define SGEN_DIAG2 ((2 << 8) | CE_CONT) 54 #define SGEN_DIAG3 ((3 << 8) | CE_CONT) 55 56 struct sgen_errstats { 57 kstat_named_t sgen_trans_err; /* error trying to transport pkt */ 58 kstat_named_t sgen_restart; /* command restart attempted */ 59 kstat_named_t sgen_incmp_err; /* command failed to complete */ 60 kstat_named_t sgen_autosen_rcv; /* autosense occurred */ 61 kstat_named_t sgen_autosen_bad; /* autosense data looks malformed */ 62 kstat_named_t sgen_sense_rcv; /* sense fetch occurred */ 63 kstat_named_t sgen_sense_bad; /* sense data looks malformed */ 64 kstat_named_t sgen_recov_err; /* sense key is KEY_RECOVERABLE */ 65 kstat_named_t sgen_nosen_err; /* sense key is KEY_NO_SENSE */ 66 kstat_named_t sgen_unrecov_err; /* sense key indicates other err */ 67 }; 68 69 typedef struct sgen_state { 70 struct scsi_device *sgen_scsidev; /* pointer to scsi_device */ 71 struct uscsi_cmd *sgen_ucmd; /* uscsi command struct */ 72 struct buf *sgen_cmdbuf; /* xfer buffer */ 73 struct scsi_pkt *sgen_cmdpkt; /* scsi packet for command */ 74 kcondvar_t sgen_cmdbuf_cv; /* cv for cmdbuf */ 75 int sgen_flags; /* see SGEN_FL_* */ 76 struct scsi_pkt *sgen_rqspkt; /* request sense packet */ 77 struct buf *sgen_rqsbuf; /* request sense xfer buffer */ 78 char *sgen_rqs_sen; /* sense buffer */ 79 int sgen_arq_enabled; /* auto request sense enabled */ 80 int sgen_diag; /* diagnostic output level */ 81 timeout_id_t sgen_restart_timeid; /* timeout for sgen_restart */ 82 kstat_t *sgen_kstats; /* for error statistics */ 83 } sgen_state_t; 84 85 /* 86 * Convenience accessors for sgen_state_t. 87 */ 88 #define sgen_mutex sgen_scsidev->sd_mutex 89 #define sgen_devinfo sgen_scsidev->sd_dev 90 #define sgen_scsiaddr sgen_scsidev->sd_address 91 #define sgen_sense sgen_scsidev->sd_sense 92 93 /* 94 * sgen_flags accessors/mutators 95 */ 96 #define SGEN_FL_OPEN 0x01 /* instance is open */ 97 #define SGEN_FL_SUSP 0x02 /* instance suspended */ 98 #define SGEN_FL_BUSY 0x04 /* command buffer busy */ 99 #define SGEN_FL_EXCL 0x08 /* exclusive open */ 100 101 #define SGEN_SET_OPEN(stp) \ 102 (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_OPEN) 103 #define SGEN_CLR_OPEN(stp) \ 104 (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_OPEN) 105 #define SGEN_IS_OPEN(stp) \ 106 ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_OPEN) == SGEN_FL_OPEN) 107 108 #define SGEN_SET_SUSP(stp) \ 109 (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_SUSP) 110 #define SGEN_CLR_SUSP(stp) \ 111 (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_SUSP) 112 #define SGEN_IS_SUSP(stp) \ 113 ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_SUSP) == SGEN_FL_SUSP) 114 115 #define SGEN_SET_BUSY(stp) \ 116 (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_BUSY) 117 #define SGEN_CLR_BUSY(stp) \ 118 (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_BUSY) 119 #define SGEN_IS_BUSY(stp) \ 120 ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_BUSY) == SGEN_FL_BUSY) 121 122 #define SGEN_SET_EXCL(stp) \ 123 (((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_EXCL) 124 #define SGEN_CLR_EXCL(stp) \ 125 (((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_EXCL) 126 #define SGEN_IS_EXCL(stp) \ 127 ((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_EXCL) == SGEN_FL_EXCL) 128 129 /* 130 * These structures form the driver's database of binding information. 131 * Inquiry strings and device types from the inquiry-config-list and 132 * device-type-config-list properties are stored. 133 */ 134 typedef struct sgen_inq_node { 135 char *node_vendor; /* up to 8 character vendor */ 136 char *node_product; /* up to 16 character product */ 137 struct sgen_inq_node *node_next; 138 } sgen_inq_node_t; 139 140 typedef struct sgen_type_node { 141 uchar_t node_type; /* SCSI device type */ 142 struct sgen_type_node *node_next; 143 } sgen_type_node_t; 144 145 struct sgen_binddb { 146 int sdb_init; /* has this been initialized? */ 147 kmutex_t sdb_lock; /* protects this structure */ 148 sgen_inq_node_t *sdb_inq_nodes; /* inquiry binding nodes */ 149 sgen_type_node_t *sdb_type_nodes; /* dev-type binding nodes */ 150 }; 151 152 #define SGEN_ESTIMATED_NUM_DEVS 4 /* for soft-state allocation */ 153 154 /* 155 * Time to wait before a retry for commands returning Busy Status 156 */ 157 #define SGEN_BSY_TIMEOUT (drv_usectohz(5 * 1000000)) 158 #define SGEN_IO_TIME 60 /* seconds */ 159 160 /* 161 * sgen_callback action codes 162 */ 163 #define COMMAND_DONE 0 /* command completed, biodone it */ 164 #define COMMAND_DONE_ERROR 1 /* command completed, indicate error */ 165 #define FETCH_SENSE 2 /* CHECK CONDITION, so initiate sense */ 166 /* fetch */ 167 168 #define SET_BP_ERROR(bp, err) bioerror(bp, err); 169 170 #endif /* defined(_KERNEL) */ 171 172 #ifdef __cplusplus 173 } 174 #endif 175 176 #endif /* _SYS_SCSI_TARGETS_SGENDEF_H */ 177