From patchwork Thu May 24 07:23:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10422953 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 D49DC60545 for ; Thu, 24 May 2018 07:23:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEEC429010 for ; Thu, 24 May 2018 07:23:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B35F629014; Thu, 24 May 2018 07:23:39 +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 50CF229012 for ; Thu, 24 May 2018 07:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935616AbeEXHXh (ORCPT ); Thu, 24 May 2018 03:23:37 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54347 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935346AbeEXHXg (ORCPT ); Thu, 24 May 2018 03:23:36 -0400 Received: by mail-wm0-f66.google.com with SMTP id f6-v6so2140687wmc.4; Thu, 24 May 2018 00:23: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=LgeIoUfyMRkdTDZMoSqA4TGg42OfM4ptSwPRNMJ/454=; b=V43coJlwnSl1ajr7iwXvrqscxtbj1lDg6fSrVc+H//sC5RttoC80dMbxDe6gkCZhCX jc80oHFlcYv9Wr6GoKueDoFoDMyi8+Ci1Lgm4qBT62gtNMT4SO7L6N1BCr69mCfpHXjO IjfQkxep8fagYxMt9PsDwefNjH2ruNeP7jVcmWC6tYkgDkeIS8nOZHueUQYduI7N4Wje 0tuU0tL/vzvu9KmkCuKG9s4JNsSrBdgZDOhnGnBFeAEWQajHpeSCWTRRTmyD9prn3Ukm Jk3BcOmtVhTEC/KxEPRRVh+r9V7Q++62B0ktQ50Sc0wCtCYb6NXTU5Llq9z19yXRdqq1 ZWDA== 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=LgeIoUfyMRkdTDZMoSqA4TGg42OfM4ptSwPRNMJ/454=; b=glLxmtxMdMP+jZnMXIcXyDCWJ2Y5zfq1P15/42kzGM+hyp1ePqBGzKZtvLzv+NXpKq el1e3TljspZL2px7d4UEllNjDjniXNmMxwtrol3fCMgfoGFAz5VrWa6h5c0Il80VJ5tb Fz7fDwvp41R0Nv52ObMBPmpDK1STQBCRjBUERESJ5ZfhDO+iA9dFdN3eMvO02/YYksY7 bU+BSkK9ovyIEyW3LNZFmAzA6bmxOJAL0Bm9jYBKMs5hdVrnjHja9ilFJ5Z69n5SV64/ q986PGpcxDtdSpRNxb4//MWtXWadOLjQimYDjmRTV5n4x82x39tlO82uz0webh2GDwwu 0y/w== X-Gm-Message-State: ALKqPwccCDON8SssLxbohztmQOkY4IO/jP8Bj6mSFgkeDwpw7T3UMkcf alwsST/4AGPWMISNCN9pEeAX7K2j X-Google-Smtp-Source: AB8JxZpa+d5bUaLeZTbAXXKq7UKDVzKNSCg1MDIJPih6G0ML6jsRQKrYpBMCevqY1/npCfwu76RdZg== X-Received: by 2002:a1c:ec82:: with SMTP id h2-v6mr5960748wmi.137.1527146614572; Thu, 24 May 2018 00:23: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 j13-v6sm10997919wre.38.2018.05.24.00.23.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 00:23:33 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-pci@vger.kernel.org Cc: Marek Vasut , Geert Uytterhoeven , Phil Edworthy , Simon Horman , Wolfram Sang , linux-renesas-soc@vger.kernel.org Subject: [PATCH 3/6] PCI: rcar: Teardown MSI setup if rcar_pcie_enable() fails Date: Thu, 24 May 2018 09:23:20 +0200 Message-Id: <20180524072323.22115-3-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180524072323.22115-1-marek.vasut+renesas@gmail.com> References: <20180524072323.22115-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: Phil Edworthy Cc: Simon Horman Cc: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org --- 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);