hpt366.c
来自「linux 内核源代码」· C语言 代码 · 共 1,677 行 · 第 1/4 页
C
1,677 行
/* * linux/drivers/ide/pci/hpt366.c Version 1.22 Dec 4, 2007 * * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> * Portions Copyright (C) 2001 Sun Microsystems, Inc. * Portions Copyright (C) 2003 Red Hat Inc * Portions Copyright (C) 2007 Bartlomiej Zolnierkiewicz * Portions Copyright (C) 2005-2007 MontaVista Software, Inc. * * Thanks to HighPoint Technologies for their assistance, and hardware. * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his * donation of an ABit BP6 mainboard, processor, and memory acellerated * development and support. * * * HighPoint has its own drivers (open source except for the RAID part) * available from http://www.highpoint-tech.com/BIOS%20+%20Driver/. * This may be useful to anyone wanting to work on this driver, however do not * trust them too much since the code tends to become less and less meaningful * as the time passes... :-/ * * Note that final HPT370 support was done by force extraction of GPL. * * - add function for getting/setting power status of drive * - the HPT370's state machine can get confused. reset it before each dma * xfer to prevent that from happening. * - reset state engine whenever we get an error. * - check for busmaster state at end of dma. * - use new highpoint timings. * - detect bus speed using highpoint register. * - use pll if we don't have a clock table. added a 66MHz table that's * just 2x the 33MHz table. * - removed turnaround. NOTE: we never want to switch between pll and * pci clocks as the chip can glitch in those cases. the highpoint * approved workaround slows everything down too much to be useful. in * addition, we would have to serialize access to each chip. * Adrian Sun <a.sun@sun.com> * * add drive timings for 66MHz PCI bus, * fix ATA Cable signal detection, fix incorrect /proc info * add /proc display for per-drive PIO/DMA/UDMA mode and * per-channel ATA-33/66 Cable detect. * Duncan Laurie <void@sun.com> * * fixup /proc output for multiple controllers * Tim Hockin <thockin@sun.com> * * On hpt366: * Reset the hpt366 on error, reset on dma * Fix disabling Fast Interrupt hpt366. * Mike Waychison <crlf@sun.com> * * Added support for 372N clocking and clock switching. The 372N needs * different clocks on read/write. This requires overloading rw_disk and * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for * keeping me sane. * Alan Cox <alan@redhat.com> * * - fix the clock turnaround code: it was writing to the wrong ports when * called for the secondary channel, caching the current clock mode per- * channel caused the cached register value to get out of sync with the * actual one, the channels weren't serialized, the turnaround shouldn't * be done on 66 MHz PCI bus * - disable UltraATA/100 for HPT370 by default as the 33 MHz clock being used * does not allow for this speed anyway * - avoid touching disabled channels (e.g. HPT371/N are single channel chips, * their primary channel is kind of virtual, it isn't tied to any pins) * - fix/remove bad/unused timing tables and use one set of tables for the whole * HPT37x chip family; save space by introducing the separate transfer mode * table in which the mode lookup is done * - use f_CNT value saved by the HighPoint BIOS as reading it directly gives * the wrong PCI frequency since DPLL has already been calibrated by BIOS; * read it only from the function 0 of HPT374 chips * - fix the hotswap code: it caused RESET- to glitch when tristating the bus, * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead * - pass to init_chipset() handlers a copy of the IDE PCI device structure as * they tamper with its fields * - pass to the init_setup handlers a copy of the ide_pci_device_t structure * since they may tamper with its fields * - prefix the driver startup messages with the real chip name * - claim the extra 240 bytes of I/O space for all chips * - optimize the UltraDMA filtering and the drive list lookup code * - use pci_get_slot() to get to the function 1 of HPT36x/374 * - cache offset of the channel's misc. control registers (MCRs) being used * throughout the driver * - only touch the relevant MCR when detecting the cable type on HPT374's * function 1 * - rename all the register related variables consistently * - move all the interrupt twiddling code from the speedproc handlers into * init_hwif_hpt366(), also grouping all the DMA related code together there * - merge two HPT37x speedproc handlers, fix the PIO timing register mask and * separate the UltraDMA and MWDMA masks there to avoid changing PIO timings * when setting an UltraDMA mode * - fix hpt3xx_tune_drive() to set the PIO mode requested, not always select * the best possible one * - clean up DMA timeout handling for HPT370 * - switch to using the enumeration type to differ between the numerous chip * variants, matching PCI device/revision ID with the chip type early, at the * init_setup stage * - extend the hpt_info structure to hold the DPLL and PCI clock frequencies, * stop duplicating it for each channel by storing the pointer in the pci_dev * structure: first, at the init_setup stage, point it to a static "template" * with only the chip type and its specific base DPLL frequency, the highest * UltraDMA mode, and the chip settings table pointer filled, then, at the * init_chipset stage, allocate per-chip instance and fill it with the rest * of the necessary information * - get rid of the constant thresholds in the HPT37x PCI clock detection code, * switch to calculating PCI clock frequency based on the chip's base DPLL * frequency * - switch to using the DPLL clock and enable UltraATA/133 mode by default on * anything newer than HPT370/A (except HPT374 that is not capable of this * mode according to the manual) * - fold PCI clock detection and DPLL setup code into init_chipset_hpt366(), * also fixing the interchanged 25/40 MHz PCI clock cases for HPT36x chips; * unify HPT36x/37x timing setup code and the speedproc handlers by joining * the register setting lists into the table indexed by the clock selected * - set the correct hwif->ultra_mask for each individual chip * - add Ultra and MW DMA mode filtering for the HPT37[24] based SATA cards * Sergei Shtylyov, <sshtylyov@ru.mvista.com> or <source@mvista.com> */#include <linux/types.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/ioport.h>#include <linux/blkdev.h>#include <linux/hdreg.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/ide.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/irq.h>/* various tuning parameters */#define HPT_RESET_STATE_ENGINE#undef HPT_DELAY_INTERRUPT#define HPT_SERIALIZE_IO 0static const char *quirk_drives[] = { "QUANTUM FIREBALLlct08 08", "QUANTUM FIREBALLP KA6.4", "QUANTUM FIREBALLP LM20.4", "QUANTUM FIREBALLP LM20.5", NULL};static const char *bad_ata100_5[] = { "IBM-DTLA-307075", "IBM-DTLA-307060", "IBM-DTLA-307045", "IBM-DTLA-307030", "IBM-DTLA-307020", "IBM-DTLA-307015", "IBM-DTLA-305040", "IBM-DTLA-305030", "IBM-DTLA-305020", "IC35L010AVER07-0", "IC35L020AVER07-0", "IC35L030AVER07-0", "IC35L040AVER07-0", "IC35L060AVER07-0", "WDC AC310200R", NULL};static const char *bad_ata66_4[] = { "IBM-DTLA-307075", "IBM-DTLA-307060", "IBM-DTLA-307045", "IBM-DTLA-307030", "IBM-DTLA-307020", "IBM-DTLA-307015", "IBM-DTLA-305040", "IBM-DTLA-305030", "IBM-DTLA-305020", "IC35L010AVER07-0", "IC35L020AVER07-0", "IC35L030AVER07-0", "IC35L040AVER07-0", "IC35L060AVER07-0", "WDC AC310200R", "MAXTOR STM3320620A", NULL};static const char *bad_ata66_3[] = { "WDC AC310200R", NULL};static const char *bad_ata33[] = { "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2", "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2", "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4", "Maxtor 90510D4", "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2", "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4", "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2", NULL};static u8 xfer_speeds[] = { XFER_UDMA_6, XFER_UDMA_5, XFER_UDMA_4, XFER_UDMA_3, XFER_UDMA_2, XFER_UDMA_1, XFER_UDMA_0, XFER_MW_DMA_2, XFER_MW_DMA_1, XFER_MW_DMA_0, XFER_PIO_4, XFER_PIO_3, XFER_PIO_2, XFER_PIO_1, XFER_PIO_0};/* Key for bus clock timings * 36x 37x * bits bits * 0:3 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA. * cycles = value + 1 * 4:7 4:8 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA. * cycles = value + 1 * 8:11 9:12 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file * register access. * 12:15 13:17 cmd_low_time. Active time of DIOW_/DIOR_ during task file * register access. * 16:18 18:20 udma_cycle_time. Clock cycles for UDMA xfer. * - 21 CLK frequency: 0=ATA clock, 1=dual ATA clock. * 19:21 22:24 pre_high_time. Time to initialize the 1st cycle for PIO and * MW DMA xfer. * 22:24 25:27 cmd_pre_high_time. Time to initialize the 1st PIO cycle for * task file register access. * 28 28 UDMA enable. * 29 29 DMA enable. * 30 30 PIO MST enable. If set, the chip is in bus master mode during * PIO xfer. * 31 31 FIFO enable. */static u32 forty_base_hpt36x[] = { /* XFER_UDMA_6 */ 0x900fd943, /* XFER_UDMA_5 */ 0x900fd943, /* XFER_UDMA_4 */ 0x900fd943, /* XFER_UDMA_3 */ 0x900ad943, /* XFER_UDMA_2 */ 0x900bd943, /* XFER_UDMA_1 */ 0x9008d943, /* XFER_UDMA_0 */ 0x9008d943, /* XFER_MW_DMA_2 */ 0xa008d943, /* XFER_MW_DMA_1 */ 0xa010d955, /* XFER_MW_DMA_0 */ 0xa010d9fc, /* XFER_PIO_4 */ 0xc008d963, /* XFER_PIO_3 */ 0xc010d974, /* XFER_PIO_2 */ 0xc010d997, /* XFER_PIO_1 */ 0xc010d9c7, /* XFER_PIO_0 */ 0xc018d9d9};static u32 thirty_three_base_hpt36x[] = { /* XFER_UDMA_6 */ 0x90c9a731, /* XFER_UDMA_5 */ 0x90c9a731, /* XFER_UDMA_4 */ 0x90c9a731, /* XFER_UDMA_3 */ 0x90cfa731, /* XFER_UDMA_2 */ 0x90caa731, /* XFER_UDMA_1 */ 0x90cba731, /* XFER_UDMA_0 */ 0x90c8a731, /* XFER_MW_DMA_2 */ 0xa0c8a731, /* XFER_MW_DMA_1 */ 0xa0c8a732, /* 0xa0c8a733 */ /* XFER_MW_DMA_0 */ 0xa0c8a797, /* XFER_PIO_4 */ 0xc0c8a731, /* XFER_PIO_3 */ 0xc0c8a742, /* XFER_PIO_2 */ 0xc0d0a753, /* XFER_PIO_1 */ 0xc0d0a7a3, /* 0xc0d0a793 */ /* XFER_PIO_0 */ 0xc0d0a7aa /* 0xc0d0a7a7 */};static u32 twenty_five_base_hpt36x[] = { /* XFER_UDMA_6 */ 0x90c98521, /* XFER_UDMA_5 */ 0x90c98521, /* XFER_UDMA_4 */ 0x90c98521, /* XFER_UDMA_3 */ 0x90cf8521, /* XFER_UDMA_2 */ 0x90cf8521, /* XFER_UDMA_1 */ 0x90cb8521, /* XFER_UDMA_0 */ 0x90cb8521, /* XFER_MW_DMA_2 */ 0xa0ca8521, /* XFER_MW_DMA_1 */ 0xa0ca8532, /* XFER_MW_DMA_0 */ 0xa0ca8575, /* XFER_PIO_4 */ 0xc0ca8521, /* XFER_PIO_3 */ 0xc0ca8532, /* XFER_PIO_2 */ 0xc0ca8542, /* XFER_PIO_1 */ 0xc0d08572, /* XFER_PIO_0 */ 0xc0d08585};#if 0/* These are the timing tables from the HighPoint open source drivers... */static u32 thirty_three_base_hpt37x[] = { /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */ /* XFER_UDMA_5 */ 0x12446231, /* XFER_UDMA_4 */ 0x12446231, /* XFER_UDMA_3 */ 0x126c6231, /* XFER_UDMA_2 */ 0x12486231, /* XFER_UDMA_1 */ 0x124c6233, /* XFER_UDMA_0 */ 0x12506297, /* XFER_MW_DMA_2 */ 0x22406c31, /* XFER_MW_DMA_1 */ 0x22406c33, /* XFER_MW_DMA_0 */ 0x22406c97, /* XFER_PIO_4 */ 0x06414e31, /* XFER_PIO_3 */ 0x06414e42, /* XFER_PIO_2 */ 0x06414e53, /* XFER_PIO_1 */ 0x06814e93, /* XFER_PIO_0 */ 0x06814ea7};static u32 fifty_base_hpt37x[] = { /* XFER_UDMA_6 */ 0x12848242, /* XFER_UDMA_5 */ 0x12848242, /* XFER_UDMA_4 */ 0x12ac8242, /* XFER_UDMA_3 */ 0x128c8242, /* XFER_UDMA_2 */ 0x120c8242, /* XFER_UDMA_1 */ 0x12148254, /* XFER_UDMA_0 */ 0x121882ea, /* XFER_MW_DMA_2 */ 0x22808242, /* XFER_MW_DMA_1 */ 0x22808254, /* XFER_MW_DMA_0 */ 0x228082ea, /* XFER_PIO_4 */ 0x0a81f442, /* XFER_PIO_3 */ 0x0a81f443, /* XFER_PIO_2 */ 0x0a81f454, /* XFER_PIO_1 */ 0x0ac1f465, /* XFER_PIO_0 */ 0x0ac1f48a};static u32 sixty_six_base_hpt37x[] = { /* XFER_UDMA_6 */ 0x1c869c62, /* XFER_UDMA_5 */ 0x1cae9c62, /* 0x1c8a9c62 */ /* XFER_UDMA_4 */ 0x1c8a9c62, /* XFER_UDMA_3 */ 0x1c8e9c62, /* XFER_UDMA_2 */ 0x1c929c62, /* XFER_UDMA_1 */ 0x1c9a9c62, /* XFER_UDMA_0 */ 0x1c829c62, /* XFER_MW_DMA_2 */ 0x2c829c62, /* XFER_MW_DMA_1 */ 0x2c829c66, /* XFER_MW_DMA_0 */ 0x2c829d2e, /* XFER_PIO_4 */ 0x0c829c62, /* XFER_PIO_3 */ 0x0c829c84, /* XFER_PIO_2 */ 0x0c829ca6, /* XFER_PIO_1 */ 0x0d029d26, /* XFER_PIO_0 */ 0x0d029d5e};#else/* * The following are the new timing tables with PIO mode data/taskfile transfer * overclocking fixed... *//* This table is taken from the HPT370 data manual rev. 1.02 */static u32 thirty_three_base_hpt37x[] = { /* XFER_UDMA_6 */ 0x16455031, /* 0x16655031 ?? */ /* XFER_UDMA_5 */ 0x16455031, /* XFER_UDMA_4 */ 0x16455031, /* XFER_UDMA_3 */ 0x166d5031, /* XFER_UDMA_2 */ 0x16495031, /* XFER_UDMA_1 */ 0x164d5033, /* XFER_UDMA_0 */ 0x16515097, /* XFER_MW_DMA_2 */ 0x26515031, /* XFER_MW_DMA_1 */ 0x26515033, /* XFER_MW_DMA_0 */ 0x26515097, /* XFER_PIO_4 */ 0x06515021, /* XFER_PIO_3 */ 0x06515022, /* XFER_PIO_2 */ 0x06515033, /* XFER_PIO_1 */ 0x06915065, /* XFER_PIO_0 */ 0x06d1508a};static u32 fifty_base_hpt37x[] = { /* XFER_UDMA_6 */ 0x1a861842, /* XFER_UDMA_5 */ 0x1a861842, /* XFER_UDMA_4 */ 0x1aae1842, /* XFER_UDMA_3 */ 0x1a8e1842, /* XFER_UDMA_2 */ 0x1a0e1842, /* XFER_UDMA_1 */ 0x1a161854, /* XFER_UDMA_0 */ 0x1a1a18ea, /* XFER_MW_DMA_2 */ 0x2a821842, /* XFER_MW_DMA_1 */ 0x2a821854, /* XFER_MW_DMA_0 */ 0x2a8218ea, /* XFER_PIO_4 */ 0x0a821842, /* XFER_PIO_3 */ 0x0a821843, /* XFER_PIO_2 */ 0x0a821855, /* XFER_PIO_1 */ 0x0ac218a8, /* XFER_PIO_0 */ 0x0b02190c};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?