From patchwork Thu May 6 15:31:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 12242675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA8E6C433ED for ; Thu, 6 May 2021 16:03:51 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71EF3610E9 for ; Thu, 6 May 2021 16:03:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71EF3610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JG652WgyqmTkchdhJQTIqEPWXKRyivSc34jGG+S8XyI=; b=SRLeXy0rR2/geIxLG2pjuuHny Qd2z74CSlOCD+8qbLh/ZJBkp6s4pUiCZz9Kfi6p+/ZcESf8ITcpLL1mfuuoL9zbBydxVb80VDxwmc BDbRX/ho7dWyr/roHACgXnxvRyRo7pmB0qtFJWhynfJyXkxKbCDDPCnNwppwGB3ZiPvK9237CIHov uc1obnJLCzj7Qk+sbEh13hRifTsp2ueOOLitwpOOFIJq0j27cK8iQHeo2XFf84lLMCffAPfGcA+84 GDQfWtAs/T3SHTp+e7AuPTFjcT0o5DyC0HXSb+qKMUCc1knzEGeTS2pa26uBtM/xbrWp/ncBwEWLR JUdGDBxxA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1legEP-004f4o-5a; Thu, 06 May 2021 15:48:05 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lefzo-004a7A-Vv for linux-arm-kernel@desiato.infradead.org; Thu, 06 May 2021 15:33:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=HvVVH0N1OL4pB67bmpFUEL2AYtVVC8SRgWwWRKZT2bY=; b=rMkt7a0AxPHOo2IZAWvNyKoHFY aj837Ucpiax0uorfpXPOL8UevlQBCbIXRm3wwFjF6HESasPu/IBXNoiSjuT6FvE3wXlKMJqCrGl+B pRZcyn1Kd7V57/RSq/Mzmy8JkjqWTCr+QwRCrRHm6pgmxjHt2O1JJdGq4DsrfoJAO8ZqaZF22H8Em fJ9PIJvkFQfCmoxi/7c8aKFhUHnEGfua2mF7zFab4MYIPqrYUxb1DQB+kUYhbFgrgcWIYHd6nNgtA IwFjdKIStZ8Gg8jeVWNgcMVfCaXT8oiJx32m/sHb639/sp+bY7xDsy3sRbPN6P/CdnYapa2auP+3d XcEAGmsg==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lefzi-0069hi-Fd for linux-arm-kernel@lists.infradead.org; Thu, 06 May 2021 15:32:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 87A2861466; Thu, 6 May 2021 15:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620315171; bh=urrwtdifV1fz+XQqM6L88XpER1LnRW6X4GCyTMrByDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IAhpZGoDLMr/XM36LpXnUhmpuYoUZemfa69scs/apqACQh8Asvic7XO+S0i337uGG DK1TdARfwbJny6lEsfYGdy1RdSSEhR/bw7uHhwcC8KpAek/F3+Tku2/6MhxRgl5E9S B2JbMXxo+u6kSPTDkEXBYaK8lAsaPQ5TsrFofh5JOjKvaeZHzMFcaofoc611m/+MgC FelmH4b66mUm0cvRU94SCd/dnm3n+yYWLC4APmCYOplQps7e7PJ9tDL6xaV0TWHElc B/rQ+nPd5mK4m2ElrKyiO7kmvRnJJhGjVbabnGOWKFIesVYwP6T/MZdI2lVk0UTSRm NbDcjjm9Jmy4g== Received: by pali.im (Postfix) id 3DA1589A; Thu, 6 May 2021 17:32:51 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Lorenzo Pieralisi , Thomas Petazzoni , Rob Herring , Bjorn Helgaas Cc: Russell King , =?utf-8?q?Marek_Beh=C3=BAn?= , Remi Pommarel , Xogium , Tomasz Maciej Nowak , Marc Zyngier , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/42] PCI: aardvark: Fix support for PME on emulated bridge Date: Thu, 6 May 2021 17:31:35 +0200 Message-Id: <20210506153153.30454-25-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210506153153.30454-1-pali@kernel.org> References: <20210506153153.30454-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210506_083254_622287_4A478E7B X-CRM114-Status: GOOD ( 14.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The emulated bridge returns incorrect value for PCI_EXP_RTSTA register during readout in advk_pci_bridge_emul_pcie_conf_read() function. Fix it by setting correct bit PCI_EXP_RTSTA_PME based on PCIE_MSG_PM_PME_MASK. Currently enabling PCI_EXP_RTSTA_PME bit in PCI_EXP_RTCTL register does nothing. This is because PCIe PME driver expects to receive PCIe interrupt defined in PCI_EXP_FLAGS_IRQ register. But aardvark hardware does not trigger PCIe INTx/MSI interrupt for PME event, rather it triggers custom aardvark interrupt which this driver is not processing yet. Fix this issue by handling PME interrupt in advk_pcie_handle_int() and chaining it to PCIe interrupt 0 with generic_handle_irq() (since aardvark hardware sets PCI_EXP_FLAGS_IRQ to zero). With this change PCIe PME driver finally starts receiving PME interrupt. To optimize advk_pci_bridge_emul_pcie_conf_write() code, touch PCIE_ISR0_REG and PCIE_ISR0_MASK_REG registers only when it is really needed, when processing PCI_EXP_RTCTL_PMEIE and PCI_EXP_RTSTA_PME bits. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Fixes: 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCI bridge config space") Cc: stable@vger.kernel.org # c0f05a6ab525 ("PCI: aardvark: Fix PCI_EXP_RTCTL register configuration") --- drivers/pci/controller/pci-aardvark.c | 40 ++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 2ea58ba10a97..fac48797d922 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -574,7 +574,10 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, case PCI_EXP_RTSTA: { u32 isr0 = advk_readl(pcie, PCIE_ISR0_REG); u32 msglog = advk_readl(pcie, PCIE_MSG_LOG_REG); - *value = (isr0 & PCIE_MSG_PM_PME_MASK) << 16 | (msglog >> 16); + u32 val = msglog >> 16; + if (isr0 & PCIE_MSG_PM_PME_MASK) + val |= PCI_EXP_RTSTA_PME; + *value = val; return PCI_BRIDGE_EMUL_HANDLED; } @@ -617,19 +620,21 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, advk_pcie_wait_for_retrain(pcie); break; - case PCI_EXP_RTCTL: { + case PCI_EXP_RTCTL: /* Only mask/unmask PME interrupt */ - u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG) & - ~PCIE_MSG_PM_PME_MASK; - if ((new & PCI_EXP_RTCTL_PMEIE) == 0) - val |= PCIE_MSG_PM_PME_MASK; - advk_writel(pcie, val, PCIE_ISR0_MASK_REG); + if (mask & PCI_EXP_RTCTL_PMEIE) { + u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG); + if ((new & PCI_EXP_RTCTL_PMEIE) == 0) + val |= PCIE_MSG_PM_PME_MASK; + else + val &= ~PCIE_MSG_PM_PME_MASK; + advk_writel(pcie, val, PCIE_ISR0_MASK_REG); + } break; - } case PCI_EXP_RTSTA: - new = (new & PCI_EXP_RTSTA_PME) >> 9; - advk_writel(pcie, new, PCIE_ISR0_REG); + if (new & PCI_EXP_RTSTA_PME) + advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG); break; default: @@ -1219,6 +1224,21 @@ static void advk_pcie_handle_int(struct advk_pcie *pcie) if (!isr0_status && !isr1_status) return; + /* Process PME interrupt */ + if (isr0_status & PCIE_MSG_PM_PME_MASK) { + /* + * Do not clear PME interrupt bit in ISR0, it is cleared by IRQ + * receiver by writing to the PCI_EXP_RTSTA register of emulated + * root bridge. Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ, + * so use PCIe interrupt 0. + */ + virq = irq_find_mapping(pcie->irq_domain, 0); + if (virq) + generic_handle_irq(virq); + else + dev_err(&pcie->pdev->dev, "unexpected PME IRQ\n"); + } + /* Process ERR interrupt */ if (err_bits) { advk_writel(pcie, err_bits, PCIE_ISR0_REG);