From patchwork Sat Aug 7 04:18:50 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: 12424143 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 2EF10C4338F for ; Sat, 7 Aug 2021 04:19:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1048861050 for ; Sat, 7 Aug 2021 04:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbhHGETW (ORCPT ); Sat, 7 Aug 2021 00:19:22 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbhHGETU (ORCPT ); Sat, 7 Aug 2021 00:19:20 -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=1628309943; x=1659845943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aXW6/p3ypW87W+JiJ4JAJc8PorvCsLNnaanq9ftqUMQ=; b=Ym9XaYYzaUQn2jKWkD2wVX2N+4z1/L+B/sDaghIw/SIM0Npv9o3D42PV 6xdCaJOZNZ0AiSS/pEhlEZDV63ZuJwEWmLjqr47V19srj03Dp49Ts5Ebh cI0qn4ICDKo6x28ofApKKr9n/ww7vdvjMfdkTydp0b2577WmX/ACXT2c3 RWT4wy9r/0k77//aZG4bOS8CdbJFdclSAPdsz1Jr7FlNARQsR0q5NlI9V zIyeJ0yjbXiq/IttFD1fu5jATK+WpWNpzO9t63pKH4sqGZ13tYxZuBp7x c0iFFvKDSNzyxF0ALAXbwbeTmax3KcE42xCy/0IP6LOlALEhW71r7W+Xl Q==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363642" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:02 +0800 IronPort-SDR: VB8fdssUJikSJUvsIo5HARe5t86jXzxqy1TD3GbLED95shJjRrXGT6/hBGwxeh8roSDT5ySmI5 uvsdDxlr3KIttP04b+APQ6UWMkgzBw41+Bt77LgttL9nSY66B7p3LPqEUx6RsoTxCu5HC0xKoo F3MXUySSjYyNWDOZE5YRFDNRZjAbb+z4DOa6t+NyimbgAQFV1JmBh0sPir0saAhsG8ifg2iPY7 kZhIlFadH0Q3mP9vf/kIPBlq0hGJ2bLC4OT5HAT0xWwW8lDNDerZBxry6OJPB9BlTaJycRcYM+ lkoH//yUdYM9EwTbayqby75G Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:30 -0700 IronPort-SDR: 8jYq1+Tf6VUQkuovmAYZRUHc+Oooki+96ZnSfM2Phsp95TNjCSPsAfAWwsXPMluHjf29o/KI71 m/Fs1RpzXClFleWQcjPLNxCuKUYEu6Y0s9ulHOvPiqRsRNz4rU6mdNRsRj8L3dt9ankA0QkZKQ btUKzK8hMcyjjle74Z/rB9fbJkZAi3oP2hil8R3PTwK5oz0AZ+nTxLTwx+0p3ZsthPXnwCClVC B4JuQFOnaOk1c85ANl5RJGoAL2qDsNOF3CrYzmJPjTSdRn2yVriaP81p5zNoBjawHnaHRc9c2h YPM= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:02 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 01/10] libata: fix ata_host_alloc_pinfo() Date: Sat, 7 Aug 2021 13:18:50 +0900 Message-Id: <20210807041859.579409-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 a non-NULL pointer. 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 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 61c762961ca8..b17e161c07e2 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; @@ -5458,8 +5459,13 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, ap->link.flags |= pi->link_flags; ap->ops = pi->port_ops; - if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) + if (!host->ops && pi->port_ops != &ata_dummy_port_ops) host->ops = pi->port_ops; + + if (ppi[j + 1]) { + j++; + pi = ppi[j]; + } } return host; From patchwork Sat Aug 7 04:18:51 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: 12424145 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 923DAC4338F for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7591961184 for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbhHGET1 (ORCPT ); Sat, 7 Aug 2021 00:19:27 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbhHGETW (ORCPT ); Sat, 7 Aug 2021 00:19:22 -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=1628309944; x=1659845944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0zuuTEioe7MID7y1H1YGfUq9+95S+EpDoqEJVj9gR/A=; b=AQ1/IL/IecP0Zvt0FSJzrwN3aRohBahb3jaXPD9Z1OspRmRoC5IFlGNP Mdb/txxnl4ugEXdPGhbeMkCgYZq1+qrj1UiHOJFr592s/dV/1XYmwU/Fw zFNOs04JT/xMaRtKQib81bc+L+L/Ek3P3j6L/+e0xmcC04gGM4GhceJRu WiI8m6i+jdSKGBfbAi5kUc7fPSaPWJ4YA49wbiytJJ5Po15fAdVd/T92r /VYgIyMnOuMBIRB1NUD/FFlmtQFFFOk1DNv8F5n2liE6Gdwh/fC6X/Nn6 xwui8Cu0uGlis1kh5gcvM/BecdqHFxtDwrHXSRXpPWOSc5MDZ0JuZZjay A==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363645" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:04 +0800 IronPort-SDR: XG/aW7NvharnXSRz1gWIHYbJzdp+4lb4KlT3Q/rFyVZPvuRbEa7jJ1iNItFBlshHVCAH6JlgNm r5DLKIG0sRqVn+AHTQXZF2z1nB66VzU9kfKXTblmBPB69LixIBXfizyJuiCKPX1iFahP2kuKm4 2kmg86zLeru3gjJfcabOZA+VMP72+dZtqOk4/VVmNp9cl9XnbIFBaQXwfvAa4xtfU8HgqjV8zt a8q2/hi8KM1sZ0HJi1HjBYRr/14mN+vr/FK8NbDNNjUT30henmF921FZ6EbbFv0cUFnRIax/4q eE2IzM3hq8iMM29PnMWsyene Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:32 -0700 IronPort-SDR: 1gsNKyc7+j49zZFioxzfQ9UuVYk8uMuKHRL3AF2XqdlmaLQ+Eh94+vKOaHS7UQDlstTC+ga9sz nvaVpcCUZjGkhJ0uDkYa+thtH3Mra6tz5ZsD3lUGPMIm3M5E8eRJnZTmK0HdNvS6uc9MrwgZhR v/xz5XJZlAyVhNDMzQfukMDcvVHcYWMRu5X0HrqRuZhapAICThdYoeEmPkn4xUP+MsIo7ly55O ukjY5P2SxUt/xfajWgFlzvxPR1udTeN2fxcWsSRjslRKJJNwGLxfVyUK77qps2UDsYCrE6samj cbI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:04 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 02/10] libata: fix ata_host_start() Date: Sat, 7 Aug 2021 13:18:51 +0900 Message-Id: <20210807041859.579409-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 b17e161c07e2..01cbf45f9d02 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5579,7 +5579,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 Sat Aug 7 04:18:52 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: 12424147 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 A89F4C432BE for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8499A611C6 for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbhHGET2 (ORCPT ); Sat, 7 Aug 2021 00:19:28 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbhHGETX (ORCPT ); Sat, 7 Aug 2021 00:19:23 -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=1628309946; x=1659845946; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GDixQfLhl+wigdfxzQ55zq0wfcgvOrepU97SohcxuxI=; b=JW83/p7L3ilvfOUjj0aeOG+utnmC+6i3HPAmTWXNdKwo8FyB+0p6/vsY D9YEkYBK6Kte7mjJ9QzIDwYsziuhZzeRczQyRZqudSwB7Jby5x8U46/Ip lm9aTZwe1ZWKMJRi9neV8rpbtNX9AXX+0VShDmdZGqpB2izd9LXxzTPcO vZIt2rHJ6pDpMunMg39friNPGvk5uI+hJvwBKlZHp7RyDyDQU5JO5762i 1kFXjmMrLJBe/1Ox3kb5bJRCQpexFNzBPniASqC7nibl3hX17dEbc3nWU cYuzqlaRwTubloS7rgv1vu/Eq3VXWUbhRXLgWKOm5yK6buJZoWCZcCSuR Q==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363648" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:06 +0800 IronPort-SDR: +HUL+iNdrMdJvWtsUvLuy0mPNY36OVn7tVVo32Y6qgbjr+j+5Dm0mOkZqnIK7HPrP9SbpPgzar i8YgDG1sUf9kUbtwKlBzuQn9CdM17c64pBYKjkyYA7G4caAWMZZqUrzhc30FxyzNTi34j1ifGo Ekn+R6D+zQIS52S4GYOI6nu5iEc9e7b/69UXNHFEWON7R06sO11dHYZZ3HLKqOVSSrDC2hNeWZ zkKyj56R3AUUb4+qwiLABnlbTtWMjsjRl2uVQYPKzXyH00UfgP/pIxpFyFNcvq35sEENoOn4qT LFaAr2MqCp4ECoWWX1wb2aYI Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:34 -0700 IronPort-SDR: 7uQnmpPLJjQ6xBWlT+TTc7YXZ9UUwDTRI9Ci1FEEwNHy12vbizIO7rkpwFi4FQ+MOj8wuYm8eb 1lYmYS7MF+uGpghk2KKokRX7Ki3NEF3VdXg4UtsXs7s3MeRoO4TK+bcezP0T1HFBUroBHPanFO 1MmUt/OwX5L7NKOEcEjzLTF/zOCXZ+K+x13k9CZMezSpybKsYZ/wgT4hGLB26tO0KFIXVCBdtp Ffi7qmdZvl3rsR4auifyEqBSQXcUKmMHtdNeC2/f/prBTaCxdxCKY3KpH1CRw+FNO/o9bLqiHW FZ8= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:05 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 03/10] libata: fix sparse warning Date: Sat, 7 Aug 2021 13:18:52 +0900 Message-Id: <20210807041859.579409-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Sat Aug 7 04:18:53 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: 12424149 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 B9DECC4320A for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CC53611CA for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231132AbhHGET2 (ORCPT ); Sat, 7 Aug 2021 00:19:28 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230468AbhHGETZ (ORCPT ); Sat, 7 Aug 2021 00:19:25 -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=1628309947; x=1659845947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+GiROEWUnztuRRKjkVPOCEL0TaSeYA6z70ChZ/n54KI=; b=YFShRcW6yYt6w3aa1tju3Bw5GdU6d7/GILAGFgF7DuJO52CXJELyIQRp rLZgTzS+JVpSJYus/nucb5XsIo4hxz3b7nBVfeMz4hveXx1o3uS2kssil dXxOqOKi9lngIiua+tlDOnsf5QA5DSBUsQWUEB9gZZSqITgRKKB0mWgI5 +FvRtRbqPgR+V2AIeXiT0eFneE8nXHBj4NvZSb9guLQopD2By3qIVxgtu a5hjm6YDf3t7EZiJZdtJixgN+j7Fv9dXyp5aV6Q3MbnQsnpZW9kscmQlY Uy+WLuXxgPE0K0FJ3HdtXs++9PwAP4Z72tBCPehA+jZSk0oFnE86Rssn7 w==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363654" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:07 +0800 IronPort-SDR: V7lngx/M6I5zfV1XiEOO+UKaeD5cW2WsznXVsbmQKWP5SUxEUGau4iWBZwgi2NvPFRfH4kuvJ/ ZK22QpycBCk/GI/ceT7lpHFox2hvYhzd5gojnSs5Qa3LwAwQPmSSgufsy4APb8dXy4q3bXXQqA mamdxriaRQDi6h/d1ggeNxWg1fVvYEgRYzV5OKXmHwNCRxhjGWfzPtUcSslknQJOQotw1Z7s79 MoAZpFHOq2xxi8RnK2G1ApPjvkEzmsqZEqHHiLrRU0zXDrBYPbrPLrHuUMv77TN4Oh6/n1z1dO 74/yquvDPS+JlKbc3B2McU+6 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:35 -0700 IronPort-SDR: 0JgNqRQCl1+9W6vmsNvsAQWLCSoxtdOERHkyiTYZJsF7J3DyhP12xSKbTzH/F6pvMYmwaF2ls9 54tdt7rvrrx+qly+PenwuWs1GBaslDEeyheaIo+F8wLW1hJqBuJbU9445T6sWNlvcyisrhqj2Y h536am0kcSFQlVicr80rEcKArVLGSzIIx3fD3luECVELx/vzSrscdyy4G4R7q65W1rZjh+dpvZ HeYz+vf7uzEfO4ZteqWVQ0fI5PfLEL+UcaoViAMqsCyGv1f10mDvkB7Czn6SY1PDA8C21YyHAM mqM= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:07 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 04/10] libata: cleanup device sleep capability detection Date: Sat, 7 Aug 2021 13:18:53 +0900 Message-Id: <20210807041859.579409-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 01cbf45f9d02..febf46b87a42 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 Sat Aug 7 04:18:54 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: 12424151 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 CF0B6C4320E for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2CA061186 for ; Sat, 7 Aug 2021 04:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbhHGET3 (ORCPT ); Sat, 7 Aug 2021 00:19:29 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbhHGET0 (ORCPT ); Sat, 7 Aug 2021 00:19:26 -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=1628309949; x=1659845949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U84M9F3y/4VazXMtbdvkj4XojBngq+NUivd0VWyCXps=; b=AM8vezkIqkbdSWZX55/rX63gAP3WYOBtApQgPtlmvYzyXcocW9r1f+8V mvc3aisnSu0mc9E60QsJFlIkiY0j6iIojxvsiaqT4k/bqm1SJbLoUl6Kn NbxuSXcx2XMrTALYb2IDKvXzFxKHNzZxTMeZy5KI1hCj49gz8R/P2UTyj XYKnGn3HmsOWx9Ho7Xhg1Wxd0tRAJ1wlOGPMRIZWg0ttyLmQvrv+eMSXO 39dzxGPqr5pQdGg4WrrQqS3HIohngj2QAHLQK+FZ4ChaknIdQiZOycTYU cChlAlKwTRbgJOKBaEHQCb+z1rfR6BAfJQJbkzrtWrcTJSkG2c7lxstCO g==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363663" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:09 +0800 IronPort-SDR: L2e2YAXmmYBsXZ8wIuPV9Gx7OKKBoaIAZuBIu67r/4P75xAsRHCDHjkoSWLlhEku5NGlwhpOMG Fvu6PnG6bA8i2aZoHyaezP9w/gUg5MjqsZGKnNWKGiT5qvn3CkaxZlKEkAzFZZYavuhg+JZTl5 Kdrfkz7BapQ6BsAvX15i3SugLZk8i/7VfQuGkqGX/gmmiH0rau56F01XyfY2fFOKN7Lrw8mHOS pMAcKbNoUon6bQwTgrfqdnGYSN/p1EvydCU6ZpklSyCTmKaBuCyQwYs3KthN+uIIGERNetGwym gf5A5sR7G9k22nyUYjZEYyk4 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:37 -0700 IronPort-SDR: Ngon84kmLIzaYJMQj5PCSWIzx2IqOfgX0a8/tszlpFotsifLpexT57uXURDdoylAN3U4aBYxGr /4sjFTOR1d1q3rvn+0HADXYNEf7GgWA9VOttAmOTyciSfPT5MvuDlONBJaqvUWHmUvVzOp4bUi 6xVUCLKKvqSRG8lxtdrv8xK5qJZ9Zf9UuHAdCNfV/Hb3/npg38gwPZlbzS3UqyJ1SM/vfqGsMk a+86wQ7R5sqLnqMON+SGy20seQ6v58KkItE6LZp1KM8fR6hLmwh2vmF2kO3mBJR1DHDD7HEOj5 jME= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:08 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 05/10] libata: cleanup ata_dev_configure() Date: Sat, 7 Aug 2021 13:18:54 +0900 Message-Id: <20210807041859.579409-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 febf46b87a42..c6a2e34e0892 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 Sat Aug 7 04:18: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: 12424153 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 693ABC4338F for ; Sat, 7 Aug 2021 04:19:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4879361184 for ; Sat, 7 Aug 2021 04:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbhHGET3 (ORCPT ); Sat, 7 Aug 2021 00:19:29 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbhHGET2 (ORCPT ); Sat, 7 Aug 2021 00:19:28 -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=1628309950; x=1659845950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sjXTmYo4sn61BUnI2kgiW2tC8+lGR9/EdPwlJmMEhHY=; b=GVM3uoWbH/++W7dzSKal7eotudJw+zdOTlhnZ7CWGMVKlv0umouygN2p xzN1KtLZlWJ3sWL6RVnsT24N9T/Vk5a7T52csZTrpW2egZ0MHh7hPbniW DYDWgFnKHc7wKDvcQvKRqZ9qiYZsVWYyVq8Ou41pUYNHx6sAY8lF33md+ jxnT2Mj+gitrOst1fSCPRtKE/VkZ0h+Ho64bKwN0G6uwucHaIeQLlE2jj Cf85TLIaGRqBGkctD5egEwfmjX+nB8Fl2W7Fw7NOWgIpG8n6CxaXRWYE9 6oVZzsXOT5k4OHjF9AP07MwS6jkQOcMJeirjHgT2avg+1rUxeV/zfmO/t A==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363679" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:10 +0800 IronPort-SDR: 2g9RON3QKBG7kXbKTHZDmT+aYV2/4iVVZRPoeiRQmrzEAS9ejuxbWcP/8cQ2dWCrQntpXakAbq OKldieFlZeSrSESQE57QieA1Y1B5mSVBrdCHOjnOwu93CpNEx6jSXgj91R1ek4/3Em5ggpZOhV C+bQutaYN/gQbli2isGcW5RPDi670hgJ9CV6j4gGThGXslAgiSIHHBxtlRPe7Hh/6yF2N3qHnN NNBVN0y1WbbVbZdcO/gXNobKKqUTzrKNIcgue/PInHrwvPpz5uPF9lXCaxEIgd0dpra5C/mh4X u1D7G4muxWX53KPMN6tIUTYF Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:38 -0700 IronPort-SDR: i20136/SGkWFwDMZXZpLNr7zpaCaxmBu5of2OP60qP5X2SZX85IpGmojx8mSxx3pz0CUKdVEmL JKXxFqqEpf5Ae19/a03FHou276/NpLwwTOWgPFwCXAaWpTJgMttke6BQveBSHGuAbkegSLKN0k VZ5Vo5FvLH5iMN+8RGUEVtgoHZtIfMjaHuvAUbnonXq9FPaB8VA3n3E5YoNXvPsCYf8+nomuNI i4QEYVOSiYGEjal8Fjnqo6/8lbPSRu66XrX92TR1T7ks/eMkXUJrHJYFQHpHv3Qii92cdA8uLC 2HA= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:10 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 06/10] libata: cleanup NCQ priority handling Date: Sat, 7 Aug 2021 13:18:55 +0900 Message-Id: <20210807041859.579409-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 c6a2e34e0892..1c4bbffe278a 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 Sat Aug 7 04:18: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: 12424155 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 75C1CC4320A for ; Sat, 7 Aug 2021 04:19:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ADD461050 for ; Sat, 7 Aug 2021 04:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbhHGETg (ORCPT ); Sat, 7 Aug 2021 00:19:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbhHGET3 (ORCPT ); Sat, 7 Aug 2021 00:19:29 -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=1628309951; x=1659845951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kP0nZC0Sw72+gnkku+0txnLWoRQMfSsK94V42t91EkI=; b=c+thhZBwugMTQW8ylJZauYJYQMVpc0+9PCXb28ZIXDxAd4LV4MbHs91d LSdzRgTBE4weTUV8nLrL37xmgOF1BrAwqRNpxpHR0tcTNk4CNJE0r+SUs mJi4pw0C3dTdwJmikAOSvsY6xASY722yqGOJ62iGb9ZcCwXebJkI2xGBM aDE2z+R/70ID0uhcg5RiaPyHQAiaubPfcAg4X4a+IkNhgCPVi3OmJtxyi NVv7qRncAf+2LHx7QAK5s83lHevxTLGxyfjBvCb5zjsXBnIwUD7b+OGus kAIyZNjAXeSdoBJjHb17doRHaWM+4xWwI/M95jskzLV2zfuu8tohnzhvv A==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363683" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:11 +0800 IronPort-SDR: N7r/pUbEMuRzrms+NUap6Vf+SherudYHOqEiDTYiiOiWwo8/06OHetpIECG9I4NfgoVUHOjmLq b2Tsu6eyc6zqHKJvrGfTpXgTz6DO5i3mcPaDFBv5kVX1TmUdRLSAe6c82lMIEfCw1y3t/SQKio nj+ab2J90xVQwPOVHZXXoK02TT9p5gDgrSuuEnFAiCs6Ii91Ls47eA6VOUJVPPrRl/pZFdRscU BbNEvsQm4Rh+aXLEP3JVXyG70UIVgFK82W4rIGsy68kOdDjbA5FQfQysYDeQHQaTdZK4Nb9s7x X6OrkK3cXTL32bfw1FDKZADS Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:40 -0700 IronPort-SDR: mMmNzQmMNzvaKN90ZLaCsGF9qtkHvxcA9UkYvyCefUHsHCQnQGJD9VdjINlrj/oqoSu8aGmzAE KLF/zYEJ8Bopiur051VV4dEovHAMTJfu5EQTvloT4DSJ0RUuymyu+QWz9sGPEsN0mGU/2R1a2K 4rm1z1hlF7ZI5hIIryYlU9oqWWShR6MVwUSjc8pwAFDzjTIc2zcMLfhZyWQEncaPX1H3A10FR+ yC69VKVpLn1pNwWUrMovLkj1jNk4ufXwMGDBYxIguaT8kePvzZgfGFNdRn/PsRReqB0jLuFAgT xy4= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:12 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 07/10] libata: fix ata_read_log_page() warning Date: Sat, 7 Aug 2021 13:18:56 +0900 Message-Id: <20210807041859.579409-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 1c4bbffe278a..a148ce94b3f1 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 Sat Aug 7 04:18: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: 12424159 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 A9BE7C432BE for ; Sat, 7 Aug 2021 04:19:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 848F761050 for ; Sat, 7 Aug 2021 04:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbhHGETh (ORCPT ); Sat, 7 Aug 2021 00:19:37 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14410 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbhHGETb (ORCPT ); Sat, 7 Aug 2021 00:19: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=1628309953; x=1659845953; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FeD81iqhRNdggxCMSF8P8CRy5kyAnolAxVz51kW9A6A=; b=REKA0avth1nKg54Jf4nfJoCQImXPwIArbCQ1juVJwo3qInvcP3owhBy1 7q+ei3wsfMrFjCUiOGX4G+HPQ0yE762rEsPvP/JPkzOAmNYHxni+ugb5L kUs8+DLd7EEOIllG10rATy0bEVAE7gdguWkDzepHOhxKtYF83kLJcFHbR frBvzCI7jlnp+4IFjfWrxYrJu+NO/VIz+HVWitCU2n6hpMasHdIgnD2Ar 8xA58nZsWAQznOy3MqP943KoRerF6T5/MNpH4vP8v5oRBoXpibQup+6RY jTcMsWaeWPXrXSGYA2kIt+Go7Z5WuYowRUTHd3DOMiQS2a13XzWJqwHEB A==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363686" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:13 +0800 IronPort-SDR: G9NUw5wwXoN0QACKkWdxfVi6RWouFU4QJJxnl5G5ZMXSaQTMpeGZWdJrh6p8PbLICP8ZIHX44G rGbhXwH8JJ4f4EZO2XBq4u1Y0e1LwKyar5jh0d0WctJw3YsN714TLtBPd7jSFvrGHt4YIn5sBX mu8N0d78zryWNZguQvgT0fEf9RBkeqzARKUxjRW6CUxkLbvoq+tQXrBoCb/YbGkUhypJieTyWe cCtrfRAvYDMLWb0FgSCqpapCRqqpcu0rwMOzDNdP+u0cpiVyRaGJzDp1OBbE1fUKOql+hBaazj oWeaW3xDcdIfVT5IECultRMy Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:41 -0700 IronPort-SDR: fg9SwwOnw2yr9s8/bujKhQHtTgmfy5eRffdQSG4P/D+zbMP28q4KLx0bYvigqpeyrBCJTkNryd 8aMtk8RB1tK8EwH3g0k6NWcR361F4fN6xvUpD9TSI69BLP/hlqf3DJA4nccNRsg1LoJ1HHn/Rs l8aKgP5qa27uN+XqbFze3x6ffIlbt06Bkq9fUcu9a1+wzepgQGxaqI3AW3qGwt9NiDlRsYcJQV oJ2Auea9rrUitF0V4ty7IZ36J4NY9TZUZWhNTLpONi6S8x/ZHALgrzssIT/taLkiwnXoCSfD1A FG0= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:13 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 08/10] libata: print feature list on device scan Date: Sat, 7 Aug 2021 13:18:57 +0900 Message-Id: <20210807041859.579409-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 a148ce94b3f1..5281864467b7 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 Sat Aug 7 04:18: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: 12424157 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 B10A1C19F34 for ; Sat, 7 Aug 2021 04:19:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A113561184 for ; Sat, 7 Aug 2021 04:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231299AbhHGETi (ORCPT ); Sat, 7 Aug 2021 00:19:38 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14411 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbhHGETc (ORCPT ); Sat, 7 Aug 2021 00:19: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=1628309954; x=1659845954; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dxUqBpMfBGL8QgT/G4aYqB14OK8eppkoSmc37wpGAVA=; b=T4kaCsY4S/i61S4FlzKiNK6FvGxmS0gspAdgHeWqC7hyyllTM4CpB1jh h4TgHYEwypJ/AlDpMSK+aD9iZo/hRNGteWNAUZYZTG++0STfMilplvl4e urqwxmfbYR7s/Ip1HGteHIx++8dFlX/0YprygOk6GTrlOVXpoD8Nzc4+r gs0oN1E8tA36DXtsMvFsfsD3CGWpHwTEWnkSfdOM7SpcB5f8vnaePkz8B n9ow7tDKD3w6Moe5/8jNPy9sUQ2runmLbSesFT4KFmGbdsWNcPpYzjYsN iS6NkvaaFyJ5Ezz+wZWQBEhbjMgieeS3COD/DbTajGHHMb446/ti05eo4 g==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363689" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:14 +0800 IronPort-SDR: k2ayp3B3B3MwLukiFAQn7uYXBzYIjlMnw9ofsEnrXRxZlKh7Jim5IT4oD9wQ67Gju7oFjE6ZAP NOHocdV5PBmUcAN+r+XwNHqoz+CIesiwR7lWe3M48pmGbSzPwAtRVUvssE9o0fWMo+DLieOrvj YFamK00G0iq40WM9ZfbRzm7hl6s4UHzqiUt4VwWTUjQxAm1heG2iueuZLByr2NOARVRyAjaOj1 s0E+WQMs4rub6ycxUwfe5i8SdjUrz09En8ewZvI4K0iAE8qujA/h00cGZpSp4ybVqofu/tdqoM B6J24CA8mSw/VmXxqlaUSzyX Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:43 -0700 IronPort-SDR: 8rmxOSSryjFqWz/7bhlmZ+X8xxfu31AeLhhFPxuEHFqzqztKOzw9z2VVPK3ugdwSp88599dz2A 8MiQ0zcwaLgxJHOle/IjdeuWfWYELnKfujJoFbFLQLBGLrJYZ6qbBRg1UR1VKTbXWWcIsgfrUF D2T0oBCHza4rqi+Wcntl18N2B4LkzANtCT6pzPim+l2qxyO0nGop7aoyu9KCXvXT64b58hlmwu O4pgsc/hbOMqSY2yiP818ZMdfu7AQax/6WUdKuFDM8984AS7ur2OMQ9jZtVb/hz3d7gmumo93b 3bc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:15 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 09/10] libahci: Introduce ncq_prio_supported sysfs sttribute Date: Sat, 7 Aug 2021 13:18:58 +0900 Message-Id: <20210807041859.579409-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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; From patchwork Sat Aug 7 04:18: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: 12424161 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 E04E8C4320A for ; Sat, 7 Aug 2021 04:19:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC7D061185 for ; Sat, 7 Aug 2021 04:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbhHGETl (ORCPT ); Sat, 7 Aug 2021 00:19:41 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:14369 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231247AbhHGETg (ORCPT ); Sat, 7 Aug 2021 00:19: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=1628309958; x=1659845958; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v0axotK745BOmKq1hqhT1UMPhW1oSJVk5yL66WtuDMY=; b=BB8/By+o0e4/B6z29KzwfC5z5obDG0XLhArYYRkeo7myZeHEIZgNWV9X KztVOSO1QB7ddbOlnhAhnZk6SPqKRtELY1YLSyiY8JawqZDHgujXAXi0C KIliX2zJI+Ip+YBacoog1CtTw+dLY0YwFotMzYOxkfp2nM4WUTyD9356M GLfE3EUrfBWZyTsv6+QlA3Edk0lEi8izo8m7LgfyirxcR4Y2zWNa7aYiY TDKuU58/BnIQ2gy12RnBIpOJichaPOkNCaN4W5cPvyBBsgnnB8xOAzGsd GP3tSKm3Ce6COqKF9Hi/fULE+Sdp4xOmKotHUvfSkL06MggaC2FRJFRwH Q==; X-IronPort-AV: E=Sophos;i="5.84,301,1620662400"; d="scan'208";a="181363694" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2021 12:19:16 +0800 IronPort-SDR: zwxci9ZM89sg1h8Vu/whG5sAWRbWxnsDFVUVl3u/a+DjEMbI2mtlXmi+7WNOsGmjsFomua6gd3 zloT3oSlD32oG+jk4x5G7PldyZk++PnIT1moKdsdn0auXytOnzquoILVexMtiYk3A5cUXUMm+F AETfb1dd56445qTdNzr9rtnyRrik/t0nYVQYQyWURQiEZgsRIgfuHScyAJ1L4r5eY973R/j/Su 7KeI+2U+Ecfhkid9i7zJB4vf/8TFgiWDnWdqhAizrjt2e7vtVcZizCk4UKhENEV040Onp/uY5L ucRRbCvgyGHXGtpYkCmQMoaz Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 20:56:45 -0700 IronPort-SDR: voDHxoG7w99GokpiODviS6Bnk/ekEg4inL25ebaj4mmnPclmXaU1Mc+8AMvVCN2/jNa/u29CjN u4HVWit2l0ioZ9DrNHdu2DS20WHWull1uScOkstaLQhoMpuJY34f/piet1GJSUlkTAwBkdI17k Zv8in9dBkXU6La6UaCtlDLZig6k6IupWHbQ/bYND6Te90nmjmB2UI8LSQIPjC3t0YX3TaqeKuc uaB7cQBYIEN+sPPyEZw3PcHAx0vhrsQdX5RdEMGqj66Zpf6BLhQYqrlw6JlG+UHe6x+CUFrQkf fNo= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Aug 2021 21:19:16 -0700 From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Subject: [PATCH v4 10/10] scsi: mpt3sas: Introduce sas_ncq_prio_supported sysfs sttribute Date: Sat, 7 Aug 2021 13:18:59 +0900 Message-Id: <20210807041859.579409-11-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210807041859.579409-1-damien.lemoal@wdc.com> References: <20210807041859.579409-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Similarly to AHCI, introduce the device sysfs attribute sas_ncq_prio_supported to advertize if a SATA device supports the NCQ priority feature. Without this new attribute, the user can only discover if a SATA device supports NCQ priority by trying to enable the feature use with the sas_ncq_prio_enable sysfs device attribute, which fails when the device does not support high priroity commands. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index b66140e4c370..f83d4d32d459 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -3918,6 +3918,24 @@ sas_device_handle_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(sas_device_handle); +/** + * sas_ncq_prio_supported_show - Indicate if device supports NCQ priority + * @dev: pointer to embedded device + * @attr: sas_ncq_prio_supported attribute descriptor + * @buf: the buffer returned + * + * A sysfs 'read-only' sdev attribute, only works with SATA + */ +static ssize_t +sas_ncq_prio_supported_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + + return sysfs_emit(buf, "%d\n", scsih_ncq_prio_supp(sdev)); +} +static DEVICE_ATTR_RO(sas_ncq_prio_supported); + /** * sas_ncq_prio_enable_show - send prioritized io commands to device * @dev: pointer to embedded device @@ -3960,6 +3978,7 @@ static DEVICE_ATTR_RW(sas_ncq_prio_enable); struct device_attribute *mpt3sas_dev_attrs[] = { &dev_attr_sas_address, &dev_attr_sas_device_handle, + &dev_attr_sas_ncq_prio_supported, &dev_attr_sas_ncq_prio_enable, NULL, };