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 
 196 #define DRIVER_SENSE            0x08
 197 
 198 #define DRIVER_MASK 0x0f
 199 #define SUGGEST_MASK 0xf0
 200 
 201 /*
 202 
 203         SENSE KEYS
 204 */
 205 
 206 #define NO_SENSE                0x00
 207 #define RECOVERED_ERROR         0x01
 208 #define NOT_READY               0x02
 209 #define MEDIUM_ERROR            0x03
 210 #define HARDWARE_ERROR          0x04
 211 #define ILLEGAL_REQUEST         0x05
 212 #define UNIT_ATTENTION          0x06
 213 #define DATA_PROTECT            0x07
 214 #define BLANK_CHECK             0x08
 215 #define COPY_ABORTED            0x0a
 216 #define ABORTED_COMMAND         0x0b
 217 #define VOLUME_OVERFLOW         0x0d
 218 #define MISCOMPARE              0x0e
 219 
 220 
 221 /*
 222         DEVICE TYPES
 223 
 224 */
 225 
 226 #define TYPE_DISK       0x00
 227 #define TYPE_TAPE       0x01
 228 #define TYPE_WORM       0x04    /* Treated as ROM by our system */
 229 #define TYPE_ROM        0x05
 230 #define TYPE_MOD        0x07  /* Magneto-optical disk - treated as TYPE_DISK */
 231 #define TYPE_NO_LUN     0x7f
 232 
 233 
 234 #define MAX_COMMAND_SIZE 12
 235 /*
 236         SCSI command sets
 237 
 238 */
 239 
 240 #define SCSI_UNKNOWN    0
 241 #define SCSI_1          1
 242 #define SCSI_1_CCS      2
 243 #define SCSI_2          3
 244 
 245 /*
 246         Every SCSI command starts with a one byte OP-code.
 247         The next byte's high three bits are the LUN of the
 248         device.  Any multi-byte quantities are stored high byte
 249         first, and may have a 5 bit MSB in the same byte
 250         as the LUN.
 251 */
 252 
 253 
 254 /*
 255         The scsi_device struct contains what we know about each given scsi
 256         device.
 257 */
 258 
 259 typedef struct scsi_device {
 260         unsigned char id, lun, index;
 261         int access_count;       /* Count of open channels/mounts */
 262         struct wait_queue * device_wait;  /* Used to wait if device is busy */
 263         struct Scsi_Host * host;
 264         char type;
 265         char scsi_level;
 266         unsigned writeable:1;
 267         unsigned removable:1; 
 268         unsigned random:1;
 269         unsigned changed:1;     /* Data invalid due to media change */
 270         unsigned busy:1;        /* Used to prevent races */
 271         unsigned lockable:1;    /* Able to prevent media removal */
 272         unsigned borken:1;      /* Tell the Seagate driver to be 
 273                                    painfully slow on this device */ 
 274         unsigned tagged_supported:1; /* Supports SCSI-II tagged queing */
 275         unsigned tagged_queue:1;   /*SCSI-II tagged queing enabled */
 276         unsigned disconnect:1;     /* can disconnect */
 277         unsigned char current_tag; /* current tag */
 278 } Scsi_Device;
 279 /*
 280         Use these to separate status msg and our bytes
 281 */
 282 
 283 #define status_byte(result) (((result) >> 1) & 0xf)
 284 #define msg_byte(result) (((result) >> 8) & 0xff)
 285 #define host_byte(result) (((result) >> 16) & 0xff)
 286 #define driver_byte(result) (((result) >> 24) & 0xff)
 287 #define sugestion(result) (driver_byte(result) & SUGGEST_MASK)
 288 
 289 #define sense_class(sense) (((sense) >> 4) & 0x7)
 290 #define sense_error(sense) ((sense) & 0xf)
 291 #define sense_valid(sense) ((sense) & 0x80);
 292 
 293 /*
 294         These are the SCSI devices available on the system.
 295 */
 296 
 297 extern int NR_SCSI_DEVICES;
 298 extern Scsi_Device * scsi_devices;
 299 /*
 300         Initializes all SCSI devices.  This scans all scsi busses.
 301 */
 302 
 303 extern unsigned long scsi_dev_init (unsigned long, unsigned long);
 304 
 305 struct scatterlist {
 306      char *  address; /* Location data is to be transferred to */
 307      char * alt_address; /* Location of actual if address is a 
 308                             dma indirect buffer.  NULL otherwise */
 309      unsigned short length;
 310      };
 311 
 312 #define ISA_DMA_THRESHOLD (0x00ffffff)
 313 
 314 void *   scsi_malloc(unsigned int);
 315 int      scsi_free(void *, unsigned int);
 316 extern unsigned int dma_free_sectors;   /* How much room do we have left */
 317 extern unsigned int need_isa_buffer;   /* True if some devices need indirection
 318                                  buffers */
 319 
 320 /*
 321         The Scsi_Cmnd structure is used by scsi.c internally, and for communication with
 322         low level drivers that support multiple outstanding commands.
 323 */
 324 typedef struct scsi_pointer {
 325   char * ptr;                     /* data pointer */
 326   int this_residual;              /* left in this buffer */
 327   struct scatterlist *buffer;     /* which buffer */
 328   int buffers_residual;           /* how many buffers left */
 329 
 330   volatile int Status;
 331   volatile int Message;
 332   volatile int have_data_in;
 333   volatile int sent_command;
 334   volatile int phase;
 335 } Scsi_Pointer;
 336 
 337 typedef struct scsi_cmnd {
 338         struct Scsi_Host * host;
 339         unsigned char target, lun,  index;
 340         struct scsi_cmnd *next, *prev;  
 341 
 342 /* These elements define the operation we are about to perform */
 343         unsigned char cmnd[12];
 344         unsigned request_bufflen; /* Actual request size */
 345 
 346         void * request_buffer;  /* Actual requested buffer */
 347 
 348 /* These elements define the operation we ultimately want to perform */
 349         unsigned char data_cmnd[12];
 350         unsigned short old_use_sg;  /* We save  use_sg here when requesting
 351                                        sense info */
 352         unsigned short use_sg;  /* Number of pieces of scatter-gather */
 353         unsigned short sglist_len;  /* size of malloc'd scatter-gather list */
 354         unsigned bufflen;     /* Size of data buffer */
 355         void *buffer;   /* Data buffer */
 356 
 357         unsigned underflow;     /* Return error if less than this amount is 
 358                                    transfered */
 359 
 360         unsigned transfersize;  /* How much we are guranteed to transfer with
 361                                    each SCSI transfer (ie, between disconnect /
 362                                    reconnects.   Probably == sector size */
 363         
 364         
 365         
 366         struct request request;  /* A copy of the command we are working on*/
 367 
 368         unsigned char sense_buffer[16];  /* Sense for this command, if needed*/
 369 
 370 
 371         int retries;
 372         int allowed;
 373         int timeout_per_command, timeout_total, timeout;
 374 /*
 375  *      We handle the timeout differently if it happens when a reset, 
 376  *      abort, etc are in process. 
 377  */
 378 
 379         unsigned volatile char internal_timeout;
 380 
 381         unsigned flags;
 382                 
 383 /* These variables are for the cdrom only.  Once we have variable size buffers
 384    in the buffer cache, they will go away. */
 385         int this_count; 
 386 /* End of special cdrom variables */
 387         
 388         /* Low-level done function - can be used by low-level driver to point
 389          to completion function.  Not used by mid/upper level code. */
 390         void (*scsi_done)(struct scsi_cmnd *);  
 391 
 392         void (*done)(struct scsi_cmnd *);  /* Mid-level done function */
 393 
 394 /* The following fields can be written to by the host specific code. 
 395    Everything else should be left alone. */
 396 
 397         Scsi_Pointer SCp;   /* Scratchpad used by some host adapters */
 398 
 399         unsigned char * host_scribble; /* The host adapter is allowed to
 400                                           call scsi_malloc and get some memory
 401                                           and hang it here.  The host adapter
 402                                           is also expected to call scsi_free
 403                                           to release this memory.  (The memory
 404                                           obtained by scsi_malloc is guaranteed
 405                                           to be at an address < 16Mb). */
 406 
 407         int result;                   /* Status code from lower level driver */
 408 
 409         unsigned char tag;              /* SCSI-II queued command tag */
 410         } Scsi_Cmnd;             
 411 
 412 /*
 413         scsi_abort aborts the current command that is executing on host host.
 414         The error code, if non zero is returned in the host byte, otherwise 
 415         DID_ABORT is returned in the hostbyte.
 416 */
 417 
 418 extern int scsi_abort (Scsi_Cmnd *, int code);
 419 
 420 extern void scsi_do_cmd (Scsi_Cmnd *, const void *cmnd ,
 421                   void *buffer, unsigned bufflen, void (*done)(struct scsi_cmnd *),
 422                   int timeout, int retries);
 423 
 424 
 425 extern Scsi_Cmnd * allocate_device(struct request **, int, int);
 426 
 427 extern Scsi_Cmnd * request_queueable(struct request *, int);
 428 
 429 extern int scsi_reset (Scsi_Cmnd *);
 430 
 431 extern int max_scsi_hosts;
 432 extern int MAX_SD, NR_SD, MAX_ST, NR_ST, MAX_SR, NR_SR, NR_SG, MAX_SG;
 433 extern unsigned long sd_init(unsigned long, unsigned long);
 434 extern unsigned long sd_init1(unsigned long, unsigned long);
 435 extern void sd_attach(Scsi_Device *);
 436 
 437 extern unsigned long sr_init(unsigned long, unsigned long);
 438 extern unsigned long sr_init1(unsigned long, unsigned long);
 439 extern void sr_attach(Scsi_Device *);
 440 
 441 extern unsigned long st_init(unsigned long, unsigned long);
 442 extern unsigned long st_init1(unsigned long, unsigned long);
 443 extern void st_attach(Scsi_Device *);
 444 
 445 extern unsigned long sg_init(unsigned long, unsigned long);
 446 extern unsigned long sg_init1(unsigned long, unsigned long);
 447 extern void sg_attach(Scsi_Device *);
 448 
 449 #if defined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR)
 450 static void end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
     /* [previous][next][first][last][top][bottom][index][help] */
 451 {
 452         struct request * req;
 453         struct buffer_head * bh;
 454         struct task_struct * p;
 455 
 456         req = &SCpnt->request;
 457         req->errors = 0;
 458         if (!uptodate) {
 459                 printk(DEVICE_NAME " I/O error: dev %04x, sector %lu\n",
 460                        req->dev,req->sector);
 461         }
 462 
 463         do {
 464           if ((bh = req->bh) != NULL) {
 465             req->bh = bh->b_reqnext;
 466             req->nr_sectors -= bh->b_size >> 9;
 467             req->sector += bh->b_size >> 9;
 468             bh->b_reqnext = NULL;
 469             bh->b_uptodate = uptodate;
 470             unlock_buffer(bh);
 471             sectors -= bh->b_size >> 9;
 472             if ((bh = req->bh) != NULL) {
 473               req->current_nr_sectors = bh->b_size >> 9;
 474               if (req->nr_sectors < req->current_nr_sectors) {
 475                 req->nr_sectors = req->current_nr_sectors;
 476                 printk("end_scsi_request: buffer-list destroyed\n");
 477               }
 478             }
 479           }
 480         } while(sectors && bh);
 481         if (req->bh){
 482           req->buffer = bh->b_data;
 483           return;
 484         };
 485         DEVICE_OFF(req->dev);
 486         if ((p = req->waiting) != NULL) {
 487                 req->waiting = NULL;
 488                 p->state = TASK_RUNNING;
 489                 if (p->counter > current->counter)
 490                         need_resched = 1;
 491         }
 492         req->dev = -1;
 493         wake_up(&scsi_devices[SCpnt->index].device_wait);
 494         return;
 495 }
 496 
 497 
 498 /* This is just like INIT_REQUEST, but we need to be aware of the fact
 499    that an interrupt may start another request, so we run this with interrupts
 500    turned off */
 501 
 502 #define INIT_SCSI_REQUEST \
 503         if (!CURRENT) {\
 504                 CLEAR_INTR; \
 505                 sti();   \
 506                 return; \
 507         } \
 508         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 509                 panic(DEVICE_NAME ": request list destroyed"); \
 510         if (CURRENT->bh) { \
 511                 if (!CURRENT->bh->b_lock) \
 512                         panic(DEVICE_NAME ": block not locked"); \
 513         }
 514 #endif
 515 
 516 #define SCSI_SLEEP(QUEUE, CONDITION) {                          \
 517         if (CONDITION) {                                        \
 518                 struct wait_queue wait = { current, NULL};      \
 519                 add_wait_queue(QUEUE, &wait);                   \
 520 sleep_repeat:                                                   \
 521                 current->state = TASK_UNINTERRUPTIBLE;          \
 522                 if (CONDITION) {                                \
 523                         schedule();                             \
 524                         goto sleep_repeat;                      \
 525                 }                                               \
 526                 remove_wait_queue(QUEUE, &wait);                \
 527                 current->state = TASK_RUNNING;                  \
 528         }; }
 529 
 530 #endif

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