Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum
@ 2026-11-25 13:18 Nirmoy Das
  2026-11-25 13:35 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Nirmoy Das @ 2026-11-25 13:18 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, linux-kernel, Ilpo Järvinen, JC Chen, Simon Cheng,
	Nirmoy Das

When the Cross-Domain End-Point (CDEP) function is disabled on the
Pericom PI7C9X3G606GPC, Port 4 exposes neither a BAR resource nor an
MSI-X capability. It still checks memory requests against
BAR 0 + 0x7f000 and BAR 0 + 0x7f080, the MSI-X Table and PBA addresses.
With the internal BAR value at zero, reads reaching Port 4 at these
addresses receive Unsupported Request (UR) Completions.

The affected system has this topology:

  0002:a1:00.0  PI7C9X3G606GPC upstream port [12d8:c008]
    +-0002:a2:04.0  PI7C9X3G606GPC Port 4 [12d8:c008]
        +-0002:a3:00.0  Micron 7450 PRO NVMe SSD [1344:51c3]

Diodes' workaround is to copy the upstream port's BAR 0 into Port 4.
This places the Table and PBA addresses within MMIO space already
allocated to the switch. Port 4 accepts the write but still returns
zero on config-space reads, so readback cannot verify the mirror.

Firmware can apply the workaround during boot, but Linux BAR sizing
reads zero from Port 4 and writes that zero back after probing.
Resource assignment can also move the upstream BAR 0, leaving the
firmware mirror stale.

Reapply the mirror after resource assignment and again after PCI
configuration state is restored during early resume. If the upstream
BAR is 64-bit, also copy BAR 1 and disable memory decoding while
updating both halves, unless mmio_always_on is set.

Acked-by: Simon Cheng <simon_cheng@diodes.com>
Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
---
Changes in v3:
- Drop RFC.
- Rebase on pci/main (v7.4-rc1); no code change.
- Add Acked-by from Simon Cheng (Diodes).

Changes in v2:
- Explain the CDEP-disabled address check and how BAR sizing can undo
  the firmware workaround.
- Clarify that Port 4 accepts BAR writes but still reads back as zero.
- Include the affected PCI topology in the commit message.

The unpatched boot log shows Linux moving the upstream BAR 0:

  [    6.440107] pci 0002:a1:00.0: BAR 0 [mem 0x10300000-0x1037ffff]
  [    6.445353] pci 0002:a1:00.0: BAR 0 [mem 0x10c00000-0x10c7ffff]: assigned

v2: https://lore.kernel.org/r/20260917103814.1985144-1-nirmoyd@nvidia.com
v1: https://lore.kernel.org/r/20260723161010.2638956-1-nirmoyd@nvidia.com

 drivers/pci/quirks.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7f1f47ea2ee415..2d3f677d0d4d20 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -6443,6 +6443,95 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2608,
 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2608,
 			 pci_fixup_pericom_acs_store_forward);
 
+#define PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC	0xc008
+
+/*
+ * With CDEP disabled, Port 4 exposes no BAR or MSI-X capability, but its
+ * internal MSI-X Table/PBA address check remains active. Mirror the
+ * upstream BAR 0 to keep these addresses in MMIO space assigned to the
+ * switch.
+ *
+ * Port 4 is device 4, function 0 below the upstream port. Its BAR 0
+ * accepts writes but reads as zero, so BAR sizing clears the mirror.
+ * Reapply it after resource assignment and during early resume, after
+ * PCI state restoration.
+ */
+static void pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror(struct pci_dev *pdev)
+{
+	struct pci_dev *upstream;
+	bool bar0_64, disable_mem;
+	u16 cmd = 0;
+	u32 bar = 0, bar1 = 0, upstream_bar = 0, upstream_bar1 = 0;
+
+	if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
+		return;
+
+	if (PCI_SLOT(pdev->devfn) != 4 || PCI_FUNC(pdev->devfn))
+		return;
+
+	upstream = pci_upstream_bridge(pdev);
+	if (!upstream || upstream->vendor != PCI_VENDOR_ID_PERICOM ||
+	    upstream->device != PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC ||
+	    pci_pcie_type(upstream) != PCI_EXP_TYPE_UPSTREAM)
+		return;
+
+	pci_read_config_dword(upstream, PCI_BASE_ADDRESS_0, &upstream_bar);
+	if (upstream_bar & PCI_BASE_ADDRESS_SPACE_IO)
+		return;
+
+	bar0_64 = (upstream_bar & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
+		  PCI_BASE_ADDRESS_MEM_TYPE_64;
+	if (bar0_64)
+		pci_read_config_dword(upstream, PCI_BASE_ADDRESS_1,
+				      &upstream_bar1);
+
+	if (!(upstream_bar & PCI_BASE_ADDRESS_MEM_MASK) &&
+	    (!bar0_64 || !upstream_bar1)) {
+		pci_warn(pdev, "skipping PI7C9X3G606GPC BAR 0 mirror workaround because upstream BAR 0 is unassigned\n");
+		return;
+	}
+
+	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &bar);
+	if (bar0_64) {
+		pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1, &bar1);
+		if (bar == upstream_bar && bar1 == upstream_bar1)
+			return;
+	} else {
+		if (bar == upstream_bar)
+			return;
+	}
+
+	/*
+	 * Disable memory decoding while updating a 64-bit BAR, unless
+	 * mmio_always_on is set, as pci_std_update_resource() does.
+	 */
+	disable_mem = bar0_64 && !pdev->mmio_always_on;
+	if (disable_mem) {
+		pci_read_config_word(pdev, PCI_COMMAND, &cmd);
+		pci_write_config_word(pdev, PCI_COMMAND,
+				      cmd & ~PCI_COMMAND_MEMORY);
+	}
+
+	pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, upstream_bar);
+	if (bar0_64)
+		pci_write_config_dword(pdev, PCI_BASE_ADDRESS_1, upstream_bar1);
+	if (disable_mem)
+		pci_write_config_word(pdev, PCI_COMMAND, cmd);
+
+	if (bar0_64)
+		pci_info(pdev, "wrote upstream BAR 0/1 %#x/%#x to Port 4 BAR 0/1 for PI7C9X3G606GPC BAR 0 mirror workaround\n",
+			 upstream_bar, upstream_bar1);
+	else
+		pci_info(pdev, "wrote upstream BAR 0 %#x to Port 4 BAR 0 for PI7C9X3G606GPC BAR 0 mirror workaround\n",
+			 upstream_bar);
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_PERICOM,
+			PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC,
+			pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror);
+DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_PERICOM,
+			       PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC,
+			       pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror);
+
 static void nvidia_ion_ahci_fixup(struct pci_dev *pdev)
 {
 	pdev->dev_flags |= PCI_DEV_FLAGS_HAS_MSI_MASKING;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum
  2026-11-25 13:18 [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum Nirmoy Das
@ 2026-11-25 13:35 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-25 13:35 UTC (permalink / raw)
  To: Nirmoy Das; +Cc: linux-pci

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] PCI: broken BAR readback check in
  pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror()
- [Medium] PCI: stale firmware BAR mirrored in
  pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror()
--

commit aff9cc8487ab3357c2581d1e1130b4ea710052d7
Author: Nirmoy Das <nirmoyd@nvidia.com>

PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum

This commit adds final and early-resume PCI fixups to mirror the upstream
port's BAR 0 (and BAR 1 if 64-bit) into Port 4 on Pericom PI7C9X3G606GPC
switches when CDEP is disabled.

> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 7f1f47ea2ee41..2d3f677d0d4d2 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -6443,6 +6443,95 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2608,
>  DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2608,
>  			 pci_fixup_pericom_acs_store_forward);
>  
> +#define PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC	0xc008
> +
> +/*
> + * With CDEP disabled, Port 4 exposes no BAR or MSI-X capability, but its
> + * internal MSI-X Table/PBA address check remains active. Mirror the
> + * upstream BAR 0 to keep these addresses in MMIO space assigned to the
> + * switch.
> + *
> + * Port 4 is device 4, function 0 below the upstream port. Its BAR 0
> + * accepts writes but reads as zero, so BAR sizing clears the mirror.
> + * Reapply it after resource assignment and during early resume, after
> + * PCI state restoration.
> + */
> +static void pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror(struct pci_dev *pdev)
> +{
> +	struct pci_dev *upstream;
> +	bool bar0_64, disable_mem;
> +	u16 cmd = 0;
> +	u32 bar = 0, bar1 = 0, upstream_bar = 0, upstream_bar1 = 0;
> +
> +	if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
> +		return;
> +
> +	if (PCI_SLOT(pdev->devfn) != 4 || PCI_FUNC(pdev->devfn))
> +		return;
> +
> +	upstream = pci_upstream_bridge(pdev);
> +	if (!upstream || upstream->vendor != PCI_VENDOR_ID_PERICOM ||
> +	    upstream->device != PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC ||
> +	    pci_pcie_type(upstream) != PCI_EXP_TYPE_UPSTREAM)
> +		return;
> +
> +	pci_read_config_dword(upstream, PCI_BASE_ADDRESS_0, &upstream_bar);
> +	if (upstream_bar & PCI_BASE_ADDRESS_SPACE_IO)
> +		return;
> +
> +	bar0_64 = (upstream_bar & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
> +		  PCI_BASE_ADDRESS_MEM_TYPE_64;
> +	if (bar0_64)
> +		pci_read_config_dword(upstream, PCI_BASE_ADDRESS_1,
> +				      &upstream_bar1);
> +
> +	if (!(upstream_bar & PCI_BASE_ADDRESS_MEM_MASK) &&
> +	    (!bar0_64 || !upstream_bar1)) {
> +		pci_warn(pdev, "skipping PI7C9X3G606GPC BAR 0 mirror workaround because upstream BAR 0 is unassigned\n");
> +		return;
> +	}

[Severity: Medium]
Can this check miss an unassigned upstream BAR 0 when firmware left a stale
address in PCI_BASE_ADDRESS_0?

During BAR sizing, __pci_size_bars() saves and restores the firmware value in
PCI_BASE_ADDRESS_0.  If claiming or reassigning upstream->resource[0] fails,
the resource is marked IORESOURCE_UNSET or cleared by reset_resource(), and
pci_std_update_resource() never writes to config space:

drivers/pci/setup-res.c:pci_std_update_resource() {
	...
	if (!res->flags)
		return;

	if (res->flags & IORESOURCE_UNSET)
		return;
	...
}

Because PCI_BASE_ADDRESS_0 still holds the firmware address, this check passes
and mirrors the stale address into Port 4.  If Linux assigned that MMIO range
to a bridge window for downstream devices, Port 4's BAR 0 + 0x7f000 and
BAR 0 + 0x7f080 address check will reject accesses to those addresses with
Unsupported Request completions.  Checking upstream->resource[0].flags for
IORESOURCE_MEM and !IORESOURCE_UNSET would ensure the upstream BAR is actually
assigned.

> +
> +	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &bar);
> +	if (bar0_64) {
> +		pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1, &bar1);
> +		if (bar == upstream_bar && bar1 == upstream_bar1)
> +			return;
> +	} else {
> +		if (bar == upstream_bar)
> +			return;
> +	}

[Severity: Medium]
What is this readback check intended to guard against?

As the comment above notes, Port 4 BAR 0 always reads back as zero when CDEP
is disabled, while the check just before this guarantees upstream_bar (or
upstream_bar1) is non-zero.  As a result, bar == upstream_bar is always false
when CDEP is disabled, so every pci_fixup_resume_early call (including runtime
resume) will toggle PCI_COMMAND_MEMORY for 64-bit BARs, rewrite BAR 0/1, and
log a pci_info() message.  Conversely, if Port 4 ever exposes a valid non-zero
BAR of its own, bar != upstream_bar will not bail out and the fixup will
overwrite Port 4's BAR with upstream_bar.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125131838.1272907-1-nirmoyd@nvidia.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 13:18 [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum Nirmoy Das
2026-11-25 13:35 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox