libata-acpi: improve _GTF execution error handling and reporting

As _GTF commands can't transfer data, device error never signals
transfer error. It indicates that the device vetoed the operation, so
it's meaningless to retry.

This patch makes libata-acpi to report and continue on device errors
when executing _GTF commands. Also commands rejected by device don't
contribute to the number of _GTF commands executed.

While at it, update _GTF execution reporting such that all successful
commands are logged at KERN_DEBUG and rename taskfile_load_raw() to
ata_acpi_run_tf() for consistency.

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 0e8634bf 66fa7f21

+46 -31
+46 -31
drivers/ata/libata-acpi.c
··· 466 EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); 467 468 /** 469 - * taskfile_load_raw - send taskfile registers to host controller 470 * @dev: target ATA device 471 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) 472 * ··· 485 * EH context. 486 * 487 * RETURNS: 488 - * 0 on success, -errno on failure. 489 */ 490 - static int taskfile_load_raw(struct ata_device *dev, 491 - const struct ata_acpi_gtf *gtf) 492 { 493 - struct ata_port *ap = dev->link->ap; 494 struct ata_taskfile tf, rtf; 495 unsigned int err_mask; 496 497 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) 498 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) ··· 515 tf.device = gtf->tf[5]; /* 0x1f6 */ 516 tf.command = gtf->tf[6]; /* 0x1f7 */ 517 518 - if (ata_msg_probe(ap)) 519 - ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd " 520 - "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n", 521 - tf.command, tf.feature, tf.nsect, 522 - tf.lbal, tf.lbam, tf.lbah, tf.device); 523 - 524 rtf = tf; 525 err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0); 526 - if (err_mask) { 527 - ata_dev_printk(dev, KERN_ERR, 528 - "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed " 529 - "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n", 530 - tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam, 531 - tf.lbah, tf.device, err_mask, rtf.command, rtf.feature); 532 - return -EIO; 533 } 534 535 - return 0; 536 } 537 538 /** ··· 576 gtf_count = rc; 577 578 /* execute them */ 579 - for (i = 0, rc = 0; i < gtf_count; i++) { 580 - int tmp; 581 - 582 - /* ACPI errors are eventually ignored. Run till the 583 - * end even after errors. 584 - */ 585 - tmp = taskfile_load_raw(dev, gtf++); 586 - if (!rc) 587 - rc = tmp; 588 - 589 - (*nr_executed)++; 590 } 591 592 ata_acpi_clear_gtf(dev); 593 594 - return rc; 595 } 596 597 /**
··· 466 EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); 467 468 /** 469 + * ata_acpi_run_tf - send taskfile registers to host controller 470 * @dev: target ATA device 471 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) 472 * ··· 485 * EH context. 486 * 487 * RETURNS: 488 + * 1 if command is executed successfully. 0 if ignored or rejected, 489 + * -errno on other errors. 490 */ 491 + static int ata_acpi_run_tf(struct ata_device *dev, 492 + const struct ata_acpi_gtf *gtf) 493 { 494 struct ata_taskfile tf, rtf; 495 unsigned int err_mask; 496 + const char *level; 497 + char msg[60]; 498 + int rc; 499 500 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) 501 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) ··· 512 tf.device = gtf->tf[5]; /* 0x1f6 */ 513 tf.command = gtf->tf[6]; /* 0x1f7 */ 514 515 rtf = tf; 516 err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0); 517 + 518 + switch (err_mask) { 519 + case 0: 520 + level = KERN_DEBUG; 521 + snprintf(msg, sizeof(msg), "succeeded"); 522 + rc = 1; 523 + break; 524 + 525 + case AC_ERR_DEV: 526 + level = KERN_INFO; 527 + snprintf(msg, sizeof(msg), 528 + "rejected by device (Stat=0x%02x Err=0x%02x)", 529 + rtf.command, rtf.feature); 530 + rc = 0; 531 + break; 532 + 533 + default: 534 + level = KERN_ERR; 535 + snprintf(msg, sizeof(msg), 536 + "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)", 537 + err_mask, rtf.command, rtf.feature); 538 + rc = -EIO; 539 + break; 540 } 541 542 + ata_dev_printk(dev, level, 543 + "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x %s\n", 544 + tf.command, tf.feature, tf.nsect, tf.lbal, 545 + tf.lbam, tf.lbah, tf.device, msg); 546 + 547 + return rc; 548 } 549 550 /** ··· 558 gtf_count = rc; 559 560 /* execute them */ 561 + for (i = 0; i < gtf_count; i++) { 562 + rc = ata_acpi_run_tf(dev, gtf++); 563 + if (rc < 0) 564 + break; 565 + if (rc) 566 + (*nr_executed)++; 567 } 568 569 ata_acpi_clear_gtf(dev); 570 571 + if (rc < 0) 572 + return rc; 573 + return 0; 574 } 575 576 /**