From: Bjorn Helgaas <helgaas@kernel.org>
To: Jim Quinlan <james.quinlan@broadcom.com>
Cc: linux-pci@vger.kernel.org,
"Nicolas Saenz Julienne" <nsaenz@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Cyril Brulebois" <kibi@debian.org>,
bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE"
<linux-rpi-kernel@lists.infradead.org>,
"moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE"
<linux-arm-kernel@lists.infradead.org>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] PCI: brcmstb: Add a way to indicate if PCIe bridge is active
Date: Wed, 6 Aug 2025 14:14:48 -0500 [thread overview]
Message-ID: <20250806191448.GA8432@bhelgaas> (raw)
In-Reply-To: <20250613220843.698227-2-james.quinlan@broadcom.com>
On Fri, Jun 13, 2025 at 06:08:42PM -0400, Jim Quinlan wrote:
> In a future commit, a new handler will be introduced that in part does
> reads and writes to some of the PCIe registers. When this handler is
> invoked, it is paramount that it does not do these register accesses when
> the PCIe bridge is inactive, as this will cause CPU abort errors.
>
> To solve this we keep a spinlock that guards a variable which indicates
> whether the bridge is on or off. When the bridge is on, access of the PCIe
> HW registers may proceed.
>
> Since there are multiple ways to reset the bridge, we introduce a general
> function to obtain the spinlock, call the specific function that is used
> for the specific SoC, sets the bridge active indicator variable, and
> releases the spinlock.
>
> Signed-off-by: Jim Quinlan <james.quinlan@broadcom.com>
> ---
> drivers/pci/controller/pcie-brcmstb.c | 40 +++++++++++++++++++++++----
> 1 file changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
> index 92887b394eb4..400854c893d8 100644
> --- a/drivers/pci/controller/pcie-brcmstb.c
> +++ b/drivers/pci/controller/pcie-brcmstb.c
> @@ -29,6 +29,7 @@
> #include <linux/reset.h>
> #include <linux/sizes.h>
> #include <linux/slab.h>
> +#include <linux/spinlock.h>
> #include <linux/string.h>
> #include <linux/types.h>
>
> @@ -254,6 +255,7 @@ struct pcie_cfg_data {
> int (*perst_set)(struct brcm_pcie *pcie, u32 val);
> int (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val);
> int (*post_setup)(struct brcm_pcie *pcie);
> + bool has_err_report;
It doesn't look worth it to me to add this. It only avoids locking in
a non-performance path.
> };
>
> struct subdev_regulators {
> @@ -299,6 +301,8 @@ struct brcm_pcie {
> struct subdev_regulators *sr;
> bool ep_wakeup_capable;
> const struct pcie_cfg_data *cfg;
> + bool bridge_on;
> + spinlock_t bridge_lock;
> };
>
> static inline bool is_bmips(const struct brcm_pcie *pcie)
> @@ -306,6 +310,24 @@ static inline bool is_bmips(const struct brcm_pcie *pcie)
> return pcie->cfg->soc_base == BCM7435 || pcie->cfg->soc_base == BCM7425;
> }
>
> +static inline int brcm_pcie_bridge_sw_init_set(struct brcm_pcie *pcie, u32 val)
> +{
> + unsigned long flags;
> + int ret;
> +
> + if (pcie->cfg->has_err_report)
> + spin_lock_irqsave(&pcie->bridge_lock, flags);
> +
> + ret = pcie->cfg->bridge_sw_init_set(pcie, val);
> + if (ret)
> + pcie->bridge_on = !val;
AFAICT, .bridge_sw_init_set(1) asserts reset, .bridge_sw_init_set(0)
deasserts reset, and it returns 0 for success, so I'm confused about
this. If either assert or deassert failed (ret != 0), I guess we
don't know the state of the bridge and can't assume it's active, so I
would have expected something like:
ret = pcie->cfg->bridge_sw_init_set(pcie, val);
if (ret)
pcie->bridge_on = false;
else
pcie->bridge_on = !val;
Tangent: the last "return ret" in brcm_pcie_bridge_sw_init_set_generic()
should be "return 0" and drop the unnecessary initialization of "ret".
And the code there would be vastly improved by using FIELD_PREP() or
u32p_replace_bits() and getting rid of the shifting.
> + if (pcie->cfg->has_err_report)
> + spin_unlock_irqrestore(&pcie->bridge_lock, flags);
> +
> + return ret;
> +}
> +
> /*
> * This is to convert the size of the inbound "BAR" region to the
> * non-linear values of PCIE_X_MISC_RC_BAR[123]_CONFIG_LO.SIZE
> @@ -1078,7 +1100,7 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie)
> int memc, ret;
>
> /* Reset the bridge */
> - ret = pcie->cfg->bridge_sw_init_set(pcie, 1);
> + ret = brcm_pcie_bridge_sw_init_set(pcie, 1);
> if (ret)
> return ret;
>
> @@ -1094,7 +1116,7 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie)
> usleep_range(100, 200);
>
> /* Take the bridge out of reset */
> - ret = pcie->cfg->bridge_sw_init_set(pcie, 0);
> + ret = brcm_pcie_bridge_sw_init_set(pcie, 0);
> if (ret)
> return ret;
>
> @@ -1545,7 +1567,7 @@ static int brcm_pcie_turn_off(struct brcm_pcie *pcie)
>
> if (!(pcie->cfg->quirks & CFG_QUIRK_AVOID_BRIDGE_SHUTDOWN))
> /* Shutdown PCIe bridge */
> - ret = pcie->cfg->bridge_sw_init_set(pcie, 1);
> + ret = brcm_pcie_bridge_sw_init_set(pcie, 1);
>
> return ret;
> }
> @@ -1633,7 +1655,9 @@ static int brcm_pcie_resume_noirq(struct device *dev)
> goto err_reset;
>
> /* Take bridge out of reset so we can access the SERDES reg */
> - pcie->cfg->bridge_sw_init_set(pcie, 0);
> + ret = brcm_pcie_bridge_sw_init_set(pcie, 0);
> + if (ret)
> + goto err_reset;
>
> /* SERDES_IDDQ = 0 */
> tmp = readl(base + HARD_DEBUG(pcie));
> @@ -1901,7 +1925,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)
> if (ret)
> return dev_err_probe(&pdev->dev, ret, "could not enable clock\n");
>
> - pcie->cfg->bridge_sw_init_set(pcie, 0);
> + ret = brcm_pcie_bridge_sw_init_set(pcie, 0);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "could not un-reset the bridge\n");
"un-reset" doesn't mean anything to me. Is this the same as "could
not take the bridge out of reset"? Or maybe "could not deassert
bridge reset"?
> if (pcie->swinit_reset) {
> ret = reset_control_assert(pcie->swinit_reset);
> @@ -1976,6 +2003,9 @@ static int brcm_pcie_probe(struct platform_device *pdev)
> return ret;
> }
>
> + if (pcie->cfg->has_err_report)
> + spin_lock_init(&pcie->bridge_lock);
> +
> return 0;
>
> fail:
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-08-06 19:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 22:08 [PATCH 0/2] PCI: brcmstb: Add panic/die handler to driver Jim Quinlan
2025-06-13 22:08 ` [PATCH 1/2] PCI: brcmstb: Add a way to indicate if PCIe bridge is active Jim Quinlan
2025-06-13 23:23 ` Florian Fainelli
2025-08-06 19:14 ` Bjorn Helgaas [this message]
2025-08-07 18:03 ` Jim Quinlan
2025-06-13 22:08 ` [PATCH 2/2] PCI: brcmstb: Add panic/die handler to driver Jim Quinlan
2025-06-13 23:28 ` Florian Fainelli
2025-08-06 18:15 ` Bjorn Helgaas
2025-08-06 18:38 ` Jim Quinlan
2025-08-06 18:50 ` Bjorn Helgaas
2025-08-06 19:16 ` Jim Quinlan
2025-08-06 20:41 ` Florian Fainelli
2025-08-07 5:26 ` Manivannan Sadhasivam
2025-08-07 14:40 ` Jim Quinlan
2025-08-07 17:00 ` Florian Fainelli
2025-08-06 19:14 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250806191448.GA8432@bhelgaas \
--to=helgaas@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhelgaas@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=james.quinlan@broadcom.com \
--cc=jim2101024@gmail.com \
--cc=kibi@debian.org \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=nsaenz@kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox