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