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

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