From patchwork Wed Apr 2 00:42:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 336213 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2C988140099 for ; Wed, 2 Apr 2014 11:43:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751740AbaDBAm7 (ORCPT ); Tue, 1 Apr 2014 20:42:59 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:32820 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751627AbaDBAm7 (ORCPT ); Tue, 1 Apr 2014 20:42:59 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s320gjkQ020552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Apr 2014 00:42:45 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s320giEv008177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 2 Apr 2014 00:42:44 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s320gh3t010920; Wed, 2 Apr 2014 00:42:43 GMT Received: from mojo.mkp.net (/141.144.6.237) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Apr 2014 17:42:43 -0700 From: "Martin K. Petersen" To: tj@kernel.org Cc: linux-ide@vger.kernel.org, "Martin K. Petersen" , Chris Samuel , Marc MERLIN Subject: [PATCH 1/2] libata: Expose trim capability in sysfs Date: Tue, 1 Apr 2014 20:42:36 -0400 Message-Id: <1396399357-28388-1-git-send-email-martin.petersen@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org From: "Martin K. Petersen" 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 Cc: Chris Samuel Cc: Marc MERLIN Tested-By: Chris Samuel Tested-By: Chris Samuel --- 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;