From nobody Fri Oct 10 13:46:58 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AED9C28D8D5 for ; Fri, 13 Jun 2025 22:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749852538; cv=none; b=O/Oyr1jFJD9l9XN3H8thvEZbsEVmgyo5Av0nDQzZf2Dn3fIpS9azRlteA/gNWPbZAzGvfw/NTY57TU+x72O6ObDhar+PuIsQ8IP2NqxTCNUCKzifh0xVs2UrXFlgxZH0At95HEVFL4jsHUj6EScDRLasYdc61zYnhNiMQHjwWXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749852538; c=relaxed/simple; bh=HD4a6r9bibYgUJ71XazUNv0yi/iISYkLeMyZ683QAeI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ErtrNYaLjRhEKqK9jjbkbVh8JobaKAiwZAoqlLoSWfG4Hpm6ayuLAwkpsTV6l1B4yBkZB81h6a+fdEpy++YrVFcwFp0dZlDps3TFfXyD/JYKQaiTbNyJxMw+7E7n6KfYzt4qLIw4vKS20qsbExx0JjtNMDPE9hX14l+LyuG9KL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=VEQ1NHrl; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="VEQ1NHrl" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-234bfe37cccso34749505ad.0 for ; Fri, 13 Jun 2025 15:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1749852536; x=1750457336; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a9nXHk5SBHvChHubaGzWpWGO2zI+zAOT3Ho0PXOlrnQ=; b=VEQ1NHrl6ViNJCE8YLom+QIPBbB4Sx9LCXbCLFl67cjiY6TZIES5N48x8lUHpLj/gd g6zH4irVxWBnU2qsr1hgfUibEdFeJKxGaX5RYNbiUcotVqWJhERLCJ+SQTa5OEWTX30N ajE4Bs4Jd22HjjM7IMf9jrJS/nuDqwHF5PUGw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749852536; x=1750457336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a9nXHk5SBHvChHubaGzWpWGO2zI+zAOT3Ho0PXOlrnQ=; b=p89yiOlg+dlSZXWKumsHpv80Lx3vSK+EQA99NockZA9P/mrnG/EuNRoyGQkYE8SA10 qOAGDhOX96+QIHpdJWr/tjBQG19+0RJmc2yHQo5LU17p8m6wsswOl/YbLLczzKwqyOiz YirY5qtczscpAk+FhY6530FLrg5a8XwjUVSTwNvLo0Bbpy4FeuycbT2CsdmDJdJSaM3U rkYGuihdsJFjKkx4IRI9nP7FF2PyJKfxDnpzFjgO++6qghPIQjzNydg+F9GAQZpXq/oZ J0KgA1PMo5wJxYdqeEcAgmHnxr8Kikhmfv/mpA2Z8dSvVNlTeY+OKCTItKnMnWbrSmNZ yVlw== X-Forwarded-Encrypted: i=1; AJvYcCW5p0HIAPNjKUwZRqEfy3gskHjGLzjbVb8WMFf0Z2hwwM1Tib3uIij3kSKV4YdpCKOh33KNqeYUTuvjPGE=@vger.kernel.org X-Gm-Message-State: AOJu0YyI235c2GKvZ8Yp3laRXEIjLN2P55miDvdclks9fGOX9nN/yBWA TUs6mh4ra/cI7IJ2anfEDEm6JBE1KNE4p/s9D/frIjiVncsG/+EO+XAdwNfnqIBZCg== X-Gm-Gg: ASbGnct4kK2TMfseBieWLaQmMvbLl475QuNLVnYCSx4yYNKlXSEDfBfoY1tVOJBuoPt 8VO1sffiSJGFqpw1JsaS9pnmnomQseVjDysWmCQWbcSoQlAkPrPaU0PdYrV908DcbXz8fits1Y1 QqQYfBpjiB46ZtR7eD5laQLDJx9KRh8vI/0MO/hkUZlQ3e15Pw4eHxiO+3opZ0GCvxKWhBqAfxH eXua2tNVnfmL0hYtGL41Gzz2DL+gm8vjh1L+qQqA2CKjMM4pBc2KLJaYSadBiOyhrYb1hX1sKxa 9eSOcv8i4rMUmiYX4wbs5rZuGAiDhqSw+bB8mRBEktNanRnVGSLnXHh0ZI5QSp6PKL3CAqLb3O3 lTMlwolQeL7TzhGX2HVLuz5cEfLN5QIQylqYK71VMrOwemdUldQ+c X-Google-Smtp-Source: AGHT+IHM8oazS7A2uh0xAgCrPVpqhejHMMo7I+G/E9MQgjoES8mLV+qqRbRGmcO3lnv9/6im+w/Xyg== X-Received: by 2002:a17:902:ecce:b0:235:225d:3087 with SMTP id d9443c01a7336-2366b14d3c9mr14390065ad.30.1749852535840; Fri, 13 Jun 2025 15:08:55 -0700 (PDT) Received: from stband-bld-1.and.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365dea7d74sm19593105ad.152.2025.06.13.15.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 15:08:55 -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 , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , 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 2/2] PCI: brcmstb: Add panic/die handler to driver Date: Fri, 13 Jun 2025 18:08:43 -0400 Message-Id: <20250613220843.698227-3-james.quinlan@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250613220843.698227-1-james.quinlan@broadcom.com> References: <20250613220843.698227-1-james.quinlan@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Whereas most PCIe HW returns 0xffffffff on illegal accesses and the like, by default Broadcom's STB PCIe controller effects an abort. Some SoCs -- 7216 and its descendants -- have new HW that identifies error details. This simple handler determines if the PCIe controller was the cause of the abort and if so, prints out diagnostic info. Unfortunately, an abort still occurs. Care is taken to read the error registers only when the PCIe bridge is active and the PCIe registers are acceptable. Otherwise, a "die" event caused by something other than the PCIe could cause an abort if the PCIe "die" handler tried to access registers when the bridge is off. Example error output: brcm-pcie 8b20000.pcie: Error: Mem Acc: 32bit, Read, @0x38000000 brcm-pcie 8b20000.pcie: Type: TO=3D0 Abt=3D0 UnspReq=3D1 AccDsble=3D0 Ba= dAddr=3D0 Signed-off-by: Jim Quinlan Reviewed-by: Florian Fainelli --- drivers/pci/controller/pcie-brcmstb.c | 155 +++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller= /pcie-brcmstb.c index 400854c893d8..abc56acad1fe 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -13,15 +13,18 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -151,6 +154,39 @@ #define MSI_INT_MASK_SET 0x10 #define MSI_INT_MASK_CLR 0x14 =20 +/* Error report registers */ +#define PCIE_OUTB_ERR_TREAT 0x6000 +#define PCIE_OUTB_ERR_TREAT_CONFIG_MASK 0x1 +#define PCIE_OUTB_ERR_TREAT_MEM_MASK 0x2 +#define PCIE_OUTB_ERR_VALID 0x6004 +#define PCIE_OUTB_ERR_CLEAR 0x6008 +#define PCIE_OUTB_ERR_ACC_INFO 0x600c +#define PCIE_OUTB_ERR_ACC_INFO_CFG_ERR_MASK 0x01 +#define PCIE_OUTB_ERR_ACC_INFO_MEM_ERR_MASK 0x02 +#define PCIE_OUTB_ERR_ACC_INFO_TYPE_64_MASK 0x04 +#define PCIE_OUTB_ERR_ACC_INFO_DIR_WRITE_MASK 0x10 +#define PCIE_OUTB_ERR_ACC_INFO_BYTE_LANES_MASK 0xff00 +#define PCIE_OUTB_ERR_ACC_ADDR 0x6010 +#define PCIE_OUTB_ERR_ACC_ADDR_BUS_MASK 0xff00000 +#define PCIE_OUTB_ERR_ACC_ADDR_DEV_MASK 0xf8000 +#define PCIE_OUTB_ERR_ACC_ADDR_FUNC_MASK 0x7000 +#define PCIE_OUTB_ERR_ACC_ADDR_REG_MASK 0xfff +#define PCIE_OUTB_ERR_CFG_CAUSE 0x6014 +#define PCIE_OUTB_ERR_CFG_CAUSE_TIMEOUT_MASK 0x40 +#define PCIE_OUTB_ERR_CFG_CAUSE_ABORT_MASK 0x20 +#define PCIE_OUTB_ERR_CFG_CAUSE_UNSUPP_REQ_MASK 0x10 +#define PCIE_OUTB_ERR_CFG_CAUSE_ACC_TIMEOUT_MASK 0x4 +#define PCIE_OUTB_ERR_CFG_CAUSE_ACC_DISABLED_MASK 0x2 +#define PCIE_OUTB_ERR_CFG_CAUSE_ACC_64BIT__MASK 0x1 +#define PCIE_OUTB_ERR_MEM_ADDR_LO 0x6018 +#define PCIE_OUTB_ERR_MEM_ADDR_HI 0x601c +#define PCIE_OUTB_ERR_MEM_CAUSE 0x6020 +#define PCIE_OUTB_ERR_MEM_CAUSE_TIMEOUT_MASK 0x40 +#define PCIE_OUTB_ERR_MEM_CAUSE_ABORT_MASK 0x20 +#define PCIE_OUTB_ERR_MEM_CAUSE_UNSUPP_REQ_MASK 0x10 +#define PCIE_OUTB_ERR_MEM_CAUSE_ACC_DISABLED_MASK 0x2 +#define PCIE_OUTB_ERR_MEM_CAUSE_BAD_ADDR_MASK 0x1 + #define PCIE_RGR1_SW_INIT_1_PERST_MASK 0x1 #define PCIE_RGR1_SW_INIT_1_PERST_SHIFT 0x0 =20 @@ -301,6 +337,8 @@ struct brcm_pcie { struct subdev_regulators *sr; bool ep_wakeup_capable; const struct pcie_cfg_data *cfg; + struct notifier_block die_notifier; + struct notifier_block panic_notifier; bool bridge_on; spinlock_t bridge_lock; }; @@ -1711,6 +1749,115 @@ static int brcm_pcie_resume_noirq(struct device *de= v) return ret; } =20 +/* Dump out PCIe errors on die or panic */ +static int _brcm_pcie_dump_err(struct brcm_pcie *pcie, + const char *type) +{ + void __iomem *base =3D pcie->base; + int i, is_cfg_err, is_mem_err, lanes; + char *width_str, *direction_str, lanes_str[9]; + u32 info, cfg_addr, cfg_cause, mem_cause, lo, hi; + unsigned long flags; + + spin_lock_irqsave(&pcie->bridge_lock, flags); + /* Don't access registers when the bridge is off */ + if (!pcie->bridge_on || readl(base + PCIE_OUTB_ERR_VALID) =3D=3D 0) { + spin_unlock_irqrestore(&pcie->bridge_lock, flags); + return NOTIFY_DONE; + } + + /* Read all necessary registers so we can release the spinlock ASAP */ + info =3D readl(base + PCIE_OUTB_ERR_ACC_INFO); + is_cfg_err =3D !!(info & PCIE_OUTB_ERR_ACC_INFO_CFG_ERR_MASK); + is_mem_err =3D !!(info & PCIE_OUTB_ERR_ACC_INFO_MEM_ERR_MASK); + if (is_cfg_err) { + cfg_addr =3D readl(base + PCIE_OUTB_ERR_ACC_ADDR); + cfg_cause =3D readl(base + PCIE_OUTB_ERR_CFG_CAUSE); + } + if (is_mem_err) { + mem_cause =3D readl(base + PCIE_OUTB_ERR_MEM_CAUSE); + lo =3D readl(base + PCIE_OUTB_ERR_MEM_ADDR_LO); + hi =3D readl(base + PCIE_OUTB_ERR_MEM_ADDR_HI); + } + /* We've got all of the info, clear the error */ + writel(1, base + PCIE_OUTB_ERR_CLEAR); + spin_unlock_irqrestore(&pcie->bridge_lock, flags); + + dev_err(pcie->dev, "handling %s error notification\n", type); + width_str =3D (info & PCIE_OUTB_ERR_ACC_INFO_TYPE_64_MASK) ? "64bit" : "3= 2bit"; + direction_str =3D (info & PCIE_OUTB_ERR_ACC_INFO_DIR_WRITE_MASK) ? "Write= " : "Read"; + lanes =3D FIELD_GET(PCIE_OUTB_ERR_ACC_INFO_BYTE_LANES_MASK, info); + for (i =3D 0, lanes_str[8] =3D 0; i < 8; i++) + lanes_str[i] =3D (lanes & (1 << i)) ? '1' : '0'; + + if (is_cfg_err) { + int bus =3D FIELD_GET(PCIE_OUTB_ERR_ACC_ADDR_BUS_MASK, cfg_addr); + int dev =3D FIELD_GET(PCIE_OUTB_ERR_ACC_ADDR_DEV_MASK, cfg_addr); + int func =3D FIELD_GET(PCIE_OUTB_ERR_ACC_ADDR_FUNC_MASK, cfg_addr); + int reg =3D FIELD_GET(PCIE_OUTB_ERR_ACC_ADDR_REG_MASK, cfg_addr); + + dev_err(pcie->dev, "Error: CFG Acc, %s, %s, Bus=3D%d, Dev=3D%d, Fun=3D%d= , Reg=3D0x%x, lanes=3D%s\n", + width_str, direction_str, bus, dev, func, reg, lanes_str); + dev_err(pcie->dev, " Type: TO=3D%d Abt=3D%d UnsupReq=3D%d AccTO=3D%d Acc= Dsbld=3D%d Acc64bit=3D%d\n", + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_TIMEOUT_MASK), + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_ABORT_MASK), + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_UNSUPP_REQ_MASK), + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_ACC_TIMEOUT_MASK), + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_ACC_DISABLED_MASK), + !!(cfg_cause & PCIE_OUTB_ERR_CFG_CAUSE_ACC_64BIT__MASK)); + } + + if (is_mem_err) { + u64 addr =3D ((u64)hi << 32) | (u64)lo; + + dev_err(pcie->dev, "Error: Mem Acc, %s, %s, @0x%llx, lanes=3D%s\n", + width_str, direction_str, addr, lanes_str); + dev_err(pcie->dev, " Type: TO=3D%d Abt=3D%d UnsupReq=3D%d AccDsble=3D%d = BadAddr=3D%d\n", + !!(mem_cause & PCIE_OUTB_ERR_MEM_CAUSE_TIMEOUT_MASK), + !!(mem_cause & PCIE_OUTB_ERR_MEM_CAUSE_ABORT_MASK), + !!(mem_cause & PCIE_OUTB_ERR_MEM_CAUSE_UNSUPP_REQ_MASK), + !!(mem_cause & PCIE_OUTB_ERR_MEM_CAUSE_ACC_DISABLED_MASK), + !!(mem_cause & PCIE_OUTB_ERR_MEM_CAUSE_BAD_ADDR_MASK)); + } + + return NOTIFY_OK; +} + +static int brcm_pcie_die_notify_cb(struct notifier_block *self, + unsigned long v, void *p) +{ + struct brcm_pcie *pcie =3D + container_of(self, struct brcm_pcie, die_notifier); + + return _brcm_pcie_dump_err(pcie, "Die"); +} + +static int brcm_pcie_panic_notify_cb(struct notifier_block *self, + unsigned long v, void *p) +{ + struct brcm_pcie *pcie =3D + container_of(self, struct brcm_pcie, panic_notifier); + + return _brcm_pcie_dump_err(pcie, "Panic"); +} + +static void brcm_register_die_notifiers(struct brcm_pcie *pcie) +{ + pcie->panic_notifier.notifier_call =3D brcm_pcie_panic_notify_cb; + atomic_notifier_chain_register(&panic_notifier_list, + &pcie->panic_notifier); + + pcie->die_notifier.notifier_call =3D brcm_pcie_die_notify_cb; + register_die_notifier(&pcie->die_notifier); +} + +static void brcm_unregister_die_notifiers(struct brcm_pcie *pcie) +{ + unregister_die_notifier(&pcie->die_notifier); + atomic_notifier_chain_unregister(&panic_notifier_list, + &pcie->panic_notifier); +} + static void __brcm_pcie_remove(struct brcm_pcie *pcie) { brcm_msi_remove(pcie); @@ -1729,6 +1876,9 @@ static void brcm_pcie_remove(struct platform_device *= pdev) =20 pci_stop_root_bus(bridge->bus); pci_remove_root_bus(bridge->bus); + if (pcie->cfg->has_err_report) + brcm_unregister_die_notifiers(pcie); + __brcm_pcie_remove(pcie); } =20 @@ -1829,6 +1979,7 @@ static const struct pcie_cfg_data bcm7216_cfg =3D { .bridge_sw_init_set =3D brcm_pcie_bridge_sw_init_set_7278, .has_phy =3D true, .num_inbound_wins =3D 3, + .has_err_report =3D true, }; =20 static const struct pcie_cfg_data bcm7712_cfg =3D { @@ -2003,8 +2154,10 @@ static int brcm_pcie_probe(struct platform_device *p= dev) return ret; } =20 - if (pcie->cfg->has_err_report) + if (pcie->cfg->has_err_report) { spin_lock_init(&pcie->bridge_lock); + brcm_register_die_notifiers(pcie); + } =20 return 0; =20 --=20 2.34.1