Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | /* * scsi.h Copyright (C) 1992 Drew Eckhardt * generic SCSI package header file by * Drew Eckhardt * * <drew@colorado.edu> * * Modified by Eric Youngdale eric@tantalus.nrl.navy.mil to * add scatter-gather, multiple outstanding request, and other * enhancements. */ #ifndef _SCSI_H #define _SCSI_H /* $Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/scsi.h,v 1.3 1993/09/24 12:20:33 drew Exp $ For documentation on the OPCODES, MESSAGES, and SENSE values, please consult the SCSI standard. */ /* SCSI opcodes */ #define TEST_UNIT_READY 0x00 #define REZERO_UNIT 0x01 #define REQUEST_SENSE 0x03 #define FORMAT_UNIT 0x04 #define READ_BLOCK_LIMITS 0x05 #define REASSIGN_BLOCKS 0x07 #define READ_6 0x08 #define WRITE_6 0x0a #define SEEK_6 0x0b #define READ_REVERSE 0x0f #define WRITE_FILEMARKS 0x10 #define SPACE 0x11 #define INQUIRY 0x12 #define RECOVER_BUFFERED_DATA 0x14 #define MODE_SELECT 0x15 #define RESERVE 0x16 #define RELEASE 0x17 #define COPY 0x18 #define ERASE 0x19 #define MODE_SENSE 0x1a #define START_STOP 0x1b #define RECEIVE_DIAGNOSTIC 0x1c #define SEND_DIAGNOSTIC 0x1d #define ALLOW_MEDIUM_REMOVAL 0x1e #define READ_CAPACITY 0x25 #define READ_10 0x28 #define WRITE_10 0x2a #define SEEK_10 0x2b #define WRITE_VERIFY 0x2e #define VERIFY 0x2f #define SEARCH_HIGH 0x30 #define SEARCH_EQUAL 0x31 #define SEARCH_LOW 0x32 #define SET_LIMITS 0x33 #define PRE_FETCH 0x34 #define READ_POSITION 0x34 #define SYNCRONIZE_CACHE 0x35 #define LOCK_UNLOCK_CACHE 0x36 #define READ_DEFECT_DATA 0x37 #define COMPARE 0x39 #define COPY_VERIFY 0x3a #define WRITE_BUFFER 0x3b #define READ_BUFFER 0x3c #define READ_LONG 0x3e #define CHANGE_DEFINITION 0x40 #define LOG_SELECT 0x4c #define LOG_SENSE 0x4d #define MODE_SELECT_10 0x55 #define MODE_SENSE_10 0x5a extern const unsigned char scsi_command_size[8]; #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7] /* MESSAGE CODES */ #define COMMAND_COMPLETE 0x00 #define EXTENDED_MESSAGE 0x01 #define SAVE_POINTERS 0x02 #define RESTORE_POINTERS 0x03 #define DISCONNECT 0x04 #define INITIATOR_ERROR 0x05 #define ABORT 0x06 #define MESSAGE_REJECT 0x07 #define NOP 0x08 #define MSG_PARITY_ERROR 0x09 #define LINKED_CMD_COMPLETE 0x0a #define LINKED_FLG_CMD_COMPLETE 0x0b #define BUS_DEVICE_RESET 0x0c #define SIMPLE_QUEUE_TAG 0x20 #define HEAD_OF_QUEUE_TAG 0x21 #define ORDERED_QUEUE_TAG 0x22 #define IDENTIFY_BASE 0x80 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\ ((can_disconnect) ? 0x40 : 0) |\ ((lun) & 0x07)) /* Status codes */ #define GOOD 0x00 #define CHECK_CONDITION 0x01 #define CONDITION_GOOD 0x02 #define BUSY 0x04 #define INTERMEDIATE_GOOD 0x08 #define INTERMEDIATE_C_GOOD 0x0a #define RESERVATION_CONFLICT 0x0c #define STATUS_MASK 0x1e /* the return of the status word will be in the following format : The low byte is the status returned by the SCSI command, with vendor specific bits masked. The next byte is the message which followed the SCSI status. This allows a stos to be used, since the Intel is a little endian machine. The final byte is a host return code, which is one of the following. IE lsb msb status msg host code Our errors returned by OUR driver, NOT SCSI message. Orr'd with SCSI message passed back to driver <IF any>. */ /* NO error */ #define DID_OK 0x00 /* Couldn't connect before timeout period */ #define DID_NO_CONNECT 0x01 /* BUS stayed busy through time out period */ #define DID_BUS_BUSY 0x02 /* TIMED OUT for other reason */ #define DID_TIME_OUT 0x03 /* BAD target. */ #define DID_BAD_TARGET 0x04 /* Told to abort for some other reason */ #define DID_ABORT 0x05 /* Parity error */ #define DID_PARITY 0x06 /* Internal error */ #define DID_ERROR 0x07 /* Reset by somebody. */ #define DID_RESET 0x08 /* Got an interrupt we weren't expecting. */ #define DID_BAD_INTR 0x09 /* Driver status */ #define DRIVER_OK 0x00 /* These indicate the error that occured, and what is available. */ #define DRIVER_BUSY 0x01 #define DRIVER_SOFT 0x02 #define DRIVER_MEDIA 0x03 #define DRIVER_ERROR 0x04 #define DRIVER_INVALID 0x05 #define DRIVER_TIMEOUT 0x06 #define DRIVER_HARD 0x07 #define SUGGEST_RETRY 0x10 #define SUGGEST_ABORT 0x20 #define SUGGEST_REMAP 0x30 #define SUGGEST_DIE 0x40 #define SUGGEST_SENSE 0x80 #define SUGGEST_IS_OK 0xff #define DRIVER_SENSE 0x08 #define DRIVER_MASK 0x0f #define SUGGEST_MASK 0xf0 /* SENSE KEYS */ #define NO_SENSE 0x00 #define RECOVERED_ERROR 0x01 #define NOT_READY 0x02 #define MEDIUM_ERROR 0x03 #define HARDWARE_ERROR 0x04 #define ILLEGAL_REQUEST 0x05 #define UNIT_ATTENTION 0x06 #define DATA_PROTECT 0x07 #define BLANK_CHECK 0x08 #define COPY_ABORTED 0x0a #define ABORTED_COMMAND 0x0b #define VOLUME_OVERFLOW 0x0d #define MISCOMPARE 0x0e /* DEVICE TYPES */ #define TYPE_DISK 0x00 #define TYPE_TAPE 0x01 #define TYPE_WORM 0x04 /* Treated as ROM by our system */ #define TYPE_ROM 0x05 #define TYPE_MOD 0x07 /* Magneto-optical disk - treated as TYPE_DISK */ #define TYPE_NO_LUN 0x7f #define MAX_COMMAND_SIZE 12 /* SCSI command sets */ #define SCSI_UNKNOWN 0 #define SCSI_1 1 #define SCSI_1_CCS 2 #define SCSI_2 3 /* Every SCSI command starts with a one byte OP-code. The next byte's high three bits are the LUN of the device. Any multi-byte quantities are stored high byte first, and may have a 5 bit MSB in the same byte as the LUN. */ /* The scsi_device struct contains what we know about each given scsi device. */ typedef struct scsi_device { unsigned char id, lun, index; int access_count; /* Count of open channels/mounts */ struct wait_queue * device_wait; /* Used to wait if device is busy */ struct Scsi_Host * host; void (*scsi_request_fn)(void); /* Used to jumpstart things after an ioctl */ char type; char scsi_level; unsigned writeable:1; unsigned removable:1; unsigned random:1; unsigned changed:1; /* Data invalid due to media change */ unsigned busy:1; /* Used to prevent races */ unsigned lockable:1; /* Able to prevent media removal */ unsigned borken:1; /* Tell the Seagate driver to be painfully slow on this device */ unsigned tagged_supported:1; /* Supports SCSI-II tagged queing */ unsigned tagged_queue:1; /*SCSI-II tagged queing enabled */ unsigned disconnect:1; /* can disconnect */ unsigned soft_reset:1; /* Uses soft reset option */ unsigned char current_tag; /* current tag */ } Scsi_Device; /* Use these to separate status msg and our bytes */ #define status_byte(result) (((result) >> 1) & 0xf) #define msg_byte(result) (((result) >> 8) & 0xff) #define host_byte(result) (((result) >> 16) & 0xff) #define driver_byte(result) (((result) >> 24) & 0xff) #define sugestion(result) (driver_byte(result) & SUGGEST_MASK) #define sense_class(sense) (((sense) >> 4) & 0x7) #define sense_error(sense) ((sense) & 0xf) #define sense_valid(sense) ((sense) & 0x80); /* These are the SCSI devices available on the system. */ extern int NR_SCSI_DEVICES; extern Scsi_Device * scsi_devices; /* Initializes all SCSI devices. This scans all scsi busses. */ extern unsigned long scsi_dev_init (unsigned long, unsigned long); struct scatterlist { char * address; /* Location data is to be transferred to */ char * alt_address; /* Location of actual if address is a dma indirect buffer. NULL otherwise */ unsigned int length; }; #define ISA_DMA_THRESHOLD (0x00ffffff) #define CONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data) /* * These are the return codes for the abort and reset functions. The mid-level * code uses these to decide what to do next. Each of the low level abort * and reset functions must correctly indicate what it has done. */ /* We did not do anything. Wait some more for this command to complete, and if this does not work, try something more serious. */ #define SCSI_ABORT_SNOOZE 0 /* This means that we were able to abort the command. We have already called the mid-level done function, and do not expect an interrupt that will lead to another call to the mid-level done function for this command */ #define SCSI_ABORT_SUCCESS 1 /* We called for an abort of this command, and we should get an interrupt when this succeeds. Thus we should not restore the timer for this command in the mid-level abort function. */ #define SCSI_ABORT_PENDING 2 /* Unable to abort - command is currently on the bus. Grin and bear it. */ #define SCSI_ABORT_BUSY 3 /* The command is not active in the low level code. Command probably finished. */ #define SCSI_ABORT_NOT_RUNNING 4 /* Something went wrong. The low level driver will indicate the correct error condition when it calls scsi_done, so the mid-level abort function can simply wait until this comes through */ #define SCSI_ABORT_ERROR 5 /* We do not know how to reset the bus, or we do not want to. Bummer. Anyway, just wait a little more for the command in question, and hope that it eventually finishes */ #define SCSI_RESET_SNOOZE 0 /* This means that we were able to reset the bus. We have restarted all of the commands that should be restarted, and we should be able to continue on normally from here. We do not expect any interrupts that will return DID_RESET to any of the other commands in the host_queue. */ #define SCSI_RESET_SUCCESS 1 /* We called for an reset of this bus, and we should get an interrupt when this succeeds. Each command should get it's own status passed up to scsi_done, but this has not happened yet. */ #define SCSI_RESET_PENDING 2 /* We did a reset, but do not expect an interrupt to signal DID_RESET. This tells the upper level code to request the sense info, and this should keep the command alive. */ #define SCSI_RESET_WAKEUP 3 /* Something went wrong, and we do not know how to fix it. */ #define SCSI_RESET_ERROR 4 void * scsi_malloc(unsigned int); int scsi_free(void *, unsigned int); extern unsigned int dma_free_sectors; /* How much room do we have left */ extern unsigned int need_isa_buffer; /* True if some devices need indirection buffers */ /* The Scsi_Cmnd structure is used by scsi.c internally, and for communication with low level drivers that support multiple outstanding commands. */ typedef struct scsi_pointer { char * ptr; /* data pointer */ int this_residual; /* left in this buffer */ struct scatterlist *buffer; /* which buffer */ int buffers_residual; /* how many buffers left */ volatile int Status; volatile int Message; volatile int have_data_in; volatile int sent_command; volatile int phase; } Scsi_Pointer; typedef struct scsi_cmnd { struct Scsi_Host * host; Scsi_Device * device; unsigned char target, lun, index; struct scsi_cmnd *next, *prev; /* These elements define the operation we are about to perform */ unsigned char cmnd[12]; unsigned request_bufflen; /* Actual request size */ void * request_buffer; /* Actual requested buffer */ /* These elements define the operation we ultimately want to perform */ unsigned char data_cmnd[12]; unsigned short old_use_sg; /* We save use_sg here when requesting sense info */ unsigned short use_sg; /* Number of pieces of scatter-gather */ unsigned short sglist_len; /* size of malloc'd scatter-gather list */ unsigned short abort_reason; /* If the mid-level code requests an abort, this is the reason. */ unsigned bufflen; /* Size of data buffer */ void *buffer; /* Data buffer */ unsigned underflow; /* Return error if less than this amount is transfered */ unsigned transfersize; /* How much we are guranteed to transfer with each SCSI transfer (ie, between disconnect / reconnects. Probably == sector size */ struct request request; /* A copy of the command we are working on*/ unsigned char sense_buffer[16]; /* Sense for this command, if needed*/ int retries; int allowed; int timeout_per_command, timeout_total, timeout; /* * We handle the timeout differently if it happens when a reset, * abort, etc are in process. */ unsigned volatile char internal_timeout; unsigned flags; /* These variables are for the cdrom only. Once we have variable size buffers in the buffer cache, they will go away. */ int this_count; /* End of special cdrom variables */ /* Low-level done function - can be used by low-level driver to point to completion function. Not used by mid/upper level code. */ void (*scsi_done)(struct scsi_cmnd *); void (*done)(struct scsi_cmnd *); /* Mid-level done function */ /* The following fields can be written to by the host specific code. Everything else should be left alone. */ Scsi_Pointer SCp; /* Scratchpad used by some host adapters */ unsigned char * host_scribble; /* The host adapter is allowed to call scsi_malloc and get some memory and hang it here. The host adapter is also expected to call scsi_free to release this memory. (The memory obtained by scsi_malloc is guaranteed to be at an address < 16Mb). */ int result; /* Status code from lower level driver */ unsigned char tag; /* SCSI-II queued command tag */ } Scsi_Cmnd; /* scsi_abort aborts the current command that is executing on host host. The error code, if non zero is returned in the host byte, otherwise DID_ABORT is returned in the hostbyte. */ extern int scsi_abort (Scsi_Cmnd *, int code); extern void scsi_do_cmd (Scsi_Cmnd *, const void *cmnd , void *buffer, unsigned bufflen, void (*done)(struct scsi_cmnd *), int timeout, int retries); extern Scsi_Cmnd * allocate_device(struct request **, int, int); extern Scsi_Cmnd * request_queueable(struct request *, int); extern int scsi_reset (Scsi_Cmnd *); extern int max_scsi_hosts; extern int MAX_SD, NR_SD, MAX_ST, NR_ST, MAX_SR, NR_SR, NR_SG, MAX_SG; extern unsigned long sd_init(unsigned long, unsigned long); extern unsigned long sd_init1(unsigned long, unsigned long); extern void sd_attach(Scsi_Device *); extern unsigned long sr_init(unsigned long, unsigned long); extern unsigned long sr_init1(unsigned long, unsigned long); extern void sr_attach(Scsi_Device *); extern unsigned long st_init(unsigned long, unsigned long); extern unsigned long st_init1(unsigned long, unsigned long); extern void st_attach(Scsi_Device *); extern unsigned long sg_init(unsigned long, unsigned long); extern unsigned long sg_init1(unsigned long, unsigned long); extern void sg_attach(Scsi_Device *); #if defined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR) static void end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors) { struct request * req; struct buffer_head * bh; struct task_struct * p; req = &SCpnt->request; req->errors = 0; if (!uptodate) { printk(DEVICE_NAME " I/O error: dev %04x, sector %lu\n", req->dev,req->sector); } do { if ((bh = req->bh) != NULL) { req->bh = bh->b_reqnext; req->nr_sectors -= bh->b_size >> 9; req->sector += bh->b_size >> 9; bh->b_reqnext = NULL; bh->b_uptodate = uptodate; unlock_buffer(bh); sectors -= bh->b_size >> 9; if ((bh = req->bh) != NULL) { req->current_nr_sectors = bh->b_size >> 9; if (req->nr_sectors < req->current_nr_sectors) { req->nr_sectors = req->current_nr_sectors; printk("end_scsi_request: buffer-list destroyed\n"); } } } } while(sectors && bh); if (req->bh){ req->buffer = bh->b_data; return; }; DEVICE_OFF(req->dev); if ((p = req->waiting) != NULL) { req->waiting = NULL; p->state = TASK_RUNNING; if (p->counter > current->counter) need_resched = 1; } req->dev = -1; wake_up(&scsi_devices[SCpnt->index].device_wait); return; } /* This is just like INIT_REQUEST, but we need to be aware of the fact that an interrupt may start another request, so we run this with interrupts turned off */ #define INIT_SCSI_REQUEST \ if (!CURRENT) {\ CLEAR_INTR; \ sti(); \ return; \ } \ if (MAJOR(CURRENT->dev) != MAJOR_NR) \ panic(DEVICE_NAME ": request list destroyed"); \ if (CURRENT->bh) { \ if (!CURRENT->bh->b_lock) \ panic(DEVICE_NAME ": block not locked"); \ } #endif #define SCSI_SLEEP(QUEUE, CONDITION) { \ if (CONDITION) { \ struct wait_queue wait = { current, NULL}; \ add_wait_queue(QUEUE, &wait); \ sleep_repeat: \ current->state = TASK_UNINTERRUPTIBLE; \ if (CONDITION) { \ schedule(); \ goto sleep_repeat; \ } \ remove_wait_queue(QUEUE, &wait); \ current->state = TASK_RUNNING; \ }; } #endif |