Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933291AbcJQS3J (ORCPT ); Mon, 17 Oct 2016 14:29:09 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:13652 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758281AbcJQS1v (ORCPT ); Mon, 17 Oct 2016 14:27:51 -0400 X-IronPort-AV: E=Sophos;i="5.31,358,1473091200"; d="scan'";a="25774228" Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Adam.Manzanares@wdc.com; From: Adam Manzanares To: , , , , , , , , , , CC: , , , , , Adam Manzanares Subject: [PATCH v6 3/3] ata: ATA Command Priority Disabled By Default Date: Mon, 17 Oct 2016 11:27:30 -0700 Message-ID: <1476728850-2309-4-git-send-email-adam.manzanares@hgst.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476728850-2309-1-git-send-email-adam.manzanares@hgst.com> References: <1476728850-2309-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: CY1PR21CA0045.namprd21.prod.outlook.com (10.163.250.141) To SN1PR0401MB1728.namprd04.prod.outlook.com (10.162.131.18) X-MS-Office365-Filtering-Correlation-Id: 98c7c622-6a95-4499-75b0-08d3f6bb4c44 X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;2:pNClMXAPYhdnPd+pOBV08Hf8h3GcBgPFGLIynHUpLjUt+AZ0L1Bo48A5wdFY/07WMOMLDNqgP/1Va0C4Rp+T50w96VM2/ENWjX7pKpfR6NbwrmgfsyVCxlyJBY34M4FPhHjwSMz0RwbyjKz1/iCvp8VOiB7iYQdEdnUdBYLiUYYF08W0lHzR/NAmacz1HKd+4POK55ZT+mgkLekWq3zQUw==;3:dL+CPIa2ojq7d40LwT2ks7KU3rfYTwYkDzykY7s0cJK5MkvRcghdvPZAEXYqrv6/kxgOExi0VDJ81KPnu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4j6WfcehNzRGkTf5n7m4goVu5ve2TRou2GXM9rlU7f/QDnQyC7g+55jLp9bHLOFJvJgS/68LYPqK88Irh/CYU18qt8gYYf+b9IcaFQTDuORc1h73fDFLvaXOVn8QyO8T0DzTRK5K3I2Rh9a5pYlCrAx55C4h+y2KBBkMlOVojIvpEAj4adbEiecY9gzPVCLzzdpNUUZjQy/Pzt81tRFFYFHmWmYgz4fpoOQ782Blj6kiqNhrfuRbj1/ipvhOAO+GHj8poJHAf9L8PF8+5ij2tQlbMlQG2O+jgLwBBi6FqOVveGRitNAmJOnphCAtyMNFxJ0Ji/QDqLH3ay2Fs/T01jhV4aoKetNMT6WgaRt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:SN1PR0401MB1728;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0401MB1728; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;4:d9LCibMvRNpW+SHRdB/9PvDmbvwHy5snoV+jYCKPRv1qV32WLGv/RXibt4ekDapD0+ZP/NX+tvBOBD9gS243TwPE2N9M6us1NT+Oq5r4ytAP+qcnI+0e7/6Euyiq8M2qbjIaMlwVOb1BeOeUJhm5K4V3nrGbt7iEt3sBdLKTCehCBMEfn0reqR2zaJyZSvq3semZ1UpqYRMq1pX+aPILWRXtRaiECq9C+HfEs38BTbejZFCFy/j0T4QOoI+JplVO0XrArGY4tphBsKXfOz2C5xM55u2a0OvnmS0X7lxVNWUwX6hVdgsEZcSJuj6JOTSqEmtPIzA3IHZxs8TyC4g1zWnEVRerecU1F3ngeW6sf4OK0vjuLs9xFVYDBZV663M79d/t7wzUBpNdQoIMov6/OOyVCc7NZ6xXBMdlRSQSkjLx5hPuOcphsh9IZjsty+itlExmza4LkCW6ue6uI2AbDg== X-Forefront-PRVS: 0098BA6C6C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(5001770100001)(6116002)(77096005)(8676002)(97736004)(305945005)(6666003)(7846002)(7736002)(81156014)(7416002)(3846002)(81166006)(5003940100001)(19580405001)(66066001)(107886002)(19580395003)(586003)(189998001)(4326007)(92566002)(36756003)(4001430100002)(50986999)(42186005)(76176999)(105586002)(106356001)(5660300001)(50226002)(47776003)(229853001)(2906002)(68736007)(48376002)(2201001)(42882006)(2950100002)(33646002)(101416001)(50466002)(7099028)(921003)(2101003)(83996005)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR0401MB1728;H:penguito.sanjose.hgst.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR0401MB1728;23:Fr3WESXlT/Yktf3wFkqBuiJajjVWyIqiPTdePDJ?= =?us-ascii?Q?h0PXaSEfVL6QZ1dD4BT2Q6h0TfvKGegm0z4HhUYECN4fLoFxxL2eWiA9/Q3p?= =?us-ascii?Q?pn1SKKodmP5cLgeWKtrx5BAyjch6wdK0T0SE1BIwi3Ij60fKoov64PXj2rho?= =?us-ascii?Q?3oK9GwrSZx/lUsJ2DimVxlA3Fgbj27IrjXfXXu3uIHDiCttJPtTIAdW22jpt?= =?us-ascii?Q?Kl7djzeQD41VYftHdWr53bF8dEzCTJIoY6sJunUxb27Pn6iKOZoGiB+0bv0y?= =?us-ascii?Q?V05pBig0R9LIam7zDynQIJSrGYdnUMvispBH9jxm9dUOz1105L1ARl8ddQ7C?= =?us-ascii?Q?z5vqfY5uuasEOjZjDwsmTComv2rZ2CGpD+WBEl5hbdrvy6y2ggBzziiKThUv?= =?us-ascii?Q?fWbEPgDPUooIKiMHWsB39DVGRjy7WLkxnmry/ul3vc8PCLltXu6UNxoYQswy?= =?us-ascii?Q?tc4ml+NdQWK/JLOpwOW6wU7WGIibm+iD7x3B1HTNOIPjlc9duMgiyBble17U?= =?us-ascii?Q?FPbj9HeQcsIlnOJh5nn1bS5k1UKbfIMXjW/+66CbPdJ6eypyJN1qhHNVXaSF?= =?us-ascii?Q?Bd0OYXQGYbqKKUnSxNVwNpT9+IKuIU+cv7gDmLTxbq6COHd+/U8Dbvb/40U8?= =?us-ascii?Q?MFV+MkW88jlfXQ0IWj7zYnyIEhrlqv8IjMla5sXre7JGg7yqpWgwuPXQku/s?= =?us-ascii?Q?3AFnw5hSYXLVw5Cpns38Q6b+OnMmStT7m6wa2WPIENVkoynqoNB/BEcgn3RA?= =?us-ascii?Q?CncRAZCIxdpfxy8OZJs8jDWv+24ywqB6eMq0VXZypVY25uZ1j56Yc0ryMlrh?= =?us-ascii?Q?15usO2IF7ZruuEO0Qz4SGGmJPjODKhjlNPNC9iB1gJq1GKhjM+AkWGCwh9f7?= =?us-ascii?Q?S/P7M8bGS65dseTauBcfTw172Db0d0gx79yjnA/423ZagWQbWuyBOa8+uA9b?= =?us-ascii?Q?c9dR1RzFRvVgGHol62K9vXCprEHARwIWkTTYgohBljmqlqe/INGJJczNksTH?= =?us-ascii?Q?0Kd5ZeD4bQec3lDeSbn9pf8NUmD9fWS10XdaZE3kBBMMgPGkxLId8eAVv9Zn?= =?us-ascii?Q?qDHeJaDNg1kLIZCRJKrTX7oVMMSjxMVxJ9HYGq+QqqLFpWnHrsnA077PE7Vt?= =?us-ascii?Q?VqsDjdZW78qOubmT4fV2IgxI7P02w/JNJBcdCY088agCa/vdY60O0nKTlPhd?= =?us-ascii?Q?RN2ynJF/SDiwlpt/br7BvGvvxF1UlMF5TqBEsJlUn09MkSE7mBbv0SDiNlCC?= =?us-ascii?Q?rlYAROjgCxwOi+aAsgOk=3D?= X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;6:QVaHdO6nb4c46c5n3VIiBJwcqTSdjAj3stuxfx0DVGPQQPJk0rzk2aSIG+P+5JQLRG+Z1cZUejNEQgdMalxGSMEqJGArBd8vRaGBsmhm+bp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aUm0ePQfI9j5vmNozLR1LsR7WScw7YX0YiHuTqTZWG9OULuQO6LDmjNEX/LuGTcVqP432iWjzIHecvCDCQ1ylOlJIVxVFHPhcnGiYoNFf6QgFgznevCvNOWNGKmOfkvBo1IL7xogByKUq+wHDJeap918HeDwIJ3lnil63C/LKDudqsEa4 X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2016 18:27:47.7395 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0401MB1728 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4869 Lines: 158 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 | 7 +++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 0d028ea..0e17285 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_ncq_prio_on, NULL }; EXPORT_SYMBOL_GPL(ahci_sdev_attrs); diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 181b530..d8e1278 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_ncq_prio_on(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 2bccc3c..f2709ac 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_ncq_prio_on_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 ncq_prio_on; + + 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; + } + + ncq_prio_on = ata_ncq_prio_on(dev); + +unlock: + spin_unlock_irq(ap->lock); + + return rc ? rc : snprintf(buf, 20, "%u\n", ncq_prio_on); +} + +static ssize_t ata_ncq_prio_on_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_NCQ_PRIO_ON; + else + dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ON; + +unlock: + spin_unlock_irqrestore(ap->lock, flags); + + return rc ? rc : len; +} + +DEVICE_ATTR(ncq_prio_on, S_IRUGO | S_IWUSR, + ata_ncq_prio_on_show, ata_ncq_prio_on_store); +EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_on); + 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_ncq_prio_on, NULL }; EXPORT_SYMBOL_GPL(ata_common_sdev_attrs); diff --git a/include/linux/libata.h b/include/linux/libata.h index 1a524cf..5f24ca1 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -167,6 +167,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_NCQ_PRIO_ON = (1 << 21), /* Priority cmds sent to dev */ ATA_DFLAG_INIT_MASK = (1 << 24) - 1, ATA_DFLAG_DETACH = (1 << 24), @@ -545,6 +546,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_ncq_prio_on; 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; @@ -1628,6 +1630,11 @@ 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_ncq_prio_on(struct ata_device *dev) +{ + return ((dev->flags & ATA_DFLAG_NCQ_PRIO_ON) == ATA_DFLAG_NCQ_PRIO_ON); +} + static inline bool ata_fpdma_dsm_supported(struct ata_device *dev) { return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) && -- 2.1.4