From 0c12735e8abf4734b011aec979092db5e63556b0 Mon Sep 17 00:00:00 2001 From: Tom Yan Date: Tue, 12 Jul 2016 21:37:02 +0800 Subject: libata-scsi: fix SET FEATURES "filtering" for ata_msense_caching() Without this fix, the DRA bit of the caching mode page would not be updated when the read look-ahead feature is toggled (e.g. with `smartctl --set`), but will only be until, for example, the write cache feature is touched. Signed-off-by: Tom Yan Signed-off-by: Tejun Heo --- include/linux/ata.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/linux/ata.h b/include/linux/ata.h index 99346be..2d68793 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -409,6 +409,9 @@ enum { SETFEATURES_WC_ON = 0x02, /* Enable write cache */ SETFEATURES_WC_OFF = 0x82, /* Disable write cache */ + SETFEATURES_RA_ON = 0xaa, /* Enable read look-ahead */ + SETFEATURES_RA_OFF = 0x55, /* Disable read look-ahead */ + /* Enable/Disable Automatic Acoustic Management */ SETFEATURES_AAM_ON = 0x42, SETFEATURES_AAM_OFF = 0xC2, -- cgit v1.1 From 2983860c766870b701c4a34f435c1e18db086244 Mon Sep 17 00:00:00 2001 From: Tom Yan Date: Wed, 13 Jul 2016 04:31:23 +0800 Subject: libata-scsi: avoid repeated calculation of number of TRIM ranges Currently libata statically allows only 1-block (512-byte) payload for each TRIM command. Each payload can carry 64 TRIM ranges since each range requires 8 bytes. It is silly to keep doing the calculation (512 / 8) in different places. Hence, define the new ATA_MAX_TRIM_RNUM for the result. Signed-off-by: Tom Yan Signed-off-by: Tejun Heo --- include/linux/ata.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/ata.h b/include/linux/ata.h index 2d68793..d20b1ee 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -48,6 +48,7 @@ enum { ATA_MAX_SECTORS_1024 = 1024, ATA_MAX_SECTORS_LBA48 = 65535,/* TODO: 65536? */ ATA_MAX_SECTORS_TAPE = 65535, + ATA_MAX_TRIM_RNUM = 64, /* 512-byte payload / (6-byte LBA + 2-byte range per entry) */ ATA_ID_WORDS = 256, ATA_ID_CONFIG = 0, @@ -1069,12 +1070,12 @@ static inline void ata_id_to_hd_driveid(u16 *id) * TO NV CACHE PINNED SET. */ static inline unsigned ata_set_lba_range_entries(void *_buffer, - unsigned buf_size, u64 sector, unsigned long count) + unsigned num, u64 sector, unsigned long count) { __le64 *buffer = _buffer; unsigned i = 0, used_bytes; - while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */ + while (i < num) { u64 entry = sector | ((u64)(count > 0xffff ? 0xffff : count) << 48); buffer[i++] = __cpu_to_le64(entry); -- cgit v1.1 From b1c04e80c6da5f5d3d4778ede23c59666135fdeb Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 14 Jul 2016 09:05:42 +0900 Subject: libata: return boolean values from ata_is_* This way we don't have to worry about the exact bit postition of the test to leak out and any crazy propagation effects in the callers. Suggested-by: Tejun Heo Signed-off-by: Christoph Hellwig Signed-off-by: Tejun Heo --- include/linux/libata.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/linux/libata.h b/include/linux/libata.h index d15c19e..4e5a09c 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1063,32 +1063,32 @@ static inline unsigned int ata_prot_flags(u8 prot) return 0; } -static inline int ata_is_atapi(u8 prot) +static inline bool ata_is_atapi(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_ATAPI; } -static inline int ata_is_nodata(u8 prot) +static inline bool ata_is_nodata(u8 prot) { return !(ata_prot_flags(prot) & ATA_PROT_FLAG_DATA); } -static inline int ata_is_pio(u8 prot) +static inline bool ata_is_pio(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_PIO; } -static inline int ata_is_dma(u8 prot) +static inline bool ata_is_dma(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_DMA; } -static inline int ata_is_ncq(u8 prot) +static inline bool ata_is_ncq(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_NCQ; } -static inline int ata_is_data(u8 prot) +static inline bool ata_is_data(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_DATA; } @@ -1407,7 +1407,7 @@ static inline bool sata_pmp_attached(struct ata_port *ap) return ap->nr_pmp_links != 0; } -static inline int ata_is_host_link(const struct ata_link *link) +static inline bool ata_is_host_link(const struct ata_link *link) { return link == &link->ap->link || link == link->ap->slave_link; } @@ -1422,7 +1422,7 @@ static inline bool sata_pmp_attached(struct ata_port *ap) return false; } -static inline int ata_is_host_link(const struct ata_link *link) +static inline bool ata_is_host_link(const struct ata_link *link) { return 1; } -- cgit v1.1 From 5b844b63ddfb65aef923eaabe0420196fd71dd13 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 14 Jul 2016 09:05:48 +0900 Subject: ata: Handle ATA NCQ NO-DATA commands correctly Add a new taskfile protocol ATA_PROT_NCQ_NODATA to handle ATA NCQ NO-DATA commands correctly. And fixup ata_scsi_zbc_out_xlat() to use it. Signed-off-by: Hannes Reinecke Signed-off-by: Christoph Hellwig Signed-off-by: Tejun Heo --- include/linux/ata.h | 1 + include/linux/libata.h | 2 ++ include/trace/events/libata.h | 1 + 3 files changed, 4 insertions(+) (limited to 'include') diff --git a/include/linux/ata.h b/include/linux/ata.h index d20b1ee..35857d1 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -530,6 +530,7 @@ enum ata_tf_protocols { ATA_PROT_PIO, /* PIO data xfer */ ATA_PROT_DMA, /* DMA */ ATA_PROT_NCQ, /* NCQ */ + ATA_PROT_NCQ_NODATA, /* NCQ no data */ ATAPI_PROT_NODATA, /* packet command, no data */ ATAPI_PROT_PIO, /* packet command, PIO data xfer*/ ATAPI_PROT_DMA, /* packet command with special DMA sauce */ diff --git a/include/linux/libata.h b/include/linux/libata.h index 4e5a09c..1abd669 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1053,6 +1053,8 @@ static inline unsigned int ata_prot_flags(u8 prot) return ATA_PROT_FLAG_DMA; case ATA_PROT_NCQ: return ATA_PROT_FLAG_DMA | ATA_PROT_FLAG_NCQ; + case ATA_PROT_NCQ_NODATA: + return ATA_PROT_FLAG_NCQ; case ATAPI_PROT_NODATA: return ATA_PROT_FLAG_ATAPI; case ATAPI_PROT_PIO: diff --git a/include/trace/events/libata.h b/include/trace/events/libata.h index 75fff86..2fbbf99 100644 --- a/include/trace/events/libata.h +++ b/include/trace/events/libata.h @@ -126,6 +126,7 @@ ata_protocol_name(ATA_PROT_PIO), \ ata_protocol_name(ATA_PROT_DMA), \ ata_protocol_name(ATA_PROT_NCQ), \ + ata_protocol_name(ATA_PROT_NCQ_NODATA), \ ata_protocol_name(ATAPI_PROT_NODATA), \ ata_protocol_name(ATAPI_PROT_PIO), \ ata_protocol_name(ATAPI_PROT_DMA)) -- cgit v1.1 From 35303d5c36415754680f953aa6128b8b907d0543 Mon Sep 17 00:00:00 2001 From: Tom Yan Date: Fri, 15 Jul 2016 05:09:02 +0800 Subject: ata: make lba_{28,48}_ok() use ATA_MAX_SECTORS{,_LBA48} Since we set ATA_MAX_SECTORS_LBA48 to 65535 to avoid the corner case in some drives that commands with "count" set to 0000h (which reprsents 65536) does not work as expected, lba_48_ok(), which is used for number-of-blocks checking when libata pack commands, should use the same limit as well. In fact, there is no reason for the two functions not to use the macros anyway. Signed-off-by: Tom Yan Signed-off-by: Tejun Heo --- include/linux/ata.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/linux/ata.h b/include/linux/ata.h index 35857d1..5b67ff4 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -46,7 +46,7 @@ enum { ATA_MAX_SECTORS_128 = 128, ATA_MAX_SECTORS = 256, ATA_MAX_SECTORS_1024 = 1024, - ATA_MAX_SECTORS_LBA48 = 65535,/* TODO: 65536? */ + ATA_MAX_SECTORS_LBA48 = 65535,/* avoid count to be 0000h */ ATA_MAX_SECTORS_TAPE = 65535, ATA_MAX_TRIM_RNUM = 64, /* 512-byte payload / (6-byte LBA + 2-byte range per entry) */ @@ -1100,13 +1100,13 @@ static inline bool ata_ok(u8 status) static inline bool lba_28_ok(u64 block, u32 n_block) { /* check the ending block number: must be LESS THAN 0x0fffffff */ - return ((block + n_block) < ((1 << 28) - 1)) && (n_block <= 256); + return ((block + n_block) < ((1 << 28) - 1)) && (n_block <= ATA_MAX_SECTORS); } static inline bool lba_48_ok(u64 block, u32 n_block) { /* check the ending block number */ - return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= 65536); + return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= ATA_MAX_SECTORS_LBA48); } #define sata_pmp_gscr_vendor(gscr) ((gscr)[SATA_PMP_GSCR_PROD_ID] & 0xffff) -- cgit v1.1 From eb0effdf53b061bd57d8efc86032454e79487263 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 16 Jul 2016 22:16:41 +0900 Subject: libata: remove ata_is_nodata The only caller can just check for !ata_is_data instead. Signed-off-by: Christoph Hellwig Signed-off-by: Tejun Heo --- include/linux/libata.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include') diff --git a/include/linux/libata.h b/include/linux/libata.h index 1abd669..283b6be 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1070,11 +1070,6 @@ static inline bool ata_is_atapi(u8 prot) return ata_prot_flags(prot) & ATA_PROT_FLAG_ATAPI; } -static inline bool ata_is_nodata(u8 prot) -{ - return !(ata_prot_flags(prot) & ATA_PROT_FLAG_DATA); -} - static inline bool ata_is_pio(u8 prot) { return ata_prot_flags(prot) & ATA_PROT_FLAG_PIO; -- cgit v1.1 From d6e50e379eb1e7f2426eac61a1bbbf6e4cf68905 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 16 Jul 2016 22:16:42 +0900 Subject: libata: remove ATA_PROT_FLAG_DATA Instead we can simply check for PIO or DMA in ata_is_data. Signed-off-by: Christoph Hellwig Signed-off-by: Tejun Heo --- include/linux/libata.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/libata.h b/include/linux/libata.h index 283b6be..5838fbf 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -149,7 +149,6 @@ enum { /* protocol flags */ ATA_PROT_FLAG_PIO = (1 << 0), /* is PIO */ ATA_PROT_FLAG_DMA = (1 << 1), /* is DMA */ - ATA_PROT_FLAG_DATA = ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA, ATA_PROT_FLAG_NCQ = (1 << 2), /* is NCQ */ ATA_PROT_FLAG_ATAPI = (1 << 3), /* is ATAPI */ @@ -1087,7 +1086,7 @@ static inline bool ata_is_ncq(u8 prot) static inline bool ata_is_data(u8 prot) { - return ata_prot_flags(prot) & ATA_PROT_FLAG_DATA; + return ata_prot_flags(prot) & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA); } static inline int is_multi_taskfile(struct ata_taskfile *tf) -- cgit v1.1 From 37f92d77dc45d1fb74eff8501f26e72a3dcaa3cf Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 16 Jul 2016 22:16:43 +0900 Subject: ata: define ATA_PROT_* in terms of ATA_PROT_FLAG_* This avoid the need to always translate between the two in ata_prot_flags and generally cleans up the taskfile protocol usage. Signed-off-by: Christoph Hellwig Signed-off-by: Tejun Heo --- include/linux/ata.h | 28 +++++++++++++++++----------- include/linux/libata.h | 42 +++++------------------------------------- 2 files changed, 22 insertions(+), 48 deletions(-) (limited to 'include') diff --git a/include/linux/ata.h b/include/linux/ata.h index 5b67ff4..adbc812 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -523,17 +523,23 @@ enum { SERR_DEV_XCHG = (1 << 26), /* device exchanged */ }; -enum ata_tf_protocols { - /* ATA taskfile protocols */ - ATA_PROT_UNKNOWN, /* unknown/invalid */ - ATA_PROT_NODATA, /* no data */ - ATA_PROT_PIO, /* PIO data xfer */ - ATA_PROT_DMA, /* DMA */ - ATA_PROT_NCQ, /* NCQ */ - ATA_PROT_NCQ_NODATA, /* NCQ no data */ - ATAPI_PROT_NODATA, /* packet command, no data */ - ATAPI_PROT_PIO, /* packet command, PIO data xfer*/ - ATAPI_PROT_DMA, /* packet command with special DMA sauce */ +enum ata_prot_flags { + /* protocol flags */ + ATA_PROT_FLAG_PIO = (1 << 0), /* is PIO */ + ATA_PROT_FLAG_DMA = (1 << 1), /* is DMA */ + ATA_PROT_FLAG_NCQ = (1 << 2), /* is NCQ */ + ATA_PROT_FLAG_ATAPI = (1 << 3), /* is ATAPI */ + + /* taskfile protocols */ + ATA_PROT_UNKNOWN = (u8)-1, + ATA_PROT_NODATA = 0, + ATA_PROT_PIO = ATA_PROT_FLAG_PIO, + ATA_PROT_DMA = ATA_PROT_FLAG_DMA, + ATA_PROT_NCQ_NODATA = ATA_PROT_FLAG_NCQ, + ATA_PROT_NCQ = ATA_PROT_FLAG_DMA | ATA_PROT_FLAG_NCQ, + ATAPI_PROT_NODATA = ATA_PROT_FLAG_ATAPI, + ATAPI_PROT_PIO = ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_PIO, + ATAPI_PROT_DMA = ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_DMA, }; enum ata_ioctls { diff --git a/include/linux/libata.h b/include/linux/libata.h index 5838fbf..e37d4f9 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -146,12 +146,6 @@ enum { ATA_TFLAG_FUA = (1 << 5), /* enable FUA */ ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */ - /* protocol flags */ - ATA_PROT_FLAG_PIO = (1 << 0), /* is PIO */ - ATA_PROT_FLAG_DMA = (1 << 1), /* is DMA */ - ATA_PROT_FLAG_NCQ = (1 << 2), /* is NCQ */ - ATA_PROT_FLAG_ATAPI = (1 << 3), /* is ATAPI */ - /* struct ata_device stuff */ ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */ ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */ @@ -1038,55 +1032,29 @@ extern const unsigned long sata_deb_timing_long[]; extern struct ata_port_operations ata_dummy_port_ops; extern const struct ata_port_info ata_dummy_port_info; -/* - * protocol tests - */ -static inline unsigned int ata_prot_flags(u8 prot) -{ - switch (prot) { - case ATA_PROT_NODATA: - return 0; - case ATA_PROT_PIO: - return ATA_PROT_FLAG_PIO; - case ATA_PROT_DMA: - return ATA_PROT_FLAG_DMA; - case ATA_PROT_NCQ: - return ATA_PROT_FLAG_DMA | ATA_PROT_FLAG_NCQ; - case ATA_PROT_NCQ_NODATA: - return ATA_PROT_FLAG_NCQ; - case ATAPI_PROT_NODATA: - return ATA_PROT_FLAG_ATAPI; - case ATAPI_PROT_PIO: - return ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_PIO; - case ATAPI_PROT_DMA: - return ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_DMA; - } - return 0; -} - static inline bool ata_is_atapi(u8 prot) { - return ata_prot_flags(prot) & ATA_PROT_FLAG_ATAPI; + return prot & ATA_PROT_FLAG_ATAPI; } static inline bool ata_is_pio(u8 prot) { - return ata_prot_flags(prot) & ATA_PROT_FLAG_PIO; + return prot & ATA_PROT_FLAG_PIO; } static inline bool ata_is_dma(u8 prot) { - return ata_prot_flags(prot) & ATA_PROT_FLAG_DMA; + return prot & ATA_PROT_FLAG_DMA; } static inline bool ata_is_ncq(u8 prot) { - return ata_prot_flags(prot) & ATA_PROT_FLAG_NCQ; + return prot & ATA_PROT_FLAG_NCQ; } static inline bool ata_is_data(u8 prot) { - return ata_prot_flags(prot) & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA); + return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA); } static inline int is_multi_taskfile(struct ata_taskfile *tf) -- cgit v1.1