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