Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757408AbcJMXCu (ORCPT ); Thu, 13 Oct 2016 19:02:50 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:62749 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752188AbcJMXB6 (ORCPT ); Thu, 13 Oct 2016 19:01:58 -0400 X-IronPort-AV: E=Sophos;i="5.31,490,1473091200"; d="scan'208";a="25178995" Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Adam.Manzanares@wdc.com; From: Adam Manzanares To: , , , , , , , , , , CC: , , , , , Adam Manzanares , Adam Manzanares Subject: [PATCH v5 4/4] ata: ATA Command Priority Disabled By Default Date: Thu, 13 Oct 2016 16:00:31 -0700 Message-ID: <1476399631-5799-5-git-send-email-adam.manzanares@hgst.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476399631-5799-1-git-send-email-adam.manzanares@hgst.com> References: <1476399631-5799-1-git-send-email-adam.manzanares@hgst.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: BY1PR13CA0002.namprd13.prod.outlook.com (10.162.107.140) To BLUPR0401MB1713.namprd04.prod.outlook.com (10.162.215.15) X-MS-Office365-Filtering-Correlation-Id: 0eb28905-189b-4f05-8bc4-08d3f3bccb62 X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1713;2:rvmdFZGt74dXfs6amTaEPDzqR1Tmhvl6hXSb9jQZEVj9vc4eCy78ZojX/RBNyrHWeTdAtWgbbpOcsQpBLgVM6Q0CZkKGZRXnRWVKg2mfASZzz72Ro9BNTedohkB4KlTgPz0i2gEZyEmnB5y6zIzohY3GKkB8U+eLd76YQ2HdTJNuD1jdTPT66P1SchTSdf/4vVplyJZkL8SFB+h9M+GEnQ==;3:o66YON0XXSHvaGe0939cBZ+8vHxfzn91a8pgbN1yocMraogEW0wwaBw7Cx/xUYsZMnIw7N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75TwqlQ6b8efcEHPwGBHPuDvr22FtmVF+wBDjc9byj9Ism86ODvkDWN6K+eHGsgzQ37E/C9EQ4FvWZpSpf5RnYXvfbox6m4cmImZm/3xHmNZzUaXfrh3bqgkHEI57XXL/N9RVr7qCFwmPs5LIM61p5fiAk22IJKsiyV4LfeZQcmLOfQnkaJZa2iHueDVp33hZ0W/kppVJxvid/uN0PASSSNa1X1PlNeI3J0i6NL7uRPp7e11htZdKIp+k1NPKNgwC17A9Z/fUGUBeyO7c5m0f9yTZCwvclxuy76dcWW/4khNM3ila2bQw3KUBEF8tzC3qMevN9SV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026);SRVR:BLUPR0401MB1713;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0401MB1713; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1713;4:LTJFz/dnEIIFTxzYrbsPOoD8OXWo9Ahk6Qzw1q3koQUPASHKFjppRS6g8lbt6FgR6n4X59YM3RyEnSi5HcqkELLJlqLAfiS5pv8T4FYoeRHow8igGGvRpCYtz965qtBWUxCJiqF6mGHay45X9HrbfjaPFOV/taVm+d/TndVr42F0bB6TD5ujQmQTtvht56RWxbzJ6DKcCazOYx9/Npy5zel69w4MGk7RTdZNDoa+2t/DwUKi8wXapfvSSVZREyKd9DOzK400Jhi6P6VAf9cGXnYavVAweDTqqLEtBMBEH/Xvh/r8ygag9msT9xxGXOUWr5tBxj9mgdCPIKgakjy4AP6V84LfoBzzFHdu+wxt36Nl0QCShIkq5RVdpRkHg/CUr/XX6zvFuPzSbh4chUltG8nCKt+QCGHmOwovh7CfTk4= X-Forefront-PRVS: 0094E3478A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(92566002)(4326007)(42882006)(7416002)(3846002)(36756003)(106356001)(7846002)(305945005)(6116002)(2906002)(50226002)(97736004)(575784001)(105586002)(19580395003)(47776003)(2201001)(2950100002)(48376002)(33646002)(586003)(7736002)(66066001)(19580405001)(76176999)(6666003)(42186005)(5003940100001)(189998001)(50466002)(77096005)(229853001)(5001770100001)(68736007)(50986999)(5660300001)(8676002)(81166006)(81156014)(101416001)(7099028)(921003)(1121003)(2101003)(83996005)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR0401MB1713;H:penguito.sanjose.hgst.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR0401MB1713;23:0YFZHaoGT4s4K/PvfAos82XR/sxaGAXKLFFrY4x?= =?us-ascii?Q?9vzKsl5kCmOwy+NDj1dxVdyGX4t/colmG2iOk7mAmp8zcpuyWAjTK/hpDxEX?= =?us-ascii?Q?eTh8XVa+53yuXu9RJNPCRZvvntPdfk/JKH2fw90uTHcqW1EpG6s7SiN8m9UM?= =?us-ascii?Q?EFW1qcV8QCXhVTqds2Ge8ZS0LTWqyVRXmMXKV1T/8qFrzedVbTVezTzC8fNx?= =?us-ascii?Q?j9xJyaECjt+usGboYfvVZjGUe1foKHmP0eAvMqN2xbkEo7ZzlJ7jDr/ZXp/D?= =?us-ascii?Q?AoV2XW9c/3e5y5JDZLf1PxGSguLoSehOSjkE3ZEDfV69y0ieoYug/FxZYCc7?= =?us-ascii?Q?BHpeSa4h2OnzNCy774fzyxp1tkW5PiWazcOPH6vcscXb0Xj/CYmZU40tbnfT?= =?us-ascii?Q?xHWXh400Om+IEqMYG/+rlnEhQngtKyOITLCtPXVlLVFqqhfkQuXZs5sHtPF6?= =?us-ascii?Q?rBdAEXUWUIOm8vC+uuP21zmSrx6JOB8Np0Xt1DJwxEikvWS8xXbUHwsuwVes?= =?us-ascii?Q?EiVLwg6MQ46Gx9mKiUIJpZv5aBzik57I2cvN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jWH8ctbftd7yd0T6hWwGmxhJX0lOvucM5JxQm5wJTvDCbE091s0CqHCIROOAOqzyXK7VGoj9QfLj4ha309ns0Di2dQxQvqtpE6WmgRPf/Z2Aq/3cM2h19h/lwEB67+gpRsm6/mujd8JdAtujWlIKIjwaTeSYYMTzAT8T28Hfxo1OvXu6raZnzLYYFs8hwd7X X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2016 23:00:56.6483 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0401MB1713 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4878 Lines: 159 Add a sysfs entry to turn on priority information being passed to a ATA device. By default this feature is turned off. This patch depends on ata: Enabling ATA Command Priorities Signed-off-by: Adam Manzanares --- drivers/ata/libahci.c | 1 + drivers/ata/libata-core.c | 2 +- drivers/ata/libata-scsi.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 8 ++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index dcf2c72..383adf7 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -140,6 +140,7 @@ EXPORT_SYMBOL_GPL(ahci_shost_attrs); struct device_attribute *ahci_sdev_attrs[] = { &dev_attr_sw_activity, &dev_attr_unload_heads, + &dev_attr_enable_prio, NULL }; EXPORT_SYMBOL_GPL(ahci_sdev_attrs); diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 181b530..d0cf987 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -787,7 +787,7 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, if (tf->flags & ATA_TFLAG_FUA) tf->device |= 1 << 7; - if (ata_ncq_prio_enabled(dev)) { + if (ata_ncq_prio_enabled(dev) && ata_prio_enabled(dev)) { if (class == IOPRIO_CLASS_RT) tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 18629e8..10ba118 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -271,6 +271,73 @@ DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR, ata_scsi_park_show, ata_scsi_park_store); EXPORT_SYMBOL_GPL(dev_attr_unload_heads); +static ssize_t ata_enable_prio_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct scsi_device *sdev = to_scsi_device(device); + struct ata_port *ap; + struct ata_device *dev; + int rc = 0; + int enable_prio; + + ap = ata_shost_to_port(sdev->host); + + spin_lock_irq(ap->lock); + dev = ata_scsi_find_dev(ap, sdev); + if (!dev) { + rc = -ENODEV; + goto unlock; + } + + enable_prio = ata_prio_enabled(dev); + +unlock: + spin_unlock_irq(ap->lock); + + return rc ? rc : snprintf(buf, 20, "%u\n", enable_prio); +} + +static ssize_t ata_enable_prio_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct scsi_device *sdev = to_scsi_device(device); + struct ata_port *ap; + struct ata_device *dev; + long int input; + unsigned long flags; + int rc; + + rc = kstrtol(buf, 10, &input); + if (rc) + return rc; + if ((input < 0) || (input > 1)) + return -EINVAL; + + ap = ata_shost_to_port(sdev->host); + + spin_lock_irqsave(ap->lock, flags); + dev = ata_scsi_find_dev(ap, sdev); + if (unlikely(!dev)) { + rc = -ENODEV; + goto unlock; + } + + if (input) + dev->flags |= ATA_DFLAG_ENABLE_PRIO; + else + dev->flags &= ~ATA_DFLAG_ENABLE_PRIO; + +unlock: + spin_unlock_irqrestore(ap->lock, flags); + + return rc ? rc : len; +} + +DEVICE_ATTR(enable_prio, S_IRUGO | S_IWUSR, + ata_enable_prio_show, ata_enable_prio_store); +EXPORT_SYMBOL_GPL(dev_attr_enable_prio); + void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq) { @@ -402,6 +469,7 @@ EXPORT_SYMBOL_GPL(dev_attr_sw_activity); struct device_attribute *ata_common_sdev_attrs[] = { &dev_attr_unload_heads, + &dev_attr_enable_prio, NULL }; EXPORT_SYMBOL_GPL(ata_common_sdev_attrs); diff --git a/include/linux/libata.h b/include/linux/libata.h index 244f261..c8acb16 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -166,6 +166,7 @@ enum { ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */ ATA_DFLAG_NCQ_SEND_RECV = (1 << 19), /* device supports NCQ SEND and RECV */ ATA_DFLAG_NCQ_PRIO = (1 << 20), /* device supports NCQ priority */ + ATA_DFLAG_ENABLE_PRIO = (1 << 21), /* User enable device priority */ ATA_DFLAG_INIT_MASK = (1 << 24) - 1, ATA_DFLAG_DETACH = (1 << 24), @@ -544,6 +545,7 @@ typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes) extern struct device_attribute dev_attr_link_power_management_policy; extern struct device_attribute dev_attr_unload_heads; +extern struct device_attribute dev_attr_enable_prio; extern struct device_attribute dev_attr_em_message_type; extern struct device_attribute dev_attr_em_message; extern struct device_attribute dev_attr_sw_activity; @@ -1627,6 +1629,12 @@ static inline int ata_ncq_prio_enabled(struct ata_device *dev) return (dev->flags & ATA_DFLAG_NCQ_PRIO) == ATA_DFLAG_NCQ_PRIO; } +static inline int ata_prio_enabled(struct ata_device *dev) +{ + return ((dev->flags & ATA_DFLAG_ENABLE_PRIO) == + ATA_DFLAG_ENABLE_PRIO); +} + static inline bool ata_fpdma_dsm_supported(struct ata_device *dev) { return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) && -- 2.1.4