From patchwork Tue Sep 12 00:56:47 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: 13380582 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 90E5FCA0EC6 for ; Tue, 12 Sep 2023 03:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240306AbjILDCB (ORCPT ); Mon, 11 Sep 2023 23:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241580AbjILDBg (ORCPT ); Mon, 11 Sep 2023 23:01:36 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9D61A39B2; Mon, 11 Sep 2023 18:32:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08855C32799; Tue, 12 Sep 2023 00:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694480237; bh=n9IvarAW0mAV9i/DxjM8+P2WnUrc0LwKNqotrPGv2EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsYoic321rosPIdE2xOpyq2Pv416yQahcHq141Y4QjqpMtbAUMyaqvS60kfGSMPMN EXsn5sq3t5xO3m71nc6yNrtVMb0UohklDJ3aqX5xRQAXd1+a1XUXEgwlJJnNmKOdOR rKOgAQjVZs8vBq6EbwFWUgeUr0y7y1YU/SK145YwxNmGpcG/Be64DXI2x4P8EuOpez a9dKQb6I5dXUnlqL+hWsTdGN8LG+/Rjf2sJznph7mlCQ8/f9TfzHJdAeJkJ7c4v6LI 2V0c1xDLQ7JLtiXQVZvVSz12nVl4JKEBSDK4lNsCPu9QoKThNij6BrLJN2P+pDwtFk hUPJrbFQSay0g== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer Subject: [PATCH v2 13/21] ata: libata-core: Detach a port devices on shutdown Date: Tue, 12 Sep 2023 09:56:47 +0900 Message-ID: <20230912005655.368075-14-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912005655.368075-1-dlemoal@kernel.org> References: <20230912005655.368075-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Modify ata_pci_shutdown_one() to schedule EH to unload a port devices before freezing and thawing the port. This ensures that drives are cleanly disabled and transitioned to standby power mode when a PCI adapter is removed or the system is powered off. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 9f05ad187c9e..7d110e5454bf 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6168,10 +6168,24 @@ EXPORT_SYMBOL_GPL(ata_pci_remove_one); void ata_pci_shutdown_one(struct pci_dev *pdev) { struct ata_host *host = pci_get_drvdata(pdev); + struct ata_port *ap; + unsigned long flags; int i; + /* Tell EH to disable all devices */ for (i = 0; i < host->n_ports; i++) { - struct ata_port *ap = host->ports[i]; + ap = host->ports[i]; + spin_lock_irqsave(ap->lock, flags); + ap->pflags |= ATA_PFLAG_UNLOADING; + ata_port_schedule_eh(ap); + spin_unlock_irqrestore(ap->lock, flags); + } + + for (i = 0; i < host->n_ports; i++) { + ap = host->ports[i]; + + /* Wait for EH to complete before freezing the port */ + ata_port_wait_eh(ap); ap->pflags |= ATA_PFLAG_FROZEN;