Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * This header file contains public constants and structures used by
0004  * the SCSI initiator code.
0005  */
0006 #ifndef _SCSI_SCSI_H
0007 #define _SCSI_SCSI_H
0008 
0009 #include <linux/types.h>
0010 #include <linux/scatterlist.h>
0011 #include <linux/kernel.h>
0012 #include <scsi/scsi_common.h>
0013 #include <scsi/scsi_proto.h>
0014 #include <scsi/scsi_status.h>
0015 
0016 struct scsi_cmnd;
0017 
0018 enum scsi_timeouts {
0019     SCSI_DEFAULT_EH_TIMEOUT     = 10 * HZ,
0020 };
0021 
0022 /*
0023  * DIX-capable adapters effectively support infinite chaining for the
0024  * protection information scatterlist
0025  */
0026 #define SCSI_MAX_PROT_SG_SEGMENTS   0xFFFF
0027 
0028 /*
0029  * Special value for scanning to specify scanning or rescanning of all
0030  * possible channels, (target) ids, or luns on a given shost.
0031  */
0032 #define SCAN_WILD_CARD  ~0
0033 
0034 /*
0035  * standard mode-select header prepended to all mode-select commands
0036  */
0037 
0038 struct ccs_modesel_head {
0039     __u8 _r1;           /* reserved */
0040     __u8 medium;        /* device-specific medium type */
0041     __u8 _r2;           /* reserved */
0042     __u8 block_desc_length; /* block descriptor length */
0043     __u8 density;       /* device-specific density code */
0044     __u8 number_blocks_hi;  /* number of blocks in this block desc */
0045     __u8 number_blocks_med;
0046     __u8 number_blocks_lo;
0047     __u8 _r3;
0048     __u8 block_length_hi;   /* block length for blocks in this desc */
0049     __u8 block_length_med;
0050     __u8 block_length_lo;
0051 };
0052 
0053 /*
0054  * The Well Known LUNS (SAM-3) in our int representation of a LUN
0055  */
0056 #define SCSI_W_LUN_BASE 0xc100
0057 #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
0058 #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
0059 #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
0060 
0061 static inline int scsi_is_wlun(u64 lun)
0062 {
0063     return (lun & 0xff00) == SCSI_W_LUN_BASE;
0064 }
0065 
0066 /**
0067  * scsi_status_is_check_condition - check the status return.
0068  *
0069  * @status: the status passed up from the driver (including host and
0070  *          driver components)
0071  *
0072  * This returns true if the status code is SAM_STAT_CHECK_CONDITION.
0073  */
0074 static inline int scsi_status_is_check_condition(int status)
0075 {
0076     if (status < 0)
0077         return false;
0078     status &= 0xfe;
0079     return status == SAM_STAT_CHECK_CONDITION;
0080 }
0081 
0082 /*
0083  *  Extended message codes.
0084  */
0085 #define     EXTENDED_MODIFY_DATA_POINTER    0x00
0086 #define     EXTENDED_SDTR                   0x01
0087 #define     EXTENDED_EXTENDED_IDENTIFY      0x02    /* SCSI-I only */
0088 #define     EXTENDED_WDTR                   0x03
0089 #define     EXTENDED_PPR                    0x04
0090 #define     EXTENDED_MODIFY_BIDI_DATA_PTR   0x05
0091 
0092 /*
0093  * Internal return values.
0094  */
0095 enum scsi_disposition {
0096     NEEDS_RETRY     = 0x2001,
0097     SUCCESS         = 0x2002,
0098     FAILED          = 0x2003,
0099     QUEUED          = 0x2004,
0100     SOFT_ERROR      = 0x2005,
0101     ADD_TO_MLQUEUE      = 0x2006,
0102     TIMEOUT_ERROR       = 0x2007,
0103     SCSI_RETURN_NOT_HANDLED = 0x2008,
0104     FAST_IO_FAIL        = 0x2009,
0105 };
0106 
0107 /*
0108  * Midlevel queue return values.
0109  */
0110 #define SCSI_MLQUEUE_HOST_BUSY   0x1055
0111 #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
0112 #define SCSI_MLQUEUE_EH_RETRY    0x1057
0113 #define SCSI_MLQUEUE_TARGET_BUSY 0x1058
0114 
0115 /*
0116  *  Use these to separate status msg and our bytes
0117  *
0118  *  These are set by:
0119  *
0120  *      status byte = set from target device
0121  *      msg_byte    (unused)
0122  *      host_byte   = set by low-level driver to indicate status.
0123  */
0124 #define host_byte(result)   (((result) >> 16) & 0xff)
0125 
0126 #define sense_class(sense)  (((sense) >> 4) & 0x7)
0127 #define sense_error(sense)  ((sense) & 0xf)
0128 #define sense_valid(sense)  ((sense) & 0x80)
0129 
0130 /*
0131  * default timeouts
0132 */
0133 #define FORMAT_UNIT_TIMEOUT     (2 * 60 * 60 * HZ)
0134 #define START_STOP_TIMEOUT      (60 * HZ)
0135 #define MOVE_MEDIUM_TIMEOUT     (5 * 60 * HZ)
0136 #define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)
0137 #define READ_DEFECT_DATA_TIMEOUT    (60 * HZ )
0138 
0139 
0140 #define IDENTIFY_BASE       0x80
0141 #define IDENTIFY(can_disconnect, lun)   (IDENTIFY_BASE |\
0142              ((can_disconnect) ?  0x40 : 0) |\
0143              ((lun) & 0x07))
0144 
0145 /*
0146  *  struct scsi_device::scsi_level values. For SCSI devices other than those
0147  *  prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
0148  *  where "resp" is a byte array of the response to an INQUIRY. The scsi_level
0149  *  variable is visible to the user via sysfs.
0150  */
0151 
0152 #define SCSI_UNKNOWN    0
0153 #define SCSI_1          1
0154 #define SCSI_1_CCS      2
0155 #define SCSI_2          3
0156 #define SCSI_3          4        /* SPC */
0157 #define SCSI_SPC_2      5
0158 #define SCSI_SPC_3      6
0159 
0160 /*
0161  * INQ PERIPHERAL QUALIFIERS
0162  */
0163 #define SCSI_INQ_PQ_CON         0x00
0164 #define SCSI_INQ_PQ_NOT_CON     0x01
0165 #define SCSI_INQ_PQ_NOT_CAP     0x03
0166 
0167 
0168 /*
0169  * Here are some scsi specific ioctl commands which are sometimes useful.
0170  *
0171  * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
0172  */
0173 
0174 /* Used to obtain PUN and LUN info.  Conflicts with CDROMAUDIOBUFSIZ */
0175 #define SCSI_IOCTL_GET_IDLUN        0x5382
0176 
0177 /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
0178 
0179 /* Used to obtain the host number of a device. */
0180 #define SCSI_IOCTL_PROBE_HOST       0x5385
0181 
0182 /* Used to obtain the bus number for a device */
0183 #define SCSI_IOCTL_GET_BUS_NUMBER   0x5386
0184 
0185 /* Used to obtain the PCI location of a device */
0186 #define SCSI_IOCTL_GET_PCI      0x5387
0187 
0188 /** scsi_status_is_good - check the status return.
0189  *
0190  * @status: the status passed up from the driver (including host and
0191  *          driver components)
0192  *
0193  * This returns true for known good conditions that may be treated as
0194  * command completed normally
0195  */
0196 static inline bool scsi_status_is_good(int status)
0197 {
0198     if (status < 0)
0199         return false;
0200 
0201     if (host_byte(status) == DID_NO_CONNECT)
0202         return false;
0203 
0204     /*
0205      * FIXME: bit0 is listed as reserved in SCSI-2, but is
0206      * significant in SCSI-3.  For now, we follow the SCSI-2
0207      * behaviour and ignore reserved bits.
0208      */
0209     status &= 0xfe;
0210     return ((status == SAM_STAT_GOOD) ||
0211         (status == SAM_STAT_CONDITION_MET) ||
0212         /* Next two "intermediate" statuses are obsolete in SAM-4 */
0213         (status == SAM_STAT_INTERMEDIATE) ||
0214         (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
0215         /* FIXME: this is obsolete in SAM-3 */
0216         (status == SAM_STAT_COMMAND_TERMINATED));
0217 }
0218 
0219 #endif /* _SCSI_SCSI_H */