1 /* 2 * (C) Copyright 2001 3 * Denis Peter, MPL AG Switzerland 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 #ifndef _SCSI_H 8 #define _SCSI_H 9 10 #include <asm/cache.h> 11 #include <linux/dma-direction.h> 12 13 struct scsi_cmd { 14 unsigned char cmd[16]; /* command */ 15 /* for request sense */ 16 unsigned char sense_buf[64] 17 __attribute__((aligned(ARCH_DMA_MINALIGN))); 18 unsigned char status; /* SCSI Status */ 19 unsigned char target; /* Target ID */ 20 unsigned char lun; /* Target LUN */ 21 unsigned char cmdlen; /* command len */ 22 unsigned long datalen; /* Total data length */ 23 unsigned char * pdata; /* pointer to data */ 24 unsigned char msgout[12]; /* Messge out buffer (NOT USED) */ 25 unsigned char msgin[12]; /* Message in buffer */ 26 unsigned char sensecmdlen; /* Sense command len */ 27 unsigned long sensedatalen; /* Sense data len */ 28 unsigned char sensecmd[6]; /* Sense command */ 29 unsigned long contr_stat; /* Controller Status */ 30 unsigned long trans_bytes; /* tranfered bytes */ 31 32 unsigned int priv; 33 enum dma_data_direction dma_dir; 34 }; 35 36 struct um_block_descriptor { 37 uint64_t um_block_addr; 38 uint32_t um_block_sz; 39 uint32_t reserve; 40 } __attribute__ ((packed)); 41 42 struct unmap_para_list { 43 uint16_t um_data_len; 44 uint16_t um_block_desc_len; 45 uint32_t reserve; 46 /*support only one block descriptor*/ 47 struct um_block_descriptor ub_desc; 48 } __attribute__ ((packed)); 49 50 /*----------------------------------------------------------- 51 ** 52 ** SCSI constants. 53 ** 54 **----------------------------------------------------------- 55 */ 56 57 /* 58 ** Messages 59 */ 60 61 #define M_COMPLETE (0x00) 62 #define M_EXTENDED (0x01) 63 #define M_SAVE_DP (0x02) 64 #define M_RESTORE_DP (0x03) 65 #define M_DISCONNECT (0x04) 66 #define M_ID_ERROR (0x05) 67 #define M_ABORT (0x06) 68 #define M_REJECT (0x07) 69 #define M_NOOP (0x08) 70 #define M_PARITY (0x09) 71 #define M_LCOMPLETE (0x0a) 72 #define M_FCOMPLETE (0x0b) 73 #define M_RESET (0x0c) 74 #define M_ABORT_TAG (0x0d) 75 #define M_CLEAR_QUEUE (0x0e) 76 #define M_INIT_REC (0x0f) 77 #define M_REL_REC (0x10) 78 #define M_TERMINATE (0x11) 79 #define M_SIMPLE_TAG (0x20) 80 #define M_HEAD_TAG (0x21) 81 #define M_ORDERED_TAG (0x22) 82 #define M_IGN_RESIDUE (0x23) 83 #define M_IDENTIFY (0x80) 84 85 #define M_X_MODIFY_DP (0x00) 86 #define M_X_SYNC_REQ (0x01) 87 #define M_X_WIDE_REQ (0x03) 88 #define M_X_PPR_REQ (0x04) 89 90 91 /* 92 ** Status 93 */ 94 95 #define S_GOOD (0x00) 96 #define S_CHECK_COND (0x02) 97 #define S_COND_MET (0x04) 98 #define S_BUSY (0x08) 99 #define S_INT (0x10) 100 #define S_INT_COND_MET (0x14) 101 #define S_CONFLICT (0x18) 102 #define S_TERMINATED (0x20) 103 #define S_QUEUE_FULL (0x28) 104 #define S_ILLEGAL (0xff) 105 #define S_SENSE (0x80) 106 107 /* 108 * Sense_keys 109 */ 110 111 #define SENSE_NO_SENSE 0x0 112 #define SENSE_RECOVERED_ERROR 0x1 113 #define SENSE_NOT_READY 0x2 114 #define SENSE_MEDIUM_ERROR 0x3 115 #define SENSE_HARDWARE_ERROR 0x4 116 #define SENSE_ILLEGAL_REQUEST 0x5 117 #define SENSE_UNIT_ATTENTION 0x6 118 #define SENSE_DATA_PROTECT 0x7 119 #define SENSE_BLANK_CHECK 0x8 120 #define SENSE_VENDOR_SPECIFIC 0x9 121 #define SENSE_COPY_ABORTED 0xA 122 #define SENSE_ABORTED_COMMAND 0xB 123 #define SENSE_VOLUME_OVERFLOW 0xD 124 #define SENSE_MISCOMPARE 0xE 125 126 127 #define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */ 128 #define SCSI_COMPARE 0x39 /* Compare (O) */ 129 #define SCSI_COPY 0x18 /* Copy (O) */ 130 #define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */ 131 #define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */ 132 #define SCSI_LOG_SELECT 0x4C /* Log Select (O) */ 133 #define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */ 134 #define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */ 135 #define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */ 136 #define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */ 137 #define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */ 138 #define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */ 139 #define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */ 140 #define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */ 141 #define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */ 142 #define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */ 143 /*************************************************************************** 144 * %%% Commands Unique to Direct Access Devices %%% 145 ***************************************************************************/ 146 #define SCSI_COMPARE 0x39 /* Compare (O) */ 147 #define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */ 148 #define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */ 149 #define SCSI_PREFETCH 0x34 /* Prefetch (O) */ 150 #define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */ 151 #define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */ 152 #define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */ 153 #define SCSI_READ16 0x48 154 #define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */ 155 #define SCSI_RD_CAPAC10 SCSI_RD_CAPAC /* Read Capacity (10) */ 156 #define SCSI_RD_CAPAC16 0x9e /* Read Capacity (16) */ 157 #define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */ 158 #define SCSI_READ_LONG 0x3E /* Read Long (O) */ 159 #define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */ 160 #define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */ 161 #define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */ 162 #define SCSI_REZERO 0x01 /* Rezero Unit (O) */ 163 #define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */ 164 #define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */ 165 #define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */ 166 #define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */ 167 #define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */ 168 #define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */ 169 #define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */ 170 #define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */ 171 #define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */ 172 #define SCSI_VERIFY 0x2F /* Verify (O) */ 173 #define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */ 174 #define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */ 175 #define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */ 176 #define SCSI_WRITE_LONG 0x3F /* Write Long (O) */ 177 #define SCSI_WRITE_SAME 0x41 /* Write Same (O) */ 178 #define SCSI_UNMAP 0x42 179 /** 180 * struct scsi_platdata - stores information about SCSI controller 181 * 182 * @base: Controller base address 183 * @max_lun: Maximum number of logical units 184 * @max_id: Maximum number of target ids 185 */ 186 struct scsi_platdata { 187 unsigned long base; 188 unsigned long max_lun; 189 unsigned long max_id; 190 }; 191 192 /* Operations for SCSI */ 193 struct scsi_ops { 194 /** 195 * exec() - execute a command 196 * 197 * @dev: SCSI bus 198 * @cmd: Command to execute 199 * @return 0 if OK, -ve on error 200 */ 201 int (*exec)(struct udevice *dev, struct scsi_cmd *cmd); 202 203 /** 204 * bus_reset() - reset the bus 205 * 206 * @dev: SCSI bus to reset 207 * @return 0 if OK, -ve on error 208 */ 209 int (*bus_reset)(struct udevice *dev); 210 }; 211 212 #define scsi_get_ops(dev) ((struct scsi_ops *)(dev)->driver->ops) 213 214 extern struct scsi_ops scsi_ops; 215 216 /** 217 * scsi_exec() - execute a command 218 * 219 * @dev: SCSI bus 220 * @cmd: Command to execute 221 * @return 0 if OK, -ve on error 222 */ 223 int scsi_exec(struct udevice *dev, struct scsi_cmd *cmd); 224 225 /** 226 * scsi_bus_reset() - reset the bus 227 * 228 * @dev: SCSI bus to reset 229 * @return 0 if OK, -ve on error 230 */ 231 int scsi_bus_reset(struct udevice *dev); 232 233 /** 234 * scsi_scan() - Scan all SCSI controllers for available devices 235 * 236 * @vebose: true to show information about each device found 237 */ 238 int scsi_scan(bool verbose); 239 240 /** 241 * scsi_scan_dev() - scan a SCSI bus and create devices 242 * 243 * @dev: SCSI bus 244 * @verbose: true to show information about each device found 245 */ 246 int scsi_scan_dev(struct udevice *dev, bool verbose); 247 248 #ifndef CONFIG_DM_SCSI 249 void scsi_low_level_init(int busdevfunc); 250 void scsi_init(void); 251 #endif 252 253 #define SCSI_IDENTIFY 0xC0 /* not used */ 254 #define SCSI_STD_INQUIRY_BYTES 36 255 #define SCSI_MAX_INQUIRY_BYTES 96 256 257 /* Hardware errors */ 258 #define SCSI_SEL_TIME_OUT 0x00000101 /* Selection time out */ 259 #define SCSI_HNS_TIME_OUT 0x00000102 /* Handshake */ 260 #define SCSI_MA_TIME_OUT 0x00000103 /* Phase error */ 261 #define SCSI_UNEXP_DIS 0x00000104 /* unexpected disconnect */ 262 263 #define SCSI_INT_STATE 0x00010000 /* unknown Interrupt number is stored in 16 LSB */ 264 265 #endif /* _SCSI_H */ 266