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.h44
1 files changed, 34 insertions, 10 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 4fb357312b3b..20f31567ccee 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
@@ -958,17 +982,17 @@ static inline void ata_id_to_hd_driveid(u16 *id)
958} 982}
959 983
960/* 984/*
961 * Write up to 'max' LBA Range Entries to the buffer that will cover the 985 * 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 986 * sector to sector + count. This is used for TRIM and for ADD LBA(S)
963 * ADD LBA(S) TO NV CACHE PINNED SET. 987 * TO NV CACHE PINNED SET.
964 */ 988 */
965static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max, 989static inline unsigned ata_set_lba_range_entries(void *_buffer,
966 u64 sector, unsigned long count) 990 unsigned buf_size, u64 sector, unsigned long count)
967{ 991{
968 __le64 *buffer = _buffer; 992 __le64 *buffer = _buffer;
969 unsigned i = 0; 993 unsigned i = 0, used_bytes;
970 994
971 while (i < max) { 995 while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */
972 u64 entry = sector | 996 u64 entry = sector |
973 ((u64)(count > 0xffff ? 0xffff : count) << 48); 997 ((u64)(count > 0xffff ? 0xffff : count) << 48);
974 buffer[i++] = __cpu_to_le64(entry); 998 buffer[i++] = __cpu_to_le64(entry);
@@ -978,9 +1002,9 @@ static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
978 sector += 0xffff; 1002 sector += 0xffff;
979 } 1003 }
980 1004
981 max = ALIGN(i * 8, 512); 1005 used_bytes = ALIGN(i * 8, 512);
982 memset(buffer + i, 0, max - i * 8); 1006 memset(buffer + i, 0, used_bytes - i * 8);
983 return max; 1007 return used_bytes;
984} 1008}
985 1009
986static inline int is_multi_taskfile(struct ata_taskfile *tf) 1010static inline int is_multi_taskfile(struct ata_taskfile *tf)