diff options
Diffstat (limited to 'drivers/ide/ide-iops.c')
-rw-r--r-- | drivers/ide/ide-iops.c | 322 |
1 files changed, 132 insertions, 190 deletions
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c index 2cbadffe922e..5d6ba14e211d 100644 --- a/drivers/ide/ide-iops.c +++ b/drivers/ide/ide-iops.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> | 2 | * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> |
3 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | 3 | * Copyright (C) 2003 Red Hat |
4 | * | 4 | * |
5 | */ | 5 | */ |
6 | 6 | ||
@@ -18,7 +18,6 @@ | |||
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/pci.h> | 19 | #include <linux/pci.h> |
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/hdreg.h> | ||
22 | #include <linux/ide.h> | 21 | #include <linux/ide.h> |
23 | #include <linux/bitops.h> | 22 | #include <linux/bitops.h> |
24 | #include <linux/nmi.h> | 23 | #include <linux/nmi.h> |
@@ -182,7 +181,7 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task) | |||
182 | tf_outb(tf->lbah, io_ports->lbah_addr); | 181 | tf_outb(tf->lbah, io_ports->lbah_addr); |
183 | 182 | ||
184 | if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) | 183 | if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) |
185 | tf_outb((tf->device & HIHI) | drive->select.all, | 184 | tf_outb((tf->device & HIHI) | drive->select, |
186 | io_ports->device_addr); | 185 | io_ports->device_addr); |
187 | } | 186 | } |
188 | EXPORT_SYMBOL_GPL(ide_tf_load); | 187 | EXPORT_SYMBOL_GPL(ide_tf_load); |
@@ -400,97 +399,14 @@ const struct ide_tp_ops default_tp_ops = { | |||
400 | .output_data = ide_output_data, | 399 | .output_data = ide_output_data, |
401 | }; | 400 | }; |
402 | 401 | ||
403 | void ide_fix_driveid (struct hd_driveid *id) | 402 | void ide_fix_driveid(u16 *id) |
404 | { | 403 | { |
405 | #ifndef __LITTLE_ENDIAN | 404 | #ifndef __LITTLE_ENDIAN |
406 | # ifdef __BIG_ENDIAN | 405 | # ifdef __BIG_ENDIAN |
407 | int i; | 406 | int i; |
408 | u16 *stringcast; | 407 | |
409 | 408 | for (i = 0; i < 256; i++) | |
410 | id->config = __le16_to_cpu(id->config); | 409 | id[i] = __le16_to_cpu(id[i]); |
411 | id->cyls = __le16_to_cpu(id->cyls); | ||
412 | id->reserved2 = __le16_to_cpu(id->reserved2); | ||
413 | id->heads = __le16_to_cpu(id->heads); | ||
414 | id->track_bytes = __le16_to_cpu(id->track_bytes); | ||
415 | id->sector_bytes = __le16_to_cpu(id->sector_bytes); | ||
416 | id->sectors = __le16_to_cpu(id->sectors); | ||
417 | id->vendor0 = __le16_to_cpu(id->vendor0); | ||
418 | id->vendor1 = __le16_to_cpu(id->vendor1); | ||
419 | id->vendor2 = __le16_to_cpu(id->vendor2); | ||
420 | stringcast = (u16 *)&id->serial_no[0]; | ||
421 | for (i = 0; i < (20/2); i++) | ||
422 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
423 | id->buf_type = __le16_to_cpu(id->buf_type); | ||
424 | id->buf_size = __le16_to_cpu(id->buf_size); | ||
425 | id->ecc_bytes = __le16_to_cpu(id->ecc_bytes); | ||
426 | stringcast = (u16 *)&id->fw_rev[0]; | ||
427 | for (i = 0; i < (8/2); i++) | ||
428 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
429 | stringcast = (u16 *)&id->model[0]; | ||
430 | for (i = 0; i < (40/2); i++) | ||
431 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
432 | id->dword_io = __le16_to_cpu(id->dword_io); | ||
433 | id->reserved50 = __le16_to_cpu(id->reserved50); | ||
434 | id->field_valid = __le16_to_cpu(id->field_valid); | ||
435 | id->cur_cyls = __le16_to_cpu(id->cur_cyls); | ||
436 | id->cur_heads = __le16_to_cpu(id->cur_heads); | ||
437 | id->cur_sectors = __le16_to_cpu(id->cur_sectors); | ||
438 | id->cur_capacity0 = __le16_to_cpu(id->cur_capacity0); | ||
439 | id->cur_capacity1 = __le16_to_cpu(id->cur_capacity1); | ||
440 | id->lba_capacity = __le32_to_cpu(id->lba_capacity); | ||
441 | id->dma_1word = __le16_to_cpu(id->dma_1word); | ||
442 | id->dma_mword = __le16_to_cpu(id->dma_mword); | ||
443 | id->eide_pio_modes = __le16_to_cpu(id->eide_pio_modes); | ||
444 | id->eide_dma_min = __le16_to_cpu(id->eide_dma_min); | ||
445 | id->eide_dma_time = __le16_to_cpu(id->eide_dma_time); | ||
446 | id->eide_pio = __le16_to_cpu(id->eide_pio); | ||
447 | id->eide_pio_iordy = __le16_to_cpu(id->eide_pio_iordy); | ||
448 | for (i = 0; i < 2; ++i) | ||
449 | id->words69_70[i] = __le16_to_cpu(id->words69_70[i]); | ||
450 | for (i = 0; i < 4; ++i) | ||
451 | id->words71_74[i] = __le16_to_cpu(id->words71_74[i]); | ||
452 | id->queue_depth = __le16_to_cpu(id->queue_depth); | ||
453 | for (i = 0; i < 4; ++i) | ||
454 | id->words76_79[i] = __le16_to_cpu(id->words76_79[i]); | ||
455 | id->major_rev_num = __le16_to_cpu(id->major_rev_num); | ||
456 | id->minor_rev_num = __le16_to_cpu(id->minor_rev_num); | ||
457 | id->command_set_1 = __le16_to_cpu(id->command_set_1); | ||
458 | id->command_set_2 = __le16_to_cpu(id->command_set_2); | ||
459 | id->cfsse = __le16_to_cpu(id->cfsse); | ||
460 | id->cfs_enable_1 = __le16_to_cpu(id->cfs_enable_1); | ||
461 | id->cfs_enable_2 = __le16_to_cpu(id->cfs_enable_2); | ||
462 | id->csf_default = __le16_to_cpu(id->csf_default); | ||
463 | id->dma_ultra = __le16_to_cpu(id->dma_ultra); | ||
464 | id->trseuc = __le16_to_cpu(id->trseuc); | ||
465 | id->trsEuc = __le16_to_cpu(id->trsEuc); | ||
466 | id->CurAPMvalues = __le16_to_cpu(id->CurAPMvalues); | ||
467 | id->mprc = __le16_to_cpu(id->mprc); | ||
468 | id->hw_config = __le16_to_cpu(id->hw_config); | ||
469 | id->acoustic = __le16_to_cpu(id->acoustic); | ||
470 | id->msrqs = __le16_to_cpu(id->msrqs); | ||
471 | id->sxfert = __le16_to_cpu(id->sxfert); | ||
472 | id->sal = __le16_to_cpu(id->sal); | ||
473 | id->spg = __le32_to_cpu(id->spg); | ||
474 | id->lba_capacity_2 = __le64_to_cpu(id->lba_capacity_2); | ||
475 | for (i = 0; i < 22; i++) | ||
476 | id->words104_125[i] = __le16_to_cpu(id->words104_125[i]); | ||
477 | id->last_lun = __le16_to_cpu(id->last_lun); | ||
478 | id->word127 = __le16_to_cpu(id->word127); | ||
479 | id->dlf = __le16_to_cpu(id->dlf); | ||
480 | id->csfo = __le16_to_cpu(id->csfo); | ||
481 | for (i = 0; i < 26; i++) | ||
482 | id->words130_155[i] = __le16_to_cpu(id->words130_155[i]); | ||
483 | id->word156 = __le16_to_cpu(id->word156); | ||
484 | for (i = 0; i < 3; i++) | ||
485 | id->words157_159[i] = __le16_to_cpu(id->words157_159[i]); | ||
486 | id->cfa_power = __le16_to_cpu(id->cfa_power); | ||
487 | for (i = 0; i < 15; i++) | ||
488 | id->words161_175[i] = __le16_to_cpu(id->words161_175[i]); | ||
489 | for (i = 0; i < 30; i++) | ||
490 | id->words176_205[i] = __le16_to_cpu(id->words176_205[i]); | ||
491 | for (i = 0; i < 49; i++) | ||
492 | id->words206_254[i] = __le16_to_cpu(id->words206_254[i]); | ||
493 | id->integrity_word = __le16_to_cpu(id->integrity_word); | ||
494 | # else | 410 | # else |
495 | # error "Please fix <asm/byteorder.h>" | 411 | # error "Please fix <asm/byteorder.h>" |
496 | # endif | 412 | # endif |
@@ -501,19 +417,21 @@ void ide_fix_driveid (struct hd_driveid *id) | |||
501 | * ide_fixstring() cleans up and (optionally) byte-swaps a text string, | 417 | * ide_fixstring() cleans up and (optionally) byte-swaps a text string, |
502 | * removing leading/trailing blanks and compressing internal blanks. | 418 | * removing leading/trailing blanks and compressing internal blanks. |
503 | * It is primarily used to tidy up the model name/number fields as | 419 | * It is primarily used to tidy up the model name/number fields as |
504 | * returned by the WIN_[P]IDENTIFY commands. | 420 | * returned by the ATA_CMD_ID_ATA[PI] commands. |
505 | */ | 421 | */ |
506 | 422 | ||
507 | void ide_fixstring (u8 *s, const int bytecount, const int byteswap) | 423 | void ide_fixstring (u8 *s, const int bytecount, const int byteswap) |
508 | { | 424 | { |
509 | u8 *p = s, *end = &s[bytecount & ~1]; /* bytecount must be even */ | 425 | u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */ |
510 | 426 | ||
511 | if (byteswap) { | 427 | if (byteswap) { |
512 | /* convert from big-endian to host byte order */ | 428 | /* convert from big-endian to host byte order */ |
513 | for (p = end ; p != s;) | 429 | for (p = s ; p != end ; p += 2) |
514 | be16_to_cpus((u16 *)(p -= 2)); | 430 | be16_to_cpus((u16 *) p); |
515 | } | 431 | } |
432 | |||
516 | /* strip leading blanks */ | 433 | /* strip leading blanks */ |
434 | p = s; | ||
517 | while (s != end && *s == ' ') | 435 | while (s != end && *s == ' ') |
518 | ++s; | 436 | ++s; |
519 | /* compress internal blanks and strip trailing blanks */ | 437 | /* compress internal blanks and strip trailing blanks */ |
@@ -556,7 +474,7 @@ int drive_is_ready (ide_drive_t *drive) | |||
556 | /* Note: this may clear a pending IRQ!! */ | 474 | /* Note: this may clear a pending IRQ!! */ |
557 | stat = hwif->tp_ops->read_status(hwif); | 475 | stat = hwif->tp_ops->read_status(hwif); |
558 | 476 | ||
559 | if (stat & BUSY_STAT) | 477 | if (stat & ATA_BUSY) |
560 | /* drive busy: definitely not interrupting */ | 478 | /* drive busy: definitely not interrupting */ |
561 | return 0; | 479 | return 0; |
562 | 480 | ||
@@ -588,10 +506,10 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti | |||
588 | udelay(1); /* spec allows drive 400ns to assert "BUSY" */ | 506 | udelay(1); /* spec allows drive 400ns to assert "BUSY" */ |
589 | stat = tp_ops->read_status(hwif); | 507 | stat = tp_ops->read_status(hwif); |
590 | 508 | ||
591 | if (stat & BUSY_STAT) { | 509 | if (stat & ATA_BUSY) { |
592 | local_irq_set(flags); | 510 | local_irq_set(flags); |
593 | timeout += jiffies; | 511 | timeout += jiffies; |
594 | while ((stat = tp_ops->read_status(hwif)) & BUSY_STAT) { | 512 | while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) { |
595 | if (time_after(jiffies, timeout)) { | 513 | if (time_after(jiffies, timeout)) { |
596 | /* | 514 | /* |
597 | * One last read after the timeout in case | 515 | * One last read after the timeout in case |
@@ -599,7 +517,7 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti | |||
599 | * progress during the timeout.. | 517 | * progress during the timeout.. |
600 | */ | 518 | */ |
601 | stat = tp_ops->read_status(hwif); | 519 | stat = tp_ops->read_status(hwif); |
602 | if (!(stat & BUSY_STAT)) | 520 | if ((stat & ATA_BUSY) == 0) |
603 | break; | 521 | break; |
604 | 522 | ||
605 | local_irq_restore(flags); | 523 | local_irq_restore(flags); |
@@ -660,18 +578,18 @@ EXPORT_SYMBOL(ide_wait_stat); | |||
660 | /** | 578 | /** |
661 | * ide_in_drive_list - look for drive in black/white list | 579 | * ide_in_drive_list - look for drive in black/white list |
662 | * @id: drive identifier | 580 | * @id: drive identifier |
663 | * @drive_table: list to inspect | 581 | * @table: list to inspect |
664 | * | 582 | * |
665 | * Look for a drive in the blacklist and the whitelist tables | 583 | * Look for a drive in the blacklist and the whitelist tables |
666 | * Returns 1 if the drive is found in the table. | 584 | * Returns 1 if the drive is found in the table. |
667 | */ | 585 | */ |
668 | 586 | ||
669 | int ide_in_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table) | 587 | int ide_in_drive_list(u16 *id, const struct drive_list_entry *table) |
670 | { | 588 | { |
671 | for ( ; drive_table->id_model; drive_table++) | 589 | for ( ; table->id_model; table++) |
672 | if ((!strcmp(drive_table->id_model, id->model)) && | 590 | if ((!strcmp(table->id_model, (char *)&id[ATA_ID_PROD])) && |
673 | (!drive_table->id_firmware || | 591 | (!table->id_firmware || |
674 | strstr(id->fw_rev, drive_table->id_firmware))) | 592 | strstr((char *)&id[ATA_ID_FW_REV], table->id_firmware))) |
675 | return 1; | 593 | return 1; |
676 | return 0; | 594 | return 0; |
677 | } | 595 | } |
@@ -702,7 +620,7 @@ static const struct drive_list_entry ivb_list[] = { | |||
702 | u8 eighty_ninty_three (ide_drive_t *drive) | 620 | u8 eighty_ninty_three (ide_drive_t *drive) |
703 | { | 621 | { |
704 | ide_hwif_t *hwif = drive->hwif; | 622 | ide_hwif_t *hwif = drive->hwif; |
705 | struct hd_driveid *id = drive->id; | 623 | u16 *id = drive->id; |
706 | int ivb = ide_in_drive_list(id, ivb_list); | 624 | int ivb = ide_in_drive_list(id, ivb_list); |
707 | 625 | ||
708 | if (hwif->cbl == ATA_CBL_PATA40_SHORT) | 626 | if (hwif->cbl == ATA_CBL_PATA40_SHORT) |
@@ -712,7 +630,7 @@ u8 eighty_ninty_three (ide_drive_t *drive) | |||
712 | printk(KERN_DEBUG "%s: skipping word 93 validity check\n", | 630 | printk(KERN_DEBUG "%s: skipping word 93 validity check\n", |
713 | drive->name); | 631 | drive->name); |
714 | 632 | ||
715 | if (ide_dev_is_sata(id) && !ivb) | 633 | if (ata_id_is_sata(id) && !ivb) |
716 | return 1; | 634 | return 1; |
717 | 635 | ||
718 | if (hwif->cbl != ATA_CBL_PATA80 && !ivb) | 636 | if (hwif->cbl != ATA_CBL_PATA80 && !ivb) |
@@ -724,11 +642,12 @@ u8 eighty_ninty_three (ide_drive_t *drive) | |||
724 | * - force bit13 (80c cable present) check also for !ivb devices | 642 | * - force bit13 (80c cable present) check also for !ivb devices |
725 | * (unless the slave device is pre-ATA3) | 643 | * (unless the slave device is pre-ATA3) |
726 | */ | 644 | */ |
727 | if ((id->hw_config & 0x4000) || (ivb && (id->hw_config & 0x2000))) | 645 | if ((id[ATA_ID_HW_CONFIG] & 0x4000) || |
646 | (ivb && (id[ATA_ID_HW_CONFIG] & 0x2000))) | ||
728 | return 1; | 647 | return 1; |
729 | 648 | ||
730 | no_80w: | 649 | no_80w: |
731 | if (drive->udma33_warned == 1) | 650 | if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED) |
732 | return 0; | 651 | return 0; |
733 | 652 | ||
734 | printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, " | 653 | printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, " |
@@ -736,7 +655,7 @@ no_80w: | |||
736 | drive->name, | 655 | drive->name, |
737 | hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host"); | 656 | hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host"); |
738 | 657 | ||
739 | drive->udma33_warned = 1; | 658 | drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED; |
740 | 659 | ||
741 | return 0; | 660 | return 0; |
742 | } | 661 | } |
@@ -745,8 +664,8 @@ int ide_driveid_update(ide_drive_t *drive) | |||
745 | { | 664 | { |
746 | ide_hwif_t *hwif = drive->hwif; | 665 | ide_hwif_t *hwif = drive->hwif; |
747 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; | 666 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
748 | struct hd_driveid *id; | 667 | u16 *id; |
749 | unsigned long timeout, flags; | 668 | unsigned long flags; |
750 | u8 stat; | 669 | u8 stat; |
751 | 670 | ||
752 | /* | 671 | /* |
@@ -757,29 +676,24 @@ int ide_driveid_update(ide_drive_t *drive) | |||
757 | SELECT_MASK(drive, 1); | 676 | SELECT_MASK(drive, 1); |
758 | tp_ops->set_irq(hwif, 0); | 677 | tp_ops->set_irq(hwif, 0); |
759 | msleep(50); | 678 | msleep(50); |
760 | tp_ops->exec_command(hwif, WIN_IDENTIFY); | 679 | tp_ops->exec_command(hwif, ATA_CMD_ID_ATA); |
761 | timeout = jiffies + WAIT_WORSTCASE; | ||
762 | do { | ||
763 | if (time_after(jiffies, timeout)) { | ||
764 | SELECT_MASK(drive, 0); | ||
765 | return 0; /* drive timed-out */ | ||
766 | } | ||
767 | 680 | ||
768 | msleep(50); /* give drive a breather */ | 681 | if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 1)) { |
769 | stat = tp_ops->read_altstatus(hwif); | 682 | SELECT_MASK(drive, 0); |
770 | } while (stat & BUSY_STAT); | 683 | return 0; |
684 | } | ||
771 | 685 | ||
772 | msleep(50); /* wait for IRQ and DRQ_STAT */ | 686 | msleep(50); /* wait for IRQ and ATA_DRQ */ |
773 | stat = tp_ops->read_status(hwif); | 687 | stat = tp_ops->read_status(hwif); |
774 | 688 | ||
775 | if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) { | 689 | if (!OK_STAT(stat, ATA_DRQ, BAD_R_STAT)) { |
776 | SELECT_MASK(drive, 0); | 690 | SELECT_MASK(drive, 0); |
777 | printk("%s: CHECK for good STATUS\n", drive->name); | 691 | printk("%s: CHECK for good STATUS\n", drive->name); |
778 | return 0; | 692 | return 0; |
779 | } | 693 | } |
780 | local_irq_save(flags); | 694 | local_irq_save(flags); |
781 | SELECT_MASK(drive, 0); | 695 | SELECT_MASK(drive, 0); |
782 | id = kmalloc(SECTOR_WORDS*4, GFP_ATOMIC); | 696 | id = kmalloc(SECTOR_SIZE, GFP_ATOMIC); |
783 | if (!id) { | 697 | if (!id) { |
784 | local_irq_restore(flags); | 698 | local_irq_restore(flags); |
785 | return 0; | 699 | return 0; |
@@ -789,16 +703,16 @@ int ide_driveid_update(ide_drive_t *drive) | |||
789 | local_irq_enable(); | 703 | local_irq_enable(); |
790 | local_irq_restore(flags); | 704 | local_irq_restore(flags); |
791 | ide_fix_driveid(id); | 705 | ide_fix_driveid(id); |
792 | if (id) { | 706 | |
793 | drive->id->dma_ultra = id->dma_ultra; | 707 | drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES]; |
794 | drive->id->dma_mword = id->dma_mword; | 708 | drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES]; |
795 | drive->id->dma_1word = id->dma_1word; | 709 | drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES]; |
796 | /* anything more ? */ | 710 | /* anything more ? */ |
797 | kfree(id); | 711 | |
798 | 712 | kfree(id); | |
799 | if (drive->using_dma && ide_id_dma_bug(drive)) | 713 | |
800 | ide_dma_off(drive); | 714 | if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive)) |
801 | } | 715 | ide_dma_off(drive); |
802 | 716 | ||
803 | return 1; | 717 | return 1; |
804 | } | 718 | } |
@@ -807,6 +721,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed) | |||
807 | { | 721 | { |
808 | ide_hwif_t *hwif = drive->hwif; | 722 | ide_hwif_t *hwif = drive->hwif; |
809 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; | 723 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
724 | u16 *id = drive->id, i; | ||
810 | int error = 0; | 725 | int error = 0; |
811 | u8 stat; | 726 | u8 stat; |
812 | ide_task_t task; | 727 | ide_task_t task; |
@@ -817,7 +732,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed) | |||
817 | #endif | 732 | #endif |
818 | 733 | ||
819 | /* Skip setting PIO flow-control modes on pre-EIDE drives */ | 734 | /* Skip setting PIO flow-control modes on pre-EIDE drives */ |
820 | if ((speed & 0xf8) == XFER_PIO_0 && !(drive->id->capability & 0x08)) | 735 | if ((speed & 0xf8) == XFER_PIO_0 && ata_id_has_iordy(drive->id) == 0) |
821 | goto skip; | 736 | goto skip; |
822 | 737 | ||
823 | /* | 738 | /* |
@@ -840,7 +755,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed) | |||
840 | 755 | ||
841 | udelay(1); | 756 | udelay(1); |
842 | SELECT_DRIVE(drive); | 757 | SELECT_DRIVE(drive); |
843 | SELECT_MASK(drive, 0); | 758 | SELECT_MASK(drive, 1); |
844 | udelay(1); | 759 | udelay(1); |
845 | tp_ops->set_irq(hwif, 0); | 760 | tp_ops->set_irq(hwif, 0); |
846 | 761 | ||
@@ -851,13 +766,13 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed) | |||
851 | 766 | ||
852 | tp_ops->tf_load(drive, &task); | 767 | tp_ops->tf_load(drive, &task); |
853 | 768 | ||
854 | tp_ops->exec_command(hwif, WIN_SETFEATURES); | 769 | tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES); |
855 | 770 | ||
856 | if (drive->quirk_list == 2) | 771 | if (drive->quirk_list == 2) |
857 | tp_ops->set_irq(hwif, 1); | 772 | tp_ops->set_irq(hwif, 1); |
858 | 773 | ||
859 | error = __ide_wait_stat(drive, drive->ready_stat, | 774 | error = __ide_wait_stat(drive, drive->ready_stat, |
860 | BUSY_STAT|DRQ_STAT|ERR_STAT, | 775 | ATA_BUSY | ATA_DRQ | ATA_ERR, |
861 | WAIT_CMD, &stat); | 776 | WAIT_CMD, &stat); |
862 | 777 | ||
863 | SELECT_MASK(drive, 0); | 778 | SELECT_MASK(drive, 0); |
@@ -869,35 +784,29 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed) | |||
869 | return error; | 784 | return error; |
870 | } | 785 | } |
871 | 786 | ||
872 | drive->id->dma_ultra &= ~0xFF00; | 787 | id[ATA_ID_UDMA_MODES] &= ~0xFF00; |
873 | drive->id->dma_mword &= ~0x0F00; | 788 | id[ATA_ID_MWDMA_MODES] &= ~0x0F00; |
874 | drive->id->dma_1word &= ~0x0F00; | 789 | id[ATA_ID_SWDMA_MODES] &= ~0x0F00; |
875 | 790 | ||
876 | skip: | 791 | skip: |
877 | #ifdef CONFIG_BLK_DEV_IDEDMA | 792 | #ifdef CONFIG_BLK_DEV_IDEDMA |
878 | if (speed >= XFER_SW_DMA_0 && drive->using_dma) | 793 | if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA)) |
879 | hwif->dma_ops->dma_host_set(drive, 1); | 794 | hwif->dma_ops->dma_host_set(drive, 1); |
880 | else if (hwif->dma_ops) /* check if host supports DMA */ | 795 | else if (hwif->dma_ops) /* check if host supports DMA */ |
881 | ide_dma_off_quietly(drive); | 796 | ide_dma_off_quietly(drive); |
882 | #endif | 797 | #endif |
883 | 798 | ||
884 | switch(speed) { | 799 | if (speed >= XFER_UDMA_0) { |
885 | case XFER_UDMA_7: drive->id->dma_ultra |= 0x8080; break; | 800 | i = 1 << (speed - XFER_UDMA_0); |
886 | case XFER_UDMA_6: drive->id->dma_ultra |= 0x4040; break; | 801 | id[ATA_ID_UDMA_MODES] |= (i << 8 | i); |
887 | case XFER_UDMA_5: drive->id->dma_ultra |= 0x2020; break; | 802 | } else if (speed >= XFER_MW_DMA_0) { |
888 | case XFER_UDMA_4: drive->id->dma_ultra |= 0x1010; break; | 803 | i = 1 << (speed - XFER_MW_DMA_0); |
889 | case XFER_UDMA_3: drive->id->dma_ultra |= 0x0808; break; | 804 | id[ATA_ID_MWDMA_MODES] |= (i << 8 | i); |
890 | case XFER_UDMA_2: drive->id->dma_ultra |= 0x0404; break; | 805 | } else if (speed >= XFER_SW_DMA_0) { |
891 | case XFER_UDMA_1: drive->id->dma_ultra |= 0x0202; break; | 806 | i = 1 << (speed - XFER_SW_DMA_0); |
892 | case XFER_UDMA_0: drive->id->dma_ultra |= 0x0101; break; | 807 | id[ATA_ID_SWDMA_MODES] |= (i << 8 | i); |
893 | case XFER_MW_DMA_2: drive->id->dma_mword |= 0x0404; break; | ||
894 | case XFER_MW_DMA_1: drive->id->dma_mword |= 0x0202; break; | ||
895 | case XFER_MW_DMA_0: drive->id->dma_mword |= 0x0101; break; | ||
896 | case XFER_SW_DMA_2: drive->id->dma_1word |= 0x0404; break; | ||
897 | case XFER_SW_DMA_1: drive->id->dma_1word |= 0x0202; break; | ||
898 | case XFER_SW_DMA_0: drive->id->dma_1word |= 0x0101; break; | ||
899 | default: break; | ||
900 | } | 808 | } |
809 | |||
901 | if (!drive->init_speed) | 810 | if (!drive->init_speed) |
902 | drive->init_speed = speed; | 811 | drive->init_speed = speed; |
903 | drive->current_speed = speed; | 812 | drive->current_speed = speed; |
@@ -977,7 +886,7 @@ void ide_execute_pkt_cmd(ide_drive_t *drive) | |||
977 | unsigned long flags; | 886 | unsigned long flags; |
978 | 887 | ||
979 | spin_lock_irqsave(&ide_lock, flags); | 888 | spin_lock_irqsave(&ide_lock, flags); |
980 | hwif->tp_ops->exec_command(hwif, WIN_PACKETCMD); | 889 | hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET); |
981 | ndelay(400); | 890 | ndelay(400); |
982 | spin_unlock_irqrestore(&ide_lock, flags); | 891 | spin_unlock_irqrestore(&ide_lock, flags); |
983 | } | 892 | } |
@@ -1010,7 +919,7 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) | |||
1010 | udelay (10); | 919 | udelay (10); |
1011 | stat = hwif->tp_ops->read_status(hwif); | 920 | stat = hwif->tp_ops->read_status(hwif); |
1012 | 921 | ||
1013 | if (OK_STAT(stat, 0, BUSY_STAT)) | 922 | if (OK_STAT(stat, 0, ATA_BUSY)) |
1014 | printk("%s: ATAPI reset complete\n", drive->name); | 923 | printk("%s: ATAPI reset complete\n", drive->name); |
1015 | else { | 924 | else { |
1016 | if (time_before(jiffies, hwgroup->poll_timeout)) { | 925 | if (time_before(jiffies, hwgroup->poll_timeout)) { |
@@ -1031,6 +940,25 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) | |||
1031 | return ide_stopped; | 940 | return ide_stopped; |
1032 | } | 941 | } |
1033 | 942 | ||
943 | static void ide_reset_report_error(ide_hwif_t *hwif, u8 err) | ||
944 | { | ||
945 | static const char *err_master_vals[] = | ||
946 | { NULL, "passed", "formatter device error", | ||
947 | "sector buffer error", "ECC circuitry error", | ||
948 | "controlling MPU error" }; | ||
949 | |||
950 | u8 err_master = err & 0x7f; | ||
951 | |||
952 | printk(KERN_ERR "%s: reset: master: ", hwif->name); | ||
953 | if (err_master && err_master < 6) | ||
954 | printk(KERN_CONT "%s", err_master_vals[err_master]); | ||
955 | else | ||
956 | printk(KERN_CONT "error (0x%02x?)", err); | ||
957 | if (err & 0x80) | ||
958 | printk(KERN_CONT "; slave: failed"); | ||
959 | printk(KERN_CONT "\n"); | ||
960 | } | ||
961 | |||
1034 | /* | 962 | /* |
1035 | * reset_pollfunc() gets invoked to poll the interface for completion every 50ms | 963 | * reset_pollfunc() gets invoked to poll the interface for completion every 50ms |
1036 | * during an ide reset operation. If the drives have not yet responded, | 964 | * during an ide reset operation. If the drives have not yet responded, |
@@ -1056,7 +984,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | |||
1056 | 984 | ||
1057 | tmp = hwif->tp_ops->read_status(hwif); | 985 | tmp = hwif->tp_ops->read_status(hwif); |
1058 | 986 | ||
1059 | if (!OK_STAT(tmp, 0, BUSY_STAT)) { | 987 | if (!OK_STAT(tmp, 0, ATA_BUSY)) { |
1060 | if (time_before(jiffies, hwgroup->poll_timeout)) { | 988 | if (time_before(jiffies, hwgroup->poll_timeout)) { |
1061 | ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); | 989 | ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); |
1062 | /* continue polling */ | 990 | /* continue polling */ |
@@ -1066,31 +994,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | |||
1066 | drive->failures++; | 994 | drive->failures++; |
1067 | err = -EIO; | 995 | err = -EIO; |
1068 | } else { | 996 | } else { |
1069 | printk("%s: reset: ", hwif->name); | ||
1070 | tmp = ide_read_error(drive); | 997 | tmp = ide_read_error(drive); |
1071 | 998 | ||
1072 | if (tmp == 1) { | 999 | if (tmp == 1) { |
1073 | printk("success\n"); | 1000 | printk(KERN_INFO "%s: reset: success\n", hwif->name); |
1074 | drive->failures = 0; | 1001 | drive->failures = 0; |
1075 | } else { | 1002 | } else { |
1003 | ide_reset_report_error(hwif, tmp); | ||
1076 | drive->failures++; | 1004 | drive->failures++; |
1077 | printk("master: "); | ||
1078 | switch (tmp & 0x7f) { | ||
1079 | case 1: printk("passed"); | ||
1080 | break; | ||
1081 | case 2: printk("formatter device error"); | ||
1082 | break; | ||
1083 | case 3: printk("sector buffer error"); | ||
1084 | break; | ||
1085 | case 4: printk("ECC circuitry error"); | ||
1086 | break; | ||
1087 | case 5: printk("controlling MPU error"); | ||
1088 | break; | ||
1089 | default:printk("error (0x%02x?)", tmp); | ||
1090 | } | ||
1091 | if (tmp & 0x80) | ||
1092 | printk("; slave: failed"); | ||
1093 | printk("\n"); | ||
1094 | err = -EIO; | 1005 | err = -EIO; |
1095 | } | 1006 | } |
1096 | } | 1007 | } |
@@ -1102,14 +1013,19 @@ out: | |||
1102 | 1013 | ||
1103 | static void ide_disk_pre_reset(ide_drive_t *drive) | 1014 | static void ide_disk_pre_reset(ide_drive_t *drive) |
1104 | { | 1015 | { |
1105 | int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1; | 1016 | int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1; |
1106 | 1017 | ||
1107 | drive->special.all = 0; | 1018 | drive->special.all = 0; |
1108 | drive->special.b.set_geometry = legacy; | 1019 | drive->special.b.set_geometry = legacy; |
1109 | drive->special.b.recalibrate = legacy; | 1020 | drive->special.b.recalibrate = legacy; |
1021 | |||
1110 | drive->mult_count = 0; | 1022 | drive->mult_count = 0; |
1111 | if (!drive->keep_settings && !drive->using_dma) | 1023 | drive->dev_flags &= ~IDE_DFLAG_PARKED; |
1024 | |||
1025 | if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 && | ||
1026 | (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) | ||
1112 | drive->mult_req = 0; | 1027 | drive->mult_req = 0; |
1028 | |||
1113 | if (drive->mult_req != drive->mult_count) | 1029 | if (drive->mult_req != drive->mult_count) |
1114 | drive->special.b.set_multmode = 1; | 1030 | drive->special.b.set_multmode = 1; |
1115 | } | 1031 | } |
@@ -1121,18 +1037,18 @@ static void pre_reset(ide_drive_t *drive) | |||
1121 | if (drive->media == ide_disk) | 1037 | if (drive->media == ide_disk) |
1122 | ide_disk_pre_reset(drive); | 1038 | ide_disk_pre_reset(drive); |
1123 | else | 1039 | else |
1124 | drive->post_reset = 1; | 1040 | drive->dev_flags |= IDE_DFLAG_POST_RESET; |
1125 | 1041 | ||
1126 | if (drive->using_dma) { | 1042 | if (drive->dev_flags & IDE_DFLAG_USING_DMA) { |
1127 | if (drive->crc_count) | 1043 | if (drive->crc_count) |
1128 | ide_check_dma_crc(drive); | 1044 | ide_check_dma_crc(drive); |
1129 | else | 1045 | else |
1130 | ide_dma_off(drive); | 1046 | ide_dma_off(drive); |
1131 | } | 1047 | } |
1132 | 1048 | ||
1133 | if (!drive->keep_settings) { | 1049 | if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) { |
1134 | if (!drive->using_dma) { | 1050 | if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) { |
1135 | drive->unmask = 0; | 1051 | drive->dev_flags &= ~IDE_DFLAG_UNMASK; |
1136 | drive->io_32bit = 0; | 1052 | drive->io_32bit = 0; |
1137 | } | 1053 | } |
1138 | return; | 1054 | return; |
@@ -1164,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive) | |||
1164 | static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | 1080 | static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) |
1165 | { | 1081 | { |
1166 | unsigned int unit; | 1082 | unsigned int unit; |
1167 | unsigned long flags; | 1083 | unsigned long flags, timeout; |
1168 | ide_hwif_t *hwif; | 1084 | ide_hwif_t *hwif; |
1169 | ide_hwgroup_t *hwgroup; | 1085 | ide_hwgroup_t *hwgroup; |
1170 | struct ide_io_ports *io_ports; | 1086 | struct ide_io_ports *io_ports; |
1171 | const struct ide_tp_ops *tp_ops; | 1087 | const struct ide_tp_ops *tp_ops; |
1172 | const struct ide_port_ops *port_ops; | 1088 | const struct ide_port_ops *port_ops; |
1089 | DEFINE_WAIT(wait); | ||
1173 | 1090 | ||
1174 | spin_lock_irqsave(&ide_lock, flags); | 1091 | spin_lock_irqsave(&ide_lock, flags); |
1175 | hwif = HWIF(drive); | 1092 | hwif = HWIF(drive); |
@@ -1187,7 +1104,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | |||
1187 | pre_reset(drive); | 1104 | pre_reset(drive); |
1188 | SELECT_DRIVE(drive); | 1105 | SELECT_DRIVE(drive); |
1189 | udelay (20); | 1106 | udelay (20); |
1190 | tp_ops->exec_command(hwif, WIN_SRST); | 1107 | tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); |
1191 | ndelay(400); | 1108 | ndelay(400); |
1192 | hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; | 1109 | hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; |
1193 | hwgroup->polling = 1; | 1110 | hwgroup->polling = 1; |
@@ -1196,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | |||
1196 | return ide_started; | 1113 | return ide_started; |
1197 | } | 1114 | } |
1198 | 1115 | ||
1116 | /* We must not disturb devices in the IDE_DFLAG_PARKED state. */ | ||
1117 | do { | ||
1118 | unsigned long now; | ||
1119 | |||
1120 | prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE); | ||
1121 | timeout = jiffies; | ||
1122 | for (unit = 0; unit < MAX_DRIVES; unit++) { | ||
1123 | ide_drive_t *tdrive = &hwif->drives[unit]; | ||
1124 | |||
1125 | if (tdrive->dev_flags & IDE_DFLAG_PRESENT && | ||
1126 | tdrive->dev_flags & IDE_DFLAG_PARKED && | ||
1127 | time_after(tdrive->sleep, timeout)) | ||
1128 | timeout = tdrive->sleep; | ||
1129 | } | ||
1130 | |||
1131 | now = jiffies; | ||
1132 | if (time_before_eq(timeout, now)) | ||
1133 | break; | ||
1134 | |||
1135 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1136 | timeout = schedule_timeout_uninterruptible(timeout - now); | ||
1137 | spin_lock_irqsave(&ide_lock, flags); | ||
1138 | } while (timeout); | ||
1139 | finish_wait(&ide_park_wq, &wait); | ||
1140 | |||
1199 | /* | 1141 | /* |
1200 | * First, reset any device state data we were maintaining | 1142 | * First, reset any device state data we were maintaining |
1201 | * for any of the drives on this interface. | 1143 | * for any of the drives on this interface. |
@@ -1270,7 +1212,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout) | |||
1270 | */ | 1212 | */ |
1271 | mdelay(1); | 1213 | mdelay(1); |
1272 | stat = hwif->tp_ops->read_status(hwif); | 1214 | stat = hwif->tp_ops->read_status(hwif); |
1273 | if ((stat & BUSY_STAT) == 0) | 1215 | if ((stat & ATA_BUSY) == 0) |
1274 | return 0; | 1216 | return 0; |
1275 | /* | 1217 | /* |
1276 | * Assume a value of 0xff means nothing is connected to | 1218 | * Assume a value of 0xff means nothing is connected to |