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