From patchwork Tue Aug 10 05:49:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A3F1C43214 for ; Tue, 10 Aug 2021 05:49:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A4DB61051 for ; Tue, 10 Aug 2021 05:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237680AbhHJFuH (ORCPT ); Tue, 10 Aug 2021 01:50:07 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9539 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234808AbhHJFuG (ORCPT ); Tue, 10 Aug 2021 01:50:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574585; x=1660110585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N9HTUe3fPenLFb7TILYqOuQ90dOIPTNwU0OUTxnf8fo=; b=U3xbJfERL0Um5mrhrvlTqwzzB6SPox/8qUoRKjxbwwlC8pwTiIWCGfcv jG3olqAsHw9v6W+RKCT+GSQHr3vG8W5NXi9JhAhn61Zf8lYdw0Fwr98xe UXhZehO7TcUx50BrkWx0oK3+K1iMnpQoKhBpXw65PHNRgVTySYiU44Hcu PSp31BdCtDL51oOG3W+c8L4rTn666471Ez7mcAOELHcmytox1XOUMd3Kk 4tDGYSHIeQhczILPicVQ3xhL5z2CbKpm/g6KZ4DGQO2r1wDrWLclSGkQF HXC+hmyb7kACe0aer7zt37RtuF9pnDl3Tgvdx06Iv5BrLPVP0Uiki7xRf Q==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340180" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:45 +0800 IronPort-SDR: IrjvkJPznNtalmOYfwRfbeiWq5reqwR6PaP1n83SqeEVOoB0zWNEgSRHHcIDKL42m5Ewj/ZNxv 7cAu+4nN4xKhcnlxKIlgGXTGEaqzQNcnlj9Jzbyn4JSNvzH2Sbfn80mtqr5z1CxLw2zAGlMbiZ vMkrJABM+LNx+kmOh376OCogjgZk2b1pxoKi982ev/8FM8Yz5pU2ZtVmJ1PCaFVg9sXxOOfj5w AcXHwhirwBkbUgBB/OUBKU+rCB8104fPRAadhkT+PBUsokyffFta04wpNHyLy0PbRNZdFimyww V6kCxLVdWNILJL7R6ya8JnbI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:07 -0700 IronPort-SDR: 79zRLzMH4X+kgTkweewrXnwysFpygZK9ky41KR3sDSm3FyGpdcX6+74D9ySlhwbz/IxFSzLc9W SYTqvzfs3h46q5kGUgwK7ImgLyY35/v+BmCtn+RFh3b1aSL1AQMvecBQKx2G7EzY3DQ5DU6rcv Ed6XJLwkoYeY/zLIRUcupUgQzqRSPKqk3HZMgbPeTblNRwd/gCcvU+MHa03NdQM2MlEVKYF0jc QtYe26zmE9ilX4bNmmNkiVFzNQg6gNu/23I4aLa7XgNh+Wd8ZzB5CtLfjvoLkm7Rv8EWn9d76r REQ= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:44 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 1/9] libata: fix ata_host_alloc_pinfo() Date: Tue, 10 Aug 2021 14:49:31 +0900 Message-Id: <20210810054939.30760-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Avoid static checkers warnings about a potential NULL pointer dereference for the port info variable pi. To do so, test that at least one port info is available on entry to ata_host_alloc_pinfo() and start the ata port initialization for() loop with pi initialized to the first port info passed as argument (which is already checked to be non NULL). Within the for() loop, get the next port info, if it is not NULL, after initializing the ata port using the previous port info. Reported-by: kernel test robot Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 61c762961ca8..b237a718ea0f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5441,16 +5441,17 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, struct ata_host *host; int i, j; + /* We must have at least one port info */ + if (!ppi[0]) + return NULL; + host = ata_host_alloc(dev, n_ports); if (!host) return NULL; - for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { + for (i = 0, j = 0, pi = ppi[0]; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; - if (ppi[j]) - pi = ppi[j++]; - ap->pio_mask = pi->pio_mask; ap->mwdma_mask = pi->mwdma_mask; ap->udma_mask = pi->udma_mask; @@ -5460,6 +5461,15 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) host->ops = pi->port_ops; + + /* + * Check that the next port info is not NULL. + * If it is, keep using the current one. + */ + if (j < n_ports - 1 && ppi[j + 1]) { + j++; + pi = ppi[j]; + } } return host; From patchwork Tue Aug 10 05:49:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5C6AC4320A for ; Tue, 10 Aug 2021 05:49:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86DFB61051 for ; Tue, 10 Aug 2021 05:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237688AbhHJFuK (ORCPT ); Tue, 10 Aug 2021 01:50:10 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9539 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237683AbhHJFuH (ORCPT ); Tue, 10 Aug 2021 01:50:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574586; x=1660110586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EIH026mlpK847URWOEkIJeSWTxgkrb13VQ8oOv5tb/A=; b=W/vrfAB++7+dIyU65/qyfAqk25H0rpuz6DJYEmRf5z5zrPyG4trrrJVJ FGlvhkqO+5Nql9XzhCEX7fDKN0a7WjgUguMzg22jipx7YOdSK6Rk/RHPK GpzwEx6PBZ1kavxzntlF+pa+Ak31AnDY9OtmP23aofCK7RHQEi/onRopN ZM4q5tWA0aEIK5zsHBkxqgqh+pNYcBzr1kqmMYP92BB7+g/26hoQ5Fvbw EaNmBRBDEkF3yKTISVn6p88Kgt0EEqqVJUbKLdNlIeL2BT94rKL9lGzlh kX1aN+HxBh9Y0Mix/ZPN/CrWl/iG222GHThlD+3/8uhz0YVSDKHFtaf4o g==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340183" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:46 +0800 IronPort-SDR: Kb7wDenXCx/erdHc/4+ScDfo4vyH5oypjl5PmWBwcXX+Qce2OI1UmG9dSVjZR1jCCPBxpVIlj+ Jk8xGO3l7lmNwUejqVTvo0SesTiBPDut+3WpwJ0OjnkixgCFY0UbX3IDxMGEAsTX1UW4XgD0Yy 37D9Gt03o0TVhWosxdi0hQKUcscTr61LhpKqf7hB8Whibftz474TeY+YQFEvgQZINiLuen08MO lTPSOmvoq+o+Wtf1w8RMVWrHaOyX5qjRwUroF8aGVMN7T1uG3vXh6fV47hAloeb193y6ele8JN JumD08tTIdufpgp2BkNmWWVP Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:08 -0700 IronPort-SDR: KaFeV7Cda16g3sRUQjPK5JqRL9J2DfaUq6F+e/1p+iIWNL6gtSv3Jakgm0wpeE4El5W8G685uE bf0u3hkGePxYeKOJ0o27+waUb4hUBoVIAXUbR6HntoICAWYKneMFSF/Q8jk2tsZYZTIdQAU6pk vy80cFqLypyYaJosfsAmO0JJuhmBjNBYp/+767S8PYesbG57kayDkQO2/Pfcp4kFQuAFR0dnzQ yBK/3dUHEOxBw9vPWV7E69IwspYvJD31MaiTkMv01qOog6y5Y7xp+NRVtU1JzhTblMVsmP0Iqs Mt4= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:45 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 2/9] libata: fix ata_host_start() Date: Tue, 10 Aug 2021 14:49:32 +0900 Message-Id: <20210810054939.30760-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The loop on entry of ata_host_start() may not initialize host->ops to a non NULL value. The test on the host_stop field of host->ops must then be preceded by a check that host->ops is not NULL. Reported-by: kernel test robot Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b237a718ea0f..d3f7830bda2e 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5583,7 +5583,7 @@ int ata_host_start(struct ata_host *host) have_stop = 1; } - if (host->ops->host_stop) + if (host->ops && host->ops->host_stop) have_stop = 1; if (have_stop) { From patchwork Tue Aug 10 05:49:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23874C4320E for ; Tue, 10 Aug 2021 05:49:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 010AF60E52 for ; Tue, 10 Aug 2021 05:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237683AbhHJFuK (ORCPT ); Tue, 10 Aug 2021 01:50:10 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9545 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237686AbhHJFuJ (ORCPT ); Tue, 10 Aug 2021 01:50:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574588; x=1660110588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+WWKZF/7COHNQFSxWKyzuz9m7BPKJUtEUV2VtAma0Ug=; b=V+QvPyZJGuq1/nYhTzHpWoAvZMs83PeB+lqCL/6FWaX3ywPqGbF5022R yUXzgQ/6Tk6xMbWE3leVhAXQKNlqd1wqyD0URjjmJIEe1ljsVYn8lWAoK E5h0xkOOgN99krOKc8AKlaJXerPHI/MczUkTAOkJEcBk76B9hLKZoUaD8 QyQ6d1fj+H9eaFMU/1NB5GiHiJEFdBK9Y/MfT4kxo8vynxkXfKHadhcTf 7VFLmg8nJX/JoYBsbYc2Anmu08gw2AsV1pt8wuhDMu8Yvh535VLvwGz5t 3RqST4+RiNDECRcEF/yuFTwcz4pIrdlMcDsgv8Mc0sPbLL7TBnUFIq95R g==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340187" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:47 +0800 IronPort-SDR: dECFMiOjfRiOnaB7t9lo4FwM1WexrQ5jGBiRSPBTJYsGHAvkuOcA5vKKpcdPkQFKA86NcBFB3U 6K6Pvn7KQvCXwSPugyEAU1dxw/MbCfKumFL0WTonlgWVIf1KAR1duRF7kGtPVWfoffuiBIyKcS AWt524rc/nsz2tGxm48nhfELla3KB7DNb68uJX6nsdJkffyf33uevAgrDSA+rC+tMPzNUSILEw Ic7pX+ncGZSJpSOriFlrkln1f9YKuOsG7yR0JZLg+L+zY42afrDRARzdx9gZNy4QsMxuoqQB4y 35TJzuSXEW25LwCu3atJSd96 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:10 -0700 IronPort-SDR: 6miro2Ao5VNffPUHj4pzEZIk5Qsqd/wrrhW9X2FS2tawqM9Vt2Dad31ad4f3hWAbUKXJun3Dhh aUZxsJi7PrJ7DxWu2snurkfj/MbiV4b7soVDpbW9BRCzGm0+LkfeEAX2Ya+ckZAd8QtXkDkMBr 0lq8lRBZA474vexmOLcVHIuuTY95Vp28eKVTRRfNgIP73nHNCQR7clwScTO823tUM4AdMoKgqJ 59HTUYR3HrxUc0IQIDIT1R5q/pPq6hpTwGZt7t3U1X+lKb176qMkimRUg/FUZ09E0gm7pRDAbm yFE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:47 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 3/9] libata: simplify ata_scsi_rbuf_fill() Date: Tue, 10 Aug 2021 14:49:33 +0900 Message-Id: <20210810054939.30760-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Sparse complains about context imbalance in ata_scsi_rbuf_get() and ata_scsi_rbuf_put() due to these functions respectively only taking and releasing the ata_scsi_rbuf_lock spinlock. Since these functions are only called from ata_scsi_rbuf_fill() with ata_scsi_rbuf_get() being called with a copy_in argument always false, the code can be simplified and ata_scsi_rbuf_{get|put} removed. This change both simplifies the code and fixes the sparse warning. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 60 ++++++--------------------------------- 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index b9588c52815d..0b7b4624e4df 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1765,53 +1765,6 @@ struct ata_scsi_args { struct scsi_cmnd *cmd; }; -/** - * ata_scsi_rbuf_get - Map response buffer. - * @cmd: SCSI command containing buffer to be mapped. - * @flags: unsigned long variable to store irq enable status - * @copy_in: copy in from user buffer - * - * Prepare buffer for simulated SCSI commands. - * - * LOCKING: - * spin_lock_irqsave(ata_scsi_rbuf_lock) on success - * - * RETURNS: - * Pointer to response buffer. - */ -static void *ata_scsi_rbuf_get(struct scsi_cmnd *cmd, bool copy_in, - unsigned long *flags) -{ - spin_lock_irqsave(&ata_scsi_rbuf_lock, *flags); - - memset(ata_scsi_rbuf, 0, ATA_SCSI_RBUF_SIZE); - if (copy_in) - sg_copy_to_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), - ata_scsi_rbuf, ATA_SCSI_RBUF_SIZE); - return ata_scsi_rbuf; -} - -/** - * ata_scsi_rbuf_put - Unmap response buffer. - * @cmd: SCSI command containing buffer to be unmapped. - * @copy_out: copy out result - * @flags: @flags passed to ata_scsi_rbuf_get() - * - * Returns rbuf buffer. The result is copied to @cmd's buffer if - * @copy_back is true. - * - * LOCKING: - * Unlocks ata_scsi_rbuf_lock. - */ -static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, bool copy_out, - unsigned long *flags) -{ - if (copy_out) - sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), - ata_scsi_rbuf, ATA_SCSI_RBUF_SIZE); - spin_unlock_irqrestore(&ata_scsi_rbuf_lock, *flags); -} - /** * ata_scsi_rbuf_fill - wrapper for SCSI command simulators * @args: device IDENTIFY data / SCSI command of interest. @@ -1830,14 +1783,19 @@ static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, bool copy_out, static void ata_scsi_rbuf_fill(struct ata_scsi_args *args, unsigned int (*actor)(struct ata_scsi_args *args, u8 *rbuf)) { - u8 *rbuf; unsigned int rc; struct scsi_cmnd *cmd = args->cmd; unsigned long flags; - rbuf = ata_scsi_rbuf_get(cmd, false, &flags); - rc = actor(args, rbuf); - ata_scsi_rbuf_put(cmd, rc == 0, &flags); + spin_lock_irqsave(&ata_scsi_rbuf_lock, flags); + + memset(ata_scsi_rbuf, 0, ATA_SCSI_RBUF_SIZE); + rc = actor(args, ata_scsi_rbuf); + if (rc == 0) + sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), + ata_scsi_rbuf, ATA_SCSI_RBUF_SIZE); + + spin_unlock_irqrestore(&ata_scsi_rbuf_lock, flags); if (rc == 0) cmd->result = SAM_STAT_GOOD; From patchwork Tue Aug 10 05:49:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A78C432BE for ; Tue, 10 Aug 2021 05:49:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 994EB61052 for ; Tue, 10 Aug 2021 05:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237699AbhHJFuQ (ORCPT ); Tue, 10 Aug 2021 01:50:16 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9548 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237684AbhHJFuL (ORCPT ); Tue, 10 Aug 2021 01:50:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574589; x=1660110589; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OJ59U610saF7sinR8ywqJVyZtYWG4GXw2CO3nDPQcQA=; b=Dud1aaDnmHmknXoIWXw8aYDJ14FSrizi6A++Vns+u0efY88+kVM2ihZI Nf57H28ZSHp7qcLXiBbxQFOe2QqiK7kHMqtvEaNGSG2eSVpbtxzjGlFbF U981dAjW8mqlQKlghrHXbKL4UNtuZf/+Ur5X6EByX02RSyx+nrs6asOQY wTxjjxEAzCJgfbnU7vZhdeiTd5W+bHzGXm1XmMhR2B3rAqLRpAQWG3Igy LKAeUyHbHtdiBt0DTnEVyT4LjDLYlpvh8AolqtdJ9wBIUbjEDxjyIU1LM Y31sepUGJizQ0ifgWdSVnOfkNZh9AUYnoTfav1bqQQKQXODZV6c09l/J/ w==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340189" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:49 +0800 IronPort-SDR: YGt6sIJzpR9aNSoChHDqThxGiYQyvsccvECFumg3CLk4Z5EIddtB9qiEPFKs1Q2gJN/4EhQPqd cC7Yan7aDtuhnoM27FNoA/GzYcGNjEycjBfSnwNwOD5ZudxRNg9nTWA2z4pXdIhIIfOZGmg5UP fl9/lKWhHDs0CdGX86qRSKeWlx5FyUIxWCewhxvb3eUVAnsGMXUL+kKzMhEmU3MBS65/fyrSrN GyNKkEpZkmeHFpryiqD+Q0uAxUQGJ9ADuIwYq+nRUWUEIRKN14LYI0XvNnb45xrYayWrhQSx1b Sk9QlpAph0fquEmvfPNYeb2Q Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:11 -0700 IronPort-SDR: ZcxXFJssi5+IZfsRiXSNI36Zilm4XWArcevRpFzdPInTjmVaes9HvDc3VSVwh0KC7MKblejZz5 iWkhhCSH+cDOGAdzRqzcRX2G+KzytCPKRmTd/nqGRUQY2lx0coxGHw9VISAStxreuoFfeVJOC7 92RupLIrJ63Xg73HJXPsK+nFtlpLw7vlio0TM8FWqIC7SzoppZACF1M8lUv3i8kL80FQjwO2gU jv+NqvdJMAGKhFPd9OrE71Udlo2knuVjIt/iq32G5KkdtnNUOARnqf1yYMG3bBxOL1bbJ/EAKC M5g= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:48 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 4/9] libata: cleanup device sleep capability detection Date: Tue, 10 Aug 2021 14:49:34 +0900 Message-Id: <20210810054939.30760-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move the code to retrieve the device sleep capability and timings out of ata_dev_configure() into the helper function ata_dev_config_devslp(). While at it, mark the device as supporting the device sleep capability only if the sata settings page was retrieved successfully to ensure that the timing information is correctly initialized. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 55 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index d3f7830bda2e..499ec1380676 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2363,6 +2363,37 @@ static void ata_dev_config_trusted(struct ata_device *dev) dev->flags |= ATA_DFLAG_TRUSTED; } +static void ata_dev_config_devslp(struct ata_device *dev) +{ + u8 *sata_setting = dev->link->ap->sector_buf; + unsigned int err_mask; + int i, j; + + /* + * Check device sleep capability. Get DevSlp timing variables + * from SATA Settings page of Identify Device Data Log. + */ + if (!ata_id_has_devslp(dev->id)) + return; + + err_mask = ata_read_log_page(dev, + ATA_LOG_IDENTIFY_DEVICE, + ATA_LOG_SATA_SETTINGS, + sata_setting, 1); + if (err_mask) { + ata_dev_dbg(dev, + "failed to get SATA Settings Log, Emask 0x%x\n", + err_mask); + return; + } + + dev->flags |= ATA_DFLAG_DEVSLP; + for (i = 0; i < ATA_LOG_DEVSLP_SIZE; i++) { + j = ATA_LOG_DEVSLP_OFFSET + i; + dev->devslp_timing[i] = sata_setting[j]; + } +} + /** * ata_dev_configure - Configure the specified ATA/ATAPI device * @dev: Target device to configure @@ -2565,29 +2596,7 @@ int ata_dev_configure(struct ata_device *dev) } } - /* Check and mark DevSlp capability. Get DevSlp timing variables - * from SATA Settings page of Identify Device Data Log. - */ - if (ata_id_has_devslp(dev->id)) { - u8 *sata_setting = ap->sector_buf; - int i, j; - - dev->flags |= ATA_DFLAG_DEVSLP; - err_mask = ata_read_log_page(dev, - ATA_LOG_IDENTIFY_DEVICE, - ATA_LOG_SATA_SETTINGS, - sata_setting, - 1); - if (err_mask) - ata_dev_dbg(dev, - "failed to get Identify Device Data, Emask 0x%x\n", - err_mask); - else - for (i = 0; i < ATA_LOG_DEVSLP_SIZE; i++) { - j = ATA_LOG_DEVSLP_OFFSET + i; - dev->devslp_timing[i] = sata_setting[j]; - } - } + ata_dev_config_devslp(dev); ata_dev_config_sense_reporting(dev); ata_dev_config_zac(dev); ata_dev_config_trusted(dev); From patchwork Tue Aug 10 05:49:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3167C4320E for ; Tue, 10 Aug 2021 05:49:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D13EB61058 for ; Tue, 10 Aug 2021 05:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbhHJFuR (ORCPT ); Tue, 10 Aug 2021 01:50:17 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9551 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237686AbhHJFuM (ORCPT ); Tue, 10 Aug 2021 01:50:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574591; x=1660110591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UnaVB6KDNNEpWf+5iF0GJ2TeYxp+J3L7FRn55Pjn1Ak=; b=VzCxKQA0GqoxTIbeFrBHDgdbsBql5zST61pKuDXistYfYNT2h/StCNt9 fbNmU73zJK/Mh+jaNl/LzkYE3ehb5bn/tQ7ZFnQGul5nbaiLQKPYWfy3M G0T0BGwcyEjmf7pAe2dWteV/cGns4xVTzNXtLjr6l4wAuLpfapH64+WUF vOiIne/mr4/0y3seC1agnDXcGaAnOouYqFN0NGnikM0jqtGo1fII5nz8v N45WjbDhiWbJR2baRvX821HKDLT6MwnHw7jxrf2tQL/H98qDxbYZBb4TQ hU8+4yS/X3G4nI9mhOLo/bEfMOLcyW/GBpKk57KbQOaYp4uy2xJYqJ7jy A==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340191" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:50 +0800 IronPort-SDR: 7gfGImA60NAujunwKAsrN5YocX6cSCTlus+hXt9wb6Kh96ClayNwlMtuwAHJKiPvNpxW/lka6f IHG68IQBQ9/X1d8+oT1wN8jqmDwc7uFKvVG7fxgKoDZgyrTdDFj5hiYUF9ZCj19zQCpiONliaS qaGSsDiyl68zKujSodwRrifTu3HrF87hZK4Eu+XtYxgv6auIpAYtVmyS4BTRP8Lc1Si9fNNG7i KoAkKG6wA5ZhkiXutkuuoh/b9NUwg0fzulYUMX7++OHpKsbpRldWqoLVlq/HcYraD063h5S6Y7 dAMBoIGBWbfe8tyfIQ9Z+uwd Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:13 -0700 IronPort-SDR: RSQ5kvYf1blmWidA4bmn9q2FjrZU+y2wk80r5LEkIiATXG1xgMqUWwu3PsRxQjwk8Sm80yPaR3 h4/6jJIwzCjpl3Y1gmnTfU3mxIHx6mh5gRZeQb0neZil1/w22txFOWTytgwKhuCC+P2qfP1x9/ XQ2blQJ9Y7BH4SQ6zbPJxNR8VxITj+bGd4+UV2w1x2K2810q+4B9UqRpDrdix+icZjC6H98PGU XHsQyHLm8dRx3RtB1TrFsXXRGtdoNQTNetROIu/3CopgV1w6CNiOzNRXEXghPudx1aC/k2rbCZ g8E= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:50 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 5/9] libata: cleanup ata_dev_configure() Date: Tue, 10 Aug 2021 14:49:35 +0900 Message-Id: <20210810054939.30760-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the helper functions ata_dev_config_lba() and ata_dev_config_chs() to configure the addressing capabilities of a device. To control message printing in these new helpers, as well as in ata_dev_configure() and in ata_hpa_resize(), add the helper function ata_dev_print_info() to avoid open coding for the eh context ATA_EHI_PRINTINFO flag in multiple functions. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 131 ++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 56 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 499ec1380676..660b450bc498 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -159,6 +159,12 @@ MODULE_DESCRIPTION("Library module for ATA devices"); MODULE_LICENSE("GPL"); MODULE_VERSION(DRV_VERSION); +static inline bool ata_dev_print_info(struct ata_device *dev) +{ + struct ata_eh_context *ehc = &dev->link->eh_context; + + return ehc->i.flags & ATA_EHI_PRINTINFO; +} static bool ata_sstatus_online(u32 sstatus) { @@ -1266,8 +1272,7 @@ static int ata_set_max_sectors(struct ata_device *dev, u64 new_sectors) */ static int ata_hpa_resize(struct ata_device *dev) { - struct ata_eh_context *ehc = &dev->link->eh_context; - int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; + bool print_info = ata_dev_print_info(dev); bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; u64 sectors = ata_id_n_sectors(dev->id); u64 native_sectors; @@ -2363,6 +2368,65 @@ static void ata_dev_config_trusted(struct ata_device *dev) dev->flags |= ATA_DFLAG_TRUSTED; } +static int ata_dev_config_lba(struct ata_device *dev) +{ + struct ata_port *ap = dev->link->ap; + const u16 *id = dev->id; + const char *lba_desc; + char ncq_desc[24]; + int ret; + + dev->flags |= ATA_DFLAG_LBA; + + if (ata_id_has_lba48(id)) { + lba_desc = "LBA48"; + dev->flags |= ATA_DFLAG_LBA48; + if (dev->n_sectors >= (1UL << 28) && + ata_id_has_flush_ext(id)) + dev->flags |= ATA_DFLAG_FLUSH_EXT; + } else { + lba_desc = "LBA"; + } + + /* config NCQ */ + ret = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); + + /* print device info to dmesg */ + if (ata_msg_drv(ap) && ata_dev_print_info(dev)) + ata_dev_info(dev, + "%llu sectors, multi %u: %s %s\n", + (unsigned long long)dev->n_sectors, + dev->multi_count, lba_desc, ncq_desc); + + return ret; +} + +static void ata_dev_config_chs(struct ata_device *dev) +{ + struct ata_port *ap = dev->link->ap; + const u16 *id = dev->id; + + if (ata_id_current_chs_valid(id)) { + /* Current CHS translation is valid. */ + dev->cylinders = id[54]; + dev->heads = id[55]; + dev->sectors = id[56]; + } else { + /* Default translation */ + dev->cylinders = id[1]; + dev->heads = id[3]; + dev->sectors = id[6]; + } + + /* print device info to dmesg */ + if (ata_msg_drv(ap) && ata_dev_print_info(dev)) + ata_dev_info(dev, + "%llu sectors, multi %u, CHS %u/%u/%u\n", + (unsigned long long)dev->n_sectors, + dev->multi_count, dev->cylinders, + dev->heads, dev->sectors); +} + static void ata_dev_config_devslp(struct ata_device *dev) { u8 *sata_setting = dev->link->ap->sector_buf; @@ -2410,8 +2474,7 @@ static void ata_dev_config_devslp(struct ata_device *dev) int ata_dev_configure(struct ata_device *dev) { struct ata_port *ap = dev->link->ap; - struct ata_eh_context *ehc = &dev->link->eh_context; - int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; + bool print_info = ata_dev_print_info(dev); const u16 *id = dev->id; unsigned long xfer_mask; unsigned int err_mask; @@ -2538,62 +2601,18 @@ int ata_dev_configure(struct ata_device *dev) dev->multi_count = cnt; } - if (ata_id_has_lba(id)) { - const char *lba_desc; - char ncq_desc[24]; - - lba_desc = "LBA"; - dev->flags |= ATA_DFLAG_LBA; - if (ata_id_has_lba48(id)) { - dev->flags |= ATA_DFLAG_LBA48; - lba_desc = "LBA48"; - - if (dev->n_sectors >= (1UL << 28) && - ata_id_has_flush_ext(id)) - dev->flags |= ATA_DFLAG_FLUSH_EXT; - } + /* print device info to dmesg */ + if (ata_msg_drv(ap) && print_info) + ata_dev_info(dev, "%s: %s, %s, max %s\n", + revbuf, modelbuf, fwrevbuf, + ata_mode_string(xfer_mask)); - /* config NCQ */ - rc = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); + if (ata_id_has_lba(id)) { + rc = ata_dev_config_lba(dev); if (rc) return rc; - - /* print device info to dmesg */ - if (ata_msg_drv(ap) && print_info) { - ata_dev_info(dev, "%s: %s, %s, max %s\n", - revbuf, modelbuf, fwrevbuf, - ata_mode_string(xfer_mask)); - ata_dev_info(dev, - "%llu sectors, multi %u: %s %s\n", - (unsigned long long)dev->n_sectors, - dev->multi_count, lba_desc, ncq_desc); - } } else { - /* CHS */ - - /* Default translation */ - dev->cylinders = id[1]; - dev->heads = id[3]; - dev->sectors = id[6]; - - if (ata_id_current_chs_valid(id)) { - /* Current CHS translation is valid. */ - dev->cylinders = id[54]; - dev->heads = id[55]; - dev->sectors = id[56]; - } - - /* print device info to dmesg */ - if (ata_msg_drv(ap) && print_info) { - ata_dev_info(dev, "%s: %s, %s, max %s\n", - revbuf, modelbuf, fwrevbuf, - ata_mode_string(xfer_mask)); - ata_dev_info(dev, - "%llu sectors, multi %u, CHS %u/%u/%u\n", - (unsigned long long)dev->n_sectors, - dev->multi_count, dev->cylinders, - dev->heads, dev->sectors); - } + ata_dev_config_chs(dev); } ata_dev_config_devslp(dev); From patchwork Tue Aug 10 05:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B2FCC41537 for ; Tue, 10 Aug 2021 05:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FF9C61073 for ; Tue, 10 Aug 2021 05:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237689AbhHJFuS (ORCPT ); Tue, 10 Aug 2021 01:50:18 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9554 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237694AbhHJFuO (ORCPT ); Tue, 10 Aug 2021 01:50:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574592; x=1660110592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K6cuMyEa9XM1/DRBQ8GMISegyu7UcWsI3qu8wFRMlZw=; b=pN2j1JA9dbA+zdiLwm1KHMP+EG8yBMTbJO1tGxP9TvY5hXl/mp+NR5lm /HIQJieBh+bJiOg+YVUTC20OLdp8atNe3mNgtj7QXXcj2b3/e0R1DcbJR 2nOLh6BmEsMuhPaHijZX+LDI/+BSV68vE900nBfAnDj2r3UJb3hgp9Zso 3MV48l1mntWPJ/TL1mPN2Qt2llhreTeW3WmAJ5yDRqLS+J6xnVjLtVv+G r9AAwooA8+suG/X2I4L3zwCPTPa966Lt4qMpqkH+ehg106UO777gdpeFn jGJy0DCSfe36wJGH/0DVlDwqNT5+U6EiX6iArIvUW2blA9YxnrvHvi+R6 Q==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340194" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:52 +0800 IronPort-SDR: FzicbaLjV53rfhBD2fpPoN2En/sULdNFkb4VbtFEp1weuTkDyDdkOo3Z/PTK+POdSFoVkiQLMC 6MusLnQF4YyZtXfSDfT8c67IYH+ulXAzWVPt5PaDEU4Gfc69YcNxjAvWHb3F7o7gvPimI0tTpI JH+IRu5uKH7Kc4SQ0mQRzLyBeabxnOjjnN6zz4CUieytKJGJr/BJ5f4XfnqfkD38TWOoRmkyW0 J+SyNQmXF8Nf+00Vc2NDVhO6+pR5ruNcyKZ4440AOYsxwfdKUb3YhJ0nIhyn0KmnZiBA4UKWso xqDM4Mlx8GPUZRA6566H70a9 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:14 -0700 IronPort-SDR: /1YUokfagieRd/kWMPyvVzGgUO4L8rlp414z0c6Jy+MeqfjQCxG4phI4wa+x5hZKGaR8LjZuz+ 1MARwP9S5/5J2u1sSd4VwLG48/3M+TULcEoFl0LxczYRBf8Q+Cp1FLart8VMCTxlZIT24Et2s4 c+xR8oqHuHSGlwYo28Gnt+j6GPY17YferOsK0Iq+97ag4DFpIWEi/CJ5cfGbHmmD0BtFvtCw+a CZJes8xtWPbaA+HOhjat/bDWgCvSJKsy325GIAODjEeToCi/TWT4J1DaXOVvnEXwfkMosWVbb3 AoU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:51 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 6/9] libata: cleanup NCQ priority handling Date: Tue, 10 Aug 2021 14:49:36 +0900 Message-Id: <20210810054939.30760-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The ata device flag ATA_DFLAG_NCQ_PRIO indicates if a device supports the NCQ Priority feature while the ATA_DFLAG_NCQ_PRIO_ENABLE device flag indicates if the feature is enabled. Enabling NCQ priority use is controlled by the user through the device sysfs attribute ncq_prio_enable. As a result, the ATA_DFLAG_NCQ_PRIO flag should not be cleared when ATA_DFLAG_NCQ_PRIO_ENABLE is not set as the device still supports the feature even after the user disables it. This leads to the following cleanups: - In ata_build_rw_tf(), set a command high priority bit based on the ATA_DFLAG_NCQ_PRIO_ENABLE flag, not on the ATA_DFLAG_NCQ flag. That is, set a command high priority only if the user enabled NCQ priority use. - In ata_dev_config_ncq_prio(), ATA_DFLAG_NCQ_PRIO should not be cleared if ATA_DFLAG_NCQ_PRIO_ENABLE is not set. If the device does not support NCQ priority, both ATA_DFLAG_NCQ_PRIO and ATA_DFLAG_NCQ_PRIO_ENABLE must be cleared. With the above ata_dev_config_ncq_prio() change, ATA_DFLAG_NCQ_PRIO flag is set on device scan and revalidation. There is no need to trigger a device revalidation in ata_ncq_prio_enable_store() when the user enables the use of NCQ priority. Remove the revalidation code from that funciton to simplify it. Also change the return value from -EIO to -EINVAL when a user tries to enable NCQ priority for a device that does not support this feature. While at it, also simplify ata_ncq_prio_enable_show(). Overall, there is no functional change introduced by this patch. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 32 ++++++++++++++------------------ drivers/ata/libata-sata.c | 37 ++++++++++++------------------------- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 660b450bc498..a845a2b8d899 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -712,11 +712,9 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, if (tf->flags & ATA_TFLAG_FUA) tf->device |= 1 << 7; - if (dev->flags & ATA_DFLAG_NCQ_PRIO) { - if (class == IOPRIO_CLASS_RT) - tf->hob_nsect |= ATA_PRIO_HIGH << - ATA_SHIFT_PRIO; - } + if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE && + 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; @@ -2178,11 +2176,6 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev) struct ata_port *ap = dev->link->ap; unsigned int err_mask; - if (!(dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE)) { - dev->flags &= ~ATA_DFLAG_NCQ_PRIO; - return; - } - err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SATA_SETTINGS, @@ -2190,18 +2183,21 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev) 1); if (err_mask) { ata_dev_dbg(dev, - "failed to get Identify Device data, Emask 0x%x\n", + "failed to get SATA settings log, Emask 0x%x\n", err_mask); - return; + goto not_supported; } - if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)) { - dev->flags |= ATA_DFLAG_NCQ_PRIO; - } else { - dev->flags &= ~ATA_DFLAG_NCQ_PRIO; - ata_dev_dbg(dev, "SATA page does not support priority\n"); - } + if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) + goto not_supported; + + dev->flags |= ATA_DFLAG_NCQ_PRIO; + + return; +not_supported: + dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; + dev->flags &= ~ATA_DFLAG_NCQ_PRIO; } static int ata_dev_config_ncq(struct ata_device *dev, diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 8adeab76dd38..dc397ebda089 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -839,23 +839,17 @@ static ssize_t ata_ncq_prio_enable_show(struct device *device, char *buf) { struct scsi_device *sdev = to_scsi_device(device); - struct ata_port *ap; + struct ata_port *ap = ata_shost_to_port(sdev->host); struct ata_device *dev; bool ncq_prio_enable; int rc = 0; - ap = ata_shost_to_port(sdev->host); - spin_lock_irq(ap->lock); dev = ata_scsi_find_dev(ap, sdev); - if (!dev) { + if (!dev) rc = -ENODEV; - goto unlock; - } - - ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE; - -unlock: + else + ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE; spin_unlock_irq(ap->lock); return rc ? rc : snprintf(buf, 20, "%u\n", ncq_prio_enable); @@ -869,7 +863,7 @@ static ssize_t ata_ncq_prio_enable_store(struct device *device, struct ata_port *ap; struct ata_device *dev; long int input; - int rc; + int rc = 0; rc = kstrtol(buf, 10, &input); if (rc) @@ -883,27 +877,20 @@ static ssize_t ata_ncq_prio_enable_store(struct device *device, return -ENODEV; spin_lock_irq(ap->lock); + + if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { + rc = -EINVAL; + goto unlock; + } + if (input) dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE; else dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; - dev->link->eh_info.action |= ATA_EH_REVALIDATE; - dev->link->eh_info.flags |= ATA_EHI_QUIET; - ata_port_schedule_eh(ap); +unlock: spin_unlock_irq(ap->lock); - ata_port_wait_eh(ap); - - if (input) { - spin_lock_irq(ap->lock); - if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { - dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; - rc = -EIO; - } - spin_unlock_irq(ap->lock); - } - return rc ? rc : len; } From patchwork Tue Aug 10 05:49:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93B6FC4320A for ; Tue, 10 Aug 2021 05:50:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7845C61058 for ; Tue, 10 Aug 2021 05:50:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237701AbhHJFuV (ORCPT ); Tue, 10 Aug 2021 01:50:21 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9548 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237696AbhHJFuQ (ORCPT ); Tue, 10 Aug 2021 01:50:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574595; x=1660110595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jcGiBKGqL/HTpWqdCz+a8CS+BImWhuMqxWT6s2+gBR8=; b=Pxgz5q3ClJCAtUDOTNJujUWkF7V8dIX0cVBiXgcFgixZ1ZLy2Uzk36bz Y42M0JRwyPH0I9zZN0ltOagEvBrxbd2l/VYgtlqEckshxsNJ8YjKxn5SY MDmyQlHztEdL/2hPqpkYy8P0xrCv4hGQLuEPHLVnijgxDE8JrTVnCRQZe 4OzBa+Xnn8dvmwGhhRvaCCBe59hUBGTQGkPSHuZbg0WyKQXA7brYTG93A UNu/URc+bkxcx5XgX3/Q8g0zwzs2YWUVNnNIeTLIhWHODQ6T19RG7S7kT MGcoUSy8Tuwf7K7WoUsXmINdMRz4wfkszfssXNHp8Hb0R5l4zI7lpN9ps A==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340197" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:53 +0800 IronPort-SDR: UFtwUHUZA3+2gRK67RYKYGEt2ELnr2zPBOelTJCG5UTy2d4JrfQ3P11AiQPJA0xqoWBbaLzGpE ak3QJriPlnKDGipvccwUn/s7OgUlQe0MDzpq0lalvHvykKQL8bVkX/C3MAMXcC6ihb1AAjABWP b7cHF8Z/EBTMfgGSqgArxSHjGI5b+qSgVuhd0Uv7FfUrUNnLkGTwbCn+VcRqfPaKhom+7x8cgZ OU2goVF80wsB5rc+8aU88VZjSar3z3DYQcD6NXS8lTFm1BwcG4XWlPTUkNt0OIEDF+vMaNJOtH 6yy3kU2jmgEtORKu1ZwPfpMe Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:16 -0700 IronPort-SDR: ayusnq6glrtnSYQAQPqC3XfRwzD6z9xbssj5tUiy4EGsAjk0U5Kq30Y1sAXc8oQTBDXUdSqZ5z aH7ScC27YvCLd0xurCZFVGCieKSbg6qjz8yap111a5afIIQNlgRdCx4lFRs/SyuOv+n4cwVKi9 HjGmqG3iz0a9vYuoPxQOSWgfuaJsFVf2Q3zklvOMTeqwXeHveCWE+nwI8rxWp41nG2C+RbJPz3 exM38edsoa+1DzllHPUMwG75PQSzwtqHaY8tvN0gSd2v1t8LIb2J+SpQhdeg2B46DpH5U3kMGA JwI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:53 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 7/9] libata: fix ata_read_log_page() warning Date: Tue, 10 Aug 2021 14:49:37 +0900 Message-Id: <20210810054939.30760-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Support for the READ LOG PAGE DMA EXT command is indicated by words 119 and 120 of a device identify data. This is tested in ata_read_log_page() with ata_id_has_read_log_dma_ext() and the READ LOG PAGE DMA command used if the device reports supports for it. However, some devices lie about this support and using the DMA version of the command fails, generating the warning message "READ LOG DMA EXT failed, trying PIO". Since READ LOG PAGE DMA EXT is an optional command, this warning is not at all important but may be scary for the user. Change ata_read_log_page() to suppres this warning and to print an error message if both DMA and PIO attempts failed. With this change, there is no need to print again an error message when ata_read_log_page() returns an error. So simplify the users of this function. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 47 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index a845a2b8d899..bad577dbbc0d 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2026,13 +2026,15 @@ unsigned int ata_read_log_page(struct ata_device *dev, u8 log, err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, buf, sectors * ATA_SECT_SIZE, 0); - if (err_mask && dma) { - dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; - ata_dev_warn(dev, "READ LOG DMA EXT failed, trying PIO\n"); - goto retry; + if (err_mask) { + if (dma) { + dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; + goto retry; + } + ata_dev_err(dev, "Read log page 0x%02x failed, Emask 0x%x\n", + (unsigned int)page, err_mask); } - DPRINTK("EXIT, err_mask=%x\n", err_mask); return err_mask; } @@ -2061,12 +2063,8 @@ static bool ata_identify_page_supported(struct ata_device *dev, u8 page) */ err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf, 1); - if (err) { - ata_dev_info(dev, - "failed to get Device Identify Log Emask 0x%x\n", - err); + if (err) return false; - } for (i = 0; i < ap->sector_buf[8]; i++) { if (ap->sector_buf[9 + i] == page) @@ -2130,11 +2128,7 @@ static void ata_dev_config_ncq_send_recv(struct ata_device *dev) } err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV, 0, ap->sector_buf, 1); - if (err_mask) { - ata_dev_dbg(dev, - "failed to get NCQ Send/Recv Log Emask 0x%x\n", - err_mask); - } else { + if (!err_mask) { u8 *cmds = dev->ncq_send_recv_cmds; dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; @@ -2160,11 +2154,7 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev) } err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA, 0, ap->sector_buf, 1); - if (err_mask) { - ata_dev_dbg(dev, - "failed to get NCQ Non-Data Log Emask 0x%x\n", - err_mask); - } else { + if (!err_mask) { u8 *cmds = dev->ncq_non_data_cmds; memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE); @@ -2181,12 +2171,8 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev) ATA_LOG_SATA_SETTINGS, ap->sector_buf, 1); - if (err_mask) { - ata_dev_dbg(dev, - "failed to get SATA settings log, Emask 0x%x\n", - err_mask); + if (err_mask) goto not_supported; - } if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) goto not_supported; @@ -2347,11 +2333,8 @@ static void ata_dev_config_trusted(struct ata_device *dev) err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SECURITY, ap->sector_buf, 1); - if (err) { - ata_dev_dbg(dev, - "failed to read Security Log, Emask 0x%x\n", err); + if (err) return; - } trusted_cap = get_unaligned_le64(&ap->sector_buf[40]); if (!(trusted_cap & (1ULL << 63))) { @@ -2440,12 +2423,8 @@ static void ata_dev_config_devslp(struct ata_device *dev) ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SATA_SETTINGS, sata_setting, 1); - if (err_mask) { - ata_dev_dbg(dev, - "failed to get SATA Settings Log, Emask 0x%x\n", - err_mask); + if (err_mask) return; - } dev->flags |= ATA_DFLAG_DEVSLP; for (i = 0; i < ATA_LOG_DEVSLP_SIZE; i++) { From patchwork Tue Aug 10 05:49:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C829C43214 for ; Tue, 10 Aug 2021 05:50:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CECB61073 for ; Tue, 10 Aug 2021 05:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237696AbhHJFuW (ORCPT ); Tue, 10 Aug 2021 01:50:22 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9551 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237697AbhHJFuQ (ORCPT ); Tue, 10 Aug 2021 01:50:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574595; x=1660110595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QxLawA2FoU92rg8+3N60ckeNjg2itVghvmelVKXdIyI=; b=jrYGqtpIez/JZYQbBQYruWdPksglYVVmge7fKURAc5/Nh8aRpXaIzyZo UGnwhyZlRSJD7HjOMLoG0WGcgJfN9zxKaEM6AJ+Jqp6jdWkFfoCffNKhw SZlpcAwoaRR71SpYnkW7/s7VCvb/jEAVehU3sP7Phx5xadWpJqbAQ75y6 0Bffc1yFjUjIi1FyFcnZRNusnxST8slZSZExstBAGifIfSlxCDjn4qN2P g2B132cbDl0V09qjcLFhkYH4ioxxShkYpeMUZCVxlO+6BnviEJCekZzHl rYa9m/JpMA0/LfarMb6gIwtk3Z5K/NMdmt9YV0fflOjlEzP7L8XLfRfxA A==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340200" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:55 +0800 IronPort-SDR: tlQY5Y9UZP0GAOdnEisnh5Sm7fqv3HyMgoA8nZoK/61O35dEIrvHvmM5f8WIPE1QJx32n4UuYs aCFXA4085IqoGkaitm0eTRyX8acjn7xO7TaKl7uJlkb4QTeWQIWKlfextE7siEFxSbT+mhRXMS oQkZmYju+TKzLvjp/StHrUQmSQwaYAmffoPNYDWEUa4K+BlNhohM2X4zWHEZkVewPfs0ibxLev 7jL0UGWdl7UTDgvpv6SibmGezZc4Av6wvSV4IZXM9vq5c4al88N0lvJynInsTee45Nnet4xVAy TOXwrlhYTyLLkDox3xFkAD/G Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:17 -0700 IronPort-SDR: hqn9Um6buocNEBzLnoseqFiJIKKJfQjWRztbg7EWBKXmPV7U06BVGmhfWQORM3801Z8+dLM73Z +zryrBgbQy+VehS/ib4o6oxF5NqwSeZQ9IKwPIwLJ4aLD4oB1cKRw8DHANSQP0KFUf0Usuw/MX /CXmkmoTLje4XTIqZnq3ggVQiCVvXH20fRDWwwTOrx9wKO0oi3bQ9tmtksO81qjNMMkaqgaWQs xFM8TVLSY3iQis3O2dcIytXsS+I5+2Z2ajJ8DeBA+D6ihhy3167pZDmZN+yIrdCPiiZqkc14Ah oXY= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:54 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 8/9] libata: print feature list on device scan Date: Tue, 10 Aug 2021 14:49:38 +0900 Message-Id: <20210810054939.30760-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Print a list of features supported by a drive when it is configured in ata_dev_configure() using the new function ata_dev_print_features(). The features printed are not already advertized and are: trusted send-recev support, device attention support, device sleep support, NCQ send-recv support and NCQ priority support. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 17 +++++++++++++++++ include/linux/libata.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index bad577dbbc0d..68a55d3e977a 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2433,6 +2433,20 @@ static void ata_dev_config_devslp(struct ata_device *dev) } } +static void ata_dev_print_features(struct ata_device *dev) +{ + if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) + return; + + ata_dev_info(dev, + "Features:%s%s%s%s%s\n", + dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", + dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", + dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", + dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", + dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : ""); +} + /** * ata_dev_configure - Configure the specified ATA/ATAPI device * @dev: Target device to configure @@ -2595,6 +2609,9 @@ int ata_dev_configure(struct ata_device *dev) ata_dev_config_zac(dev); ata_dev_config_trusted(dev); dev->cdb_len = 32; + + if (ata_msg_drv(ap) && print_info) + ata_dev_print_features(dev); } /* ATAPI-specific feature tests */ diff --git a/include/linux/libata.h b/include/linux/libata.h index 3fcd24236793..b23f28cfc8e0 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -161,6 +161,10 @@ enum { ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */ ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */ + ATA_DFLAG_FEATURES_MASK = ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ + ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ + ATA_DFLAG_NCQ_PRIO, + ATA_DEV_UNKNOWN = 0, /* unknown device */ ATA_DEV_ATA = 1, /* ATA device */ ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */ From patchwork Tue Aug 10 05:49:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12428029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BC44C4320A for ; Tue, 10 Aug 2021 05:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01AB66101E for ; Tue, 10 Aug 2021 05:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237277AbhHJFwE (ORCPT ); Tue, 10 Aug 2021 01:52:04 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:9554 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237693AbhHJFuS (ORCPT ); Tue, 10 Aug 2021 01:50:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628574597; x=1660110597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PaQ6Zl6aq899pRIUCn+Us/+eg+Mn4yjWtQ689aYZ9Us=; b=JjWwnn+PD4fPNO35QrS2OW/8qUd5vZbyMhph37ziaF1EQ6lvY5dDLEyH xQUdi2b0ZtW12KNKTlkinMlh46u6acqcmgYBwMCtIIz/mz8/APnc5W5zY CQl+SUqhtkhdIsMw+jJNurUCldEVf6e3Gf4iiXkCFnkm4bJ1t2qDOkvKq J1VfWndw+kxxbFNToBGxTjnwYMu8s0NNIgJFKIlFqvDJRBt4SNPgNUzA3 DplJKZaKscjmId4sBHPHHPJTNNZhfxiJLUGVecFE6YkIbKYNL+8yMWfS0 54e7cl5b2KpQSGXMxAA86PZt8uXYO1FtiJzv1UUv2EbumfjV3rt1na+cO w==; X-IronPort-AV: E=Sophos;i="5.84,309,1620662400"; d="scan'208";a="288340204" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2021 13:49:57 +0800 IronPort-SDR: x30euQLS5YCPljHgV1rgmTp9B3v87AJ3iOnK3Sc7zlnsC+L9wNBm+pHdkWnKKIBk+UZ6MX0NgQ oKh6Z2gisDI3X0rVDtvE+ZNlxukpT5Pw7qP2ey8h9FWAaHEEScl6xPlBDNAIYpJNTjuO4MWRtS /9ywJOUftOpqqv0oE6e9HQbLolz+W4WpuDra++l7Y2fuxPkh1pR4P3QvFRVJO85hOJ8hJ02Rou NAId60EILd7Zc8FXsL+phaOj0b3jhHz9DYlG5gVRhdZtSXEf5Hh2oyYzZ10Pt3wPUvIV/fvp2R ACMKiqrbbKusr+KYwVPcmz17 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2021 22:27:19 -0700 IronPort-SDR: sb9i6YE5JTUumSZ6lN5WizaVfpdEtP+H058mvhPp2sbUqqgH09igT+xBVSmqqz+hf7ActuKzas VRXMLXx1OOcv77kifu1G2VP+jLb7IpNnQ04nY2TxluMas4CjeBMA7Qazp+JCuw5nfGxoKd6lUu exe3XFnlA7EgTW15M1SPW2osP8+nJ3+hcAIppcFubOUMWICGhQLko40rxaabw223wVyFAq2vAk diHFeJ3r1+NXjmEj590NVlRDVKwVmTD6Udu1XOUFK1jGRxhGtuUVjWlTAc+g9La+P2yxRBIFru +Jc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Aug 2021 22:49:56 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v5 9/9] libahci: Introduce ncq_prio_supported sysfs sttribute Date: Tue, 10 Aug 2021 14:49:39 +0900 Message-Id: <20210810054939.30760-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810054939.30760-1-damien.lemoal@wdc.com> References: <20210810054939.30760-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Currently, the only way a user can determine if a SATA device supports NCQ priority is to try to enable the use of this feature using the ncq_prio_enable sysfs device attribute. If enabling the feature fails, it is because the device does not support NCQ priority. Otherwise, the feature is enabled and indicates that the device supports NCQ priority. Improve this odd interface by introducing the read-only ncq_prio_supported sysfs device attribute to indicate if a SATA device supports NCQ priority. The value of this attribute reflects if the device flag ATA_DFLAG_NCQ_PRIO is set or cleared. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libahci.c | 1 + drivers/ata/libata-sata.c | 24 ++++++++++++++++++++++++ include/linux/libata.h | 1 + 3 files changed, 26 insertions(+) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index fec2e9754aed..5b3fa2cbe722 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -125,6 +125,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_supported, &dev_attr_ncq_prio_enable, NULL }; diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index dc397ebda089..5566fd4bb38f 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -834,6 +834,30 @@ DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, ata_scsi_lpm_show, ata_scsi_lpm_store); EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); +static ssize_t ata_ncq_prio_supported_show(struct device *device, + struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(device); + struct ata_port *ap = ata_shost_to_port(sdev->host); + struct ata_device *dev; + bool ncq_prio_supported; + int rc = 0; + + spin_lock_irq(ap->lock); + dev = ata_scsi_find_dev(ap, sdev); + if (!dev) + rc = -ENODEV; + else + ncq_prio_supported = dev->flags & ATA_DFLAG_NCQ_PRIO; + spin_unlock_irq(ap->lock); + + return rc ? rc : sysfs_emit(buf, "%u\n", ncq_prio_supported); +} + +DEVICE_ATTR(ncq_prio_supported, S_IRUGO, ata_ncq_prio_supported_show, NULL); +EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_supported); + static ssize_t ata_ncq_prio_enable_show(struct device *device, struct device_attribute *attr, char *buf) diff --git a/include/linux/libata.h b/include/linux/libata.h index b23f28cfc8e0..a2d1bae7900b 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -539,6 +539,7 @@ typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes) extern struct device_attribute dev_attr_unload_heads; #ifdef CONFIG_SATA_HOST extern struct device_attribute dev_attr_link_power_management_policy; +extern struct device_attribute dev_attr_ncq_prio_supported; extern struct device_attribute dev_attr_ncq_prio_enable; extern struct device_attribute dev_attr_em_message_type; extern struct device_attribute dev_attr_em_message;