Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/libata-dev

* 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/libata-dev:
libata: fix ATAPI draining
libata: update atapi_eh_request_sense() such that lbam/lbah contains buffer size
libata-acpi: implement _GTF command filtering
libata-acpi: improve _GTF execution error handling and reporting
libata-acpi: improve ACPI disabling
libata-acpi: implement dev->gtf_cache and evaluate _GTF right after _STM during resume
libata-acpi: implement and use ata_acpi_init_gtm()
libata-acpi: add new hooks ata_acpi_dissociate() and ata_acpi_on_disable()
libata: ata_dev_disable() should be called from EH context
libata: add more opcodes to ata.h
libata: update ata_*_printk() macros such that level can be a variable
libata-acpi: adjust constness in ata_acpi_gtm/stm() parameters
sata_mv: improve warnings about Highpoint RocketRAID 23xx cards
libata: add ST3160023AS / 3.42 to NCQ blacklist
libata: clear link->eh_info.serror from ata_std_postreset()
sata_sil: fix spurious IRQ handling

+421 -175
+272 -119
drivers/ata/libata-acpi.c
··· 6 6 * Copyright (C) 2006 Randy Dunlap 7 7 */ 8 8 9 + #include <linux/module.h> 9 10 #include <linux/ata.h> 10 11 #include <linux/delay.h> 11 12 #include <linux/device.h> ··· 26 25 #include <acpi/acmacros.h> 27 26 #include <acpi/actypes.h> 28 27 28 + enum { 29 + ATA_ACPI_FILTER_SETXFER = 1 << 0, 30 + ATA_ACPI_FILTER_LOCK = 1 << 1, 31 + 32 + ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER | 33 + ATA_ACPI_FILTER_LOCK, 34 + }; 35 + 36 + static unsigned int ata_acpi_gtf_filter = ATA_ACPI_FILTER_DEFAULT; 37 + module_param_named(acpi_gtf_filter, ata_acpi_gtf_filter, int, 0644); 38 + MODULE_PARM_DESC(acpi_gtf_filter, "filter mask for ACPI _GTF commands, set to filter out (0x1=set xfermode, 0x2=lock/freeze lock)"); 39 + 29 40 #define NO_PORT_MULT 0xffff 30 41 #define SATA_ADR(root, pmp) (((root) << 16) | (pmp)) 31 42 ··· 52 39 static int is_pci_dev(struct device *dev) 53 40 { 54 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; 55 48 } 56 49 57 50 /** ··· 113 94 114 95 dev->acpi_handle = acpi_get_child(ap->acpi_handle, i); 115 96 } 97 + 98 + if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0) 99 + ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; 116 100 } 117 101 118 102 static void ata_acpi_handle_hotplug(struct ata_port *ap, struct kobject *kobj, ··· 210 188 } 211 189 212 190 /** 191 + * ata_acpi_dissociate - dissociate ATA host from ACPI objects 192 + * @host: target ATA host 193 + * 194 + * This function is called during driver detach after the whole host 195 + * is shut down. 196 + * 197 + * LOCKING: 198 + * EH context. 199 + */ 200 + void ata_acpi_dissociate(struct ata_host *host) 201 + { 202 + int i; 203 + 204 + /* Restore initial _GTM values so that driver which attaches 205 + * afterward can use them too. 206 + */ 207 + for (i = 0; i < host->n_ports; i++) { 208 + struct ata_port *ap = host->ports[i]; 209 + const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 210 + 211 + if (ap->acpi_handle && gtm) 212 + ata_acpi_stm(ap, gtm); 213 + } 214 + } 215 + 216 + /** 213 217 * ata_acpi_gtm - execute _GTM 214 218 * @ap: target ATA port 215 219 * @gtm: out parameter for _GTM result ··· 248 200 * RETURNS: 249 201 * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. 250 202 */ 251 - int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *gtm) 203 + int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm) 252 204 { 253 205 struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; 254 206 union acpi_object *out_obj; ··· 307 259 * RETURNS: 308 260 * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. 309 261 */ 310 - int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm) 262 + int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm) 311 263 { 312 264 acpi_status status; 265 + struct ata_acpi_gtm stm_buf = *stm; 313 266 struct acpi_object_list input; 314 267 union acpi_object in_params[3]; 315 268 316 269 in_params[0].type = ACPI_TYPE_BUFFER; 317 270 in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); 318 - in_params[0].buffer.pointer = (u8 *)stm; 271 + in_params[0].buffer.pointer = (u8 *)&stm_buf; 319 272 /* Buffers for id may need byteswapping ? */ 320 273 in_params[1].type = ACPI_TYPE_BUFFER; 321 274 in_params[1].buffer.length = 512; ··· 346 297 * ata_dev_get_GTF - get the drive bootup default taskfile settings 347 298 * @dev: target ATA device 348 299 * @gtf: output parameter for buffer containing _GTF taskfile arrays 349 - * @ptr_to_free: pointer which should be freed 350 300 * 351 301 * This applies to both PATA and SATA drives. 352 302 * ··· 359 311 * EH context. 360 312 * 361 313 * RETURNS: 362 - * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't 363 - * contain valid data. 314 + * Number of taskfiles on success, 0 if _GTF doesn't exist. -EINVAL 315 + * if _GTF is invalid. 364 316 */ 365 - static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf, 366 - void **ptr_to_free) 317 + static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf) 367 318 { 368 319 struct ata_port *ap = dev->link->ap; 369 320 acpi_status status; 370 321 struct acpi_buffer output; 371 322 union acpi_object *out_obj; 372 323 int rc = 0; 324 + 325 + /* if _GTF is cached, use the cached value */ 326 + if (dev->gtf_cache) { 327 + out_obj = dev->gtf_cache; 328 + goto done; 329 + } 373 330 374 331 /* set up output buffer */ 375 332 output.length = ACPI_ALLOCATE_BUFFER; ··· 386 333 387 334 /* _GTF has no input parameters */ 388 335 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 336 + out_obj = dev->gtf_cache = output.pointer; 389 337 390 338 if (ACPI_FAILURE(status)) { 391 339 if (status != AE_NOT_FOUND) { 392 340 ata_dev_printk(dev, KERN_WARNING, 393 341 "_GTF evaluation failed (AE 0x%x)\n", 394 342 status); 343 + rc = -EINVAL; 395 344 } 396 345 goto out_free; 397 346 } ··· 405 350 __FUNCTION__, 406 351 (unsigned long long)output.length, 407 352 output.pointer); 353 + rc = -EINVAL; 408 354 goto out_free; 409 355 } 410 356 411 - out_obj = output.pointer; 412 357 if (out_obj->type != ACPI_TYPE_BUFFER) { 413 358 ata_dev_printk(dev, KERN_WARNING, 414 359 "_GTF unexpected object type 0x%x\n", 415 360 out_obj->type); 361 + rc = -EINVAL; 416 362 goto out_free; 417 363 } 418 364 ··· 421 365 ata_dev_printk(dev, KERN_WARNING, 422 366 "unexpected _GTF length (%d)\n", 423 367 out_obj->buffer.length); 368 + rc = -EINVAL; 424 369 goto out_free; 425 370 } 426 371 427 - *ptr_to_free = out_obj; 428 - *gtf = (void *)out_obj->buffer.pointer; 372 + done: 429 373 rc = out_obj->buffer.length / REGS_PER_GTF; 430 - 431 - if (ata_msg_probe(ap)) 432 - ata_dev_printk(dev, KERN_DEBUG, "%s: returning " 433 - "gtf=%p, gtf_count=%d, ptr_to_free=%p\n", 434 - __FUNCTION__, *gtf, rc, *ptr_to_free); 374 + if (gtf) { 375 + *gtf = (void *)out_obj->buffer.pointer; 376 + if (ata_msg_probe(ap)) 377 + ata_dev_printk(dev, KERN_DEBUG, 378 + "%s: returning gtf=%p, gtf_count=%d\n", 379 + __FUNCTION__, *gtf, rc); 380 + } 435 381 return rc; 436 382 437 383 out_free: 438 - kfree(output.pointer); 384 + ata_acpi_clear_gtf(dev); 439 385 return rc; 440 386 } 441 387 ··· 451 393 452 394 int ata_acpi_cbl_80wire(struct ata_port *ap) 453 395 { 454 - struct ata_acpi_gtm gtm; 396 + const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 455 397 int valid = 0; 456 398 457 - /* No _GTM data, no information */ 458 - if (ata_acpi_gtm(ap, &gtm) < 0) 399 + if (!gtm) 459 400 return 0; 460 401 461 402 /* Split timing, DMA enabled */ 462 - if ((gtm.flags & 0x11) == 0x11 && gtm.drive[0].dma < 55) 403 + if ((gtm->flags & 0x11) == 0x11 && gtm->drive[0].dma < 55) 463 404 valid |= 1; 464 - if ((gtm.flags & 0x14) == 0x14 && gtm.drive[1].dma < 55) 405 + if ((gtm->flags & 0x14) == 0x14 && gtm->drive[1].dma < 55) 465 406 valid |= 2; 466 407 /* Shared timing, DMA enabled */ 467 - if ((gtm.flags & 0x11) == 0x01 && gtm.drive[0].dma < 55) 408 + if ((gtm->flags & 0x11) == 0x01 && gtm->drive[0].dma < 55) 468 409 valid |= 1; 469 - if ((gtm.flags & 0x14) == 0x04 && gtm.drive[0].dma < 55) 410 + if ((gtm->flags & 0x14) == 0x04 && gtm->drive[0].dma < 55) 470 411 valid |= 2; 471 412 472 413 /* Drive check */ ··· 478 421 479 422 EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); 480 423 424 + static void ata_acpi_gtf_to_tf(struct ata_device *dev, 425 + const struct ata_acpi_gtf *gtf, 426 + struct ata_taskfile *tf) 427 + { 428 + ata_tf_init(dev, tf); 429 + 430 + tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 431 + tf->protocol = ATA_PROT_NODATA; 432 + tf->feature = gtf->tf[0]; /* 0x1f1 */ 433 + tf->nsect = gtf->tf[1]; /* 0x1f2 */ 434 + tf->lbal = gtf->tf[2]; /* 0x1f3 */ 435 + tf->lbam = gtf->tf[3]; /* 0x1f4 */ 436 + tf->lbah = gtf->tf[4]; /* 0x1f5 */ 437 + tf->device = gtf->tf[5]; /* 0x1f6 */ 438 + tf->command = gtf->tf[6]; /* 0x1f7 */ 439 + } 440 + 441 + static int ata_acpi_filter_tf(const struct ata_taskfile *tf, 442 + const struct ata_taskfile *ptf) 443 + { 444 + if (ata_acpi_gtf_filter & ATA_ACPI_FILTER_SETXFER) { 445 + /* libata doesn't use ACPI to configure transfer mode. 446 + * It will only confuse device configuration. Skip. 447 + */ 448 + if (tf->command == ATA_CMD_SET_FEATURES && 449 + tf->feature == SETFEATURES_XFER) 450 + return 1; 451 + } 452 + 453 + if (ata_acpi_gtf_filter & ATA_ACPI_FILTER_LOCK) { 454 + /* BIOS writers, sorry but we don't wanna lock 455 + * features unless the user explicitly said so. 456 + */ 457 + 458 + /* DEVICE CONFIGURATION FREEZE LOCK */ 459 + if (tf->command == ATA_CMD_CONF_OVERLAY && 460 + tf->feature == ATA_DCO_FREEZE_LOCK) 461 + return 1; 462 + 463 + /* SECURITY FREEZE LOCK */ 464 + if (tf->command == ATA_CMD_SEC_FREEZE_LOCK) 465 + return 1; 466 + 467 + /* SET MAX LOCK and SET MAX FREEZE LOCK */ 468 + if ((!ptf || ptf->command != ATA_CMD_READ_NATIVE_MAX) && 469 + tf->command == ATA_CMD_SET_MAX && 470 + (tf->feature == ATA_SET_MAX_LOCK || 471 + tf->feature == ATA_SET_MAX_FREEZE_LOCK)) 472 + return 1; 473 + } 474 + 475 + return 0; 476 + } 477 + 481 478 /** 482 - * taskfile_load_raw - send taskfile registers to host controller 479 + * ata_acpi_run_tf - send taskfile registers to host controller 483 480 * @dev: target ATA device 484 481 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) 485 482 * ··· 552 441 * EH context. 553 442 * 554 443 * RETURNS: 555 - * 0 on success, -errno on failure. 444 + * 1 if command is executed successfully. 0 if ignored, rejected or 445 + * filtered out, -errno on other errors. 556 446 */ 557 - static int taskfile_load_raw(struct ata_device *dev, 558 - const struct ata_acpi_gtf *gtf) 447 + static int ata_acpi_run_tf(struct ata_device *dev, 448 + const struct ata_acpi_gtf *gtf, 449 + const struct ata_acpi_gtf *prev_gtf) 559 450 { 560 - struct ata_port *ap = dev->link->ap; 561 - struct ata_taskfile tf, rtf; 451 + struct ata_taskfile *pptf = NULL; 452 + struct ata_taskfile tf, ptf, rtf; 562 453 unsigned int err_mask; 454 + const char *level; 455 + char msg[60]; 456 + int rc; 563 457 564 458 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) 565 459 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) 566 460 && (gtf->tf[6] == 0)) 567 461 return 0; 568 462 569 - ata_tf_init(dev, &tf); 570 - 571 - /* convert gtf to tf */ 572 - tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ 573 - tf.protocol = ATA_PROT_NODATA; 574 - tf.feature = gtf->tf[0]; /* 0x1f1 */ 575 - tf.nsect = gtf->tf[1]; /* 0x1f2 */ 576 - tf.lbal = gtf->tf[2]; /* 0x1f3 */ 577 - tf.lbam = gtf->tf[3]; /* 0x1f4 */ 578 - tf.lbah = gtf->tf[4]; /* 0x1f5 */ 579 - tf.device = gtf->tf[5]; /* 0x1f6 */ 580 - tf.command = gtf->tf[6]; /* 0x1f7 */ 581 - 582 - if (ata_msg_probe(ap)) 583 - ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd " 584 - "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n", 585 - tf.command, tf.feature, tf.nsect, 586 - tf.lbal, tf.lbam, tf.lbah, tf.device); 587 - 588 - rtf = tf; 589 - err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0); 590 - if (err_mask) { 591 - ata_dev_printk(dev, KERN_ERR, 592 - "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed " 593 - "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n", 594 - tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam, 595 - tf.lbah, tf.device, err_mask, rtf.command, rtf.feature); 596 - return -EIO; 463 + ata_acpi_gtf_to_tf(dev, gtf, &tf); 464 + if (prev_gtf) { 465 + ata_acpi_gtf_to_tf(dev, prev_gtf, &ptf); 466 + pptf = &ptf; 597 467 } 598 468 599 - return 0; 469 + if (!ata_acpi_filter_tf(&tf, pptf)) { 470 + rtf = tf; 471 + err_mask = ata_exec_internal(dev, &rtf, NULL, 472 + DMA_NONE, NULL, 0, 0); 473 + 474 + switch (err_mask) { 475 + case 0: 476 + level = KERN_DEBUG; 477 + snprintf(msg, sizeof(msg), "succeeded"); 478 + rc = 1; 479 + break; 480 + 481 + case AC_ERR_DEV: 482 + level = KERN_INFO; 483 + snprintf(msg, sizeof(msg), 484 + "rejected by device (Stat=0x%02x Err=0x%02x)", 485 + rtf.command, rtf.feature); 486 + rc = 0; 487 + break; 488 + 489 + default: 490 + level = KERN_ERR; 491 + snprintf(msg, sizeof(msg), 492 + "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)", 493 + err_mask, rtf.command, rtf.feature); 494 + rc = -EIO; 495 + break; 496 + } 497 + } else { 498 + level = KERN_INFO; 499 + snprintf(msg, sizeof(msg), "filtered out"); 500 + rc = 0; 501 + } 502 + 503 + ata_dev_printk(dev, level, 504 + "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x %s\n", 505 + tf.command, tf.feature, tf.nsect, tf.lbal, 506 + tf.lbam, tf.lbah, tf.device, msg); 507 + 508 + return rc; 600 509 } 601 510 602 511 /** 603 512 * ata_acpi_exec_tfs - get then write drive taskfile settings 604 513 * @dev: target ATA device 514 + * @nr_executed: out paramter for the number of executed commands 605 515 * 606 516 * Evaluate _GTF and excute returned taskfiles. 607 517 * ··· 630 498 * EH context. 631 499 * 632 500 * RETURNS: 633 - * Number of executed taskfiles on success, 0 if _GTF doesn't exist or 634 - * doesn't contain valid data. -errno on other errors. 501 + * Number of executed taskfiles on success, 0 if _GTF doesn't exist. 502 + * -errno on other errors. 635 503 */ 636 - static int ata_acpi_exec_tfs(struct ata_device *dev) 504 + static int ata_acpi_exec_tfs(struct ata_device *dev, int *nr_executed) 637 505 { 638 - struct ata_acpi_gtf *gtf = NULL; 639 - void *ptr_to_free = NULL; 506 + struct ata_acpi_gtf *gtf = NULL, *pgtf = NULL; 640 507 int gtf_count, i, rc; 641 508 642 509 /* get taskfiles */ 643 - gtf_count = ata_dev_get_GTF(dev, &gtf, &ptr_to_free); 510 + rc = ata_dev_get_GTF(dev, &gtf); 511 + if (rc < 0) 512 + return rc; 513 + gtf_count = rc; 644 514 645 515 /* execute them */ 646 - for (i = 0, rc = 0; i < gtf_count; i++) { 647 - int tmp; 648 - 649 - /* ACPI errors are eventually ignored. Run till the 650 - * end even after errors. 651 - */ 652 - tmp = taskfile_load_raw(dev, gtf++); 653 - if (!rc) 654 - rc = tmp; 516 + for (i = 0; i < gtf_count; i++, gtf++) { 517 + rc = ata_acpi_run_tf(dev, gtf, pgtf); 518 + if (rc < 0) 519 + break; 520 + if (rc) { 521 + (*nr_executed)++; 522 + pgtf = gtf; 523 + } 655 524 } 656 525 657 - kfree(ptr_to_free); 526 + ata_acpi_clear_gtf(dev); 658 527 659 - if (rc == 0) 660 - return gtf_count; 661 - return rc; 528 + if (rc < 0) 529 + return rc; 530 + return 0; 662 531 } 663 532 664 533 /** ··· 729 596 */ 730 597 int ata_acpi_on_suspend(struct ata_port *ap) 731 598 { 732 - unsigned long flags; 733 - int rc; 734 - 735 - /* proceed iff per-port acpi_handle is valid */ 736 - if (!ap->acpi_handle) 737 - return 0; 738 - BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); 739 - 740 - /* store timing parameters */ 741 - rc = ata_acpi_gtm(ap, &ap->acpi_gtm); 742 - 743 - spin_lock_irqsave(ap->lock, flags); 744 - if (rc == 0) 745 - ap->pflags |= ATA_PFLAG_GTM_VALID; 746 - else 747 - ap->pflags &= ~ATA_PFLAG_GTM_VALID; 748 - spin_unlock_irqrestore(ap->lock, flags); 749 - 750 - if (rc == -ENOENT) 751 - rc = 0; 752 - return rc; 599 + /* nada */ 600 + return 0; 753 601 } 754 602 755 603 /** ··· 745 631 */ 746 632 void ata_acpi_on_resume(struct ata_port *ap) 747 633 { 634 + const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 748 635 struct ata_device *dev; 749 636 750 - if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) { 751 - BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); 637 + if (ap->acpi_handle && gtm) { 638 + /* _GTM valid */ 752 639 753 640 /* restore timing parameters */ 754 - ata_acpi_stm(ap, &ap->acpi_gtm); 755 - } 641 + ata_acpi_stm(ap, gtm); 756 642 757 - /* schedule _GTF */ 758 - ata_link_for_each_dev(dev, &ap->link) 759 - dev->flags |= ATA_DFLAG_ACPI_PENDING; 643 + /* _GTF should immediately follow _STM so that it can 644 + * use values set by _STM. Cache _GTF result and 645 + * schedule _GTF. 646 + */ 647 + ata_link_for_each_dev(dev, &ap->link) { 648 + ata_acpi_clear_gtf(dev); 649 + if (ata_dev_get_GTF(dev, NULL) >= 0) 650 + dev->flags |= ATA_DFLAG_ACPI_PENDING; 651 + } 652 + } else { 653 + /* SATA _GTF needs to be evaulated after _SDD and 654 + * there's no reason to evaluate IDE _GTF early 655 + * without _STM. Clear cache and schedule _GTF. 656 + */ 657 + ata_link_for_each_dev(dev, &ap->link) { 658 + ata_acpi_clear_gtf(dev); 659 + dev->flags |= ATA_DFLAG_ACPI_PENDING; 660 + } 661 + } 760 662 } 761 663 762 664 /** ··· 794 664 struct ata_port *ap = dev->link->ap; 795 665 struct ata_eh_context *ehc = &ap->link.eh_context; 796 666 int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; 667 + int nr_executed = 0; 797 668 int rc; 798 669 799 670 if (!dev->acpi_handle) ··· 813 682 } 814 683 815 684 /* do _GTF */ 816 - rc = ata_acpi_exec_tfs(dev); 817 - if (rc < 0) 685 + rc = ata_acpi_exec_tfs(dev, &nr_executed); 686 + if (rc) 818 687 goto acpi_err; 819 688 820 689 dev->flags &= ~ATA_DFLAG_ACPI_PENDING; 821 690 822 691 /* refresh IDENTIFY page if any _GTF command has been executed */ 823 - if (rc > 0) { 692 + if (nr_executed) { 824 693 rc = ata_dev_reread_id(dev, 0); 825 694 if (rc < 0) { 826 695 ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY " ··· 832 701 return 0; 833 702 834 703 acpi_err: 835 - /* let EH retry on the first failure, disable ACPI on the second */ 836 - if (dev->flags & ATA_DFLAG_ACPI_FAILED) { 837 - ata_dev_printk(dev, KERN_WARNING, "ACPI on devcfg failed the " 838 - "second time, disabling (errno=%d)\n", rc); 704 + /* ignore evaluation failure if we can continue safely */ 705 + if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) 706 + return 0; 839 707 840 - dev->acpi_handle = NULL; 841 - 842 - /* if port is working, request IDENTIFY reload and continue */ 843 - if (!(ap->pflags & ATA_PFLAG_FROZEN)) 844 - rc = 1; 708 + /* fail and let EH retry once more for unknown IO errors */ 709 + if (!(dev->flags & ATA_DFLAG_ACPI_FAILED)) { 710 + dev->flags |= ATA_DFLAG_ACPI_FAILED; 711 + return rc; 845 712 } 846 - dev->flags |= ATA_DFLAG_ACPI_FAILED; 713 + 714 + ata_dev_printk(dev, KERN_WARNING, 715 + "ACPI: failed the second time, disabled\n"); 716 + dev->acpi_handle = NULL; 717 + 718 + /* We can safely continue if no _GTF command has been executed 719 + * and port is not frozen. 720 + */ 721 + if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) 722 + return 0; 723 + 847 724 return rc; 725 + } 726 + 727 + /** 728 + * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled 729 + * @dev: target ATA device 730 + * 731 + * This function is called when @dev is about to be disabled. 732 + * 733 + * LOCKING: 734 + * EH context. 735 + */ 736 + void ata_acpi_on_disable(struct ata_device *dev) 737 + { 738 + ata_acpi_clear_gtf(dev); 848 739 }
+73 -28
drivers/ata/libata-core.c
··· 64 64 #include <linux/libata.h> 65 65 #include <asm/semaphore.h> 66 66 #include <asm/byteorder.h> 67 + #include <linux/cdrom.h> 67 68 68 69 #include "libata.h" 69 70 ··· 623 622 if (ata_dev_enabled(dev)) { 624 623 if (ata_msg_drv(dev->link->ap)) 625 624 ata_dev_printk(dev, KERN_WARNING, "disabled\n"); 625 + ata_acpi_on_disable(dev); 626 626 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | 627 627 ATA_DNXFER_QUIET); 628 628 dev->class++; ··· 3925 3923 /* clear SError */ 3926 3924 if (sata_scr_read(link, SCR_ERROR, &serror) == 0) 3927 3925 sata_scr_write(link, SCR_ERROR, serror); 3926 + link->eh_info.serror = 0; 3928 3927 3929 3928 /* is double-select really necessary? */ 3930 3929 if (classes[0] != ATA_DEV_NONE) ··· 4152 4149 { "HITACHI HDS7250SASUN500G*", NULL, ATA_HORKAGE_NONCQ }, 4153 4150 { "HITACHI HDS7225SBSUN250G*", NULL, ATA_HORKAGE_NONCQ }, 4154 4151 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, 4152 + { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ }, 4155 4153 4156 4154 /* Blacklist entries taken from Silicon Image 3124/3132 4157 4155 Windows driver .inf file - also several Linux problem reports */ ··· 4653 4649 } 4654 4650 4655 4651 /** 4652 + * atapi_qc_may_overflow - Check whether data transfer may overflow 4653 + * @qc: ATA command in question 4654 + * 4655 + * ATAPI commands which transfer variable length data to host 4656 + * might overflow due to application error or hardare bug. This 4657 + * function checks whether overflow should be drained and ignored 4658 + * for @qc. 4659 + * 4660 + * LOCKING: 4661 + * None. 4662 + * 4663 + * RETURNS: 4664 + * 1 if @qc may overflow; otherwise, 0. 4665 + */ 4666 + static int atapi_qc_may_overflow(struct ata_queued_cmd *qc) 4667 + { 4668 + if (qc->tf.protocol != ATA_PROT_ATAPI && 4669 + qc->tf.protocol != ATA_PROT_ATAPI_DMA) 4670 + return 0; 4671 + 4672 + if (qc->tf.flags & ATA_TFLAG_WRITE) 4673 + return 0; 4674 + 4675 + switch (qc->cdb[0]) { 4676 + case READ_10: 4677 + case READ_12: 4678 + case WRITE_10: 4679 + case WRITE_12: 4680 + case GPCMD_READ_CD: 4681 + case GPCMD_READ_CD_MSF: 4682 + return 0; 4683 + } 4684 + 4685 + return 1; 4686 + } 4687 + 4688 + /** 4656 4689 * ata_std_qc_defer - Check whether a qc needs to be deferred 4657 4690 * @qc: ATA command in question 4658 4691 * ··· 5177 5136 * Inherited from caller. 5178 5137 * 5179 5138 */ 5180 - 5181 - static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) 5139 + static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) 5182 5140 { 5183 5141 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 5184 - struct scatterlist *sg = qc->__sg; 5185 - struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem); 5186 5142 struct ata_port *ap = qc->ap; 5143 + struct ata_eh_info *ehi = &qc->dev->link->eh_info; 5144 + struct scatterlist *sg; 5187 5145 struct page *page; 5188 5146 unsigned char *buf; 5189 5147 unsigned int offset, count; 5190 - int no_more_sg = 0; 5191 - 5192 - if (qc->curbytes + bytes >= qc->nbytes) 5193 - ap->hsm_task_state = HSM_ST_LAST; 5194 5148 5195 5149 next_sg: 5196 - if (unlikely(no_more_sg)) { 5150 + sg = qc->cursg; 5151 + if (unlikely(!sg)) { 5197 5152 /* 5198 5153 * The end of qc->sg is reached and the device expects 5199 5154 * more data to transfer. In order not to overrun qc->sg ··· 5198 5161 * - for write case, padding zero data to the device 5199 5162 */ 5200 5163 u16 pad_buf[1] = { 0 }; 5201 - unsigned int words = bytes >> 1; 5202 5164 unsigned int i; 5203 5165 5204 - if (words) /* warning if bytes > 1 */ 5205 - ata_dev_printk(qc->dev, KERN_WARNING, 5206 - "%u bytes trailing data\n", bytes); 5166 + if (bytes > qc->curbytes - qc->nbytes + ATAPI_MAX_DRAIN) { 5167 + ata_ehi_push_desc(ehi, "too much trailing data " 5168 + "buf=%u cur=%u bytes=%u", 5169 + qc->nbytes, qc->curbytes, bytes); 5170 + return -1; 5171 + } 5207 5172 5208 - for (i = 0; i < words; i++) 5173 + /* overflow is exptected for misc ATAPI commands */ 5174 + if (bytes && !atapi_qc_may_overflow(qc)) 5175 + ata_dev_printk(qc->dev, KERN_WARNING, "ATAPI %u bytes " 5176 + "trailing data (cdb=%02x nbytes=%u)\n", 5177 + bytes, qc->cdb[0], qc->nbytes); 5178 + 5179 + for (i = 0; i < (bytes + 1) / 2; i++) 5209 5180 ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write); 5210 5181 5211 - ap->hsm_task_state = HSM_ST_LAST; 5212 - return; 5213 - } 5182 + qc->curbytes += bytes; 5214 5183 5215 - sg = qc->cursg; 5184 + return 0; 5185 + } 5216 5186 5217 5187 page = sg_page(sg); 5218 5188 offset = sg->offset + qc->cursg_ofs; ··· 5254 5210 } 5255 5211 5256 5212 bytes -= count; 5213 + if ((count & 1) && bytes) 5214 + bytes--; 5257 5215 qc->curbytes += count; 5258 5216 qc->cursg_ofs += count; 5259 5217 5260 5218 if (qc->cursg_ofs == sg->length) { 5261 - if (qc->cursg == lsg) 5262 - no_more_sg = 1; 5263 - 5264 5219 qc->cursg = sg_next(qc->cursg); 5265 5220 qc->cursg_ofs = 0; 5266 5221 } 5267 5222 5268 5223 if (bytes) 5269 5224 goto next_sg; 5225 + 5226 + return 0; 5270 5227 } 5271 5228 5272 5229 /** ··· 5310 5265 5311 5266 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); 5312 5267 5313 - __atapi_pio_bytes(qc, bytes); 5268 + if (__atapi_pio_bytes(qc, bytes)) 5269 + goto err_out; 5314 5270 ata_altstatus(ap); /* flush */ 5315 5271 5316 5272 return; ··· 7254 7208 7255 7209 ata_port_wait_eh(ap); 7256 7210 7257 - /* EH is now guaranteed to see UNLOADING, so no new device 7258 - * will be attached. Disable all existing devices. 7211 + /* EH is now guaranteed to see UNLOADING - EH context belongs 7212 + * to us. Disable all existing devices. 7259 7213 */ 7260 - spin_lock_irqsave(ap->lock, flags); 7261 - 7262 7214 ata_port_for_each_link(link, ap) { 7263 7215 ata_link_for_each_dev(dev, link) 7264 7216 ata_dev_disable(dev); 7265 7217 } 7266 - 7267 - spin_unlock_irqrestore(ap->lock, flags); 7268 7218 7269 7219 /* Final freeze & EH. All in-flight commands are aborted. EH 7270 7220 * will be skipped and retrials will be terminated with bad ··· 7293 7251 7294 7252 for (i = 0; i < host->n_ports; i++) 7295 7253 ata_port_detach(host->ports[i]); 7254 + 7255 + /* the host is dead now, dissociate ACPI */ 7256 + ata_acpi_dissociate(host); 7296 7257 } 7297 7258 7298 7259 /**
+2 -2
drivers/ata/libata-eh.c
··· 1264 1264 tf.feature |= ATAPI_PKT_DMA; 1265 1265 } else { 1266 1266 tf.protocol = ATA_PROT_ATAPI; 1267 - tf.lbam = (8 * 1024) & 0xff; 1268 - tf.lbah = (8 * 1024) >> 8; 1267 + tf.lbam = SCSI_SENSE_BUFFERSIZE; 1268 + tf.lbah = 0; 1269 1269 } 1270 1270 1271 1271 return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
+6 -2
drivers/ata/libata.h
··· 108 108 #ifdef CONFIG_ATA_ACPI 109 109 extern void ata_acpi_associate_sata_port(struct ata_port *ap); 110 110 extern void ata_acpi_associate(struct ata_host *host); 111 + extern void ata_acpi_dissociate(struct ata_host *host); 111 112 extern int ata_acpi_on_suspend(struct ata_port *ap); 112 113 extern void ata_acpi_on_resume(struct ata_port *ap); 113 - extern int ata_acpi_on_devcfg(struct ata_device *adev); 114 + extern int ata_acpi_on_devcfg(struct ata_device *dev); 115 + extern void ata_acpi_on_disable(struct ata_device *dev); 114 116 #else 115 117 static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { } 116 118 static inline void ata_acpi_associate(struct ata_host *host) { } 119 + static inline void ata_acpi_dissociate(struct ata_host *host) { } 117 120 static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; } 118 121 static inline void ata_acpi_on_resume(struct ata_port *ap) { } 119 - static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; } 122 + static inline int ata_acpi_on_devcfg(struct ata_device *dev) { return 0; } 123 + static inline void ata_acpi_on_disable(struct ata_device *dev) { } 120 124 #endif 121 125 122 126 /* libata-scsi.c */
+25 -5
drivers/ata/sata_mv.c
··· 2506 2506 if (pdev->vendor == PCI_VENDOR_ID_TTI && 2507 2507 (pdev->device == 0x2300 || pdev->device == 0x2310)) 2508 2508 { 2509 - printk(KERN_WARNING "sata_mv: Highpoint RocketRAID BIOS" 2510 - " will CORRUPT DATA on attached drives when" 2511 - " configured as \"Legacy\". BEWARE!\n"); 2512 - printk(KERN_WARNING "sata_mv: Use BIOS \"JBOD\" volumes" 2513 - " instead for safety.\n"); 2509 + /* 2510 + * Highpoint RocketRAID PCIe 23xx series cards: 2511 + * 2512 + * Unconfigured drives are treated as "Legacy" 2513 + * by the BIOS, and it overwrites sector 8 with 2514 + * a "Lgcy" metadata block prior to Linux boot. 2515 + * 2516 + * Configured drives (RAID or JBOD) leave sector 8 2517 + * alone, but instead overwrite a high numbered 2518 + * sector for the RAID metadata. This sector can 2519 + * be determined exactly, by truncating the physical 2520 + * drive capacity to a nice even GB value. 2521 + * 2522 + * RAID metadata is at: (dev->n_sectors & ~0xfffff) 2523 + * 2524 + * Warn the user, lest they think we're just buggy. 2525 + */ 2526 + printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID" 2527 + " BIOS CORRUPTS DATA on all attached drives," 2528 + " regardless of if/how they are configured." 2529 + " BEWARE!\n"); 2530 + printk(KERN_WARNING DRV_NAME ": For data safety, do not" 2531 + " use sectors 8-9 on \"Legacy\" drives," 2532 + " and avoid the final two gigabytes on" 2533 + " all RocketRAID BIOS initialized drives.\n"); 2514 2534 } 2515 2535 case chip_6042: 2516 2536 hpriv->ops = &mv6xxx_ops;
+7 -11
drivers/ata/sata_sil.c
··· 390 390 sil_scr_read(ap, SCR_ERROR, &serror); 391 391 sil_scr_write(ap, SCR_ERROR, serror); 392 392 393 - /* Trigger hotplug and accumulate SError only if the 394 - * port isn't already frozen. Otherwise, PHY events 395 - * during hardreset makes controllers with broken SIEN 396 - * repeat probing needlessly. 393 + /* Sometimes spurious interrupts occur, double check 394 + * it's PHYRDY CHG. 397 395 */ 398 - if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 399 - ata_ehi_hotplugged(&ap->link.eh_info); 396 + if (serror & SERR_PHYRDY_CHG) { 400 397 ap->link.eh_info.serror |= serror; 398 + goto freeze; 401 399 } 402 400 403 - goto freeze; 401 + if (!(bmdma2 & SIL_DMA_COMPLETE)) 402 + return; 404 403 } 405 404 406 - if (unlikely(!qc)) 407 - goto freeze; 408 - 409 - if (unlikely(qc->tf.flags & ATA_TFLAG_POLLING)) { 405 + if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) { 410 406 /* this sometimes happens, just clear IRQ */ 411 407 ata_chk_status(ap); 412 408 return;
+15
include/linux/ata.h
··· 190 190 ATA_CMD_READ_LOG_EXT = 0x2f, 191 191 ATA_CMD_PMP_READ = 0xE4, 192 192 ATA_CMD_PMP_WRITE = 0xE8, 193 + ATA_CMD_CONF_OVERLAY = 0xB1, 194 + ATA_CMD_SEC_FREEZE_LOCK = 0xF5, 193 195 194 196 /* READ_LOG_EXT pages */ 195 197 ATA_LOG_SATA_NCQ = 0x10, ··· 240 238 /* SETFEATURE Sector counts for SATA features */ 241 239 SATA_AN = 0x05, /* Asynchronous Notification */ 242 240 SATA_DIPM = 0x03, /* Device Initiated Power Management */ 241 + 242 + /* feature values for SET_MAX */ 243 + ATA_SET_MAX_ADDR = 0x00, 244 + ATA_SET_MAX_PASSWD = 0x01, 245 + ATA_SET_MAX_LOCK = 0x02, 246 + ATA_SET_MAX_UNLOCK = 0x03, 247 + ATA_SET_MAX_FREEZE_LOCK = 0x04, 248 + 249 + /* feature values for DEVICE CONFIGURATION OVERLAY */ 250 + ATA_DCO_RESTORE = 0xC0, 251 + ATA_DCO_FREEZE_LOCK = 0xC1, 252 + ATA_DCO_IDENTIFY = 0xC2, 253 + ATA_DCO_SET = 0xC3, 243 254 244 255 /* ATAPI stuff */ 245 256 ATAPI_PKT_DMA = (1 << 0),
+21 -8
include/linux/libata.h
··· 119 119 ATA_DEF_BUSY_WAIT = 10000, 120 120 ATA_SHORT_PAUSE = (HZ >> 6) + 1, 121 121 122 + ATAPI_MAX_DRAIN = 16 << 10, 123 + 122 124 ATA_SHT_EMULATED = 1, 123 125 ATA_SHT_CMD_PER_LUN = 1, 124 126 ATA_SHT_THIS_ID = -1, ··· 213 211 214 212 ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */ 215 213 ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */ 216 - ATA_PFLAG_GTM_VALID = (1 << 19), /* acpi_gtm data valid */ 214 + ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */ 217 215 218 216 /* struct ata_queued_cmd flags */ 219 217 ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */ ··· 500 498 struct scsi_device *sdev; /* attached SCSI device */ 501 499 #ifdef CONFIG_ATA_ACPI 502 500 acpi_handle acpi_handle; 501 + union acpi_object *gtf_cache; 503 502 #endif 504 503 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ 505 504 u64 n_sectors; /* size of device, if ATA */ ··· 656 653 657 654 #ifdef CONFIG_ATA_ACPI 658 655 acpi_handle acpi_handle; 659 - struct ata_acpi_gtm acpi_gtm; 656 + struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ 660 657 #endif 661 658 u8 sector_buf[ATA_SECT_SIZE]; /* owned by EH */ 662 659 }; ··· 942 939 943 940 /* libata-acpi.c */ 944 941 #ifdef CONFIG_ATA_ACPI 942 + static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 943 + { 944 + if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID) 945 + return &ap->__acpi_init_gtm; 946 + return NULL; 947 + } 945 948 extern int ata_acpi_cbl_80wire(struct ata_port *ap); 946 - int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm); 947 - int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *stm); 949 + int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm); 950 + int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm); 948 951 #else 952 + static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 953 + { 954 + return NULL; 955 + } 949 956 static inline int ata_acpi_cbl_80wire(struct ata_port *ap) { return 0; } 950 957 #endif 951 958 ··· 1026 1013 * printk helpers 1027 1014 */ 1028 1015 #define ata_port_printk(ap, lv, fmt, args...) \ 1029 - printk(lv"ata%u: "fmt, (ap)->print_id , ##args) 1016 + printk("%sata%u: "fmt, lv, (ap)->print_id , ##args) 1030 1017 1031 1018 #define ata_link_printk(link, lv, fmt, args...) do { \ 1032 1019 if ((link)->ap->nr_pmp_links) \ 1033 - printk(lv"ata%u.%02u: "fmt, (link)->ap->print_id, \ 1020 + printk("%sata%u.%02u: "fmt, lv, (link)->ap->print_id, \ 1034 1021 (link)->pmp , ##args); \ 1035 1022 else \ 1036 - printk(lv"ata%u: "fmt, (link)->ap->print_id , ##args); \ 1023 + printk("%sata%u: "fmt, lv, (link)->ap->print_id , ##args); \ 1037 1024 } while(0) 1038 1025 1039 1026 #define ata_dev_printk(dev, lv, fmt, args...) \ 1040 - printk(lv"ata%u.%02u: "fmt, (dev)->link->ap->print_id, \ 1027 + printk("%sata%u.%02u: "fmt, lv, (dev)->link->ap->print_id, \ 1041 1028 (dev)->link->pmp + (dev)->devno , ##args) 1042 1029 1043 1030 /*