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

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