From patchwork Wed Aug 23 18:58:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 9918179 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 20F2D602CB for ; Wed, 23 Aug 2017 18:59:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A79222A68 for ; Wed, 23 Aug 2017 18:59:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8BDF28A12; Wed, 23 Aug 2017 18:59:41 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4FD9B28A15 for ; Wed, 23 Aug 2017 18:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ef/xc3pVfjDbAbGhs1F+jX24dH3u0F0JRGTee1nc6T0=; b=TI2Kws6b5XgHcD Pg95wECNCOTEUq4FqZQP/AqqE537L3ZN1FqVlkUKM4ok4juaxaGogjoK0Jfvrvt25sbVOAZuiKttv b4mwvOqZJhOsEwlrWL/cARczx7qz94DdiF8o3n2ugeLGZ2tiC/X8ukMUNHJi8HvXLs2KYrUe0hzW+ 5DhYcN3WWvLyp1TcK8/y+PlQZ+tpuATG+tWpOnIDX5FgpDLApv8qKbJBrG/z4Xk/t+/DsHIkdpfc3 fT9+OBxHKOzUJiBpMS0hXHjED5H3MINS2dSAO+CwZtGWdb9PB602ZU2xcmJ0jUDxcov43hSWP68jp Iljmk+aLe/tmUNAH0aow==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dkarw-0007P3-9g; Wed, 23 Aug 2017 18:59:12 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dkare-00077l-2A; Wed, 23 Aug 2017 18:58:55 +0000 Received: from localhost (unknown [69.71.4.159]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1BC4020C10; Wed, 23 Aug 2017 18:58:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BC4020C10 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Date: Wed, 23 Aug 2017 13:58:30 -0500 From: Bjorn Helgaas To: honghui.zhang@mediatek.com Subject: Re: [PATCH v2 0/3] PCI: mediatek: Add MSI support for MT2712 and MT7622 Message-ID: <20170823185830.GE8498@bhelgaas-glaptop.roam.corp.google.com> References: <1502715868-17651-1-git-send-email-honghui.zhang@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1502715868-17651-1-git-send-email-honghui.zhang@mediatek.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170823_115854_230638_E485DBE8 X-CRM114-Status: GOOD ( 24.42 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: youlin.pei@mediatek.com, devicetree@vger.kernel.org, hongkun.cao@mediatek.com, ryder.lee@mediatek.com, linux-pci@vger.kernel.org, sean.wang@mediatek.com, xinping.qian@mediatek.com, linux-kernel@vger.kernel.org, matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org, yong.wu@mediatek.com, bhelgaas@google.com, yingjoe.chen@mediatek.com, eddie.huang@mediatek.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Aug 14, 2017 at 09:04:25PM +0800, honghui.zhang@mediatek.com wrote: > From: Honghui Zhang > > MT2712 and MT7622's PCIe host controller support MSI, but only 32bit MSI > address are supportted. It connect to GIC with the same IRQ number of INTx > IRQ, so it shares the same IRQ with INTx IRQ. > > This patchset add MSI support for MT2712 and MT7622. > Also do some code fixup and cleanups. > > Change Since V1: > - Add the first two patches into this patchset. > - Using -ENODEV instead of PTR_ERR if msi_domain == NULL > - Change the error logs with consistency of lower-case > - Using has_msi instead of support_msi to make the parameter name a bit shorter > > Honghui Zhang (3): > PCI: mediatek: Fix return value in case of error > PCI: mediatek: take use of bus->sysdata to get host private data > PCI: mediatek: add msi support for MT2712 and MT7622 > > drivers/pci/host/pcie-mediatek.c | 157 +++++++++++++++++++++++++++++++++++++-- > 1 file changed, 151 insertions(+), 6 deletions(-) Since "PCI: mediatek: Add controller support for MT2712 and MT7622" patch hasn't appeared upstream yet, I folded the return value fix directly into it. I applied the others to pci/host-mediatek. I modified the third one to remove what seemed to be needless differences from the rcar and tegra drivers. The incremental diff is attached. Please check to make sure I didn't break anything. diff --git a/drivers/pci/host/pcie-mediatek.c b/drivers/pci/host/pcie-mediatek.c index 35ab2321ed16..8891c00bf13c 100644 --- a/drivers/pci/host/pcie-mediatek.c +++ b/drivers/pci/host/pcie-mediatek.c @@ -134,7 +134,7 @@ struct mtk_pcie_port; /** * struct mtk_pcie_soc - differentiate between host generations - * @has_msi: whether this host support MSI interrupt or not + * @has_msi: whether this host supports MSI interrupts or not * @ops: pointer to configuration access functions * @startup: pointer to controller setting functions * @setup_irq: pointer to initialize IRQ functions @@ -439,44 +439,51 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) return 0; } -static int mtk_pcie_assign_msi(struct mtk_pcie_port *port) +static int mtk_pcie_msi_alloc(struct mtk_pcie_port *port) { - int pos; + int msi; - pos = find_first_zero_bit(port->msi_irq_in_use, MTK_MSI_IRQS_NUM); - if (pos < MTK_MSI_IRQS_NUM) - set_bit(pos, port->msi_irq_in_use); + msi = find_first_zero_bit(port->msi_irq_in_use, MTK_MSI_IRQS_NUM); + if (msi < MTK_MSI_IRQS_NUM) + set_bit(msi, port->msi_irq_in_use); else return -ENOSPC; - return pos; + return msi; +} + +static void mtk_pcie_msi_free(struct mtk_pcie_port *port, unsigned long hwirq) +{ + clear_bit(hwirq, port->msi_irq_in_use); } static int mtk_pcie_msi_setup_irq(struct msi_controller *chip, - struct pci_dev *pdev, - struct msi_desc *desc) + struct pci_dev *pdev, struct msi_desc *desc) { struct mtk_pcie_port *port; struct msi_msg msg; + unsigned int irq; int hwirq; - u32 irq; port = mtk_pcie_find_port(pdev->bus, pdev->devfn); if (!port) return -EINVAL; - chip->dev = &pdev->dev; - hwirq = mtk_pcie_assign_msi(port); + hwirq = mtk_pcie_msi_alloc(port); if (hwirq < 0) return hwirq; irq = irq_create_mapping(port->msi_domain, hwirq); - if (!irq) + if (!irq) { + mtk_pcie_msi_free(port, hwirq); return -EINVAL; + } + + chip->dev = &pdev->dev; irq_set_msi_desc(irq, desc); - /* MT2712/MT7622 only support 32 bit MSI address */ + /* MT2712/MT7622 only support 32-bit MSI addresses */ msg.address_hi = 0; msg.address_lo = lower_32_bits((u64)(port->base + PCIE_MSI_VECTOR)); msg.data = hwirq; @@ -497,10 +504,8 @@ static void mtk_msi_teardown_irq(struct msi_controller *chip, unsigned int irq) if (!port) return; - if (!test_bit(hwirq, port->msi_irq_in_use)) - dev_err(&pdev->dev, "trying to free unused MSI#%d\n", irq); - else - clear_bit(hwirq, port->msi_irq_in_use); + irq_dispose_mapping(irq); + mtk_pcie_msi_free(port, hwirq); } static struct msi_controller mtk_pcie_msi_chip = { @@ -529,16 +534,26 @@ static const struct irq_domain_ops msi_domain_ops = { .map = mtk_pcie_msi_map, }; -static void mtk_pcie_enable_msi(struct mtk_pcie_port *port) +static int mtk_pcie_enable_msi(struct mtk_pcie_port *port) { u32 val; + port->msi_domain = irq_domain_add_linear(node, MTK_MSI_IRQS_NUM, + &msi_domain_ops, + &mtk_pcie_msi_chip); + if (!port->msi_domain) { + dev_err(dev, "failed to create MSI IRQ domain\n"); + return -ENOMEM; + } + val = lower_32_bits((u64)(port->base + PCIE_MSI_VECTOR)); writel(val, port->base + PCIE_IMSI_ADDR); val = readl(port->base + PCIE_INT_MASK); val &= ~MSI_MASK; writel(val, port->base + PCIE_INT_MASK); + + return 0; } static int mtk_pcie_intx_map(struct irq_domain *domain, unsigned int irq, @@ -559,6 +574,7 @@ static int mtk_pcie_init_irq_domain(struct mtk_pcie_port *port, { struct device *dev = port->pcie->dev; struct device_node *pcie_intc_node; + int err; /* Setup INTx */ pcie_intc_node = of_get_next_child(node, NULL); @@ -574,16 +590,10 @@ static int mtk_pcie_init_irq_domain(struct mtk_pcie_port *port, return -ENODEV; } - /* Setup MSI */ if (IS_ENABLED(CONFIG_PCI_MSI)) { - port->msi_domain = irq_domain_add_linear(node, MTK_MSI_IRQS_NUM, - &msi_domain_ops, - &mtk_pcie_msi_chip); - if (!port->msi_domain) { - dev_err(dev, "failed to get MSI IRQ domain\n"); - return -ENODEV; - } - mtk_pcie_enable_msi(port); + err = mtk_pcie_enable_msi(port); + if (err < 0) + return err; } return 0;