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