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.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 6617c9f8f2ca..915da43edee1 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,42 @@ static inline int ata_id_has_unload(const u16 *id)
723 return 0; 730 return 0;
724} 731}
725 732
733static inline int ata_id_form_factor(const u16 *id)
734{
735 u16 val = id[168];
736
737 if (ata_id_major_version(id) < 7 || val == 0 || val == 0xffff)
738 return 0;
739
740 val &= 0xf;
741
742 if (val > 5)
743 return 0;
744
745 return val;
746}
747
748static inline int ata_id_rotation_rate(const u16 *id)
749{
750 u16 val = id[217];
751
752 if (ata_id_major_version(id) < 7 || val == 0 || val == 0xffff)
753 return 0;
754
755 if (val > 1 && val < 0x401)
756 return 0;
757
758 return val;
759}
760
761static inline int ata_id_has_trim(const u16 *id)
762{
763 if (ata_id_major_version(id) >= 7 &&
764 (id[ATA_ID_DATA_SET_MGMT] & 1))
765 return 1;
766 return 0;
767}
768
726static inline int ata_id_current_chs_valid(const u16 *id) 769static inline int ata_id_current_chs_valid(const u16 *id)
727{ 770{
728 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command 771 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -863,6 +906,32 @@ static inline void ata_id_to_hd_driveid(u16 *id)
863#endif 906#endif
864} 907}
865 908
909/*
910 * Write up to 'max' LBA Range Entries to the buffer that will cover the
911 * extent from sector to sector + count. This is used for TRIM and for
912 * ADD LBA(S) TO NV CACHE PINNED SET.
913 */
914static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
915 u64 sector, unsigned long count)
916{
917 __le64 *buffer = _buffer;
918 unsigned i = 0;
919
920 while (i < max) {
921 u64 entry = sector |
922 ((u64)(count > 0xffff ? 0xffff : count) << 48);
923 buffer[i++] = __cpu_to_le64(entry);
924 if (count <= 0xffff)
925 break;
926 count -= 0xffff;
927 sector += 0xffff;
928 }
929
930 max = ALIGN(i * 8, 512);
931 memset(buffer + i, 0, max - i * 8);
932 return max;
933}
934
866static inline int is_multi_taskfile(struct ata_taskfile *tf) 935static inline int is_multi_taskfile(struct ata_taskfile *tf)
867{ 936{
868 return (tf->command == ATA_CMD_READ_MULTI) || 937 return (tf->command == ATA_CMD_READ_MULTI) ||