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

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