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