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

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