root/drivers/block/ide.h

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

INCLUDED FROM


   1 /*
   2  *  linux/drivers/block/ide.h
   3  *
   4  *  Copyright (C) 1994, 1995  Linus Torvalds & authors
   5  */
   6 
   7 /*
   8  * This is the multiple IDE interface driver, as evolved from hd.c.  
   9  * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
  10  * There can be up to two drives per interface, as per the ATA-2 spec.
  11  *
  12  * Primary i/f:    ide0: major=3;  (hda)         minor=0; (hdb)         minor=64
  13  * Secondary i/f:  ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
  14  * Tertiary i/f:   ide2: major=33; (hde)         minor=0; (hdf)         minor=64
  15  * Quaternary i/f: ide3: major=34; (hdg)         minor=0; (hdh)         minor=64
  16  */
  17 
  18 /******************************************************************************
  19  * IDE driver configuration options (play with these as desired):
  20  */
  21 #undef REALLY_SLOW_IO                   /* most systems can safely undef this */
  22 #include <asm/io.h>
  23 
  24 #undef  REALLY_FAST_IO                  /* define if ide ports are perfect */
  25 #define INITIAL_MULT_COUNT      0       /* off=0; on=2,4,8,16,32, etc.. */
  26 
  27 #ifndef DISK_RECOVERY_TIME              /* off=0; on=access_delay_time */
  28 #define DISK_RECOVERY_TIME      0       /*  for hardware that needs it */
  29 #endif
  30 #ifndef OK_TO_RESET_CONTROLLER          /* 1 needed for good error recovery */
  31 #define OK_TO_RESET_CONTROLLER  1       /* 0 for use with AH2372A/B interface */
  32 #endif
  33 #ifndef SUPPORT_DTC2278                 /* 1 to support DTC2278 chipset */
  34 #define SUPPORT_DTC2278         1       /* 0 to reduce kernel size */
  35 #endif
  36 #ifndef FANCY_STATUS_DUMPS              /* 1 for human-readable drive errors */
  37 #define FANCY_STATUS_DUMPS      1       /* 0 to reduce kernel size */
  38 #endif
  39 
  40 /*
  41  * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
  42  */
  43 #define IDE_DRIVE_CMD           99      /* (magic) undef to reduce kernel size*/
  44 
  45 /*
  46  *  "No user-serviceable parts" beyond this point  :)
  47  *****************************************************************************/
  48 
  49 typedef unsigned char   byte;   /* used everywhere */
  50 
  51 /*
  52  * Probably not wise to fiddle with these
  53  */
  54 #define ERROR_MAX       8       /* Max read/write errors per sector */
  55 #define ERROR_RESET     3       /* Reset controller every 4th retry */
  56 #define ERROR_RECAL     1       /* Recalibrate every 2nd retry */
  57 
  58 /*
  59  * Ensure that various configuration flags have compatible settings
  60  */
  61 #ifdef REALLY_SLOW_IO
  62 #undef REALLY_FAST_IO
  63 #endif
  64 
  65 /*
  66  * Definitions for accessing IDE controller registers
  67  */
  68 
  69 #define HWIF(drive)             ((ide_hwif_t *)drive->hwif)
  70 #define HWGROUP(drive)          ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
  71 
  72 #define IDE_DATA_REG            (HWIF(drive)->io_base)
  73 #define IDE_ERROR_REG           (HWIF(drive)->io_base+1)
  74 #define IDE_NSECTOR_REG         (HWIF(drive)->io_base+2)
  75 #define IDE_SECTOR_REG          (HWIF(drive)->io_base+3)
  76 #define IDE_LCYL_REG            (HWIF(drive)->io_base+4)
  77 #define IDE_HCYL_REG            (HWIF(drive)->io_base+5)
  78 #define IDE_SELECT_REG          (HWIF(drive)->io_base+6)
  79 #define IDE_STATUS_REG          (HWIF(drive)->io_base+7)
  80 #define IDE_CONTROL_REG         (HWIF(drive)->ctl_port)
  81 #define IDE_FEATURE_REG         IDE_ERROR_REG
  82 #define IDE_COMMAND_REG         IDE_STATUS_REG
  83 #define IDE_ALTSTATUS_REG       IDE_CONTROL_REG
  84 
  85 #ifdef REALLY_FAST_IO
  86 #define OUT_BYTE(b,p)           outb((b),p)
  87 #define IN_BYTE(p)              (byte)inb(p)
  88 #else
  89 #define OUT_BYTE(b,p)           outb_p((b),p)
  90 #define IN_BYTE(p)              (byte)inb_p(p)
  91 #endif /* REALLY_FAST_IO */
  92 
  93 #define GET_ERR()               IN_BYTE(IDE_ERROR_REG)
  94 #define GET_STAT()              IN_BYTE(IDE_STATUS_REG)
  95 #define OK_STAT(stat,good,bad)  (((stat)&((good)|(bad)))==(good))
  96 #define BAD_R_STAT              (BUSY_STAT   | ERR_STAT)
  97 #define BAD_W_STAT              (BAD_R_STAT  | WRERR_STAT)
  98 #define BAD_STAT                (BAD_R_STAT  | DRQ_STAT)
  99 #define DRIVE_READY             (READY_STAT  | SEEK_STAT)
 100 #define DATA_READY              (DRIVE_READY | DRQ_STAT)
 101 
 102 /*
 103  * Some more useful definitions
 104  */
 105 #define IDE_MAJOR_NAME  "ide"   /* the same for all i/f; see also genhd.c */
 106 #define MAJOR_NAME      IDE_MAJOR_NAME
 107 #define PARTN_BITS      6       /* number of minor dev bits for partitions */
 108 #define PARTN_MASK      ((1<<PARTN_BITS)-1)     /* a useful bit mask */
 109 #define MAX_DRIVES      2       /* per interface; 2 assumed by lots of code */
 110 #define MAX_HWIFS       4       /* an arbitrary, but realistic limit */
 111 #define SECTOR_WORDS    (512 / 4)       /* number of 32bit words per sector */
 112 
 113 /*
 114  * Timeouts for various operations:
 115  */
 116 #define WAIT_DRQ        (5*HZ/100)      /* 50msec - spec allows up to 20ms */
 117 #define WAIT_READY      (3*HZ/100)      /* 30msec - should be instantaneous */
 118 #define WAIT_PIDENTIFY  (1*HZ)  /* 1sec   - should be less than 3ms (?) */
 119 #define WAIT_WORSTCASE  (30*HZ) /* 30sec  - worst case when spinning up */
 120 #define WAIT_CMD        (10*HZ) /* 10sec  - maximum wait for an IRQ to happen */
 121 
 122 #ifdef CONFIG_BLK_DEV_IDECD
 123 
 124 struct atapi_request_sense {
 125   unsigned char error_code : 7;
 126   unsigned char valid      : 1;
 127   byte reserved1;
 128   unsigned char sense_key  : 4;
 129   unsigned char reserved2  : 1;
 130   unsigned char ili        : 1;
 131   unsigned char reserved3  : 2;
 132   byte info[4];
 133   byte sense_len;
 134   byte command_info[4];
 135   byte asc;
 136   byte ascq;
 137   byte fru;
 138   byte sense_key_specific[3];
 139 };
 140 
 141 struct packet_command {
 142   char *buffer;
 143   int buflen;
 144   int stat;
 145   struct atapi_request_sense *sense_data;
 146   unsigned char c[12];
 147 };
 148 
 149 /* Space to hold the disk TOC. */
 150 
 151 #define MAX_TRACKS 99
 152 struct atapi_toc_header {
 153   unsigned short toc_length;
 154   byte first_track;
 155   byte last_track;
 156 };
 157 
 158 struct atapi_toc_entry {
 159   byte reserved1;
 160   unsigned control : 4;
 161   unsigned adr     : 4;
 162   byte track;
 163   byte reserved2;
 164   unsigned lba;
 165 };
 166 
 167 struct atapi_toc {
 168   int    last_session_lba;
 169   int    xa_flag;
 170   unsigned capacity;
 171   struct atapi_toc_header hdr;
 172   struct atapi_toc_entry  ent[MAX_TRACKS+1];  /* One extra for the leadout. */
 173 };
 174 
 175 /* Extra per-device info for cdrom drives. */
 176 struct cdrom_info {
 177 
 178   /* Buffer for table of contents.  NULL if we haven't allocated
 179      a TOC buffer for this device yet. */
 180 
 181   struct atapi_toc *toc;
 182 
 183   /* Sector buffer.  If a read request wants only the first part of a cdrom
 184      block, we cache the rest of the block here, in the expectation that that
 185      data is going to be wanted soon.  SECTOR_BUFFERED is the number of the
 186      first buffered sector, and NSECTORS_BUFFERED is the number of sectors
 187      in the buffer.  Before the buffer is allocated, we should have
 188      SECTOR_BUFFER == NULL and NSECTORS_BUFFERED == 0. */
 189 
 190   unsigned long sector_buffered;
 191   unsigned long nsectors_buffered;
 192   char *sector_buffer;
 193 
 194   /* The result of the last successful request sense command
 195      on this device. */
 196   struct atapi_request_sense sense_data;
 197 };
 198 
 199 #endif /* CONFIG_BLK_DEV_IDECD */
 200 
 201 /*
 202  * Now for the data we need to maintain per-drive:  ide_drive_t
 203  */
 204 typedef enum {disk, cdrom} media_t;
 205 
 206 typedef union {
 207         unsigned all                    : 8;    /* all of the bits together */
 208         struct {
 209                 unsigned set_geometry   : 1;    /* respecify drive geometry */
 210                 unsigned recalibrate    : 1;    /* seek to cyl 0      */
 211                 unsigned set_multmode   : 1;    /* set multmode count */
 212                 unsigned reserved       : 5;    /* unused */
 213                 } b;
 214         } special_t;
 215 
 216 typedef union {
 217         unsigned all                    : 8;    /* all of the bits together */
 218         struct {
 219                 unsigned head           : 4;    /* always zeros here */
 220                 unsigned unit           : 1;    /* drive select number, 0 or 1 */
 221                 unsigned bit5           : 1;    /* always 1 */
 222                 unsigned lba            : 1;    /* using LBA instead of CHS */
 223                 unsigned bit7           : 1;    /* always 1 */
 224         } b;
 225         } select_t;
 226 
 227 typedef struct ide_drive_s {
 228         special_t       special;        /* special action flags */
 229         unsigned present        : 1;    /* drive is physically present */
 230         unsigned noprobe        : 1;    /* from:  hdx=noprobe */
 231         unsigned keep_settings  : 1;    /* restore settings after drive reset */
 232         unsigned busy           : 1;    /* currently doing revalidate_disk() */
 233         unsigned vlb_32bit      : 1;    /* use 32bit in/out for data */
 234         unsigned vlb_sync       : 1;    /* needed for some 32bit chip sets */
 235         unsigned removeable     : 1;    /* 1 if need to do check_media_change */
 236         unsigned using_dma      : 1;    /* disk is using dma for read/write */
 237         unsigned unmask         : 1;    /* flag: okay to unmask other irqs */
 238         media_t         media;          /* disk, cdrom, tape */
 239         select_t        select;         /* basic drive/head select reg value */
 240         void            *hwif;          /* actually (ide_hwif_t *) */
 241         byte            ctl;            /* "normal" value for IDE_CONTROL_REG */
 242         byte            ready_stat;     /* min status value for drive ready */
 243         byte            mult_count;     /* current multiple sector setting */
 244         byte            mult_req;       /* requested multiple sector setting */
 245         byte            chipset;        /* interface chipset access method */
 246         byte            bad_wstat;      /* used for ignoring WRERR_STAT */
 247         byte            sect0;          /* offset of first sector for DM6:DDO */
 248         byte            usage;          /* current "open()" count for drive */
 249         byte            head;           /* "real" number of heads */
 250         byte            sect;           /* "real" sectors per track */
 251         byte            bios_head;      /* BIOS/fdisk/LILO number of heads */
 252         byte            bios_sect;      /* BIOS/fdisk/LILO sectors per track */
 253         unsigned short  bios_cyl;       /* BIOS/fdisk/LILO number of cyls */
 254         unsigned short  cyl;            /* "real" number of cyls */
 255         struct wait_queue *wqueue;      /* used to wait for drive in open() */
 256         struct hd_driveid *id;          /* drive model identification info */
 257         struct hd_struct  *part;        /* drive partition table */
 258         char            name[4];        /* drive name, such as "hda" */
 259 #ifdef CONFIG_BLK_DEV_IDECD
 260         struct cdrom_info cdrom_info;   /* from ide-cd.c */
 261 #endif /* CONFIG_BLK_DEV_IDECD */
 262         } ide_drive_t;
 263 
 264 /*
 265  * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
 266  *
 267  * The caller is assumed to have selected the drive and programmed the drive's
 268  * sector address using CHS or LBA.  All that remains is to prepare for DMA
 269  * and then issue the actual read/write DMA/PIO command to the drive.
 270  *
 271  * Returns 0 if all went well.
 272  * Returns 1 if DMA read/write could not be started, in which case the caller
 273  * should either try again later, or revert to PIO for the current request.
 274  */
 275 typedef enum {ide_dma_read = 0, ide_dma_write = 1, ide_dma_abort = 2, ide_dma_check = 3} ide_dma_action_t;
 276 typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
 277 
 278 typedef struct hwif_s {
 279         struct hwif_s   *next;          /* for linked-list in ide_hwgroup_t */
 280         void            *hwgroup;       /* actually (ide_hwgroup_t *) */
 281         unsigned short  io_base;        /* base io port addr */
 282         unsigned short  ctl_port;       /* usually io_base+0x206 */
 283         ide_drive_t     drives[MAX_DRIVES];     /* drive info */
 284         struct gendisk  *gd;            /* gendisk structure */
 285         ide_dmaproc_t   *dmaproc;       /* dma read/write/abort routine */
 286         unsigned long   *dmatable;      /* dma physical region descriptor table */
 287         unsigned short  dma_base;       /* base addr for dma ports (triton) */
 288         byte            irq;            /* our irq number */
 289         byte            major;          /* our major number */
 290         byte            drivecount;     /* how many drives attached */
 291         char            name[5];        /* name of interface, eg. "ide0" */
 292         unsigned        noprobe : 1;    /* don't probe for this interface */
 293         unsigned        present : 1;    /* this interface exists */
 294 #if (DISK_RECOVERY_TIME > 0)
 295         unsigned long   last_time;      /* time when previous rq was done */
 296 #endif
 297 #ifdef CONFIG_BLK_DEV_IDECD
 298         struct request request_sense_request;   /* from ide-cd.c */
 299         struct packet_command request_sense_pc; /* from ide-cd.c */
 300 #endif /* CONFIG_BLK_DEV_IDECD */
 301         } ide_hwif_t;
 302 
 303 /*
 304  *  internal ide interrupt handler type
 305  */
 306 typedef void (ide_handler_t)(ide_drive_t *);
 307 
 308 typedef struct hwgroup_s {
 309         ide_handler_t           *handler;/* irq handler, if active */
 310         ide_drive_t             *drive; /* current drive */
 311         ide_hwif_t              *hwif;  /* ptr to current hwif in linked-list */
 312         struct request          *rq;    /* current request */
 313         struct timer_list       timer;  /* failsafe timer */
 314         struct request          wrq;    /* local copy of current write rq */
 315         unsigned long   reset_timeout;  /* timeout value during ide resets */
 316 #ifdef CONFIG_BLK_DEV_IDECD
 317         int                     doing_atapi_reset;
 318 #endif /* CONFIG_BLK_DEV_IDECD */
 319         } ide_hwgroup_t;
 320 
 321 /*
 322  * One final include file, which references some of the data/defns from above
 323  */
 324 #define IDE_DRIVER      /* "parameter" for blk.h */
 325 #include "blk.h"
 326 
 327 #if (DISK_RECOVERY_TIME > 0)
 328 void ide_set_recovery_timer (ide_hwif_t *);
 329 #define SET_RECOVERY_TIMER(drive) ide_set_recovery_timer (drive)
 330 #else
 331 #define SET_RECOVERY_TIMER(drive)
 332 #endif
 333 
 334 /*
 335  * The main (re-)entry point for handling a new request is IDE_DO_REQUEST.
 336  * Note that IDE_DO_REQUEST should *only* ever be invoked from an interrupt
 337  * handler.  All others, such as a timer expiry handler, should call
 338  * do_hwgroup_request() instead (currently local to ide.c).
 339  */
 340 void ide_do_request (ide_hwgroup_t *);
 341 #define IDE_DO_REQUEST { SET_RECOVERY_TIMER(HWIF(drive)); ide_do_request(HWGROUP(drive)); }
 342 
 343 
 344 /*
 345  * This is used for (nearly) all data transfers from the IDE interface
 346  */
 347 void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
 348 
 349 /*
 350  * This is used for (nearly) all data transfers to the IDE interface
 351  */
 352 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
 353 
 354 /*
 355  * This is used on exit from the driver, to designate the next irq handler
 356  * and also to start the safety timer.
 357  */
 358 void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler);
 359 
 360 /*
 361  * Error reporting, in human readable form (luxurious, but a memory hog).
 362  */
 363 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
 364 
 365 /*
 366  * ide_error() takes action based on the error returned by the controller.
 367  *
 368  * Returns 1 if an ide reset operation has been initiated, in which case
 369  * the caller MUST simply return from the driver (through however many levels).
 370  * Returns 0 otherwise.
 371  */
 372 int ide_error (ide_drive_t *drive, const char *msg, byte stat);
 373 
 374 /*
 375  * This routine busy-waits for the drive status to be not "busy".
 376  * It then checks the status for all of the "good" bits and none
 377  * of the "bad" bits, and if all is okay it returns 0.  All other
 378  * cases return 1 after invoking ide_error()
 379  *
 380  */
 381 int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
 382 
 383 /*
 384  * This is called from genhd.c to correct DiskManager/EZ-Drive geometries
 385  */
 386 int ide_xlate_1024(dev_t, int, const char *);
 387 
 388 /*
 389  * Start a reset operation for an IDE interface.
 390  * Returns 0 if the reset operation is still in progress,
 391  *  in which case the drive MUST return, to await completion.
 392  * Returns 1 if the reset is complete (success or failure).
 393  */
 394 int ide_do_reset (ide_drive_t *);
 395 
 396 /*
 397  * ide_alloc(): memory allocation for use *only* during driver initialization.
 398  * If "within_area" is non-zero, the memory will be allocated such that
 399  * it lies entirely within a "within_area" sized area (eg. 4096).  This is
 400  * needed for DMA stuff.  "within_area" must be a power of two (not validated).
 401  * All allocations are longword aligned.
 402  */
 403 void *ide_alloc (unsigned long bytecount, unsigned long within_area);
 404 
 405 #ifdef CONFIG_BLK_DEV_IDECD
 406 /*
 407  * These are routines in ide-cd.c invoked from ide.c
 408  */
 409 void ide_do_rw_cdrom (ide_drive_t *, unsigned long);
 410 int ide_cdrom_ioctl (ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
 411 int ide_cdrom_check_media_change (ide_drive_t *);
 412 int ide_cdrom_open (struct inode *, struct file *, ide_drive_t *);
 413 void ide_cdrom_release (struct inode *, struct file *, ide_drive_t *);
 414 void ide_cdrom_setup (ide_drive_t *);
 415 #endif /* CONFIG_BLK_DEV_IDECD */
 416 
 417 #ifdef CONFIG_BLK_DEV_TRITON
 418 void ide_init_triton (ide_hwif_t *);
 419 #endif /* CONFIG_BLK_DEV_TRITON */
 420 

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