From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, linux-pci@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v5 6/6] PCI: spacemit-k1: Add Spacemit K3 PCIe host controller support
Date: Mon, 07 Sep 2026 11:42:55 +0000 [thread overview]
Message-ID: <20260907114256.3272E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907112606.465778-7-inochiama@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Incorrect PCIe Gen3 Equalization Preset Request Vector assignment.
- [High] The driver accesses link MMIO registers before peripheral clocks are enabled, causing a bus fault.
- [Medium] The error path in k3_pcie_init incorrectly de-asserts PERST#, failing to safely reset the device.
- [Low] Use of undefined PHY bulk API functions causing build failure.
--
commit 63c719f7a87ffea307709340b4548f687247044d
Author: Inochi Amaoto <inochiama@gmail.com>
Subject: PCI: spacemit-k1: Add Spacemit K3 PCIe host controller support
This commit adds driver support for the PCIe controller on the Spacemit K3
SoC. The controller is similar to the Synopsys DesignWare PCIe IP but adds
support for an external MSI interrupt controller and multiple PHYs.
> diff --git a/drivers/pci/controller/dwc/pcie-spacemit-k1.c b/drivers/pci/controller/dwc/pcie-spacemit-k1.c
> index c610b367412aa..5031b688fdab0 100644
> --- a/drivers/pci/controller/dwc/pcie-spacemit-k1.c
> +++ b/drivers/pci/controller/dwc/pcie-spacemit-k1.c
[ ... ]
> @@ -303,6 +316,116 @@ static int k1_pcie_parse_port(struct k1_pcie *k1)
> return ret;
> }
>
> +static int k3_pcie_init(struct dw_pcie_rp *pp)
> +{
> + struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> + struct k1_pcie *k1 = to_k1_pcie(pci);
> + u32 reset_ctrl = k1->pmu_off + PCIE_CLK_RESET_CONTROL;
> + u32 val;
> + int ret;
> +
> + regmap_clear_bits(k1->pmu, reset_ctrl, LTSSM_EN);
> +
> + k1_pcie_toggle_soft_reset(k1);
> +
> + /* K3: Set IGNORE_PERSTN and drive PERSTN_OE high (assert reset) */
> + regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CONTROL_LOGIC,
> + PCIE_IGNORE_PERSTN | PCIE_PERSTN_OE | PCIE_PERSTN_OUT,
> + PCIE_IGNORE_PERSTN | PCIE_PERSTN_OE);
> +
> + ret = k1_pcie_enable_resources(k1);
> + if (ret)
> + goto failed_resources;
> +
> + regmap_set_bits(k1->pmu, reset_ctrl, PCIE_AUX_PWR_DET);
> + regmap_clear_bits(k1->pmu, reset_ctrl, APP_HOLD_PHY_RST);
> +
> + ret = phy_bulk_init(k1->phy_count, k1->phys);
[Severity: Low]
Does phy_bulk_init() exist in the mainline kernel? It seems this API might
be missing, which could cause a build failure here.
> + if (ret)
> + goto failed_phy;
> +
> + msleep(PCIE_T_PVPERL_MS);
> +
> + regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CONTROL_LOGIC,
> + PCIE_PERSTN_OUT | PCIE_PERSTN_OE);
> +
> + val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
> + val = u32_replace_bits(val, BIT(7),
> + GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC);
[Severity: High]
Does this assignment set the correct equalization preset? BIT(7) evaluates
to 128 (0x80), which when inserted into the 16-bit preset request vector
field, assigns preset 8 to Lane 1 and 0 to all other lanes. Could this
cause PCIe Gen3 link training to fail or use incorrect presets?
> + dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
> +
> + k1_pcie_set_device_id(k1);
> +
> + /* Finally, as a workaround, disable ASPM L1 */
> + k1_pcie_disable_aspm_l1(k1);
> +
> + return 0;
> +
> +failed_phy:
> + k1_pcie_disable_resources(k1);
> +failed_resources:
> + regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CONTROL_LOGIC,
> + PCIE_PERSTN_OUT | PCIE_PERSTN_OE | PCIE_IGNORE_PERSTN,
> + PCIE_PERSTN_OUT | PCIE_PERSTN_OE);
[Severity: Medium]
In this error path, PCIE_PERSTN_OUT is set high, which appears to de-assert
PERST#. Should this be clearing PCIE_PERSTN_OUT instead, to ensure the
endpoint device is safely held in reset after initialization fails?
> +
> + return ret;
> +}
[ ... ]
> +static int k3_pcie_parse_port(struct k1_pcie *k1)
> +{
> + u32 status0, status1, status2;
> +
> + /* This register require a RAW for cleanup */
> + status0 = readl_relaxed(k1->link + K3_PHY_AHB_IRQSTATUS_INTX);
[Severity: High]
Can this unclocked read cause a bus hang or synchronous external abort?
k3_pcie_parse_port() is called unconditionally during k1_pcie_probe():
k1_pcie_probe()
data->parse_port() -> k3_pcie_parse_port()
...
dw_pcie_host_init()
k3_pcie_init()
k1_pcie_enable_resources()
It looks like the peripheral clocks are not enabled until
k1_pcie_enable_resources() is called later in the host initialization.
Reading the k1->link registers before the clocks are enabled might fault.
> + status1 = readl_relaxed(k1->link + INTR_STATUS);
> + status2 = readl_relaxed(k1->link + K3_ADDR_INTR_STATUS1);
> +
> + writel_relaxed(status0, k1->link + K3_PHY_AHB_IRQSTATUS_INTX);
> + writel_relaxed(status1, k1->link + INTR_STATUS);
> + writel_relaxed(status2, k1->link + K3_ADDR_INTR_STATUS1);
> +
> + return k1_pcie_parse_port(k1);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907112606.465778-1-inochiama@gmail.com?part=6
next prev parent reply other threads:[~2026-09-07 11:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 11:25 [PATCH v5 0/6] riscv: spacemit: Add PCIe RC controller support for K3 Inochi Amaoto
2026-09-07 11:26 ` [PATCH v5 1/6] PCI: spacemit-k1: Add device data support Inochi Amaoto
2026-09-07 11:31 ` sashiko-bot
2026-09-08 10:26 ` Andy Shevchenko
2026-09-09 8:00 ` Inochi Amaoto
2026-09-10 5:44 ` Yao Zi
2026-09-10 6:42 ` Andy Shevchenko
2026-09-10 12:15 ` Yao Zi
2026-09-07 11:26 ` [PATCH v5 2/6] PCI: spacemit-k1: Add multiple PHY handles support Inochi Amaoto
2026-09-07 11:37 ` sashiko-bot
2026-09-08 10:29 ` Andy Shevchenko
2026-09-09 8:00 ` Inochi Amaoto
2026-09-09 14:27 ` Andy Shevchenko
2026-09-07 11:26 ` [PATCH v5 3/6] PCI: spacemit-k1: Add device id update helper Inochi Amaoto
2026-09-07 11:31 ` sashiko-bot
2026-09-07 11:26 ` [PATCH v5 4/6] dt-bindings: PCI: snps,dw-pcie: Add msi-parent for MSI handle check Inochi Amaoto
2026-09-07 11:35 ` sashiko-bot
2026-09-07 11:26 ` [PATCH v5 5/6] dt-bindings: PCI: spacemit: Introduce Spacemit K3 PCIe host controller Inochi Amaoto
2026-09-07 11:38 ` sashiko-bot
2026-09-07 13:08 ` Troy Mitchell
2026-09-09 8:01 ` Inochi Amaoto
2026-09-07 11:26 ` [PATCH v5 6/6] PCI: spacemit-k1: Add Spacemit K3 PCIe host controller support Inochi Amaoto
2026-09-07 11:42 ` sashiko-bot [this message]
2026-09-07 13:14 ` Troy Mitchell
2026-09-09 7:51 ` Inochi Amaoto
2026-09-10 9:51 ` Troy Mitchell
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=20260907114256.3272E1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=inochiama@gmail.com \
--cc=linux-pci@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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