| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

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 */
195 typedef 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
289/*
290 * the return of the status word will be in the following format :
291 * The low byte is the status returned by the SCSI command,
292 * with vendor specific bits masked.
293 *
294 * The next byte is the message which followed the SCSI status.
295 * This allows a stos to be used, since the Intel is a little
296 * endian machine.
297 *
298 * The final byte is a host return code, which is one of the following.
299 *
300 * IE
301 * lsb msb
302 * status msg host code
303 *
304 * Our errors returned by OUR driver, NOT SCSI message. Or'd with
305 * SCSI message passed back to driver <IF any>.
306 */
307#define DID_OK 0x00 /* NO error */
308#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
309#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
310#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
311#define DID_BAD_TARGET 0x04 /* BAD target. */
312#define DID_ABORT 0x05 /* Told to abort for some other reason */
313#define DID_PARITY 0x06 /* Parity error */
314#define DID_ERROR 0x07 /* Internal error */
315#define DID_RESET 0x08 /* Reset by somebody. */
316#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
317#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
318#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
319#define DRIVER_OK 0x00 /* Driver status */
320
321/*
322 * These indicate the error that occurred, and what is available.
323 */
324#define DRIVER_BUSY 0x01
325#define DRIVER_SOFT 0x02
326#define DRIVER_MEDIA 0x03
327#define DRIVER_ERROR 0x04
328
329#define DRIVER_INVALID 0x05
330#define DRIVER_TIMEOUT 0x06
331#define DRIVER_HARD 0x07
332#define DRIVER_SENSE 0x08
333
334#define SUGGEST_RETRY 0x10
335#define SUGGEST_ABORT 0x20
336#define SUGGEST_REMAP 0x30
337#define SUGGEST_DIE 0x40
338#define SUGGEST_SENSE 0x80
339#define SUGGEST_IS_OK 0xff
340
341#define DRIVER_MASK 0x0f
342#define SUGGEST_MASK 0xf0
343
344#define MAX_COMMAND_SIZE 12
345#define SCSI_SENSE_BUFFERSIZE 64
346
347/*
348 * SCSI command sets
349 */
350
351#define SCSI_UNKNOWN 0
352#define SCSI_1 1
353#define SCSI_1_CCS 2
354#define SCSI_2 3
355#define SCSI_3 4
356
357/*
358 * Every SCSI command starts with a one byte OP-code.
359 * The next byte's high three bits are the LUN of the
360 * device. Any multi-byte quantities are stored high byte
361 * first, and may have a 5 bit MSB in the same byte
362 * as the LUN.
363 */
364
365/*
366 * As the scsi do command functions are intelligent, and may need to
367 * redo a command, we need to keep track of the last command
368 * executed on each one.
369 */
370#define WAS_RESET 0x01
371#define WAS_TIMEDOUT 0x02
372#define WAS_SENSE 0x04
373#define IS_RESETTING 0x08
374#define IS_ABORTING 0x10
375#define ASKED_FOR_SENSE 0x20
376#define SYNC_RESET 0x40
377
378/*
379 * Add some typedefs so that we can prototyope a bunch of the functions.
380 */
381 struct scsi_cmnd;
382 struct scsi_request;
383 struct umas_data;
384
385#define SCSI_CMND_MAGIC 0xE25C23A5
386#define SCSI_REQ_MAGIC 0x75F6D354
387
388
389#define RQ_INACTIVE (-1)
390#define RQ_ACTIVE 1
391#define RQ_SCSI_BUSY 0xffff
392#define RQ_SCSI_DONE 0xfffe
393#define RQ_SCSI_DISCONNECTING 0xffe0
394
395/*
396 * Ok, this is an expanded form so that we can use the same
397 * request for paging requests when that is implemented. In
398 * paging, 'bh' is NULL, and the semaphore is used to wait
399 * for read/write completion.
400 */
401 struct request
402{
403 int cmd; /* READ or WRITE */
404 int errors;
405 uint32_t start_time;
406 uint32_t sector;
407 uint32_t nr_sectors;
408 uint32_t hard_sector, hard_nr_sectors;
409 uint32_t nr_segments;
410 uint32_t nr_hw_segments;
411 uint32_t current_nr_sectors;
412 void *special;
413 char *buffer;
414 struct buffer_head *bh;
415 struct buffer_head *bhtail;
416};
417
418
419
420/*
421 * The SCSI_CMD_T structure is used by scsi.c internally, and for communication
422 * with low level drivers that support multiple outstanding commands.
423 */
424 typedef struct scsi_pointer
425{
426 char *ptr; /* data pointer */
427 int this_residual; /* left in this buffer */
428 struct scatterlist *buffer; /* which buffer */
429 int buffers_residual; /* how many buffers left */
430
431 volatile int Status;
432 volatile int Message;
433 volatile int have_data_in;
434 volatile int sent_command;
435 volatile int phase;
436} Scsi_Pointer;
437
438
439
440/*
441 * FIXME(eric) - one of the great regrets that I have is that I failed to define
442 * these structure elements as something like sc_foo instead of foo. This would
443 * make it so much easier to grep through sources and so forth. I propose that
444 * all new elements that get added to these structures follow this convention.
445 * As time goes on and as people have the stomach for it, it should be possible to
446 * go back and retrofit at least some of the elements here with with the prefix.
447 */
448 typedef struct scsi_cmnd
449{
450 struct umas_data *umas;
451
452 /*
453 * A SCSI Command is assigned a nonzero serial_number when internal_cmnd
454 * passes it to the driver's queue command function. The serial_number
455 * is cleared when scsi_done is entered indicating that the command has
456 * been completed. If a timeout occurs, the serial number at the moment
457 * of timeout is copied into serial_number_at_timeout. By subsequently
458 * comparing the serial_number and serial_number_at_timeout fields
459 * during abort or reset processing, we can detect whether the command
460 * has already completed. This also detects cases where the command has
461 * completed and the SCSI Command structure has already being reused
462 * for another command, so that we can avoid incorrectly aborting or
463 * resetting the new command.
464 */
465 uint32_t serial_number;
466
467 uint32_t target;
468 uint32_t lun;
469 uint32_t channel;
470 uint8_t cmd_len;
471 uint8_t old_cmd_len;
472 uint8_t sc_data_direction;
473 uint8_t sc_old_data_direction;
474
475 /* These elements define the operation we are about to perform */
476 uint8_t cmnd[MAX_COMMAND_SIZE];
477 uint32_t request_bufflen; /* Actual request size */
478
479 uint8_t *request_buff; /* Actual requested buffer */
480
481 /* These elements define the operation we ultimately want to perform */
482 uint8_t data_cmnd[MAX_COMMAND_SIZE];
483 uint16_t old_use_sg; /* We save use_sg here when requesting sense info */
484 uint16_t use_sg; /* Number of pieces of scatter-gather */
485 uint16_t sglist_len; /* size of malloc'd scatter-gather list */
486 uint32_t bufflen; /* Size of data buffer */
487 void *buffer; /* Data buffer */
488
489 uint32_t transfersize; /* How much we are guaranteed to transfer
490 * with each SCSI transfer (ie, between
491 * disconnect reconnects.
492 * Probably == sector size */
493
494 struct request request; /* A copy of the command we are working on */
495
496 uint8_t sense_buffer[SCSI_SENSE_BUFFERSIZE];
497 /* obtained by REQUEST SENSE when CHECK
498 * CONDITION is received on original
499 * command (auto-sense) */
500 int result; /* Status code from lower level driver */
501} SCSI_CMD_T;
502
503/*
504 * Flag bit for the internal_timeout array
505 */
506#define NORMAL_TIMEOUT 0
507
508/*
509 * Definitions and prototypes used for scsi mid-level queue.
510 */
511#define SCSI_MLQUEUE_HOST_BUSY 0x1055
512#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
513
514/* old style reset request from external source (private to sg.c and
515 * scsi_error.c, supplied by scsi_obsolete.c)
516 * */
517#define SCSI_TRY_RESET_DEVICE 1
518#define SCSI_TRY_RESET_BUS 2
519#define SCSI_TRY_RESET_HOST 3
520
522
523#endif /* _SCSI_H_ */
524