1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * This header file contains public constants and structures used by 4 * both the SCSI initiator and the SCSI target code. 5 * 6 * For documentation on the OPCODES, MESSAGES, and SENSE values, 7 * please consult the SCSI standard. 8 */ 9 10#ifndef _SCSI_PROTO_H_ 11#define _SCSI_PROTO_H_ 12 13#include <linux/types.h> 14 15/* 16 * SCSI opcodes 17 */ 18 19#define TEST_UNIT_READY 0x00 20#define REZERO_UNIT 0x01 21#define REQUEST_SENSE 0x03 22#define FORMAT_UNIT 0x04 23#define READ_BLOCK_LIMITS 0x05 24#define REASSIGN_BLOCKS 0x07 25#define INITIALIZE_ELEMENT_STATUS 0x07 26#define READ_6 0x08 27#define WRITE_6 0x0a 28#define SEEK_6 0x0b 29#define READ_REVERSE 0x0f 30#define WRITE_FILEMARKS 0x10 31#define SPACE 0x11 32#define INQUIRY 0x12 33#define RECOVER_BUFFERED_DATA 0x14 34#define MODE_SELECT 0x15 35#define RESERVE 0x16 36#define RELEASE 0x17 37#define COPY 0x18 38#define ERASE 0x19 39#define MODE_SENSE 0x1a 40#define START_STOP 0x1b 41#define RECEIVE_DIAGNOSTIC 0x1c 42#define SEND_DIAGNOSTIC 0x1d 43#define ALLOW_MEDIUM_REMOVAL 0x1e 44 45#define READ_FORMAT_CAPACITIES 0x23 46#define SET_WINDOW 0x24 47#define READ_CAPACITY 0x25 48#define READ_10 0x28 49#define WRITE_10 0x2a 50#define SEEK_10 0x2b 51#define POSITION_TO_ELEMENT 0x2b 52#define WRITE_VERIFY 0x2e 53#define VERIFY 0x2f 54#define SEARCH_HIGH 0x30 55#define SEARCH_EQUAL 0x31 56#define SEARCH_LOW 0x32 57#define SET_LIMITS 0x33 58#define PRE_FETCH 0x34 59#define READ_POSITION 0x34 60#define SYNCHRONIZE_CACHE 0x35 61#define LOCK_UNLOCK_CACHE 0x36 62#define READ_DEFECT_DATA 0x37 63#define MEDIUM_SCAN 0x38 64#define COMPARE 0x39 65#define COPY_VERIFY 0x3a 66#define WRITE_BUFFER 0x3b 67#define READ_BUFFER 0x3c 68#define UPDATE_BLOCK 0x3d 69#define READ_LONG 0x3e 70#define WRITE_LONG 0x3f 71#define CHANGE_DEFINITION 0x40 72#define WRITE_SAME 0x41 73#define UNMAP 0x42 74#define READ_TOC 0x43 75#define READ_HEADER 0x44 76#define GET_EVENT_STATUS_NOTIFICATION 0x4a 77#define LOG_SELECT 0x4c 78#define LOG_SENSE 0x4d 79#define XDWRITEREAD_10 0x53 80#define MODE_SELECT_10 0x55 81#define RESERVE_10 0x56 82#define RELEASE_10 0x57 83#define MODE_SENSE_10 0x5a 84#define PERSISTENT_RESERVE_IN 0x5e 85#define PERSISTENT_RESERVE_OUT 0x5f 86#define VARIABLE_LENGTH_CMD 0x7f 87#define REPORT_LUNS 0xa0 88#define SECURITY_PROTOCOL_IN 0xa2 89#define MAINTENANCE_IN 0xa3 90#define MAINTENANCE_OUT 0xa4 91#define MOVE_MEDIUM 0xa5 92#define EXCHANGE_MEDIUM 0xa6 93#define READ_12 0xa8 94#define SERVICE_ACTION_OUT_12 0xa9 95#define WRITE_12 0xaa 96#define READ_MEDIA_SERIAL_NUMBER 0xab /* Obsolete with SPC-2 */ 97#define SERVICE_ACTION_IN_12 0xab 98#define WRITE_VERIFY_12 0xae 99#define VERIFY_12 0xaf 100#define SEARCH_HIGH_12 0xb0 101#define SEARCH_EQUAL_12 0xb1 102#define SEARCH_LOW_12 0xb2 103#define SECURITY_PROTOCOL_OUT 0xb5 104#define READ_ELEMENT_STATUS 0xb8 105#define SEND_VOLUME_TAG 0xb6 106#define WRITE_LONG_2 0xea 107#define EXTENDED_COPY 0x83 108#define RECEIVE_COPY_RESULTS 0x84 109#define ACCESS_CONTROL_IN 0x86 110#define ACCESS_CONTROL_OUT 0x87 111#define READ_16 0x88 112#define COMPARE_AND_WRITE 0x89 113#define WRITE_16 0x8a 114#define READ_ATTRIBUTE 0x8c 115#define WRITE_ATTRIBUTE 0x8d 116#define WRITE_VERIFY_16 0x8e 117#define VERIFY_16 0x8f 118#define SYNCHRONIZE_CACHE_16 0x91 119#define WRITE_SAME_16 0x93 120#define ZBC_OUT 0x94 121#define ZBC_IN 0x95 122#define SERVICE_ACTION_BIDIRECTIONAL 0x9d 123#define SERVICE_ACTION_IN_16 0x9e 124#define SERVICE_ACTION_OUT_16 0x9f 125#ifdef __KERNEL__ 126/* values for service action in */ 127#define SAI_READ_CAPACITY_16 0x10 128#define SAI_GET_LBA_STATUS 0x12 129#define SAI_REPORT_REFERRALS 0x13 130/* values for maintenance in */ 131#define MI_REPORT_IDENTIFYING_INFORMATION 0x05 132#define MI_REPORT_TARGET_PGS 0x0a 133#define MI_REPORT_ALIASES 0x0b 134#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c 135#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d 136#define MI_REPORT_PRIORITY 0x0e 137#define MI_REPORT_TIMESTAMP 0x0f 138#define MI_MANAGEMENT_PROTOCOL_IN 0x10 139/* value for MI_REPORT_TARGET_PGS ext header */ 140#define MI_EXT_HDR_PARAM_FMT 0x20 141/* values for maintenance out */ 142#define MO_SET_IDENTIFYING_INFORMATION 0x06 143#define MO_SET_TARGET_PGS 0x0a 144#define MO_CHANGE_ALIASES 0x0b 145#define MO_SET_PRIORITY 0x0e 146#define MO_SET_TIMESTAMP 0x0f 147#define MO_MANAGEMENT_PROTOCOL_OUT 0x10 148/* values for ZBC_IN */ 149#define ZI_REPORT_ZONES 0x00 150/* values for ZBC_OUT */ 151#define ZO_CLOSE_ZONE 0x01 152#define ZO_FINISH_ZONE 0x02 153#define ZO_OPEN_ZONE 0x03 154#define ZO_RESET_WRITE_POINTER 0x04 155/* values for variable length command */ 156#define XDREAD_32 0x03 157#define XDWRITE_32 0x04 158#define XPWRITE_32 0x06 159#define XDWRITEREAD_32 0x07 160#define READ_32 0x09 161#define VERIFY_32 0x0a 162#define WRITE_32 0x0b 163#define WRITE_VERIFY_32 0x0c 164#define WRITE_SAME_32 0x0d 165#define ATA_32 0x1ff0 166 167/* Values for T10/04-262r7 */ 168#define ATA_16 0x85 /* 16-byte pass-thru */ 169#define ATA_12 0xa1 /* 12-byte pass-thru */ 170 171/* Vendor specific CDBs start here */ 172#define VENDOR_SPECIFIC_CDB 0xc0 173 174/* 175 * SCSI command lengths 176 */ 177 178#define SCSI_MAX_VARLEN_CDB_SIZE 260 179 180/* defined in T10 SCSI Primary Commands-2 (SPC2) */ 181struct scsi_varlen_cdb_hdr { 182 __u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */ 183 __u8 control; 184 __u8 misc[5]; 185 __u8 additional_cdb_length; /* total cdb length - 8 */ 186 __be16 service_action; 187 /* service specific data follows */ 188}; 189 190/* 191 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 192 * T10/1561-D Revision 4 Draft dated 7th November 2002. 193 */ 194#define SAM_STAT_GOOD 0x00 195#define SAM_STAT_CHECK_CONDITION 0x02 196#define SAM_STAT_CONDITION_MET 0x04 197#define SAM_STAT_BUSY 0x08 198#define SAM_STAT_INTERMEDIATE 0x10 199#define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 200#define SAM_STAT_RESERVATION_CONFLICT 0x18 201#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ 202#define SAM_STAT_TASK_SET_FULL 0x28 203#define SAM_STAT_ACA_ACTIVE 0x30 204#define SAM_STAT_TASK_ABORTED 0x40 205#endif /* __KERNEL__ */ 206 207/* 208 * Status codes. These are deprecated as they are shifted 1 bit right 209 * from those found in the SCSI standards. This causes confusion for 210 * applications that are ported to several OSes. Prefer SAM Status codes 211 * above. 212 */ 213 214#define GOOD 0x00 215#define CHECK_CONDITION 0x01 216#define CONDITION_GOOD 0x02 217#define BUSY 0x04 218#define INTERMEDIATE_GOOD 0x08 219#define INTERMEDIATE_C_GOOD 0x0a 220#define RESERVATION_CONFLICT 0x0c 221#define COMMAND_TERMINATED 0x11 222#define QUEUE_FULL 0x14 223#define ACA_ACTIVE 0x18 224#define TASK_ABORTED 0x20 225 226#define STATUS_MASK 0xfe 227 228/* 229 * SENSE KEYS 230 */ 231 232#define NO_SENSE 0x00 233#define RECOVERED_ERROR 0x01 234#define NOT_READY 0x02 235#define MEDIUM_ERROR 0x03 236#define HARDWARE_ERROR 0x04 237#define ILLEGAL_REQUEST 0x05 238#define UNIT_ATTENTION 0x06 239#define DATA_PROTECT 0x07 240#define BLANK_CHECK 0x08 241#define COPY_ABORTED 0x0a 242#define ABORTED_COMMAND 0x0b 243#define VOLUME_OVERFLOW 0x0d 244#define MISCOMPARE 0x0e 245 246 247/* 248 * DEVICE TYPES 249 * Please keep them in 0x%02x format for $MODALIAS to work 250 */ 251 252#define TYPE_DISK 0x00 253#define TYPE_TAPE 0x01 254#define TYPE_PRINTER 0x02 255#define TYPE_PROCESSOR 0x03 /* HP scanners use this */ 256#define TYPE_WORM 0x04 /* Treated as ROM by our system */ 257#define TYPE_ROM 0x05 258#define TYPE_SCANNER 0x06 259#define TYPE_MOD 0x07 /* Magneto-optical disk - 260 * - treated as TYPE_DISK */ 261#define TYPE_MEDIUM_CHANGER 0x08 262#define TYPE_COMM 0x09 /* Communications device */ 263#define TYPE_RAID 0x0c 264#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ 265#define TYPE_RBC 0x0e 266#define TYPE_OSD 0x11 267#define TYPE_ZBC 0x14 268#define TYPE_WLUN 0x1e /* well-known logical unit */ 269#define TYPE_NO_LUN 0x7f 270 271#ifdef __KERNEL__ 272/* SCSI protocols; these are taken from SPC-3 section 7.5 */ 273enum scsi_protocol { 274 SCSI_PROTOCOL_FCP = 0, /* Fibre Channel */ 275 SCSI_PROTOCOL_SPI = 1, /* parallel SCSI */ 276 SCSI_PROTOCOL_SSA = 2, /* Serial Storage Architecture - Obsolete */ 277 SCSI_PROTOCOL_SBP = 3, /* firewire */ 278 SCSI_PROTOCOL_SRP = 4, /* Infiniband RDMA */ 279 SCSI_PROTOCOL_ISCSI = 5, 280 SCSI_PROTOCOL_SAS = 6, 281 SCSI_PROTOCOL_ADT = 7, /* Media Changers */ 282 SCSI_PROTOCOL_ATA = 8, 283 SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */ 284}; 285 286/* 287 * ScsiLun: 8 byte LUN. 288 */ 289struct scsi_lun { 290 __u8 scsi_lun[8]; 291}; 292#endif /* __KERNEL__ */ 293 294/* SPC asymmetric access states */ 295#define SCSI_ACCESS_STATE_OPTIMAL 0x00 296#define SCSI_ACCESS_STATE_ACTIVE 0x01 297#define SCSI_ACCESS_STATE_STANDBY 0x02 298#define SCSI_ACCESS_STATE_UNAVAILABLE 0x03 299#define SCSI_ACCESS_STATE_LBA 0x04 300#define SCSI_ACCESS_STATE_OFFLINE 0x0e 301#define SCSI_ACCESS_STATE_TRANSITIONING 0x0f 302 303/* Values for REPORT TARGET GROUP STATES */ 304#define SCSI_ACCESS_STATE_MASK 0x0f 305#define SCSI_ACCESS_STATE_PREFERRED 0x80 306 307/* Reporting options for REPORT ZONES */ 308enum zbc_zone_reporting_options { 309 ZBC_ZONE_REPORTING_OPTION_ALL = 0x00, 310 ZBC_ZONE_REPORTING_OPTION_EMPTY = 0x01, 311 ZBC_ZONE_REPORTING_OPTION_IMPLICIT_OPEN = 0x02, 312 ZBC_ZONE_REPORTING_OPTION_EXPLICIT_OPEN = 0x03, 313 ZBC_ZONE_REPORTING_OPTION_CLOSED = 0x04, 314 ZBC_ZONE_REPORTING_OPTION_FULL = 0x05, 315 ZBC_ZONE_REPORTING_OPTION_READONLY = 0x06, 316 ZBC_ZONE_REPORTING_OPTION_OFFLINE = 0x07, 317 /* 0x08 to 0x0f are reserved */ 318 ZBC_ZONE_REPORTING_OPTION_NEED_RESET_WP = 0x10, 319 ZBC_ZONE_REPORTING_OPTION_NON_SEQWRITE = 0x11, 320 /* 0x12 to 0x3e are reserved */ 321 ZBC_ZONE_REPORTING_OPTION_NON_WP = 0x3f, 322}; 323 324#define ZBC_REPORT_ZONE_PARTIAL 0x80 325 326/* Zone types of REPORT ZONES zone descriptors */ 327enum zbc_zone_type { 328 ZBC_ZONE_TYPE_CONV = 0x1, 329 ZBC_ZONE_TYPE_SEQWRITE_REQ = 0x2, 330 ZBC_ZONE_TYPE_SEQWRITE_PREF = 0x3, 331 /* 0x4 to 0xf are reserved */ 332}; 333 334/* Zone conditions of REPORT ZONES zone descriptors */ 335enum zbc_zone_cond { 336 ZBC_ZONE_COND_NO_WP = 0x0, 337 ZBC_ZONE_COND_EMPTY = 0x1, 338 ZBC_ZONE_COND_IMP_OPEN = 0x2, 339 ZBC_ZONE_COND_EXP_OPEN = 0x3, 340 ZBC_ZONE_COND_CLOSED = 0x4, 341 /* 0x5 to 0xc are reserved */ 342 ZBC_ZONE_COND_READONLY = 0xd, 343 ZBC_ZONE_COND_FULL = 0xe, 344 ZBC_ZONE_COND_OFFLINE = 0xf, 345}; 346 347#endif /* _SCSI_PROTO_H_ */ 348