29 #ifndef __LINUX_ATA_H__
30 #define __LINUX_ATA_H__
32 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/types.h>
35 #include <asm/byteorder.h>
38 #define ATA_DMA_BOUNDARY 0xffffUL
39 #define ATA_DMA_MASK 0xffffffffULL
515 static inline unsigned int ata_prot_flags(
u8 prot)
536 static inline int ata_is_atapi(
u8 prot)
541 static inline int ata_is_nodata(
u8 prot)
546 static inline int ata_is_pio(
u8 prot)
551 static inline int ata_is_dma(
u8 prot)
556 static inline int ata_is_ncq(
u8 prot)
561 static inline int ata_is_data(
u8 prot)
569 #define ata_id_is_ata(id) (((id)[ATA_ID_CONFIG] & (1 << 15)) == 0)
570 #define ata_id_has_lba(id) ((id)[ATA_ID_CAPABILITY] & (1 << 9))
571 #define ata_id_has_dma(id) ((id)[ATA_ID_CAPABILITY] & (1 << 8))
572 #define ata_id_has_ncq(id) ((id)[ATA_ID_SATA_CAPABILITY] & (1 << 8))
573 #define ata_id_queue_depth(id) (((id)[ATA_ID_QUEUE_DEPTH] & 0x1f) + 1)
574 #define ata_id_removeable(id) ((id)[ATA_ID_CONFIG] & (1 << 7))
575 #define ata_id_has_atapi_AN(id) \
576 ((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
577 ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
578 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 5)))
579 #define ata_id_has_fpdma_aa(id) \
580 ((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
581 ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
582 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 2)))
583 #define ata_id_iordy_disable(id) ((id)[ATA_ID_CAPABILITY] & (1 << 10))
584 #define ata_id_has_iordy(id) ((id)[ATA_ID_CAPABILITY] & (1 << 11))
585 #define ata_id_u32(id,n) \
586 (((u32) (id)[(n) + 1] << 16) | ((u32) (id)[(n)]))
587 #define ata_id_u64(id,n) \
588 ( ((u64) (id)[(n) + 3] << 48) | \
589 ((u64) (id)[(n) + 2] << 32) | \
590 ((u64) (id)[(n) + 1] << 16) | \
591 ((u64) (id)[(n) + 0]) )
593 #define ata_id_cdb_intr(id) (((id)[ATA_ID_CONFIG] & 0x60) == 0x20)
594 #define ata_id_has_da(id) ((id)[ATA_ID_SATA_CAPABILITY_2] & (1 << 4))
595 #define ata_id_has_devslp(id) ((id)[ATA_ID_FEATURE_SUPP] & (1 << 8))
597 static inline bool ata_id_has_hipm(
const u16 *
id)
601 if (val == 0 || val == 0xffff)
604 return val & (1 << 9);
607 static inline bool ata_id_has_dipm(
const u16 *
id)
611 if (val == 0 || val == 0xffff)
614 return val & (1 << 3);
618 static inline bool ata_id_has_fua(
const u16 *
id)
625 static inline bool ata_id_has_flush(
const u16 *
id)
632 static inline bool ata_id_flush_enabled(
const u16 *
id)
634 if (ata_id_has_flush(
id) == 0)
641 static inline bool ata_id_has_flush_ext(
const u16 *
id)
648 static inline bool ata_id_flush_ext_enabled(
const u16 *
id)
650 if (ata_id_has_flush_ext(
id) == 0)
661 static inline u32 ata_id_logical_sector_size(
const u16 *
id)
673 static inline u8 ata_id_log2_per_physical_sector(
const u16 *
id)
693 static inline u16 ata_id_logical_sector_offset(
const u16 *
id,
696 u16 word_209 =
id[209];
698 if ((log2_per_phys > 1) && (word_209 & 0xc000) == 0x4000) {
701 return (1 << log2_per_phys) -
first;
706 static inline bool ata_id_has_lba48(
const u16 *
id)
715 static inline bool ata_id_lba48_enabled(
const u16 *
id)
717 if (ata_id_has_lba48(
id) == 0)
724 static inline bool ata_id_hpa_enabled(
const u16 *
id)
738 static inline bool ata_id_has_wcache(
const u16 *
id)
746 static inline bool ata_id_has_pm(
const u16 *
id)
753 static inline bool ata_id_rahead_enabled(
const u16 *
id)
760 static inline bool ata_id_wcache_enabled(
const u16 *
id)
780 static inline unsigned int ata_id_major_version(
const u16 *
id)
787 for (mver = 14; mver >= 1; mver--)
793 static inline bool ata_id_is_sata(
const u16 *
id)
806 static inline bool ata_id_has_tpm(
const u16 *
id)
809 if (ata_id_major_version(
id) < 8)
811 if ((
id[48] & 0xC000) != 0x4000)
813 return id[48] & (1 << 0);
816 static inline bool ata_id_has_dword_io(
const u16 *
id)
819 if (ata_id_major_version(
id) > 7)
824 static inline bool ata_id_has_unload(
const u16 *
id)
826 if (ata_id_major_version(
id) >= 7 &&
833 static inline bool ata_id_has_wwn(
const u16 *
id)
838 static inline int ata_id_form_factor(
const u16 *
id)
842 if (ata_id_major_version(
id) < 7 || val == 0 || val == 0xffff)
853 static inline int ata_id_rotation_rate(
const u16 *
id)
857 if (ata_id_major_version(
id) < 7 || val == 0 || val == 0xffff)
860 if (val > 1 && val < 0x401)
866 static inline bool ata_id_has_trim(
const u16 *
id)
868 if (ata_id_major_version(
id) >= 7 &&
874 static inline bool ata_id_has_zero_after_trim(
const u16 *
id)
877 if (ata_id_has_trim(
id) &&
884 static inline bool ata_id_current_chs_valid(
const u16 *
id)
896 static inline bool ata_id_is_cfa(
const u16 *
id)
912 static inline bool ata_id_is_ssd(
const u16 *
id)
917 static inline bool ata_id_pio_need_iordy(
const u16 *
id,
const u8 pio)
920 if (pio > 4 && ata_id_is_cfa(
id))
929 static inline bool ata_drive_40wire(
const u16 *
dev_id)
931 if (ata_id_is_sata(dev_id))
938 static inline bool ata_drive_40wire_relaxed(
const u16 *dev_id)
945 static inline int atapi_cdb_len(
const u16 *dev_id)
955 static inline bool atapi_command_packet_set(
const u16 *dev_id)
960 static inline bool atapi_id_dmadir(
const u16 *dev_id)
962 return ata_id_major_version(dev_id) >= 7 && (dev_id[62] & 0x8000);
973 static inline bool ata_id_is_lba_capacity_ok(
u16 *
id)
975 unsigned long lba_sects, chs_sects,
head,
tail;
999 if (lba_sects - chs_sects < chs_sects/10)
1003 head = (lba_sects >> 16) & 0xffff;
1004 tail = lba_sects & 0xffff;
1005 lba_sects = head | (tail << 16);
1007 if (lba_sects - chs_sects < chs_sects/10) {
1015 static inline void ata_id_to_hd_driveid(
u16 *
id)
1040 static inline unsigned ata_set_lba_range_entries(
void *
_buffer,
1046 while (i < buf_size / 8 ) {
1048 ((
u64)(count > 0xffff ? 0xffff : count) << 48);
1050 if (count <= 0xffff)
1070 static inline bool ata_ok(
u8 status)
1076 static inline bool lba_28_ok(
u64 block,
u32 n_block)
1079 return ((block + n_block) < ((1 << 28) - 1)) && (n_block <= 256);
1082 static inline bool lba_48_ok(
u64 block,
u32 n_block)
1085 return ((block + n_block - 1) < ((
u64)1 << 48)) && (n_block <= 65536);
1088 #define sata_pmp_gscr_vendor(gscr) ((gscr)[SATA_PMP_GSCR_PROD_ID] & 0xffff)
1089 #define sata_pmp_gscr_devid(gscr) ((gscr)[SATA_PMP_GSCR_PROD_ID] >> 16)
1090 #define sata_pmp_gscr_rev(gscr) (((gscr)[SATA_PMP_GSCR_REV] >> 8) & 0xff)
1091 #define sata_pmp_gscr_ports(gscr) ((gscr)[SATA_PMP_GSCR_PORT_INFO] & 0xf)