From patchwork Mon Jul 25 15:12:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12928247 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 731C1C433EF for ; Mon, 25 Jul 2022 15:42:44 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=xRK8tXG1YEO8WLA7yJl+P5xuuurHdKlc092y2/yaDmk=; b=lnGZtjmzkq/eLU ahVKeOJNdRKje4b1nS7HrJa3Q/E9x3vP9mcEGASQC9PNepiE96UiWUTB3pY2IDSaHeX+9mOP2ekEj Pjbnc/nQCYARCaGcaFzzX4/oNK5zUzQnsqs3RHakiisNQ88Y40SNvRKhN8o1btloBqlWLAyM/e0I/ OVinPeV59sS3RTwly5U7rWbeF+pm8Wj8Mf3uoxPu/aQixIYWcG98Ue+cQhXzW24+agS+/7MA9RKAj rOR7Iusjo5QilozL0J8Hh+6bVq1cZJKnQExWiJktigcMNZH1SiQpsGhIsRRyz+jAxvbaJNYx7DWoC G0/Km3s1BZPK/c4ILJkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oG0Cy-00FQVO-9u; Mon, 25 Jul 2022 15:41:25 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFzm2-00FGyq-Hu; Mon, 25 Jul 2022 15:13:36 +0000 Received: by mail-pf1-x434.google.com with SMTP id o12so10690124pfp.5; Mon, 25 Jul 2022 08:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xI+CaZm7AHUscnYqQYFqdG4FTtSq1DoKhCMhOBlS3fE=; b=OnY0rVF2m4WIM7h85TZx9pPO4Ehy+e7cElKMLbhxoh4Zh+DI9SuU0o4MYVdIyG4pZA RhzWlN3yZVHjFgM+aV1Y2PbYEqlyRrlP1QXUbzGV5ZrrFibslr6UxAameeDC+DdZm1A1 KPhHw2JNlf2UwhjE6CsMI0NgdFbsJGxWJpkGo/qVJMRqw0vuqBWNlesw7T4ZqdTl5VH4 akvrzqLP6ZiY3wCVP5IKao6HfOJ8cJipDWTkOSams7ApAFBPjrMjPZ/HJBWQW2QXjs7C SWPwWT/vHciN6c/qVrYUZuana8iJltVeCPgkn3FaUGlOJiboBq3Ryk/faQhgu2PN9XMb 9VJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xI+CaZm7AHUscnYqQYFqdG4FTtSq1DoKhCMhOBlS3fE=; b=aUgoX2uHONn4a9h7Y/Y15C5gGxNPKkTWxNFGoVLUXtIhqku/qcsC0nDNQeFXmIMrl7 4H36HQt6iMX+Wy3cNg/EbizFZDOvr/b1IMHOPGEHxkd5G3NrJuOyjQnHrip21g84LDZg om5XUZQz6uBC+DfxAlWoJACMyqUjERNTOLmkXaXTbZm6vS1GQR8cEQmFrKC3NTaJiqe4 sTDJq7RAbtPWAKbQMIHgwxFnjhW3TxOeCnesBSgoFhhcUXRFlQoSjckFOxQbHfme2sRS itVnWAscWC5kwfz7wq3xt9ugsx+MW1qRuo6vio/tWGX8YDGnokVp0JaWLNkrqD/PIema +g7g== X-Gm-Message-State: AJIora+izShs2Y6EnJloMsk3LdnthGRm03rbKyYK6WShjHg6oklM7BbR JshOT0jfPo7Fa81iHUEhuvU= X-Google-Smtp-Source: AGRyM1vsa4Y8EuFQldpA75OhwPbn8kQCUj/eHUetPEinSfboGW+WPPmgHmfunyGl0wLyXyWb2gr+bg== X-Received: by 2002:aa7:888a:0:b0:52b:17e8:fd1 with SMTP id z10-20020aa7888a000000b0052b17e80fd1mr13249304pfe.46.1658762011028; Mon, 25 Jul 2022 08:13:31 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id a9-20020a170902ecc900b001641b2d61d4sm6649667plh.30.2022.07.25.08.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 08:13:30 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Bjorn Helgaas , Lorenzo Pieralisi , Cyril Brulebois , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 3/7] PCI: brcmstb: Gate config space access on link status Date: Mon, 25 Jul 2022 11:12:52 -0400 Message-Id: <20220725151258.42574-4-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220725151258.42574-1-jim2101024@gmail.com> References: <20220725151258.42574-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220725_081334_652267_599C50C4 X-CRM114-Status: GOOD ( 14.18 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Our PCIe RC HW has an atypical behavior: if it does not have PCIe link established between itself and downstream, any subsequent config space access for a downstream device causes a CPU abort. This commit allows a config space access for dowwnstream devices only if the PCIe link is up. Note that config space accesses to the root port are diverted to the RC registers and are honored regardless of link status. Some other minor changes are also made: (1) limit the "where" offset to 4K and (2) reject RC accesses if devfn != 0. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 15e47e8c94eb..3443206d2a95 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -683,14 +683,18 @@ static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn, void __iomem *base = pcie->base; int idx; - /* Accesses to the RC go right to the RC registers if slot==0 */ + /* Accesses to the RC go right to the RC registers if !devfn */ if (pci_is_root_bus(bus)) - return PCI_SLOT(devfn) ? NULL : base + where; + return devfn ? NULL : base + (where & 0xfff); + + /* An access to our HW w/o link-up will cause a CPU Abort */ + if (!brcm_pcie_link_up(pcie)) + return NULL; /* For devices, write to the config space index register */ idx = PCIE_ECAM_OFFSET(bus->number, devfn, 0); writel(idx, pcie->base + PCIE_EXT_CFG_INDEX); - return base + PCIE_EXT_CFG_DATA + where; + return base + PCIE_EXT_CFG_DATA + (where & 0xfff); } static void __iomem *brcm_pcie_map_conf32(struct pci_bus *bus, unsigned int devfn, @@ -700,12 +704,16 @@ static void __iomem *brcm_pcie_map_conf32(struct pci_bus *bus, unsigned int devf void __iomem *base = pcie->base; int idx; - /* Accesses to the RC go right to the RC registers if slot==0 */ + /* Accesses to the RC go right to the RC registers if !devfn */ if (pci_is_root_bus(bus)) - return PCI_SLOT(devfn) ? NULL : base + (where & ~0x3); + return devfn ? NULL : base + (where & 0xffc); + + /* An access to our HW w/o link-up will cause a CPU Abort */ + if (!brcm_pcie_link_up(pcie)) + return NULL; /* For devices, write to the config space index register */ - idx = PCIE_ECAM_OFFSET(bus->number, devfn, (where & ~3)); + idx = PCIE_ECAM_OFFSET(bus->number, devfn, (where & 0xffc)); writel(idx, base + IDX_ADDR(pcie)); return base + DATA_ADDR(pcie); }