1
2
3
4
5
6
7
8
9 #ifndef _SCSI_H
10 #define _SCSI_H
11
12
13
14
15
16
17
18
19
20
21
22
23 #define TEST_UNIT_READY 0x00
24 #define REZERO_UNIT 0x01
25 #define REQUEST_SENSE 0x03
26 #define FORMAT_UNIT 0x04
27 #define REASSIGN_BLOCKS 0x07
28 #define READ_6 0x08
29 #define WRITE_6 0x0a
30 #define SEEK_6 0x0b
31 #define INQUIRY 0x12
32 #define MODE_SELECT 0x15
33 #define RESERVE 0x16
34 #define RELEASE 0x17
35 #define COPY 0x18
36 #define MODE_SENSE 0x1a
37 #define START_STOP 0x1b
38 #define RECIEVE_DAIGNOSTIC 0x1c
39 #define SEND_DIAGNOSTIC 0x1d
40 #define ALLOW_MEDIUM_REMOVAL 0x1e
41
42 #define READ_CAPACITY 0x25
43 #define READ_10 0x28
44 #define WRITE_10 0x2a
45 #define SEEK_10 0x2b
46 #define WRITE_VERIFY 0x2e
47 #define VERIFY 0x2f
48 #define SEARCH_HIGH 0x30
49 #define SEARCH_EQUAL 0x31
50 #define SEARCH_LOW 0x32
51 #define SET_LIMITS 0x33
52 #define COMPARE 0x39
53 #define COPY_VERIFY 0x3a
54
55 #define COMMAND_SIZE(opcode) ((opcode) ? ((opcode) > 0x20 ? 10 : 6) : 0)
56
57
58
59
60
61 #define COMMAND_COMPLETE 0x00
62 #define EXTENDED_MESSAGE 0x01
63 #define SAVE_POINTERS 0x02
64 #define RESTORE_POINTERS 0x03
65 #define DISCONNECT 0x04
66 #define INITIATOR_ERROR 0x05
67 #define ABORT 0x06
68 #define MESSAGE_REJECT 0x07
69 #define NOP 0x08
70 #define MSG_PARITY_ERROR 0x09
71 #define LINKED_CMD_COMPLETE 0x0a
72 #define LINKED_FLG_CMD_COMPLETE 0x0b
73 #define BUS_DEVICE_RESET 0x0c
74 #define IDENTIFY_BASE 0x80
75 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
76 ((can_disconnect) ? 0x40 : 0) |\
77 ((lun) & 0x07))
78
79
80
81
82
83
84 #define GOOD 0x00
85 #define CHECK_CONDITION 0x01
86 #define CONDITION_GOOD 0x02
87 #define BUSY 0x04
88 #define INTERMEDIATE_GOOD 0x08
89 #define INTERMEDIATE_C_GOOD 0x0a
90 #define RESERVATION_CONFLICT 0x0c
91
92 #define STATUS_MASK 0x1e
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 #define DID_OK 0x00
115
116 #define DID_NO_CONNECT 0x01
117
118 #define DID_BUS_BUSY 0x02
119
120 #define DID_TIME_OUT 0x03
121
122 #define DID_BAD_TARGET 0x04
123
124 #define DID_ABORT 0x05
125
126
127
128 #define DID_PARITY 0x06
129
130
131
132 #define DID_ERROR 0x07
133
134
135
136 #define DID_RESET 0x08
137
138
139
140 #define DID_BAD_INTR 0x09
141
142
143
144
145 #define DRIVER_OK 0x00
146
147
148
149
150
151 #define DRIVER_BUSY 0x01
152 #define DRIVER_SOFT 0x02
153 #define DRIVER_MEDIA 0x03
154 #define DRIVER_ERROR 0x04
155
156 #define DRIVER_INVALID 0x05
157 #define DRIVER_TIMEOUT 0x06
158 #define DRIVER_HARD 0x07
159
160 #define SUGGEST_RETRY 0x08
161 #define SUGGEST_ABORT 0x09
162 #define SUGGEST_REMAP 0x0a
163 #define SUGGEST_DIE 0x0b
164
165 #define DRIVER_SENSE 0x10
166
167 #define DRIVER_MASK 0x0f
168 #define SUGGEST_MASK 0xf0
169
170
171
172
173
174
175 #define NO_SENSE 0x00
176 #define RECOVERED_ERROR 0x01
177 #define NOT_READY 0x02
178 #define MEDIUM_ERROR 0x03
179 #define HARDWARE_ERROR 0x04
180 #define ILLEGAL_REQUEST 0x05
181 #define UNIT_ATTENTION 0x06
182 #define DATA_PROTECT 0x07
183 #define BLANK_CHECK 0x08
184 #define COPY_ABORTED 0x0a
185 #define ABORTED_COMMAND 0x0b
186 #define VOLUME_OVERFLOW 0x0d
187 #define MISCOMPARE 0x0e
188
189
190
191
192
193
194
195 #define TYPE_DISK 0x00
196 #define TYPE_TAPE 0x01
197 #define TYPE_WORM 0x04
198 #define TYPE_ROM 0x05
199 #define TYPE_NO_LUN 0x7f
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 typedef struct scsi_device {
215 unsigned char host_no, id, lun;
216 unsigned writeable:1;
217 unsigned removable:1;
218 unsigned random:1;
219 } Scsi_Device;
220
221
222
223
224 #define status_byte(result) (((result) >> 1) & 0xf)
225 #define msg_byte(result) (((result) >> 8) & 0xff)
226 #define host_byte(result) (((result) >> 16) & 0xff)
227 #define driver_byte(result) (((result) >> 24) & 0xff)
228 #define sugestion(result) (driver_byte(result) & SUGGEST_MASK)
229
230 #define sense_class(sense) (((sense) >> 4) & 0x7)
231 #define sense_error(sense) ((sense) & 0xf)
232 #define sense_valid(sense) ((sense) & 0x80);
233
234
235
236
237
238 #define MAX_SCSI_DEVICE 4
239 extern int NR_SCSI_DEVICES;
240 extern Scsi_Device scsi_devices[MAX_SCSI_DEVICE];
241
242
243
244
245
246
247 extern int scsi_abort (int host, int code);
248
249
250
251
252
253 extern void scsi_dev_init (void);
254
255
256
257
258
259
260
261 extern void scsi_do_cmd (int host, unsigned char target, const void *cmnd ,
262 void *buffer, unsigned bufflen, void (*done)(int,int),
263 int timeout, unsigned char *sense_buffer, int retries);
264
265 extern int scsi_reset (int host);
266 #endif