Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1801482imw; Sat, 16 Jul 2022 15:28:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNcX25CF3MSjJx7cKqhWP1E3bthDjch/oIa+0DOSyzGzHHH2HCRW3FgFq8L13wGIlifVC4 X-Received: by 2002:a05:6402:228f:b0:43a:896:e4f0 with SMTP id cw15-20020a056402228f00b0043a0896e4f0mr27102379edb.81.1658010510005; Sat, 16 Jul 2022 15:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658010510; cv=none; d=google.com; s=arc-20160816; b=n92rtuE+PRL1oNbeUPNzfrC+U35fzUgcAJWAW5Hs2+F3vmrrBn+nQzNMmeIpt4i3fL W3rr1Vi976Sx6CbXvOlCuRminuKKCNxCFZIgf5wh1DlDAXGgOuqPVEdYgoaDP+GMyMrO fCSfV12ZPBpnOokL2gqn7AYFFw2fQSWo4HL0TPC7s+AYN3ErB2HleB6c5yIIj3PCOArz 48FaETG/Xc8COKeG7+Amh4E/9E0X9f66FwU9X2Eiq6RW1K9zXOhWNeufWeL9/iNpHRFE Pi7M5KgpkX5swy7CcdG8GOWaBuvgWbdTsW0LFHavM1XI9b+PYylEW6oXfuHeW4RUS0bc MCFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=VkZuzjpphc3hRwU3DZRuPBK7JhfYOuym3N4nWR7ADgs=; b=ORPzvJmHtbmluQZlOqG//UNFQgwnfFZVJ9JgXqFET8gpBMSB7f5gLC4tfRd/20k6mA QWys2i53U8a3EbUoSTKYaz6Gd+GQxWWcykuJ5tRYr/sQzRqQ4Wu/ZQrxVEdn4qM3TtX7 O+wyjL5BsZPgl6h/4gFViemAU90oRFjhMzWhQbCOzMOjmmIN4aV0n6dFfnvSC1wv5rmv XQe24vNjQnZHwMs4fprmFEX1f0a8JUx0Nop51AK62Y7prEZaUukkOLS6GTMLwAh01WST ZM97EgWYBS+eLFk1E01TtMGPWAvXFY8MflrLVO9/cB+qmxK5y0tbVZJP0jWTY00F60Mw gMaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=it06odQY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa7d845000000b0043a24a419f4si8477235eds.317.2022.07.16.15.28.05; Sat, 16 Jul 2022 15:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=it06odQY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232667AbiGPWZR (ORCPT + 99 others); Sat, 16 Jul 2022 18:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232591AbiGPWZL (ORCPT ); Sat, 16 Jul 2022 18:25:11 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA381C91D; Sat, 16 Jul 2022 15:25:09 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id q13-20020a17090a304d00b001f1af9a18a2so694786pjl.5; Sat, 16 Jul 2022 15:25:09 -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=VkZuzjpphc3hRwU3DZRuPBK7JhfYOuym3N4nWR7ADgs=; b=it06odQYV4an9HwynsjEosZr1HZe64JDlVydFVDU22TVm6YybuB9qumKvbS1IE61sH /qdHnF/gAMWv41oujk5+WDfNAPoGSX7tV8/P9Mjj/0+U4Hd+AwF54szjML7idRvL5Ibn BsJEENppGe14IxeP/9dVDToaaqbhQJbsVP1VW0sB7qdyMHxWw0S8VBwX+Hi/D3zStlUO sr2xDe1rUbuW99covL0cNzRbxYyUr4Y/xiyq1oDhtkHkg9Tmm831OqTLZl7KZtdTuswM PaNcp0EiXVLeTbwG43tZOu6M3Jh16SgaUOJT632efQqyadXde+RXejsbwXYSwJSVFcGf WKdQ== 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=VkZuzjpphc3hRwU3DZRuPBK7JhfYOuym3N4nWR7ADgs=; b=yAX36/MMinVHTBy2eVEzz+viaRSek6W3Lkfev0VJ9L6jd70dfCEfnlTM+q+Co5/S0j d/yNLmZDxRp9EpopFr5Z2Vf6A6icDJT7SF9ngiVkcducYONt2vwObfbvXH35TkqcTxF2 a7uV/MiQcZ8eSwYpzGGomn770CcIyZzkAgDSDlzFhrrYgtFeYaIQN0CXiGMEcaVpxsJu o4Aejjj8QtyIyhM/7vvEMIrv56ymuGf1xLNeH9jlKP8YdUyj30IPJPhFDayhC91gpmJf JmghQLeFJ+MMgfkWV61sLiAaKquJWhaP5G6GtqYPbCwLjpbfsyPicuQVGRuUjmS+Ly9g NPBA== X-Gm-Message-State: AJIora8+cs7cdEecTe+v6GBVmfqxDh5VxF1SKYVkgVbxBREQUlPCO7xO yHxLPyRB4+m7gPXjqyh9FnA0IB1G6tI= X-Received: by 2002:a17:902:f64f:b0:16c:23c2:e2dd with SMTP id m15-20020a170902f64f00b0016c23c2e2ddmr20547647plg.3.1658010308459; Sat, 16 Jul 2022 15:25:08 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id y12-20020aa78f2c000000b00528c149fe97sm6318662pfr.89.2022.07.16.15.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 15:25:08 -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=20Wilczy=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 v2 3/6] PCI: brcmstb: Add "refusal mode" to preclude PCIe-induced CPU aborts Date: Sat, 16 Jul 2022 18:24:50 -0400 Message-Id: <20220716222454.29914-4-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220716222454.29914-1-jim2101024@gmail.com> References: <20220716222454.29914-1-jim2101024@gmail.com> X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 causes a CPU abort. This commit sets a "refusal mode" if the PCIe link-up fails, and this has our pci_ops map_bus function returning a NULL address, which in turn precludes the access from happening. Right now, "refusal mode" is window dressing. It will become relevant in a future commit when brcm_pcie_start_link() is invoked during enumeration instead of before it. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index c026446d5830..72219a4f3964 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -255,6 +255,7 @@ struct brcm_pcie { u32 hw_rev; void (*perst_set)(struct brcm_pcie *pcie, u32 val); void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); + bool refusal_mode; }; static inline bool is_bmips(const struct brcm_pcie *pcie) @@ -687,6 +688,19 @@ static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn, if (pci_is_root_bus(bus)) return PCI_SLOT(devfn) ? NULL : base + where; + if (pcie->refusal_mode) { + /* + * At this point we do not have PCIe link-up. If there is + * a config read or write access besides those targeting + * the host bridge, our PCIe HW throws a CPU abort. To + * prevent this we return the NULL address. The calling + * functions -- pci_generic_config_*() -- will notice this + * and not perform the access, and if it is a read access, + * 0xffffffff is returned. + */ + 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); @@ -704,6 +718,11 @@ static void __iomem *brcm_pcie_map_conf32(struct pci_bus *bus, unsigned int devf if (pci_is_root_bus(bus)) return PCI_SLOT(devfn) ? NULL : base + (where & ~0x3); + if (pcie->refusal_mode) { + /* See note above in brcm_pcie_map_conf() */ + return NULL; + } + /* For devices, write to the config space index register */ idx = PCIE_ECAM_OFFSET(bus->number, devfn, (where & ~3)); writel(idx, base + IDX_ADDR(pcie)); @@ -989,6 +1008,7 @@ static int brcm_pcie_start_link(struct brcm_pcie *pcie) dev_err(dev, "link down\n"); return -ENODEV; } + pcie->refusal_mode = false; if (!brcm_pcie_rc_mode(pcie)) { dev_err(dev, "PCIe misconfigured; is in EP mode\n"); @@ -1134,6 +1154,8 @@ static void brcm_pcie_turn_off(struct brcm_pcie *pcie) void __iomem *base = pcie->base; int tmp; + pcie->refusal_mode = true; + if (brcm_pcie_link_up(pcie)) brcm_pcie_enter_l23(pcie); /* Assert fundamental reset */ @@ -1185,6 +1207,7 @@ static int brcm_pcie_resume(struct device *dev) u32 tmp; int ret; + pcie->refusal_mode = true; base = pcie->base; ret = clk_prepare_enable(pcie->clk); if (ret) @@ -1361,6 +1384,7 @@ static int brcm_pcie_probe(struct platform_device *pdev) pcie->type = data->type; pcie->perst_set = data->perst_set; pcie->bridge_sw_init_set = data->bridge_sw_init_set; + pcie->refusal_mode = true; pcie->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(pcie->base)) -- 2.17.1