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  *         Copyright (C) 1993, 1994, 1995 Eric Youngdale
   4  *  generic SCSI package header file by
   5  *      Initial versions: Drew Eckhardt
   6  *      Subsequent revisions: Eric Youngdale
   7  *
   8  *  <drew@colorado.edu>
   9  *
  10  *       Modified by Eric Youngdale eric@aib.com to
  11  *       add scatter-gather, multiple outstanding request, and other
  12  *       enhancements.
  13  */
  14 
  15 #ifndef _SCSI_H
  16 #define _SCSI_H
  17 
  18 /*
  19  * Some of the public constants are being movedd to this file.
  20  * We include it here so that what came from where is transparent.
  21  */
  22 #include <linux/scsi.h>
  23 
  24 
  25 /*
  26  * Some defs, in case these are not defined elsewhere.
  27  */
  28 #ifndef TRUE
  29 # define TRUE 1
  30 #endif
  31 #ifndef FALSE
  32 # define FALSE 0
  33 #endif
  34 
  35 
  36 extern void scsi_make_blocked_list(void);
  37 extern volatile int in_scan_scsis;
  38 extern const unsigned char scsi_command_size[8];
  39 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
  40 
  41 #define IDENTIFY_BASE       0x80
  42 #define IDENTIFY(can_disconnect, lun)   (IDENTIFY_BASE |\
  43                      ((can_disconnect) ?  0x40 : 0) |\
  44                      ((lun) & 0x07)) 
  45 
  46                  
  47     
  48 /*
  49  *  the return of the status word will be in the following format :
  50  *  The low byte is the status returned by the SCSI command, 
  51  *  with vendor specific bits masked.
  52  *  
  53  *  The next byte is the message which followed the SCSI status.
  54  *  This allows a stos to be used, since the Intel is a little
  55  *  endian machine.
  56  *  
  57  *  The final byte is a host return code, which is one of the following.
  58  *  
  59  *  IE 
  60  *  lsb     msb
  61  *  status  msg host code   
  62  *  
  63  *  Our errors returned by OUR driver, NOT SCSI message.  Or'd with
  64  *  SCSI message passed back to driver <IF any>.
  65  */
  66 
  67 
  68 #define DID_OK          0x00 /* NO error                                */
  69 #define DID_NO_CONNECT  0x01 /* Couldn't connect before timeout period  */
  70 #define DID_BUS_BUSY    0x02 /* BUS stayed busy through time out period */
  71 #define DID_TIME_OUT    0x03 /* TIMED OUT for other reason              */
  72 #define DID_BAD_TARGET  0x04 /* BAD target.                             */
  73 #define DID_ABORT       0x05 /* Told to abort for some other reason     */
  74 #define DID_PARITY      0x06 /* Parity error                            */
  75 #define DID_ERROR       0x07 /* Internal error                          */
  76 #define DID_RESET       0x08 /* Reset by somebody.                      */
  77 #define DID_BAD_INTR    0x09 /* Got an interrupt we weren't expecting.  */ 
  78 #define DRIVER_OK       0x00 /* Driver status                           */ 
  79 
  80 /*
  81  *  These indicate the error that occurred, and what is available.
  82  */
  83 
  84 #define DRIVER_BUSY         0x01
  85 #define DRIVER_SOFT         0x02
  86 #define DRIVER_MEDIA        0x03
  87 #define DRIVER_ERROR        0x04    
  88 
  89 #define DRIVER_INVALID      0x05
  90 #define DRIVER_TIMEOUT      0x06
  91 #define DRIVER_HARD         0x07
  92 
  93 #define SUGGEST_RETRY       0x10
  94 #define SUGGEST_ABORT       0x20 
  95 #define SUGGEST_REMAP       0x30
  96 #define SUGGEST_DIE         0x40
  97 #define SUGGEST_SENSE       0x80
  98 #define SUGGEST_IS_OK       0xff
  99 
 100 #define DRIVER_SENSE        0x08
 101 
 102 #define DRIVER_MASK         0x0f
 103 #define SUGGEST_MASK        0xf0
 104 
 105 #define MAX_COMMAND_SIZE    12
 106 
 107 /*
 108  *  SCSI command sets
 109  */
 110 
 111 #define SCSI_UNKNOWN    0
 112 #define SCSI_1          1
 113 #define SCSI_1_CCS      2
 114 #define SCSI_2          3
 115 
 116 /*
 117  *  Every SCSI command starts with a one byte OP-code.
 118  *  The next byte's high three bits are the LUN of the
 119  *  device.  Any multi-byte quantities are stored high byte
 120  *  first, and may have a 5 bit MSB in the same byte
 121  *  as the LUN.
 122  */
 123 
 124 /*
 125  *      Manufacturers list
 126  */
 127 
 128 #define SCSI_MAN_UNKNOWN     0
 129 #define SCSI_MAN_NEC         1
 130 #define SCSI_MAN_TOSHIBA     2
 131 #define SCSI_MAN_NEC_OLDCDR  3
 132 #define SCSI_MAN_SONY        4
 133 #define SCSI_MAN_PIONEER     5
 134 
 135 /*
 136  *  As the scsi do command functions are intelligent, and may need to
 137  *  redo a command, we need to keep track of the last command
 138  *  executed on each one.
 139  */
 140 
 141 #define WAS_RESET       0x01
 142 #define WAS_TIMEDOUT    0x02
 143 #define WAS_SENSE       0x04
 144 #define IS_RESETTING    0x08
 145 #define IS_ABORTING     0x10
 146 #define ASKED_FOR_SENSE 0x20
 147 
 148 /*
 149  *  The scsi_device struct contains what we know about each given scsi
 150  *  device.
 151  */
 152 
 153 typedef struct scsi_device {
 154     struct scsi_device * next;      /* Used for linked list */
 155 
 156     unsigned char id, lun, channel;
 157 
 158     unsigned int manufacturer;      /* Manufacturer of device, for using 
 159                                      * vendor-specific cmd's */
 160     int attached;                   /* # of high level drivers attached to 
 161                                      * this */
 162     int access_count;               /* Count of open channels/mounts */
 163     struct wait_queue * device_wait;/* Used to wait if device is busy */
 164     struct Scsi_Host * host;
 165     void (*scsi_request_fn)(void);  /* Used to jumpstart things after an 
 166                                      * ioctl */
 167     void *hostdata;                 /* available to low-level driver */
 168     char type;
 169     char scsi_level;
 170     char vendor[8], model[16], rev[4];
 171     unsigned char current_tag;      /* current tag */
 172     unsigned char sync_min_period;  /* Not less than this period */
 173     unsigned char sync_max_offset;  /* Not greater than this offset */
 174 
 175     unsigned writeable:1;
 176     unsigned removable:1; 
 177     unsigned random:1;
 178     unsigned has_cmdblocks:1;
 179     unsigned changed:1;             /* Data invalid due to media change */
 180     unsigned busy:1;                /* Used to prevent races */
 181     unsigned lockable:1;            /* Able to prevent media removal */
 182     unsigned borken:1;              /* Tell the Seagate driver to be 
 183                                      * painfully slow on this device */ 
 184     unsigned tagged_supported:1;    /* Supports SCSI-II tagged queuing */
 185     unsigned tagged_queue:1;        /* SCSI-II tagged queuing enabled */
 186     unsigned disconnect:1;          /* can disconnect */
 187     unsigned soft_reset:1;          /* Uses soft reset option */
 188     unsigned sync:1;                /* Negotiate for sync transfers */
 189     unsigned single_lun:1;          /* Indicates we should only allow I/O to
 190                                        one of the luns for the device at a time. */
 191     unsigned was_reset:1;       /* There was a bus reset on the bus for this
 192                                    device */
 193     unsigned expecting_cc_ua:1;    /* Expecting a CHECK_CONDITION/UNIT_ATTN
 194                                       because we did a bus reset. */
 195 } Scsi_Device;
 196 
 197 /*
 198  *  Use these to separate status msg and our bytes
 199  */
 200 
 201 #define status_byte(result) (((result) >> 1) & 0xf)
 202 #define msg_byte(result)    (((result) >> 8) & 0xff)
 203 #define host_byte(result)   (((result) >> 16) & 0xff)
 204 #define driver_byte(result) (((result) >> 24) & 0xff)
 205 #define suggestion(result)  (driver_byte(result) & SUGGEST_MASK)
 206 
 207 #define sense_class(sense)  (((sense) >> 4) & 0x7)
 208 #define sense_error(sense)  ((sense) & 0xf)
 209 #define sense_valid(sense)  ((sense) & 0x80);
 210 
 211 /*
 212  *  These are the SCSI devices available on the system.
 213  */
 214 
 215 extern Scsi_Device * scsi_devices;
 216 
 217 /*
 218  *  Initializes all SCSI devices.  This scans all scsi busses.
 219  */ 
 220 
 221 extern int scsi_dev_init (void);
 222 
 223 struct scatterlist {
 224     char *  address;    /* Location data is to be transferred to */
 225     char * alt_address; /* Location of actual if address is a 
 226                          * dma indirect buffer.  NULL otherwise */
 227     unsigned int length;
 228 };
 229 
 230 #ifdef __alpha__
 231 # define ISA_DMA_THRESHOLD (~0UL)
 232 #else
 233 # define ISA_DMA_THRESHOLD (0x00ffffff)
 234 #endif
 235 #define CONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data)
 236 
 237 
 238 /*
 239  * These are the return codes for the abort and reset functions.  The mid-level
 240  * code uses these to decide what to do next.  Each of the low level abort
 241  * and reset functions must correctly indicate what it has done.
 242  * The descriptions are written from the point of view of the mid-level code,
 243  * so that the return code is telling the mid-level drivers exactly what
 244  * the low level driver has already done, and what remains to be done.
 245  */
 246 
 247 /* We did not do anything.  
 248  * Wait some more for this command to complete, and if this does not work, 
 249  * try something more serious. */ 
 250 #define SCSI_ABORT_SNOOZE 0
 251 
 252 /* This means that we were able to abort the command.  We have already
 253  * called the mid-level done function, and do not expect an interrupt that 
 254  * will lead to another call to the mid-level done function for this command */
 255 #define SCSI_ABORT_SUCCESS 1
 256 
 257 /* We called for an abort of this command, and we should get an interrupt 
 258  * when this succeeds.  Thus we should not restore the timer for this
 259  * command in the mid-level abort function. */
 260 #define SCSI_ABORT_PENDING 2
 261 
 262 /* Unable to abort - command is currently on the bus.  Grin and bear it. */
 263 #define SCSI_ABORT_BUSY 3
 264 
 265 /* The command is not active in the low level code. Command probably
 266  * finished. */
 267 #define SCSI_ABORT_NOT_RUNNING 4
 268 
 269 /* Something went wrong.  The low level driver will indicate the correct
 270  * error condition when it calls scsi_done, so the mid-level abort function
 271  * can simply wait until this comes through */
 272 #define SCSI_ABORT_ERROR 5
 273 
 274 /* We do not know how to reset the bus, or we do not want to.  Bummer.
 275  * Anyway, just wait a little more for the command in question, and hope that
 276  * it eventually finishes.  If it never finishes, the SCSI device could
 277  * hang, so use this with caution. */
 278 #define SCSI_RESET_SNOOZE 0
 279 
 280 /* We do not know how to reset the bus, or we do not want to.  Bummer.
 281  * We have given up on this ever completing.  The mid-level code will
 282  * request sense information to decide how to proceed from here. */
 283 #define SCSI_RESET_PUNT 1
 284 
 285 /* This means that we were able to reset the bus.  We have restarted all of
 286  * the commands that should be restarted, and we should be able to continue
 287  * on normally from here.  We do not expect any interrupts that will return
 288  * DID_RESET to any of the other commands in the host_queue, and the mid-level
 289  * code does not need to do anything special to keep the commands alive. 
 290  * If a hard reset was performed then all outstanding commands on the
 291  * bus have been restarted. */
 292 #define SCSI_RESET_SUCCESS 2
 293 
 294 /* We called for a reset of this bus, and we should get an interrupt 
 295  * when this succeeds.  Each command should get its own status
 296  * passed up to scsi_done, but this has not happened yet. 
 297  * If a hard reset was performed, then we expect an interrupt
 298  * for *each* of the outstanding commands that will have the
 299  * effect of restarting the commands.
 300  */
 301 #define SCSI_RESET_PENDING 3
 302 
 303 /* We did a reset, but do not expect an interrupt to signal DID_RESET.
 304  * This tells the upper level code to request the sense info, and this
 305  * should keep the command alive. */
 306 #define SCSI_RESET_WAKEUP 4
 307 
 308 /* Something went wrong, and we do not know how to fix it. */
 309 #define SCSI_RESET_ERROR 5
 310 
 311 /*
 312  * This is a bitmask that is ored with one of the above codes.
 313  * It tells the mid-level code that we did a hard reset.
 314  */
 315 #define SCSI_RESET_BUS_RESET 0x100
 316 /*
 317  * Used to mask off bits and to obtain the basic action that was
 318  * performed.  
 319  */
 320 #define SCSI_RESET_ACTION   0xff
 321 
 322 void *   scsi_malloc(unsigned int);
 323 int      scsi_free(void *, unsigned int);
 324 extern unsigned int dma_free_sectors;  /* How much room do we have left */
 325 extern unsigned int need_isa_buffer;   /* True if some devices need indirection
 326                                         * buffers */
 327 
 328 /*
 329  * The Scsi_Cmnd structure is used by scsi.c internally, and for communication
 330  * with low level drivers that support multiple outstanding commands.
 331  */
 332 typedef struct scsi_pointer {
 333     char * ptr;                     /* data pointer */
 334     int this_residual;              /* left in this buffer */
 335     struct scatterlist *buffer;     /* which buffer */
 336     int buffers_residual;           /* how many buffers left */
 337     
 338     volatile int Status;
 339     volatile int Message;
 340     volatile int have_data_in;
 341     volatile int sent_command;
 342     volatile int phase;
 343 } Scsi_Pointer;
 344 
 345 typedef struct scsi_cmnd {
 346     struct Scsi_Host * host;
 347     Scsi_Device * device;
 348     unsigned char target, lun, channel;
 349     unsigned char cmd_len;
 350     unsigned char old_cmd_len;
 351     struct scsi_cmnd *next, *prev;  
 352     
 353     /* These elements define the operation we are about to perform */
 354     unsigned char cmnd[12];
 355     unsigned request_bufflen;   /* Actual request size */
 356     
 357     void * request_buffer;      /* Actual requested buffer */
 358     
 359     /* These elements define the operation we ultimately want to perform */
 360     unsigned char data_cmnd[12];
 361     unsigned short old_use_sg;  /* We save  use_sg here when requesting
 362                                  * sense info */
 363     unsigned short use_sg;      /* Number of pieces of scatter-gather */
 364     unsigned short sglist_len;  /* size of malloc'd scatter-gather list */
 365     unsigned short abort_reason;/* If the mid-level code requests an
 366                                  * abort, this is the reason. */
 367     unsigned bufflen;           /* Size of data buffer */
 368     void *buffer;               /* Data buffer */
 369     
 370     unsigned underflow;         /* Return error if less than this amount is 
 371                                  * transfered */
 372     
 373     unsigned transfersize;      /* How much we are guaranteed to transfer with
 374                                  * each SCSI transfer (ie, between disconnect /
 375                                  * reconnects.   Probably == sector size */
 376     
 377     
 378     struct request request;     /* A copy of the command we are working on */
 379 
 380     unsigned char sense_buffer[16];  /* Sense for this command, if needed */
 381 
 382 
 383     int retries;
 384     int allowed;
 385     int timeout_per_command, timeout_total, timeout;
 386 
 387     /*
 388      *  We handle the timeout differently if it happens when a reset, 
 389      *  abort, etc are in process. 
 390      */
 391     unsigned volatile char internal_timeout;
 392     
 393     unsigned flags;
 394     
 395     /* These variables are for the cdrom only. Once we have variable size 
 396      * buffers in the buffer cache, they will go away. */
 397     int this_count; 
 398     /* End of special cdrom variables */
 399     
 400     /* Low-level done function - can be used by low-level driver to point
 401      *  to completion function.  Not used by mid/upper level code. */
 402     void (*scsi_done)(struct scsi_cmnd *);  
 403     void (*done)(struct scsi_cmnd *);  /* Mid-level done function */
 404     
 405     /*
 406      * The following fields can be written to by the host specific code. 
 407      * Everything else should be left alone. 
 408      */
 409     
 410     Scsi_Pointer SCp;   /* Scratchpad used by some host adapters */
 411     
 412     unsigned char * host_scribble; /* The host adapter is allowed to
 413                                     * call scsi_malloc and get some memory
 414                                     * and hang it here.  The host adapter
 415                                     * is also expected to call scsi_free
 416                                     * to release this memory.  (The memory
 417                                     * obtained by scsi_malloc is guaranteed
 418                                     * to be at an address < 16Mb). */
 419     
 420     int result;                    /* Status code from lower level driver */
 421     
 422     unsigned char tag;             /* SCSI-II queued command tag */
 423     unsigned long pid;             /* Process ID, starts at 0 */
 424 } Scsi_Cmnd;         
 425 
 426 /*
 427  *  scsi_abort aborts the current command that is executing on host host.
 428  *  The error code, if non zero is returned in the host byte, otherwise 
 429  *  DID_ABORT is returned in the hostbyte.
 430  */
 431 
 432 extern int scsi_abort (Scsi_Cmnd *, int code, int pid);
 433 
 434 extern void scsi_do_cmd (Scsi_Cmnd *, const void *cmnd ,
 435                          void *buffer, unsigned bufflen, 
 436                          void (*done)(struct scsi_cmnd *),
 437                          int timeout, int retries);
 438 
 439 
 440 extern Scsi_Cmnd * allocate_device(struct request **, Scsi_Device *, int);
 441 
 442 extern Scsi_Cmnd * request_queueable(struct request *, Scsi_Device *);
 443 extern int scsi_reset (Scsi_Cmnd *, int);
 444 
 445 extern int max_scsi_hosts;
 446 
 447 extern void proc_print_scsidevice(Scsi_Device *, char *, int *, int);
 448 
 449 extern void print_command(unsigned char *);
 450 extern void print_sense(const char *, Scsi_Cmnd *);
 451 
 452 
 453 #if defined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR)
 454 #include "hosts.h"
 455 
 456 static Scsi_Cmnd * end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
     /* [previous][next][first][last][top][bottom][index][help] */
 457 {
 458     struct request * req;
 459     struct buffer_head * bh;
 460     
 461     req = &SCpnt->request;
 462     req->errors = 0;
 463     if (!uptodate) {
 464         printk(DEVICE_NAME " I/O error: dev %s, sector %lu\n",
 465                kdevname(req->rq_dev), req->sector);
 466     }
 467     
 468     do {
 469         if ((bh = req->bh) != NULL) {
 470             req->bh = bh->b_reqnext;
 471             req->nr_sectors -= bh->b_size >> 9;
 472             req->sector += bh->b_size >> 9;
 473             bh->b_reqnext = NULL;
 474             bh->b_uptodate = uptodate;
 475             unlock_buffer(bh);
 476             sectors -= bh->b_size >> 9;
 477             if ((bh = req->bh) != NULL) {
 478                 req->current_nr_sectors = bh->b_size >> 9;
 479                 if (req->nr_sectors < req->current_nr_sectors) {
 480                     req->nr_sectors = req->current_nr_sectors;
 481                     printk("end_scsi_request: buffer-list destroyed\n");
 482                 }
 483             }
 484         }
 485     } while(sectors && bh);
 486     if (req->bh){
 487         req->buffer = bh->b_data;
 488         return SCpnt;
 489     };
 490     DEVICE_OFF(req->rq_dev);
 491     if (req->sem != NULL) {
 492         up(req->sem);
 493     }
 494     
 495     if (SCpnt->host->block) {
 496         struct Scsi_Host * next;
 497         
 498         for (next = SCpnt->host->block; next != SCpnt->host;
 499              next = next->block)
 500             wake_up(&next->host_wait);
 501     }
 502     
 503     req->rq_status = RQ_INACTIVE;
 504     wake_up(&wait_for_request);
 505     wake_up(&SCpnt->device->device_wait);
 506     return NULL;
 507 }
 508 
 509 
 510 /* This is just like INIT_REQUEST, but we need to be aware of the fact
 511  * that an interrupt may start another request, so we run this with interrupts
 512  * turned off 
 513  */
 514 #define INIT_SCSI_REQUEST       \
 515     if (!CURRENT) {             \
 516         CLEAR_INTR;             \
 517         restore_flags(flags);   \
 518         return;                 \
 519     }                           \
 520     if (MAJOR(CURRENT->rq_dev) != MAJOR_NR)           \
 521         panic(DEVICE_NAME ": request list destroyed");\
 522     if (CURRENT->bh) {                                \
 523         if (!CURRENT->bh->b_lock)                     \
 524             panic(DEVICE_NAME ": block not locked");  \
 525     }
 526 #endif
 527 
 528 #define SCSI_SLEEP(QUEUE, CONDITION) {              \
 529     if (CONDITION) {                                \
 530         struct wait_queue wait = { current, NULL};  \
 531         add_wait_queue(QUEUE, &wait);               \
 532         for(;;) {                                   \
 533         current->state = TASK_UNINTERRUPTIBLE;      \
 534         if (CONDITION) {                            \
 535             if (intr_count)                         \
 536                 panic("scsi: trying to call schedule() in interrupt" \
 537                       ", file %s, line %d.\n", __FILE__, __LINE__);  \
 538             schedule();                 \
 539         }                               \
 540         else                            \
 541             break;                      \
 542         }                               \
 543         remove_wait_queue(QUEUE, &wait);\
 544         current->state = TASK_RUNNING;  \
 545     }; }
 546 
 547 #endif
 548 
 549 /*
 550  * Overrides for Emacs so that we follow Linus's tabbing style.
 551  * Emacs will notice this stuff at the end of the file and automatically
 552  * adjust the settings for this buffer only.  This must remain at the end
 553  * of the file.
 554  * ---------------------------------------------------------------------------
 555  * Local variables:
 556  * c-indent-level: 4 
 557  * c-brace-imaginary-offset: 0
 558  * c-brace-offset: -4
 559  * c-argdecl-indent: 4
 560  * c-label-offset: -4
 561  * c-continued-statement-offset: 4
 562  * c-continued-brace-offset: 0
 563  * indent-tabs-mode: nil
 564  * tab-width: 8
 565  * End:
 566  */

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