From patchwork Thu Nov 25 12:45:51 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: 12693649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B90F3C4332F for ; Thu, 25 Nov 2021 12:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=rXjZIxYw/fXMTw/gwPUDTYZXxNe0/3+LF2/5AYnjmpw=; b=yzi3YMac+TAc3X Dqf+OnUbgGXbFPkDyuyRnMD7NGlvec0m1tTmLUnJPzAfC9B/kqDYxWhkmaisIVh7/KPXgR5nbEhM7 y7ujx2LUGfAWHEUMZMgvq/y4SQS7NQD58rLROcvFX1Y7mPFMIFZmZvWc/nYPS0yTX70h4mav5DJgl otjY7EN03hNww+OtJNhbVtAspeKCuDDiVArN1qOoyJhFMvszaXgSCqtia4A9mqdfVlggKxA46cfp6 +qwJA+XyvqWO9TpMJHnYcBV3anaFKA+9hP9s/CWyHiAHMVri6Vv97FzTwAAeyomhBSLJxjscqcqxX yBqTG/o+yMG+u0AAbgCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9F-007SqQ-0r; Thu, 25 Nov 2021 12:46:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE94-007SnN-By for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:37 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BBDA4610A7; Thu, 25 Nov 2021 12:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844393; bh=tPbNDMR/pO/XPt3w0yjPE5vVD9ywEbzQpey0qyJc5AU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0DpSVTPYHPRgHrA99G17xbggKeFyLVfMnuzn8kj+rNnt5CWQALQNFFKWceLwK58c Gb83wxr+S8X1Ar5xy+KtkQ8hdsFB0az0BVvvl8zKebrj62fc+BUDJeXuJCK19mYDit SVkTxTg8N1WLOdt5knnj8v06L9kfvRKF1U3hirwZzyTP/zT3o9q7gQRWgJ2Or8Ypw5 bZly5veqkkyW+5PC1I4EWp7GQ37dWuVhJZ2+YVFAkGPRBhPIFQhbi1hQWm/GNcz5mD 9AAn9FXnEBARTxUkcczGc0LUXFt39imW0/DT+BSsl70/2Ue2s7HMv0QpXyJ8JaZkYk jdAgiB8YK4Hpw== Received: by pali.im (Postfix) id 01C47EDE; Thu, 25 Nov 2021 13:46:30 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/15] PCI: mvebu: Check for valid ports Date: Thu, 25 Nov 2021 13:45:51 +0100 Message-Id: <20211125124605.25915-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044634_504305_F1CC6C72 X-CRM114-Status: GOOD ( 12.09 ) 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 Some mvebu ports do not have to be initialized. So skip these uninitialized mvebu ports in every port iteration function to prevent access to unmapped memory or dereferencing NULL pointers. Uninitialized mvebu port has base address set to NULL. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 06f06085beba..d655c887ba1b 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -625,6 +625,9 @@ static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie, for (i = 0; i < pcie->nports; i++) { struct mvebu_pcie_port *port = &pcie->ports[i]; + if (!port->base) + continue; + if (bus->number == 0 && port->devfn == devfn) return port; if (bus->number != 0 && @@ -800,6 +803,8 @@ static int mvebu_pcie_suspend(struct device *dev) pcie = dev_get_drvdata(dev); for (i = 0; i < pcie->nports; i++) { struct mvebu_pcie_port *port = pcie->ports + i; + if (!port->base) + continue; port->saved_pcie_stat = mvebu_readl(port, PCIE_STAT_OFF); } @@ -814,6 +819,8 @@ static int mvebu_pcie_resume(struct device *dev) pcie = dev_get_drvdata(dev); for (i = 0; i < pcie->nports; i++) { struct mvebu_pcie_port *port = pcie->ports + i; + if (!port->base) + continue; mvebu_writel(port, port->saved_pcie_stat, PCIE_STAT_OFF); mvebu_pcie_setup_hw(port); } From patchwork Thu Nov 25 12:45:52 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: 12693655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA481C433EF for ; Thu, 25 Nov 2021 12:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=zn/jQVhwcbp78xrejj1R6+PY9hit99jNZclcZx/96rA=; b=WksJ8/o8CP085d geXeFzFovqxeosF+1ffJptavbKarQwu8/YmvJ+VSxZhLOhel2Xq5e+0+hlyyYop8P7Ri/fASfDyiX 9uuQIisgZi5YwaT/BacFHrBo2YHNail6OCSbGzFLnJ2zvxSp0w3XSlCY7bMblW8D5JbPCajCgmnKd XbkxZv80oi9g68LuDoszErXTZU3VDSulg7HsW+hXZgDhBu0xaK+9R2jFm0HbqnuL674umvQNC10uO zjhiUkog28hZaNkYiCJd3pbMo0fgfX7qVYVc3/dHnrU443GqIeRb9yhwYo8s1wahTNUe2Cy5HrBJa lo7sHXBiiREXFxEW2wuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEBb-007TsL-0d; Thu, 25 Nov 2021 12:49:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE97-007SpG-K9 for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:39 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8B0761130; Thu, 25 Nov 2021 12:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844395; bh=kIxbqqnl03bqhcc87mZU1EX4mGZmPj5F3GGmUg4gbBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOSLIddDQzrES0ip0gB2f3eHw28HqIopb6ULFkYl07tSmyuCZX22Z7kEMCMFlckyw /sO4M8wnpL9eszVep/luKUCWo9U+s7ixygTmGPMNhbi0o2pCcQ1H4NnHFWyB743eYH k4JMrVWVIRFu+bblJzQSY+qRlUSBW7dhXk3IroRz6t/5qZNLGocsYQvQs+Fe/dsMq+ SgSTvaP2O9x/N9ssMijCY98ATo02yqDhYkXnruNlGhf/wz50IRvLp2/+xRjoRYcpOi PxZCizDaQmLHdOswi4PLKNuTGKNF7tZrDwBLUpNKjqSvdY/WM3eKoT7qf03nNhwJwO ThdbnAJMlmm7A== Received: by pali.im (Postfix) id 0D591F3C; Thu, 25 Nov 2021 13:46:32 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/15] PCI: mvebu: Check for errors from pci_bridge_emul_init() call Date: Thu, 25 Nov 2021 13:45:52 +0100 Message-Id: <20211125124605.25915-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044637_731439_C444D868 X-CRM114-Status: GOOD ( 12.99 ) 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 Function pci_bridge_emul_init() may fail so correctly check for errors. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index d655c887ba1b..6197f7e7c317 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -581,7 +581,7 @@ static struct pci_bridge_emul_ops mvebu_pci_bridge_emul_ops = { * Initialize the configuration space of the PCI-to-PCI bridge * associated with the given PCIe interface. */ -static void mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port) +static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port) { struct pci_bridge_emul *bridge = &port->bridge; u32 pcie_cap = mvebu_readl(port, PCIE_CAP_PCIEXP); @@ -608,7 +608,7 @@ static void mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port) bridge->data = port; bridge->ops = &mvebu_pci_bridge_emul_ops; - pci_bridge_emul_init(bridge, PCI_BRIDGE_EMUL_NO_PREFETCHABLE_BAR); + return pci_bridge_emul_init(bridge, PCI_BRIDGE_EMUL_NO_PREFETCHABLE_BAR); } static inline struct mvebu_pcie *sys_to_pcie(struct pci_sys_data *sys) @@ -1094,9 +1094,18 @@ static int mvebu_pcie_probe(struct platform_device *pdev) continue; } + ret = mvebu_pci_bridge_emul_init(port); + if (ret < 0) { + dev_err(dev, "%s: cannot init emulated bridge\n", + port->name); + devm_iounmap(dev, port->base); + port->base = NULL; + mvebu_pcie_powerdown(port); + continue; + } + mvebu_pcie_setup_hw(port); mvebu_pcie_set_local_dev_nr(port, 1); - mvebu_pci_bridge_emul_init(port); } bridge->sysdata = pcie; From patchwork Thu Nov 25 12:45:53 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: 12693650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99BB5C433F5 for ; Thu, 25 Nov 2021 12:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=iYLA6xZeaEID1yNpklE9zhLlYV5X9XXdvvkDqqQgoo8=; b=j2JkIUB3kIUehy Od2l/zd1MP+d0WSqIFq7lYjzjNGedQ3YvARlBc8MGC9unfdVTpZ5Am10FJFcDamDQ0bCxoE6tw1WZ uUcOE5d7iDdn8XoxPdGPAVoU7zxb5HGp3n4v4v8L4eDTQ9PqHlAE5X1kxSmM3LiUoHEUcMOtcxYQ7 u0s90vlU7NGnHAe7vNlHt5LEs6tShV5jZgJ4bdW/b7HC2dnF5LRujWySAwWqWEIz6ek1cDpLQgi51 RYOTtrLPuUpxAIKYcnYkmmelVW+7E+dPbhSrGD9l3qDOTbILtgMHEEYhpWfTkPhEAAyFN8NIh4/aI NyHVbAWuDwzgk6DPAQPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9a-007SzL-KY; Thu, 25 Nov 2021 12:47:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE94-007SnZ-Cy for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:37 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 632F9610F8; Thu, 25 Nov 2021 12:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844393; bh=CFRpIIvV+dRawyP1HEAT1CWwpAzBUW1TAumtSAX1zdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPR7zYq10qu2cCGOR1Su7Z7FMC7TwAqk3pyARxezKNxK3nDejX3oj3OJVfu8QG2dd jtonb2lywy0K2v0aTMKnkrgwmzOOPVFXGaFTTcEiu4dkeuLP36ojWnOr1fcR5lHS3H +iH/qJF5T//9r5r0eod1KccMscu/jmqzSqvO7Te2CVLVDCCHNf7rfi0tZeGImv8+SD twfoldtaNiVR3vOmivZ/qgiIxmLxMsKGwWqiYoBCiUD/bFtfJugL2m8OXXuO5faxnF W4WpTDG0mo6V3C1LECIKoSJUBprj5f95H3Z+oHUDiuupZywnGiB8bZ2FQ5MVI8mobG H7x6B0DboyCIQ== Received: by pali.im (Postfix) id 21E8EFB1; Thu, 25 Nov 2021 13:46:33 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/15] PCI: mvebu: Check that PCI bridge specified in DT has function number zero Date: Thu, 25 Nov 2021 13:45:53 +0100 Message-Id: <20211125124605.25915-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044634_504676_6EF56E58 X-CRM114-Status: GOOD ( 10.72 ) 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 Driver cannot handle PCI bridges at non-zero function address. So add appropriate check. Currently all in-tree kernel DTS files set PCI bridge function to zero. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 6197f7e7c317..08274132cdfb 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -864,6 +864,11 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie, port->devfn = of_pci_get_devfn(child); if (port->devfn < 0) goto skip; + if (PCI_FUNC(port->devfn) != 0) { + dev_err(dev, "%s: invalid function number, must be zero\n", + port->name); + goto skip; + } ret = mvebu_get_tgt_attr(dev->of_node, port->devfn, IORESOURCE_MEM, &port->mem_target, &port->mem_attr); From patchwork Thu Nov 25 12:45:54 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: 12693653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0621C433EF for ; Thu, 25 Nov 2021 12:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=ZYmj87Kd1riE3vLYfahhgOItK6fRxjWxf6XblrbU3pc=; b=isXXO+9hBJLKgc AYK8SmyhRrVCSka4i5GVcVnMV4mwwvJsKtBAFh0+fUJSA1rlfJgwF3oJ1E4Y/Jb3bv8lvI0wIpFrL lyM2IQ7Fwc8cSSmMeSUQgEy5kKNpLP34VP2rixgH49/qTteAcJpfY/dYVvwIydD7M38TJcPKY1Xct XCtMppuGzp66EaTRJlVSROVzcLf/wCC8AuPhrjbngQbKE+VwbNeB+8NrR/d1HPUHlGiXeuA69GMzD Tawk7PDKahIlH0sDzhBBx0ZHaB96cjmGvpeiUwpJW9b1Jhd2dDJxIm7doRNr9oqSgFO+cnT5B/Rjx c9j7gNBsOK6lVZUc4T2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEAg-007TJK-Kq; Thu, 25 Nov 2021 12:48:15 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE95-007SoG-Kv for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:38 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14572610FB; Thu, 25 Nov 2021 12:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844395; bh=V49Dl6I3ETYyBXCva0Ab5YRCPF20sbpwGL5aEs5sgZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kvm31VUlPXoPnaVkKfH4RfPkFELOCasP8eM7ZRiPWKDrUYF7fe5tvMMhhoU+fzDiL 7SzZkIR9yvX9tPU7K3+kjN21luO04b9pUjXPL5Cw7ylhZOaGVHSIlqrLL8z4kC744P 5N1xI0mTznUKsgoDU6uyKayGJmQqqdWNSaQD9oOqNTZHMXhEKygg/PmVSu9R1yhrIa 86E47HhNcRElH1tekn2OEFdJav3JxOh0pctuDBBBaF6lY/oxwLRcqFSVQb1Rx86Uqj t9PNgSBTw2pKnN768RVJIz5Y/1Ag84yCWZdkqzRhRE+KelYvIrbd2DfTeFXTJ5JGof To1vc5sTxiVaA== Received: by pali.im (Postfix) id 6C55467E; Thu, 25 Nov 2021 13:46:34 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/15] PCI: mvebu: Handle invalid size of read config request Date: Thu, 25 Nov 2021 13:45:54 +0100 Message-Id: <20211125124605.25915-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044635_752982_49BD0EEA X-CRM114-Status: UNSURE ( 9.76 ) X-CRM114-Notice: Please train this message. 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 Function mvebu_pcie_hw_rd_conf() does not handle invalid size. So correctly set read value to all-ones and return appropriate error return value PCIBIOS_BAD_REGISTER_NUMBER like in mvebu_pcie_hw_wr_conf() function. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 08274132cdfb..19c6ee298442 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -261,6 +261,9 @@ static int mvebu_pcie_hw_rd_conf(struct mvebu_pcie_port *port, case 4: *val = readl_relaxed(conf_data); break; + default: + *val = 0xffffffff; + return PCIBIOS_BAD_REGISTER_NUMBER; } return PCIBIOS_SUCCESSFUL; From patchwork Thu Nov 25 12:45:55 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: 12693654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58ED4C433EF for ; Thu, 25 Nov 2021 12:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=qI+tXEyLweOdEo8sPyNBeZq2k76JUeAaq8t77v2MXso=; b=tcGXwxkj3jdWRO wJ51x/0YieLHOefpVKqCLyoLPhiPLAWkKPGWEGdCjl+Ao1KCx7KROH/Z0u9ERG4UG360/um7pPd1B jQlvU4DDc8w/hCl/ryAMtmE0XIPGD6UCO5jmeUXh9j6goSHz3zPv6QwbXci6BDKS1eLnINn6/QQL6 l8MXb/h7Ju7sX2GhGF7CVqNkWZKAZ++xwkQ1U9gEIN3nMtDybLEpjFGgKdQze9AFzZdZBekYbZMVY 96z0Cg56+JaW2YuDujoV7aEZXNiemCtPS/UUm+ccm2OrNpvMYn6n86WTgbQqYGNsN7ZUpxFAP1vbJ c8S2HAsJIrkWnGIKkOJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEB9-007TaW-RT; Thu, 25 Nov 2021 12:48:44 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE96-007Sod-3h for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:38 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C3CD61106; Thu, 25 Nov 2021 12:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844395; bh=Dy8qixfk57rxiBBpn+qUTpl4vWEooJOjRKRfTNJLD/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bij3g2C/t7Mf00IbUdKDfY+HDz0dRyV/6sQFImcbYYDCwQTYPPh3g/g7cXQD8rb9s 0QsFyQ7NrGavpa385+PNBioY3/GJj3rLoOHrg1dDsg9Q8RO5sKL3V3vruiD92w33bx rYMIWtoc5FoCU5WvyG3cDgEsxophgKKGjOTpflxQRNYwTKjPLkwIq4qdRb+u2lw2zd 8hVrfgvGxq/oO8zbxocOABbESreRdJjQ5FuO9yF1CEN83PYMzZFyIXhwpLS5TDET2q je/wkVobQnaA8h3+CtFVbsKdqAJPoFYwkonmG2d3vlKGV+NysCh5yQiIaxZ95Q7Tm6 C0W9to3icYTvg== Received: by pali.im (Postfix) id 5B737EDE; Thu, 25 Nov 2021 13:46:35 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/15] PCI: mvebu: Disallow mapping interrupts on emulated bridges Date: Thu, 25 Nov 2021 13:45:55 +0100 Message-Id: <20211125124605.25915-6-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044636_217621_69E8516B X-CRM114-Status: GOOD ( 13.02 ) 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 Interrupt support on mvebu emulated bridges is not implemented yet. So properly indicate return value to callers that they cannot request interrupts from emulated bridge. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 19c6ee298442..a3df352d440e 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -705,6 +705,15 @@ static struct pci_ops mvebu_pcie_ops = { .write = mvebu_pcie_wr_conf, }; +static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) +{ + /* Interrupt support on mvebu emulated bridges is not implemented yet */ + if (dev->bus->number == 0) + return 0; /* Proper return code 0 == NO_IRQ */ + + return of_irq_parse_and_map_pci(dev, slot, pin); +} + static resource_size_t mvebu_pcie_align_resource(struct pci_dev *dev, const struct resource *res, resource_size_t start, @@ -1119,6 +1128,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev) bridge->sysdata = pcie; bridge->ops = &mvebu_pcie_ops; bridge->align_resource = mvebu_pcie_align_resource; + bridge->map_irq = mvebu_pcie_map_irq; return pci_host_probe(bridge); } From patchwork Thu Nov 25 12:45:56 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: 12693658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F33EAC433EF for ; Thu, 25 Nov 2021 12:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=Qw2SsYfEdvP3UGJkC7yLfCiRu0hxPyHBaGHOLFeWDQY=; b=ANSmlKnanTfu0N eCcjJMN0GP04K8WnRb9vU3V0CBBnQToV2f7LXdnzeePSBOLpSsXjU6yt5NZwgiLadEbxjvA8baOm5 1uyGuD6OLwCcXEf9EvlKjKeWo92ZFtOuM6ACZVkTVchGIHmc82edoZMj6Xn+F6/5LXPdVZ+MReNR8 j/A6P1rSRFDiQojLc9LUDcT25iKddYlh6VXfjTNCbwvZVll3GR/XPKV3sXOlO/6FqU/zgzj+pHCxX weujWRW3/carMxlJpThx+2avuwzUMaMdABFOjU5YUj2sICTMlDtcV5DsuDPTNFSCNZbOwviabjUuU PbTBJ7JIjr73hBom4LeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqED9-007Uo9-Az; Thu, 25 Nov 2021 12:50:47 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE99-007SpG-GB for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:41 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7750D61139; Thu, 25 Nov 2021 12:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844399; bh=8IVaDVY9hPRIGDZRDN90aFjLyHB9vSl+f8YJ0WtixNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rEwyH3uNfHbBqv91vf66yCBCcd+vPBv2NFDtCdRxmaEbxzVZFKfzIBhUntF7oCDHs RWeiQYola42948pTu9MtHMtmCjjnbtIzLzOsc1DEbKlKyU59CSjNTfUFCCgk2MXs9v N+Gsu7p45MG2E56JNfAfKxQ8Ed2BM7MaQ0bd3oqmAEoWgIOuS8C9/oGEpXfVkbpNrM 82LYNbCfpkB+iMxy4atLGUUz1yhHeD7NkpLestOwtcg5+fBlRiI8kQkWtuDbXsd2Ww iWrUeHXCRyRqqowtQSyigEKU9rU7VVaT8hc5uYnmBKPMx3PW6AxPep/5c8rbaYvqlp gNeyoJIiHdjGQ== Received: by pali.im (Postfix) id 57DC467E; Thu, 25 Nov 2021 13:46:36 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/15] PCI: mvebu: Fix support for bus mastering and PCI_COMMAND on emulated bridge Date: Thu, 25 Nov 2021 13:45:56 +0100 Message-Id: <20211125124605.25915-7-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044639_618268_84E17FBE X-CRM114-Status: GOOD ( 13.92 ) 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 According to PCI specifications bits [0:2] of Command Register, this should be by default disabled on reset. So explicitly disable these bits at early beginning of driver initialization. Also remove code which unconditionally enables all 3 bits and let kernel code (via pci_set_master() function) to handle bus mastering of PCI Bridge via emulated PCI_COMMAND on emulated bridge. Adjust existing functions mvebu_pcie_handle_iobase_change() and mvebu_pcie_handle_membase_change() to handle PCI_IO_BASE and PCI_MEM_BASE registers correctly even when bus mastering on emulated bridge is disabled. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 52 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index a3df352d440e..32694763e930 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -226,16 +226,14 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) { u32 cmd, mask; - /* Point PCIe unit MBUS decode windows to DRAM space. */ - mvebu_pcie_setup_wins(port); - - /* Master + slave enable. */ + /* Disable Root Bridge I/O space, memory space and bus mastering. */ cmd = mvebu_readl(port, PCIE_CMD_OFF); - cmd |= PCI_COMMAND_IO; - cmd |= PCI_COMMAND_MEMORY; - cmd |= PCI_COMMAND_MASTER; + cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); mvebu_writel(port, cmd, PCIE_CMD_OFF); + /* Point PCIe unit MBUS decode windows to DRAM space. */ + mvebu_pcie_setup_wins(port); + /* Enable interrupt lines A-D. */ mask = mvebu_readl(port, PCIE_MASK_OFF); mask |= PCIE_MASK_ENABLE_INTS; @@ -385,8 +383,7 @@ static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) /* Are the new iobase/iolimit values invalid? */ if (conf->iolimit < conf->iobase || - conf->iolimitupper < conf->iobaseupper || - !(conf->command & PCI_COMMAND_IO)) { + conf->iolimitupper < conf->iobaseupper) { mvebu_pcie_set_window(port, port->io_target, port->io_attr, &desired, &port->iowin); return; @@ -423,8 +420,7 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) struct pci_bridge_emul_conf *conf = &port->bridge.conf; /* Are the new membase/memlimit values invalid? */ - if (conf->memlimit < conf->membase || - !(conf->command & PCI_COMMAND_MEMORY)) { + if (conf->memlimit < conf->membase) { mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, &desired, &port->memwin); return; @@ -444,6 +440,24 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) &port->memwin); } +static pci_bridge_emul_read_status_t +mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge, + int reg, u32 *value) +{ + struct mvebu_pcie_port *port = bridge->data; + + switch (reg) { + case PCI_COMMAND: + *value = mvebu_readl(port, PCIE_CMD_OFF); + break; + + default: + return PCI_BRIDGE_EMUL_NOT_HANDLED; + } + + return PCI_BRIDGE_EMUL_HANDLED; +} + static pci_bridge_emul_read_status_t mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, int reg, u32 *value) @@ -498,17 +512,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge, switch (reg) { case PCI_COMMAND: - { - if (!mvebu_has_ioport(port)) - conf->command &= ~PCI_COMMAND_IO; - - if ((old ^ new) & PCI_COMMAND_IO) - mvebu_pcie_handle_iobase_change(port); - if ((old ^ new) & PCI_COMMAND_MEMORY) - mvebu_pcie_handle_membase_change(port); + if (!mvebu_has_ioport(port)) { + conf->command = cpu_to_le16( + le16_to_cpu(conf->command) & ~PCI_COMMAND_IO); + new &= ~PCI_COMMAND_IO; + } + mvebu_writel(port, new, PCIE_CMD_OFF); break; - } case PCI_IO_BASE: /* @@ -575,6 +586,7 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, } static struct pci_bridge_emul_ops mvebu_pci_bridge_emul_ops = { + .read_base = mvebu_pci_bridge_emul_base_conf_read, .write_base = mvebu_pci_bridge_emul_base_conf_write, .read_pcie = mvebu_pci_bridge_emul_pcie_conf_read, .write_pcie = mvebu_pci_bridge_emul_pcie_conf_write, From patchwork Thu Nov 25 12:45:57 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: 12693656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00C0DC433EF for ; Thu, 25 Nov 2021 12:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=kSHp7fSWwx5dJnNDHVdKMptDihlb4Kl9aYYSbY0Eew0=; b=nCfEIYD+xZl7rD i7dtCKD3ex1fSlFk6SYcqumIlR9UlbhDntNL40gwBl2O9g89s2X8Iz6fi6K20f7K0PCtP3DKcfxrJ tQqLmV6MGFvkuoCkloyRsbECmPUsTjIjWnq2/8QRly8iSqU7YtfKO0FuGu6xoj+yWqAwAf8m/rtxg InhJc1HhQ3V9GOXrkiACPkws/vEjDVSHdM9y22d0x2ySoyuSOypQkHPWKZB6dycWkIorDslOdsRse kTa7ZbzRIuoJa6QZi3+eZvA7huPfCADOo/qhws/tHbelErbKzMSnm4/bHDf5PVJw4GJg1YCP143qG u77f3kZekjnBSUD9E8pQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqECE-007UBO-6U; Thu, 25 Nov 2021 12:49:50 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE98-007Spo-58 for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:39 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9CA366112D; Thu, 25 Nov 2021 12:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844397; bh=M7RVNYqJpq9GBdt/IbkDk02dbz1vB+spQULec4Ir+Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ixvmxJhjksDOJD4scZVavPK6vsC14fkStyOjsYuJyH6kp7Kk13lwTuv+JlEAY6KKy hD99qv3k1nuFILREDjCQTp0fOCXertNrKjjHTFFFya53mniotvv7Pzhhf2iFGZJYbQ Fch4YnLZbxjcBlnF9/XhR/BDBLRJ5IHi5uSPaQt4qkxebJG8Izb5v42VnzxXDhq4a/ u5AyJ8GOVCjzWzwkSr2i2EaJlbxuvyQ4KJZrntNqd6TeLeVDLJpIzJQg3IKe6sS+FO 1RnQI96aAfz4anv6RGm6dblkqVqkeZJuOdM/ZNx0/tYQtBshPZWcw7Mgfb6qDSKs8h Uy5lcmVH3PnkA== Received: by pali.im (Postfix) id 5D6DAEDE; Thu, 25 Nov 2021 13:46:37 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/15] PCI: mvebu: Do not modify PCI IO type bits in conf_write Date: Thu, 25 Nov 2021 13:45:57 +0100 Message-Id: <20211125124605.25915-8-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044638_263766_A22B4128 X-CRM114-Status: GOOD ( 10.11 ) 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 PCI IO type bits are already initialized in mvebu_pci_bridge_emul_init() function and only when IO support is enabled. These type bits are read-only and pci-bridge-emul.c code already does not allow to modify them from upper layers. When IO support is disabled then all IO registers should be read-only and return zeros. Therefore do not modify PCI IO type bits in mvebu_pci_bridge_emul_base_conf_write() callback. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 32694763e930..a0b661972436 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -522,13 +522,6 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge, break; case PCI_IO_BASE: - /* - * We keep bit 1 set, it is a read-only bit that - * indicates we support 32 bits addressing for the - * I/O - */ - conf->iobase |= PCI_IO_RANGE_TYPE_32; - conf->iolimit |= PCI_IO_RANGE_TYPE_32; mvebu_pcie_handle_iobase_change(port); break; From patchwork Thu Nov 25 12:45:58 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: 12693657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE0D9C433EF for ; Thu, 25 Nov 2021 12:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=ACOdBOk/caehVh0owxfF3Ve4VDJzG+1BtKo+uYiSetg=; b=CLi/huQwXqym2x eNGJl4Fksmq+oLC3Zh2tbsE6GjWJyLIPv2L70PEIcvPRvkTEWGmK+bwesqye+jRtGKvthuqkqMDYe qcKr7PUPpoUuR1pqtO3qpCHfs787DaKEcmalXrBAhFITEzDr8LUSK0u8pD7EA/3B+ajh6K2uKUSH/ Rv7yAdSaKLrPLpgltyL7p9wcQRMDjbNNkPvCqsFNrrh4ZelcNK41OVB7koCeByng3k8GFKifcjB6L 8hfR0kjKrxV76sT9BajhEBo8WRJBgZO/Bq76zUg4/7xmJPCVBLSYDXb/Q7HjaDGC7+gpGj5l5C/DX YN5Mk7p7/uHf27yPTLrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqECk-007UYK-1c; Thu, 25 Nov 2021 12:50:22 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE99-007Sqa-Bg for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:41 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFF5D6113D; Thu, 25 Nov 2021 12:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844399; bh=G2rKjdlzxb1XNs2lbCrBQXhcMuLp67aIGgdoCkybPjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eEq9SR3JH7/OWh15A1+wZOPKWoTqJbLSnrH+8yz3ixHgFXG37Tq+W1uFKWpszTXRq XlP4+1v9Q7gzV9LE9RXylQmGsaWIVLcxLg63XATtmj430LS1g4o4EDWAcGuwgYKCKK BpyzTsP4MMoujXGVuohFEClGOtXEsHizpDRIJuRm6RbyS9ILXJXPHyum4FH/zmvnNy 5/G6MlhCqrSE5fREYPd7Xqxy/ciNCzznS+GxQq9G8PEO2QVWJ3WV8w3djJNE8mcfd6 /G5Dx4JntuZvmVP6Wtj9vWJvBKnhkAqtdAYaQ9gUAidalAqqTSaOH5im36C3HPVcrC y7fTtPZz9q7Fg== Received: by pali.im (Postfix) id 6EA43EDE; Thu, 25 Nov 2021 13:46:38 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/15] PCI: mvebu: Propagate errors when updating PCI_IO_BASE and PCI_MEM_BASE registers Date: Thu, 25 Nov 2021 13:45:58 +0100 Message-Id: <20211125124605.25915-9-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044639_495203_DC3B544F X-CRM114-Status: GOOD ( 16.01 ) 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 Properly propagate failure from mvebu_pcie_add_windows() function back to the caller mvebu_pci_bridge_emul_base_conf_write() and correctly updates PCI_IO_BASE, PCI_MEM_BASE and PCI_IO_BASE_UPPER16 registers on error. On error set base value higher than limit value which indicates that address range is disabled. When IO is unsupported then let IO registers zeroed as required by PCIe base specification. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 82 ++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index a0b661972436..12afa565bfcf 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -315,7 +315,7 @@ static void mvebu_pcie_del_windows(struct mvebu_pcie_port *port, * areas each having a power of two size. We start from the largest * one (i.e highest order bit set in the size). */ -static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port, +static int mvebu_pcie_add_windows(struct mvebu_pcie_port *port, unsigned int target, unsigned int attribute, phys_addr_t base, size_t size, phys_addr_t remap) @@ -336,7 +336,7 @@ static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port, &base, &end, ret); mvebu_pcie_del_windows(port, base - size_mapped, size_mapped); - return; + return ret; } size -= sz; @@ -345,16 +345,20 @@ static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port, if (remap != MVEBU_MBUS_NO_REMAP) remap += sz; } + + return 0; } -static void mvebu_pcie_set_window(struct mvebu_pcie_port *port, +static int mvebu_pcie_set_window(struct mvebu_pcie_port *port, unsigned int target, unsigned int attribute, const struct mvebu_pcie_window *desired, struct mvebu_pcie_window *cur) { + int ret; + if (desired->base == cur->base && desired->remap == cur->remap && desired->size == cur->size) - return; + return 0; if (cur->size != 0) { mvebu_pcie_del_windows(port, cur->base, cur->size); @@ -369,30 +373,35 @@ static void mvebu_pcie_set_window(struct mvebu_pcie_port *port, } if (desired->size == 0) - return; + return 0; + + ret = mvebu_pcie_add_windows(port, target, attribute, desired->base, + desired->size, desired->remap); + if (ret) { + cur->size = 0; + cur->base = 0; + return ret; + } - mvebu_pcie_add_windows(port, target, attribute, desired->base, - desired->size, desired->remap); *cur = *desired; + return 0; } -static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) +static int mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) { struct mvebu_pcie_window desired = {}; struct pci_bridge_emul_conf *conf = &port->bridge.conf; /* Are the new iobase/iolimit values invalid? */ if (conf->iolimit < conf->iobase || - conf->iolimitupper < conf->iobaseupper) { - mvebu_pcie_set_window(port, port->io_target, port->io_attr, - &desired, &port->iowin); - return; - } + conf->iolimitupper < conf->iobaseupper) + return mvebu_pcie_set_window(port, port->io_target, port->io_attr, + &desired, &port->iowin); if (!mvebu_has_ioport(port)) { dev_WARN(&port->pcie->pdev->dev, "Attempt to set IO when IO is disabled\n"); - return; + return -EOPNOTSUPP; } /* @@ -410,21 +419,19 @@ static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) desired.remap) + 1; - mvebu_pcie_set_window(port, port->io_target, port->io_attr, &desired, - &port->iowin); + return mvebu_pcie_set_window(port, port->io_target, port->io_attr, &desired, + &port->iowin); } -static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) +static int mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) { struct mvebu_pcie_window desired = {.remap = MVEBU_MBUS_NO_REMAP}; struct pci_bridge_emul_conf *conf = &port->bridge.conf; /* Are the new membase/memlimit values invalid? */ - if (conf->memlimit < conf->membase) { - mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, - &desired, &port->memwin); - return; - } + if (conf->memlimit < conf->membase) + return mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, + &desired, &port->memwin); /* * We read the PCI-to-PCI bridge emulated registers, and @@ -436,8 +443,8 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) desired.size = (((conf->memlimit & 0xFFF0) << 16) | 0xFFFFF) - desired.base + 1; - mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, &desired, - &port->memwin); + return mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, &desired, + &port->memwin); } static pci_bridge_emul_read_status_t @@ -522,15 +529,36 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge, break; case PCI_IO_BASE: - mvebu_pcie_handle_iobase_change(port); + if ((mask & 0xffff) && mvebu_pcie_handle_iobase_change(port)) { + /* On error disable IO range */ + conf->iobase &= ~0xf0; + conf->iolimit &= ~0xf0; + conf->iobaseupper = cpu_to_le16(0x0000); + conf->iolimitupper = cpu_to_le16(0x0000); + if (mvebu_has_ioport(port)) + conf->iobase |= 0xf0; + } break; case PCI_MEMORY_BASE: - mvebu_pcie_handle_membase_change(port); + if (mvebu_pcie_handle_membase_change(port)) { + /* On error disable mem range */ + conf->membase = cpu_to_le16(le16_to_cpu(conf->membase) & ~0xfff0); + conf->memlimit = cpu_to_le16(le16_to_cpu(conf->memlimit) & ~0xfff0); + conf->membase = cpu_to_le16(le16_to_cpu(conf->membase) | 0xfff0); + } break; case PCI_IO_BASE_UPPER16: - mvebu_pcie_handle_iobase_change(port); + if (mvebu_pcie_handle_iobase_change(port)) { + /* On error disable IO range */ + conf->iobase &= ~0xf0; + conf->iolimit &= ~0xf0; + conf->iobaseupper = cpu_to_le16(0x0000); + conf->iolimitupper = cpu_to_le16(0x0000); + if (mvebu_has_ioport(port)) + conf->iobase |= 0xf0; + } break; case PCI_PRIMARY_BUS: From patchwork Thu Nov 25 12:45:59 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: 12693659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 612AFC433EF for ; Thu, 25 Nov 2021 12:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=cS/ldVaiqbL1thYKyZzOAZ2rBRzhl3OREee/yTObhvI=; b=dB2Z7x9N+d8FJ5 5RY/N7Ojg44OJeyETcbmqlWWMY+VzfoGcP/vGggHWOTQJCD6Z71r689p6+O4EtE5atXHVU5CG/KlS vxtPA/ZRjYcvRPF0rqV5pxbmtOriNpBaNtJ4MEgd9ufv8pzptbKH5qvpLZJJZ+rZJcdJSoSPRxPr+ 84VUsomH6aShaeqLpYvG0zds+DqDuz+uJvhB/ZojJqiDo16daDoaEvdyEf0HNdseBiAQ7PVSC/efd /YLyFvJYVxPdVhNJtFW6RqimRjuii+ioCZfJvVLUDUzZFLa/umLIonGb6PTmXRyF2v2DcHSB+VaNp ZXo+NJuhUTJNVDa6jW4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEDc-007V3t-2B; Thu, 25 Nov 2021 12:51:16 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9A-007Spo-1I for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:41 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B93EA610D2; Thu, 25 Nov 2021 12:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844399; bh=HAwmzdzGbp3IRdqXEag5++Pgk0BJ9we/P6AQ8qPIyTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRIycqlRwe0l1Cpe9qadszwuU8qNRH+vVX/HsiQnK7rhxqghhwTZ4uy32NGKbh8qs GR2RQ3Bj2IMZqTezqHB0X0pVrbnqDMrQLzK9n+jfePCfgRp69th2x1ML2jOzYp44aW MecvdFbDzJtyGiz4VtNejtEViTY3tOAZO2TMGG9a3vda7x/8nKQ4ELUBtddz1ViJUi xk6xMwAgeB8z7GXWgXZGGHwieC02Vop7XQsMvq3Y+GHIwZTj8VB7TDhMnx8ReGIYeo kcCSX8WmUcKVL7CsKG7iwU9yt18Low8+yJW9nVnsTTHTRV3eKeBmUAa638kq2n6B5w /viQaVb0SXsLA== Received: by pali.im (Postfix) id 77E46EDE; Thu, 25 Nov 2021 13:46:39 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/15] PCI: mvebu: Setup PCIe controller to Root Complex mode Date: Thu, 25 Nov 2021 13:45:59 +0100 Message-Id: <20211125124605.25915-10-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044640_174282_F7EB0CC7 X-CRM114-Status: GOOD ( 10.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 This driver operates only in Root Complex mode, so ensure that hardware is properly configured in Root Complex mode. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 12afa565bfcf..017ae9f869ac 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -56,6 +56,7 @@ #define PCIE_MASK_ENABLE_INTS 0x0f000000 #define PCIE_CTRL_OFF 0x1a00 #define PCIE_CTRL_X1_MODE 0x0001 +#define PCIE_CTRL_RC_MODE BIT(1) #define PCIE_STAT_OFF 0x1a04 #define PCIE_STAT_BUS 0xff00 #define PCIE_STAT_DEV 0x1f0000 @@ -224,7 +225,12 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) { - u32 cmd, mask; + u32 ctrl, cmd, mask; + + /* Setup PCIe controller to Root Complex mode. */ + ctrl = mvebu_readl(port, PCIE_CTRL_OFF); + ctrl |= PCIE_CTRL_RC_MODE; + mvebu_writel(port, ctrl, PCIE_CTRL_OFF); /* Disable Root Bridge I/O space, memory space and bus mastering. */ cmd = mvebu_readl(port, PCIE_CMD_OFF); From patchwork Thu Nov 25 12:46:00 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: 12693660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6381C433EF for ; Thu, 25 Nov 2021 12:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=RRpvgd9gYqNM6GIlQHVp3Rkv+rCrnNowsN580YBTZ+A=; b=IEq7/xnlP0lNDL 0dVnA9hmUhoCwRPl1Gn50zZCopMhTwVUynfmt6RFrWrkciyVlnOPYrewoC65OOCikG2pwHFRozPJU /FKgkxWgkZHc0RykIwiBcQK2zPeRWAuBCgpJOX9W7MFwvUdOKLJUJPIEwhFp0Gda2+glX5hySQAJ2 QQzgCSURrHFlEn6hMO3o4vGDkZ5HPRzeIjFMIhpwm0kDPCymV73xsyCsYBXnzm5zj6E6nDtDML0t5 tOtkdZg13YRylQfZVcZULXqU99+/c3NyuzL1SeTARoLhNoW8M/tjbYnHAHZcAwmlCGm8qpLA+rh3Q BZltMbbIzfmSEaPuvesQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEE9-007VKs-Hu; Thu, 25 Nov 2021 12:51:49 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9B-007Sqa-FG for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:42 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 312CC610F9; Thu, 25 Nov 2021 12:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844401; bh=I22+rZTnzG+DDCPyUEnV19dYpz4cUH9W+Ns6gKnI/bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GjVCqedx94OmhYlagOgMOGMSEpsMVcpvrjaii9/oLYfZ+dIP4NAKEhhvly67MOgJo fJUmifie6FJwo2wUCExn+EZ5MI11dPLKBQIUrhm/zhkwnl6OEZ8UMiX6q+zgb8UdKV t4Jv5i1cVtFsK+Kq/nrw58A0ABDbcxY9R4Thkvq4qNMOnOv+5QqAQLUKMUMHrtdRI1 JNf3J6y21K2JNRS10MM0spUFI6P5Wib+7kZPvtFQDrCI5rnrqjW2PWY/GqXXPTJtUB eOl0XW5GwHXTiUU1O/Z67bJMpM/amWj1r+dk7j3n3P0Xz0hAMJWrivQh6eNA88KPQh LwLQjFtRvh+kQ== Received: by pali.im (Postfix) id 8AD9767E; Thu, 25 Nov 2021 13:46:40 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/15] PCI: mvebu: Set PCI Bridge Class Code to PCI Bridge Date: Thu, 25 Nov 2021 13:46:00 +0100 Message-Id: <20211125124605.25915-11-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044641_612405_589D4D07 X-CRM114-Status: GOOD ( 14.50 ) 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 default value of Class Code of this bridge corresponds to a Memory controller, though. This is probably relict from the past when old Marvell/Galileo PCI-based controllers were used as standalone PCI device for connecting SDRAM or workaround for PCs with broken BIOS. Details are in commit 36de23a4c5f0 ("MIPS: Cobalt: Explain GT64111 early PCI fixup"). Change the Class Code to correspond to a PCI Bridge. Add comment explaining this change. Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 017ae9f869ac..4edce441901c 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -225,7 +225,7 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) { - u32 ctrl, cmd, mask; + u32 ctrl, cmd, dev_rev, mask; /* Setup PCIe controller to Root Complex mode. */ ctrl = mvebu_readl(port, PCIE_CTRL_OFF); @@ -237,6 +237,32 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); mvebu_writel(port, cmd, PCIE_CMD_OFF); + /* + * Change Class Code of PCI Bridge device to PCI Bridge (0x6004) + * because default value is Memory controller (0x5080). + * + * Note that this mvebu PCI Bridge does not have compliant Type 1 + * Configuration Space. Header Type is reported as Type 0 and it + * has format of Type 0 config space. + * + * Moreover Type 0 BAR registers (ranges 0x10 - 0x28 and 0x30 - 0x34) + * have the same format in Marvell's specification as in PCIe + * specification, but their meaning is totally different and they do + * different things: they are aliased into internal mvebu registers + * (e.g. PCIE_BAR_LO_OFF) and these should not be changed or + * reconfigured by pci device drivers. + * + * Therefore driver uses emulation of PCI Bridge which emulates + * access to configuration space via internal mvebu registers or + * emulated configuration buffer. Driver access these PCI Bridge + * directly for simplification, but these registers can be accessed + * also via standard mvebu way for accessing PCI config space. + */ + dev_rev = mvebu_readl(port, PCIE_DEV_REV_OFF); + dev_rev &= ~0xffffff00; + dev_rev |= (PCI_CLASS_BRIDGE_PCI << 8) << 8; + mvebu_writel(port, dev_rev, PCIE_DEV_REV_OFF); + /* Point PCIe unit MBUS decode windows to DRAM space. */ mvebu_pcie_setup_wins(port); From patchwork Thu Nov 25 12:46:01 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: 12693661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62DA1C433F5 for ; Thu, 25 Nov 2021 12:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=oZmO8c5jKuJOmLYtpx7hduRDG3/puN0k83jfEdAdOOs=; b=UI9pDVvhJbhNX5 gm8tS4CNA2oy8P3at6z9QxLKveuc/x4CalGxeq5rRX6Jv08qCyz5TrgjjV4RmFpMyniui5tMdYwUH xWrcG3QENtY3ix5HDnBwQxskrPgNBIPBtfH7loYpxAUCGoydGyis2MG0CA25GrUZXddvIbCx9tfLN 4zFxPGgU1vBif253zUucZKTkRBbWSWXBMFmT3+hMX1B8P5vGERmr8E/iB8xdIHyH21sN5NbX1fU4o w4SkSin8hWbPfJJzB2H0PsRdgZUFquoa0sSL8uABCMRe332gL81B1soqHWkHLDEydcJJlOdDl58gh SDbgwFGny0N2kfygd8Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEEg-007VaQ-NX; Thu, 25 Nov 2021 12:52:22 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9C-007SpG-Ce for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5F1D6112E; Thu, 25 Nov 2021 12:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844402; bh=Mty959mLbQPgGqYK1YgoWBQXMBWeDHeOIHaBNRXQLDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZ8jAeCM1FvwWsjUuBg22F3rqTn5Gxri9xshTqL27+M4DZFIHFMqelcZo4gZzIB7k YRWlQcuuT9pTyetEgh+/jrN1DhhrNriQJ+FSS/eA+8enUxQGrTvOvT3WmgRszWIa/r IiwwScu5hGrGYuD0e+Yz1Di/hTXGBBaoDr3wV5P/9RWhE9qr4uJEDOyYj5nXIVf4IJ hyXUkgYY7TSYEdyIQ27zD4WOUV8b5jL/Lvey24mJ5AimP73nJXvzofRa3vtK1Q5H3a sFz4rKoY3CghoBHbHSpaWLXcUUC+cnE9BobMHgArFX0kVd6uiJVP2P+8C3bmCx32XR ALDcUhSAkkHeg== Received: by pali.im (Postfix) id A5A7867E; Thu, 25 Nov 2021 13:46:41 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/15] PCI: mvebu: Fix configuring secondary bus of PCIe Root Port via emulated bridge Date: Thu, 25 Nov 2021 13:46:01 +0100 Message-Id: <20211125124605.25915-12-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044642_584263_3FD72F1F X-CRM114-Status: GOOD ( 21.82 ) 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 It looks like that mvebu PCIe controller has for each PCIe link fully independent PCIe host bridge and so every PCIe Root Port is isolated not only on its own bus but also isolated from each others. But in past device tree structure was defined to put all PCIe Root Ports (as PCI Bridge devices) into one root bus 0 and this bus is emulated by pci-mvebu.c driver. Probably reason for this decision was incorrect understanding of PCIe topology of these Armada SoCs and also reason of misunderstanding how is PCIe controller generating Type 0 and Type 1 config requests (it is fully different compared to other drivers). Probably incorrect setup leaded to very surprised things like having PCIe Root Port (PCI Bridge device, with even incorrect Device Class set to Memory Controller) and the PCIe device behind the Root Port on the same PCI bus, which obviously was needed to somehow hack (as these two devices cannot be in reality on the same bus). Properly set mvebu local bus number and mvebu local device number based on PCI Bridge secondary bus number configuration. Also correctly report configured secondary bus number in config space. And explain in driver comment why this setup is correct. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 98 +++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 4edce441901c..36fbdc4f0e06 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -127,6 +127,11 @@ static bool mvebu_pcie_link_up(struct mvebu_pcie_port *port) return !(mvebu_readl(port, PCIE_STAT_OFF) & PCIE_STAT_LINK_DOWN); } +static u8 mvebu_pcie_get_local_bus_nr(struct mvebu_pcie_port *port) +{ + return (mvebu_readl(port, PCIE_STAT_OFF) & PCIE_STAT_BUS) >> 8; +} + static void mvebu_pcie_set_local_bus_nr(struct mvebu_pcie_port *port, int nr) { u32 stat; @@ -490,6 +495,20 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge, *value = mvebu_readl(port, PCIE_CMD_OFF); break; + case PCI_PRIMARY_BUS: { + /* + * From the whole 32bit register we support reading from HW only + * secondary bus number which is mvebu local bus number. + * Other bits are retrieved only from emulated config buffer. + */ + __le32 *cfgspace = (__le32 *)&bridge->conf; + u32 val = le32_to_cpu(cfgspace[PCI_PRIMARY_BUS / 4]); + val &= ~0xff00; + val |= mvebu_pcie_get_local_bus_nr(port) << 8; + *value = val; + break; + } + default: return PCI_BRIDGE_EMUL_NOT_HANDLED; } @@ -594,7 +613,8 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge, break; case PCI_PRIMARY_BUS: - mvebu_pcie_set_local_bus_nr(port, conf->secondary_bus); + if (mask & 0xff00) + mvebu_pcie_set_local_bus_nr(port, conf->secondary_bus); break; default: @@ -1186,8 +1206,84 @@ static int mvebu_pcie_probe(struct platform_device *pdev) continue; } + /* + * PCIe topology exported by mvebu hw is quite complicated. In + * reality has something like N fully independent host bridges + * where each host bridge has one PCIe Root Port (which acts as + * PCI Bridge device). Each host bridge has its own independent + * internal registers, independent access to PCI config space, + * independent interrupt lines, independent window and memory + * access configuration. But additionally there is some kind of + * peer-to-peer support between PCIe devices behind different + * host bridges limited just to forwarding of memory and I/O + * transactions (forwarding of error messages and config cycles + * is not supported). So we could say there are N independent + * PCIe Root Complexes. + * + * For this kind of setup DT should have been structured into + * N independent PCIe controllers / host bridges. But instead + * structure in past was defined to put PCIe Root Ports of all + * host bridges into one bus zero, like in classic multi-port + * Root Complex setup with just one host bridge. + * + * This means that pci-mvebu.c driver provides "virtual" bus 0 + * on which registers all PCIe Root Ports (PCI Bridge devices) + * specified in DT by their BDF addresses and virtually routes + * PCI config access of each PCI bridge device to specific PCIe + * host bridge. + * + * Normally PCI Bridge should choose between Type 0 and Type 1 + * config requests based on primary and secondary bus numbers + * configured on the bridge itself. But because mvebu PCI Bridge + * does not have registers for primary and secondary bus numbers + * in its config space, it determinates type of config requests + * via its own custom way. + * + * There are two options how mvebu determinate type of config + * request. + * + * 1. If Secondary Bus Number Enable bit is not set or is not + * available (applies for pre-XP PCIe controllers) then Type 0 + * is used if target bus number equals Local Bus Number (bits + * [15:8] in register 0x1a04) and target device number differs + * from Local Device Number (bits [20:16] in register 0x1a04). + * Type 1 is used if target bus number differs from Local Bus + * Number. And when target bus number equals Local Bus Number + * and target device equals Local Device Number then request is + * routed to Local PCI Bridge (PCIe Root Port). + * + * 2. If Secondary Bus Number Enable bit is set (bit 7 in + * register 0x1a2c) then mvebu hw determinate type of config + * request like compliant PCI Bridge based on primary bus number + * which is configured via Local Bus Number (bits [15:8] in + * register 0x1a04) and secondary bus number which is configured + * via Secondary Bus Number (bits [7:0] in register 0x1a2c). + * Local PCI Bridge (PCIe Root Port) is available on primary bus + * as device with Local Device Number (bits [20:16] in register + * 0x1a04). + * + * Secondary Bus Number Enable bit is disabled by default and + * option 2. is not available on pre-XP PCIe controllers. Hence + * this driver always use option 1. + * + * Basically it means that primary and secondary buses shares + * one virtual number configured via Local Bus Number bits and + * Local Device Number bits determinates if accessing primary + * or secondary bus. Set Local Device Number to 1 and redirect + * all writes of PCI Bridge Secondary Bus Number register to + * Local Bus Number (bits [15:8] in register 0x1a04). + * + * So when accessing devices on buses behind secondary bus + * number it would work correctly. And also when accessing + * device 0 at secondary bus number via config space would be + * correctly routed to secondary bus. Due to issues described + * in mvebu_pcie_setup_hw(), PCI Bridges at primary bus (zero) + * are not accessed directly via PCI config space but rarher + * indirectly via kernel emulated PCI bridge driver. + */ mvebu_pcie_setup_hw(port); mvebu_pcie_set_local_dev_nr(port, 1); + mvebu_pcie_set_local_bus_nr(port, 0); } bridge->sysdata = pcie; From patchwork Thu Nov 25 12:46:02 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: 12693662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 517A0C433EF for ; Thu, 25 Nov 2021 12:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=RZxN2q1/rqA6UGYDM1CcgWwa3vSOhFpyo1e+/p1rvsc=; b=n2LwvNsWZS/NUw L4oyQ9MJF/g1/tVoLcXn0yD37Pxtw9Ha6wwFixAMSBWc4Qj3ubiOQnYxq6YXFukTGgcJ+WQUFkieG Ubuo2XKxYbxtAUWP+CI5xAhqNscRjVL+wWf4ROdyw7Zd8XzTg+rzgAFrsl3KdfZzFK/EAYAIclvIE 0OC8OYKVCT34enVuLau6vvKOQsxOwttmcLBX9KgnHgq4l5M806bka2Y6P8kP2nVRN8j8Px8zySl4t tH81Gr1/eTEjNKkWnrzyOebCGO+pZ7G/cVSeHx9DZQFxTINaRyF/PHaSP/+OH0lM5rGFCIP0jcP0f cyWAekpNW2Vrz3vOOTBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEFA-007VpB-5R; Thu, 25 Nov 2021 12:52:52 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9D-007Sqa-86 for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFC5961131; Thu, 25 Nov 2021 12:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844403; bh=7IW9blK/IMJBVLWjKlB8p1LQPUnBoN7J+3jnRgIKmoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bln5kbB7dLx5PJDb/oLLEqvWOKQ1+NmzcCexth7QJp7mASDPM8LN05ujos6LP1die YP5RhuPz8TosihuoAqXObqM6Hz8IcdT/Rd23nd/YZP3U5KmMMqJLJg0srm3wRlrJ9z QKOj77j+j6CK2pcI/Zt/vVAuVZOXmEwrf89UzUUCdqWwJAc+T2dyiuTQT0gWExlN77 MMD50tp2zFGhA2EsXUJ8Y475YGWs66fB8DAVeGB0vMhSgHIYz9GXdls6b1IhaBIw9d Dm91B52G/O1PUO8ZcUUUT67n383bila83NW/P2IQELZGPlCpMR+I4goKC0sddc80i2 izijHrwr0gt3g== Received: by pali.im (Postfix) id B096767E; Thu, 25 Nov 2021 13:46:42 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/15] PCI: mvebu: Fix support for PCI_BRIDGE_CTL_BUS_RESET on emulated bridge Date: Thu, 25 Nov 2021 13:46:02 +0100 Message-Id: <20211125124605.25915-13-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044643_370187_F4BDCED4 X-CRM114-Status: GOOD ( 11.81 ) 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 Hardware supports PCIe Hot Reset via PCIE_CTRL_OFF register. Use it for implementing PCI_BRIDGE_CTL_BUS_RESET bit of PCI_BRIDGE_CONTROL register on emulated bridge. With this change the function pci_reset_secondary_bus() starts working and can reset connected PCIe card. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 36fbdc4f0e06..3075ea98c131 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -57,6 +57,7 @@ #define PCIE_CTRL_OFF 0x1a00 #define PCIE_CTRL_X1_MODE 0x0001 #define PCIE_CTRL_RC_MODE BIT(1) +#define PCIE_CTRL_MASTER_HOT_RESET BIT(24) #define PCIE_STAT_OFF 0x1a04 #define PCIE_STAT_BUS 0xff00 #define PCIE_STAT_DEV 0x1f0000 @@ -509,6 +510,22 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge, break; } + case PCI_INTERRUPT_LINE: { + /* + * From the whole 32bit register we support reading from HW only + * one bit: PCI_BRIDGE_CTL_BUS_RESET. + * Other bits are retrieved only from emulated config buffer. + */ + __le32 *cfgspace = (__le32 *)&bridge->conf; + u32 val = le32_to_cpu(cfgspace[PCI_INTERRUPT_LINE / 4]); + if (mvebu_readl(port, PCIE_CTRL_OFF) & PCIE_CTRL_MASTER_HOT_RESET) + val |= PCI_BRIDGE_CTL_BUS_RESET << 16; + else + val &= ~(PCI_BRIDGE_CTL_BUS_RESET << 16); + *value = val; + break; + } + default: return PCI_BRIDGE_EMUL_NOT_HANDLED; } @@ -617,6 +634,17 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge, mvebu_pcie_set_local_bus_nr(port, conf->secondary_bus); break; + case PCI_INTERRUPT_LINE: + if (mask & (PCI_BRIDGE_CTL_BUS_RESET << 16)) { + u32 ctrl = mvebu_readl(port, PCIE_CTRL_OFF); + if (new & (PCI_BRIDGE_CTL_BUS_RESET << 16)) + ctrl |= PCIE_CTRL_MASTER_HOT_RESET; + else + ctrl &= ~PCIE_CTRL_MASTER_HOT_RESET; + mvebu_writel(port, ctrl, PCIE_CTRL_OFF); + } + break; + default: break; } From patchwork Thu Nov 25 12:46:03 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: 12693663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F822C433F5 for ; Thu, 25 Nov 2021 12:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=NXGn3NEUbHbF1TCS9C9bEKYwlzNb+81Ugbnt0S9FV0Y=; b=kuTQpS3+ziNUuN 5cLxfWJkC5lDkHqn1tMjk3ScsiqUAPA6gt8tKZAHZr4iLppRtpIUGXt8MMSwRdOBQ1Eh7UikqA08W tfEUfZZLECxSPCiJL8DvqYpFh6k/7KEiJIDrbUa0//llUZON1HLO8cVvzf3jSqTyb5yVkECEDqJ1H 35V2y/RJGuDyRf9Tqjd2RUZaIbhDWwh3NnUPZY7TPVXK777kX+BLdwU/YE38w+/LprSnT/Mq8H01O gq9TXgrLBuYIlqZbAI2mb6ZD3KTbqnNfr5gCuG5FhzYq9Hxm4A4SsY4e8PxLaSqnnBwx0iDuyFe75 BeGOV9phubvmYQRCFXbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEG9-007WLh-Tm; Thu, 25 Nov 2021 12:53:54 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9E-007StZ-QQ for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:46 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id EC7A06113A; Thu, 25 Nov 2021 12:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844404; bh=KCtYPffRqVHBtYw7sAB0t28qNlEFwS3xDyAknC6AO+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d95IwIRJOHxQXlTYX3JKRREc2fJIC8ojDIZpx5lM3rcShz1ijwt9y79ybml0xmgmQ q0EgPt15+6aWA0dV/+eESEPlRXwjUSwkCxwfLgI7lwyDjqtCnqzi5aYx4bd77+ipdK Oz//kqL/R5UNQSUTUoLsmDFcdGtpoq56ShnGIC513NW6Rs93Kjq2kap+LpxSCQ2M6n o3Tsa9Rgp6EuAABJpazN8rUv7gQRz2WZjO2wLHJGWonvactjiodkP3dEq6iyw5AeyP L1nZ3OyekGhszZKL/4sJRYFYo5d/5MvtimRkgPyq0PliCvtl+lg3MBjOHcXgM05jtJ 1IWnX8IH1J0Jw== Received: by pali.im (Postfix) id AD86167E; Thu, 25 Nov 2021 13:46:43 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/15] PCI: mvebu: Fix support for PCI_EXP_DEVCTL on emulated bridge Date: Thu, 25 Nov 2021 13:46:03 +0100 Message-Id: <20211125124605.25915-14-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044644_931342_0CAD393C X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. 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 Comment in Armada 370 functional specification is misleading. PCI_EXP_DEVCTL_*RE bits are supported and configures receiving of error interrupts. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 3075ea98c131..c9b736344b56 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -545,9 +545,7 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, break; case PCI_EXP_DEVCTL: - *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL) & - ~(PCI_EXP_DEVCTL_URRE | PCI_EXP_DEVCTL_FERE | - PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_CERE); + *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL); break; case PCI_EXP_LNKCAP: @@ -658,13 +656,6 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, switch (reg) { case PCI_EXP_DEVCTL: - /* - * Armada370 data says these bits must always - * be zero when in root complex mode. - */ - new &= ~(PCI_EXP_DEVCTL_URRE | PCI_EXP_DEVCTL_FERE | - PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_CERE); - mvebu_writel(port, new, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL); break; From patchwork Thu Nov 25 12:46:04 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: 12693665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88A84C433EF for ; Thu, 25 Nov 2021 12:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=qZnnVZuS2lyyPmz1IE9/QpHVmSPFAFvlTzqS3bwWUbw=; b=EJ+bxZWmRFFKK/ j+12dbfBHzD7G7aNG6nmfTCq07vzV89gPFN2ECsOb8fWtHIecvKAWGMK/O4m4jC1MvMlFdZa84leQ R76uFPvdsSg5CvrzQVlUOqjmHiXPC8VtwBV2AJkLpAI4z++yV9lONb3mrsYnBB7bkrY/+SjaiD/9D +ulp23eHpGY1sjDBdxcqDCvFNwPKShfRhMeWP6WKpPkpvAltM1T4j5P12yoGrQdLuC2V2g3nU3Hdz A3AYxXr57CPzYpBsUOQXByiQXlCEVP0DpV8RrctFNYM8GuCWYszFwUUTlAoztTNtLhJwl4pYWzpuD RMh4UQgefJarYxXtdtIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEI1-007XEB-VR; Thu, 25 Nov 2021 12:55:50 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9H-007StZ-Ga for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:48 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id D66DD6113B; Thu, 25 Nov 2021 12:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844407; bh=dOK1Q8ui3OxrTW5NWDaV2x8xsH/B8xAQ7TbI/Tpnk80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N3i3gDaQtNeKWacYBowXh4lVNmS64IGWu9G4Rh9Pz4hA+4kXn33jvUSiTCCKFwqQH 22LZyY4TnoWWip71S+eoO/ECbe3KbafplU4KfAKnG5UccGtuDvILMrOhuxJ2DBmOHb x2hilyEes2645QKw9m33NCSPkU5iSWHN2uynXPrfwfp3NIEulU/u2EEg+ZwscawoP8 21HRl+z6o1Re7aCYDciGDg/R848A4WrW3vsuG8dGiKx3On0EFDppE5tMz8F8+8ds3b 5j+2OWqrvHFav4ZYPqOCb9JVdhKwQvUkOM/9wxzBBG67mOBGG57UmDY5lxy+kKGOCk n0u4OtdaMX4Lg== Received: by pali.im (Postfix) id B4222EDE; Thu, 25 Nov 2021 13:46:44 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/15] PCI: mvebu: Fix support for PCI_EXP_RTSTA on emulated bridge Date: Thu, 25 Nov 2021 13:46:04 +0100 Message-Id: <20211125124605.25915-15-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044647_629303_2393543F X-CRM114-Status: GOOD ( 10.40 ) 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 PME Status bit in Root Status Register (PCIE_RC_RTSTA_OFF) is read-only and can be cleared only by writing 0b to the Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index c9b736344b56..798cf5cff8be 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -52,6 +52,8 @@ PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where) | \ PCIE_CONF_ADDR_EN) #define PCIE_CONF_DATA_OFF 0x18fc +#define PCIE_INT_CAUSE_OFF 0x1900 +#define PCIE_INT_PM_PME BIT(28) #define PCIE_MASK_OFF 0x1910 #define PCIE_MASK_ENABLE_INTS 0x0f000000 #define PCIE_CTRL_OFF 0x1a00 @@ -672,7 +674,14 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, break; case PCI_EXP_RTSTA: - mvebu_writel(port, new, PCIE_RC_RTSTA); + /* + * PME Status bit in Root Status Register (PCIE_RC_RTSTA) + * is read-only and can be cleared only by writing 0b to the + * Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). So + * clear PME via Interrupt Cause. + */ + if (new & PCI_EXP_RTSTA_PME) + mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF); break; } } From patchwork Thu Nov 25 12:46:05 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: 12693664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 756C7C433EF for ; Thu, 25 Nov 2021 12:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=h5SSKQuzELTsOEzirZMsKiDYA/TO1COHWcqFFjA+lzE=; b=kdiuLtiyOAIjSA 1UKnaZP8o7lzzpT5ACRX/s/hM4BnQvq5RGz0wa8dA/yCDXHqiMJyn6NkGnFi9iFopTmnS6o/PebFN FAanHb7SHKcLspmMGP5RLxqbyAbvNW2FakKVtRlnP5l1LuxA+D3CLzEbw5OUemvNuVSt3mhnxmuYx j2oPTtp17jzUSJEIKDkJXicJNDH6W5CBPUGrP0zCLXllVYQnpJjqvfssWU+qwZVttH9IcIeJfZVue 5MBViNMUsmIWdkedf65LKxS27zBtLYgaL/Xevnj+VQ2teKsC5a1eooahI01TrlrlG+IEvfQh+QM9Z eqn65VOlonwJmWeuWq6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqEGv-007Why-KH; Thu, 25 Nov 2021 12:54:42 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqE9G-007SpG-8g for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 12:46:47 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 01D4361100; Thu, 25 Nov 2021 12:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637844406; bh=JV4lwZuiAfd90eHa9xfMZBjWna+Fc5JfrSlxVTopPF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KDjsCBGBOIirmv0i3zdhy1tGoFuNUUJyehXqRwCdtD2TfxspOO3Y4c2rmSOIB8cjo f4Mn7Yb2vAv5P+80pId7DY65asQBju/93huGMHL0FYh17mrDiwp8Ut2IBQe9tz3uRg eylAW81f0laQeIv0XXYIXoJWUZiblQkq7EkfK6opRTFp4zoh4D2qTT2iFBJ5n7mnPx T/x/Cei9EL9Xy2Kq82c2eFeh4hIflIXwBzq5UctBDk5LcXQWwk/JakCW2GC3yJb8Fr fmGfrYnemYUIjmmKfud4OuF6CPdvCKwP+a0TbaQq5KNILHzqWwOBssAJXcKJZjay6Y k7khJCYL9Mqjw== Received: by pali.im (Postfix) id B587367E; Thu, 25 Nov 2021 13:46:45 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Thomas Petazzoni , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/15] PCI: mvebu: Fix support for DEVCAP2, DEVCTL2 and LNKCTL2 registers on emulated bridge Date: Thu, 25 Nov 2021 13:46:05 +0100 Message-Id: <20211125124605.25915-16-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211125124605.25915-1-pali@kernel.org> References: <20211125124605.25915-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_044646_402056_F942BDAD X-CRM114-Status: UNSURE ( 9.15 ) X-CRM114-Notice: Please train this message. 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 Armada XP and new hardware supports access to DEVCAP2, DEVCTL2 and LNKCTL2 configuration registers of PCIe core via PCIE_CAP_PCIEXP. So export them via emulated software root bridge. Pre-XP hardware does not support these registers and returns zeros. Signed-off-by: Pali Rohár Fixes: 1f08673eef12 ("PCI: mvebu: Convert to PCI emulated bridge config space") Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-mvebu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 798cf5cff8be..9a17bab4019f 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -571,6 +571,18 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, *value = mvebu_readl(port, PCIE_RC_RTSTA); break; + case PCI_EXP_DEVCAP2: + *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCAP2); + break; + + case PCI_EXP_DEVCTL2: + *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL2); + break; + + case PCI_EXP_LNKCTL2: + *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL2); + break; + default: return PCI_BRIDGE_EMUL_NOT_HANDLED; } @@ -683,6 +695,17 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, if (new & PCI_EXP_RTSTA_PME) mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF); break; + + case PCI_EXP_DEVCTL2: + mvebu_writel(port, new, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL2); + break; + + case PCI_EXP_LNKCTL2: + mvebu_writel(port, new, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL2); + break; + + default: + break; } }