aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ata.h
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:31 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:31 -0400
commita02227c9774b3bff08c7f557d06247e0a03ac435 (patch)
tree53bd926333ce6269043fae426144312e163e1fe9 /include/linux/ata.h
parent93734a234447a3c091f76d76f7351af9d4dde518 (diff)
ide: lba_capacity_is_ok() -> ata_id_is_lba_capacity_ok()
Rename lba_capacity_is_ok() to ata_id_is_lba_capacity_ok() and move it to <linux/ata.h> (remove needless parens while at it). Cc: Jeff Garzik <jgarzik@pobox.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'include/linux/ata.h')
-rw-r--r--include/linux/ata.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 4c3f50070033..a53318b8cbd0 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -782,6 +782,56 @@ static inline int atapi_id_dmadir(const u16 *dev_id)
782 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);
783} 783}
784 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 */
793static 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
785static inline void ata_id_to_hd_driveid(u16 *id) 835static inline void ata_id_to_hd_driveid(u16 *id)
786{ 836{
787#ifdef __BIG_ENDIAN 837#ifdef __BIG_ENDIAN