1 /* 2 * scsi.h Copyright (C) 1992 Drew Eckhardt 3 * generic SCSI package header file by 4 * Drew Eckhardt 5 * 6 * <drew@colorado.edu> 7 * 8 * Modified by Eric Youngdale eric@tantalus.nrl.navy.mil to 9 * add scatter-gather, multiple outstanding request, and other 10 * enhancements. 11 */ 12
13 #ifndef_SCSI_H 14 #define_SCSI_H 15
16 /* 17 $Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/scsi.h,v 1.3 1993/09/24 12:20:33 drew Exp $ 18
19 For documentation on the OPCODES, MESSAGES, and SENSE values, 20 please consult the SCSI standard. 21
22 */ 23
24 /* 25 SCSI opcodes 26 */ 27
28 #defineTEST_UNIT_READY 0x00
29 #defineREZERO_UNIT 0x01
30 #defineREQUEST_SENSE 0x03
31 #defineFORMAT_UNIT 0x04
32 #defineREAD_BLOCK_LIMITS 0x05
33 #defineREASSIGN_BLOCKS 0x07
34 #defineREAD_6 0x08
35 #defineWRITE_6 0x0a
36 #defineSEEK_6 0x0b
37 #define READ_REVERSE 0x0f
38 #defineWRITE_FILEMARKS 0x10
39 #defineSPACE 0x11
40 #defineINQUIRY 0x12
41 #define RECOVER_BUFFERED_DATA 0x14
42 #defineMODE_SELECT 0x15
43 #defineRESERVE 0x16
44 #define RELEASE 0x17
45 #defineCOPY 0x18
46 #defineERASE 0x19
47 #defineMODE_SENSE 0x1a
48 #defineSTART_STOP 0x1b
49 #define RECEIVE_DIAGNOSTIC 0x1c
50 #defineSEND_DIAGNOSTIC 0x1d
51 #defineALLOW_MEDIUM_REMOVAL 0x1e
52
53 #defineREAD_CAPACITY 0x25
54 #defineREAD_10 0x28
55 #defineWRITE_10 0x2a
56 #defineSEEK_10 0x2b
57 #defineWRITE_VERIFY 0x2e
58 #define VERIFY 0x2f
59 #defineSEARCH_HIGH 0x30
60 #defineSEARCH_EQUAL 0x31
61 #defineSEARCH_LOW 0x32
62 #define SET_LIMITS 0x33
63 #define PRE_FETCH 0x34
64 #defineREAD_POSITION 0x34
65 #define SYNCHRONIZE_CACHE 0x35
66 #define LOCK_UNLOCK_CACHE 0x36
67 #define READ_DEFECT_DATA 0x37
68 #defineCOMPARE 0x39
69 #defineCOPY_VERIFY 0x3a
70 #defineWRITE_BUFFER 0x3b
71 #define READ_BUFFER 0x3c
72 #define READ_LONG 0x3e
73 #defineCHANGE_DEFINITION 0x40
74 #defineLOG_SELECT 0x4c
75 #define LOG_SENSE 0x4d
76 #defineMODE_SELECT_10 0x55
77 #defineMODE_SENSE_10 0x5a
78
79 externvoidscsi_make_blocked_list(void);
80 externvolatileintin_scan_scsis;
81 externconstunsignedcharscsi_command_size[8];
82 #defineCOMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
83
84 /* 85 MESSAGE CODES 86 */ 87
88 #defineCOMMAND_COMPLETE 0x00
89 #defineEXTENDED_MESSAGE 0x01
90 #defineEXTENDED_MODIFY_DATA_POINTER 0x00
91 #defineEXTENDED_SDTR 0x01
92 #defineEXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ 93 #defineEXTENDED_WDTR 0x03
94 #defineSAVE_POINTERS 0x02
95 #defineRESTORE_POINTERS 0x03
96 #defineDISCONNECT 0x04
97 #define INITIATOR_ERROR 0x05
98 #defineABORT 0x06
99 #defineMESSAGE_REJECT 0x07
100 #defineNOP 0x08
101 #define MSG_PARITY_ERROR 0x09
102 #defineLINKED_CMD_COMPLETE 0x0a
103 #defineLINKED_FLG_CMD_COMPLETE 0x0b
104 #defineBUS_DEVICE_RESET 0x0c
105
106 #defineINITIATE_RECOVERY 0x0f /* SCSI-II only */ 107 #define RELEASE_RECOVERY 0x10 /* SCSI-II only */ 108
109 #defineSIMPLE_QUEUE_TAG 0x20
110 #defineHEAD_OF_QUEUE_TAG 0x21
111 #defineORDERED_QUEUE_TAG 0x22
112
113 #defineIDENTIFY_BASE 0x80
114 #defineIDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
115 ((can_disconnect) ? 0x40 : 0) |\
116 ((lun) & 0x07))
117
118
119 /* 120 Status codes 121 */ 122
123 #defineGOOD 0x00
124 #defineCHECK_CONDITION 0x01
125 #defineCONDITION_GOOD 0x02
126 #defineBUSY 0x04
127 #defineINTERMEDIATE_GOOD 0x08
128 #defineINTERMEDIATE_C_GOOD 0x0a
129 #defineRESERVATION_CONFLICT 0x0c
130 #defineQUEUE_FULL 0x1a
131
132 #defineSTATUS_MASK 0x1e
133
134 /* 135 the return of the status word will be in the following format : 136 The low byte is the status returned by the SCSI command, 137 with vendor specific bits masked. 138
139 The next byte is the message which followed the SCSI status. 140 This allows a stos to be used, since the Intel is a little 141 endian machine. 142
143 The final byte is a host return code, which is one of the following. 144
145 IE 146 lsb msb 147 status msg host code 148
149 Our errors returned by OUR driver, NOT SCSI message. Or'd with 150 SCSI message passed back to driver <IF any>. 151 */ 152
153 /* NO error */ 154 #defineDID_OK 0x00
155 /* Couldn't connect before timeout period */ 156 #defineDID_NO_CONNECT 0x01
157 /* BUS stayed busy through time out period */ 158 #defineDID_BUS_BUSY 0x02
159 /* TIMED OUT for other reason */ 160 #defineDID_TIME_OUT 0x03
161 /* BAD target. */ 162 #defineDID_BAD_TARGET 0x04
163 /* Told to abort for some other reason */ 164 #defineDID_ABORT 0x05
165 /* 166 Parity error 167 */ 168 #defineDID_PARITY 0x06
169 /* 170 Internal error 171 */ 172 #defineDID_ERROR 0x07
173 /* 174 Reset by somebody. 175 */ 176 #defineDID_RESET 0x08
177 /* 178 Got an interrupt we weren't expecting. 179 */ 180 #defineDID_BAD_INTR 0x09
181
182 /* 183 Driver status 184 */ 185 #defineDRIVER_OK 0x00
186
187 /* 188 These indicate the error that occurred, and what is available. 189 */ 190
191 #define DRIVER_BUSY 0x01
192 #defineDRIVER_SOFT 0x02
193 #define DRIVER_MEDIA 0x03
194 #defineDRIVER_ERROR 0x04
195
196 #defineDRIVER_INVALID 0x05
197 #defineDRIVER_TIMEOUT 0x06
198 #defineDRIVER_HARD 0x07
199
200 #defineSUGGEST_RETRY 0x10
201 #defineSUGGEST_ABORT 0x20
202 #defineSUGGEST_REMAP 0x30
203 #defineSUGGEST_DIE 0x40
204 #defineSUGGEST_SENSE 0x80
205 #defineSUGGEST_IS_OK 0xff
206
207 #defineDRIVER_SENSE 0x08
208
209 #define DRIVER_MASK 0x0f
210 #defineSUGGEST_MASK 0xf0
211
212 /* 213
214 SENSE KEYS 215 */ 216
217 #defineNO_SENSE 0x00
218 #defineRECOVERED_ERROR 0x01
219 #defineNOT_READY 0x02
220 #defineMEDIUM_ERROR 0x03
221 #defineHARDWARE_ERROR 0x04
222 #defineILLEGAL_REQUEST 0x05
223 #defineUNIT_ATTENTION 0x06
224 #defineDATA_PROTECT 0x07
225 #defineBLANK_CHECK 0x08
226 #defineCOPY_ABORTED 0x0a
227 #defineABORTED_COMMAND 0x0b
228 #defineVOLUME_OVERFLOW 0x0d
229 #defineMISCOMPARE 0x0e
230
231
232 /* 233 DEVICE TYPES 234
235 */ 236
237 #defineTYPE_DISK 0x00
238 #defineTYPE_TAPE 0x01
239 #defineTYPE_PROCESSOR 0x03 /* HP scanners use this */ 240 #defineTYPE_WORM 0x04 /* Treated as ROM by our system */ 241 #defineTYPE_ROM 0x05
242 #defineTYPE_SCANNER 0x06
243 #defineTYPE_MOD 0x07 /* Magneto-optical disk - treated as TYPE_DISK */ 244 #define TYPE_NO_LUN 0x7f
245
246
247 #defineMAX_COMMAND_SIZE 12
248 /* 249 SCSI command sets 250
251 */ 252
253 #define SCSI_UNKNOWN 0
254 #define SCSI_1 1
255 #define SCSI_1_CCS 2
256 #defineSCSI_2 3
257
258 /* 259 Every SCSI command starts with a one byte OP-code. 260 The next byte's high three bits are the LUN of the 261 device. Any multi-byte quantities are stored high byte 262 first, and may have a 5 bit MSB in the same byte 263 as the LUN. 264 */ 265
266 /* 267 Manufacturers list 268 */ 269
270 #defineSCSI_MAN_UNKNOWN 0
271 #defineSCSI_MAN_NEC 1
272 #defineSCSI_MAN_TOSHIBA 2
273 #defineSCSI_MAN_NEC_OLDCDR 3
274
275 /* 276 The scsi_device struct contains what we know about each given scsi 277 device. 278 */ 279
280 typedefstructscsi_device{ 281 structscsi_device * next; /* Used for linked list */ 282 unsignedcharid, lun;
283 unsignedintmanufacturer; /* Manufacturer of device, for using vendor-specific cmd's */ 284 intattached; /* # of high level drivers attached to this */ 285 intaccess_count; /* Count of open channels/mounts */ 286 structwait_queue * device_wait; /* Used to wait if device is busy */ 287 structScsi_Host * host;
288 void (*scsi_request_fn)(void); /* Used to jumpstart things after an ioctl */ 289 void *hostdata; /* available to low-level driver */ 290 chartype;
291 charscsi_level;
292 unsignedwriteable:1;
293 unsignedremovable:1;
294 unsignedrandom:1;
295 unsignedchanged:1; /* Data invalid due to media change */ 296 unsignedbusy:1; /* Used to prevent races */ 297 unsignedlockable:1; /* Able to prevent media removal */ 298 unsignedborken:1; /* Tell the Seagate driver to be 299 painfully slow on this device */ 300 unsignedtagged_supported:1; /* Supports SCSI-II tagged queuing */ 301 unsignedtagged_queue:1; /*SCSI-II tagged queuing enabled */ 302 unsigneddisconnect:1; /* can disconnect */ 303 unsignedsoft_reset:1; /* Uses soft reset option */ 304 unsignedcharcurrent_tag; /* current tag */ 305 unsignedsync:1; /* Negotiate for sync transfers */ 306 unsignedchar sync_min_period; /* Not less than this period */ 307 unsignedchar sync_max_offset; /* Not greater than this offset */ 308 }Scsi_Device;
309 /* 310 Use these to separate status msg and our bytes 311 */ 312
313 #definestatus_byte(result) (((result) >> 1) & 0xf)
314 #definemsg_byte(result) (((result) >> 8) & 0xff)
315 #definehost_byte(result) (((result) >> 16) & 0xff)
316 #definedriver_byte(result) (((result) >> 24) & 0xff)
317 #definesuggestion(result) (driver_byte(result) & SUGGEST_MASK)
318
319 #definesense_class(sense) (((sense) >> 4) & 0x7)
320 #definesense_error(sense) ((sense) & 0xf)
321 #define sense_valid(sense) ((sense) & 0x80);
322
323 /* 324 These are the SCSI devices available on the system. 325 */ 326
327 externScsi_Device * scsi_devices;
328 /* 329 Initializes all SCSI devices. This scans all scsi busses. 330 */ 331
332 externunsignedlongscsi_dev_init (unsignedlong, unsignedlong);
333
334 structscatterlist{ 335 char * address; /* Location data is to be transferred to */ 336 char * alt_address; /* Location of actual if address is a 337 dma indirect buffer. NULL otherwise */ 338 unsignedintlength;
339 };
340
341 #defineISA_DMA_THRESHOLD (0x00ffffff)
342 #defineCONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data)
343
344
345 /* 346 * These are the return codes for the abort and reset functions. The mid-level 347 * code uses these to decide what to do next. Each of the low level abort 348 * and reset functions must correctly indicate what it has done. 349 */ 350
351 /* We did not do anything. Wait 352 some more for this command to complete, and if this does not work, try 353 something more serious. */ 354 #defineSCSI_ABORT_SNOOZE 0
355
356 /* This means that we were able to abort the command. We have already 357 called the mid-level done function, and do not expect an interrupt that will 358 lead to another call to the mid-level done function for this command */ 359 #defineSCSI_ABORT_SUCCESS 1
360
361 /* We called for an abort of this command, and we should get an interrupt 362 when this succeeds. Thus we should not restore the timer for this 363 command in the mid-level abort function. */ 364 #defineSCSI_ABORT_PENDING 2
365
366 /* Unable to abort - command is currently on the bus. Grin and bear it. */ 367 #defineSCSI_ABORT_BUSY 3
368
369 /* The command is not active in the low level code. Command probably 370 finished. */ 371 #defineSCSI_ABORT_NOT_RUNNING 4
372
373 /* Something went wrong. The low level driver will indicate the correct 374 error condition when it calls scsi_done, so the mid-level abort function 375 can simply wait until this comes through */ 376 #defineSCSI_ABORT_ERROR 5
377
378 /* We do not know how to reset the bus, or we do not want to. Bummer. 379 Anyway, just wait a little more for the command in question, and hope that 380 it eventually finishes. If it never finishes, the SCSI device could 381 hang, so use this with caution. */ 382 #defineSCSI_RESET_SNOOZE 0
383
384 /* We do not know how to reset the bus, or we do not want to. Bummer. 385 We have given up on this ever completing. The mid-level code will 386 request sense information to decide how to proceed from here. */ 387 #defineSCSI_RESET_PUNT 1
388
389 /* This means that we were able to reset the bus. We have restarted all of 390 the commands that should be restarted, and we should be able to continue 391 on normally from here. We do not expect any interrupts that will return 392 DID_RESET to any of the other commands in the host_queue, and the mid-level 393 code does not need to do anything special to keep the commands alive. */ 394 #defineSCSI_RESET_SUCCESS 2
395
396 /* We called for a reset of this bus, and we should get an interrupt 397 when this succeeds. Each command should get its own status 398 passed up to scsi_done, but this has not happened yet. */ 399 #defineSCSI_RESET_PENDING 3
400
401 /* We did a reset, but do not expect an interrupt to signal DID_RESET. 402 This tells the upper level code to request the sense info, and this 403 should keep the command alive. */ 404 #defineSCSI_RESET_WAKEUP 4
405
406 /* Something went wrong, and we do not know how to fix it. */ 407 #defineSCSI_RESET_ERROR 5
408
409 void * scsi_malloc(unsignedint);
410 intscsi_free(void *, unsignedint);
411 externunsignedintdma_free_sectors; /* How much room do we have left */ 412 externunsignedintneed_isa_buffer; /* True if some devices need indirection 413 buffers */ 414
415 /* 416 The Scsi_Cmnd structure is used by scsi.c internally, and for communication with 417 low level drivers that support multiple outstanding commands. 418 */ 419 typedefstruct scsi_pointer { 420 char * ptr; /* data pointer */ 421 intthis_residual; /* left in this buffer */ 422 structscatterlist *buffer; /* which buffer */ 423 intbuffers_residual; /* how many buffers left */ 424
425 volatileintStatus;
426 volatileintMessage;
427 volatileinthave_data_in;
428 volatileintsent_command;
429 volatileintphase;
430 }Scsi_Pointer;
431
432 typedefstructscsi_cmnd{ 433 structScsi_Host * host;
434 Scsi_Device * device;
435 unsignedchartarget, lun;
436 unsignedcharcmd_len;
437 unsignedcharold_cmd_len;
438 structscsi_cmnd *next, *prev;
439
440 /* These elements define the operation we are about to perform */ 441 unsignedcharcmnd[12];
442 unsignedrequest_bufflen; /* Actual request size */ 443
444 void * request_buffer; /* Actual requested buffer */ 445
446 /* These elements define the operation we ultimately want to perform */ 447 unsignedchardata_cmnd[12];
448 unsignedshortold_use_sg; /* We save use_sg here when requesting 449 sense info */ 450 unsignedshortuse_sg; /* Number of pieces of scatter-gather */ 451 unsignedshortsglist_len; /* size of malloc'd scatter-gather list */ 452 unsignedshortabort_reason; /* If the mid-level code requests an 453 abort, this is the reason. */ 454 unsignedbufflen; /* Size of data buffer */ 455 void *buffer; /* Data buffer */ 456
457 unsignedunderflow; /* Return error if less than this amount is 458 transfered */ 459
460 unsignedtransfersize; /* How much we are guaranteed to transfer with 461 each SCSI transfer (ie, between disconnect / 462 reconnects. Probably == sector size */ 463
464
465
466 structrequestrequest; /* A copy of the command we are working on*/ 467
468 unsignedcharsense_buffer[16]; /* Sense for this command, if needed*/ 469
470
471 intretries;
472 intallowed;
473 inttimeout_per_command, timeout_total, timeout;
474 /* 475 * We handle the timeout differently if it happens when a reset, 476 * abort, etc are in process. 477 */ 478
479 unsignedvolatilecharinternal_timeout;
480
481 unsignedflags;
482
483 /* These variables are for the cdrom only. Once we have variable size buffers 484 in the buffer cache, they will go away. */ 485 intthis_count;
486 /* End of special cdrom variables */ 487
488 /* Low-level done function - can be used by low-level driver to point 489 to completion function. Not used by mid/upper level code. */ 490 void (*scsi_done)(structscsi_cmnd *);
491 void (*done)(structscsi_cmnd *); /* Mid-level done function */ 492
493 /* The following fields can be written to by the host specific code. 494 Everything else should be left alone. */ 495
496 Scsi_PointerSCp; /* Scratchpad used by some host adapters */ 497
498 unsignedchar * host_scribble; /* The host adapter is allowed to 499 call scsi_malloc and get some memory 500 and hang it here. The host adapter 501 is also expected to call scsi_free 502 to release this memory. (The memory 503 obtained by scsi_malloc is guaranteed 504 to be at an address < 16Mb). */ 505
506 intresult; /* Status code from lower level driver */ 507
508 unsignedchartag; /* SCSI-II queued command tag */ 509 unsignedlongpid; /* Process ID, starts at 0 */ 510 }Scsi_Cmnd;
511
512 /* 513 scsi_abort aborts the current command that is executing on host host. 514 The error code, if non zero is returned in the host byte, otherwise 515 DID_ABORT is returned in the hostbyte. 516 */ 517
518 externintscsi_abort (Scsi_Cmnd *, intcode, intpid);
519
520 externvoidscsi_do_cmd (Scsi_Cmnd *, constvoid *cmnd ,
521 void *buffer, unsignedbufflen, void (*done)(structscsi_cmnd *),
522 inttimeout, intretries);
523
524
525 externScsi_Cmnd * allocate_device(structrequest **, Scsi_Device *, int);
526
527 externScsi_Cmnd * request_queueable(structrequest *, Scsi_Device *);
528 externintscsi_reset (Scsi_Cmnd *);
529
530 externintmax_scsi_hosts;
531
532 #ifdefined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR)
533 #include "hosts.h"
534 staticScsi_Cmnd * end_scsi_request(Scsi_Cmnd * SCpnt, intuptodate, intsectors)
/* */ 535 { 536 structrequest * req;
537 structbuffer_head * bh;
538
539 req = &SCpnt->request;
540 req->errors = 0;
541 if (!uptodate) { 542 printk(DEVICE_NAME " I/O error: dev %04x, sector %lu\n",
543 req->dev,req->sector);
544 } 545
546 do{ 547 if ((bh = req->bh) != NULL) { 548 req->bh = bh->b_reqnext;
549 req->nr_sectors -= bh->b_size >> 9;
550 req->sector += bh->b_size >> 9;
551 bh->b_reqnext = NULL;
552 bh->b_uptodate = uptodate;
553 unlock_buffer(bh);
554 sectors -= bh->b_size >> 9;
555 if ((bh = req->bh) != NULL) { 556 req->current_nr_sectors = bh->b_size >> 9;
557 if (req->nr_sectors < req->current_nr_sectors) { 558 req->nr_sectors = req->current_nr_sectors;
559 printk("end_scsi_request: buffer-list destroyed\n");
560 } 561 } 562 } 563 }while(sectors && bh);
564 if (req->bh){ 565 req->buffer = bh->b_data;
566 returnSCpnt;
567 };
568 DEVICE_OFF(req->dev);
569 if (req->sem != NULL) { 570 up(req->sem);
571 } 572
573 if (SCpnt->host->block) { 574 structScsi_Host * next;
575
576 for (next = SCpnt->host->block; next != SCpnt->host;
577 next = next->block)
578 wake_up(&next->host_wait);
579 } 580
581 req->dev = -1;
582 wake_up(&wait_for_request);
583 wake_up(&SCpnt->device->device_wait);
584 returnNULL;
585 } 586
587
588 /* This is just like INIT_REQUEST, but we need to be aware of the fact 589 that an interrupt may start another request, so we run this with interrupts 590 turned off */ 591
592 #defineINIT_SCSI_REQUEST \
593 if (!CURRENT) {\
594 CLEAR_INTR; \
595 restore_flags(flags); \
596 return; \
597 } \
598 if (MAJOR(CURRENT->dev) != MAJOR_NR) \
599 panic(DEVICE_NAME ": request list destroyed"); \
600 if (CURRENT->bh) { \
601 if (!CURRENT->bh->b_lock) \
602 panic(DEVICE_NAME ": block not locked"); \
603 } 604 #endif 605
606 #defineSCSI_SLEEP(QUEUE, CONDITION) { \
607 if (CONDITION) { \
608 structwait_queuewait = {current, NULL}; \
609 add_wait_queue(QUEUE, &wait); \
610 for(;;) { \
611 current->state = TASK_UNINTERRUPTIBLE; \
612 if (CONDITION) { \
613 if (intr_count) \
614 panic("scsi: trying to call schedule() in interrupt" \
615 ", file %s, line %d.\n", __FILE__, __LINE__); \
616 schedule(); \
617 } \
618 else \
619 break; \
620 } \
621 remove_wait_queue(QUEUE, &wait); \
622 current->state = TASK_RUNNING; \
623 }; } 624
625 #endif 626
627 /* 628 * Overrides for Emacs so that we follow Linus's tabbing style. 629 * Emacs will notice this stuff at the end of the file and automatically 630 * adjust the settings for this buffer only. This must remain at the end 631 * of the file. 632 * --------------------------------------------------------------------------- 633 * Local variables: 634 * c-indent-level: 8 635 * c-brace-imaginary-offset: 0 636 * c-brace-offset: -8 637 * c-argdecl-indent: 8 638 * c-label-offset: -8 639 * c-continued-statement-offset: 8 640 * c-continued-brace-offset: 0 641 * End: 642 */