From patchwork Mon Jun 5 10:52:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13267214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C07AEC7EE32 for ; Mon, 5 Jun 2023 10:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbjFEKxB (ORCPT ); Mon, 5 Jun 2023 06:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbjFEKwv (ORCPT ); Mon, 5 Jun 2023 06:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C753F9; Mon, 5 Jun 2023 03:52:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 08EF362281; Mon, 5 Jun 2023 10:52:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD39EC433EF; Mon, 5 Jun 2023 10:52:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685962367; bh=rQ8/mjK/Dgp1u1RF/QawrvRn8L8w+/XbQ7He6zsazhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYs+s72H6WJnielhczNqRrCgHb9pLnkPTMnQSAtTODwIEE+LitDhxWdrXLrN8WfYN DdTy0vZoz0f53VePyzmkZxQwNOLQTOuGvKQ+Wq+JqvaGzRgXaznGmw9chAtyi9Onu8 VBlXSXBehxT/wiqR9XL/DXddRhS1Wh4GWGKTNagVQH5EoFpivGw45WKdF2PeLmtPn4 UVAU6EQdAaNHx0odF+9pa2WQRZR1aeXIxQgC3R31+N5kxV6qZ8m3/Y+nBNVI3k3GKE vY03XPTDLdnymY0WVuQ91GrNrAE8C8UTYgkQ47Vg+3L7IOmdIh1fWBcEsCCcTbGMMK M4zuDAyIVCopg== From: Damien Le Moal To: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: John Garry , Jason Yan Subject: [PATCH v2 1/3] ata: libata-sata: Improve ata_change_queue_depth() Date: Mon, 5 Jun 2023 19:52:42 +0900 Message-Id: <20230605105244.1045490-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605105244.1045490-1-dlemoal@kernel.org> References: <20230605105244.1045490-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org ata_change_queue_depth() implements different behaviors for ATA devices managed by libsas than for those managed by libata directly. Specifically, if a user attempts to set a device queue depth to a value larger than 32 (ATA_MAX_QUEUE), the queue depth is capped to the maximum and set to 32 for libsas managed devices whereas for libata managed devices, the queue depth is unchanged and an error returned to the user. This is due to the fact that for libsas devices, sdev->host->can_queue may indicate the host (HBA) maximum number of commands that can be queued rather than the device maximum queue depth. Change ata_change_queue_depth() to provide a consistent behavior for all devices by changing the queue depth capping code to a check that the user provided value does not exceed the device maximum queue depth. This check is moved before the code clearing or setting the ATA_DFLAG_NCQ_OFF flag to ensure that this flag is not modified when an invlaid queue depth is provided. While at it, two other small improvements are added: 1) Use ata_ncq_supported() instead of ata_ncq_enabled() and clear the ATA_DFLAG_NCQ_OFF flag only and only if needed. 2) If the user provided queue depth is equal to the current queue depth, do not return an error as that is useless. Overall, the behavior of ata_change_queue_depth() for libata managed devices is unchanged. The behavior with libsas managed devices becomes consistent with libata managed devices. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: John Garry Reviewed-by: Johannes Thumshirn --- drivers/ata/libata-sata.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index e3c9cb617048..6c07025011ed 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1035,6 +1035,7 @@ int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, { struct ata_device *dev; unsigned long flags; + int max_queue_depth; spin_lock_irqsave(ap->lock, flags); @@ -1044,22 +1045,32 @@ int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, return sdev->queue_depth; } - /* NCQ enabled? */ - dev->flags &= ~ATA_DFLAG_NCQ_OFF; - if (queue_depth == 1 || !ata_ncq_enabled(dev)) { + /* + * Make sure that the queue depth requested does not exceed the device + * capabilities. + */ + max_queue_depth = min(ATA_MAX_QUEUE, sdev->host->can_queue); + max_queue_depth = min(max_queue_depth, ata_id_queue_depth(dev->id)); + if (queue_depth > max_queue_depth) { + spin_unlock_irqrestore(ap->lock, flags); + return -EINVAL; + } + + /* + * If NCQ is not supported by the device or if the target queue depth + * is 1 (to disable drive side command queueing), turn off NCQ. + */ + if (queue_depth == 1 || !ata_ncq_supported(dev)) { dev->flags |= ATA_DFLAG_NCQ_OFF; queue_depth = 1; + } else { + dev->flags &= ~ATA_DFLAG_NCQ_OFF; } spin_unlock_irqrestore(ap->lock, flags); - /* limit and apply queue depth */ - queue_depth = min(queue_depth, sdev->host->can_queue); - queue_depth = min(queue_depth, ata_id_queue_depth(dev->id)); - queue_depth = min(queue_depth, ATA_MAX_QUEUE); - - if (sdev->queue_depth == queue_depth) - return -EINVAL; + if (queue_depth == sdev->queue_depth) + return sdev->queue_depth; return scsi_change_queue_depth(sdev, queue_depth); } From patchwork Mon Jun 5 10:52:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13267212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1656C77B73 for ; Mon, 5 Jun 2023 10:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbjFEKw7 (ORCPT ); Mon, 5 Jun 2023 06:52:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbjFEKwv (ORCPT ); Mon, 5 Jun 2023 06:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B3B4FF; Mon, 5 Jun 2023 03:52:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1C9B62288; Mon, 5 Jun 2023 10:52:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B29B9C4339B; Mon, 5 Jun 2023 10:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685962368; bh=aYzso8fy5Dgl/2hBGMWOcNZpxClSlia8ZTc/DNTTbhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LiWkx0YPY8FsVee3FzY5OUB0q3C/vz9iCpcPV/VgkWN1+6BbTKKk+Y8wXGV/M5N4N MfUMEsToaBoYjx8ONjldEUpeZGi+R5RduxZmazz5p9PO9A7vumNbhG1mkvEfg7c6fe ujdDYjOjCcjk63YzBCPwHIL6nxe0lBEipmvf96NmjTrn6UAij2oY1m1bY4vSPnsjag gv50kgHa0CGQ7R8zSMS6nQGHwe/NFmxoUqigA0sE0hXi8Zmr7joTGp31tqAPvtkCnR mMNrnHT8XGZY9QnUKDZY/GMXAbPV/xRIg3liporW2nSfcFmKYb7aZIqsjv8/Emhadl PZ7UXQhm6l7kQ== From: Damien Le Moal To: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: John Garry , Jason Yan Subject: [PATCH v2 2/3] ata: libata-eh: Use ata_ncq_enabled() in ata_eh_speed_down() Date: Mon, 5 Jun 2023 19:52:43 +0900 Message-Id: <20230605105244.1045490-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605105244.1045490-1-dlemoal@kernel.org> References: <20230605105244.1045490-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In ata_eh_speed_down(), instead of hard-coding the test on the device flags to detect if NCQ is supported and enabled, use ata_ncq_enabled(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn Reviewed-by: John Garry --- drivers/ata/libata-eh.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index c7336a0a884d..b80e68000dd3 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1817,9 +1817,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, verdict = ata_eh_speed_down_verdict(dev); /* turn off NCQ? */ - if ((verdict & ATA_EH_SPDN_NCQ_OFF) && - (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | - ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) { + if ((verdict & ATA_EH_SPDN_NCQ_OFF) && ata_ncq_enabled(dev)) { dev->flags |= ATA_DFLAG_NCQ_OFF; ata_dev_warn(dev, "NCQ disabled due to excessive errors\n"); goto done; From patchwork Mon Jun 5 10:52:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13267213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EEBAC7EE23 for ; Mon, 5 Jun 2023 10:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbjFEKxC (ORCPT ); Mon, 5 Jun 2023 06:53:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbjFEKwv (ORCPT ); Mon, 5 Jun 2023 06:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 387B6102; Mon, 5 Jun 2023 03:52:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C2AFD60FC8; Mon, 5 Jun 2023 10:52:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9679FC433D2; Mon, 5 Jun 2023 10:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685962369; bh=LCWH8t6kozpxMnw6bvJ/h5UUoZlbMzqTFCVsNCIPZsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ohGOAXiHVBmJF07Ovr+5pCl/j6OVJXO0sKeFFkoOnTw2vNWUTaMSRSk0CaeuCA/dC Bp7vdmBrbtuFnKkucc0qpw5aYl/Ulfk/NpDd8kID5fEnGQAy9FnFne2S2ZGPqGVtpa NWCPzQ/7nMJ4ouSG6cprt6RNFjY8+8RpYRbqRc55XcEdp6bwVOunxd8H2TxX373GaT T9dZ8bSoMjiwWX3Q1EqMqjTmuScdGEwg4vtsK/HfSRtkBPjlVNUTW87kPXG+AiH7IJ D4HGfrX3anh2xMhq0tfQerHVWDqLgliVSgOP8YeydFtQFS6D++YOUCGqxDITIIMjv+ 0I98CeaIbXEcA== From: Damien Le Moal To: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: John Garry , Jason Yan Subject: [PATCH v2 3/3] ata: libata-scsi: Use ata_ncq_supported in ata_scsi_dev_config() Date: Mon, 5 Jun 2023 19:52:44 +0900 Message-Id: <20230605105244.1045490-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605105244.1045490-1-dlemoal@kernel.org> References: <20230605105244.1045490-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In ata_scsi_dev_config(), instead of hard-coding the test to check if an ATA device supports NCQ by looking at the ATA_DFLAG_NCQ flag, use ata_ncq_supported(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: John Garry Reviewed-by: Johannes Thumshirn --- drivers/ata/libata-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 7bb12deab70c..9e79998e3958 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1122,7 +1122,7 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) if (dev->flags & ATA_DFLAG_AN) set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); - if (dev->flags & ATA_DFLAG_NCQ) + if (ata_ncq_supported(dev)) depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); depth = min(ATA_MAX_QUEUE, depth); scsi_change_queue_depth(sdev, depth);