Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933499AbcJMUCn (ORCPT ); Thu, 13 Oct 2016 16:02:43 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:32825 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbcJMUCd (ORCPT ); Thu, 13 Oct 2016 16:02:33 -0400 X-IronPort-AV: E=Sophos;i="5.31,489,1473091200"; d="scan'";a="25155221" 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 3/4] ata: Enabling ATA Command Priorities Date: Thu, 13 Oct 2016 12:53:52 -0700 Message-ID: <1476388433-2539-4-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: d90ce83d-9e74-4440-a091-08d3f3a2b404 X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;2:fZw3F1jtIsR1qf+S0/dz1sCMe618ZeSRe5jbuaMrTTcBWkauG1w8LFJE0rd5vZXhWv4LzFxOKH3+9Dmy9pFJt78TQfLFu4OZBKuyOaMcUoutpipqfsBhuXDiXNnFoTzH2I706IS0LcVJIGfwGhuCV0aR0TcgcKHs3MYXHac2jGVDkMrUncunkAVoRIWC6Y8uwCcicYU44U9LYjA3RwDvqw==;3:b01/tDirvg17W6dFqXJBz9y/pWHpUV34f1WaaMOL5uMFYNNoxWyR6Eww3UQQExBqduJCUg0A9s/0J+TlelV+Dtj74dHKkVXm7BIvasBPpVqNMNmfGjPh6xFtOdisZtiRP99z3BoNTiJ8vBqReUXDGw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0401MB1715; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;25:90BcjyWjL1j5Oq0/WyaF96WC//IEDptBc+lBrSTbUO02wXjtxrKa6f+/6MSylDPJK0KY5Wd2K0VAM6BlSsxffyD+o8QGkXRNcNGoOZnyf3/U2VEUfPZMYRnH7L4HTq8PVc+2VVmbrfASOZUnxECzTYVt98KqhEpIubytmp7DXyeQbfkFg7I+t/P6BoFXy4rBW6s0JuYGzox8+a//kmP7IPm2NqRTn/oQnt9HlIFULwYMfzCMC1nFWoHGFnZv2cyPC6lsF2ZQk+nFJJbJDz9OkKKw8qonHCj2oYcgvkjlNjub/CYvMP5RrR0Zle19VPz7nE2SguRYqdgbtFsJfTu1tJUW2eRK84hZA8NrLkCogctwcGbuyhQYWLtdPfU684UqjPAsXKWetagWLljEG+E2pVOsYv6M9an7la2py3lL6yhGy2anDdEfbmjesa8p1pzrPDTGCN5LdYG4EEM75PvU+q388utG/gj/QabPwc8j82vVOFbl/birMD3z8J+6I4X9pGTxv7K75aPX3OCmtEayh4H+vn8v/nFrrdMRjbKmpZOoQMElEdRy1riURl+gC+G/SPFtu2pwB8BYJHb4dQdWyFu3+VQadD+r2aKBzqK8+2iSJXFgsM2G0NXbKPw3S7Uwe/h1f0BHoQWlhAwSjeySfo7ejaPtzMvbzU43yajPjxDmT8LyqhGO5pnphwpzznhCRp0Ks7MrX3ZBh6jmrF+APigflVAwiiaC2zUnYg83Rj0= X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;31:71D2Y+OZNmYJTm0nC8FnsHfDmBPV/BjN52mic7UFZ8F58Hl5xmblCo8XLeJQhmSUSNX7EFY4LxcLsxtOMRpWbdXZ0a5ZMOQWW8m5hNMOu7Oin0mNCO3wtjymZbysIWh9PlmulHMuuhipQVhcJKtNuGsFjeadA2CwLU5Mqi2QRKzX/0ndPCLU06+87V19oqOegAlTHieMiZV84Q7FIHlD0a+FziSwJHi8kPAImxl0/+ExCrDR7NboUTD8JKJ5H45hc+fl08fWqbywy+HjMkQl6Q==;20:6n7qcEnz6mO9DKmN8WOnNbI7fn0DpOF0fh+jTAua6p9lPXaReFZvb/y6HwYletlRZd3ybqaPPjlSEzMHv/3ROLowVH4wAXvvldQoEY5Up/xq6n6Y3K6Pj5sOgE9Ez5d4hIfPbxNITJnUOSERkStirjFNOWACEP0vbG9Ef0S4EffBRoVJcH6Xc7bvsYeyEo/RgoP1ZxeVDGwwYcNYj9gwTsPaUyZcUCsS9jzgjBXtbWxHXzdtJ01Ktpq7yIiUOUxvwpH8gMTFQUaDLkZx8Fwimxd2xbqOtVAI3vniC6aMEnh7AI/D/TO33dm7Iv5iQgJQjNQbZ039cKHv4xS9/DRW4pBvyNwxImdzTSxSpcCBD0h3EY3n5RT2wBtJMhequaiNkI1C7EU6D2wY4JTYJSb9gKUQDtnFvIgrkrWuJjR1LMfJ9F4gz6fEkI9UAkG4Gnxg7ciwgDKzeAFVyAIZKF9lCHHZtcuTHdlihuavzFFPFBR3LbvbDO3vH+4Lrn8fvYsG 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:Tx56xz2F7fFUrd1xVm4Pwsx4C1dAZ5k6j0MHNu/fTKSHVkMRPnwj9s6qas6eKy6s6uYBhsUw5cWqMaK0POZ1JIZdvt02Ju2mLmvJiSbVDG39Z1+ipLxGEjz5EiLAwWhFS69umyTO5cAx1V3uqaia4ubkx4uozgm2H2SWPjjN3pQyKfj/LO+7tUEHPa6LkeuY225Pk6WKfy13NEueOLzzRHEF7rxcnKOWg1QLSvFUFWZmJebCk4drKcvEVd45VomLeu38ds9UWMHe+1raM6B2Rfl3HYm1DdCIwTnLrxkJe2XBouCiDeXGA5AHWk3NKV8wu7xRhd5mUGSiPnMxE2VGMIBkzte3gvwrp0mwrxbjMLcQVkS5r9m8TIcvYCk1KrDaIho+pN4U8O+Amh9E/8B4OZWEqd1Z9tXEXFi0x3HcSiI= 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)(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:KXXDOXfuzerEOcchbPTx2+MqqEF8E86FzhxIM+T?= =?us-ascii?Q?nAVhq2HHj6tfoC0T3PsfMDSxiNtDe948LLKFWV85dbpQn4cUxV64zYHUFeFJ?= =?us-ascii?Q?PrIDR9kmFcB6TbqVsJnRC2GZuOdYoWSB8coLfhuRyxE0F9snHIkJz0nMMHyE?= =?us-ascii?Q?s8xK7n8n1hPFWgqPJLuD0dtwrWzoBh/aEt1Lfsnu9GsgVJRw3ARQyN7BwwtH?= =?us-ascii?Q?aoJxnZkQ8Jk6SPPfQbN5YgKPaP3lraiTLm3C1nd8q5p2YGO64Ap4YeNoFCxG?= =?us-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y4TSmQLNjPXFWLeTN354?= =?us-ascii?Q?g99OjYAWkSbopN5uxHHTTy18WBayKA6DQriuG?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;6:KVYJJCRxIE7LMG7F2VqbTyR8r4qbSlgjcMcFndkubrpeNUkOPf7kC3WYN+6vX/9h3iYvRg/yOZpzlPgWANGEwZndsNTft5qOGtowo3GpaJtODARDi/OFtsj7acTm9bGO3Bg6PA9Mz6y5/GNDE2SHPD5faBHWqCQuHVROwa99qH9KgmE9nPssYF0toZGLOpmZTH+zS0ef4ONEbM06COsy/ZI+ASwnhj696YRmjkLV8cXz9uvz3JRLuEIyggeaUFPQoFVFUsyJHClnq9y2twWhOo+ojdtcyJalgNlWSETfHrXLXHUdcjKrpPwbQCX5dnCRamX8HtD4Wls993ZG3yuIX5sDY7Zoo4rfKAR6uhe/1o4=;5:NjBee5X/23HQIPpM7YoFfTpx4CTxTQL9xu8KNIpZPEg7sfsm8xq8x3DdrPUmso7Og1tISRuWc9wkBYioBGrR2yA/dUFaYms6ykPXQl5rq/9/RXlOC9oFjVu4L+g6um4VzS+qgCQtZoljWIgdSIV3dZdgEqDsNMzBqZsLPsvxx0Q=;24:PxYhDubyMN8lTlLf+fSZlFX0TDpLk89GQnreQeIaqmdgCd4iMSPuK5hzVN0djtEJKcCQ6REUHhMKS17uchp4BCdXYIyXEsCT6SI71ZHlw1k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR0401MB1715;7:tI6fRZbVeIlRzpQo4F4ex8heyKNOACg2+6ke0v6j67CFgFtEc6fF7AsfBvAuCCvM7v5MWoo27zQy4NHeCYLiXpSKGho7nk0u/wKDarisnZah20K5HdrWdyMJU/M+BJliSPg/kp3LNq6rPuhK1L/VMhFCpqWjBGhJGIJUtsDrHzDRCjZstUoTxknZrX4heETv7qcY1SYttRT1s6gOQAAQCzULEA4ryC9PH3Tgw0LjMEko/PrRAXzK5fg4yokiLqPQ00BlX1jDAKNjKFaS34aAyD8vUwr8BX+YkR+VsYcFksD7zS3+FACWYSpHV/K1C+K+rTPzBav3hC1nmd7W7cQCdDXQbejhyOQb2ORcuWiTk9s=;20:r74c/V5DMzMIXJQrGxcxJ9Fh/G7G2aE3EzMGqg+E570ywj7XmqH0rIuwDuaaCD/wD6FBxcIoX0/Btiw79lrf2nNxEopEdvDcrFC/LZdFXut2Fjbg4Jmoc2RftyaL9/SteKR/soNCUklSy6yUja1nkNnmN5jG/N24QU7xvsYLoshtw1IERKTfsrvvE3S+JhPQ2LbOwnnZqR75KQKwfJ2JznR6U8nAmQPaVczwDsBGepj1tfdG50QfiIg+iB9Wvoqg X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2016 19:54:10.4199 (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: 6501 Lines: 201 This patch checks to see if an ATA device supports NCQ command priorities. If so and the user has specified an iocontext that indicates IO_PRIO_CLASS_RT then we build a tf with a high priority command. Signed-off-by: Adam Manzanares --- drivers/ata/libata-core.c | 35 ++++++++++++++++++++++++++++++++++- drivers/ata/libata-scsi.c | 6 +++++- drivers/ata/libata.h | 2 +- include/linux/ata.h | 6 ++++++ include/linux/libata.h | 18 ++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 223a770..181b530 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -739,6 +739,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) * @n_block: Number of blocks * @tf_flags: RW/FUA etc... * @tag: tag + * @class: IO priority class * * LOCKING: * None. @@ -753,7 +754,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) */ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, u64 block, u32 n_block, unsigned int tf_flags, - unsigned int tag) + unsigned int tag, int class) { tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; tf->flags |= tf_flags; @@ -785,6 +786,12 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, tf->device = ATA_LBA; if (tf->flags & ATA_TFLAG_FUA) tf->device |= 1 << 7; + + if (ata_ncq_prio_enabled(dev)) { + if (class == IOPRIO_CLASS_RT) + tf->hob_nsect |= ATA_PRIO_HIGH << + ATA_SHIFT_PRIO; + } } else if (dev->flags & ATA_DFLAG_LBA) { tf->flags |= ATA_TFLAG_LBA; @@ -2156,6 +2163,30 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev) } } +static void ata_dev_config_ncq_prio(struct ata_device *dev) +{ + struct ata_port *ap = dev->link->ap; + unsigned int err_mask; + + err_mask = ata_read_log_page(dev, + ATA_LOG_SATA_ID_DEV_DATA, + ATA_LOG_SATA_SETTINGS, + ap->sector_buf, + 1); + if (err_mask) { + ata_dev_dbg(dev, + "failed to get Identify Device data, Emask 0x%x\n", + err_mask); + return; + } + + if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)) + dev->flags |= ATA_DFLAG_NCQ_PRIO; + else + ata_dev_dbg(dev, "SATA page does not support priority\n"); + +} + static int ata_dev_config_ncq(struct ata_device *dev, char *desc, size_t desc_sz) { @@ -2205,6 +2236,8 @@ static int ata_dev_config_ncq(struct ata_device *dev, ata_dev_config_ncq_send_recv(dev); if (ata_id_has_ncq_non_data(dev->id)) ata_dev_config_ncq_non_data(dev); + if (ata_id_has_ncq_prio(dev->id)) + ata_dev_config_ncq_prio(dev); } return 0; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e207b33..18629e8 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "libata.h" #include "libata-transport.h" @@ -1757,6 +1758,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) { struct scsi_cmnd *scmd = qc->scsicmd; const u8 *cdb = scmd->cmnd; + struct request *rq = scmd->request; + int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); unsigned int tf_flags = 0; u64 block; u32 n_block; @@ -1823,7 +1826,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) qc->nbytes = n_block * scmd->device->sector_size; rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, - qc->tag); + qc->tag, class); + if (likely(rc == 0)) return 0; diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 3b301a4..8f3a559 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -66,7 +66,7 @@ extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag); extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, u64 block, u32 n_block, unsigned int tf_flags, - unsigned int tag); + unsigned int tag, int class); extern u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev); extern unsigned ata_exec_internal(struct ata_device *dev, diff --git a/include/linux/ata.h b/include/linux/ata.h index adbc812..ebe4c3b 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -347,6 +347,7 @@ enum { ATA_LOG_DEVSLP_DETO = 0x01, ATA_LOG_DEVSLP_VALID = 0x07, ATA_LOG_DEVSLP_VALID_MASK = 0x80, + ATA_LOG_NCQ_PRIO_OFFSET = 0x09, /* NCQ send and receive log */ ATA_LOG_NCQ_SEND_RECV_SUBCMDS_OFFSET = 0x00, @@ -897,6 +898,11 @@ static inline bool ata_id_has_ncq_non_data(const u16 *id) return id[ATA_ID_SATA_CAPABILITY_2] & BIT(5); } +static inline bool ata_id_has_ncq_prio(const u16 *id) +{ + return id[ATA_ID_SATA_CAPABILITY] & BIT(12); +} + static inline bool ata_id_has_trim(const u16 *id) { if (ata_id_major_version(id) >= 7 && diff --git a/include/linux/libata.h b/include/linux/libata.h index e37d4f9..244f261 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -165,6 +165,7 @@ enum { ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */ 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_INIT_MASK = (1 << 24) - 1, ATA_DFLAG_DETACH = (1 << 24), @@ -341,7 +342,9 @@ enum { ATA_SHIFT_PIO = 0, ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES, ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES, + ATA_SHIFT_PRIO = 6, + ATA_PRIO_HIGH = 2, /* size of buffer to pad xfers ending on unaligned boundaries */ ATA_DMA_PAD_SZ = 4, @@ -1609,6 +1612,21 @@ static inline int ata_ncq_enabled(struct ata_device *dev) ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ; } +/** + * ata_ncq_prio_enabled - Test whether NCQ prio is enabled + * @dev: ATA device to test for + * + * LOCKING: + * spin_lock_irqsave(host lock) + * + * RETURNS: + * 1 if NCQ prio is enabled for @dev, 0 otherwise. + */ +static inline int ata_ncq_prio_enabled(struct ata_device *dev) +{ + return (dev->flags & ATA_DFLAG_NCQ_PRIO) == ATA_DFLAG_NCQ_PRIO; +} + static inline bool ata_fpdma_dsm_supported(struct ata_device *dev) { return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) && -- 2.1.4