diff options
author | Matthew Wilcox <willy@linux.intel.com> | 2009-04-02 10:37:25 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2009-04-06 20:00:51 -0400 |
commit | 0c659b82d11eaf5e1bee1f2bcb9994b9d09d175c (patch) | |
tree | 5568b38d3642533b3a8a1aa88c973278b24e62d1 /include/linux/ata.h | |
parent | c3f93b8fc6471ddbbc2a7e89fdfcfc8367e17564 (diff) |
ata: Add TRIM infrastructure
This is common code shared between the IDE and libata implementations
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'include/linux/ata.h')
-rw-r--r-- | include/linux/ata.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h index 6617c9f8f2ca..cb79b7a208e1 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h | |||
@@ -29,6 +29,8 @@ | |||
29 | #ifndef __LINUX_ATA_H__ | 29 | #ifndef __LINUX_ATA_H__ |
30 | #define __LINUX_ATA_H__ | 30 | #define __LINUX_ATA_H__ |
31 | 31 | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/string.h> | ||
32 | #include <linux/types.h> | 34 | #include <linux/types.h> |
33 | #include <asm/byteorder.h> | 35 | #include <asm/byteorder.h> |
34 | 36 | ||
@@ -91,6 +93,7 @@ enum { | |||
91 | ATA_ID_CFA_POWER = 160, | 93 | ATA_ID_CFA_POWER = 160, |
92 | ATA_ID_CFA_KEY_MGMT = 162, | 94 | ATA_ID_CFA_KEY_MGMT = 162, |
93 | ATA_ID_CFA_MODES = 163, | 95 | ATA_ID_CFA_MODES = 163, |
96 | ATA_ID_DATA_SET_MGMT = 169, | ||
94 | ATA_ID_ROT_SPEED = 217, | 97 | ATA_ID_ROT_SPEED = 217, |
95 | ATA_ID_PIO4 = (1 << 1), | 98 | ATA_ID_PIO4 = (1 << 1), |
96 | 99 | ||
@@ -248,6 +251,7 @@ enum { | |||
248 | ATA_CMD_SMART = 0xB0, | 251 | ATA_CMD_SMART = 0xB0, |
249 | ATA_CMD_MEDIA_LOCK = 0xDE, | 252 | ATA_CMD_MEDIA_LOCK = 0xDE, |
250 | ATA_CMD_MEDIA_UNLOCK = 0xDF, | 253 | ATA_CMD_MEDIA_UNLOCK = 0xDF, |
254 | ATA_CMD_DSM = 0x06, | ||
251 | /* marked obsolete in the ATA/ATAPI-7 spec */ | 255 | /* marked obsolete in the ATA/ATAPI-7 spec */ |
252 | ATA_CMD_RESTORE = 0x10, | 256 | ATA_CMD_RESTORE = 0x10, |
253 | 257 | ||
@@ -321,6 +325,9 @@ enum { | |||
321 | ATA_SMART_READ_VALUES = 0xD0, | 325 | ATA_SMART_READ_VALUES = 0xD0, |
322 | ATA_SMART_READ_THRESHOLDS = 0xD1, | 326 | ATA_SMART_READ_THRESHOLDS = 0xD1, |
323 | 327 | ||
328 | /* feature values for Data Set Management */ | ||
329 | ATA_DSM_TRIM = 0x01, | ||
330 | |||
324 | /* password used in LBA Mid / LBA High for executing SMART commands */ | 331 | /* password used in LBA Mid / LBA High for executing SMART commands */ |
325 | ATA_SMART_LBAM_PASS = 0x4F, | 332 | ATA_SMART_LBAM_PASS = 0x4F, |
326 | ATA_SMART_LBAH_PASS = 0xC2, | 333 | ATA_SMART_LBAH_PASS = 0xC2, |
@@ -723,6 +730,14 @@ static inline int ata_id_has_unload(const u16 *id) | |||
723 | return 0; | 730 | return 0; |
724 | } | 731 | } |
725 | 732 | ||
733 | static inline int ata_id_has_trim(const u16 *id) | ||
734 | { | ||
735 | if (ata_id_major_version(id) >= 7 && | ||
736 | (id[ATA_ID_DATA_SET_MGMT] & 1)) | ||
737 | return 1; | ||
738 | return 0; | ||
739 | } | ||
740 | |||
726 | static inline int ata_id_current_chs_valid(const u16 *id) | 741 | static inline int ata_id_current_chs_valid(const u16 *id) |
727 | { | 742 | { |
728 | /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command | 743 | /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command |
@@ -863,6 +878,32 @@ static inline void ata_id_to_hd_driveid(u16 *id) | |||
863 | #endif | 878 | #endif |
864 | } | 879 | } |
865 | 880 | ||
881 | /* | ||
882 | * Write up to 'max' LBA Range Entries to the buffer that will cover the | ||
883 | * extent from sector to sector + count. This is used for TRIM and for | ||
884 | * ADD LBA(S) TO NV CACHE PINNED SET. | ||
885 | */ | ||
886 | static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max, | ||
887 | u64 sector, unsigned long count) | ||
888 | { | ||
889 | __le64 *buffer = _buffer; | ||
890 | unsigned i = 0; | ||
891 | |||
892 | while (i < max) { | ||
893 | u64 entry = sector | | ||
894 | ((u64)(count > 0xffff ? 0xffff : count) << 48); | ||
895 | buffer[i++] = __cpu_to_le64(entry); | ||
896 | if (count <= 0xffff) | ||
897 | break; | ||
898 | count -= 0xffff; | ||
899 | sector += 0xffff; | ||
900 | } | ||
901 | |||
902 | max = ALIGN(i * 8, 512); | ||
903 | memset(buffer + i, 0, max - i * 8); | ||
904 | return max; | ||
905 | } | ||
906 | |||
866 | static inline int is_multi_taskfile(struct ata_taskfile *tf) | 907 | static inline int is_multi_taskfile(struct ata_taskfile *tf) |
867 | { | 908 | { |
868 | return (tf->command == ATA_CMD_READ_MULTI) || | 909 | return (tf->command == ATA_CMD_READ_MULTI) || |