Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933912AbcJMUC6 (ORCPT ); Thu, 13 Oct 2016 16:02:58 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:26938 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148AbcJMUCd (ORCPT ); Thu, 13 Oct 2016 16:02:33 -0400 X-IronPort-AV: E=Sophos;i="5.31,489,1473091200"; d="scan'208";a="25155228" Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Adam.Manzanares@wdc.com; From: Adam Manzanares To: , , , , , , , , , , CC: , , , , , Adam Manzanares , Adam Manzanares Subject: [PATCH v4 4/4] ata: ATA Command Priority Disabled By Default Date: Thu, 13 Oct 2016 12:53:53 -0700 Message-ID: <1476388433-2539-5-git-send-email-adam.manzanares@hgst.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476388433-2539-1-git-send-email-adam.manzanares@hgst.com> References: <1476388433-2539-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: CY1PR21CA0075.namprd21.prod.outlook.com (10.163.250.171) To BLUPR0401MB1715.namprd04.prod.outlook.com (10.162.215.17) X-MS-Office365-Filtering-Correlation-Id: 051f6807-b61a-4362-46a7-08d3f3a2b54b X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;2:E+jDib1PPAC4Q7aoPZvwszNsXQYMNcrntXmsA7tyVKWBaidgxYaQ4lHcXm7mQ3rSYakG+q1eEnwmnsDY+/pTKuzKQjQ4Yoxg/6NkdLddDvWzlITiSxhVaTvsiVvFoqseRyEITGnbX/rLLjQw3lqOO5GSRzBIOo/uBrq9/UkmC9gzzjurgh92gZnuBtv2VpuDUH7gpssY5DDv/CS/f9OM6Q==;3:V/R2aYodseIZ/6HWU/HNL/AlYQZNuD+eR7jOop9VUkNk/bLbVHeqJJxn/E4Rn8T8meNoMSyuU/QG8JYGY7WbCepRTUrvIL6mBpXknFU3IShT+sDirpLHKQggAKpoZ6fjxJjzER6J6Z78nZZrCURYXQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0401MB1715; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;25:jKkxal8+lQSikVviHSDgpy8SIVbfBLfiI6gDqPtaZ3fiOj++6boqfbt49LD9mgHR2AtrBuJBSRX81tIasBVskW1Qb2XhERNp5Tl1a4hlosNNq/E7ItUSwD2AL6IGpQn6TSraTXMB6mjivuyO1yppiyCI+qtQZzfmT9BkXuZG8t6ufNFBhkshryg/K04Ef9hFiVkEYkEvMqnxTnXXxA8QTOJYrR4H+Y0bLmNdKNVYDgmVYW1ES3/y0St9rrSiYr7FER7cT62t1hWRAVYU0xozSPwri4kpUqpHr0caXjBgZ7Q5vXmHJp9rMt/15ywmAlrWASK/AL7MhIVTFya1dkHLC1HbydDTaZghy+s+e5bbFuLr5DQAlEgZ4g8bx4rOjapVOb1Hcg1qyVklSCqAQ2kmRJ+mBkC/LL1uIUAZQvUCy9rM/GQQUy37uTAnFma55bLMUlqLSfBK362zHnrXT/ge78Aq9R4pH611wYH+612cxEVkcLLP4nvXniHPMvXTeVas3lJddlA1sgC3dFIe+gTR3DRxBgxuPxXFg7pFNkdDUq3L/IDiF92JGxQqAqvYChHCcxd1fdsFG2APY0y9A2LmtONaDOObsBtt5EgN/TIO3jBpLnb0MSpDPminK6RZveZ1CARk4/M0BxFIvSwf0vvZCVApcdVGsCSwic7yJw4GFsnvgg4Hp3AcfiUinTUWqcZNY6B29fPrlSbPeYKEKpvAEQ== X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;31:WhV1tuM1f1O09c2S8KWQKqvYw9+ZuH/m6uX2OFgG9VquNtOwLmn0KXAQcUlqwwdqBz+y+z1FJiIMD31B69RIibVAsoHIeYhUmUsj5nI2SllSTwq1PSI4Q16FyOzAXAfsd6uRur1vRBET6RVxm1TKdCxaLjHaYazh3mZtyp8HQ9YEFqbkeOtg1i/t74zr5Nsf1ItHnZDVB1WhUgnKCPUjavcCe/AgmAuEnSZAjHH0qBt8jeM1W1AjYkbxY/+H0pkl;20:HlY3IoMUee0lLVB4bvZ02jV+qKRnGprmcyC1cLOyv9GAkHGX9UhCSO+GchBryrm6J5hZY6wcN6oIiMytGktmwwbpKltxj0Ed3A8yGWLW8oTtP5ZKEn1T3uH+LHtr+SWi4QnpohkA+5S4eiLd49eDFMXcySXr9hlRmPXBQlTSbEV+x+tooI2hbn7+epqhThs04tj2+1gXP4j+pUZ17x+zp/hlXMKxpr7cMtfy62SlFGUNY/yj+V7LX1AsrmzjHvKw0cmS8MzahnI5x9Q/AnmkxEllefua+p25eYgYZuttLXOaCwikOBv8hF+AeTR7sV+FFATethycyElXcB35h62EJxnoVK8teOcUYnIOAt9C0yK/EC++HtfjIJqUaJMe0Lfj2QezZ8TFbaOr4IJHT87yIezqaWWDKZrECM7AHgLr0dr5J+aQrUyPHBgX/Clr6xsgW1mb1pGbe8VBV5tFoIuOE69ueejG3khHN173bOkw/MuOTy8BMnu0PwoEgbLJiguT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:BLUPR0401MB1715;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0401MB1715; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;4:bNpjJ4HNKHQqf788qYDaJ+ESJLG3QgjUSR2n08b3SBYpO8qO+YmlsXaRbkaB/cx7ENROqtocv96zuYpnfFqbvxC+BVBCpeVqSRTAnBHVTnppdQGRJwZ02R2H2s7db1pIf0sZZRBCcgtQadtsW6UX9eYbgKVUx7ILwwNGPrAkC5FoQNWJRtFoFL47JqR6dgnNN+kyR+5DxwyPQ82q1O4q+G221KWWYmnGd3Y1TaI582aoLIfKs4aGiJuiNNw7SgA8MB9mO+tXBGZ1R83QUQFRWYM5IJOdLcvexZTERuuT4+DLE3520pKcbsT+xSwt+2e7dWgFXgw2wTKBab+OlY7DbpsOOUWb/ncIiCZGMdU4fX3mJNTQm1ps5z3HXCeIXLvGgBl6GWG39NZXX4c5UXNQbGvuvigxDCe5v/eyiNl/0Sw= X-Forefront-PRVS: 0094E3478A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(105586002)(189998001)(50466002)(36756003)(101416001)(42186005)(92566002)(6666003)(42882006)(2950100002)(4326007)(33646002)(19580395003)(2906002)(19580405001)(2201001)(68736007)(5660300001)(50986999)(48376002)(76176999)(575784001)(229853001)(50226002)(6116002)(3846002)(81166006)(81156014)(305945005)(47776003)(5003940100001)(77096005)(7736002)(7416002)(5001770100001)(7846002)(586003)(8676002)(97736004)(106356001)(66066001)(7099028)(921003)(83996005)(2101003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR0401MB1715;H:penguito.sanjose.hgst.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR0401MB1715;23:FXRfW0sDi8wsvaFNUlw0UbX87NyRsdcajtr7x/g?= =?us-ascii?Q?StnR4xbfVDezezAP+3bnpHkRxBiNCQU0vDqtA3JvRtI9++mpHG0sDnInq+mY?= =?us-ascii?Q?T0GVRqfBzSe2XMekeOMOwcvfOXSx7894rAq6KKDjdIW8vARcFFQywDFl3vDY?= =?us-ascii?Q?fJb9hx6qfEKQutdG0svnOiP2Q58PN+ywe2VI7dBSNL4Y9eam/SbvPfW426gz?= =?us-ascii?Q?3AHGHQvYG9QXzksp1NJ2zxzPQd0RFQEJXduZKH2Ahk9ddZkqufNyrQm2tlMn?= =?us-ascii?Q?pJjyr3qmFDaCHNTacMcw5h2sssYHEmgBEorST0JhHS5YHEoAnltsXCSP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w4tKBzCuTASmEvASX1qyzdU6gnHuehPJ3AqVMXnfQ4TBTg3xyn7y3+gEnXtbH9fEN4qIdBn1gVwEOfHmtJDFgtqWW67wvRulxWJ30ZKAgdBSAu0AfG8HU=;20:sdmfRYwjFB9QeSqBkikooF4E8lsHLTcrA/3pz7iK+UlqcXjc2g6RappCdZXJmR/yxLySODn2Vd5d5CN/dPJvF3rpSHsU4byVPcU+elGWWWEERQQ+RR1WTG1TKjPE14Smc4oa7TqpW5hz6z+xzEkMXS3zOA7a7zv/VTa3yMgl6t4+u/bal1BySsRBQAuY6d5ZGyJ+VVn0/Itv7fwVROFQXaF5vL/TNhYWpc5L7jc/Sg7BgR3LfVZZsRhG0391G5/U X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2016 19:54:12.5450 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0401MB1715 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