1/* 2 * This header file contains public constants and structures used by 3 * the SCSI initiator code. 4 */ 5#ifndef _SCSI_SCSI_H 6#define _SCSI_SCSI_H 7 8#include <linux/types.h> 9#include <linux/scatterlist.h> 10#include <linux/kernel.h> 11#include <scsi/scsi_common.h> 12#include <scsi/scsi_proto.h> 13 14struct scsi_cmnd; 15 16enum scsi_timeouts { 17 SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ, 18}; 19 20/* 21 * DIX-capable adapters effectively support infinite chaining for the 22 * protection information scatterlist 23 */ 24#define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF 25 26/* 27 * Special value for scanning to specify scanning or rescanning of all 28 * possible channels, (target) ids, or luns on a given shost. 29 */ 30#define SCAN_WILD_CARD ~0 31 32/** scsi_status_is_good - check the status return. 33 * 34 * @status: the status passed up from the driver (including host and 35 * driver components) 36 * 37 * This returns true for known good conditions that may be treated as 38 * command completed normally 39 */ 40static inline int scsi_status_is_good(int status) 41{ 42 /* 43 * FIXME: bit0 is listed as reserved in SCSI-2, but is 44 * significant in SCSI-3. For now, we follow the SCSI-2 45 * behaviour and ignore reserved bits. 46 */ 47 status &= 0xfe; 48 return ((status == SAM_STAT_GOOD) || 49 (status == SAM_STAT_INTERMEDIATE) || 50 (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) || 51 /* FIXME: this is obsolete in SAM-3 */ 52 (status == SAM_STAT_COMMAND_TERMINATED)); 53} 54 55 56/* 57 * standard mode-select header prepended to all mode-select commands 58 */ 59 60struct ccs_modesel_head { 61 __u8 _r1; /* reserved */ 62 __u8 medium; /* device-specific medium type */ 63 __u8 _r2; /* reserved */ 64 __u8 block_desc_length; /* block descriptor length */ 65 __u8 density; /* device-specific density code */ 66 __u8 number_blocks_hi; /* number of blocks in this block desc */ 67 __u8 number_blocks_med; 68 __u8 number_blocks_lo; 69 __u8 _r3; 70 __u8 block_length_hi; /* block length for blocks in this desc */ 71 __u8 block_length_med; 72 __u8 block_length_lo; 73}; 74 75/* 76 * The Well Known LUNS (SAM-3) in our int representation of a LUN 77 */ 78#define SCSI_W_LUN_BASE 0xc100 79#define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1) 80#define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2) 81#define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3) 82 83static inline int scsi_is_wlun(u64 lun) 84{ 85 return (lun & 0xff00) == SCSI_W_LUN_BASE; 86} 87 88 89/* 90 * MESSAGE CODES 91 */ 92 93#define COMMAND_COMPLETE 0x00 94#define EXTENDED_MESSAGE 0x01 95#define EXTENDED_MODIFY_DATA_POINTER 0x00 96#define EXTENDED_SDTR 0x01 97#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ 98#define EXTENDED_WDTR 0x03 99#define EXTENDED_PPR 0x04 100#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 101#define SAVE_POINTERS 0x02 102#define RESTORE_POINTERS 0x03 103#define DISCONNECT 0x04 104#define INITIATOR_ERROR 0x05 105#define ABORT_TASK_SET 0x06 106#define MESSAGE_REJECT 0x07 107#define NOP 0x08 108#define MSG_PARITY_ERROR 0x09 109#define LINKED_CMD_COMPLETE 0x0a 110#define LINKED_FLG_CMD_COMPLETE 0x0b 111#define TARGET_RESET 0x0c 112#define ABORT_TASK 0x0d 113#define CLEAR_TASK_SET 0x0e 114#define INITIATE_RECOVERY 0x0f /* SCSI-II only */ 115#define RELEASE_RECOVERY 0x10 /* SCSI-II only */ 116#define CLEAR_ACA 0x16 117#define LOGICAL_UNIT_RESET 0x17 118#define SIMPLE_QUEUE_TAG 0x20 119#define HEAD_OF_QUEUE_TAG 0x21 120#define ORDERED_QUEUE_TAG 0x22 121#define IGNORE_WIDE_RESIDUE 0x23 122#define ACA 0x24 123#define QAS_REQUEST 0x55 124 125/* Old SCSI2 names, don't use in new code */ 126#define BUS_DEVICE_RESET TARGET_RESET 127#define ABORT ABORT_TASK_SET 128 129/* 130 * Host byte codes 131 */ 132 133#define DID_OK 0x00 /* NO error */ 134#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ 135#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ 136#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ 137#define DID_BAD_TARGET 0x04 /* BAD target. */ 138#define DID_ABORT 0x05 /* Told to abort for some other reason */ 139#define DID_PARITY 0x06 /* Parity error */ 140#define DID_ERROR 0x07 /* Internal error */ 141#define DID_RESET 0x08 /* Reset by somebody. */ 142#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ 143#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ 144#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ 145#define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ 146#define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also 147 * without decrementing the retry count */ 148#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution 149 * and the driver blocked the port to 150 * recover the link. Transport class will 151 * retry or fail IO */ 152#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ 153#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on 154 * other paths */ 155#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other 156 * paths might yield different results */ 157#define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */ 158#define DID_MEDIUM_ERROR 0x13 /* Medium error */ 159#define DRIVER_OK 0x00 /* Driver status */ 160 161/* 162 * These indicate the error that occurred, and what is available. 163 */ 164 165#define DRIVER_BUSY 0x01 166#define DRIVER_SOFT 0x02 167#define DRIVER_MEDIA 0x03 168#define DRIVER_ERROR 0x04 169 170#define DRIVER_INVALID 0x05 171#define DRIVER_TIMEOUT 0x06 172#define DRIVER_HARD 0x07 173#define DRIVER_SENSE 0x08 174 175/* 176 * Internal return values. 177 */ 178 179#define NEEDS_RETRY 0x2001 180#define SUCCESS 0x2002 181#define FAILED 0x2003 182#define QUEUED 0x2004 183#define SOFT_ERROR 0x2005 184#define ADD_TO_MLQUEUE 0x2006 185#define TIMEOUT_ERROR 0x2007 186#define SCSI_RETURN_NOT_HANDLED 0x2008 187#define FAST_IO_FAIL 0x2009 188 189/* 190 * Midlevel queue return values. 191 */ 192#define SCSI_MLQUEUE_HOST_BUSY 0x1055 193#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056 194#define SCSI_MLQUEUE_EH_RETRY 0x1057 195#define SCSI_MLQUEUE_TARGET_BUSY 0x1058 196 197/* 198 * Use these to separate status msg and our bytes 199 * 200 * These are set by: 201 * 202 * status byte = set from target device 203 * msg_byte = return status from host adapter itself. 204 * host_byte = set by low-level driver to indicate status. 205 * driver_byte = set by mid-level. 206 */ 207#define status_byte(result) (((result) >> 1) & 0x7f) 208#define msg_byte(result) (((result) >> 8) & 0xff) 209#define host_byte(result) (((result) >> 16) & 0xff) 210#define driver_byte(result) (((result) >> 24) & 0xff) 211 212#define sense_class(sense) (((sense) >> 4) & 0x7) 213#define sense_error(sense) ((sense) & 0xf) 214#define sense_valid(sense) ((sense) & 0x80) 215 216/* 217 * default timeouts 218*/ 219#define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ) 220#define START_STOP_TIMEOUT (60 * HZ) 221#define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ) 222#define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ) 223#define READ_DEFECT_DATA_TIMEOUT (60 * HZ ) 224 225 226#define IDENTIFY_BASE 0x80 227#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\ 228 ((can_disconnect) ? 0x40 : 0) |\ 229 ((lun) & 0x07)) 230 231/* 232 * struct scsi_device::scsi_level values. For SCSI devices other than those 233 * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1) 234 * where "resp" is a byte array of the response to an INQUIRY. The scsi_level 235 * variable is visible to the user via sysfs. 236 */ 237 238#define SCSI_UNKNOWN 0 239#define SCSI_1 1 240#define SCSI_1_CCS 2 241#define SCSI_2 3 242#define SCSI_3 4 /* SPC */ 243#define SCSI_SPC_2 5 244#define SCSI_SPC_3 6 245 246/* 247 * INQ PERIPHERAL QUALIFIERS 248 */ 249#define SCSI_INQ_PQ_CON 0x00 250#define SCSI_INQ_PQ_NOT_CON 0x01 251#define SCSI_INQ_PQ_NOT_CAP 0x03 252 253 254/* 255 * Here are some scsi specific ioctl commands which are sometimes useful. 256 * 257 * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395 258 */ 259 260/* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */ 261#define SCSI_IOCTL_GET_IDLUN 0x5382 262 263/* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */ 264 265/* Used to obtain the host number of a device. */ 266#define SCSI_IOCTL_PROBE_HOST 0x5385 267 268/* Used to obtain the bus number for a device */ 269#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 270 271/* Used to obtain the PCI location of a device */ 272#define SCSI_IOCTL_GET_PCI 0x5387 273 274/* Pull a u32 out of a SCSI message (using BE SCSI conventions) */ 275static inline __u32 scsi_to_u32(__u8 *ptr) 276{ 277 return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3]; 278} 279 280#endif /* _SCSI_SCSI_H */ 281