Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ide: add ide_use_fast_pio() helper (v3)

* add ide_use_fast_pio() helper for use by host drivers

* add DMA capability and hwif->autodma checks to ide_use_dma()

- au1xxx-ide/it8213/it821x drivers didn't check for (id->capability & 1)

[ for the IT8211/2 in SMART mode this check shouldn't be made but since
in it821x_fixups() we set DMA bit explicitly:

if(strstr(id->model, "Integrated Technology Express")) {
/* In raid mode the ident block is slightly buggy
We need to set the bits so that the IDE layer knows
LBA28. LBA48 and DMA ar valid */
id->capability |= 3; /* LBA28, DMA */

we are better off using generic helper if we can ]

- ide-cris driver didn't set ->autodma

[ before the patch hwif->autodma was only checked in the chipset specific
hwif->ide_dma_check implementations, for ide-cris it is cris_dma_check()
function so there no behavior change here ]

v2:
* updated patch description (thanks to Alan Cox for the feedback)

v3:
* updated for scc_pata driver

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

+73 -166
+5 -7
drivers/ide/cris/ide-cris.c
··· 821 821 hwif->ultra_mask = cris_ultra_mask; 822 822 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ 823 823 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */ 824 + hwif->autodma = 1; 825 + hwif->drives[0].autodma = 1; 826 + hwif->drives[1].autodma = 1; 824 827 } 825 828 826 829 /* Reset pulse */ ··· 1049 1046 static int cris_dma_check(ide_drive_t *drive) 1050 1047 { 1051 1048 ide_hwif_t *hwif = drive->hwif; 1052 - struct hd_driveid* id = drive->id; 1053 1049 1054 - if (id && (id->capability & 1)) { 1055 - if (ide_use_dma(drive)) { 1056 - if (cris_config_drive_for_dma(drive)) 1057 - return hwif->ide_dma_on(drive); 1058 - } 1059 - } 1050 + if (ide_use_dma(drive) && cris_config_drive_for_dma(drive)) 1051 + return hwif->ide_dma_on(drive); 1060 1052 1061 1053 return hwif->ide_dma_off_quietly(drive); 1062 1054 }
+3
drivers/ide/ide-dma.c
··· 680 680 struct hd_driveid *id = drive->id; 681 681 ide_hwif_t *hwif = drive->hwif; 682 682 683 + if ((id->capability & 1) == 0 || drive->autodma == 0) 684 + return 0; 685 + 683 686 /* consult the list of known "bad" drives */ 684 687 if (__ide_dma_bad_drive(drive)) 685 688 return 0;
+15
drivers/ide/ide-lib.c
··· 205 205 206 206 EXPORT_SYMBOL(ide_dma_enable); 207 207 208 + int ide_use_fast_pio(ide_drive_t *drive) 209 + { 210 + struct hd_driveid *id = drive->id; 211 + 212 + if ((id->capability & 1) && drive->autodma) 213 + return 1; 214 + 215 + if ((id->capability & 8) || (id->field_valid & 2)) 216 + return 1; 217 + 218 + return 0; 219 + } 220 + 221 + EXPORT_SYMBOL_GPL(ide_use_fast_pio); 222 + 208 223 /* 209 224 * Standard (generic) timings for PIO modes, from ATA2 specification. 210 225 * These timings are for access to the IDE data port register *only*.
+3 -11
drivers/ide/pci/aec62xx.c
··· 210 210 static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive) 211 211 { 212 212 ide_hwif_t *hwif = HWIF(drive); 213 - struct hd_driveid *id = drive->id; 214 213 215 - if ((id->capability & 1) && drive->autodma) { 214 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 215 + return hwif->ide_dma_on(drive); 216 216 217 - if (ide_use_dma(drive)) { 218 - if (config_chipset_for_dma(drive)) 219 - return hwif->ide_dma_on(drive); 220 - } 221 - 222 - goto fast_ata_pio; 223 - 224 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 225 - fast_ata_pio: 217 + if (ide_use_fast_pio(drive)) { 226 218 aec62xx_tune_drive(drive, 5); 227 219 return hwif->ide_dma_off_quietly(drive); 228 220 }
+3 -11
drivers/ide/pci/atiixp.c
··· 253 253 static int atiixp_dma_check(ide_drive_t *drive) 254 254 { 255 255 ide_hwif_t *hwif = HWIF(drive); 256 - struct hd_driveid *id = drive->id; 257 256 u8 tspeed, speed; 258 257 259 258 drive->init_speed = 0; 260 259 261 - if ((id->capability & 1) && drive->autodma) { 260 + if (ide_use_dma(drive) && atiixp_config_drive_for_dma(drive)) 261 + return hwif->ide_dma_on(drive); 262 262 263 - if (ide_use_dma(drive)) { 264 - if (atiixp_config_drive_for_dma(drive)) 265 - return hwif->ide_dma_on(drive); 266 - } 267 - 268 - goto fast_ata_pio; 269 - 270 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 271 - fast_ata_pio: 263 + if (ide_use_fast_pio(drive)) { 272 264 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 273 265 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; 274 266 hwif->speedproc(drive, speed);
+3 -11
drivers/ide/pci/cmd64x.c
··· 475 475 static int cmd64x_config_drive_for_dma (ide_drive_t *drive) 476 476 { 477 477 ide_hwif_t *hwif = HWIF(drive); 478 - struct hd_driveid *id = drive->id; 479 478 480 - if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) { 479 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 480 + return hwif->ide_dma_on(drive); 481 481 482 - if (ide_use_dma(drive)) { 483 - if (config_chipset_for_dma(drive)) 484 - return hwif->ide_dma_on(drive); 485 - } 486 - 487 - goto fast_ata_pio; 488 - 489 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 490 - fast_ata_pio: 482 + if (ide_use_fast_pio(drive)) { 491 483 config_chipset_for_pio(drive, 1); 492 484 return hwif->ide_dma_off_quietly(drive); 493 485 }
+3 -10
drivers/ide/pci/cs5535.c
··· 196 196 static int cs5535_dma_check(ide_drive_t *drive) 197 197 { 198 198 ide_hwif_t *hwif = drive->hwif; 199 - struct hd_driveid *id = drive->id; 200 199 u8 speed; 201 200 202 201 drive->init_speed = 0; 203 202 204 - if ((id->capability & 1) && drive->autodma) { 205 - if (ide_use_dma(drive)) { 206 - if (cs5535_config_drive_for_dma(drive)) 207 - return hwif->ide_dma_on(drive); 208 - } 203 + if (ide_use_dma(drive) && cs5535_config_drive_for_dma(drive)) 204 + return hwif->ide_dma_on(drive); 209 205 210 - goto fast_ata_pio; 211 - 212 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 213 - fast_ata_pio: 206 + if (ide_use_fast_pio(drive)) { 214 207 speed = ide_get_best_pio_mode(drive, 255, 4, NULL); 215 208 cs5535_set_drive(drive, speed); 216 209 return hwif->ide_dma_off_quietly(drive);
+4 -12
drivers/ide/pci/hpt34x.c
··· 110 110 static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive) 111 111 { 112 112 ide_hwif_t *hwif = HWIF(drive); 113 - struct hd_driveid *id = drive->id; 114 113 115 114 drive->init_speed = 0; 116 115 117 - if (id && (id->capability & 1) && drive->autodma) { 118 - 119 - if (ide_use_dma(drive)) { 120 - if (config_chipset_for_dma(drive)) 116 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 121 117 #ifndef CONFIG_HPT34X_AUTODMA 122 - return hwif->ide_dma_off_quietly(drive); 118 + return hwif->ide_dma_off_quietly(drive); 123 119 #else 124 - return hwif->ide_dma_on(drive); 120 + return hwif->ide_dma_on(drive); 125 121 #endif 126 - } 127 122 128 - goto fast_ata_pio; 129 - 130 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 131 - fast_ata_pio: 123 + if (ide_use_fast_pio(drive)) { 132 124 hpt34x_tune_drive(drive, 255); 133 125 return hwif->ide_dma_off_quietly(drive); 134 126 }
+3 -8
drivers/ide/pci/hpt366.c
··· 737 737 static int hpt366_config_drive_xfer_rate(ide_drive_t *drive) 738 738 { 739 739 ide_hwif_t *hwif = HWIF(drive); 740 - struct hd_driveid *id = drive->id; 741 740 742 741 drive->init_speed = 0; 743 742 744 - if ((id->capability & 1) && drive->autodma) { 745 - if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 746 - return hwif->ide_dma_on(drive); 743 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 744 + return hwif->ide_dma_on(drive); 747 745 748 - goto fast_ata_pio; 749 - 750 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 751 - fast_ata_pio: 746 + if (ide_use_fast_pio(drive)) { 752 747 hpt3xx_tune_drive(drive, 255); 753 748 return hwif->ide_dma_off_quietly(drive); 754 749 }
+3 -9
drivers/ide/pci/pdc202xx_new.c
··· 282 282 static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive) 283 283 { 284 284 ide_hwif_t *hwif = HWIF(drive); 285 - struct hd_driveid *id = drive->id; 286 285 287 286 drive->init_speed = 0; 288 287 289 - if ((id->capability & 1) && drive->autodma) { 288 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 289 + return hwif->ide_dma_on(drive); 290 290 291 - if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 292 - return hwif->ide_dma_on(drive); 293 - 294 - goto fast_ata_pio; 295 - 296 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 297 - fast_ata_pio: 291 + if (ide_use_fast_pio(drive)) { 298 292 hwif->tuneproc(drive, 255); 299 293 return hwif->ide_dma_off_quietly(drive); 300 294 }
+3 -11
drivers/ide/pci/pdc202xx_old.c
··· 323 323 static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive) 324 324 { 325 325 ide_hwif_t *hwif = HWIF(drive); 326 - struct hd_driveid *id = drive->id; 327 326 328 327 drive->init_speed = 0; 329 328 330 - if (id && (id->capability & 1) && drive->autodma) { 329 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 330 + return hwif->ide_dma_on(drive); 331 331 332 - if (ide_use_dma(drive)) { 333 - if (config_chipset_for_dma(drive)) 334 - return hwif->ide_dma_on(drive); 335 - } 336 - 337 - goto fast_ata_pio; 338 - 339 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 340 - fast_ata_pio: 332 + if (ide_use_fast_pio(drive)) { 341 333 pdc202xx_tune_drive(drive, 255); 342 334 return hwif->ide_dma_off_quietly(drive); 343 335 }
+3 -9
drivers/ide/pci/piix.c
··· 387 387 static int piix_config_drive_xfer_rate (ide_drive_t *drive) 388 388 { 389 389 ide_hwif_t *hwif = HWIF(drive); 390 - struct hd_driveid *id = drive->id; 391 390 392 391 drive->init_speed = 0; 393 392 394 - if ((id->capability & 1) && drive->autodma) { 393 + if (ide_use_dma(drive) && piix_config_drive_for_dma(drive)) 394 + return hwif->ide_dma_on(drive); 395 395 396 - if (ide_use_dma(drive) && piix_config_drive_for_dma(drive)) 397 - return hwif->ide_dma_on(drive); 398 - 399 - goto fast_ata_pio; 400 - 401 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 402 - fast_ata_pio: 396 + if (ide_use_fast_pio(drive)) { 403 397 /* Find best PIO mode. */ 404 398 (void) hwif->speedproc(drive, XFER_PIO_0 + 405 399 ide_get_best_pio_mode(drive, 255, 4, NULL));
+3 -11
drivers/ide/pci/serverworks.c
··· 316 316 static int svwks_config_drive_xfer_rate (ide_drive_t *drive) 317 317 { 318 318 ide_hwif_t *hwif = HWIF(drive); 319 - struct hd_driveid *id = drive->id; 320 319 321 320 drive->init_speed = 0; 322 321 323 - if ((id->capability & 1) && drive->autodma) { 322 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 323 + return hwif->ide_dma_on(drive); 324 324 325 - if (ide_use_dma(drive)) { 326 - if (config_chipset_for_dma(drive)) 327 - return hwif->ide_dma_on(drive); 328 - } 329 - 330 - goto fast_ata_pio; 331 - 332 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 333 - fast_ata_pio: 325 + if (ide_use_fast_pio(drive)) { 334 326 config_chipset_for_pio(drive); 335 327 // hwif->tuneproc(drive, 5); 336 328 return hwif->ide_dma_off_quietly(drive);
+3 -11
drivers/ide/pci/siimage.c
··· 415 415 static int siimage_config_drive_for_dma (ide_drive_t *drive) 416 416 { 417 417 ide_hwif_t *hwif = HWIF(drive); 418 - struct hd_driveid *id = drive->id; 419 418 420 - if ((id->capability & 1) != 0 && drive->autodma) { 419 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 420 + return hwif->ide_dma_on(drive); 421 421 422 - if (ide_use_dma(drive)) { 423 - if (config_chipset_for_dma(drive)) 424 - return hwif->ide_dma_on(drive); 425 - } 426 - 427 - goto fast_ata_pio; 428 - 429 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 430 - fast_ata_pio: 422 + if (ide_use_fast_pio(drive)) { 431 423 config_chipset_for_pio(drive, 1); 432 424 return hwif->ide_dma_off_quietly(drive); 433 425 }
+3 -11
drivers/ide/pci/sis5513.c
··· 670 670 static int sis5513_config_xfer_rate(ide_drive_t *drive) 671 671 { 672 672 ide_hwif_t *hwif = HWIF(drive); 673 - struct hd_driveid *id = drive->id; 674 673 675 674 config_art_rwp_pio(drive, 5); 676 675 677 676 drive->init_speed = 0; 678 677 679 - if (id && (id->capability & 1) && drive->autodma) { 678 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 679 + return hwif->ide_dma_on(drive); 680 680 681 - if (ide_use_dma(drive)) { 682 - if (config_chipset_for_dma(drive)) 683 - return hwif->ide_dma_on(drive); 684 - } 685 - 686 - goto fast_ata_pio; 687 - 688 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 689 - fast_ata_pio: 681 + if (ide_use_fast_pio(drive)) { 690 682 sis5513_tune_drive(drive, 5); 691 683 return hwif->ide_dma_off_quietly(drive); 692 684 }
+3 -9
drivers/ide/pci/slc90e66.c
··· 180 180 static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive) 181 181 { 182 182 ide_hwif_t *hwif = HWIF(drive); 183 - struct hd_driveid *id = drive->id; 184 183 185 184 drive->init_speed = 0; 186 185 187 - if ((id->capability & 1) && drive->autodma) { 186 + if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive)) 187 + return hwif->ide_dma_on(drive); 188 188 189 - if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive)) 190 - return hwif->ide_dma_on(drive); 191 - 192 - goto fast_ata_pio; 193 - 194 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 195 - fast_ata_pio: 189 + if (ide_use_fast_pio(drive)) { 196 190 (void) hwif->speedproc(drive, XFER_PIO_0 + 197 191 ide_get_best_pio_mode(drive, 255, 4, NULL)); 198 192 return hwif->ide_dma_off_quietly(drive);
+3 -9
drivers/ide/pci/tc86c001.c
··· 186 186 static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive) 187 187 { 188 188 ide_hwif_t *hwif = HWIF(drive); 189 - struct hd_driveid *id = drive->id; 190 189 191 - if ((id->capability & 1) && drive->autodma) { 190 + if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 191 + return hwif->ide_dma_on(drive); 192 192 193 - if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 194 - return hwif->ide_dma_on(drive); 195 - 196 - goto fast_ata_pio; 197 - 198 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 199 - fast_ata_pio: 193 + if (ide_use_fast_pio(drive)) { 200 194 tc86c001_tune_drive(drive, 255); 201 195 return hwif->ide_dma_off_quietly(drive); 202 196 }
+2 -7
drivers/ide/pci/triflex.c
··· 114 114 static int triflex_config_drive_xfer_rate(ide_drive_t *drive) 115 115 { 116 116 ide_hwif_t *hwif = HWIF(drive); 117 - struct hd_driveid *id = drive->id; 118 117 119 - if ((id->capability & 1) && drive->autodma) { 120 - if (ide_use_dma(drive)) { 121 - if (triflex_config_drive_for_dma(drive)) 122 - return hwif->ide_dma_on(drive); 123 - } 124 - } 118 + if (ide_use_dma(drive) && triflex_config_drive_for_dma(drive)) 119 + return hwif->ide_dma_on(drive); 125 120 126 121 hwif->tuneproc(drive, 255); 127 122 return hwif->ide_dma_off_quietly(drive);
+4 -9
drivers/ide/ppc/scc_pata.c
··· 383 383 static int scc_config_drive_for_dma(ide_drive_t *drive) 384 384 { 385 385 ide_hwif_t *hwif = HWIF(drive); 386 - struct hd_driveid *id = drive->id; 387 386 388 - if ((id->capability & 1) != 0 && drive->autodma) { 389 - if (ide_use_dma(drive)) { 390 - if (scc_config_chipset_for_dma(drive)) 391 - return hwif->ide_dma_on(drive); 392 - } 393 - goto fast_ata_pio; 394 - } else if ((id->capability & 8) || (id->field_valid & 2)) { 395 - fast_ata_pio: 387 + if (ide_use_dma(drive) && scc_config_chipset_for_dma(drive)) 388 + return hwif->ide_dma_on(drive); 389 + 390 + if (ide_use_fast_pio(drive)) { 396 391 hwif->tuneproc(drive, 4); 397 392 hwif->ide_dma_off_quietly(drive); 398 393 }
+1
include/linux/ide.h
··· 1352 1352 extern char *ide_xfer_verbose(u8 xfer_rate); 1353 1353 extern void ide_toggle_bounce(ide_drive_t *drive, int on); 1354 1354 extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate); 1355 + int ide_use_fast_pio(ide_drive_t *); 1355 1356 1356 1357 u8 ide_dump_status(ide_drive_t *, const char *, u8); 1357 1358