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

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