aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/pci
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-05-09 18:01:08 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-05-09 18:01:08 -0400
commit2d5eaa6dd744a641e75503232a01f52d0768884c (patch)
tree0736bd00ea3bd032d601d0a676c998cb043b877a /drivers/ide/pci
parent18137207236285989dfc0ee7f929b954199228f3 (diff)
ide: rework the code for selecting the best DMA transfer mode (v3)
Depends on the "ide: fix UDMA/MWDMA/SWDMA masks" patch. * add ide_hwif_t.udma_filter hook for filtering UDMA mask (use it in alim15x3, hpt366, siimage and serverworks drivers) * add ide_max_dma_mode() for finding best DMA mode for the device (loosely based on some older libata-core.c code) * convert ide_dma_speed() users to use ide_max_dma_mode() * make ide_rate_filter() take "ide_drive_t *drive" as an argument instead of "u8 mode" and teach it to how to use UDMA mask to do filtering * use ide_rate_filter() in hpt366 driver * remove no longer needed ide_dma_speed() and *_ratemask() * unexport eighty_ninty_three() v2: * rename ->filter_udma_mask to ->udma_filter [ Suggested by Sergei Shtylyov <sshtylyov@ru.mvista.com>. ] v3: * updated for scc_pata driver (fixes XFER_UDMA_6 filtering for user-space originated transfer mode change requests when 100MHz clock is used) Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/pci')
-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
20 files changed, 137 insertions, 457 deletions
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;