root/drivers/block/triton.c

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

DEFINITIONS

This source file includes following definitions.
  1. dma_intr
  2. build_dmatable
  3. config_drive_for_dma
  4. triton_dmaproc
  5. print_triton_drive_flags
  6. ide_init_triton

   1 /*
   2  *  linux/drivers/block/triton.c        Version 1.04  Dec 1, 1995
   3  *
   4  *  Copyright (c) 1995  Mark Lord
   5  *  May be copied or modified under the terms of the GNU General Public License
   6  */
   7 
   8 /*
   9  * This module provides support for the Bus Master IDE DMA function
  10  * of the Intel PCI Triton chipset (82371FB).
  11  *
  12  * DMA is currently supported only for hard disk drives (not cdroms).
  13  *
  14  * Support for cdroms will likely be added at a later date,
  15  * after broader experience has been obtained with hard disks.
  16  *
  17  * Up to four drives may be enabled for DMA, and the Triton chipset will
  18  * (hopefully) arbitrate the PCI bus among them.  Note that the 82371FB chip
  19  * provides a single "line buffer" for the BM IDE function, so performance of
  20  * multiple (two) drives doing DMA simultaneously will suffer somewhat,
  21  * as they contest for that resource bottleneck.  This is handled transparently
  22  * inside the 82371FB chip.
  23  *
  24  * By default, DMA support is prepared for use, but is currently enabled only
  25  * for drives which support multi-word DMA mode2 (mword2), or which are
  26  * recognized as "good" (see table below).  Drives with only mode0 or mode1
  27  * (single or multi) DMA should also work with this chipset/driver (eg. MC2112A)
  28  * but are not enabled by default.  Use "hdparm -i" to view modes supported
  29  * by a given drive.
  30  *
  31  * The hdparm-2.4 (or later) utility can be used for manually enabling/disabling
  32  * DMA support, but must be (re-)compiled against this kernel version or later.
  33  *
  34  * To enable DMA, use "hdparm -d1 /dev/hd?" on a per-drive basis after booting.
  35  * If problems arise, ide.c will disable DMA operation after a few retries.
  36  * This error recovery mechanism works and has been extremely well exercised.
  37  *
  38  * IDE drives, depending on their vintage, may support several different modes
  39  * of DMA operation.  The boot-time modes are indicated with a "*" in
  40  * the "hdparm -i" listing, and can be changed with *knowledgeable* use of
  41  * the "hdparm -X" feature.  There is seldom a need to do this, as drives
  42  * normally power-up with their "best" PIO/DMA modes enabled.
  43  *
  44  * Testing was done with an ASUS P55TP4XE/100 system and the following drives:
  45  *
  46  *   Quantum Fireball 1080A (1Gig w/83kB buffer), DMA mode2, PIO mode4.
  47  *      - DMA mode2 works well (7.4MB/sec), despite the tiny on-drive buffer.
  48  *      - This drive also does PIO mode4, at about the same speed as DMA mode2.
  49  *        An awesome drive for the price!
  50  *
  51  *   Fujitsu M1606TA (1Gig w/256kB buffer), DMA mode2, PIO mode4.
  52  *      - DMA mode2 gives horrible performance (1.6MB/sec), despite the good
  53  *        size of the on-drive buffer and a boasted 10ms average access time.
  54  *      - PIO mode4 was better, but peaked at a mere 4.5MB/sec.
  55  *
  56  *   Micropolis MC2112A (1Gig w/508kB buffer), drive pre-dates EIDE and ATA2.
  57  *      - DMA works fine (2.2MB/sec), probably due to the large on-drive buffer.
  58  *      - This older drive can also be tweaked for fastPIO (3.7MB/sec) by using
  59  *        maximum clock settings (5,4) and setting all flags except prefetch.
  60  *
  61  *   Western Digital AC31000H (1Gig w/128kB buffer), DMA mode1, PIO mode3.
  62  *      - DMA does not work reliably.  The drive appears to be somewhat tardy
  63  *        in deasserting DMARQ at the end of a sector.  This is evident in
  64  *        the observation that WRITEs work most of the time, depending on
  65  *        cache-buffer occupancy, but multi-sector reads seldom work.
  66  *
  67  * Testing was done with a Gigabyte GA-586 ATE system and the following drive:
  68  * (Uwe Bonnes - bon@elektron.ikp.physik.th-darmstadt.de)
  69  *
  70  *   Western Digital AC31600H (1.6Gig w/128kB buffer), DMA mode2, PIO mode4.
  71  *      - much better than its 1Gig cousin, this drive is reported to work
  72  *        very well with DMA (7.3MB/sec).
  73  *
  74  * Other drives:
  75  *
  76  *   Maxtor 7540AV (515Meg w/32kB buffer), DMA modes mword0/sword2, PIO mode3.
  77  *      - a budget drive, with budget performance, around 3MB/sec.
  78  *
  79  *   Western Digital AC2850F (814Meg w/64kB buffer), DMA mode1, PIO mode3.
  80  *      - another "caviar" drive, similar to the AC31000, except that this one
  81  *        worked with DMA in at least one system.  Throughput is about 3.8MB/sec
  82  *        for both DMA and PIO.
  83  *
  84  *   Conner CFS850A (812Meg w/64kB buffer), DMA mode2, PIO mode4.
  85  *      - like most Conner models, this drive proves that even a fast interface
  86  *        cannot improve slow media.  Both DMA and PIO peak around 3.5MB/sec.
  87  *
  88  * If you have any drive models to add, email your results to:  mlord@bnr.ca
  89  * Keep an eye on /var/adm/messages for "DMA disabled" messages.
  90  *
  91  * Some people have reported trouble with Intel Zappa motherboards.
  92  * This can be fixed by upgrading the AMI BIOS to version 1.00.04.BS0,
  93  * available from ftp://ftp.intel.com/pub/bios/10004bs0.exe
  94  * (thanks to Glen Morrell <glen@spin.Stanford.edu> for researching this).
  95  *
  96  * And, yes, Intel Zappa boards really *do* use the Triton IDE ports.
  97  */
  98 #define _TRITON_C
  99 #include <linux/config.h>
 100 #ifndef CONFIG_BLK_DEV_TRITON
 101 #define CONFIG_BLK_DEV_TRITON y
 102 #endif
 103 #include <linux/types.h>
 104 #include <linux/kernel.h>
 105 #include <linux/timer.h>
 106 #include <linux/mm.h>
 107 #include <linux/ioport.h>
 108 #include <linux/interrupt.h>
 109 #include <linux/blkdev.h>
 110 #include <linux/hdreg.h>
 111 #include <linux/pci.h>
 112 #include <linux/bios32.h>
 113 
 114 #include <asm/io.h>
 115 #include <asm/dma.h>
 116 
 117 #include "ide.h"
 118 
 119 /*
 120  * good_dma_drives() lists the model names (from "hdparm -i")
 121  * of drives which do not support mword2 DMA but which are
 122  * known to work fine with this interface under Linux.
 123  */
 124 const char *good_dma_drives[] = {"Micropolis 2112A"};
 125 
 126 /*
 127  * Our Physical Region Descriptor (PRD) table should be large enough
 128  * to handle the biggest I/O request we are likely to see.  Since requests
 129  * can have no more than 256 sectors, and since the typical blocksize is
 130  * two sectors, we can get by with a limit of 128 entries here for the
 131  * usual worst case.  Most requests seem to include some contiguous blocks,
 132  * further reducing the number of table entries required.
 133  *
 134  * Note that the driver reverts to PIO mode for individual requests that exceed
 135  * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
 136  * 100% of all crazy scenarios here is not necessary.
 137  *
 138  * As it turns out, though, we must allocate a full 4KB page for this,
 139  * so the two PRD tables (ide0 & ide1) will each get half of that,
 140  * allowing each to have about 256 entries (8 bytes each) from this.
 141  */
 142 #define PRD_BYTES       8
 143 #define PRD_ENTRIES     (PAGE_SIZE / (2 * PRD_BYTES))
 144 
 145 /*
 146  * dma_intr() is the handler for disk read/write DMA interrupts
 147  */
 148 static void dma_intr (ide_drive_t *drive)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150         byte stat, dma_stat;
 151         int i;
 152         struct request *rq = HWGROUP(drive)->rq;
 153         unsigned short dma_base = HWIF(drive)->dma_base;
 154 
 155         dma_stat = inb(dma_base+2);             /* get DMA status */
 156         outb(inb(dma_base)&~1, dma_base);       /* stop DMA operation */
 157         stat = GET_STAT();                      /* get drive status */
 158         if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) {
 159                 if ((dma_stat & 7) == 4) {      /* verify good DMA status */
 160                         rq = HWGROUP(drive)->rq;
 161                         for (i = rq->nr_sectors; i > 0;) {
 162                                 i -= rq->current_nr_sectors;
 163                                 ide_end_request(1, HWGROUP(drive));
 164                         }
 165                         return;
 166                 }
 167                 printk("%s: bad DMA status: 0x%02x\n", drive->name, dma_stat);
 168         }
 169         sti();
 170         ide_error(drive, "dma_intr", stat);
 171 }
 172 
 173 /*
 174  * build_dmatable() prepares a dma request.
 175  * Returns 0 if all went okay, returns 1 otherwise.
 176  */
 177 static int build_dmatable (ide_drive_t *drive)
     /* [previous][next][first][last][top][bottom][index][help] */
 178 {
 179         struct request *rq = HWGROUP(drive)->rq;
 180         struct buffer_head *bh = rq->bh;
 181         unsigned long size, addr, *table = HWIF(drive)->dmatable;
 182         unsigned int count = 0;
 183 
 184         do {
 185                 /*
 186                  * Determine addr and size of next buffer area.  We assume that
 187                  * individual virtual buffers are always composed linearly in
 188                  * physical memory.  For example, we assume that any 8kB buffer
 189                  * is always composed of two adjacent physical 4kB pages rather
 190                  * than two possibly non-adjacent physical 4kB pages.
 191                  */
 192                 if (bh == NULL) {  /* paging requests have (rq->bh == NULL) */
 193                         addr = virt_to_bus (rq->buffer);
 194                         size = rq->nr_sectors << 9;
 195                 } else {
 196                         /* group sequential buffers into one large buffer */
 197                         addr = virt_to_bus (bh->b_data);
 198                         size = bh->b_size;
 199                         while ((bh = bh->b_reqnext) != NULL) {
 200                                 if ((addr + size) != virt_to_bus (bh->b_data))
 201                                         break;
 202                                 size += bh->b_size;
 203                         }
 204                 }
 205 
 206                 /*
 207                  * Fill in the dma table, without crossing any 64kB boundaries.
 208                  * We assume 16-bit alignment of all blocks.
 209                  */
 210                 while (size) {
 211                         if (++count >= PRD_ENTRIES) {
 212                                 printk("%s: DMA table too small\n", drive->name);
 213                                 return 1; /* revert to PIO for this request */
 214                         } else {
 215                                 unsigned long bcount = 0x10000 - (addr & 0xffff);
 216                                 if (bcount > size)
 217                                         bcount = size;
 218                                 *table++ = addr;
 219                                 *table++ = bcount;
 220                                 addr += bcount;
 221                                 size -= bcount;
 222                         }
 223                 }
 224         } while (bh != NULL);
 225         if (count) {
 226                 *--table |= 0x80000000; /* set End-Of-Table (EOT) bit */
 227                 return 0;
 228         }
 229         printk("%s: empty DMA table?\n", drive->name);
 230         return 1;       /* let the PIO routines handle this weirdness */
 231 }
 232 
 233 static int config_drive_for_dma (ide_drive_t *drive)
     /* [previous][next][first][last][top][bottom][index][help] */
 234 {
 235         const char **list;
 236 
 237         struct hd_driveid *id = drive->id;
 238         if (id && (id->capability & 1)) {
 239                 /* Enable DMA on any drive that supports mword2 DMA */
 240                 if ((id->field_valid & 2) && (id->dma_mword & 0x404) == 0x404) {
 241                         drive->using_dma = 1;
 242                         return 0;               /* DMA enabled */
 243                 }
 244                 /* Consult the list of known "good" drives */
 245                 list = good_dma_drives;
 246                 while (*list) {
 247                         if (!strcmp(*list++,id->model)) {
 248                                 drive->using_dma = 1;
 249                                 return 0;       /* DMA enabled */
 250                         }
 251                 }
 252         }
 253         return 1;       /* DMA not enabled */
 254 }
 255 
 256 /*
 257  * triton_dmaproc() initiates/aborts DMA read/write operations on a drive.
 258  *
 259  * The caller is assumed to have selected the drive and programmed the drive's
 260  * sector address using CHS or LBA.  All that remains is to prepare for DMA
 261  * and then issue the actual read/write DMA/PIO command to the drive.
 262  *
 263  * Returns 0 if all went well.
 264  * Returns 1 if DMA read/write could not be started, in which case
 265  * the caller should revert to PIO for the current request.
 266  */
 267 static int triton_dmaproc (ide_dma_action_t func, ide_drive_t *drive)
     /* [previous][next][first][last][top][bottom][index][help] */
 268 {
 269         unsigned long dma_base = HWIF(drive)->dma_base;
 270         unsigned int reading = (1 << 3);
 271 
 272         switch (func) {
 273                 case ide_dma_abort:
 274                         outb(inb(dma_base)&~1, dma_base);       /* stop DMA */
 275                         return 0;
 276                 case ide_dma_check:
 277                         return config_drive_for_dma (drive);
 278                 case ide_dma_write:
 279                         reading = 0;
 280                 case ide_dma_read:
 281                         break;
 282                 default:
 283                         printk("triton_dmaproc: unsupported func: %d\n", func);
 284                         return 1;
 285         }
 286         if (build_dmatable (drive))
 287                 return 1;
 288         outl(virt_to_bus (HWIF(drive)->dmatable), dma_base + 4); /* PRD table */
 289         outb(reading, dma_base);                        /* specify r/w */
 290         outb(0x26, dma_base+2);                         /* clear status bits */
 291         ide_set_handler (drive, &dma_intr, WAIT_CMD);   /* issue cmd to drive */
 292         OUT_BYTE(reading ? WIN_READDMA : WIN_WRITEDMA, IDE_COMMAND_REG);
 293         outb(inb(dma_base)|1, dma_base);                /* begin DMA */
 294         return 0;
 295 }
 296 
 297 /*
 298  * print_triton_drive_flags() displays the currently programmed options
 299  * in the Triton chipset for a given drive.
 300  *
 301  *      If fastDMA  is "no", then slow ISA timings are used for DMA data xfers.
 302  *      If fastPIO  is "no", then slow ISA timings are used for PIO data xfers.
 303  *      If IORDY    is "no", then IORDY is assumed to always be asserted.
 304  *      If PreFetch is "no", then data pre-fetch/post are not used.
 305  *
 306  * When "fastPIO" and/or "fastDMA" are "yes", then faster PCI timings and
 307  * back-to-back 16-bit data transfers are enabled, using the sample_CLKs
 308  * and recovery_CLKs (PCI clock cycles) timing parameters for that interface.
 309  */
 310 static void print_triton_drive_flags (unsigned int unit, byte flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 311 {
 312         printk("         %s ", unit ? "slave :" : "master:");
 313         printk( "fastDMA=%s",   (flags&9)       ? "on " : "off");
 314         printk(" PreFetch=%s",  (flags&4)       ? "on " : "off");
 315         printk(" IORDY=%s",     (flags&2)       ? "on " : "off");
 316         printk(" fastPIO=%s\n", ((flags&9)==1)  ? "on " : "off");
 317 }
 318 
 319 /*
 320  * ide_init_triton() prepares the IDE driver for DMA operation.
 321  * This routine is called once, from ide.c during driver initialization,
 322  * for each triton chipset which is found (unlikely to be more than one).
 323  */
 324 void ide_init_triton (byte bus, byte fn)
     /* [previous][next][first][last][top][bottom][index][help] */
 325 {
 326         int rc = 0, h;
 327         unsigned short bmiba, pcicmd;
 328         unsigned int timings;
 329         unsigned long dmatable = 0;
 330         extern ide_hwif_t ide_hwifs[];
 331 
 332         /*
 333          * See if IDE and BM-DMA features are enabled:
 334          */
 335         if ((rc = pcibios_read_config_word(bus, fn, 0x04, &pcicmd)))
 336                 goto quit;
 337         if ((pcicmd & 5) != 5) {
 338                 if ((pcicmd & 1) == 0)
 339                         printk("ide: Triton IDE ports are not enabled\n");
 340                 else
 341                         printk("ide: Triton BM-DMA feature is not enabled\n");
 342                 goto quit;
 343         }
 344 #if 0
 345         (void) pcibios_write_config_word(bus, fn, 0x42, 0x8037); /* for my MC2112A */
 346 #endif
 347         /*
 348          * See if ide port(s) are enabled
 349          */
 350         if ((rc = pcibios_read_config_dword(bus, fn, 0x40, &timings)))
 351                 goto quit;
 352         if (!(timings & 0x80008000)) {
 353                 printk("ide: neither Triton IDE port is enabled\n");
 354                 goto quit;
 355         }
 356         printk("ide: Triton BM-IDE on PCI bus %d function %d\n", bus, fn);
 357 
 358         /*
 359          * Get the bmiba base address
 360          */
 361         if ((rc = pcibios_read_config_word(bus, fn, 0x20, &bmiba)))
 362                 goto quit;
 363         bmiba &= 0xfff0;        /* extract port base address */
 364 
 365         /*
 366          * Save the dma_base port addr for each interface
 367          */
 368         for (h = 0; h < MAX_HWIFS; ++h) {
 369                 ide_hwif_t *hwif = &ide_hwifs[h];
 370                 unsigned short base, time;
 371                 if (hwif->io_base == 0x1f0 && (timings & 0x8000)) {
 372                         time = timings & 0xffff;
 373                         base = bmiba;
 374                 } else if (hwif->io_base == 0x170 && (timings & 0x80000000)) {
 375                         time = timings >> 16;
 376                         base = bmiba + 8;
 377                 } else
 378                         continue;
 379                 printk("    %s: BusMaster DMA at 0x%04x-0x%04x", hwif->name, base, base+7);
 380                 if (check_region(base, 8)) {
 381                         printk(" -- ERROR, PORTS ALREADY IN USE");
 382                 } else {
 383                         request_region(base, 8, hwif->name);
 384                         hwif->dma_base = base;
 385                         if (!dmatable) {
 386                                 /*
 387                                  * Since we know we are on a PCI bus, we could
 388                                  * actually use __get_free_pages() here instead
 389                                  * of __get_dma_pages() -- no ISA limitations.
 390                                  */
 391                                 dmatable = __get_dma_pages(GFP_KERNEL, 0);
 392                         }
 393                         if (dmatable) {
 394                                 hwif->dmatable = (unsigned long *) dmatable;
 395                                 dmatable += (PRD_ENTRIES * PRD_BYTES);
 396                                 outl(virt_to_bus(hwif->dmatable), base + 4);
 397                                 hwif->dmaproc  = &triton_dmaproc;
 398                         }
 399                 }
 400                 printk("\n    %s timing: (0x%04x) sample_CLKs=%d, recovery_CLKs=%d\n",
 401                  hwif->name, time, ((~time>>12)&3)+2, ((~time>>8)&3)+1);
 402                 print_triton_drive_flags (0, time & 0xf);
 403                 print_triton_drive_flags (1, (time >> 4) & 0xf);
 404         }
 405 
 406 quit: if (rc) printk("ide: pcibios access failed - %s\n", pcibios_strerror(rc));
 407 }
 408 

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