root/drivers/scsi/scsi.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. end_scsi_request

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

/* [previous][next][first][last][top][bottom][index][help] */