/* SPDX-License-Identifier: GPL-2.0 */1/*2* This header file contains public constants and structures used by3* the SCSI initiator code.4*/5#ifndef _SCSI_SCSI_H6#define _SCSI_SCSI_H78#include <linux/types.h>910#include <asm/param.h>1112#include <scsi/scsi_common.h>13#include <scsi/scsi_proto.h>14#include <scsi/scsi_status.h>1516struct scsi_cmnd;1718enum scsi_timeouts {19SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ,20};2122/*23* DIX-capable adapters effectively support infinite chaining for the24* protection information scatterlist25*/26#define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF2728/*29* Special value for scanning to specify scanning or rescanning of all30* possible channels, (target) ids, or luns on a given shost.31*/32#define SCAN_WILD_CARD ~03334/*35* standard mode-select header prepended to all mode-select commands36*/3738struct ccs_modesel_head {39__u8 _r1; /* reserved */40__u8 medium; /* device-specific medium type */41__u8 _r2; /* reserved */42__u8 block_desc_length; /* block descriptor length */43__u8 density; /* device-specific density code */44__u8 number_blocks_hi; /* number of blocks in this block desc */45__u8 number_blocks_med;46__u8 number_blocks_lo;47__u8 _r3;48__u8 block_length_hi; /* block length for blocks in this desc */49__u8 block_length_med;50__u8 block_length_lo;51};5253/*54* The Well Known LUNS (SAM-3) in our int representation of a LUN55*/56#define SCSI_W_LUN_BASE 0xc10057#define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)58#define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)59#define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)6061static inline int scsi_is_wlun(u64 lun)62{63return (lun & 0xff00) == SCSI_W_LUN_BASE;64}6566/**67* scsi_status_is_check_condition - check the status return.68*69* @status: the status passed up from the driver (including host and70* driver components)71*72* Returns: %true if the status code is SAM_STAT_CHECK_CONDITION.73*/74static inline int scsi_status_is_check_condition(int status)75{76if (status < 0)77return false;78status &= 0xfe;79return status == SAM_STAT_CHECK_CONDITION;80}8182/*83* Extended message codes.84*/85#define EXTENDED_MODIFY_DATA_POINTER 0x0086#define EXTENDED_SDTR 0x0187#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */88#define EXTENDED_WDTR 0x0389#define EXTENDED_PPR 0x0490#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x059192/*93* Internal return values.94*/95enum scsi_disposition {96NEEDS_RETRY = 0x2001,97SUCCESS = 0x2002,98FAILED = 0x2003,99QUEUED = 0x2004,100SOFT_ERROR = 0x2005,101ADD_TO_MLQUEUE = 0x2006,102TIMEOUT_ERROR = 0x2007,103SCSI_RETURN_NOT_HANDLED = 0x2008,104FAST_IO_FAIL = 0x2009,105};106107/*108* Midlevel queue return values.109*/110#define SCSI_MLQUEUE_HOST_BUSY 0x1055111#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056112#define SCSI_MLQUEUE_EH_RETRY 0x1057113#define SCSI_MLQUEUE_TARGET_BUSY 0x1058114115/*116* Use these to separate status msg and our bytes117*118* These are set by:119*120* status byte = set from target device121* msg_byte (unused)122* host_byte = set by low-level driver to indicate status.123*/124#define status_byte(result) (result & 0xff)125#define host_byte(result) (((result) >> 16) & 0xff)126127#define sense_class(sense) (((sense) >> 4) & 0x7)128#define sense_error(sense) ((sense) & 0xf)129#define sense_valid(sense) ((sense) & 0x80)130131/*132* default timeouts133*/134#define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ)135#define START_STOP_TIMEOUT (60 * HZ)136#define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ)137#define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)138#define READ_DEFECT_DATA_TIMEOUT (60 * HZ )139140141#define IDENTIFY_BASE 0x80142#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\143((can_disconnect) ? 0x40 : 0) |\144((lun) & 0x07))145146/*147* struct scsi_device::scsi_level values. For SCSI devices other than those148* prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)149* where "resp" is a byte array of the response to an INQUIRY. The scsi_level150* variable is visible to the user via sysfs.151*/152153#define SCSI_UNKNOWN 0154#define SCSI_1 1155#define SCSI_1_CCS 2156#define SCSI_2 3157#define SCSI_3 4 /* SPC */158#define SCSI_SPC_2 5159#define SCSI_SPC_3 6160#define SCSI_SPC_4 7161#define SCSI_SPC_5 8162#define SCSI_SPC_6 14163164/*165* INQ PERIPHERAL QUALIFIERS166*/167#define SCSI_INQ_PQ_CON 0x00168#define SCSI_INQ_PQ_NOT_CON 0x01169#define SCSI_INQ_PQ_NOT_CAP 0x03170171172/*173* Here are some scsi specific ioctl commands which are sometimes useful.174*175* Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395176*/177178/* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */179#define SCSI_IOCTL_GET_IDLUN 0x5382180181/* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */182183/* Used to obtain the host number of a device. */184#define SCSI_IOCTL_PROBE_HOST 0x5385185186/* Used to obtain the bus number for a device */187#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386188189/* Used to obtain the PCI location of a device */190#define SCSI_IOCTL_GET_PCI 0x5387191192/**193* scsi_status_is_good - check the status return.194*195* @status: the status passed up from the driver (including host and196* driver components)197*198* Returns: %true for known good conditions that may be treated as199* command completed normally200*/201static inline bool scsi_status_is_good(int status)202{203if (status < 0)204return false;205206if (host_byte(status) == DID_NO_CONNECT)207return false;208209/*210* FIXME: bit0 is listed as reserved in SCSI-2, but is211* significant in SCSI-3. For now, we follow the SCSI-2212* behaviour and ignore reserved bits.213*/214status &= 0xfe;215return ((status == SAM_STAT_GOOD) ||216(status == SAM_STAT_CONDITION_MET) ||217/* Next two "intermediate" statuses are obsolete in SAM-4 */218(status == SAM_STAT_INTERMEDIATE) ||219(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||220/* FIXME: this is obsolete in SAM-3 */221(status == SAM_STAT_COMMAND_TERMINATED));222}223224#endif /* _SCSI_SCSI_H */225226227