root/kernel/blk_drv/scsi/scsi.h

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

INCLUDED FROM


DEFINITIONS

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

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