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