M4521_BSP V3.02.000
The Board Support Package for M4521
UmasScsi.h
Go to the documentation of this file.
1/*
2 * scsi.h Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995, 1998, 1999 Eric Youngdale
4 * generic SCSI package header file by
5 * Initial versions: Drew Eckhardt
6 * Subsequent revisions: Eric Youngdale
7 *
8 * <drew@colorado.edu>
9 *
10 * Modified by Eric Youngdale eric@andante.org to
11 * add scatter-gather, multiple outstanding request, and other
12 * enhancements.
13 */
14
15#ifndef _SCSI_H_
16#define _SCSI_H_
17
19
20/*
21 * Some of the public constants are being moved to this file.
22 * We include it here so that what came from where is transparent.
23 */
24
25/*
26 * SCSI opcodes
27 */
28#define TEST_UNIT_READY 0x00
29#define REZERO_UNIT 0x01
30#define REQUEST_SENSE 0x03
31#define FORMAT_UNIT 0x04
32#define READ_BLOCK_LIMITS 0x05
33#define REASSIGN_BLOCKS 0x07
34#define READ_6 0x08
35#define WRITE_6 0x0a
36#define SEEK_6 0x0b
37#define READ_REVERSE 0x0f
38#define WRITE_FILEMARKS 0x10
39#define SPACE 0x11
40#define INQUIRY 0x12
41#define RECOVER_BUFFERED_DATA 0x14
42#define MODE_SELECT 0x15
43#define RESERVE 0x16
44#define RELEASE 0x17
45#define COPY 0x18
46#define ERASE 0x19
47#define MODE_SENSE 0x1a
48#define START_STOP 0x1b
49#define RECEIVE_DIAGNOSTIC 0x1c
50#define SEND_DIAGNOSTIC 0x1d
51#define ALLOW_MEDIUM_REMOVAL 0x1e
52
53#define SET_WINDOW 0x24
54#define READ_CAPACITY 0x25
55#define READ_10 0x28
56#define WRITE_10 0x2a
57#define SEEK_10 0x2b
58#define WRITE_VERIFY 0x2e
59#define VERIFY 0x2f
60#define SEARCH_HIGH 0x30
61#define SEARCH_EQUAL 0x31
62#define SEARCH_LOW 0x32
63#define SET_LIMITS 0x33
64#define PRE_FETCH 0x34
65#define READ_POSITION 0x34
66#define SYNCHRONIZE_CACHE 0x35
67#define LOCK_UNLOCK_CACHE 0x36
68#define READ_DEFECT_DATA 0x37
69#define MEDIUM_SCAN 0x38
70#define COMPARE 0x39
71#define COPY_VERIFY 0x3a
72#define WRITE_BUFFER 0x3b
73#define READ_BUFFER 0x3c
74#define UPDATE_BLOCK 0x3d
75#define READ_LONG 0x3e
76#define WRITE_LONG 0x3f
77#define CHANGE_DEFINITION 0x40
78#define WRITE_SAME 0x41
79#define READ_TOC 0x43
80#define LOG_SELECT 0x4c
81#define LOG_SENSE 0x4d
82#define MODE_SELECT_10 0x55
83#define RESERVE_10 0x56
84#define RELEASE_10 0x57
85#define MODE_SENSE_10 0x5a
86#define PERSISTENT_RESERVE_IN 0x5e
87#define PERSISTENT_RESERVE_OUT 0x5f
88#define MOVE_MEDIUM 0xa5
89#define READ_12 0xa8
90#define WRITE_12 0xaa
91#define WRITE_VERIFY_12 0xae
92#define SEARCH_HIGH_12 0xb0
93#define SEARCH_EQUAL_12 0xb1
94#define SEARCH_LOW_12 0xb2
95#define READ_ELEMENT_STATUS 0xb8
96#define SEND_VOLUME_TAG 0xb6
97#define WRITE_LONG_2 0xea
98
99/*
100 * Status codes
101 */
102#define GOOD 0x00
103#define CHECK_CONDITION 0x01
104#define CONDITION_GOOD 0x02
105#define BUSY 0x04
106#define INTERMEDIATE_GOOD 0x08
107#define INTERMEDIATE_C_GOOD 0x0a
108#define RESERVATION_CONFLICT 0x0c
109#define COMMAND_TERMINATED 0x11
110#define QUEUE_FULL 0x14
111#define STATUS_MASK 0x3e
112
113
114/*
115 * SENSE KEYS
116 */
117#define NO_SENSE 0x00
118#define RECOVERED_ERROR 0x01
119#define NOT_READY 0x02
120#define MEDIUM_ERROR 0x03
121#define HARDWARE_ERROR 0x04
122#define ILLEGAL_REQUEST 0x05
123#define UNIT_ATTENTION 0x06
124#define DATA_PROTECT 0x07
125#define BLANK_CHECK 0x08
126#define COPY_ABORTED 0x0a
127#define ABORTED_COMMAND 0x0b
128#define VOLUME_OVERFLOW 0x0d
129#define MISCOMPARE 0x0e
130
131
132/*
133 * DEVICE TYPES
134 */
135#define TYPE_DISK 0x00
136#define TYPE_TAPE 0x01
137#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
138#define TYPE_WORM 0x04 /* Treated as ROM by our system */
139#define TYPE_CDROM 0x05
140#define TYPE_SCANNER 0x06
141#define TYPE_MOD 0x07 /* Magneto-optical disk -
142 * - treated as TYPE_DISK */
143#define TYPE_MEDIUM_CHANGER 0x08
144#define TYPE_COMM 0x09 /* Communications device */
145#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
146#define TYPE_NO_LUN 0x7f
147
148/*
149 * MESSAGE CODES
150 */
151#define COMMAND_COMPLETE 0x00
152#define EXTENDED_MESSAGE 0x01
153#define EXTENDED_MODIFY_DATA_POINTER 0x00
154#define EXTENDED_SDTR 0x01
155#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
156#define EXTENDED_WDTR 0x03
157#define SAVE_POINTERS 0x02
158#define RESTORE_POINTERS 0x03
159#define DISCONNECT 0x04
160#define INITIATOR_ERROR 0x05
161#define ABORT 0x06
162#define MESSAGE_REJECT 0x07
163#define NOP 0x08
164#define MSG_PARITY_ERROR 0x09
165#define LINKED_CMD_COMPLETE 0x0a
166#define LINKED_FLG_CMD_COMPLETE 0x0b
167#define BUS_DEVICE_RESET 0x0c
168
169#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
170#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
171
172#define SIMPLE_QUEUE_TAG 0x20
173#define HEAD_OF_QUEUE_TAG 0x21
174#define ORDERED_QUEUE_TAG 0x22
175
176/*
177 * Here are some scsi specific ioctl commands which are sometimes useful.
178 */
179/* These are a few other constants only used by scsi devices */
180#define SCSI_IOCTL_GET_IDLUN 0x5382
181
182/* Used to turn on and off tagged queuing for scsi devices */
183
184#define SCSI_IOCTL_TAGGED_ENABLE 0x5383
185#define SCSI_IOCTL_TAGGED_DISABLE 0x5384
186
187/* Used to obtain the host number of a device. */
188#define SCSI_IOCTL_PROBE_HOST 0x5385
189
190/* Used to get the bus number for a device */
191#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
192
193
194/* copied from scatterlist.h, and remove scatterlist.h */
195typedef struct scatterlist
196{
197 char *address; /* Location data is to be transferred to */
198 char *alt_address; /* Location of actual if address is a
199 * dma indirect buffer. NULL otherwise */
200 uint32_t length;
201} SCATTER_LIST_T;
202
203#define ISA_DMA_THRESHOLD (0x00ffffff)
204
205
206/*
207 * These are the values that the SCpnt->sc_data_direction and
208 * SRpnt->sr_data_direction can take. These need to be set
209 * The SCSI_DATA_UNKNOWN value is essentially the default.
210 * In the event that the command creator didn't bother to
211 * set a value, you will see SCSI_DATA_UNKNOWN.
212 */
213#define SCSI_DATA_UNKNOWN 0
214#define SCSI_DATA_WRITE 1
215#define SCSI_DATA_READ 2
216#define SCSI_DATA_NONE 3
217
218/*
219 * Some defs, in case these are not defined elsewhere.
220 */
221#ifndef TRUE
222#define TRUE 1
223#endif
224#ifndef FALSE
225#define FALSE 0
226#endif
227
228
229#ifdef DEBUG
230#define SCSI_TIMEOUT (5*HZ)
231#else
232#define SCSI_TIMEOUT (2*HZ)
233#endif
234
235
236
237/*
238 * Use these to separate status msg and our bytes
239 *
240 * These are set by:
241 *
242 * status byte = set from target device
243 * msg_byte = return status from host adapter itself.
244 * host_byte = set by low-level driver to indicate status.
245 * driver_byte = set by mid-level.
246 */
247#define status_byte(result) (((result) >> 1) & 0x1f)
248#define msg_byte(result) (((result) >> 8) & 0xff)
249#define host_byte(result) (((result) >> 16) & 0xff)
250#define driver_byte(result) (((result) >> 24) & 0xff)
251#define suggestion(result) (driver_byte(result) & SUGGEST_MASK)
252
253#define sense_class(sense) (((sense) >> 4) & 0x7)
254#define sense_error(sense) ((sense) & 0xf)
255#define sense_valid(sense) ((sense) & 0x80);
256
257#define NEEDS_RETRY 0x2001
258#define SUCCESS 0x2002
259#define FAILED 0x2003
260#define QUEUED 0x2004
261#define SOFT_ERROR 0x2005
262#define ADD_TO_MLQUEUE 0x2006
263
264/*
265 * These are the values that scsi_cmd->state can take.
266 */
267#define SCSI_STATE_TIMEOUT 0x1000
268#define SCSI_STATE_FINISHED 0x1001
269#define SCSI_STATE_FAILED 0x1002
270#define SCSI_STATE_QUEUED 0x1003
271#define SCSI_STATE_UNUSED 0x1006
272#define SCSI_STATE_DISCONNECTING 0x1008
273#define SCSI_STATE_INITIALIZING 0x1009
274#define SCSI_STATE_BHQUEUE 0x100a
275#define SCSI_STATE_MLQUEUE 0x100b
276
277/*
278 * These are the values that the owner field can take.
279 * They are used as an indication of who the command belongs to.
280 */
281#define SCSI_OWNER_HIGHLEVEL 0x100
282#define SCSI_OWNER_MIDLEVEL 0x101
283#define SCSI_OWNER_LOWLEVEL 0x102
284#define SCSI_OWNER_ERROR_HANDLER 0x103
285#define SCSI_OWNER_BH_HANDLER 0x104
286#define SCSI_OWNER_NOBODY 0x105
287
288#define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
289
290#define IDENTIFY_BASE 0x80
291#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
292 ((can_disconnect) ? 0x40 : 0) |\
293 ((lun) & 0x07))
294
295
296/*
297 * the return of the status word will be in the following format :
298 * The low byte is the status returned by the SCSI command,
299 * with vendor specific bits masked.
300 *
301 * The next byte is the message which followed the SCSI status.
302 * This allows a stos to be used, since the Intel is a little
303 * endian machine.
304 *
305 * The final byte is a host return code, which is one of the following.
306 *
307 * IE
308 * lsb msb
309 * status msg host code
310 *
311 * Our errors returned by OUR driver, NOT SCSI message. Or'd with
312 * SCSI message passed back to driver <IF any>.
313 */
314#define DID_OK 0x00 /* NO error */
315#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
316#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
317#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
318#define DID_BAD_TARGET 0x04 /* BAD target. */
319#define DID_ABORT 0x05 /* Told to abort for some other reason */
320#define DID_PARITY 0x06 /* Parity error */
321#define DID_ERROR 0x07 /* Internal error */
322#define DID_RESET 0x08 /* Reset by somebody. */
323#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
324#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
325#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
326#define DRIVER_OK 0x00 /* Driver status */
327
328/*
329 * These indicate the error that occurred, and what is available.
330 */
331#define DRIVER_BUSY 0x01
332#define DRIVER_SOFT 0x02
333#define DRIVER_MEDIA 0x03
334#define DRIVER_ERROR 0x04
335
336#define DRIVER_INVALID 0x05
337#define DRIVER_TIMEOUT 0x06
338#define DRIVER_HARD 0x07
339#define DRIVER_SENSE 0x08
340
341#define SUGGEST_RETRY 0x10
342#define SUGGEST_ABORT 0x20
343#define SUGGEST_REMAP 0x30
344#define SUGGEST_DIE 0x40
345#define SUGGEST_SENSE 0x80
346#define SUGGEST_IS_OK 0xff
347
348#define DRIVER_MASK 0x0f
349#define SUGGEST_MASK 0xf0
350
351#define MAX_COMMAND_SIZE 12
352#define SCSI_SENSE_BUFFERSIZE 64
353
354/*
355 * SCSI command sets
356 */
357
358#define SCSI_UNKNOWN 0
359#define SCSI_1 1
360#define SCSI_1_CCS 2
361#define SCSI_2 3
362#define SCSI_3 4
363
364/*
365 * Every SCSI command starts with a one byte OP-code.
366 * The next byte's high three bits are the LUN of the
367 * device. Any multi-byte quantities are stored high byte
368 * first, and may have a 5 bit MSB in the same byte
369 * as the LUN.
370 */
371
372/*
373 * As the scsi do command functions are intelligent, and may need to
374 * redo a command, we need to keep track of the last command
375 * executed on each one.
376 */
377#define WAS_RESET 0x01
378#define WAS_TIMEDOUT 0x02
379#define WAS_SENSE 0x04
380#define IS_RESETTING 0x08
381#define IS_ABORTING 0x10
382#define ASKED_FOR_SENSE 0x20
383#define SYNC_RESET 0x40
384
385/*
386 * Add some typedefs so that we can prototyope a bunch of the functions.
387 */
388struct scsi_cmnd;
389struct scsi_request;
390struct umas_data;
391
392#define SCSI_CMND_MAGIC 0xE25C23A5
393#define SCSI_REQ_MAGIC 0x75F6D354
394
395
396#define RQ_INACTIVE (-1)
397#define RQ_ACTIVE 1
398#define RQ_SCSI_BUSY 0xffff
399#define RQ_SCSI_DONE 0xfffe
400#define RQ_SCSI_DISCONNECTING 0xffe0
401
402/*
403 * Ok, this is an expanded form so that we can use the same
404 * request for paging requests when that is implemented. In
405 * paging, 'bh' is NULL, and the semaphore is used to wait
406 * for read/write completion.
407 */
408struct request
409{
410 int cmd; /* READ or WRITE */
411 int errors;
412 uint32_t start_time;
413 uint32_t sector;
414 uint32_t nr_sectors;
415 uint32_t hard_sector, hard_nr_sectors;
416 uint32_t nr_segments;
417 uint32_t nr_hw_segments;
418 uint32_t current_nr_sectors;
419 void *special;
420 char *buffer;
421 struct buffer_head *bh;
422 struct buffer_head *bhtail;
423};
424
425
426
427/*
428 * The SCSI_CMD_T structure is used by scsi.c internally, and for communication
429 * with low level drivers that support multiple outstanding commands.
430 */
431typedef struct scsi_pointer
432{
433 char *ptr; /* data pointer */
434 int this_residual; /* left in this buffer */
435 struct scatterlist *buffer; /* which buffer */
436 int buffers_residual; /* how many buffers left */
437
438 volatile int Status;
439 volatile int Message;
440 volatile int have_data_in;
441 volatile int sent_command;
442 volatile int phase;
443} Scsi_Pointer;
444
445
446
447/*
448 * FIXME(eric) - one of the great regrets that I have is that I failed to define
449 * these structure elements as something like sc_foo instead of foo. This would
450 * make it so much easier to grep through sources and so forth. I propose that
451 * all new elements that get added to these structures follow this convention.
452 * As time goes on and as people have the stomach for it, it should be possible to
453 * go back and retrofit at least some of the elements here with with the prefix.
454 */
455typedef struct scsi_cmnd
456{
457 struct umas_data *umas;
458
459 /*
460 * A SCSI Command is assigned a nonzero serial_number when internal_cmnd
461 * passes it to the driver's queue command function. The serial_number
462 * is cleared when scsi_done is entered indicating that the command has
463 * been completed. If a timeout occurs, the serial number at the moment
464 * of timeout is copied into serial_number_at_timeout. By subsequently
465 * comparing the serial_number and serial_number_at_timeout fields
466 * during abort or reset processing, we can detect whether the command
467 * has already completed. This also detects cases where the command has
468 * completed and the SCSI Command structure has already being reused
469 * for another command, so that we can avoid incorrectly aborting or
470 * resetting the new command.
471 */
472 uint32_t serial_number;
473
474 uint32_t target;
475 uint32_t lun;
476 uint32_t channel;
477 uint8_t cmd_len;
478 uint8_t old_cmd_len;
479 uint8_t sc_data_direction;
480 uint8_t sc_old_data_direction;
481
482 /* These elements define the operation we are about to perform */
483 uint8_t cmnd[MAX_COMMAND_SIZE];
484 uint32_t request_bufflen; /* Actual request size */
485
486 uint8_t *request_buff; /* Actual requested buffer */
487
488 /* These elements define the operation we ultimately want to perform */
489 uint8_t data_cmnd[MAX_COMMAND_SIZE];
490 uint16_t old_use_sg; /* We save use_sg here when requesting sense info */
491 uint16_t use_sg; /* Number of pieces of scatter-gather */
492 uint16_t sglist_len; /* size of malloc'd scatter-gather list */
493 uint32_t bufflen; /* Size of data buffer */
494 void *buffer; /* Data buffer */
495
496 uint32_t transfersize; /* How much we are guaranteed to transfer
497 * with each SCSI transfer (ie, between
498 * disconnect reconnects.
499 * Probably == sector size */
500
501 struct request request; /* A copy of the command we are working on */
502
503 uint8_t sense_buffer[SCSI_SENSE_BUFFERSIZE];
504 /* obtained by REQUEST SENSE when CHECK
505 * CONDITION is received on original
506 * command (auto-sense) */
507 int result; /* Status code from lower level driver */
508} SCSI_CMD_T;
509
510/*
511 * Flag bit for the internal_timeout array
512 */
513#define NORMAL_TIMEOUT 0
514
515/*
516 * Definitions and prototypes used for scsi mid-level queue.
517 */
518#define SCSI_MLQUEUE_HOST_BUSY 0x1055
519#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
520
521/* old style reset request from external source (private to sg.c and
522 * scsi_error.c, supplied by scsi_obsolete.c)
523 * */
524#define SCSI_TRY_RESET_DEVICE 1
525#define SCSI_TRY_RESET_BUS 2
526#define SCSI_TRY_RESET_HOST 3
527
529
530#endif /* _SCSI_H_ */
531