aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ata.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ata.h')
-rw-r--r--include/linux/ata.h51
1 files changed, 38 insertions, 13 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 4fb357312b3b..700c5b9b3583 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -75,6 +75,7 @@ enum {
75 ATA_ID_EIDE_DMA_TIME = 66, 75 ATA_ID_EIDE_DMA_TIME = 66,
76 ATA_ID_EIDE_PIO = 67, 76 ATA_ID_EIDE_PIO = 67,
77 ATA_ID_EIDE_PIO_IORDY = 68, 77 ATA_ID_EIDE_PIO_IORDY = 68,
78 ATA_ID_ADDITIONAL_SUPP = 69,
78 ATA_ID_QUEUE_DEPTH = 75, 79 ATA_ID_QUEUE_DEPTH = 75,
79 ATA_ID_MAJOR_VER = 80, 80 ATA_ID_MAJOR_VER = 80,
80 ATA_ID_COMMAND_SET_1 = 82, 81 ATA_ID_COMMAND_SET_1 = 82,
@@ -87,6 +88,7 @@ enum {
87 ATA_ID_HW_CONFIG = 93, 88 ATA_ID_HW_CONFIG = 93,
88 ATA_ID_SPG = 98, 89 ATA_ID_SPG = 98,
89 ATA_ID_LBA_CAPACITY_2 = 100, 90 ATA_ID_LBA_CAPACITY_2 = 100,
91 ATA_ID_SECTOR_SIZE = 106,
90 ATA_ID_LAST_LUN = 126, 92 ATA_ID_LAST_LUN = 126,
91 ATA_ID_DLF = 128, 93 ATA_ID_DLF = 128,
92 ATA_ID_CSFO = 129, 94 ATA_ID_CSFO = 129,
@@ -638,6 +640,18 @@ static inline int ata_id_flush_ext_enabled(const u16 *id)
638 return (id[ATA_ID_CFS_ENABLE_2] & 0x2400) == 0x2400; 640 return (id[ATA_ID_CFS_ENABLE_2] & 0x2400) == 0x2400;
639} 641}
640 642
643static inline int ata_id_has_large_logical_sectors(const u16 *id)
644{
645 if ((id[ATA_ID_SECTOR_SIZE] & 0xc000) != 0x4000)
646 return 0;
647 return id[ATA_ID_SECTOR_SIZE] & (1 << 13);
648}
649
650static inline u16 ata_id_logical_per_physical_sectors(const u16 *id)
651{
652 return 1 << (id[ATA_ID_SECTOR_SIZE] & 0xf);
653}
654
641static inline int ata_id_has_lba48(const u16 *id) 655static inline int ata_id_has_lba48(const u16 *id)
642{ 656{
643 if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000) 657 if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
@@ -803,6 +817,16 @@ static inline int ata_id_has_trim(const u16 *id)
803 return 0; 817 return 0;
804} 818}
805 819
820static inline int ata_id_has_zero_after_trim(const u16 *id)
821{
822 /* DSM supported, deterministic read, and read zero after trim set */
823 if (ata_id_has_trim(id) &&
824 (id[ATA_ID_ADDITIONAL_SUPP] & 0x4020) == 0x4020)
825 return 1;
826
827 return 0;
828}
829
806static inline int ata_id_current_chs_valid(const u16 *id) 830static inline int ata_id_current_chs_valid(const u16 *id)
807{ 831{
808 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command 832 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -817,7 +841,8 @@ static inline int ata_id_current_chs_valid(const u16 *id)
817 841
818static inline int ata_id_is_cfa(const u16 *id) 842static inline int ata_id_is_cfa(const u16 *id)
819{ 843{
820 if (id[ATA_ID_CONFIG] == 0x848A) /* Traditional CF */ 844 if ((id[ATA_ID_CONFIG] == 0x848A) || /* Traditional CF */
845 (id[ATA_ID_CONFIG] == 0x844A)) /* Delkin Devices CF */
821 return 1; 846 return 1;
822 /* 847 /*
823 * CF specs don't require specific value in the word 0 anymore and yet 848 * CF specs don't require specific value in the word 0 anymore and yet
@@ -958,17 +983,17 @@ static inline void ata_id_to_hd_driveid(u16 *id)
958} 983}
959 984
960/* 985/*
961 * Write up to 'max' LBA Range Entries to the buffer that will cover the 986 * Write LBA Range Entries to the buffer that will cover the extent from
962 * extent from sector to sector + count. This is used for TRIM and for 987 * sector to sector + count. This is used for TRIM and for ADD LBA(S)
963 * ADD LBA(S) TO NV CACHE PINNED SET. 988 * TO NV CACHE PINNED SET.
964 */ 989 */
965static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max, 990static inline unsigned ata_set_lba_range_entries(void *_buffer,
966 u64 sector, unsigned long count) 991 unsigned buf_size, u64 sector, unsigned long count)
967{ 992{
968 __le64 *buffer = _buffer; 993 __le64 *buffer = _buffer;
969 unsigned i = 0; 994 unsigned i = 0, used_bytes;
970 995
971 while (i < max) { 996 while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */
972 u64 entry = sector | 997 u64 entry = sector |
973 ((u64)(count > 0xffff ? 0xffff : count) << 48); 998 ((u64)(count > 0xffff ? 0xffff : count) << 48);
974 buffer[i++] = __cpu_to_le64(entry); 999 buffer[i++] = __cpu_to_le64(entry);
@@ -978,9 +1003,9 @@ static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
978 sector += 0xffff; 1003 sector += 0xffff;
979 } 1004 }
980 1005
981 max = ALIGN(i * 8, 512); 1006 used_bytes = ALIGN(i * 8, 512);
982 memset(buffer + i, 0, max - i * 8); 1007 memset(buffer + i, 0, used_bytes - i * 8);
983 return max; 1008 return used_bytes;
984} 1009}
985 1010
986static inline int is_multi_taskfile(struct ata_taskfile *tf) 1011static inline int is_multi_taskfile(struct ata_taskfile *tf)
@@ -1000,8 +1025,8 @@ static inline int ata_ok(u8 status)
1000 1025
1001static inline int lba_28_ok(u64 block, u32 n_block) 1026static inline int lba_28_ok(u64 block, u32 n_block)
1002{ 1027{
1003 /* check the ending block number */ 1028 /* check the ending block number: must be LESS THAN 0x0fffffff */
1004 return ((block + n_block) < ((u64)1 << 28)) && (n_block <= 256); 1029 return ((block + n_block) < ((1 << 28) - 1)) && (n_block <= 256);
1005} 1030}
1006 1031
1007static inline int lba_48_ok(u64 block, u32 n_block) 1032static inline int lba_48_ok(u64 block, u32 n_block)