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

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