From: Marc C <marc.ceeeee@gmail.com>
To: tj@kernel.org, linux-ide@vger.kernel.org
Cc: Marc Carino <marc.ceeeee@gmail.com>
Subject: [PATCH v4 3/3] libata: Add support for queued DSM TRIM
Date: Fri, 23 Aug 2013 02:40:47 -0700 [thread overview]
Message-ID: <1377250847-24132-4-git-send-email-marc.ceeeee@gmail.com> (raw)
In-Reply-To: <1377250847-24132-1-git-send-email-marc.ceeeee@gmail.com>
From: Marc Carino <marc.ceeeee@gmail.com>
Some new SSDs support the queued version of the DSM TRIM command.
Let the driver use the new command if supported.
Signed-off-by: Marc Carino <marc.ceeeee@gmail.com>
---
drivers/ata/libata-scsi.c | 25 +++++++++++++++++++------
include/linux/libata.h | 11 +++++++++++
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 83c0890..0c807a9 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3098,12 +3098,25 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
buf = page_address(sg_page(scsi_sglist(scmd)));
size = ata_set_lba_range_entries(buf, 512, block, n_block);
- tf->protocol = ATA_PROT_DMA;
- tf->hob_feature = 0;
- tf->feature = ATA_DSM_TRIM;
- tf->hob_nsect = (size / 512) >> 8;
- tf->nsect = size / 512;
- tf->command = ATA_CMD_DSM;
+ if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) {
+ /* Newer devices support queued TRIM commands */
+ tf->protocol = ATA_PROT_NCQ;
+ tf->command = ATA_CMD_FPDMA_SEND;
+ tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f;
+ tf->nsect = qc->tag << 3;
+ tf->hob_feature = (size / 512) >> 8;
+ tf->feature = size / 512;
+
+ tf->auxiliary = 1;
+ } else {
+ tf->protocol = ATA_PROT_DMA;
+ tf->hob_feature = 0;
+ tf->feature = ATA_DSM_TRIM;
+ tf->hob_nsect = (size / 512) >> 8;
+ tf->nsect = size / 512;
+ tf->command = ATA_CMD_DSM;
+ }
+
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 |
ATA_TFLAG_WRITE;
diff --git a/include/linux/libata.h b/include/linux/libata.h
index b925504..69d1b8b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1608,6 +1608,17 @@ static inline int ata_ncq_enabled(struct ata_device *dev)
ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
}
+static inline int ata_fpdma_dsm_supported(struct ata_device *dev)
+{
+ if ((dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
+ (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
+ ATA_LOG_NCQ_SEND_RECV_DSM_TRIM)) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
{
qc->tf.ctl |= ATA_NIEN;
--
1.8.1.2
next prev parent reply other threads:[~2013-08-23 9:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 9:40 [PATCH v4 0/3] Introduce new SATA queued commands Marc C
2013-08-23 9:40 ` [PATCH v4 1/3] libata: Populate host-to-device FIS "auxiliary" field Marc C
2013-08-23 12:27 ` Sergei Shtylyov
2013-08-23 9:40 ` [PATCH v4 2/3] libata: Add support for SEND/RECEIVE FPDMA QUEUED Marc C
2013-08-23 12:43 ` Sergei Shtylyov
2013-08-23 16:06 ` Tejun Heo
2013-08-23 9:40 ` Marc C [this message]
2013-08-23 16:07 ` [PATCH v4 3/3] libata: Add support for queued DSM TRIM Tejun Heo
2013-08-23 16:08 ` [PATCH v4 0/3] Introduce new SATA queued commands Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377250847-24132-4-git-send-email-marc.ceeeee@gmail.com \
--to=marc.ceeeee@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).