blob: 20f6932602bcf9f7cf96fe7d5f9df4a83fdf1f71 [file] [log] [blame]
wdenke85390d2002-04-01 14:29:03 +00001/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenke85390d2002-04-01 14:29:03 +00006 */
7 #ifndef _SCSI_H
8 #define _SCSI_H
9
Simon Glassb9560ad2017-06-14 21:28:30 -060010struct scsi_cmd {
wdenke85390d2002-04-01 14:29:03 +000011 unsigned char cmd[16]; /* command */
Puneet Saxenaf5766132012-04-03 14:56:06 +053012 /* for request sense */
13 unsigned char sense_buf[64]
14 __attribute__((aligned(ARCH_DMA_MINALIGN)));
wdenke85390d2002-04-01 14:29:03 +000015 unsigned char status; /* SCSI Status */
16 unsigned char target; /* Target ID */
17 unsigned char lun; /* Target LUN */
18 unsigned char cmdlen; /* command len */
19 unsigned long datalen; /* Total data length */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020020 unsigned char * pdata; /* pointer to data */
wdenke85390d2002-04-01 14:29:03 +000021 unsigned char msgout[12]; /* Messge out buffer (NOT USED) */
22 unsigned char msgin[12]; /* Message in buffer */
23 unsigned char sensecmdlen; /* Sense command len */
24 unsigned long sensedatalen; /* Sense data len */
25 unsigned char sensecmd[6]; /* Sense command */
26 unsigned long contr_stat; /* Controller Status */
27 unsigned long trans_bytes; /* tranfered bytes */
28
29 unsigned int priv;
Simon Glassb9560ad2017-06-14 21:28:30 -060030};
wdenke85390d2002-04-01 14:29:03 +000031
32/*-----------------------------------------------------------
33**
34** SCSI constants.
35**
36**-----------------------------------------------------------
37*/
38
39/*
40** Messages
41*/
42
43#define M_COMPLETE (0x00)
44#define M_EXTENDED (0x01)
45#define M_SAVE_DP (0x02)
46#define M_RESTORE_DP (0x03)
47#define M_DISCONNECT (0x04)
48#define M_ID_ERROR (0x05)
49#define M_ABORT (0x06)
50#define M_REJECT (0x07)
51#define M_NOOP (0x08)
52#define M_PARITY (0x09)
53#define M_LCOMPLETE (0x0a)
54#define M_FCOMPLETE (0x0b)
55#define M_RESET (0x0c)
56#define M_ABORT_TAG (0x0d)
57#define M_CLEAR_QUEUE (0x0e)
58#define M_INIT_REC (0x0f)
59#define M_REL_REC (0x10)
60#define M_TERMINATE (0x11)
61#define M_SIMPLE_TAG (0x20)
62#define M_HEAD_TAG (0x21)
63#define M_ORDERED_TAG (0x22)
64#define M_IGN_RESIDUE (0x23)
Wolfgang Denk53677ef2008-05-20 16:00:29 +020065#define M_IDENTIFY (0x80)
wdenke85390d2002-04-01 14:29:03 +000066
67#define M_X_MODIFY_DP (0x00)
68#define M_X_SYNC_REQ (0x01)
69#define M_X_WIDE_REQ (0x03)
70#define M_X_PPR_REQ (0x04)
71
72
73/*
74** Status
75*/
76
77#define S_GOOD (0x00)
78#define S_CHECK_COND (0x02)
79#define S_COND_MET (0x04)
80#define S_BUSY (0x08)
81#define S_INT (0x10)
82#define S_INT_COND_MET (0x14)
83#define S_CONFLICT (0x18)
84#define S_TERMINATED (0x20)
85#define S_QUEUE_FULL (0x28)
86#define S_ILLEGAL (0xff)
87#define S_SENSE (0x80)
88
89/*
90 * Sense_keys
91 */
92
93#define SENSE_NO_SENSE 0x0
94#define SENSE_RECOVERED_ERROR 0x1
95#define SENSE_NOT_READY 0x2
96#define SENSE_MEDIUM_ERROR 0x3
97#define SENSE_HARDWARE_ERROR 0x4
98#define SENSE_ILLEGAL_REQUEST 0x5
99#define SENSE_UNIT_ATTENTION 0x6
100#define SENSE_DATA_PROTECT 0x7
101#define SENSE_BLANK_CHECK 0x8
102#define SENSE_VENDOR_SPECIFIC 0x9
103#define SENSE_COPY_ABORTED 0xA
104#define SENSE_ABORTED_COMMAND 0xB
105#define SENSE_VOLUME_OVERFLOW 0xD
106#define SENSE_MISCOMPARE 0xE
107
108
109#define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */
110#define SCSI_COMPARE 0x39 /* Compare (O) */
111#define SCSI_COPY 0x18 /* Copy (O) */
112#define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */
113#define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */
114#define SCSI_LOG_SELECT 0x4C /* Log Select (O) */
115#define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */
116#define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */
117#define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */
118#define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */
119#define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */
120#define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */
121#define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */
122#define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */
123#define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */
124#define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */
125/***************************************************************************
126 * %%% Commands Unique to Direct Access Devices %%%
127 ***************************************************************************/
128#define SCSI_COMPARE 0x39 /* Compare (O) */
129#define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */
130#define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */
131#define SCSI_PREFETCH 0x34 /* Prefetch (O) */
132#define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */
133#define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */
134#define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */
Mark Langsdorf2b42c932015-06-05 00:58:45 +0100135#define SCSI_READ16 0x48
wdenke85390d2002-04-01 14:29:03 +0000136#define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */
Gabe Black19d1d412012-10-29 05:23:54 +0000137#define SCSI_RD_CAPAC10 SCSI_RD_CAPAC /* Read Capacity (10) */
138#define SCSI_RD_CAPAC16 0x9e /* Read Capacity (16) */
wdenke85390d2002-04-01 14:29:03 +0000139#define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */
140#define SCSI_READ_LONG 0x3E /* Read Long (O) */
141#define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */
142#define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */
143#define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */
144#define SCSI_REZERO 0x01 /* Rezero Unit (O) */
145#define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */
146#define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */
147#define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */
148#define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */
149#define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */
150#define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */
151#define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */
152#define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */
153#define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */
154#define SCSI_VERIFY 0x2F /* Verify (O) */
155#define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */
156#define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */
157#define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */
158#define SCSI_WRITE_LONG 0x3F /* Write Long (O) */
159#define SCSI_WRITE_SAME 0x41 /* Write Same (O) */
160
Michal Simeke8a016b2016-09-08 15:06:45 +0200161/**
162 * struct scsi_platdata - stores information about SCSI controller
163 *
164 * @base: Controller base address
165 * @max_lun: Maximum number of logical units
166 * @max_id: Maximum number of target ids
167 */
168struct scsi_platdata {
169 unsigned long base;
170 unsigned long max_lun;
171 unsigned long max_id;
172};
Simon Glass04368242017-06-14 21:28:28 -0600173
Simon Glass322f73f2017-06-14 21:28:39 -0600174/* Operations for SCSI */
175struct scsi_ops {
176 /**
177 * exec() - execute a command
178 *
179 * @dev: SCSI bus
180 * @cmd: Command to execute
181 * @return 0 if OK, -ve on error
182 */
183 int (*exec)(struct udevice *dev, struct scsi_cmd *cmd);
184
185 /**
186 * bus_reset() - reset the bus
187 *
188 * @dev: SCSI bus to reset
189 * @return 0 if OK, -ve on error
190 */
191 int (*bus_reset)(struct udevice *dev);
192};
193
Simon Glass7cf1afc2017-06-14 21:28:37 -0600194#ifndef CONFIG_DM_SCSI
Simon Glass04368242017-06-14 21:28:28 -0600195void scsi_low_level_init(int busdevfunc);
196void scsi_init(void);
Michal Simeke8a016b2016-09-08 15:06:45 +0200197#endif
198
Simon Glass4682c8a2017-06-14 21:28:40 -0600199int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb);
200int scsi_bus_reset(struct udevice *dev);
Simon Glass04368242017-06-14 21:28:28 -0600201
Simon Glass8eab1a52017-06-14 21:28:41 -0600202/**
203 * scsi_scan() - Scan all SCSI controllers for available devices
204 *
205 * @vebose: true to show information about each device found
Simon Glass04368242017-06-14 21:28:28 -0600206 */
Simon Glass8eab1a52017-06-14 21:28:41 -0600207int scsi_scan(bool verbose);
Simon Glass04368242017-06-14 21:28:28 -0600208
wdenke85390d2002-04-01 14:29:03 +0000209#define SCSI_IDENTIFY 0xC0 /* not used */
210
211/* Hardware errors */
212#define SCSI_SEL_TIME_OUT 0x00000101 /* Selection time out */
213#define SCSI_HNS_TIME_OUT 0x00000102 /* Handshake */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200214#define SCSI_MA_TIME_OUT 0x00000103 /* Phase error */
wdenke85390d2002-04-01 14:29:03 +0000215#define SCSI_UNEXP_DIS 0x00000104 /* unexpected disconnect */
216
217#define SCSI_INT_STATE 0x00010000 /* unknown Interrupt number is stored in 16 LSB */
218
wdenke85390d2002-04-01 14:29:03 +0000219#endif /* _SCSI_H */