From patchwork Thu Sep 21 18:07:50 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: 1837851 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=RDwGQlJ2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Rs7Gl2V8Yz1ynH for ; Fri, 22 Sep 2023 07:05:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232403AbjIUVFv (ORCPT ); Thu, 21 Sep 2023 17:05:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233023AbjIUVFT (ORCPT ); Thu, 21 Sep 2023 17:05:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3B12B0598; Thu, 21 Sep 2023 11:08:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07BD4C433CA; Thu, 21 Sep 2023 18:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319708; bh=flFAd8DdULULocs8cxL0Hlh1zT/I0HWgfXuDa6s6GKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RDwGQlJ2OgC64uxH4SBsGUcCxZdr4brlxXU/H0gtjrlIQveZrhdqX+5oETXMySFWI Bjed7fmomcQXbpXRj/OFJDPitLJITeDlbtPHc51StAutKgqk08MXj/0f63leQ0us+A SlxhSf8cPWl2xZZBMyx2Ey0n2BXK0/1+L8TO44Fh7aauneJc4/4w2Ua50Okghwu8c1 8DT7Ka8aTyHekzWnCgOuemwBuIskccDRqDQe5UNxrkPq7IblWhvgnlHo/YDuLyb+Os QJN8oVy/BjUVRR32k4TYF+7dscd7soGdSQyOoEYCOCJR1Ijj9NmWfdkEAx3aqfMkNE 14oA8mZmpjPcg== 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 , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 15/23] ata: libata-core: Detach a port devices on shutdown Date: Fri, 22 Sep 2023 03:07:50 +0900 Message-ID: <20230921180758.955317-16-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@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 Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- 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 de661780a31e..6b38ebaad019 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6164,10 +6164,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;