From patchwork Thu Aug 12 02:43:55 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: 12432329 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 78326C43214 for ; Thu, 12 Aug 2021 02:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E63F6101E for ; Thu, 12 Aug 2021 02:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233700AbhHLCob (ORCPT ); Wed, 11 Aug 2021 22:44:31 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbhHLCoa (ORCPT ); Wed, 11 Aug 2021 22:44:30 -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=1628736245; x=1660272245; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N9HTUe3fPenLFb7TILYqOuQ90dOIPTNwU0OUTxnf8fo=; b=Ge0cg1uOTP2VCjPW6Z8DXp0NV1RkhZpYhgOqSoYHYEQvRFXyxgbf7iUj RNgRsUOewPxgmi4GoxqyHqbmA6DbwDNgTLy0hxc4jMiecGIa47ighWCHO rbWX0LQgCY3NaEclOwV8CR8E2GStDwbCwVU62YRfgfLTBbGNZWM+fAu1s nTL+K9r1wBfRPL3YyNwFuWoi9EKTnrk3rGdWMsHyQhtclmEHy9McPa3Ph TlIiUq8Bw4m5FAkQgCSg9TD9A9amWD/PkCO1EmRmpw9M1gqD7dbSG5bsG AOUCN4c1eTfAa4zwZAnrhGAyBTgLPyWK7+kkcxOFksKji7JFQhjKDoUyr Q==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999856" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:05 +0800 IronPort-SDR: Lq4VrNoeBoXhnGlSjftFi0Tmg9MK2WTGuTo/2qTeaRacYBMdtFiudl5feYd17qbsO0BPLVkEGs zk6LZE4kX4WTeV1Kgh8BM5rIQDIr+6mvQFvE6MsY2gUgJ1WXMpVffmAaXCIA0VxWN7C1lde08m p7y117LcMFkM/nyI9DfWIE4s86bncw97tzZYrx3LrPxI8zKjQFqRi51H6XKzSNnbwtTKQ8DB1b EZhghUpVFKON6HuVvQ2s9PHYY9QpBsxsvmLRedgUEHG69WFb1STi43flztguTBRLxWSfNxp05j BstFBBoClTSkLvZ7NO+Mfk/I Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:35 -0700 IronPort-SDR: 8SseMKCTyzRJjk+0sDVc/tZ+R+fllLBeOROh7bGCJqBrL3bAsum6xcG8ZjvLkGJ11nIlGrS6u1 u93kMcliPJ8Ogd5YBi9lCchTJE3G32HLLMOjZJh0wftFRq5Apbj5P0OGSlRCPZN7+Xj3kFazpX idJFZ9Pw2Z2igaPZswQOy1pijS5syETEs4BozmcrJn0UPjKXNhGKSYbndZyE0R/L7VS/ygsB4Z Q8k+8hqDUiEe5LwV1s6TLmqL/KF9C+TzpM+M6GqdBe09Q39kxPl9OkWTiIjTAlrX0N+aPvssU9 L1c= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:05 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 1/9] libata: fix ata_host_alloc_pinfo() Date: Thu, 12 Aug 2021 11:43:55 +0900 Message-Id: <20210812024403.765819-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 --- 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 Thu Aug 12 02:43:56 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: 12432331 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 C6CE5C4338F for ; Thu, 12 Aug 2021 02:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC52B6105A for ; Thu, 12 Aug 2021 02:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233719AbhHLCoc (ORCPT ); Wed, 11 Aug 2021 22:44:32 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60783 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233659AbhHLCob (ORCPT ); Wed, 11 Aug 2021 22:44:31 -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=1628736246; x=1660272246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EIH026mlpK847URWOEkIJeSWTxgkrb13VQ8oOv5tb/A=; b=Vj11t3r3g2tHt9sgyIQ5pf8963uNdyoOxF5DvTun8Qp0K0ASUPtD8Gi9 6XcVpIip94NoqB5qDEMuq0nS1U7HhifhL1NweD8Q/8NmA6Y1rKrX1tgUW Ab/E39won4aKbddw8lLyZKJXE6e4FoxwSIQ6asSvWeuWzDCGsYeCX9nHF PygU6wvE0RMHB/f+wqmhU7jfQAM6kSyZCmValebf7valRiQp2tK7b8TX2 mpdivSxvjdZLF6cte70mTn5SJbgZTbcLb4QKb4TcycdBYdFKN4T85Q1dL npWFtdeubem/NaWQd/4X+g7Pu9ul9P94mZpJiK0gavlbG/5hAHggU9Eub A==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999859" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:06 +0800 IronPort-SDR: WhqVUhbcYnFxY+5i9pJf0DrlqT1nPcdtjMG412rmcog+YtPzqFjA4QMQXmA+28RsYIldSMQCs+ loNqvj/t5mCKG5io1sTgxmvG0w3PHvoOcbQqUtwhW7Vs4LYOa+Ew1SeS17ceKeQN31mlWLa7Cf +TTnDH7IpPfSGht1ap6koxYiT9jpLgw7N9CxJH37722KlmUihM2NHpMykjDaog+LlJkZsGVbqv VuBdzOMfF9pXnnytiz87qOqDKxqmDl4IyzPs0AbLhruhOU5ByNkivEHe5ZA15EUyhQmRCmrXOA GLGYjSyERAPTkgQWoMSpjbzn Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:36 -0700 IronPort-SDR: 4YARjhaKZdjltWHRHtZQGGMjuzxr96RHSMRCJNmLKXllbhnlL8uJUSiRD2BLmqRbCsfN5JslSz IvCZUzGbkHYqzIgR5s/FskUnowxHqxebOAwIFXwDv+08OyQipBqfZnl0Cr2hITD5fwMlp0kwUp 0jbir9srf0wuf2MnYtg0oOdRtGedDoE1bBE+yVrcVO3IAttaWbyJFqBJLYnun7M7JNxvk/7smL VOgu0BWTtrR7kyY+q2wVqD0sJ6vzTfM7USpe1PRZnA7llOMWRb21tcg2Ve+OIj4hlRM1xZIswa e5o= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:06 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 2/9] libata: fix ata_host_start() Date: Thu, 12 Aug 2021 11:43:56 +0900 Message-Id: <20210812024403.765819-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:43:57 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: 12432333 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 AD994C4320A for ; Thu, 12 Aug 2021 02:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 930E46109E for ; Thu, 12 Aug 2021 02:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233724AbhHLCoc (ORCPT ); Wed, 11 Aug 2021 22:44:32 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60785 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbhHLCoc (ORCPT ); Wed, 11 Aug 2021 22:44:32 -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=1628736247; x=1660272247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+WWKZF/7COHNQFSxWKyzuz9m7BPKJUtEUV2VtAma0Ug=; b=nkHprQEKXRWra6e/8JBVBt7qsSfGTRINMQ8SLmEoMs333xvXIHKJ0TS7 YQSNd4eminX4+/XxfbIdLg7J2BXdruuPJc1xfKs5sb6IaLbh4evlYB9ol 9oly0wQLQjsQEiS9LPqGLAnhnCroCgLYEJlB8ss0ZecFkFW6d3rsBDwmS OVVAgmyBlp3iMCYvyFpkn9BYGBDBLl8+roV7MnUy2gmcXv5694T+KfKOz tR1BICk7Shk+PiMqOzMMWGMEUmdMqmvK1+8evnfJUvvqo1hkvS6j1CqYD sEH3LObIRwD1DEpEf9PMBmbcWif5qJV4+Wz307MfRf341XkLaBvlxwa2z w==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999868" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:07 +0800 IronPort-SDR: NMyhAqPicNVrUGPtsjoz/1aL0dKkouwiC8gSewI59LpxYeZTAKfc2enrKgVJQRNdA6It0ATt8C 2SENnc2r9AbR7VLYjTDiNUwDSpMHPlj7GFcthsnohDebU65WPTXiXcW0mPCjPgFVEw8dbVO5SP q8VDeEFSvR2kQn7lbkjDrjcCj1O3vylQoTXOzpiPVjRCVyxi27P0EttaaXBVIsqcl8xCWZHQdb YrxJOjvcwYnKe3j7rn6x9Cnjo+ubUkNpI1FgMZfHB72QtjZ/tjRngcVv6eeRdMqb0yTvkjV8DZ YUV9BNSfjL1r6uLBTW5mpuSh Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:37 -0700 IronPort-SDR: qqDC4viKgi3Tm0iZwIeKhfPBrXnJP0Vrn+3ZUsFTLYx7emr7irsC/8oOsnzH1HPGkBV+6c5gvs 29Js17VqCp9bS33yi/Qod4VUOykDrtcLMQ6oADv9Chhc/rBDJvB8g4W8evgsdPl45wijjPiHRV jB2FhYLytBooRJuImvnHPT4ypzCvfJuSaV5DGExc4sz94eEzvluE5Vnt8ThQs2+KgnUmtED3n0 b8HOQeGj+0z1eGE5afW96HZwDDiQyM+p0g3BvrSds5SQQki9viMlGoW5CjcojYvx2hLSbDnvev 820= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:07 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 3/9] libata: simplify ata_scsi_rbuf_fill() Date: Thu, 12 Aug 2021 11:43:57 +0900 Message-Id: <20210812024403.765819-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:43:58 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: 12432335 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 A4069C19F33 for ; Thu, 12 Aug 2021 02:44:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FB2A610A3 for ; Thu, 12 Aug 2021 02:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233731AbhHLCoe (ORCPT ); Wed, 11 Aug 2021 22:44:34 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60785 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbhHLCod (ORCPT ); Wed, 11 Aug 2021 22:44:33 -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=1628736248; x=1660272248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OJ59U610saF7sinR8ywqJVyZtYWG4GXw2CO3nDPQcQA=; b=c3ZqIF1rlLyY+cQLUGkGnRA9v1OrgHZY3oc79h/Azx5k7vINLYkEj2Wv dHBBMf/YFnvS9XjyrH5xO208VecIu5+zCC4EZcstY0b+ijFZeqNEPIsni DV1BMguUOOJVd/mEm2Zrvb5AQT8jHkRZb97CQ1nHGl6bMdQpTlbTlxqrQ L0M3nILCSx33kedSxvFk93oockyL+xn4zNiYwWOrF1Pk/bui+JtiaO/rk cwoLwpZOTHxzCIBLqxDDN4whp7jDuP9COvN4NXUVZwv1bb0t0oVtY8ai3 SYnz+2N4bjwA1uJyyJa0xWJK1lFaQ5GVocRi3GxtoD7sR2gIq8jPBOoxx Q==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999876" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:07 +0800 IronPort-SDR: /f8k3drYvPLgy0ASW7fRUkPsLKkMNRPHK/pXluNywYbEXiZ3SOvp7RH9fF2TsK5IKo1lgJbfxR kKdZXU8VCLM7T4+0Q6vuIVNK5zpStHie4ASnxoHRwVtg8+w7zhLv+fIJlp0xxmbvVs6/38EhUo i8wHtaYn+4a+RuSUvSnAPLoyO2QIHBNa+BnV5TDkUXqtz9JGH/QJuTNQaZcNSrWgAgP6TRwKqT Xv+NuilI54PcoLZ+nRoNHIaB7xMOnDFgXCM700Kyr7euigNwrGZxjDNcQprpye8FMZN2IoB8hw 5+0RWxy/rBUizen5olgqAHfb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:38 -0700 IronPort-SDR: k5d4/GWMFPbhH2pXf4oR6NfSoTwbgo5EZ3Wtm/Os0oJjj7ZD7OS7806eqoBAiO4hs2HO7NV7J8 hQ0cXI/rdiNgoyERdL4EsO3aKWag5gVnFWq+Iz+0Tke6UbUrHRynadsaZqVteOt6EBgEAfYmhG 3QjvTH9Xd8Krbya14UP+ZkfmaEfoPbu2SJA3Ndaw8aoxPjKP9zdjGZUPSP86nqB1c5kXMht4lx iubtpun26PXC+kKdsWtl0RJRvHI+V/iYuZ6HAxOelwqn7XSWj6JZy6LoCMOfdGgvXolOWZWZ4I eGs= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:08 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 4/9] libata: cleanup device sleep capability detection Date: Thu, 12 Aug 2021 11:43:58 +0900 Message-Id: <20210812024403.765819-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:43:59 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: 12432337 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 1B1A6C432BE for ; Thu, 12 Aug 2021 02:44:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC2FF61077 for ; Thu, 12 Aug 2021 02:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbhHLCoe (ORCPT ); Wed, 11 Aug 2021 22:44:34 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60785 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233738AbhHLCoe (ORCPT ); Wed, 11 Aug 2021 22:44:34 -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=1628736249; x=1660272249; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UnaVB6KDNNEpWf+5iF0GJ2TeYxp+J3L7FRn55Pjn1Ak=; b=DQ3kstj0rvIuW+0Ww+SC4uaLV7grE2ELz+Uw0buq9qTSc6RTa38FP83k IcBv78azSjtb8/GpWDvS+16aOQaJyrFAfb8rFrma0V2tCJUTsV/ZX7Y4h 4ekfTulCw5/FFT8tkv0gRmhyf05PPnIn3PBpGt6oYGZVUaZP66DIMfKQ6 qXeNlUO3V8vFtLEROWVwRmAqZMgaJV/pRlC9+8oEd2cGk9aU/1xDMVRA4 3o4jlirKqBOcV6xJwb0KcYvAFkgKXjRFncPnykzf9XqymIpD3Hgdd0SpD +yYgFThpfuLFcAv2ekMfcxmSw0JQdEJsGFyM0TcAcsQLgwdrLu0Je/TZe g==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999884" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:08 +0800 IronPort-SDR: aQdHTsuo0Q5McAgUZMasXyDHIlbisaFsTHr7l0+8gf1TCWnGHPmPUxrUrBNaiGOpK95UCy/Go2 DWnd/Y5mlq8p0TXObsDpc9dCSPHAsp6bh4QPVhkG8Kvu8l2gMa2XZp9wjlv+ucZu+vNapoAy+5 f9GCQhowJxelFATMIPPecJ8ZU2698rjYRiH9TBhdXNuCr+vx1DvnOpbqe+MwOWNcxPoYqegiGH /dIcolCgh5eFyIhTFSZkx2d9oicwamokMB/VY3k1H3EQG5xuOPt4Mm9lr8T1f9jHMmr66zlWCa dCn0tC1OzjcUiWghXzcvwo/w Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:39 -0700 IronPort-SDR: WSlbdD97QFoUjM7kXc7dItdFBmklD7MoyoHuEA8vdmLLN1Jx7GPoEVvApiO7fnqPqtKrJQBQqX l2dPd85NC5nrqAbPLPm7W+NZsJBafh5K8Psfu/TSMm7IJ6B/fJekMiBM8l+T1lVBeAo1PmGVKh kNf6rdmsDurTEWl5kdFVKNKMlQ2aQGb6f/djEggXdGUaqJuKAxJW1U5QcZBg0u5diFl1IezWPY +QLzdxuwSgGQEyMCTTVd7E9VdrDdtaEWt/ZnaUpNk431eH6RmuyxA/VGV/a7KOaXNR5XJCOU2W HeI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:09 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 5/9] libata: cleanup ata_dev_configure() Date: Thu, 12 Aug 2021 11:43:59 +0900 Message-Id: <20210812024403.765819-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:44:00 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: 12432339 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 AD485C4320A for ; Thu, 12 Aug 2021 02:44:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EC4A6101E for ; Thu, 12 Aug 2021 02:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233777AbhHLCoi (ORCPT ); Wed, 11 Aug 2021 22:44:38 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60785 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233741AbhHLCof (ORCPT ); Wed, 11 Aug 2021 22:44:35 -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=1628736250; x=1660272250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K6cuMyEa9XM1/DRBQ8GMISegyu7UcWsI3qu8wFRMlZw=; b=jMzXKT0V2eK7SIXBCJ3CmVpugY856AgsvdaB4BFZgXhQS+KqqDlEwaS2 mpZOyneMAFPp1SgQBNQ/uZuSb41h//Ki1LXEjc4ewXERjOZQ9j5z5Rbdg clKHMlUKHsVCAtQk5i6y+VB4r+RMnI+TOd4Yb9CDWA2EeBfzzWrS/uBZ7 kieizeJHcR9CWyRv1I/21YCkiYsnISHXwpPWSVmv1/rMHFvdofdqVxk9z A8UZZePFkupmnlr22qDj8ulx0nyvnQ2MZbixebfxDaWkKBr+0ZuPC6gKd sQtvuLOrUMVDwyrDrAiGC/wkJrT/J5lwnGWlqgazXXbUfDfGhWJAM+K1G A==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999891" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:10 +0800 IronPort-SDR: gx0vFtEuBfyAcyw5esoIFooHZ7+CbjgC1CL9HxoE0VY/KTE+fEbryPMunif09UYOHCJvTvPcsG U+kIv7yvwoUJcliLTY4Rrs7EcED7L5iRjK79trZhBhm/4Xy3oRaEMxntmw98ajrplwv7lOPNZk UijedYZiwx3hV4DU4i6DO/XD3t3zY4a4QcIAGaKXBEu3PTNk2288YFw2pOYhgD5kPmmiRLtGGl N9dndg3VvPysm+QosC9hrNOwPMye+BjWdJQ+4xWfhTlL/HNyWvtCT8HXqs6ABcLDNK2Hh7s7Wk J/vAAbCX0OP50ib8k8k70R2R Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:40 -0700 IronPort-SDR: ACZsSOJYugDGjf9AhzrAkJ+FpvPVH/GmmEl6QsuaHcrs79dX40EntIshP6W6dnJURitbcRmeEx Dw3gwGVIzsZ903wYrz1rhXZowAkmrR65T/Oot0Vbv70Dz631nGfOn6Bl2TXtEUw37/e34C/x0S Pe/uYpKRIy3K4YzWCWB14KSDpJYUUhmr3NkqhfU/ItD6rZFNzRf55rsPSu5hd8x+maiFtOb8pc DYCkRGsutRN/E68iZEKW7GxQvf8/FwpcoFcm3NBWm/sUCn/AauYlVpYWYTdMmC2yHivVmQtlX5 Ou4= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:10 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 6/9] libata: cleanup NCQ priority handling Date: Thu, 12 Aug 2021 11:44:00 +0900 Message-Id: <20210812024403.765819-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:44:01 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: 12432341 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 963B2C43214 for ; Thu, 12 Aug 2021 02:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C98B6105A for ; Thu, 12 Aug 2021 02:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233747AbhHLCoi (ORCPT ); Wed, 11 Aug 2021 22:44:38 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60797 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233758AbhHLCog (ORCPT ); Wed, 11 Aug 2021 22:44:36 -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=1628736251; x=1660272251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jcGiBKGqL/HTpWqdCz+a8CS+BImWhuMqxWT6s2+gBR8=; b=NZV9hIcxgIYa6nD8gIADujBe5AKcSHt/vUd2yY97Wdb8lExVamG+JUt0 GBcP1a/dJom+JATwQlac1ajN8EI/A9OD2I6eP9E2FOSYpJqTt8fy6TI+c /qbqoikUDIrstvdH0bAATLck7CuUGA8XAfPuszaR1G2MRADskLoawk/OU HhMKgihh5sLHPUPM/VV7QUIpfiXOJc0fcQ6qbln2DyQsm2t7Z+5LiCYKe M+y5B9mTeYluQuy5hCILi5FhkxA2+k9gfxHW4cj2ApBKZxx8KC2uzrx+o qxYlR9ZZMsI5Fdq0jtBR31tqqHz/vg5ne5H8eGi1JMss/X2GzwYsjALdh w==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999898" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:11 +0800 IronPort-SDR: TAtPXhLURTxFM3L6KixGPGoguZ+ewGD61Bzs4ZKu0/k8abvJRnfMVOlvvpkY2SuNxmp2UTr84y BL1aS0qeulzXomy+mU1pEkLjPE1AUtW+b3CNbUeL4CMqPxmR+MkrFW1um/gguuBbbNFpM+fgcU D366k1qnBt/yMXtocBXR3Fw+1VMLxvxP2zZGk2pOq3H8Ug+sE7UbRIDprsuTCHr4bgkePtrYjt SJdJroIP43wVUXOdt5gfx+od368Idk0cK1hPvkGjJmiyqdeSVyf2HSajvm6k7GHBWGrlCj7fYg 1s16pYuRe4Cbx4bqMeYh+/Jb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:41 -0700 IronPort-SDR: 9X2GZz6IaDEPTh/rF4NrK68seHSaSWY+ioZUKYTGxPjU04czXybSakmPEDhHDpCYut8EP6OBCD eASKHEOo1XEmjq6A8HziKWhuqa71JXfzHdX9NkXtBaHIogxgugOX+WhUtvMAHVxEQGMs8ftGg0 qk1muaKPfDYEBHWgWPycx6R9zgae1ll+KNS84zoDeLsxPeU+Fn1lsZ3wmiOwEvsnH8mtK0ZPgT IDthMs35S4AE4OH8eUSvTGDvzW2FUI/vPWx0miASB8tp7b5BtjoYSeFlnTQ5tqrZfIkItRw1Ld TYI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:11 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 7/9] libata: fix ata_read_log_page() warning Date: Thu, 12 Aug 2021 11:44:01 +0900 Message-Id: <20210812024403.765819-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:44:02 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: 12432343 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 1E674C4338F for ; Thu, 12 Aug 2021 02:44:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 006EC6101E for ; Thu, 12 Aug 2021 02:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233758AbhHLCoj (ORCPT ); Wed, 11 Aug 2021 22:44:39 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60785 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233733AbhHLCoh (ORCPT ); Wed, 11 Aug 2021 22:44:37 -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=1628736253; x=1660272253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QxLawA2FoU92rg8+3N60ckeNjg2itVghvmelVKXdIyI=; b=Z6ksMTWJzlWKJZg0F7H0nU/g17r/1pdnSWS4oxj1qR5Cg9bAehcvZwgj keSljUpqON93eEtt2iFrQssk09aR7twoLQ0VgH72k1g+yhAMci5yVzt6m usOcXhj0PWfjR0VE2sn0xmQLpNdQ9fCPDr3gPLZS6OZ3PMLANMtGPuDoY qiYFE/IPq3780hiLWJ6nf9vOShaz9M6InUDtjUkfJd9nmtIcjOUYHrbpw KehDdBkDNYO0ZF+cTg7R+eTTpgMYzbUrRaUolJll2FMUvBNgmSB0CBtvt dR0V1Xq92pPT/+vsmujhFGp+K4aWDTYrPYjhO826oIBqAImujxYudVVXv Q==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999902" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:12 +0800 IronPort-SDR: Nl994DRrmXxrQjAQesDuScbw7sYyAx4Jf29b4uEU2DWSHiq48oqGKvyH8NsEDzHaKdR58DPyN3 cq8Ex9pv9uyUTfSKiU7BcSDqB/K3CYQhPj3Jhu1EkOdRT1cigAKx4CZRhb633q6xiPMaMw7V+w CPt9/O/DbmAokwlFarwHpXF0QnIzdjHjtit3cQe4KPlBQHKFf3xz2xSFkPzxjRMtszIyqFRPmo 7KISlc2QMZKjGfqjnHpAPaZGqSLvWyoP1mH0nBjP8Gi61yMA4Fdu/9KlABFoAoXVcW3DEPHbV9 g5b9ZUGUpH+mtUBn1qYScaMi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:42 -0700 IronPort-SDR: 4JMrYB64WMalT4y1XH7bd7XH6Rwf7neJoc3uXlt2+8rn3iCKU1emckI23PtLLfrk8eudQPL3MK WFrHUMVoN26NEj6FYqLDKwClqt0yN6Vc8BmEwnvX7ToN6LB03Pj2AYNZR9uo+2BSUunAamjixr LGrK5uDtUV5wbfgq+DqbFvvKS+WpfhAsTsmFLUtFb97LFp86sF1OGhHjzrZOvH0ZvWwj/ue4qO IwlBsQyih1les24lvyH5tcKtOKZgKSBulNsD/gPmyItPWx/0eVt7uKUeRTWoLABaDa5YwhaaEr iXs= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:12 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 8/9] libata: print feature list on device scan Date: Thu, 12 Aug 2021 11:44:02 +0900 Message-Id: <20210812024403.765819-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 Thu Aug 12 02:44:03 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: 12432345 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 DB6C6C432BE for ; Thu, 12 Aug 2021 02:44:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C30546105A for ; Thu, 12 Aug 2021 02:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233763AbhHLCoj (ORCPT ); Wed, 11 Aug 2021 22:44:39 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:60797 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233741AbhHLCoi (ORCPT ); Wed, 11 Aug 2021 22:44:38 -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=1628736253; x=1660272253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vN2oiBTls/J4Y9W2lVbQUymPeVbZdsgb/efvUuqJGVQ=; b=n1csh0TcaAiFZyiTJmdRZIKCAAEFzYE8WIWO2LQYZoR/dskA+12tRka4 LzpIcxN856v+2AE68sntAbFid2IU4vcZMux6msOmWrC7utUVI+HWcXvrk P+hhMUeylu0O4bieTdcSNsq/V7Za4ogxStjEBhmNtSvOLW+yv/6W/hHqQ bHQvQ2XPynnUwVUer5jRQ5sBxNXZpiTR+RmUJ+8fn2niYaFd4ci19Qh/R MRu6V8XTxp54NNH49bjlOhJQoV0sm25KIFQtciMCxb5nALyY3OIWI4T6t poz/y79R7NJ4n1btms+AdUvfY9u3s6bK9TpqXzmjfgg8GRz108vYOxA4U w==; X-IronPort-AV: E=Sophos;i="5.84,314,1620662400"; d="scan'208";a="176999907" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Aug 2021 10:44:13 +0800 IronPort-SDR: 4+iGKYXZy103vRapqDYWY8dtCgnci9E7nVwqTdWajA/N3vHHafvakjIG1WseL04tcXeEnzLxcb lbDi7E8rc6KPAWqFPbqr6uY17EVopiiF7WDn11tx4DFOcNUY5l9Nz3lLwd1HQn77Wh92WfluEd 2s9XM844iY2iSKn5Jk5UWBOL9oaucLJlHJkxvkRGqVsmJfkZXwOvQqBbT16Cywr0KnYGKsc+A6 11MiwgSknXA6WFkA6lAzFCKojxWifqqb90RvFg9hUijSd4U+DfNub+CQQa+UcjLm5qqKFBnHGe Zxo8YC5EBJ40BqaqQj3dm6AT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 19:19:43 -0700 IronPort-SDR: q6dw9ImJYlSjHIIJCMz2J9XI1elAbfyeakh7P6huB+O9Nv9mJBLVe0M1c9oa+TYMOuSqCpRZFS 0WKfGDeT64fFLCxE1mGWje9x35cyNjWlrjfFVAkKBDa1ei8TglU76zc6EX6qbU61GMC4E9F6ZL GUdOjsq7FAhsfCLns5TstVr3EjP7lUpHBF63x8D8zt+XWel3XcDnYBaclSvqrh2FILeOhuT27w I3Gy+W7xJ6yRc628DJgvbepdXFrYm60nGsNrRzNt7Bwvc+nGBWqk7KHWs5kYyjHPc3e+h8OHCV vAI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Aug 2021 19:44:13 -0700 From: Damien Le Moal To: Jens Axboe , linux-ide@vger.kernel.org Cc: linux-block@vger.kernel.org Subject: [PATCH v6 9/9] libata: Introduce ncq_prio_supported sysfs sttribute Date: Thu, 12 Aug 2021 11:44:03 +0900 Message-Id: <20210812024403.765819-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210812024403.765819-1-damien.lemoal@wdc.com> References: <20210812024403.765819-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 success 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 the status of device flag ATA_DFLAG_NCQ_PRIO, which is set only for devices supporting NCQ priority. Add this new sysfs attribute to the device attributes group of libahci and libata-sata. Signed-off-by: Damien Le Moal --- drivers/ata/libahci.c | 1 + drivers/ata/libata-sata.c | 25 +++++++++++++++++++++++++ include/linux/libata.h | 1 + 3 files changed, 27 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..8f3ff830ab0c 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) @@ -901,6 +925,7 @@ EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable); struct device_attribute *ata_ncq_sdev_attrs[] = { &dev_attr_unload_heads, &dev_attr_ncq_prio_enable, + &dev_attr_ncq_prio_supported, NULL }; EXPORT_SYMBOL_GPL(ata_ncq_sdev_attrs); 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;