linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] libata: Expose trim capability in sysfs
@ 2014-04-02  0:42 Martin K. Petersen
  2014-04-02  0:42 ` [PATCH 2/2] libata: Update queued trim blacklist for M5x0 drives Martin K. Petersen
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Martin K. Petersen @ 2014-04-02  0:42 UTC (permalink / raw)
  To: tj; +Cc: linux-ide, Martin K. Petersen, Chris Samuel, Marc MERLIN

From: "Martin K. Petersen" <martin.petersen@oracle.com>

Now that drives with support for queued trim are starting to appear, it
would be helpful to expose the chosen trim mode to userland. Create a
sysfs "trim" attribute for each ata_device that displays whether trim is
"unsupported", "unqueued" or "queued".

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Chris Samuel <chris@csamuel.org>
Cc: Marc MERLIN <marc@merlins.org>
---
 drivers/ata/libata-transport.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index e37413228228..a9a1a9055a3a 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -559,6 +559,37 @@ show_ata_dev_gscr(struct device *dev,
 
 static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL);
 
+enum {
+	ATA_TRIM_UNSUPPORTED = 0,
+	ATA_TRIM_UNQUEUED = 1,
+	ATA_TRIM_QUEUED = 2,
+};
+
+static const char *trim_mode[] = {
+	[ATA_TRIM_UNSUPPORTED] = "unsupported",
+	[ATA_TRIM_UNQUEUED] = "unqueued",
+	[ATA_TRIM_QUEUED] = "queued",
+};
+
+static ssize_t
+show_ata_dev_trim(struct device *dev,
+		  struct device_attribute *attr, char *buf)
+{
+	struct ata_device *ata_dev = transport_class_to_dev(dev);
+	unsigned int mode;
+
+	if (!ata_id_has_trim(ata_dev->id))
+		mode = ATA_TRIM_UNSUPPORTED;
+	else if (ata_fpdma_dsm_supported(ata_dev))
+		mode = ATA_TRIM_QUEUED;
+	else
+		mode = ATA_TRIM_UNQUEUED;
+
+	return snprintf(buf, 20, "%s\n", trim_mode[mode]);
+}
+
+static DEVICE_ATTR(trim, S_IRUGO, show_ata_dev_trim, NULL);
+
 static DECLARE_TRANSPORT_CLASS(ata_dev_class,
 			       "ata_device", NULL, NULL, NULL);
 
@@ -732,6 +763,7 @@ struct scsi_transport_template *ata_attach_transport(void)
 	SETUP_DEV_ATTRIBUTE(ering);
 	SETUP_DEV_ATTRIBUTE(id);
 	SETUP_DEV_ATTRIBUTE(gscr);
+	SETUP_DEV_ATTRIBUTE(trim);
 	BUG_ON(count > ATA_DEV_ATTRS);
 	i->dev_attrs[count] = NULL;
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-04-16 20:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-02  0:42 [PATCH 1/2] libata: Expose trim capability in sysfs Martin K. Petersen
2014-04-02  0:42 ` [PATCH 2/2] libata: Update queued trim blacklist for M5x0 drives Martin K. Petersen
2014-04-02 17:11   ` Tejun Heo
2014-04-02 17:09 ` [PATCH 1/2] libata: Expose trim capability in sysfs Tejun Heo
2014-04-02 17:26   ` Martin K. Petersen
2014-04-04 17:29     ` Marc MERLIN
2014-04-04 21:49 ` Chris Samuel
2014-04-05  8:12 ` Chris Samuel
2014-04-07 19:52   ` Martin K. Petersen
2014-04-06  4:03 ` Marc MERLIN
     [not found]   ` <1403024.0HLhjfholh@quad>
2014-04-06  6:19     ` Marc MERLIN
2014-04-16 20:16 ` Tejun Heo

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).