From patchwork Mon Aug 26 07:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=NfoPGmMD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-2140-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj5x6LFpz1yXd for ; Mon, 26 Aug 2024 17:31:17 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ECF411C20C3E for ; Mon, 26 Aug 2024 07:31:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BDB885654; Mon, 26 Aug 2024 07:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NfoPGmMD" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE8F813211C for ; Mon, 26 Aug 2024 07:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657469; cv=none; b=NWu5QgjQm5HzDtEt0eJu+sKEGP2O2Pv+Fi4tHgZXWGHSH0FyEBALjSlYpsbzQQVs/d6clIgufnobKoLbsVVDw6kTWkwhnad1RrfaaHZNGscci2isH42oPMc190lQ4kwkH1xN/jdkYGAFFubBqt0lzyx3CQ3D4P7divWgzkBaii8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657469; c=relaxed/simple; bh=bknYmcwS216yV1xpvFAiecowwNzrfnRh2GOy7kO256s=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Id9b/8qm2THqJdrVyNwOj0TeJWS2wusXrRepVxZdwPPI9gHObKK92XapxuqvyRkUE8jbDBrb8LeLOHqAFP/FEtBMH8g5hL0PXh8Wa5XQmXGgmqEXz6w7q4AIPGUJn69fyfDQAPv9wJCAlbrkvmAr3PKzgmnLf4zpGHg5tG7VsRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NfoPGmMD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29E12C8CDC4; Mon, 26 Aug 2024 07:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657468; bh=bknYmcwS216yV1xpvFAiecowwNzrfnRh2GOy7kO256s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NfoPGmMDVJaJ1GJJmw5VyR2XJszBJPeOGQSTx5yz19UTeqBg6FnNDB+bRcn77zI/8 szhhOq/pvoHiWqW3yGIcjqjHO14YKcnJoUYTNXICfIsini1fce7PQ/we0TnZEAW8KB VcjtGeuzAMjI0YN0gaMQF6spNfyTIjrb2ZrnTExUXUGG05R05sv0NCuD8FQpn+Ca3Z LxIfa+qWpEwE464st835UkcwXd7dgsqcfPqwGMaZXQXwr3TgrmWy1bCPvrc+5fmr1X XCBBnPRV4PQ7bVNa2wVRB2k+vCzo441yLlsc+DKrX9kpjt8o+CkMMGVRfyDLbhaA8Y IA5KGkaMu2bzA== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 1/7] ata: libata: Fix ata_tdev_free() kdoc comment Date: Mon, 26 Aug 2024 16:31:00 +0900 Message-ID: <20240826073106.56918-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix the kdoc comment of ata_tdev_free() to correctly describe that this function operates on a ATA device and not on a link or PHY. Signed-off-by: Damien Le Moal --- drivers/ata/libata-transport.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index 48800cd0e75d..474816a9efa1 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -660,14 +660,14 @@ static int ata_tdev_match(struct attribute_container *cont, } /** - * ata_tdev_free -- free a ATA LINK - * @dev: ATA PHY to free + * ata_tdev_free -- free a ATA device + * @dev: ATA device to free * - * Frees the specified ATA PHY. + * Free the specified ATA device. * * Note: - * This function must only be called on a PHY that has not - * successfully been added using ata_tdev_add(). + * This function must only be called on a device that has not successfully + * been added using ata_tdev_add(). */ static void ata_tdev_free(struct ata_device *dev) { From patchwork Mon Aug 26 07:31:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ImziCe2d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-2141-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj5y0BpMz1yfF for ; Mon, 26 Aug 2024 17:31:17 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7C73CB225C0 for ; Mon, 26 Aug 2024 07:31:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B391182490; Mon, 26 Aug 2024 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ImziCe2d" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69A036F2F6 for ; Mon, 26 Aug 2024 07:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657470; cv=none; b=DPUM9x2PSoA8Ua0V11c6hiV3UTe5iaS9Ojgt2bh8dylxlc5yzwZFlI+chcORRmUChdtioFWVQ1Uoa6ojsJQuHwMgC466WKAXwj7Qrg3Z1kSNLSLXQtLiB8JDOcmRu1KQ70uJ1QA6STk07fTyj3xk7dGHSbxuyU10F+2LmyooJZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657470; c=relaxed/simple; bh=ADFZOZJN+o/waq/964U0BBdgXy/hajbQBjs+rgTvbqY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DlEmo8M864VdvwMhiz1wIZrIyBDLfaRBvTal0h8U4L3L1vSgbfB8gJIYocxcqcG3YD1eyG4RIToVmST8fFXt+2PtCDHKB6CZRGZGJbhDOhlQSn+PaTR0wyeI3JfyKcqbCzsw3yEWv7p7JihTUvwya+uizbwgs1nWq2eisGH69Xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ImziCe2d; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C542CC8CDC5; Mon, 26 Aug 2024 07:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657469; bh=ADFZOZJN+o/waq/964U0BBdgXy/hajbQBjs+rgTvbqY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ImziCe2dyiUrHIpJTdTj8paAOaRDuJ/339AvNFDVwC6eisc2piT3Kk5ZZ483Ob2WD if0xish7BjnyDjzu2ua7h1cj/0N7Cd2tbawF3TEOWny/OKVpWTV04lXBtGbLhhl0ox q86vw1DoRIfzz8wDhc8d0IUksUagJbY42u3trwZkYiBDIYJXUC6Biq5nXtNK+1Q4Ua WqPlTxHfwffNJOqiz3qbnMI+0pYyigAdJKUQgCnVdRD2ZHGUvUVNE6e0zZyF7Wh1SO PXw73keV7k6vUa6/tb33UM/+oH5uXyfvcGKH22hxoD/I7QOJwE7Z1zHc5kWoHpl6X6 vqrW49t9JDmKA== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 2/7] ata: libata: Improve __ata_qc_complete() Date: Mon, 26 Aug 2024 16:31:01 +0900 Message-ID: <20240826073106.56918-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function __ata_qc_complete() is always called with a qc that already has been dereferenced and so is guaranteed to be non-NULL (as otherwise the kernel would have crashed). So remove the warning for a NULL qc as it is useless. Furthermore, the qc passed to __ata_qc_complete() must always be marked as active with the ATA_QCFLAG_ACTIVE flag. If that is not the case, in addition to the existing warning, return early so that we do not attempt to complete an invalid qc. Finally, fix the comment related to clearing the qc active flag as that operation applies to all devices, not just ATAPI ones. Signed-off-by: Damien Le Moal Reviewed-by: Niklas Cassel --- drivers/ata/libata-core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index e4023fc288ac..5acc37397f4b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -4829,8 +4829,9 @@ void __ata_qc_complete(struct ata_queued_cmd *qc) struct ata_port *ap; struct ata_link *link; - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ - WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); + if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE))) + return; + ap = qc->ap; link = qc->dev->link; @@ -4852,9 +4853,10 @@ void __ata_qc_complete(struct ata_queued_cmd *qc) ap->excl_link == link)) ap->excl_link = NULL; - /* atapi: mark qc as inactive to prevent the interrupt handler - * from completing the command twice later, before the error handler - * is called. (when rc != 0 and atapi request sense is needed) + /* + * Mark qc as inactive to prevent the port interrupt handler from + * completing the command twice later, before the error handler is + * called. */ qc->flags &= ~ATA_QCFLAG_ACTIVE; ap->qc_active &= ~(1ULL << qc->tag); From patchwork Mon Aug 26 07:31:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976672 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=HsH8c2Rb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-2143-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj5z4Skfz1yXd for ; Mon, 26 Aug 2024 17:31:19 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C30C91C212C2 for ; Mon, 26 Aug 2024 07:31:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38F94135A63; Mon, 26 Aug 2024 07:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HsH8c2Rb" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDE09339AB for ; Mon, 26 Aug 2024 07:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657471; cv=none; b=guHXU3c3SvOU3QHsJFl5BNDGCftMh2GA/PmozlCWwCMB+AQkYblfv2XoTjycFCogUwz7NG3mZ+dq7uI7n9gkTn/T26qfgudQpaB8QunwJ8cMekxvCuy6YLR5n7HazBbJVFd4N27Nv8v3TQXGLlzNrxNFm0CZZJwEk9xhxVAvN/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657471; c=relaxed/simple; bh=cg0GUS1dbsv+RbdVSWlvtGhkD9sN/cJLBy067OcNHpI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L/aQ8OyFAZtmZyz26RXHzGcGZhoyjtpVtZBEbZpKMyQJTliXvOb62NaP5YuAJd45LI9TNnLW7k1LVe3zCYr5LvZriZECja281ptIzjXVE5l6pNGcZ+OdaTw4nWAS0leGWuh3MdPBuXWy2dJlroVaON7KE9uzayDMQI1V0/4oZhs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HsH8c2Rb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D402C8CDC3; Mon, 26 Aug 2024 07:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657469; bh=cg0GUS1dbsv+RbdVSWlvtGhkD9sN/cJLBy067OcNHpI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HsH8c2Rbnk2w+CBOzRYrSDA9ZmMV1PfSY45XbUbT8NY54JHQJ3cu1MJ8a4OBU9F8U i6HTkI50QDVu8qYti4kXAr6Tv+U1S+tSpmAKOMWEdss1GNPJhJBj93vbFleVJIDagl ZLC+5KXvzWMDXk97MLbxyI5F+dDbSaW1oCkWzRBKIwTFuM2mFAcxZJFMpwAiITmABg TkAIS+CRYTnQgJM/c6Xjfri+0jgK7uW1rUnQcEbcssSDy8PcNPtThipfjhlsxY0VSI 8wp2w28PsP7sVW+x7jqpD+vu43bzwmsqUYIxgqIu3stv3+t8vAFhFFmwqrUwOGZoVK 2eAmcGPwTfQgA== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 3/7] ata: libata: Move sata_down_spd_limit() to libata-sata.c Date: Mon, 26 Aug 2024 16:31:02 +0900 Message-ID: <20240826073106.56918-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the definition of the function sata_down_spd_limit() to libata-sata.c where it belongs, together with sata_set_spd(). The helper function ata_sstatus_online() is also changed to be an inline function defined in drivers/ata/libata.h. Signed-off-by: Damien Le Moal Reviewed-by: Niklas Cassel --- drivers/ata/libata-core.c | 85 --------------------------------------- drivers/ata/libata-sata.c | 80 ++++++++++++++++++++++++++++++++++++ drivers/ata/libata.h | 17 +++++++- 3 files changed, 96 insertions(+), 86 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 5acc37397f4b..b957eb900a00 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -167,11 +167,6 @@ static inline bool ata_dev_print_info(const struct ata_device *dev) return ehc->i.flags & ATA_EHI_PRINTINFO; } -static bool ata_sstatus_online(u32 sstatus) -{ - return (sstatus & 0xf) == 0x3; -} - /** * ata_link_next - link iteration helper * @link: the previous link, NULL to start @@ -3200,86 +3195,6 @@ struct ata_device *ata_dev_pair(struct ata_device *adev) } EXPORT_SYMBOL_GPL(ata_dev_pair); -/** - * sata_down_spd_limit - adjust SATA spd limit downward - * @link: Link to adjust SATA spd limit for - * @spd_limit: Additional limit - * - * Adjust SATA spd limit of @link downward. Note that this - * function only adjusts the limit. The change must be applied - * using sata_set_spd(). - * - * If @spd_limit is non-zero, the speed is limited to equal to or - * lower than @spd_limit if such speed is supported. If - * @spd_limit is slower than any supported speed, only the lowest - * supported speed is allowed. - * - * LOCKING: - * Inherited from caller. - * - * RETURNS: - * 0 on success, negative errno on failure - */ -int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) -{ - u32 sstatus, spd, mask; - int rc, bit; - - if (!sata_scr_valid(link)) - return -EOPNOTSUPP; - - /* If SCR can be read, use it to determine the current SPD. - * If not, use cached value in link->sata_spd. - */ - rc = sata_scr_read(link, SCR_STATUS, &sstatus); - if (rc == 0 && ata_sstatus_online(sstatus)) - spd = (sstatus >> 4) & 0xf; - else - spd = link->sata_spd; - - mask = link->sata_spd_limit; - if (mask <= 1) - return -EINVAL; - - /* unconditionally mask off the highest bit */ - bit = fls(mask) - 1; - mask &= ~(1 << bit); - - /* - * Mask off all speeds higher than or equal to the current one. At - * this point, if current SPD is not available and we previously - * recorded the link speed from SStatus, the driver has already - * masked off the highest bit so mask should already be 1 or 0. - * Otherwise, we should not force 1.5Gbps on a link where we have - * not previously recorded speed from SStatus. Just return in this - * case. - */ - if (spd > 1) - mask &= (1 << (spd - 1)) - 1; - else if (link->sata_spd) - return -EINVAL; - - /* were we already at the bottom? */ - if (!mask) - return -EINVAL; - - if (spd_limit) { - if (mask & ((1 << spd_limit) - 1)) - mask &= (1 << spd_limit) - 1; - else { - bit = ffs(mask) - 1; - mask = 1 << bit; - } - } - - link->sata_spd_limit = mask; - - ata_link_warn(link, "limiting SATA link speed to %s\n", - sata_spd_string(fls(mask))); - - return 0; -} - #ifdef CONFIG_ATA_ACPI /** * ata_timing_cycle2mode - find xfer mode for the specified cycle duration diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index ecd37649d4d4..549377b82670 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -517,6 +517,86 @@ int sata_set_spd(struct ata_link *link) } EXPORT_SYMBOL_GPL(sata_set_spd); +/** + * sata_down_spd_limit - adjust SATA spd limit downward + * @link: Link to adjust SATA spd limit for + * @spd_limit: Additional limit + * + * Adjust SATA spd limit of @link downward. Note that this + * function only adjusts the limit. The change must be applied + * using sata_set_spd(). + * + * If @spd_limit is non-zero, the speed is limited to equal to or + * lower than @spd_limit if such speed is supported. If + * @spd_limit is slower than any supported speed, only the lowest + * supported speed is allowed. + * + * LOCKING: + * Inherited from caller. + * + * RETURNS: + * 0 on success, negative errno on failure + */ +int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) +{ + u32 sstatus, spd, mask; + int rc, bit; + + if (!sata_scr_valid(link)) + return -EOPNOTSUPP; + + /* If SCR can be read, use it to determine the current SPD. + * If not, use cached value in link->sata_spd. + */ + rc = sata_scr_read(link, SCR_STATUS, &sstatus); + if (rc == 0 && ata_sstatus_online(sstatus)) + spd = (sstatus >> 4) & 0xf; + else + spd = link->sata_spd; + + mask = link->sata_spd_limit; + if (mask <= 1) + return -EINVAL; + + /* unconditionally mask off the highest bit */ + bit = fls(mask) - 1; + mask &= ~(1 << bit); + + /* + * Mask off all speeds higher than or equal to the current one. At + * this point, if current SPD is not available and we previously + * recorded the link speed from SStatus, the driver has already + * masked off the highest bit so mask should already be 1 or 0. + * Otherwise, we should not force 1.5Gbps on a link where we have + * not previously recorded speed from SStatus. Just return in this + * case. + */ + if (spd > 1) + mask &= (1 << (spd - 1)) - 1; + else if (link->sata_spd) + return -EINVAL; + + /* were we already at the bottom? */ + if (!mask) + return -EINVAL; + + if (spd_limit) { + if (mask & ((1 << spd_limit) - 1)) + mask &= (1 << spd_limit) - 1; + else { + bit = ffs(mask) - 1; + mask = 1 << bit; + } + } + + link->sata_spd_limit = mask; + + ata_link_warn(link, "limiting SATA link speed to %s\n", + sata_spd_string(fls(mask))); + + return 0; +} + /** * sata_link_hardreset - reset link via SATA phy reset * @link: link to reset diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 6abf265f626e..eda2d5dfd234 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -38,6 +38,12 @@ extern int libata_noacpi; extern int libata_allow_tpm; extern const struct device_type ata_port_type; extern struct ata_link *ata_dev_phys_link(struct ata_device *dev); + +static inline bool ata_sstatus_online(u32 sstatus) +{ + return (sstatus & 0xf) == 0x3; +} + #ifdef CONFIG_ATA_FORCE extern void ata_force_cbl(struct ata_port *ap); #else @@ -65,7 +71,6 @@ extern bool ata_dev_power_init_tf(struct ata_device *dev, struct ata_taskfile *tf, bool set_active); extern void ata_dev_power_set_standby(struct ata_device *dev); extern void ata_dev_power_set_active(struct ata_device *dev); -extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); extern unsigned int ata_dev_set_feature(struct ata_device *dev, u8 subcmd, u8 action); @@ -87,6 +92,16 @@ extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log, #define to_ata_port(d) container_of(d, struct ata_port, tdev) +/* libata-sata.c */ +#ifdef CONFIG_SATA_HOST +int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); +#else +static inline int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) +{ + return -EOPNOTSUPP; +} +#endif + /* libata-acpi.c */ #ifdef CONFIG_ATA_ACPI extern unsigned int ata_acpi_gtf_filter; From patchwork Mon Aug 26 07:31:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=o+La4PQC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-2142-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj5y49Vsz1yfF for ; Mon, 26 Aug 2024 17:31:18 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2590EB21BA9 for ; Mon, 26 Aug 2024 07:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3FD013211C; Mon, 26 Aug 2024 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o+La4PQC" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6774131E4B for ; Mon, 26 Aug 2024 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657470; cv=none; b=VD7o5wNprIEKqTAEZl+ogJZNYtUZ9UwMB2HzlNz7OlaHTDakVxy0NL14H7rfiDx3QCrkGALG4rsu91EfILCTrdCrj8tw/M1fmPKY4MI4Tnf7riEqodZmy69BBzbr6buGGQd4FdUTvDSfDiGSbqaMUTD9Gz0BY66rnj3yTcFVKpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657470; c=relaxed/simple; bh=jU9nreu4bp9n9GnpJBAFSuPiWZ5fbi8Ds6kcMojZ1UQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uchDu/OtgAuJ/bvEdnDlpjVGoG/VlRxqfzEdHMTNOm0ek6wvrNt0+TpDfYbHWvbvQ7ydr3IBffHkQIX9f3QrnFwbTjOQGne8sK7+SyNSe8tHBAWWUB0BWI+EDe45PmvEG3+YROTukm0/WXX5A73EUaHqjvu9swp9LqghRJ2lKbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o+La4PQC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D87DC8CDC1; Mon, 26 Aug 2024 07:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657470; bh=jU9nreu4bp9n9GnpJBAFSuPiWZ5fbi8Ds6kcMojZ1UQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=o+La4PQC3J2Y+ThG+1s/WQTeYse1lKy/Xa0Y1gv3YJV7goNSLeUGWZxj8yT2H6C3R VvJiIGsL/YviC4CIan6ESSpK3hHLYnhoE0QkviOAkMgQxzympbEyVxB8zEJ3Tr3y2a Ku9YkIwokG7tzOTAg+W6DYWtbRPXlr6rbKJWhN7K2lcv9OP5TGnUYCSTGCNbZII9ib 2z/jBARHgLpwELnlykk8ByPU1MRHDGJUYbEeAMoSXz1jzJOPbVRxlgODUMOvANzGUL n+k0X+woff2M10GWYtkc4AvueRrCX1NPsH2y6R2+HerK4oM83QRTB3bg0C+NrYjsWK n0/DPBiDLMecQ== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 4/7] ata: libata: Move sata_std_hardreset() definition to libata-sata.c Date: Mon, 26 Aug 2024 16:31:03 +0900 Message-ID: <20240826073106.56918-5-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unlike ata_std_prereset() and ata_std_postreset(), the function sata_std_hardreset() applies only to SATA devices, as its name implies. So move its definition to libata-sata.c. Together with this, also move the definition of sata_port_ops to libata-sata.c, where it belongs. Signed-off-by: Damien Le Moal Reviewed-by: Niklas Cassel --- drivers/ata/libata-core.c | 35 ----------------------------------- drivers/ata/libata-sata.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 9 +++++++-- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b957eb900a00..b5a051bbb01f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -72,14 +72,6 @@ const struct ata_port_operations ata_base_port_ops = { .end_eh = ata_std_end_eh, }; -const struct ata_port_operations sata_port_ops = { - .inherits = &ata_base_port_ops, - - .qc_defer = ata_std_qc_defer, - .hardreset = sata_std_hardreset, -}; -EXPORT_SYMBOL_GPL(sata_port_ops); - static unsigned int ata_dev_init_params(struct ata_device *dev, u16 heads, u16 sectors); static unsigned int ata_dev_set_xfermode(struct ata_device *dev); @@ -3676,33 +3668,6 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline) } EXPORT_SYMBOL_GPL(ata_std_prereset); -/** - * sata_std_hardreset - COMRESET w/o waiting or classification - * @link: link to reset - * @class: resulting class of attached device - * @deadline: deadline jiffies for the operation - * - * Standard SATA COMRESET w/o waiting or classification. - * - * LOCKING: - * Kernel thread context (may sleep) - * - * RETURNS: - * 0 if link offline, -EAGAIN if link online, -errno on errors. - */ -int sata_std_hardreset(struct ata_link *link, unsigned int *class, - unsigned long deadline) -{ - const unsigned int *timing = sata_ehc_deb_timing(&link->eh_context); - bool online; - int rc; - - /* do hardreset */ - rc = sata_link_hardreset(link, timing, deadline, &online, NULL); - return online ? -EAGAIN : rc; -} -EXPORT_SYMBOL_GPL(sata_std_hardreset); - /** * ata_std_postreset - standard postreset callback * @link: the target ata_link diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 549377b82670..286b5699dafd 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -706,6 +706,34 @@ int sata_link_hardreset(struct ata_link *link, const unsigned int *timing, } EXPORT_SYMBOL_GPL(sata_link_hardreset); +/** + * sata_std_hardreset - COMRESET w/o waiting or classification + * @link: link to reset + * @class: resulting class of attached device + * @deadline: deadline jiffies for the operation + * + * Standard SATA COMRESET w/o waiting or classification. + * + * LOCKING: + * Kernel thread context (may sleep) + * + * RETURNS: + * 0 if link offline, -EAGAIN if link online, -errno on errors. + */ +int sata_std_hardreset(struct ata_link *link, unsigned int *class, + unsigned long deadline) +{ + const unsigned int *timing = sata_ehc_deb_timing(&link->eh_context); + bool online; + int rc; + + rc = sata_link_hardreset(link, timing, deadline, &online, NULL); + if (online) + return -EAGAIN; + return rc; +} +EXPORT_SYMBOL_GPL(sata_std_hardreset); + /** * ata_qc_complete_multiple - Complete multiple qcs successfully * @ap: port in question @@ -1656,3 +1684,11 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) ehc->i.err_mask &= ~AC_ERR_DEV; } EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error); + +const struct ata_port_operations sata_port_ops = { + .inherits = &ata_base_port_ops, + + .qc_defer = ata_std_qc_defer, + .hardreset = sata_std_hardreset, +}; +EXPORT_SYMBOL_GPL(sata_port_ops); diff --git a/include/linux/libata.h b/include/linux/libata.h index 0279c0a6302f..46e35acc611c 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1104,8 +1104,6 @@ static inline bool ata_port_is_frozen(const struct ata_port *ap) extern int ata_std_prereset(struct ata_link *link, unsigned long deadline); extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, int (*check_ready)(struct ata_link *link)); -extern int sata_std_hardreset(struct ata_link *link, unsigned int *class, - unsigned long deadline); extern void ata_std_postreset(struct ata_link *link, unsigned int *classes); extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports); @@ -1229,6 +1227,8 @@ extern int sata_scr_read(struct ata_link *link, int reg, u32 *val); extern int sata_scr_write(struct ata_link *link, int reg, u32 val); extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val); extern int sata_set_spd(struct ata_link *link); +int sata_std_hardreset(struct ata_link *link, unsigned int *class, + unsigned long deadline); extern int sata_link_hardreset(struct ata_link *link, const unsigned int *timing, unsigned long deadline, bool *online, int (*check_ready)(struct ata_link *)); @@ -1256,6 +1256,11 @@ static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val) return -EOPNOTSUPP; } static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; } +static inline int sata_std_hardreset(struct ata_link *link, unsigned int *class, + unsigned long deadline) +{ + return -EOPNOTSUPP; +} static inline int sata_link_hardreset(struct ata_link *link, const unsigned int *timing, unsigned long deadline, From patchwork Mon Aug 26 07:31:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=rUgACtan; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-2144-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj605kB5z1yXd for ; Mon, 26 Aug 2024 17:31:20 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7DE791C20356 for ; Mon, 26 Aug 2024 07:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA25513774B; Mon, 26 Aug 2024 07:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rUgACtan" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8E63136671 for ; Mon, 26 Aug 2024 07:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657471; cv=none; b=rKRqSDhKUwdhVbIfI13H6AUxgHkZyNXYxl7hAV3O9NPOH63SgKb4qxHSzJ5cTFH9wAU476VEq6obri0vrTUYCb13CiVIkE9YKFZ4QNPnt/vogxfSky2ODYy34m9P4rKyzVaCZzki9pqnKvcppG6JdRBj8uKiQmAA/F8/TzMYWE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657471; c=relaxed/simple; bh=Je4YOLLz8VpI5+9LbwLXm0VwJcqvz+f3N875tXulX7k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L/q52v1OYEQPlgAu59+yeqNeaWipxXyiI3YjBOhBeIQAvdD+o9xjYWLUD1i1fxXOrdEZhCmQER5+WXEW9qtDVPVPfGOkbn7tk9ulXNiFuwoLVmP6M8c/3dof1kV1Ll6tD99lFvEq5mZROziSG6Onsc8L+8lJZeewG86YFQJREM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rUgACtan; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D33A8C8CDC5; Mon, 26 Aug 2024 07:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657471; bh=Je4YOLLz8VpI5+9LbwLXm0VwJcqvz+f3N875tXulX7k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rUgACtanuXEqso35hRkBtlCZEm70eCXDpttrVQ/zXdbny6NDvvbpPGx3Gz32wh8a1 JwPKm5bk9cKXFA4YzrXLTlcmFyCLoNHJc8Ic+qSAiF8VuBMq8wrSXpq3IxF9lSVDWG VsO3aiSw72BLOjk7+rMFpVyUNu5BmpzN5RtnQyLuEwgh5LYFTx3MI4Pwox95qdx2O3 HKr2BoE2sa5RuriV8BPcUCf4AnPsuRs666p5AYCpzfS+9NRkjYWEklJVjbkVsQfDpH AziYhjIg3oYpBu1io7VDotuYbNJnTukqWp0dXqi5VZhfVp3EXheV0yKikY+8izrgX6 aikfXtBkl2D/w== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 5/7] ata: libata: Rename ata_eh_read_sense_success_ncq_log() Date: Mon, 26 Aug 2024 16:31:04 +0900 Message-ID: <20240826073106.56918-6-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function ata_eh_read_sense_success_ncq_log() does more that just reading the sense data for successful NCQ commands log page as it also sets the sense data for all commands listed in the log page. Rename this function to ata_eh_get_ncq_success_sense() to better describe what the function does. Furthermore, since this function is only called from ata_eh_get_success_sense() in libata-eh.c, there is no need to export it and its declaration can be moved to drivers/ata/libata.h. To be consistent with this change, the function ata_eh_read_sense_success_non_ncq() is also renamed to ata_eh_get_non_ncq_success_sense(). Signed-off-by: Damien Le Moal Reviewed-by: Niklas Cassel --- drivers/ata/libata-eh.c | 6 +++--- drivers/ata/libata-sata.c | 7 +++---- drivers/ata/libata.h | 5 +++++ include/linux/libata.h | 5 ----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 214b935c2ced..107aad2a1af5 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1924,7 +1924,7 @@ static inline bool ata_eh_quiet(struct ata_queued_cmd *qc) return qc->flags & ATA_QCFLAG_QUIET; } -static int ata_eh_read_sense_success_non_ncq(struct ata_link *link) +static int ata_eh_get_non_ncq_success_sense(struct ata_link *link) { struct ata_port *ap = link->ap; struct ata_queued_cmd *qc; @@ -1976,9 +1976,9 @@ static void ata_eh_get_success_sense(struct ata_link *link) * request sense ext command to retrieve the sense data. */ if (link->sactive) - ret = ata_eh_read_sense_success_ncq_log(link); + ret = ata_eh_get_ncq_success_sense(link); else - ret = ata_eh_read_sense_success_non_ncq(link); + ret = ata_eh_get_non_ncq_success_sense(link); if (ret) goto out; diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 286b5699dafd..020893da900d 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1487,8 +1487,8 @@ static int ata_eh_read_log_10h(struct ata_device *dev, } /** - * ata_eh_read_sense_success_ncq_log - Read the sense data for successful - * NCQ commands log + * ata_eh_get_ncq_success_sense - Read and process the sense data for + * successful NCQ commands log page * @link: ATA link to get sense data for * * Read the sense data for successful NCQ commands log page to obtain @@ -1501,7 +1501,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev, * RETURNS: * 0 on success, -errno otherwise. */ -int ata_eh_read_sense_success_ncq_log(struct ata_link *link) +int ata_eh_get_ncq_success_sense(struct ata_link *link) { struct ata_device *dev = link->device; struct ata_port *ap = dev->link->ap; @@ -1573,7 +1573,6 @@ int ata_eh_read_sense_success_ncq_log(struct ata_link *link) return ret; } -EXPORT_SYMBOL_GPL(ata_eh_read_sense_success_ncq_log); /** * ata_eh_analyze_ncq_error - analyze NCQ error diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index eda2d5dfd234..5ca17784a350 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -95,11 +95,16 @@ extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log, /* libata-sata.c */ #ifdef CONFIG_SATA_HOST int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); +int ata_eh_get_ncq_success_sense(struct ata_link *link); #else static inline int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) { return -EOPNOTSUPP; } +static inline int ata_eh_get_ncq_success_sense(struct ata_link *link) +{ + return -EOPNOTSUPP; +} #endif /* libata-acpi.c */ diff --git a/include/linux/libata.h b/include/linux/libata.h index 46e35acc611c..e07a9b5d45df 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1234,7 +1234,6 @@ extern int sata_link_hardreset(struct ata_link *link, bool *online, int (*check_ready)(struct ata_link *)); extern int sata_link_resume(struct ata_link *link, const unsigned int *params, unsigned long deadline); -extern int ata_eh_read_sense_success_ncq_log(struct ata_link *link); extern void ata_eh_analyze_ncq_error(struct ata_link *link); #else static inline const unsigned int * @@ -1277,10 +1276,6 @@ static inline int sata_link_resume(struct ata_link *link, { return -EOPNOTSUPP; } -static inline int ata_eh_read_sense_success_ncq_log(struct ata_link *link) -{ - return -EOPNOTSUPP; -} static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { } #endif extern int sata_link_debounce(struct ata_link *link, From patchwork Mon Aug 26 07:31:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976674 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Ob2T2oI4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ide+bounces-2145-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj606zCWz1yfF for ; Mon, 26 Aug 2024 17:31:20 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E2A402892FC for ; Mon, 26 Aug 2024 07:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55A7413777F; Mon, 26 Aug 2024 07:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ob2T2oI4" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13FEC136671 for ; Mon, 26 Aug 2024 07:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657472; cv=none; b=n/D3fvkKbVgtykjx4HW1c0mF5ihy1bAJ3kVpnLheuvq1uGMFliEu0HuenKdB6E2rZxImp0OSpTXXLmiISnUpr0pMBMVlx1VD4+IIvykp6SvVmjDkGdlKMnYnhh3XbguC6Gb5gVHwzSalse6w2hvpTHpDpzfZABMMWZFhVQqxoXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657472; c=relaxed/simple; bh=pOp3VQtjrm2eHf4OQPtuColveo4cfiRiUSwAvoEyqsw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RIdQgBVpvinpeP4+GbaqXhp3tce1wOsF/d4xEl9sHpE4g9jfXZlEN0SavaGmEkBDlS9VPwtadFpH9zGf58zGoMzwfgw0rAg3OkCWdyxOnbP2ntGQH95DzKQM0DduNBfzv3zPeffPR332Llzy3Nas6L5Zc/5hZgfOBJ7BUGHN1xs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ob2T2oI4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84F4AC8CDC4; Mon, 26 Aug 2024 07:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657471; bh=pOp3VQtjrm2eHf4OQPtuColveo4cfiRiUSwAvoEyqsw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ob2T2oI4zCtOCqn6dj8/27o3TDdVBNPkf3OEMjuVRhWwtkn6tzvbVsxKT4avQH2b8 0R6LHKdO6T37SMfMhFGVaNI4zbQDMJSs43t8zdII2Wky3YEYyytVWT5CDChpPRy9d5 jPxtmNAwhsTyVLm6fQ49RTVDOQKqWXYP3hRjk+a2ErWL6igK8ua/SprM9IAfThUOAl uYFyRKh5JzsyrIvrR7BOldipv+1msLfA1tLCrwfel7UjeiEm+RfwOLTa8jTrwXWupy rk6S7osui3dfqtJzabjfamwKMLBaq3Hzq6Rq1rrWFxxTOLTrLAvqrlEpYUDvyIwrb4 Kwt8kax7ktWHQ== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 6/7] ata: libata: Move ncq_sense_buf to struct ata_device Date: Mon, 26 Aug 2024 16:31:05 +0900 Message-ID: <20240826073106.56918-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The ncq_sense_buf buffer field of struct ata_port is allocated and used only for devices that support command duration limits. So move this field out of struct ata_port and into struct ata_device together with the CDL log buffer. Signed-off-by: Damien Le Moal --- drivers/ata/libata-core.c | 11 +++++------ drivers/ata/libata-sata.c | 2 +- drivers/ata/libata-transport.c | 3 +++ include/linux/libata.h | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b5a051bbb01f..6a1d300dd1f5 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2581,9 +2581,9 @@ static void ata_dev_config_cdl(struct ata_device *dev) * policy set to 0xD (successful completion with sense data available * bit set). */ - if (!ap->ncq_sense_buf) { - ap->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); - if (!ap->ncq_sense_buf) + if (!dev->ncq_sense_buf) { + dev->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); + if (!dev->ncq_sense_buf) goto not_supported; } @@ -2604,8 +2604,8 @@ static void ata_dev_config_cdl(struct ata_device *dev) not_supported: dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); - kfree(ap->ncq_sense_buf); - ap->ncq_sense_buf = NULL; + kfree(dev->ncq_sense_buf); + dev->ncq_sense_buf = NULL; } static int ata_dev_config_lba(struct ata_device *dev) @@ -5462,7 +5462,6 @@ void ata_port_free(struct ata_port *ap) kfree(ap->pmp_link); kfree(ap->slave_link); - kfree(ap->ncq_sense_buf); ida_free(&ata_ida, ap->print_id); kfree(ap); } diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 020893da900d..50ea254a213d 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1505,7 +1505,7 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link) { struct ata_device *dev = link->device; struct ata_port *ap = dev->link->ap; - u8 *buf = ap->ncq_sense_buf; + u8 *buf = dev->ncq_sense_buf; struct ata_queued_cmd *qc; unsigned int err_mask, tag; u8 *sense, sk = 0, asc = 0, ascq = 0; diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index 474816a9efa1..14f50c91ceb9 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -671,6 +671,9 @@ static int ata_tdev_match(struct attribute_container *cont, */ static void ata_tdev_free(struct ata_device *dev) { + kfree(dev->ncq_sense_buf); + dev->ncq_sense_buf = NULL; + transport_destroy_device(&dev->tdev); put_device(&dev->tdev); } diff --git a/include/linux/libata.h b/include/linux/libata.h index e07a9b5d45df..3fb6980c8aa1 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -762,7 +762,8 @@ struct ata_device { /* Concurrent positioning ranges */ struct ata_cpr_log *cpr_log; - /* Command Duration Limits log support */ + /* Command Duration Limits support */ + u8 *ncq_sense_buf; u8 cdl[ATA_LOG_CDL_SIZE]; /* error history */ @@ -915,7 +916,6 @@ struct ata_port { struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ #endif /* owned by EH */ - u8 *ncq_sense_buf; u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned; }; From patchwork Mon Aug 26 07:31:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1976675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=U8B3tf+X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-2146-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj6151Mxz1yfr for ; Mon, 26 Aug 2024 17:31:21 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D66AC1C2034E for ; Mon, 26 Aug 2024 07:31:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0431137905; Mon, 26 Aug 2024 07:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U8B3tf+X" X-Original-To: linux-ide@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B048A136671 for ; Mon, 26 Aug 2024 07:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657472; cv=none; b=BWqD7A0IR2tT6yMY88d+695WNfgM4qKiEcP6iwouSAr7mTwq89PU9Zb3glB/hx8jhXZYd60yxwJ6iKIoI+/gqiOQPtz/bKpOxrV/6C7rg0p7hXmO326qaIGmzirs7vmy/erZ3EX1D2Whan/MywVOvhWE/gZo022er7QMPJRPtzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724657472; c=relaxed/simple; bh=VQeLVRCwCccMNRuqGa7+mLUZJRGvSpjRkR8FZPdc83k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ORESTPeb1mw3w2sbr0ZalzPKN05FQPLlm6NOakgGjHiZqsy7YKt33HLY7Z3VGwKZef9wBSC8Ta8rZGgXqrwoZE+9Di+Hhx2ykYIfASKNH60iJiK2IqfsNaD4HWGGCBPBd5lpB3NkW6pPrHJB2P5jPC+UJetPq8TGFoOSBkbeiSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U8B3tf+X; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39DD3C8CDC1; Mon, 26 Aug 2024 07:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724657472; bh=VQeLVRCwCccMNRuqGa7+mLUZJRGvSpjRkR8FZPdc83k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U8B3tf+XjtqjjkK6rRLS4DvznZ9qMFIDzIlYe16/GKSvGDrngpjN9Vx0r0CTu0dej QBIXUDnqklGo6lLeHm9wAgJclI3XZF833ZajXw59U8P8IPRwrbp9Yruk9PQT0Qwomi LA55bJ7IQC+HqYdi/cqUdfH/gmXeQKG675B2vv6xgPfK6gP7WchB2UIlLCP1LM4cxu WxxST5DguFrUFz4zDqeSt0X6Hp52r0nSiGu7Ic2CZkrUCAvm2z7Z76am1X0YG6huyv FUdTLJWa9v70pMfjVj/Nq1uue8qcacj1glKpmxcwiE8Bhlh8oupbG+X6d2DdGCEPyg HMWqdvParu/Dg== From: Damien Le Moal To: linux-ide@vger.kernel.org, Niklas Cassel Subject: [PATCH 7/7] ata: libata: Improve CDL resource management Date: Mon, 26 Aug 2024 16:31:06 +0900 Message-ID: <20240826073106.56918-8-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826073106.56918-1-dlemoal@kernel.org> References: <20240826073106.56918-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The command duration limits (CDL) log buffer of struct ata_device is needed only if a device actually supports CDL. The same applies to the ncq_sense_log buffer. Group these 2 buffers into a new structure ata_cdl defining both buffers as embedded buffers (no allocation needed) and allocate this structure from ata_dev_config_cdl() only for devices that support CDL. The functions ata_dev_init_cdl_resources() and ata_dev_cleanup_cdl_resources() are defined to manage this new structure allocation, initialization and cleanup when a device is removed. ata_dev_cleanup_cdl_resources() is called from ata_tdev_free(). Note that the cdl log buffer name is changed to desc_log_buf to make it clearer what it is. This change reduces the size of struct ata_device and reduces memory usage for ATA devices that do not support CDL. Signed-off-by: Damien Le Moal --- drivers/ata/libata-core.c | 56 +++++++++++++++++++++------------- drivers/ata/libata-sata.c | 2 +- drivers/ata/libata-scsi.c | 2 +- drivers/ata/libata-transport.c | 4 +-- drivers/ata/libata.h | 1 + include/linux/libata.h | 18 +++++++++-- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 6a1d300dd1f5..bcee96e29b34 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2475,12 +2475,41 @@ static void ata_dev_config_trusted(struct ata_device *dev) dev->flags |= ATA_DFLAG_TRUSTED; } +static int ata_dev_init_cdl_resources(struct ata_device *dev) +{ + struct ata_cdl *cdl = dev->cdl; + unsigned int err_mask; + + if (!cdl) { + cdl = kzalloc(sizeof(struct ata_cdl), GFP_KERNEL); + if (!cdl) + return -ENOMEM; + dev->cdl = cdl; + } + + err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, cdl->desc_log_buf, + ATA_LOG_CDL_SIZE / ATA_SECT_SIZE); + if (err_mask) { + ata_dev_warn(dev, "Read Command Duration Limits log failed\n"); + return -EIO; + } + + return 0; +} + +void ata_dev_cleanup_cdl_resources(struct ata_device *dev) +{ + kfree(dev->cdl); + dev->cdl = NULL; +} + static void ata_dev_config_cdl(struct ata_device *dev) { struct ata_port *ap = dev->link->ap; unsigned int err_mask; bool cdl_enabled; u64 val; + int ret; if (ata_id_major_version(dev->id) < 11) goto not_supported; @@ -2575,37 +2604,20 @@ static void ata_dev_config_cdl(struct ata_device *dev) } } - /* - * Allocate a buffer to handle reading the sense data for successful - * NCQ Commands log page for commands using a CDL with one of the limit - * policy set to 0xD (successful completion with sense data available - * bit set). - */ - if (!dev->ncq_sense_buf) { - dev->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); - if (!dev->ncq_sense_buf) - goto not_supported; - } - - /* - * Command duration limits is supported: cache the CDL log page 18h - * (command duration descriptors). - */ - err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1); - if (err_mask) { - ata_dev_warn(dev, "Read Command Duration Limits log failed\n"); + /* CDL is supported: allocate and initialize needed resources. */ + ret = ata_dev_init_cdl_resources(dev); + if (ret) { + ata_dev_warn(dev, "Initialize CDL resources failed\n"); goto not_supported; } - memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE); dev->flags |= ATA_DFLAG_CDL; return; not_supported: dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); - kfree(dev->ncq_sense_buf); - dev->ncq_sense_buf = NULL; + ata_dev_cleanup_cdl_resources(dev); } static int ata_dev_config_lba(struct ata_device *dev) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 50ea254a213d..e05fb09af061 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1505,7 +1505,7 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link) { struct ata_device *dev = link->device; struct ata_port *ap = dev->link->ap; - u8 *buf = dev->ncq_sense_buf; + u8 *buf = dev->cdl->ncq_sense_log_buf; struct ata_queued_cmd *qc; unsigned int err_mask, tag; u8 *sense, sk = 0, asc = 0, ascq = 0; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a3ffce4b218d..7fed924d6561 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2259,7 +2259,7 @@ static inline u16 ata_xlat_cdl_limit(u8 *buf) static unsigned int ata_msense_control_spgt2(struct ata_device *dev, u8 *buf, u8 spg) { - u8 *b, *cdl = dev->cdl, *desc; + u8 *b, *cdl = dev->cdl->desc_log_buf, *desc; u32 policy; int i; diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index 14f50c91ceb9..add230c0d51e 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -671,9 +671,7 @@ static int ata_tdev_match(struct attribute_container *cont, */ static void ata_tdev_free(struct ata_device *dev) { - kfree(dev->ncq_sense_buf); - dev->ncq_sense_buf = NULL; - + ata_dev_cleanup_cdl_resources(dev); transport_destroy_device(&dev->tdev); put_device(&dev->tdev); } diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 5ca17784a350..df11f923e1a2 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -89,6 +89,7 @@ extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); extern const char *sata_spd_string(unsigned int spd); extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log, u8 page, void *buf, unsigned int sectors); +void ata_dev_cleanup_cdl_resources(struct ata_device *dev); #define to_ata_port(d) container_of(d, struct ata_port, tdev) diff --git a/include/linux/libata.h b/include/linux/libata.h index 3fb6980c8aa1..37a5509adc77 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -700,6 +700,21 @@ struct ata_cpr_log { struct ata_cpr cpr[] __counted_by(nr_cpr); }; +struct ata_cdl { + /* + * Buffer to cache the CDL log page 18h (command duration descriptors) + * for SCSI-ATA translation. + */ + u8 desc_log_buf[ATA_LOG_CDL_SIZE]; + + /* + * Buffer to handle reading the sense data for successful NCQ Commands + * log page for commands using a CDL with one of the limits policy set + * to 0xD (successful completion with sense data available bit set). + */ + u8 ncq_sense_log_buf[ATA_LOG_SENSE_NCQ_SIZE]; +}; + struct ata_device { struct ata_link *link; unsigned int devno; /* 0 or 1 */ @@ -763,8 +778,7 @@ struct ata_device { struct ata_cpr_log *cpr_log; /* Command Duration Limits support */ - u8 *ncq_sense_buf; - u8 cdl[ATA_LOG_CDL_SIZE]; + struct ata_cdl *cdl; /* error history */ int spdn_cnt;