aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ide/arm/icside.c2
-rw-r--r--drivers/ide/cris/ide-cris.c2
-rw-r--r--drivers/ide/ide-dma.c74
-rw-r--r--drivers/ide/ide-iops.c2
-rw-r--r--drivers/ide/ide-lib.c125
-rw-r--r--drivers/ide/ide.c1
-rw-r--r--drivers/ide/pci/aec62xx.c32
-rw-r--r--drivers/ide/pci/alim15x3.c76
-rw-r--r--drivers/ide/pci/atiixp.c20
-rw-r--r--drivers/ide/pci/cmd64x.c65
-rw-r--r--drivers/ide/pci/cs5535.c20
-rw-r--r--drivers/ide/pci/hpt34x.c9
-rw-r--r--drivers/ide/pci/hpt366.c67
-rw-r--r--drivers/ide/pci/it8213.c20
-rw-r--r--drivers/ide/pci/it821x.c20
-rw-r--r--drivers/ide/pci/jmicron.c21
-rw-r--r--drivers/ide/pci/pdc202xx_new.c14
-rw-r--r--drivers/ide/pci/pdc202xx_old.c27
-rw-r--r--drivers/ide/pci/piix.c66
-rw-r--r--drivers/ide/pci/scc_pata.c21
-rw-r--r--drivers/ide/pci/serverworks.c31
-rw-r--r--drivers/ide/pci/siimage.c45
-rw-r--r--drivers/ide/pci/sis5513.c14
-rw-r--r--drivers/ide/pci/slc90e66.c13
-rw-r--r--drivers/ide/pci/tc86c001.c9
-rw-r--r--drivers/ide/pci/triflex.c4
-rw-r--r--include/linux/ide.h10
27 files changed, 236 insertions, 574 deletions
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index e2953fc1fafb..f383ace2a087 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -342,7 +342,7 @@ static int icside_dma_check(ide_drive_t *drive)
342 * Enable DMA on any drive that has multiword DMA 342 * Enable DMA on any drive that has multiword DMA
343 */ 343 */
344 if (id->field_valid & 2) { 344 if (id->field_valid & 2) {
345 xfer_mode = ide_dma_speed(drive, 0); 345 xfer_mode = ide_max_dma_mode(drive);
346 goto out; 346 goto out;
347 } 347 }
348 348
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 5e8efc89255a..9691d089fce8 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -1004,7 +1004,7 @@ static int cris_ide_build_dmatable (ide_drive_t *drive)
1004 1004
1005static int cris_config_drive_for_dma (ide_drive_t *drive) 1005static int cris_config_drive_for_dma (ide_drive_t *drive)
1006{ 1006{
1007 u8 speed = ide_dma_speed(drive, 1); 1007 u8 speed = ide_max_dma_mode(drive);
1008 1008
1009 if (!speed) 1009 if (!speed)
1010 return 0; 1010 return 0;
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index fd213088b06b..f28fabb791fe 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -705,6 +705,80 @@ int ide_use_dma(ide_drive_t *drive)
705 705
706EXPORT_SYMBOL_GPL(ide_use_dma); 706EXPORT_SYMBOL_GPL(ide_use_dma);
707 707
708static const u8 xfer_mode_bases[] = {
709 XFER_UDMA_0,
710 XFER_MW_DMA_0,
711 XFER_SW_DMA_0,
712};
713
714static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base)
715{
716 struct hd_driveid *id = drive->id;
717 ide_hwif_t *hwif = drive->hwif;
718 unsigned int mask = 0;
719
720 switch(base) {
721 case XFER_UDMA_0:
722 if ((id->field_valid & 4) == 0)
723 break;
724
725 mask = id->dma_ultra & hwif->ultra_mask;
726
727 if (hwif->udma_filter)
728 mask &= hwif->udma_filter(drive);
729
730 if ((mask & 0x78) && (eighty_ninty_three(drive) == 0))
731 mask &= 0x07;
732 break;
733 case XFER_MW_DMA_0:
734 mask = id->dma_mword & hwif->mwdma_mask;
735 break;
736 case XFER_SW_DMA_0:
737 mask = id->dma_1word & hwif->swdma_mask;
738 break;
739 default:
740 BUG();
741 break;
742 }
743
744 return mask;
745}
746
747/**
748 * ide_max_dma_mode - compute DMA speed
749 * @drive: IDE device
750 *
751 * Checks the drive capabilities and returns the speed to use
752 * for the DMA transfer. Returns 0 if the drive is incapable
753 * of DMA transfers.
754 */
755
756u8 ide_max_dma_mode(ide_drive_t *drive)
757{
758 ide_hwif_t *hwif = drive->hwif;
759 unsigned int mask;
760 int x, i;
761 u8 mode = 0;
762
763 if (drive->media != ide_disk && hwif->atapi_dma == 0)
764 return 0;
765
766 for (i = 0; i < ARRAY_SIZE(xfer_mode_bases); i++) {
767 mask = ide_get_mode_mask(drive, xfer_mode_bases[i]);
768 x = fls(mask) - 1;
769 if (x >= 0) {
770 mode = xfer_mode_bases[i] + x;
771 break;
772 }
773 }
774
775 printk(KERN_DEBUG "%s: selected mode 0x%x\n", drive->name, mode);
776
777 return mode;
778}
779
780EXPORT_SYMBOL_GPL(ide_max_dma_mode);
781
708void ide_dma_verbose(ide_drive_t *drive) 782void ide_dma_verbose(ide_drive_t *drive)
709{ 783{
710 struct hd_driveid *id = drive->id; 784 struct hd_driveid *id = drive->id;
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 3caa176b3155..ed6128f6cd98 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -592,8 +592,6 @@ u8 eighty_ninty_three (ide_drive_t *drive)
592 return 1; 592 return 1;
593} 593}
594 594
595EXPORT_SYMBOL(eighty_ninty_three);
596
597int ide_ata66_check (ide_drive_t *drive, ide_task_t *args) 595int ide_ata66_check (ide_drive_t *drive, ide_task_t *args)
598{ 596{
599 if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) && 597 if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) &&
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 68719314df3f..4557fc5a3ea3 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -69,123 +69,34 @@ char *ide_xfer_verbose (u8 xfer_rate)
69EXPORT_SYMBOL(ide_xfer_verbose); 69EXPORT_SYMBOL(ide_xfer_verbose);
70 70
71/** 71/**
72 * ide_dma_speed - compute DMA speed 72 * ide_rate_filter - filter transfer mode
73 * @drive: drive 73 * @drive: IDE device
74 * @mode: modes available
75 *
76 * Checks the drive capabilities and returns the speed to use
77 * for the DMA transfer. Returns 0 if the drive is incapable
78 * of DMA transfers.
79 */
80
81u8 ide_dma_speed(ide_drive_t *drive, u8 mode)
82{
83 struct hd_driveid *id = drive->id;
84 ide_hwif_t *hwif = HWIF(drive);
85 u8 ultra_mask, mwdma_mask, swdma_mask;
86 u8 speed = 0;
87
88 if (drive->media != ide_disk && hwif->atapi_dma == 0)
89 return 0;
90
91 /* Capable of UltraDMA modes? */
92 ultra_mask = id->dma_ultra & hwif->ultra_mask;
93
94 if (!(id->field_valid & 4))
95 mode = 0; /* fallback to MW/SW DMA if no UltraDMA */
96
97 switch (mode) {
98 case 4:
99 if (ultra_mask & 0x40) {
100 speed = XFER_UDMA_6;
101 break;
102 }
103 case 3:
104 if (ultra_mask & 0x20) {
105 speed = XFER_UDMA_5;
106 break;
107 }
108 case 2:
109 if (ultra_mask & 0x10) {
110 speed = XFER_UDMA_4;
111 break;
112 }
113 if (ultra_mask & 0x08) {
114 speed = XFER_UDMA_3;
115 break;
116 }
117 case 1:
118 if (ultra_mask & 0x04) {
119 speed = XFER_UDMA_2;
120 break;
121 }
122 if (ultra_mask & 0x02) {
123 speed = XFER_UDMA_1;
124 break;
125 }
126 if (ultra_mask & 0x01) {
127 speed = XFER_UDMA_0;
128 break;
129 }
130 case 0:
131 mwdma_mask = id->dma_mword & hwif->mwdma_mask;
132
133 if (mwdma_mask & 0x04) {
134 speed = XFER_MW_DMA_2;
135 break;
136 }
137 if (mwdma_mask & 0x02) {
138 speed = XFER_MW_DMA_1;
139 break;
140 }
141 if (mwdma_mask & 0x01) {
142 speed = XFER_MW_DMA_0;
143 break;
144 }
145
146 swdma_mask = id->dma_1word & hwif->swdma_mask;
147
148 if (swdma_mask & 0x04) {
149 speed = XFER_SW_DMA_2;
150 break;
151 }
152 if (swdma_mask & 0x02) {
153 speed = XFER_SW_DMA_1;
154 break;
155 }
156 if (swdma_mask & 0x01) {
157 speed = XFER_SW_DMA_0;
158 break;
159 }
160 }
161
162 return speed;
163}
164EXPORT_SYMBOL(ide_dma_speed);
165
166
167/**
168 * ide_rate_filter - return best speed for mode
169 * @mode: modes available
170 * @speed: desired speed 74 * @speed: desired speed
171 * 75 *
172 * Given the available DMA/UDMA mode this function returns 76 * Given the available transfer modes this function returns
173 * the best available speed at or below the speed requested. 77 * the best available speed at or below the speed requested.
78 *
79 * FIXME: filter also PIO/SWDMA/MWDMA modes
174 */ 80 */
175 81
176u8 ide_rate_filter (u8 mode, u8 speed) 82u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
177{ 83{
178#ifdef CONFIG_BLK_DEV_IDEDMA 84#ifdef CONFIG_BLK_DEV_IDEDMA
179 static u8 speed_max[] = { 85 ide_hwif_t *hwif = drive->hwif;
180 XFER_MW_DMA_2, XFER_UDMA_2, XFER_UDMA_4, 86 u8 mask = hwif->ultra_mask, mode = XFER_MW_DMA_2;
181 XFER_UDMA_5, XFER_UDMA_6 87
182 }; 88 if (hwif->udma_filter)
89 mask = hwif->udma_filter(drive);
90
91 if ((mask & 0x78) && (eighty_ninty_three(drive) == 0))
92 mask &= 0x07;
93
94 if (mask)
95 mode = fls(mask) - 1 + XFER_UDMA_0;
183 96
184// printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed); 97// printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed);
185 98
186 /* So that we remember to update this if new modes appear */ 99 return min(speed, mode);
187 BUG_ON(mode > 4);
188 return min(speed, speed_max[mode]);
189#else /* !CONFIG_BLK_DEV_IDEDMA */ 100#else /* !CONFIG_BLK_DEV_IDEDMA */
190 return min(speed, (u8)XFER_PIO_4); 101 return min(speed, (u8)XFER_PIO_4);
191#endif /* CONFIG_BLK_DEV_IDEDMA */ 102#endif /* CONFIG_BLK_DEV_IDEDMA */
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index c06424fe647b..73f752142f9e 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -477,6 +477,7 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
477 477
478 hwif->tuneproc = tmp_hwif->tuneproc; 478 hwif->tuneproc = tmp_hwif->tuneproc;
479 hwif->speedproc = tmp_hwif->speedproc; 479 hwif->speedproc = tmp_hwif->speedproc;
480 hwif->udma_filter = tmp_hwif->udma_filter;
480 hwif->selectproc = tmp_hwif->selectproc; 481 hwif->selectproc = tmp_hwif->selectproc;
481 hwif->reset_poll = tmp_hwif->reset_poll; 482 hwif->reset_poll = tmp_hwif->reset_poll;
482 hwif->pre_reset = tmp_hwif->pre_reset; 483 hwif->pre_reset = tmp_hwif->pre_reset;
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index abe0b1bb55ff..099539e8c7a3 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -87,38 +87,12 @@ static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entr
87 return chipset_table->ultra_settings; 87 return chipset_table->ultra_settings;
88} 88}
89 89
90static u8 aec62xx_ratemask (ide_drive_t *drive)
91{
92 ide_hwif_t *hwif = HWIF(drive);
93 u8 mode;
94
95 switch(hwif->pci_dev->device) {
96 case PCI_DEVICE_ID_ARTOP_ATP865:
97 case PCI_DEVICE_ID_ARTOP_ATP865R:
98 mode = (inb(hwif->channel ?
99 hwif->mate->dma_status :
100 hwif->dma_status) & 0x10) ? 4 : 3;
101 break;
102 case PCI_DEVICE_ID_ARTOP_ATP860:
103 case PCI_DEVICE_ID_ARTOP_ATP860R:
104 mode = 2;
105 break;
106 case PCI_DEVICE_ID_ARTOP_ATP850UF:
107 default:
108 return 1;
109 }
110
111 if (!eighty_ninty_three(drive))
112 mode = min(mode, (u8)1);
113 return mode;
114}
115
116static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed) 90static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed)
117{ 91{
118 ide_hwif_t *hwif = HWIF(drive); 92 ide_hwif_t *hwif = HWIF(drive);
119 struct pci_dev *dev = hwif->pci_dev; 93 struct pci_dev *dev = hwif->pci_dev;
120 u16 d_conf = 0; 94 u16 d_conf = 0;
121 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); 95 u8 speed = ide_rate_filter(drive, xferspeed);
122 u8 ultra = 0, ultra_conf = 0; 96 u8 ultra = 0, ultra_conf = 0;
123 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0; 97 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
124 unsigned long flags; 98 unsigned long flags;
@@ -145,7 +119,7 @@ static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145{ 119{
146 ide_hwif_t *hwif = HWIF(drive); 120 ide_hwif_t *hwif = HWIF(drive);
147 struct pci_dev *dev = hwif->pci_dev; 121 struct pci_dev *dev = hwif->pci_dev;
148 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); 122 u8 speed = ide_rate_filter(drive, xferspeed);
149 u8 unit = (drive->select.b.unit & 0x01); 123 u8 unit = (drive->select.b.unit & 0x01);
150 u8 tmp1 = 0, tmp2 = 0; 124 u8 tmp1 = 0, tmp2 = 0;
151 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 125 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
@@ -183,7 +157,7 @@ static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed)
183 157
184static int config_chipset_for_dma (ide_drive_t *drive) 158static int config_chipset_for_dma (ide_drive_t *drive)
185{ 159{
186 u8 speed = ide_dma_speed(drive, aec62xx_ratemask(drive)); 160 u8 speed = ide_max_dma_mode(drive);
187 161
188 if (!(speed)) 162 if (!(speed))
189 return 0; 163 return 0;
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 26c27d946c67..76643b626bdd 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -378,74 +378,31 @@ static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio)
378} 378}
379 379
380/** 380/**
381 * ali15x3_can_ultra - check for ultra DMA support 381 * ali_udma_filter - compute UDMA mask
382 * @drive: drive to do the check 382 * @drive: IDE device
383 * 383 *
384 * Check the drive and controller revisions. Return 0 if UDMA is 384 * Return available UDMA modes.
385 * not available, or 1 if UDMA can be used. The actual rules for 385 *
386 * the ALi are 386 * The actual rules for the ALi are:
387 * No UDMA on revisions <= 0x20 387 * No UDMA on revisions <= 0x20
388 * Disk only for revisions < 0xC2 388 * Disk only for revisions < 0xC2
389 * Not WDC drives for revisions < 0xC2 389 * Not WDC drives for revisions < 0xC2
390 * 390 *
391 * FIXME: WDC ifdef needs to die 391 * FIXME: WDC ifdef needs to die
392 */ 392 */
393
394static u8 ali15x3_can_ultra (ide_drive_t *drive)
395{
396#ifndef CONFIG_WDC_ALI15X3
397 struct hd_driveid *id = drive->id;
398#endif /* CONFIG_WDC_ALI15X3 */
399
400 if (m5229_revision <= 0x20) {
401 return 0;
402 } else if ((m5229_revision < 0xC2) &&
403#ifndef CONFIG_WDC_ALI15X3
404 ((chip_is_1543c_e && strstr(id->model, "WDC ")) ||
405 (drive->media!=ide_disk))) {
406#else /* CONFIG_WDC_ALI15X3 */
407 (drive->media!=ide_disk)) {
408#endif /* CONFIG_WDC_ALI15X3 */
409 return 0;
410 } else {
411 return 1;
412 }
413}
414 393
415/** 394static u8 ali_udma_filter(ide_drive_t *drive)
416 * ali15x3_ratemask - generate DMA mode list
417 * @drive: drive to compute against
418 *
419 * Generate a list of the available DMA modes for the drive.
420 * FIXME: this function contains lots of bogus masking we can dump
421 *
422 * Return the highest available mode (UDMA33, UDMA66, UDMA100,..)
423 */
424
425static u8 ali15x3_ratemask (ide_drive_t *drive)
426{ 395{
427 u8 mode = 0, can_ultra = ali15x3_can_ultra(drive); 396 if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
428 397 if (drive->media != ide_disk)
429 if (m5229_revision > 0xC4 && can_ultra) { 398 return 0;
430 mode = 4; 399#ifndef CONFIG_WDC_ALI15X3
431 } else if (m5229_revision == 0xC4 && can_ultra) { 400 if (chip_is_1543c_e && strstr(drive->id->model, "WDC "))
432 mode = 3; 401 return 0;
433 } else if (m5229_revision >= 0xC2 && can_ultra) { 402#endif
434 mode = 2;
435 } else if (can_ultra) {
436 return 1;
437 } else {
438 return 0;
439 } 403 }
440 404
441 /* 405 return drive->hwif->ultra_mask;
442 * If the drive sees no suitable cable then UDMA 33
443 * is the highest permitted mode
444 */
445
446 if (!eighty_ninty_three(drive))
447 mode = min(mode, (u8)1);
448 return mode;
449} 406}
450 407
451/** 408/**
@@ -461,7 +418,7 @@ static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
461{ 418{
462 ide_hwif_t *hwif = HWIF(drive); 419 ide_hwif_t *hwif = HWIF(drive);
463 struct pci_dev *dev = hwif->pci_dev; 420 struct pci_dev *dev = hwif->pci_dev;
464 u8 speed = ide_rate_filter(ali15x3_ratemask(drive), xferspeed); 421 u8 speed = ide_rate_filter(drive, xferspeed);
465 u8 speed1 = speed; 422 u8 speed1 = speed;
466 u8 unit = (drive->select.b.unit & 0x01); 423 u8 unit = (drive->select.b.unit & 0x01);
467 u8 tmpbyte = 0x00; 424 u8 tmpbyte = 0x00;
@@ -511,7 +468,7 @@ static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
511 468
512static int config_chipset_for_dma (ide_drive_t *drive) 469static int config_chipset_for_dma (ide_drive_t *drive)
513{ 470{
514 u8 speed = ide_dma_speed(drive, ali15x3_ratemask(drive)); 471 u8 speed = ide_max_dma_mode(drive);
515 472
516 if (!(speed)) 473 if (!(speed))
517 return 0; 474 return 0;
@@ -771,6 +728,7 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
771 hwif->autodma = 0; 728 hwif->autodma = 0;
772 hwif->tuneproc = &ali15x3_tune_drive; 729 hwif->tuneproc = &ali15x3_tune_drive;
773 hwif->speedproc = &ali15x3_tune_chipset; 730 hwif->speedproc = &ali15x3_tune_chipset;
731 hwif->udma_filter = &ali_udma_filter;
774 732
775 /* don't use LBA48 DMA on ALi devices before rev 0xC5 */ 733 /* don't use LBA48 DMA on ALi devices before rev 0xC5 */
776 hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0; 734 hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0;
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 2d48af32e3f4..f7e80d6076d7 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -49,22 +49,6 @@ static int save_mdma_mode[4];
49static DEFINE_SPINLOCK(atiixp_lock); 49static DEFINE_SPINLOCK(atiixp_lock);
50 50
51/** 51/**
52 * atiixp_ratemask - compute rate mask for ATIIXP IDE
53 * @drive: IDE drive to compute for
54 *
55 * Returns the available modes for the ATIIXP IDE controller.
56 */
57
58static u8 atiixp_ratemask(ide_drive_t *drive)
59{
60 u8 mode = 3;
61
62 if (!eighty_ninty_three(drive))
63 mode = min(mode, (u8)1);
64 return mode;
65}
66
67/**
68 * atiixp_dma_2_pio - return the PIO mode matching DMA 52 * atiixp_dma_2_pio - return the PIO mode matching DMA
69 * @xfer_rate: transfer speed 53 * @xfer_rate: transfer speed
70 * 54 *
@@ -189,7 +173,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
189 u16 tmp16; 173 u16 tmp16;
190 u8 speed, pio; 174 u8 speed, pio;
191 175
192 speed = ide_rate_filter(atiixp_ratemask(drive), xferspeed); 176 speed = ide_rate_filter(drive, xferspeed);
193 177
194 spin_lock_irqsave(&atiixp_lock, flags); 178 spin_lock_irqsave(&atiixp_lock, flags);
195 179
@@ -233,7 +217,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
233 217
234static int atiixp_config_drive_for_dma(ide_drive_t *drive) 218static int atiixp_config_drive_for_dma(ide_drive_t *drive)
235{ 219{
236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive)); 220 u8 speed = ide_max_dma_mode(drive);
237 221
238 if (!speed) 222 if (!speed)
239 return 0; 223 return 0;
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 610c45f7b4e2..19f5ac1f866c 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -292,55 +292,6 @@ static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio)
292 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 292 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
293} 293}
294 294
295static u8 cmd64x_ratemask (ide_drive_t *drive)
296{
297 struct pci_dev *dev = HWIF(drive)->pci_dev;
298 u8 mode = 0;
299
300 switch(dev->device) {
301 case PCI_DEVICE_ID_CMD_649:
302 mode = 3;
303 break;
304 case PCI_DEVICE_ID_CMD_648:
305 mode = 2;
306 break;
307 case PCI_DEVICE_ID_CMD_643:
308 return 0;
309
310 case PCI_DEVICE_ID_CMD_646:
311 {
312 unsigned int class_rev = 0;
313 pci_read_config_dword(dev,
314 PCI_CLASS_REVISION, &class_rev);
315 class_rev &= 0xff;
316 /*
317 * UltraDMA only supported on PCI646U and PCI646U2, which
318 * correspond to revisions 0x03, 0x05 and 0x07 respectively.
319 * Actually, although the CMD tech support people won't
320 * tell me the details, the 0x03 revision cannot support
321 * UDMA correctly without hardware modifications, and even
322 * then it only works with Quantum disks due to some
323 * hold time assumptions in the 646U part which are fixed
324 * in the 646U2.
325 *
326 * So we only do UltraDMA on revision 0x05 and 0x07 chipsets.
327 */
328 switch(class_rev) {
329 case 0x07:
330 case 0x05:
331 return 1;
332 case 0x03:
333 case 0x01:
334 default:
335 return 0;
336 }
337 }
338 }
339 if (!eighty_ninty_three(drive))
340 mode = min(mode, (u8)1);
341 return mode;
342}
343
344static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed) 295static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
345{ 296{
346 ide_hwif_t *hwif = HWIF(drive); 297 ide_hwif_t *hwif = HWIF(drive);
@@ -348,7 +299,7 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
348 u8 unit = drive->dn & 0x01; 299 u8 unit = drive->dn & 0x01;
349 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; 300 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0;
350 301
351 speed = ide_rate_filter(cmd64x_ratemask(drive), speed); 302 speed = ide_rate_filter(drive, speed);
352 303
353 if (speed >= XFER_SW_DMA_0) { 304 if (speed >= XFER_SW_DMA_0) {
354 (void) pci_read_config_byte(dev, pciU, &regU); 305 (void) pci_read_config_byte(dev, pciU, &regU);
@@ -403,7 +354,7 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
403 354
404static int config_chipset_for_dma (ide_drive_t *drive) 355static int config_chipset_for_dma (ide_drive_t *drive)
405{ 356{
406 u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive)); 357 u8 speed = ide_max_dma_mode(drive);
407 358
408 if (!speed) 359 if (!speed)
409 return 0; 360 return 0;
@@ -646,6 +597,18 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
646 597
647 hwif->ultra_mask = hwif->cds->udma_mask; 598 hwif->ultra_mask = hwif->cds->udma_mask;
648 599
600 /*
601 * UltraDMA only supported on PCI646U and PCI646U2, which
602 * correspond to revisions 0x03, 0x05 and 0x07 respectively.
603 * Actually, although the CMD tech support people won't
604 * tell me the details, the 0x03 revision cannot support
605 * UDMA correctly without hardware modifications, and even
606 * then it only works with Quantum disks due to some
607 * hold time assumptions in the 646U part which are fixed
608 * in the 646U2.
609 *
610 * So we only do UltraDMA on revision 0x05 and 0x07 chipsets.
611 */
649 if (dev->device == PCI_DEVICE_ID_CMD_646 && class_rev < 5) 612 if (dev->device == PCI_DEVICE_ID_CMD_646 && class_rev < 5)
650 hwif->ultra_mask = 0x00; 613 hwif->ultra_mask = 0x00;
651 614
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 45f43efbf92c..66a101e470d0 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -127,20 +127,6 @@ static void cs5535_set_speed(ide_drive_t *drive, u8 speed)
127 } 127 }
128} 128}
129 129
130static u8 cs5535_ratemask(ide_drive_t *drive)
131{
132 /* eighty93 will return 1 if it's 80core and capable of
133 exceeding udma2, 0 otherwise. we need ratemask to set
134 the max speed and if we can > udma2 then we return 2
135 which selects speed_max as udma4 which is the 5535's max
136 speed, and 1 selects udma2 which is the max for 40c */
137 if (!eighty_ninty_three(drive))
138 return 1;
139
140 return 2;
141}
142
143
144/**** 130/****
145 * cs5535_set_drive - Configure the drive to the new speed 131 * cs5535_set_drive - Configure the drive to the new speed
146 * @drive: Drive to set up 132 * @drive: Drive to set up
@@ -151,7 +137,7 @@ static u8 cs5535_ratemask(ide_drive_t *drive)
151 */ 137 */
152static int cs5535_set_drive(ide_drive_t *drive, u8 speed) 138static int cs5535_set_drive(ide_drive_t *drive, u8 speed)
153{ 139{
154 speed = ide_rate_filter(cs5535_ratemask(drive), speed); 140 speed = ide_rate_filter(drive, speed);
155 ide_config_drive_speed(drive, speed); 141 ide_config_drive_speed(drive, speed);
156 cs5535_set_speed(drive, speed); 142 cs5535_set_speed(drive, speed);
157 143
@@ -180,9 +166,7 @@ static void cs5535_tuneproc(ide_drive_t *drive, u8 xferspeed)
180 166
181static int cs5535_config_drive_for_dma(ide_drive_t *drive) 167static int cs5535_config_drive_for_dma(ide_drive_t *drive)
182{ 168{
183 u8 speed; 169 u8 speed = ide_max_dma_mode(drive);
184
185 speed = ide_dma_speed(drive, cs5535_ratemask(drive));
186 170
187 /* If no DMA speed was available then let dma_check hit pio */ 171 /* If no DMA speed was available then let dma_check hit pio */
188 if (!speed) { 172 if (!speed) {
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 924eaa3a5708..473e1b33dbf7 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -43,15 +43,10 @@
43 43
44#define HPT343_DEBUG_DRIVE_INFO 0 44#define HPT343_DEBUG_DRIVE_INFO 0
45 45
46static u8 hpt34x_ratemask (ide_drive_t *drive)
47{
48 return 1;
49}
50
51static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) 46static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
52{ 47{
53 struct pci_dev *dev = HWIF(drive)->pci_dev; 48 struct pci_dev *dev = HWIF(drive)->pci_dev;
54 u8 speed = ide_rate_filter(hpt34x_ratemask(drive), xferspeed); 49 u8 speed = ide_rate_filter(drive, xferspeed);
55 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0; 50 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
56 u8 hi_speed, lo_speed; 51 u8 hi_speed, lo_speed;
57 52
@@ -98,7 +93,7 @@ static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
98 93
99static int config_chipset_for_dma (ide_drive_t *drive) 94static int config_chipset_for_dma (ide_drive_t *drive)
100{ 95{
101 u8 speed = ide_dma_speed(drive, hpt34x_ratemask(drive)); 96 u8 speed = ide_max_dma_mode(drive);
102 97
103 if (!(speed)) 98 if (!(speed))
104 return 0; 99 return 0;
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index cf9d344d19f8..de5ad9c35dc6 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -514,43 +514,31 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)
514 return 0; 514 return 0;
515} 515}
516 516
517static u8 hpt3xx_ratemask(ide_drive_t *drive)
518{
519 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
520 u8 mode = info->max_mode;
521
522 if (!eighty_ninty_three(drive) && mode)
523 mode = min(mode, (u8)1);
524 return mode;
525}
526
527/* 517/*
528 * Note for the future; the SATA hpt37x we must set 518 * Note for the future; the SATA hpt37x we must set
529 * either PIO or UDMA modes 0,4,5 519 * either PIO or UDMA modes 0,4,5
530 */ 520 */
531 521
532static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) 522static u8 hpt3xx_udma_filter(ide_drive_t *drive)
533{ 523{
534 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev); 524 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
535 u8 chip_type = info->chip_type; 525 u8 chip_type = info->chip_type;
536 u8 mode = hpt3xx_ratemask(drive); 526 u8 mode = info->max_mode;
537 527 u8 mask;
538 if (drive->media != ide_disk)
539 return min(speed, (u8)XFER_PIO_4);
540 528
541 switch (mode) { 529 switch (mode) {
542 case 0x04: 530 case 0x04:
543 speed = min_t(u8, speed, XFER_UDMA_6); 531 mask = 0x7f;
544 break; 532 break;
545 case 0x03: 533 case 0x03:
546 speed = min_t(u8, speed, XFER_UDMA_5); 534 mask = 0x3f;
547 if (chip_type >= HPT374) 535 if (chip_type >= HPT374)
548 break; 536 break;
549 if (!check_in_drive_list(drive, bad_ata100_5)) 537 if (!check_in_drive_list(drive, bad_ata100_5))
550 goto check_bad_ata33; 538 goto check_bad_ata33;
551 /* fall thru */ 539 /* fall thru */
552 case 0x02: 540 case 0x02:
553 speed = min_t(u8, speed, XFER_UDMA_4); 541 mask = 0x1f;
554 542
555 /* 543 /*
556 * CHECK ME, Does this need to be changed to HPT374 ?? 544 * CHECK ME, Does this need to be changed to HPT374 ??
@@ -561,13 +549,13 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed)
561 !check_in_drive_list(drive, bad_ata66_4)) 549 !check_in_drive_list(drive, bad_ata66_4))
562 goto check_bad_ata33; 550 goto check_bad_ata33;
563 551
564 speed = min_t(u8, speed, XFER_UDMA_3); 552 mask = 0x0f;
565 if (HPT366_ALLOW_ATA66_3 && 553 if (HPT366_ALLOW_ATA66_3 &&
566 !check_in_drive_list(drive, bad_ata66_3)) 554 !check_in_drive_list(drive, bad_ata66_3))
567 goto check_bad_ata33; 555 goto check_bad_ata33;
568 /* fall thru */ 556 /* fall thru */
569 case 0x01: 557 case 0x01:
570 speed = min_t(u8, speed, XFER_UDMA_2); 558 mask = 0x07;
571 559
572 check_bad_ata33: 560 check_bad_ata33:
573 if (chip_type >= HPT370A) 561 if (chip_type >= HPT370A)
@@ -577,10 +565,10 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed)
577 /* fall thru */ 565 /* fall thru */
578 case 0x00: 566 case 0x00:
579 default: 567 default:
580 speed = min_t(u8, speed, XFER_MW_DMA_2); 568 mask = 0x00;
581 break; 569 break;
582 } 570 }
583 return speed; 571 return mask;
584} 572}
585 573
586static u32 get_speed_setting(u8 speed, struct hpt_info *info) 574static u32 get_speed_setting(u8 speed, struct hpt_info *info)
@@ -608,12 +596,19 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
608 ide_hwif_t *hwif = HWIF(drive); 596 ide_hwif_t *hwif = HWIF(drive);
609 struct pci_dev *dev = hwif->pci_dev; 597 struct pci_dev *dev = hwif->pci_dev;
610 struct hpt_info *info = pci_get_drvdata(dev); 598 struct hpt_info *info = pci_get_drvdata(dev);
611 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 599 u8 speed = ide_rate_filter(drive, xferspeed);
612 u8 itr_addr = drive->dn ? 0x44 : 0x40; 600 u8 itr_addr = drive->dn ? 0x44 : 0x40;
613 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
614 (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
615 u32 new_itr = get_speed_setting(speed, info);
616 u32 old_itr = 0; 601 u32 old_itr = 0;
602 u32 itr_mask, new_itr;
603
604 /* TODO: move this to ide_rate_filter() [ check ->atapi_dma ] */
605 if (drive->media != ide_disk)
606 speed = min_t(u8, speed, XFER_PIO_4);
607
608 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
609 (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
610
611 new_itr = get_speed_setting(speed, info);
617 612
618 /* 613 /*
619 * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well) 614 * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well)
@@ -633,12 +628,19 @@ static int hpt37x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
633 ide_hwif_t *hwif = HWIF(drive); 628 ide_hwif_t *hwif = HWIF(drive);
634 struct pci_dev *dev = hwif->pci_dev; 629 struct pci_dev *dev = hwif->pci_dev;
635 struct hpt_info *info = pci_get_drvdata(dev); 630 struct hpt_info *info = pci_get_drvdata(dev);
636 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 631 u8 speed = ide_rate_filter(drive, xferspeed);
637 u8 itr_addr = 0x40 + (drive->dn * 4); 632 u8 itr_addr = 0x40 + (drive->dn * 4);
638 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
639 (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
640 u32 new_itr = get_speed_setting(speed, info);
641 u32 old_itr = 0; 633 u32 old_itr = 0;
634 u32 itr_mask, new_itr;
635
636 /* TODO: move this to ide_rate_filter() [ check ->atapi_dma ] */
637 if (drive->media != ide_disk)
638 speed = min_t(u8, speed, XFER_PIO_4);
639
640 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
641 (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
642
643 new_itr = get_speed_setting(speed, info);
642 644
643 pci_read_config_dword(dev, itr_addr, &old_itr); 645 pci_read_config_dword(dev, itr_addr, &old_itr);
644 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask); 646 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
@@ -676,7 +678,7 @@ static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
676 */ 678 */
677static int config_chipset_for_dma(ide_drive_t *drive) 679static int config_chipset_for_dma(ide_drive_t *drive)
678{ 680{
679 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); 681 u8 speed = ide_max_dma_mode(drive);
680 682
681 if (!speed) 683 if (!speed)
682 return 0; 684 return 0;
@@ -1271,6 +1273,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1271 hwif->intrproc = &hpt3xx_intrproc; 1273 hwif->intrproc = &hpt3xx_intrproc;
1272 hwif->maskproc = &hpt3xx_maskproc; 1274 hwif->maskproc = &hpt3xx_maskproc;
1273 hwif->busproc = &hpt3xx_busproc; 1275 hwif->busproc = &hpt3xx_busproc;
1276 hwif->udma_filter = &hpt3xx_udma_filter;
1274 1277
1275 /* 1278 /*
1276 * HPT3xxN chips have some complications: 1279 * HPT3xxN chips have some complications:
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 424f00bb160d..02b56cb7bb1b 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -17,22 +17,6 @@
17 17
18#include <asm/io.h> 18#include <asm/io.h>
19 19
20/*
21 * it8213_ratemask - Compute available modes
22 * @drive: IDE drive
23 *
24 * Compute the available speeds for the devices on the interface. This
25 * is all modes to ATA133 clipped by drive cable setup.
26 */
27
28static u8 it8213_ratemask (ide_drive_t *drive)
29{
30 u8 mode = 4;
31 if (!eighty_ninty_three(drive))
32 mode = min_t(u8, mode, 1);
33 return mode;
34}
35
36/** 20/**
37 * it8213_dma_2_pio - return the PIO mode matching DMA 21 * it8213_dma_2_pio - return the PIO mode matching DMA
38 * @xfer_rate: transfer speed 22 * @xfer_rate: transfer speed
@@ -145,7 +129,7 @@ static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145 ide_hwif_t *hwif = HWIF(drive); 129 ide_hwif_t *hwif = HWIF(drive);
146 struct pci_dev *dev = hwif->pci_dev; 130 struct pci_dev *dev = hwif->pci_dev;
147 u8 maslave = 0x40; 131 u8 maslave = 0x40;
148 u8 speed = ide_rate_filter(it8213_ratemask(drive), xferspeed); 132 u8 speed = ide_rate_filter(drive, xferspeed);
149 int a_speed = 3 << (drive->dn * 4); 133 int a_speed = 3 << (drive->dn * 4);
150 int u_flag = 1 << drive->dn; 134 int u_flag = 1 << drive->dn;
151 int v_flag = 0x01 << drive->dn; 135 int v_flag = 0x01 << drive->dn;
@@ -222,7 +206,7 @@ static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
222 206
223static int config_chipset_for_dma (ide_drive_t *drive) 207static int config_chipset_for_dma (ide_drive_t *drive)
224{ 208{
225 u8 speed = ide_dma_speed(drive, it8213_ratemask(drive)); 209 u8 speed = ide_max_dma_mode(drive);
226 210
227 if (!speed) 211 if (!speed)
228 return 0; 212 return 0;
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 4e1254813ee0..442f658c6ae7 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -229,22 +229,6 @@ static void it821x_clock_strategy(ide_drive_t *drive)
229} 229}
230 230
231/** 231/**
232 * it821x_ratemask - Compute available modes
233 * @drive: IDE drive
234 *
235 * Compute the available speeds for the devices on the interface. This
236 * is all modes to ATA133 clipped by drive cable setup.
237 */
238
239static u8 it821x_ratemask (ide_drive_t *drive)
240{
241 u8 mode = 4;
242 if (!eighty_ninty_three(drive))
243 mode = min(mode, (u8)1);
244 return mode;
245}
246
247/**
248 * it821x_tunepio - tune a drive 232 * it821x_tunepio - tune a drive
249 * @drive: drive to tune 233 * @drive: drive to tune
250 * @pio: the desired PIO mode 234 * @pio: the desired PIO mode
@@ -438,7 +422,7 @@ static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
438 422
439 ide_hwif_t *hwif = drive->hwif; 423 ide_hwif_t *hwif = drive->hwif;
440 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 424 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
441 u8 speed = ide_rate_filter(it821x_ratemask(drive), xferspeed); 425 u8 speed = ide_rate_filter(drive, xferspeed);
442 426
443 switch (speed) { 427 switch (speed) {
444 case XFER_PIO_4: 428 case XFER_PIO_4:
@@ -488,7 +472,7 @@ static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
488 472
489static int config_chipset_for_dma (ide_drive_t *drive) 473static int config_chipset_for_dma (ide_drive_t *drive)
490{ 474{
491 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive)); 475 u8 speed = ide_max_dma_mode(drive);
492 476
493 if (speed == 0) 477 if (speed == 0)
494 return 0; 478 return 0;
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index be4fc96c29e0..dbb3c199cba9 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -22,22 +22,6 @@ typedef enum {
22} port_type; 22} port_type;
23 23
24/** 24/**
25 * jmicron_ratemask - Compute available modes
26 * @drive: IDE drive
27 *
28 * Compute the available speeds for the devices on the interface. This
29 * is all modes to ATA133 clipped by drive cable setup.
30 */
31
32static u8 jmicron_ratemask(ide_drive_t *drive)
33{
34 u8 mode = 4;
35 if (!eighty_ninty_three(drive))
36 mode = min(mode, (u8)1);
37 return mode;
38}
39
40/**
41 * ata66_jmicron - Cable check 25 * ata66_jmicron - Cable check
42 * @hwif: IDE port 26 * @hwif: IDE port
43 * 27 *
@@ -129,8 +113,7 @@ static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
129 113
130static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed) 114static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
131{ 115{
132 116 u8 speed = ide_rate_filter(drive, xferspeed);
133 u8 speed = ide_rate_filter(jmicron_ratemask(drive), xferspeed);
134 117
135 return ide_config_drive_speed(drive, speed); 118 return ide_config_drive_speed(drive, speed);
136} 119}
@@ -145,7 +128,7 @@ static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
145 128
146static int config_chipset_for_dma (ide_drive_t *drive) 129static int config_chipset_for_dma (ide_drive_t *drive)
147{ 130{
148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive)); 131 u8 speed = ide_max_dma_mode(drive);
149 132
150 if (!speed) 133 if (!speed)
151 return 0; 134 return 0;
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index a23853445af9..772ca4007de4 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -82,16 +82,6 @@ static u8 max_dma_rate(struct pci_dev *pdev)
82 return mode; 82 return mode;
83} 83}
84 84
85static u8 pdcnew_ratemask(ide_drive_t *drive)
86{
87 u8 mode = max_dma_rate(HWIF(drive)->pci_dev);
88
89 if (!eighty_ninty_three(drive))
90 mode = min_t(u8, mode, 1);
91
92 return mode;
93}
94
95/** 85/**
96 * get_indexed_reg - Get indexed register 86 * get_indexed_reg - Get indexed register
97 * @hwif: for the port address 87 * @hwif: for the port address
@@ -164,7 +154,7 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
164 u8 adj = (drive->dn & 1) ? 0x08 : 0x00; 154 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
165 int err; 155 int err;
166 156
167 speed = ide_rate_filter(pdcnew_ratemask(drive), speed); 157 speed = ide_rate_filter(drive, speed);
168 158
169 /* 159 /*
170 * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will 160 * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will
@@ -267,7 +257,7 @@ static int config_chipset_for_dma(ide_drive_t *drive)
267 set_indexed_reg(hwif, 0x13 + adj, tmp | 0x03); 257 set_indexed_reg(hwif, 0x13 + adj, tmp | 0x03);
268 } 258 }
269 259
270 speed = ide_dma_speed(drive, pdcnew_ratemask(drive)); 260 speed = ide_max_dma_mode(drive);
271 261
272 if (!speed) 262 if (!speed)
273 return 0; 263 return 0;
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index d7a38067fb34..207a6191fac7 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -101,35 +101,12 @@ static const char *pdc_quirk_drives[] = {
101#define MC1 0x02 /* DMA"C" timing */ 101#define MC1 0x02 /* DMA"C" timing */
102#define MC0 0x01 /* DMA"C" timing */ 102#define MC0 0x01 /* DMA"C" timing */
103 103
104static u8 pdc202xx_ratemask (ide_drive_t *drive)
105{
106 u8 mode;
107
108 switch(HWIF(drive)->pci_dev->device) {
109 case PCI_DEVICE_ID_PROMISE_20267:
110 case PCI_DEVICE_ID_PROMISE_20265:
111 mode = 3;
112 break;
113 case PCI_DEVICE_ID_PROMISE_20263:
114 case PCI_DEVICE_ID_PROMISE_20262:
115 mode = 2;
116 break;
117 case PCI_DEVICE_ID_PROMISE_20246:
118 return 1;
119 default:
120 return 0;
121 }
122 if (!eighty_ninty_three(drive))
123 mode = min(mode, (u8)1);
124 return mode;
125}
126
127static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed) 104static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
128{ 105{
129 ide_hwif_t *hwif = HWIF(drive); 106 ide_hwif_t *hwif = HWIF(drive);
130 struct pci_dev *dev = hwif->pci_dev; 107 struct pci_dev *dev = hwif->pci_dev;
131 u8 drive_pci = 0x60 + (drive->dn << 2); 108 u8 drive_pci = 0x60 + (drive->dn << 2);
132 u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed); 109 u8 speed = ide_rate_filter(drive, xferspeed);
133 110
134 u32 drive_conf; 111 u32 drive_conf;
135 u8 AP, BP, CP, DP; 112 u8 AP, BP, CP, DP;
@@ -308,7 +285,7 @@ chipset_is_set:
308 if (drive->media == ide_disk) /* PREFETCH_EN */ 285 if (drive->media == ide_disk) /* PREFETCH_EN */
309 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN); 286 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
310 287
311 speed = ide_dma_speed(drive, pdc202xx_ratemask(drive)); 288 speed = ide_max_dma_mode(drive);
312 289
313 if (!(speed)) { 290 if (!(speed)) {
314 /* restore original pci-config space */ 291 /* restore original pci-config space */
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 17ea44edb4eb..84d3938a430a 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -106,68 +106,6 @@
106static int no_piix_dma; 106static int no_piix_dma;
107 107
108/** 108/**
109 * piix_ratemask - compute rate mask for PIIX IDE
110 * @drive: IDE drive to compute for
111 *
112 * Returns the available modes for the PIIX IDE controller.
113 */
114
115static u8 piix_ratemask (ide_drive_t *drive)
116{
117 struct pci_dev *dev = HWIF(drive)->pci_dev;
118 u8 mode;
119
120 switch(dev->device) {
121 case PCI_DEVICE_ID_INTEL_82801EB_1:
122 mode = 3;
123 break;
124 /* UDMA 100 capable */
125 case PCI_DEVICE_ID_INTEL_82801BA_8:
126 case PCI_DEVICE_ID_INTEL_82801BA_9:
127 case PCI_DEVICE_ID_INTEL_82801CA_10:
128 case PCI_DEVICE_ID_INTEL_82801CA_11:
129 case PCI_DEVICE_ID_INTEL_82801E_11:
130 case PCI_DEVICE_ID_INTEL_82801DB_1:
131 case PCI_DEVICE_ID_INTEL_82801DB_10:
132 case PCI_DEVICE_ID_INTEL_82801DB_11:
133 case PCI_DEVICE_ID_INTEL_82801EB_11:
134 case PCI_DEVICE_ID_INTEL_ESB_2:
135 case PCI_DEVICE_ID_INTEL_ICH6_19:
136 case PCI_DEVICE_ID_INTEL_ICH7_21:
137 case PCI_DEVICE_ID_INTEL_ESB2_18:
138 case PCI_DEVICE_ID_INTEL_ICH8_6:
139 mode = 3;
140 break;
141 /* UDMA 66 capable */
142 case PCI_DEVICE_ID_INTEL_82801AA_1:
143 case PCI_DEVICE_ID_INTEL_82372FB_1:
144 mode = 2;
145 break;
146 /* UDMA 33 capable */
147 case PCI_DEVICE_ID_INTEL_82371AB:
148 case PCI_DEVICE_ID_INTEL_82443MX_1:
149 case PCI_DEVICE_ID_INTEL_82451NX:
150 case PCI_DEVICE_ID_INTEL_82801AB_1:
151 return 1;
152 /* Non UDMA capable (MWDMA2) */
153 case PCI_DEVICE_ID_INTEL_82371SB_1:
154 case PCI_DEVICE_ID_INTEL_82371FB_1:
155 case PCI_DEVICE_ID_INTEL_82371FB_0:
156 case PCI_DEVICE_ID_INTEL_82371MX:
157 default:
158 return 0;
159 }
160
161 /*
162 * If we are UDMA66 capable fall back to UDMA33
163 * if the drive cannot see an 80pin cable.
164 */
165 if (!eighty_ninty_three(drive))
166 mode = min_t(u8, mode, 1);
167 return mode;
168}
169
170/**
171 * piix_dma_2_pio - return the PIO mode matching DMA 109 * piix_dma_2_pio - return the PIO mode matching DMA
172 * @xfer_rate: transfer speed 110 * @xfer_rate: transfer speed
173 * 111 *
@@ -301,7 +239,7 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
301 ide_hwif_t *hwif = HWIF(drive); 239 ide_hwif_t *hwif = HWIF(drive);
302 struct pci_dev *dev = hwif->pci_dev; 240 struct pci_dev *dev = hwif->pci_dev;
303 u8 maslave = hwif->channel ? 0x42 : 0x40; 241 u8 maslave = hwif->channel ? 0x42 : 0x40;
304 u8 speed = ide_rate_filter(piix_ratemask(drive), xferspeed); 242 u8 speed = ide_rate_filter(drive, xferspeed);
305 int a_speed = 3 << (drive->dn * 4); 243 int a_speed = 3 << (drive->dn * 4);
306 int u_flag = 1 << drive->dn; 244 int u_flag = 1 << drive->dn;
307 int v_flag = 0x01 << drive->dn; 245 int v_flag = 0x01 << drive->dn;
@@ -376,7 +314,7 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
376 314
377static int piix_config_drive_for_dma (ide_drive_t *drive) 315static int piix_config_drive_for_dma (ide_drive_t *drive)
378{ 316{
379 u8 speed = ide_dma_speed(drive, piix_ratemask(drive)); 317 u8 speed = ide_max_dma_mode(drive);
380 318
381 /* 319 /*
382 * If no DMA speed was available or the chipset has DMA bugs 320 * If no DMA speed was available or the chipset has DMA bugs
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index f84bf791f72e..cbf936325355 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -190,23 +190,6 @@ scc_ide_outsl(unsigned long port, void *addr, u32 count)
190} 190}
191 191
192/** 192/**
193 * scc_ratemask - Compute available modes
194 * @drive: IDE drive
195 *
196 * Compute the available speeds for the devices on the interface.
197 * Enforce UDMA33 as a limit if there is no 80pin cable present.
198 */
199
200static u8 scc_ratemask(ide_drive_t *drive)
201{
202 u8 mode = 4;
203
204 if (!eighty_ninty_three(drive))
205 mode = min(mode, (u8)1);
206 return mode;
207}
208
209/**
210 * scc_tuneproc - tune a drive PIO mode 193 * scc_tuneproc - tune a drive PIO mode
211 * @drive: drive to tune 194 * @drive: drive to tune
212 * @mode_wanted: the target operating mode 195 * @mode_wanted: the target operating mode
@@ -273,7 +256,7 @@ static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
273static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed) 256static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
274{ 257{
275 ide_hwif_t *hwif = HWIF(drive); 258 ide_hwif_t *hwif = HWIF(drive);
276 u8 speed = ide_rate_filter(scc_ratemask(drive), xferspeed); 259 u8 speed = ide_rate_filter(drive, xferspeed);
277 struct scc_ports *ports = ide_get_hwifdata(hwif); 260 struct scc_ports *ports = ide_get_hwifdata(hwif);
278 unsigned long ctl_base = ports->ctl; 261 unsigned long ctl_base = ports->ctl;
279 unsigned long cckctrl_port = ctl_base + 0xff0; 262 unsigned long cckctrl_port = ctl_base + 0xff0;
@@ -347,7 +330,7 @@ static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
347 330
348static int scc_config_chipset_for_dma(ide_drive_t *drive) 331static int scc_config_chipset_for_dma(ide_drive_t *drive)
349{ 332{
350 u8 speed = ide_dma_speed(drive, scc_ratemask(drive)); 333 u8 speed = ide_max_dma_mode(drive);
351 334
352 if (!speed) 335 if (!speed)
353 return 0; 336 return 0;
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index dbcd37a0c652..2fa6d92d16cc 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -65,16 +65,16 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list)
65 return 0; 65 return 0;
66} 66}
67 67
68static u8 svwks_ratemask (ide_drive_t *drive) 68static u8 svwks_udma_filter(ide_drive_t *drive)
69{ 69{
70 struct pci_dev *dev = HWIF(drive)->pci_dev; 70 struct pci_dev *dev = HWIF(drive)->pci_dev;
71 u8 mode = 0; 71 u8 mask = 0;
72 72
73 if (!svwks_revision) 73 if (!svwks_revision)
74 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision); 74 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
75 75
76 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) 76 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
77 return 2; 77 return 0x1f;
78 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 78 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
79 u32 reg = 0; 79 u32 reg = 0;
80 if (isa_dev) 80 if (isa_dev)
@@ -86,25 +86,31 @@ static u8 svwks_ratemask (ide_drive_t *drive)
86 if(drive->media == ide_disk) 86 if(drive->media == ide_disk)
87 return 0; 87 return 0;
88 /* Check the OSB4 DMA33 enable bit */ 88 /* Check the OSB4 DMA33 enable bit */
89 return ((reg & 0x00004000) == 0x00004000) ? 1 : 0; 89 return ((reg & 0x00004000) == 0x00004000) ? 0x07 : 0;
90 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) { 90 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
91 return 1; 91 return 0x07;
92 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) { 92 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
93 u8 btr = 0; 93 u8 btr = 0, mode;
94 pci_read_config_byte(dev, 0x5A, &btr); 94 pci_read_config_byte(dev, 0x5A, &btr);
95 mode = btr & 0x3; 95 mode = btr & 0x3;
96 if (!eighty_ninty_three(drive)) 96
97 mode = min(mode, (u8)1);
98 /* If someone decides to do UDMA133 on CSB5 the same 97 /* If someone decides to do UDMA133 on CSB5 the same
99 issue will bite so be inclusive */ 98 issue will bite so be inclusive */
100 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100)) 99 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
101 mode = 2; 100 mode = 2;
101
102 switch(mode) {
103 case 2: mask = 0x1f; break;
104 case 1: mask = 0x07; break;
105 default: mask = 0x00; break;
106 }
102 } 107 }
103 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 108 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
104 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) && 109 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
105 (!(PCI_FUNC(dev->devfn) & 1))) 110 (!(PCI_FUNC(dev->devfn) & 1)))
106 mode = 2; 111 mask = 0x1f;
107 return mode; 112
113 return mask;
108} 114}
109 115
110static u8 svwks_csb_check (struct pci_dev *dev) 116static u8 svwks_csb_check (struct pci_dev *dev)
@@ -141,7 +147,7 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
141 if (xferspeed == 255) /* PIO auto-tuning */ 147 if (xferspeed == 255) /* PIO auto-tuning */
142 speed = XFER_PIO_0 + pio; 148 speed = XFER_PIO_0 + pio;
143 else 149 else
144 speed = ide_rate_filter(svwks_ratemask(drive), xferspeed); 150 speed = ide_rate_filter(drive, xferspeed);
145 151
146 /* If we are about to put a disk into UDMA mode we screwed up. 152 /* If we are about to put a disk into UDMA mode we screwed up.
147 Our code assumes we never _ever_ do this on an OSB4 */ 153 Our code assumes we never _ever_ do this on an OSB4 */
@@ -304,7 +310,7 @@ static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
304 310
305static int config_chipset_for_dma (ide_drive_t *drive) 311static int config_chipset_for_dma (ide_drive_t *drive)
306{ 312{
307 u8 speed = ide_dma_speed(drive, svwks_ratemask(drive)); 313 u8 speed = ide_max_dma_mode(drive);
308 314
309 if (!(speed)) 315 if (!(speed))
310 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL); 316 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
@@ -500,6 +506,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
500 506
501 hwif->tuneproc = &svwks_tune_drive; 507 hwif->tuneproc = &svwks_tune_drive;
502 hwif->speedproc = &svwks_tune_chipset; 508 hwif->speedproc = &svwks_tune_chipset;
509 hwif->udma_filter = &svwks_udma_filter;
503 510
504 hwif->atapi_dma = 1; 511 hwif->atapi_dma = 1;
505 512
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index c0188de3cc66..5314ec913724 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -122,45 +122,41 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
122} 122}
123 123
124/** 124/**
125 * siimage_ratemask - Compute available modes 125 * sil_udma_filter - compute UDMA mask
126 * @drive: IDE drive 126 * @drive: IDE device
127 *
128 * Compute the available UDMA speeds for the device on the interface.
127 * 129 *
128 * Compute the available speeds for the devices on the interface.
129 * For the CMD680 this depends on the clocking mode (scsc), for the 130 * For the CMD680 this depends on the clocking mode (scsc), for the
130 * SI3312 SATA controller life is a bit simpler. Enforce UDMA33 131 * SI3112 SATA controller life is a bit simpler.
131 * as a limit if there is no 80pin cable present.
132 */ 132 */
133 133
134static byte siimage_ratemask (ide_drive_t *drive) 134static u8 sil_udma_filter(ide_drive_t *drive)
135{ 135{
136 ide_hwif_t *hwif = HWIF(drive); 136 ide_hwif_t *hwif = drive->hwif;
137 u8 mode = 0, scsc = 0;
138 unsigned long base = (unsigned long) hwif->hwif_data; 137 unsigned long base = (unsigned long) hwif->hwif_data;
138 u8 mask = 0, scsc = 0;
139 139
140 if (hwif->mmio) 140 if (hwif->mmio)
141 scsc = hwif->INB(base + 0x4A); 141 scsc = hwif->INB(base + 0x4A);
142 else 142 else
143 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); 143 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc);
144 144
145 if(is_sata(hwif)) 145 if (is_sata(hwif)) {
146 { 146 mask = strstr(drive->id->model, "Maxtor") ? 0x3f : 0x7f;
147 if(strstr(drive->id->model, "Maxtor")) 147 goto out;
148 return 3;
149 return 4;
150 } 148 }
151 149
152 if ((scsc & 0x30) == 0x10) /* 133 */ 150 if ((scsc & 0x30) == 0x10) /* 133 */
153 mode = 4; 151 mask = 0x7f;
154 else if ((scsc & 0x30) == 0x20) /* 2xPCI */ 152 else if ((scsc & 0x30) == 0x20) /* 2xPCI */
155 mode = 4; 153 mask = 0x7f;
156 else if ((scsc & 0x30) == 0x00) /* 100 */ 154 else if ((scsc & 0x30) == 0x00) /* 100 */
157 mode = 3; 155 mask = 0x3f;
158 else /* Disabled ? */ 156 else /* Disabled ? */
159 BUG(); 157 BUG();
160 158out:
161 if (!eighty_ninty_three(drive)) 159 return mask;
162 mode = min(mode, (u8)1);
163 return mode;
164} 160}
165 161
166/** 162/**
@@ -306,7 +302,7 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
306 ide_hwif_t *hwif = HWIF(drive); 302 ide_hwif_t *hwif = HWIF(drive);
307 u16 ultra = 0, multi = 0; 303 u16 ultra = 0, multi = 0;
308 u8 mode = 0, unit = drive->select.b.unit; 304 u8 mode = 0, unit = drive->select.b.unit;
309 u8 speed = ide_rate_filter(siimage_ratemask(drive), xferspeed); 305 u8 speed = ide_rate_filter(drive, xferspeed);
310 unsigned long base = (unsigned long)hwif->hwif_data; 306 unsigned long base = (unsigned long)hwif->hwif_data;
311 u8 scsc = 0, addr_mask = ((hwif->channel) ? 307 u8 scsc = 0, addr_mask = ((hwif->channel) ?
312 ((hwif->mmio) ? 0xF4 : 0x84) : 308 ((hwif->mmio) ? 0xF4 : 0x84) :
@@ -389,7 +385,7 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
389 385
390static int config_chipset_for_dma (ide_drive_t *drive) 386static int config_chipset_for_dma (ide_drive_t *drive)
391{ 387{
392 u8 speed = ide_dma_speed(drive, siimage_ratemask(drive)); 388 u8 speed = ide_max_dma_mode(drive);
393 389
394 if (!speed) 390 if (!speed)
395 return 0; 391 return 0;
@@ -989,6 +985,7 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
989 hwif->tuneproc = &siimage_tuneproc; 985 hwif->tuneproc = &siimage_tuneproc;
990 hwif->reset_poll = &siimage_reset_poll; 986 hwif->reset_poll = &siimage_reset_poll;
991 hwif->pre_reset = &siimage_pre_reset; 987 hwif->pre_reset = &siimage_pre_reset;
988 hwif->udma_filter = &sil_udma_filter;
992 989
993 if(is_sata(hwif)) { 990 if(is_sata(hwif)) {
994 static int first = 1; 991 static int first = 1;
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 6fe4ecb6c06c..83c80ed73e99 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -428,16 +428,6 @@ static int sis_get_info (char *buffer, char **addr, off_t offset, int count)
428} 428}
429#endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) */ 429#endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) */
430 430
431static u8 sis5513_ratemask (ide_drive_t *drive)
432{
433 u8 rates[] = { 0, 0, 1, 2, 3, 3, 4, 4 };
434 u8 mode = rates[chipset_family];
435
436 if (!eighty_ninty_three(drive))
437 mode = min(mode, (u8)1);
438 return mode;
439}
440
441/* 431/*
442 * Configuration functions 432 * Configuration functions
443 */ 433 */
@@ -563,7 +553,7 @@ static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
563 u8 drive_pci, reg, speed; 553 u8 drive_pci, reg, speed;
564 u32 regdw; 554 u32 regdw;
565 555
566 speed = ide_rate_filter(sis5513_ratemask(drive), xferspeed); 556 speed = ide_rate_filter(drive, xferspeed);
567 557
568 /* See config_art_rwp_pio for drive pci config registers */ 558 /* See config_art_rwp_pio for drive pci config registers */
569 drive_pci = 0x40; 559 drive_pci = 0x40;
@@ -653,7 +643,7 @@ static void sis5513_tune_drive (ide_drive_t *drive, u8 pio)
653 */ 643 */
654static int config_chipset_for_dma (ide_drive_t *drive) 644static int config_chipset_for_dma (ide_drive_t *drive)
655{ 645{
656 u8 speed = ide_dma_speed(drive, sis5513_ratemask(drive)); 646 u8 speed = ide_max_dma_mode(drive);
657 647
658#ifdef DEBUG 648#ifdef DEBUG
659 printk("SIS5513: config_chipset_for_dma, drive %d, ultra %x\n", 649 printk("SIS5513: config_chipset_for_dma, drive %d, ultra %x\n",
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 852ccb36da1d..9e95a5cbf984 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -21,15 +21,6 @@
21 21
22#include <asm/io.h> 22#include <asm/io.h>
23 23
24static u8 slc90e66_ratemask (ide_drive_t *drive)
25{
26 u8 mode = 2;
27
28 if (!eighty_ninty_three(drive))
29 mode = min_t(u8, mode, 1);
30 return mode;
31}
32
33static u8 slc90e66_dma_2_pio (u8 xfer_rate) { 24static u8 slc90e66_dma_2_pio (u8 xfer_rate) {
34 switch(xfer_rate) { 25 switch(xfer_rate) {
35 case XFER_UDMA_4: 26 case XFER_UDMA_4:
@@ -122,7 +113,7 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
122 ide_hwif_t *hwif = HWIF(drive); 113 ide_hwif_t *hwif = HWIF(drive);
123 struct pci_dev *dev = hwif->pci_dev; 114 struct pci_dev *dev = hwif->pci_dev;
124 u8 maslave = hwif->channel ? 0x42 : 0x40; 115 u8 maslave = hwif->channel ? 0x42 : 0x40;
125 u8 speed = ide_rate_filter(slc90e66_ratemask(drive), xferspeed); 116 u8 speed = ide_rate_filter(drive, xferspeed);
126 int sitre = 0, a_speed = 7 << (drive->dn * 4); 117 int sitre = 0, a_speed = 7 << (drive->dn * 4);
127 int u_speed = 0, u_flag = 1 << drive->dn; 118 int u_speed = 0, u_flag = 1 << drive->dn;
128 u16 reg4042, reg44, reg48, reg4a; 119 u16 reg4042, reg44, reg48, reg4a;
@@ -171,7 +162,7 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
171 162
172static int slc90e66_config_drive_for_dma (ide_drive_t *drive) 163static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
173{ 164{
174 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive)); 165 u8 speed = ide_max_dma_mode(drive);
175 166
176 if (!speed) 167 if (!speed)
177 return 0; 168 return 0;
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 0b6d81d6ce48..168f035caa3f 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -13,18 +13,13 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/ide.h> 14#include <linux/ide.h>
15 15
16static inline u8 tc86c001_ratemask(ide_drive_t *drive)
17{
18 return eighty_ninty_three(drive) ? 2 : 1;
19}
20
21static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed) 16static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed)
22{ 17{
23 ide_hwif_t *hwif = HWIF(drive); 18 ide_hwif_t *hwif = HWIF(drive);
24 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00); 19 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00);
25 u16 mode, scr = hwif->INW(scr_port); 20 u16 mode, scr = hwif->INW(scr_port);
26 21
27 speed = ide_rate_filter(tc86c001_ratemask(drive), speed); 22 speed = ide_rate_filter(drive, speed);
28 23
29 switch (speed) { 24 switch (speed) {
30 case XFER_UDMA_4: mode = 0x00c0; break; 25 case XFER_UDMA_4: mode = 0x00c0; break;
@@ -174,7 +169,7 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
174 169
175static int config_chipset_for_dma(ide_drive_t *drive) 170static int config_chipset_for_dma(ide_drive_t *drive)
176{ 171{
177 u8 speed = ide_dma_speed(drive, tc86c001_ratemask(drive)); 172 u8 speed = ide_max_dma_mode(drive);
178 173
179 if (!speed) 174 if (!speed)
180 return 0; 175 return 0;
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 5e06179c3469..8a877235b949 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -48,7 +48,7 @@ static int triflex_tune_chipset(ide_drive_t *drive, u8 xferspeed)
48 u16 timing = 0; 48 u16 timing = 0;
49 u32 triflex_timings = 0; 49 u32 triflex_timings = 0;
50 u8 unit = (drive->select.b.unit & 0x01); 50 u8 unit = (drive->select.b.unit & 0x01);
51 u8 speed = ide_rate_filter(0, xferspeed); 51 u8 speed = ide_rate_filter(drive, xferspeed);
52 52
53 pci_read_config_dword(dev, channel_offset, &triflex_timings); 53 pci_read_config_dword(dev, channel_offset, &triflex_timings);
54 54
@@ -102,7 +102,7 @@ static void triflex_tune_drive(ide_drive_t *drive, u8 pio)
102 102
103static int triflex_config_drive_for_dma(ide_drive_t *drive) 103static int triflex_config_drive_for_dma(ide_drive_t *drive)
104{ 104{
105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */ 105 u8 speed = ide_max_dma_mode(drive);
106 106
107 if (!speed) 107 if (!speed)
108 return 0; 108 return 0;
diff --git a/include/linux/ide.h b/include/linux/ide.h
index c9375c863584..23ab4dc05009 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -717,11 +717,8 @@ typedef struct hwif_s {
717 int (*quirkproc)(ide_drive_t *); 717 int (*quirkproc)(ide_drive_t *);
718 /* driver soft-power interface */ 718 /* driver soft-power interface */
719 int (*busproc)(ide_drive_t *, int); 719 int (*busproc)(ide_drive_t *, int);
720// /* host rate limiter */
721// u8 (*ratemask)(ide_drive_t *);
722// /* device rate limiter */
723// u8 (*ratefilter)(ide_drive_t *, u8);
724#endif 720#endif
721 u8 (*udma_filter)(ide_drive_t *);
725 722
726 void (*ata_input_data)(ide_drive_t *, void *, u32); 723 void (*ata_input_data)(ide_drive_t *, void *, u32);
727 void (*ata_output_data)(ide_drive_t *, void *, u32); 724 void (*ata_output_data)(ide_drive_t *, void *, u32);
@@ -1279,6 +1276,7 @@ int ide_in_drive_list(struct hd_driveid *, const struct drive_list_entry *);
1279int __ide_dma_bad_drive(ide_drive_t *); 1276int __ide_dma_bad_drive(ide_drive_t *);
1280int __ide_dma_good_drive(ide_drive_t *); 1277int __ide_dma_good_drive(ide_drive_t *);
1281int ide_use_dma(ide_drive_t *); 1278int ide_use_dma(ide_drive_t *);
1279u8 ide_max_dma_mode(ide_drive_t *);
1282void ide_dma_off(ide_drive_t *); 1280void ide_dma_off(ide_drive_t *);
1283void ide_dma_verbose(ide_drive_t *); 1281void ide_dma_verbose(ide_drive_t *);
1284int ide_set_dma(ide_drive_t *); 1282int ide_set_dma(ide_drive_t *);
@@ -1305,6 +1303,7 @@ extern int __ide_dma_timeout(ide_drive_t *);
1305 1303
1306#else 1304#else
1307static inline int ide_use_dma(ide_drive_t *drive) { return 0; } 1305static inline int ide_use_dma(ide_drive_t *drive) { return 0; }
1306static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; }
1308static inline void ide_dma_off(ide_drive_t *drive) { ; } 1307static inline void ide_dma_off(ide_drive_t *drive) { ; }
1309static inline void ide_dma_verbose(ide_drive_t *drive) { ; } 1308static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
1310static inline int ide_set_dma(ide_drive_t *drive) { return 1; } 1309static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
@@ -1349,8 +1348,7 @@ static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1349} 1348}
1350 1349
1351/* ide-lib.c */ 1350/* ide-lib.c */
1352extern u8 ide_dma_speed(ide_drive_t *drive, u8 mode); 1351u8 ide_rate_filter(ide_drive_t *, u8);
1353extern u8 ide_rate_filter(u8 mode, u8 speed);
1354extern int ide_dma_enable(ide_drive_t *drive); 1352extern int ide_dma_enable(ide_drive_t *drive);
1355extern char *ide_xfer_verbose(u8 xfer_rate); 1353extern char *ide_xfer_verbose(u8 xfer_rate);
1356extern void ide_toggle_bounce(ide_drive_t *drive, int on); 1354extern void ide_toggle_bounce(ide_drive_t *drive, int on);