diff options
author | David Vrabel <david.vrabel@csr.com> | 2008-10-20 11:07:19 -0400 |
---|---|---|
committer | David Vrabel <david.vrabel@csr.com> | 2008-10-20 11:07:19 -0400 |
commit | 61e0e79ee3c609eb34edf2fe023708cba6a79b1f (patch) | |
tree | 663deacffd4071120dc9badb70428fe5f124c7b9 /include/linux/ata.h | |
parent | c15895ef30c2c03e99802951787183039a349d32 (diff) | |
parent | 0cfd81031a26717fe14380d18275f8e217571615 (diff) |
Merge branch 'master' into for-upstream
Conflicts:
Documentation/ABI/testing/sysfs-bus-usb
drivers/Makefile
Diffstat (limited to 'include/linux/ata.h')
-rw-r--r-- | include/linux/ata.h | 127 |
1 files changed, 126 insertions, 1 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h index 8a12d718c169..a53318b8cbd0 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h | |||
@@ -30,6 +30,7 @@ | |||
30 | #define __LINUX_ATA_H__ | 30 | #define __LINUX_ATA_H__ |
31 | 31 | ||
32 | #include <linux/types.h> | 32 | #include <linux/types.h> |
33 | #include <asm/byteorder.h> | ||
33 | 34 | ||
34 | /* defines only for the constants which don't work well as enums */ | 35 | /* defines only for the constants which don't work well as enums */ |
35 | #define ATA_DMA_BOUNDARY 0xffffUL | 36 | #define ATA_DMA_BOUNDARY 0xffffUL |
@@ -88,6 +89,7 @@ enum { | |||
88 | ATA_ID_DLF = 128, | 89 | ATA_ID_DLF = 128, |
89 | ATA_ID_CSFO = 129, | 90 | ATA_ID_CSFO = 129, |
90 | ATA_ID_CFA_POWER = 160, | 91 | ATA_ID_CFA_POWER = 160, |
92 | ATA_ID_ROT_SPEED = 217, | ||
91 | ATA_ID_PIO4 = (1 << 1), | 93 | ATA_ID_PIO4 = (1 << 1), |
92 | 94 | ||
93 | ATA_ID_SERNO_LEN = 20, | 95 | ATA_ID_SERNO_LEN = 20, |
@@ -557,6 +559,15 @@ static inline int ata_id_has_flush(const u16 *id) | |||
557 | return id[ATA_ID_COMMAND_SET_2] & (1 << 12); | 559 | return id[ATA_ID_COMMAND_SET_2] & (1 << 12); |
558 | } | 560 | } |
559 | 561 | ||
562 | static inline int ata_id_flush_enabled(const u16 *id) | ||
563 | { | ||
564 | if (ata_id_has_flush(id) == 0) | ||
565 | return 0; | ||
566 | if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000) | ||
567 | return 0; | ||
568 | return id[ATA_ID_CFS_ENABLE_2] & (1 << 12); | ||
569 | } | ||
570 | |||
560 | static inline int ata_id_has_flush_ext(const u16 *id) | 571 | static inline int ata_id_has_flush_ext(const u16 *id) |
561 | { | 572 | { |
562 | if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000) | 573 | if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000) |
@@ -564,6 +575,19 @@ static inline int ata_id_has_flush_ext(const u16 *id) | |||
564 | return id[ATA_ID_COMMAND_SET_2] & (1 << 13); | 575 | return id[ATA_ID_COMMAND_SET_2] & (1 << 13); |
565 | } | 576 | } |
566 | 577 | ||
578 | static inline int ata_id_flush_ext_enabled(const u16 *id) | ||
579 | { | ||
580 | if (ata_id_has_flush_ext(id) == 0) | ||
581 | return 0; | ||
582 | if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000) | ||
583 | return 0; | ||
584 | /* | ||
585 | * some Maxtor disks have bit 13 defined incorrectly | ||
586 | * so check bit 10 too | ||
587 | */ | ||
588 | return (id[ATA_ID_CFS_ENABLE_2] & 0x2400) == 0x2400; | ||
589 | } | ||
590 | |||
567 | static inline int ata_id_has_lba48(const u16 *id) | 591 | static inline int ata_id_has_lba48(const u16 *id) |
568 | { | 592 | { |
569 | if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000) | 593 | if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000) |
@@ -573,6 +597,15 @@ static inline int ata_id_has_lba48(const u16 *id) | |||
573 | return id[ATA_ID_COMMAND_SET_2] & (1 << 10); | 597 | return id[ATA_ID_COMMAND_SET_2] & (1 << 10); |
574 | } | 598 | } |
575 | 599 | ||
600 | static inline int ata_id_lba48_enabled(const u16 *id) | ||
601 | { | ||
602 | if (ata_id_has_lba48(id) == 0) | ||
603 | return 0; | ||
604 | if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000) | ||
605 | return 0; | ||
606 | return id[ATA_ID_CFS_ENABLE_2] & (1 << 10); | ||
607 | } | ||
608 | |||
576 | static inline int ata_id_hpa_enabled(const u16 *id) | 609 | static inline int ata_id_hpa_enabled(const u16 *id) |
577 | { | 610 | { |
578 | /* Yes children, word 83 valid bits cover word 82 data */ | 611 | /* Yes children, word 83 valid bits cover word 82 data */ |
@@ -644,7 +677,15 @@ static inline unsigned int ata_id_major_version(const u16 *id) | |||
644 | 677 | ||
645 | static inline int ata_id_is_sata(const u16 *id) | 678 | static inline int ata_id_is_sata(const u16 *id) |
646 | { | 679 | { |
647 | return ata_id_major_version(id) >= 5 && id[ATA_ID_HW_CONFIG] == 0; | 680 | /* |
681 | * See if word 93 is 0 AND drive is at least ATA-5 compatible | ||
682 | * verifying that word 80 by casting it to a signed type -- | ||
683 | * this trick allows us to filter out the reserved values of | ||
684 | * 0x0000 and 0xffff along with the earlier ATA revisions... | ||
685 | */ | ||
686 | if (id[ATA_ID_HW_CONFIG] == 0 && (short)id[ATA_ID_MAJOR_VER] >= 0x0020) | ||
687 | return 1; | ||
688 | return 0; | ||
648 | } | 689 | } |
649 | 690 | ||
650 | static inline int ata_id_has_tpm(const u16 *id) | 691 | static inline int ata_id_has_tpm(const u16 *id) |
@@ -667,6 +708,15 @@ static inline int ata_id_has_dword_io(const u16 *id) | |||
667 | return 0; | 708 | return 0; |
668 | } | 709 | } |
669 | 710 | ||
711 | static inline int ata_id_has_unload(const u16 *id) | ||
712 | { | ||
713 | if (ata_id_major_version(id) >= 7 && | ||
714 | (id[ATA_ID_CFSSE] & 0xC000) == 0x4000 && | ||
715 | id[ATA_ID_CFSSE] & (1 << 13)) | ||
716 | return 1; | ||
717 | return 0; | ||
718 | } | ||
719 | |||
670 | static inline int ata_id_current_chs_valid(const u16 *id) | 720 | static inline int ata_id_current_chs_valid(const u16 *id) |
671 | { | 721 | { |
672 | /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command | 722 | /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command |
@@ -691,6 +741,11 @@ static inline int ata_id_is_cfa(const u16 *id) | |||
691 | return 0; | 741 | return 0; |
692 | } | 742 | } |
693 | 743 | ||
744 | static inline int ata_id_is_ssd(const u16 *id) | ||
745 | { | ||
746 | return id[ATA_ID_ROT_SPEED] == 0x01; | ||
747 | } | ||
748 | |||
694 | static inline int ata_drive_40wire(const u16 *dev_id) | 749 | static inline int ata_drive_40wire(const u16 *dev_id) |
695 | { | 750 | { |
696 | if (ata_id_is_sata(dev_id)) | 751 | if (ata_id_is_sata(dev_id)) |
@@ -727,6 +782,76 @@ static inline int atapi_id_dmadir(const u16 *dev_id) | |||
727 | return ata_id_major_version(dev_id) >= 7 && (dev_id[62] & 0x8000); | 782 | return ata_id_major_version(dev_id) >= 7 && (dev_id[62] & 0x8000); |
728 | } | 783 | } |
729 | 784 | ||
785 | /* | ||
786 | * ata_id_is_lba_capacity_ok() performs a sanity check on | ||
787 | * the claimed LBA capacity value for the device. | ||
788 | * | ||
789 | * Returns 1 if LBA capacity looks sensible, 0 otherwise. | ||
790 | * | ||
791 | * It is called only once for each device. | ||
792 | */ | ||
793 | static inline int ata_id_is_lba_capacity_ok(u16 *id) | ||
794 | { | ||
795 | unsigned long lba_sects, chs_sects, head, tail; | ||
796 | |||
797 | /* No non-LBA info .. so valid! */ | ||
798 | if (id[ATA_ID_CYLS] == 0) | ||
799 | return 1; | ||
800 | |||
801 | lba_sects = ata_id_u32(id, ATA_ID_LBA_CAPACITY); | ||
802 | |||
803 | /* | ||
804 | * The ATA spec tells large drives to return | ||
805 | * C/H/S = 16383/16/63 independent of their size. | ||
806 | * Some drives can be jumpered to use 15 heads instead of 16. | ||
807 | * Some drives can be jumpered to use 4092 cyls instead of 16383. | ||
808 | */ | ||
809 | if ((id[ATA_ID_CYLS] == 16383 || | ||
810 | (id[ATA_ID_CYLS] == 4092 && id[ATA_ID_CUR_CYLS] == 16383)) && | ||
811 | id[ATA_ID_SECTORS] == 63 && | ||
812 | (id[ATA_ID_HEADS] == 15 || id[ATA_ID_HEADS] == 16) && | ||
813 | (lba_sects >= 16383 * 63 * id[ATA_ID_HEADS])) | ||
814 | return 1; | ||
815 | |||
816 | chs_sects = id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * id[ATA_ID_SECTORS]; | ||
817 | |||
818 | /* perform a rough sanity check on lba_sects: within 10% is OK */ | ||
819 | if (lba_sects - chs_sects < chs_sects/10) | ||
820 | return 1; | ||
821 | |||
822 | /* some drives have the word order reversed */ | ||
823 | head = (lba_sects >> 16) & 0xffff; | ||
824 | tail = lba_sects & 0xffff; | ||
825 | lba_sects = head | (tail << 16); | ||
826 | |||
827 | if (lba_sects - chs_sects < chs_sects/10) { | ||
828 | *(__le32 *)&id[ATA_ID_LBA_CAPACITY] = __cpu_to_le32(lba_sects); | ||
829 | return 1; /* LBA capacity is (now) good */ | ||
830 | } | ||
831 | |||
832 | return 0; /* LBA capacity value may be bad */ | ||
833 | } | ||
834 | |||
835 | static inline void ata_id_to_hd_driveid(u16 *id) | ||
836 | { | ||
837 | #ifdef __BIG_ENDIAN | ||
838 | /* accessed in struct hd_driveid as 8-bit values */ | ||
839 | id[ATA_ID_MAX_MULTSECT] = __cpu_to_le16(id[ATA_ID_MAX_MULTSECT]); | ||
840 | id[ATA_ID_CAPABILITY] = __cpu_to_le16(id[ATA_ID_CAPABILITY]); | ||
841 | id[ATA_ID_OLD_PIO_MODES] = __cpu_to_le16(id[ATA_ID_OLD_PIO_MODES]); | ||
842 | id[ATA_ID_OLD_DMA_MODES] = __cpu_to_le16(id[ATA_ID_OLD_DMA_MODES]); | ||
843 | id[ATA_ID_MULTSECT] = __cpu_to_le16(id[ATA_ID_MULTSECT]); | ||
844 | |||
845 | /* as 32-bit values */ | ||
846 | *(u32 *)&id[ATA_ID_LBA_CAPACITY] = ata_id_u32(id, ATA_ID_LBA_CAPACITY); | ||
847 | *(u32 *)&id[ATA_ID_SPG] = ata_id_u32(id, ATA_ID_SPG); | ||
848 | |||
849 | /* as 64-bit value */ | ||
850 | *(u64 *)&id[ATA_ID_LBA_CAPACITY_2] = | ||
851 | ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); | ||
852 | #endif | ||
853 | } | ||
854 | |||
730 | static inline int is_multi_taskfile(struct ata_taskfile *tf) | 855 | static inline int is_multi_taskfile(struct ata_taskfile *tf) |
731 | { | 856 | { |
732 | return (tf->command == ATA_CMD_READ_MULTI) || | 857 | return (tf->command == ATA_CMD_READ_MULTI) || |