libata-acpi: implement dev->gtf_cache and evaluate _GTF right after _STM during resume

On certain implementations, _GTF evaluation depends on preceding _STM
and both can be pretty picky about the configuration. Using _GTM
result cached during controller initialization satisfies the most
neurotic _STM implementation. However, libata evaluates _GTF after
reset during device configuration and the hardware state can be
different from what _GTF expects and can cause evaluation failure.

This patch adds dev->gtf_cache and updates ata_dev_get_GTF() such that
it uses the cached value if available. Cache is cleared with a call
to ata_acpi_clear_gtf().

Because for SATA ACPI nodes _GTF must be evaluated after _SDD which
can't be done till IDENTIFY is complete, _GTF caching from
ata_acpi_on_resume() is used only for IDE ACPI nodes.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>

authored by Tejun Heo and committed by Jeff Garzik 398e0782 c05e6ff0

+50 -20
+49 -20
drivers/ata/libata-acpi.c
··· 41 return (dev->bus == &pci_bus_type); 42 } 43 44 /** 45 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects 46 * @ap: target SATA port ··· 333 * ata_dev_get_GTF - get the drive bootup default taskfile settings 334 * @dev: target ATA device 335 * @gtf: output parameter for buffer containing _GTF taskfile arrays 336 - * @ptr_to_free: pointer which should be freed 337 * 338 * This applies to both PATA and SATA drives. 339 * ··· 349 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't 350 * contain valid data. 351 */ 352 - static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf, 353 - void **ptr_to_free) 354 { 355 struct ata_port *ap = dev->link->ap; 356 acpi_status status; 357 struct acpi_buffer output; 358 union acpi_object *out_obj; 359 int rc = 0; 360 361 /* set up output buffer */ 362 output.length = ACPI_ALLOCATE_BUFFER; ··· 373 374 /* _GTF has no input parameters */ 375 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 376 377 if (ACPI_FAILURE(status)) { 378 if (status != AE_NOT_FOUND) { ··· 394 goto out_free; 395 } 396 397 - out_obj = output.pointer; 398 if (out_obj->type != ACPI_TYPE_BUFFER) { 399 ata_dev_printk(dev, KERN_WARNING, 400 "_GTF unexpected object type 0x%x\n", ··· 408 goto out_free; 409 } 410 411 - *ptr_to_free = out_obj; 412 - *gtf = (void *)out_obj->buffer.pointer; 413 rc = out_obj->buffer.length / REGS_PER_GTF; 414 - 415 - if (ata_msg_probe(ap)) 416 - ata_dev_printk(dev, KERN_DEBUG, "%s: returning " 417 - "gtf=%p, gtf_count=%d, ptr_to_free=%p\n", 418 - __FUNCTION__, *gtf, rc, *ptr_to_free); 419 return rc; 420 421 out_free: 422 - kfree(output.pointer); 423 return rc; 424 } 425 ··· 544 static int ata_acpi_exec_tfs(struct ata_device *dev) 545 { 546 struct ata_acpi_gtf *gtf = NULL; 547 - void *ptr_to_free = NULL; 548 int gtf_count, i, rc; 549 550 /* get taskfiles */ 551 - gtf_count = ata_dev_get_GTF(dev, &gtf, &ptr_to_free); 552 553 /* execute them */ 554 for (i = 0, rc = 0; i < gtf_count; i++) { ··· 561 rc = tmp; 562 } 563 564 - kfree(ptr_to_free); 565 566 if (rc == 0) 567 return gtf_count; ··· 654 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 655 struct ata_device *dev; 656 657 - /* restore timing parameters */ 658 - if (ap->acpi_handle && gtm) 659 ata_acpi_stm(ap, gtm); 660 661 - /* schedule _GTF */ 662 - ata_link_for_each_dev(dev, &ap->link) 663 - dev->flags |= ATA_DFLAG_ACPI_PENDING; 664 } 665 666 /** ··· 763 */ 764 void ata_acpi_on_disable(struct ata_device *dev) 765 { 766 }
··· 41 return (dev->bus == &pci_bus_type); 42 } 43 44 + static void ata_acpi_clear_gtf(struct ata_device *dev) 45 + { 46 + kfree(dev->gtf_cache); 47 + dev->gtf_cache = NULL; 48 + } 49 + 50 /** 51 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects 52 * @ap: target SATA port ··· 327 * ata_dev_get_GTF - get the drive bootup default taskfile settings 328 * @dev: target ATA device 329 * @gtf: output parameter for buffer containing _GTF taskfile arrays 330 * 331 * This applies to both PATA and SATA drives. 332 * ··· 344 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't 345 * contain valid data. 346 */ 347 + static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf) 348 { 349 struct ata_port *ap = dev->link->ap; 350 acpi_status status; 351 struct acpi_buffer output; 352 union acpi_object *out_obj; 353 int rc = 0; 354 + 355 + /* if _GTF is cached, use the cached value */ 356 + if (dev->gtf_cache) { 357 + out_obj = dev->gtf_cache; 358 + goto done; 359 + } 360 361 /* set up output buffer */ 362 output.length = ACPI_ALLOCATE_BUFFER; ··· 363 364 /* _GTF has no input parameters */ 365 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 366 + out_obj = dev->gtf_cache = output.pointer; 367 368 if (ACPI_FAILURE(status)) { 369 if (status != AE_NOT_FOUND) { ··· 383 goto out_free; 384 } 385 386 if (out_obj->type != ACPI_TYPE_BUFFER) { 387 ata_dev_printk(dev, KERN_WARNING, 388 "_GTF unexpected object type 0x%x\n", ··· 398 goto out_free; 399 } 400 401 + done: 402 rc = out_obj->buffer.length / REGS_PER_GTF; 403 + if (gtf) { 404 + *gtf = (void *)out_obj->buffer.pointer; 405 + if (ata_msg_probe(ap)) 406 + ata_dev_printk(dev, KERN_DEBUG, 407 + "%s: returning gtf=%p, gtf_count=%d\n", 408 + __FUNCTION__, *gtf, rc); 409 + } 410 return rc; 411 412 out_free: 413 + ata_acpi_clear_gtf(dev); 414 return rc; 415 } 416 ··· 533 static int ata_acpi_exec_tfs(struct ata_device *dev) 534 { 535 struct ata_acpi_gtf *gtf = NULL; 536 int gtf_count, i, rc; 537 538 /* get taskfiles */ 539 + gtf_count = ata_dev_get_GTF(dev, &gtf); 540 541 /* execute them */ 542 for (i = 0, rc = 0; i < gtf_count; i++) { ··· 551 rc = tmp; 552 } 553 554 + ata_acpi_clear_gtf(dev); 555 556 if (rc == 0) 557 return gtf_count; ··· 644 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 645 struct ata_device *dev; 646 647 + if (ap->acpi_handle && gtm) { 648 + /* _GTM valid */ 649 + 650 + /* restore timing parameters */ 651 ata_acpi_stm(ap, gtm); 652 653 + /* _GTF should immediately follow _STM so that it can 654 + * use values set by _STM. Cache _GTF result and 655 + * schedule _GTF. 656 + */ 657 + ata_link_for_each_dev(dev, &ap->link) { 658 + ata_acpi_clear_gtf(dev); 659 + if (ata_dev_get_GTF(dev, NULL) >= 0) 660 + dev->flags |= ATA_DFLAG_ACPI_PENDING; 661 + } 662 + } else { 663 + /* SATA _GTF needs to be evaulated after _SDD and 664 + * there's no reason to evaluate IDE _GTF early 665 + * without _STM. Clear cache and schedule _GTF. 666 + */ 667 + ata_link_for_each_dev(dev, &ap->link) { 668 + ata_acpi_clear_gtf(dev); 669 + dev->flags |= ATA_DFLAG_ACPI_PENDING; 670 + } 671 + } 672 } 673 674 /** ··· 735 */ 736 void ata_acpi_on_disable(struct ata_device *dev) 737 { 738 + ata_acpi_clear_gtf(dev); 739 }
+1
include/linux/libata.h
··· 498 struct scsi_device *sdev; /* attached SCSI device */ 499 #ifdef CONFIG_ATA_ACPI 500 acpi_handle acpi_handle; 501 #endif 502 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ 503 u64 n_sectors; /* size of device, if ATA */
··· 498 struct scsi_device *sdev; /* attached SCSI device */ 499 #ifdef CONFIG_ATA_ACPI 500 acpi_handle acpi_handle; 501 + union acpi_object *gtf_cache; 502 #endif 503 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ 504 u64 n_sectors; /* size of device, if ATA */