From patchwork Thu May 24 14:36:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10424923 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8F126019D for ; Thu, 24 May 2018 14:36:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D47C32951B for ; Thu, 24 May 2018 14:36:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C902D29620; Thu, 24 May 2018 14:36:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 637012951B for ; Thu, 24 May 2018 14:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033380AbeEXOgw (ORCPT ); Thu, 24 May 2018 10:36:52 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34980 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033374AbeEXOgg (ORCPT ); Thu, 24 May 2018 10:36:36 -0400 Received: by mail-wr0-f196.google.com with SMTP id i14-v6so3574305wre.2; Thu, 24 May 2018 07:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fl+pxIjduDuE/7h0+24hskwtNMLsyGxIQjrZ6mTnnIM=; b=CGzr/Zy8fvBDgT+Ff8Bjcf+23NJ83Kv21wRs5n9Pl7GZ9VTY4KNLCtrOp/636p9N8B CBhP7Y+dHEF6mmch/4X4W+7u9vvaQQu02El+ckQ+fWmKJ54aLGUhnHNZwRtS4D5UFW0M 1R6I0KcAsPKBlZnX9lJY8S9LFaJQiiihYqqZ98jWSxs35ylbHwG++NdiOgWUu/6kRQhB VWRSreOnJCZfPGY07PRmkepJ+XH+TLsWKDK4kc/ji+OPatLbEB7Ib+8X7WgdHd/kOCzb ZCQ6aVbysfFxcEEkCAXnU+wN/UW/C9PUc98HrA1dywo/FkIEn8cPMwHNuWxBlbDa9Q5+ dIPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fl+pxIjduDuE/7h0+24hskwtNMLsyGxIQjrZ6mTnnIM=; b=gBnavmBTEDtRkKoEfyJ+wC+2JLjqsDeSfU/G6R4i/d6hTd0Q+bnwtb5vkn3/d0CyCY Sk4Q32Oh2lyOEzpb70VnoUfVHO5pFk0QyC3qzIZNJH/qmiz7ij1XoqNCqnZXJGZ4iQVA ONHHYB7ZgQslxY/tGG0HRWxPuDlNNJYqihcUdV2NaX5oP2RaIFIlHBOqq2gibmiaqcx7 GUVIKXo6PGd+U/PjQwSn37eyck81xtGodtzfxev7XNxMCk+p5GDF+pFpRXp7s5dCJOQt iYo1sHlgk1DW+K2RKlIPM/Rx659XVag9NKzMSgKY7LBLMHdaNqnjq5qdBEW09GDFg46k Uezw== X-Gm-Message-State: ALKqPwdvSoQlHtsxK6NrXvyeAo3DY3q7GCwAlAhKWCzQUw8tUHvDkNPP uaV+ncSQFHX6dQrzBjZJNbAI9MSq X-Google-Smtp-Source: AB8JxZocequCVy8OM34njyw4R7tOrZavNpvlYCsmY3luN068nHmwJDgnTMhs2cYSaKerJjZijecvDQ== X-Received: by 2002:adf:9724:: with SMTP id r33-v6mr2478279wrb.79.1527172594967; Thu, 24 May 2018 07:36:34 -0700 (PDT) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id x17-v6sm14348276wmd.46.2018.05.24.07.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 07:36:34 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-pci@vger.kernel.org Cc: Marek Vasut , Geert Uytterhoeven , Lorenzo Pieralisi , Phil Edworthy , Simon Horman , Wolfram Sang , linux-renesas-soc@vger.kernel.org Subject: [PATCH v4 3/6] PCI: rcar: Teardown MSI setup if rcar_pcie_enable() fails Date: Thu, 24 May 2018 16:36:21 +0200 Message-Id: <20180524143624.26718-4-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180524143624.26718-1-marek.vasut+renesas@gmail.com> References: <20180524143624.26718-1-marek.vasut+renesas@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the rcar_pcie_enable() fails and MSIs are enabled, the setup done in rcar_pcie_enable_msi() is never undone. Add a function to tear down the MSI setup by disabling the MSI handling in the PCIe block, deallocating the pages requested for the MSIs and zapping the IRQ mapping. Signed-off-by: Marek Vasut Cc: Geert Uytterhoeven Cc: Lorenzo Pieralisi Cc: Phil Edworthy Cc: Simon Horman Cc: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org Reviewed-by: Simon Horman --- V2: No change V3: No change V4: Rebase on top of Lorenzo's pci/rcar, fix up the rebase breakage induced by patches therein --- drivers/pci/host/pcie-rcar.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index 6bb1cdec26be..d6a7e8482dcf 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -923,6 +923,28 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) return err; } +static void rcar_pcie_teardown_msi(struct rcar_pcie *pcie) +{ + struct rcar_msi *msi = &pcie->msi; + int irq, i; + + /* Disable all MSI interrupts */ + rcar_pci_write_reg(pcie, 0, PCIEMSIIER); + + /* Disable address decoding of the MSI interrupt, MSIFE */ + rcar_pci_write_reg(pcie, 0, PCIEMSIALR); + + free_pages(msi->pages, 0); + + for (i = 0; i < INT_PCI_MSI_NR; i++) { + irq = irq_find_mapping(msi->domain, i); + if (irq > 0) + irq_dispose_mapping(irq); + } + + irq_domain_remove(msi->domain); +} + static int rcar_pcie_get_resources(struct rcar_pcie *pcie) { struct device *dev = pcie->dev; @@ -1151,10 +1173,14 @@ static int rcar_pcie_probe(struct platform_device *pdev) err = rcar_pcie_enable(pcie); if (err) - goto err_clk_disable; + goto err_msi_teardown; return 0; +err_msi_teardown: + if (IS_ENABLED(CONFIG_PCI_MSI)) + rcar_pcie_teardown_msi(pcie); + err_clk_disable: clk_disable_unprepare(pcie->bus_clk);