From: Bjorn Helgaas <helgaas@kernel.org>
To: Qiang Yu <qiang.yu@oss.qualcomm.com>
Cc: "Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Jingoo Han" <jingoohan1@gmail.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org,
"Wenbin Yao" <wenbin.yao@oss.qualcomm.com>
Subject: Re: [PATCH 2/5] PCI: dwc: Add new APIs to remove standard and extended Capability
Date: Fri, 26 Dec 2025 15:07:41 -0600 [thread overview]
Message-ID: <20251226210741.GA4141010@bhelgaas> (raw)
In-Reply-To: <20251109-remove_cap-v1-2-2208f46f4dc2@oss.qualcomm.com>
On Sun, Nov 09, 2025 at 10:59:41PM -0800, Qiang Yu wrote:
> On some platforms, certain PCIe Capabilities may be present in hardware
> but are not fully implemented as defined in PCIe spec. These incomplete
> capabilities should be hidden from the PCI framework to prevent unexpected
> behavior.
>
> Introduce two APIs to remove a specific PCIe Capability and Extended
> Capability by updating the previous capability's next offset field to skip
> over the unwanted capability. These APIs allow RC drivers to easily hide
> unsupported or partially implemented capabilities from software.
It's super annoying to have to do this, but I suppose from the
hardware point of view these things *could* work depending on the
design of the platform outside the device. So the designers probably
assume platform firmware knows those details and hides things that
aren't supported. But in the DT case, there likely *is* no platform
firmware, so the native RC driver has to do it instead.
> Co-developed-by: Wenbin Yao <wenbin.yao@oss.qualcomm.com>
> Signed-off-by: Wenbin Yao <wenbin.yao@oss.qualcomm.com>
> Signed-off-by: Qiang Yu <qiang.yu@oss.qualcomm.com>
> ---
> drivers/pci/controller/dwc/pcie-designware.c | 53 ++++++++++++++++++++++++++++
> drivers/pci/controller/dwc/pcie-designware.h | 2 ++
> 2 files changed, 55 insertions(+)
>
> diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
> index 5585d3ed74316bd218572484f6320019db8d6a10..24f8e9959cb81ca41e91d27057cc115d32e8d523 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.c
> +++ b/drivers/pci/controller/dwc/pcie-designware.c
> @@ -234,6 +234,59 @@ u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap)
> }
> EXPORT_SYMBOL_GPL(dw_pcie_find_ext_capability);
>
> +void dw_pcie_remove_capability(struct dw_pcie *pci, u8 cap)
> +{
> + u8 cap_pos, pre_pos, next_pos;
> + u16 reg;
> +
> + cap_pos = PCI_FIND_NEXT_CAP(dw_pcie_read_cfg, PCI_CAPABILITY_LIST, cap,
> + &pre_pos, pci);
> + if (!cap_pos)
> + return;
> +
> + reg = dw_pcie_readw_dbi(pci, cap_pos);
> + next_pos = (reg & 0xff00) >> 8;
> +
> + dw_pcie_dbi_ro_wr_en(pci);
> + if (pre_pos == PCI_CAPABILITY_LIST)
> + dw_pcie_writeb_dbi(pci, PCI_CAPABILITY_LIST, next_pos);
> + else
> + dw_pcie_writeb_dbi(pci, pre_pos + 1, next_pos);
> + dw_pcie_dbi_ro_wr_dis(pci);
> +}
> +EXPORT_SYMBOL_GPL(dw_pcie_remove_capability);
> +
> +void dw_pcie_remove_ext_capability(struct dw_pcie *pci, u8 cap)
> +{
> + int cap_pos, next_pos, pre_pos;
> + u32 pre_header, header;
> +
> + cap_pos = PCI_FIND_NEXT_EXT_CAP(dw_pcie_read_cfg, 0, cap, &pre_pos, pci);
> + if (!cap_pos)
> + return;
> +
> + header = dw_pcie_readl_dbi(pci, cap_pos);
Blank line here to match style of other comments.
> + /*
> + * If the first cap at offset PCI_CFG_SPACE_SIZE is removed,
> + * only set it's capid to zero as it cannot be skipped.
If setting the capid to zero works here, why won't it work for all
capabilities? If setting capid to zero is enough, we wouldn't need to
mess with keeping track of the previous capability, and we could drop
the first patch.
s/it's/its/
> + */
> + if (cap_pos == PCI_CFG_SPACE_SIZE) {
> + dw_pcie_dbi_ro_wr_en(pci);
> + dw_pcie_writel_dbi(pci, cap_pos, header & 0xffff0000);
> + dw_pcie_dbi_ro_wr_dis(pci);
> + return;
> + }
> +
> + pre_header = dw_pcie_readl_dbi(pci, pre_pos);
> + next_pos = PCI_EXT_CAP_NEXT(header);
> +
> + dw_pcie_dbi_ro_wr_en(pci);
> + dw_pcie_writel_dbi(pci, pre_pos,
> + (pre_header & 0xfffff) | (next_pos << 20));
> + dw_pcie_dbi_ro_wr_dis(pci);
> +}
> +EXPORT_SYMBOL_GPL(dw_pcie_remove_ext_capability);
> +
> static u16 __dw_pcie_find_vsec_capability(struct dw_pcie *pci, u16 vendor_id,
> u16 vsec_id)
> {
> diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
> index e995f692a1ecd10130d3be3358827f801811387f..b68dbc528001b63448db8b1a93bf56a5e53bd33e 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.h
> +++ b/drivers/pci/controller/dwc/pcie-designware.h
> @@ -552,6 +552,8 @@ void dw_pcie_version_detect(struct dw_pcie *pci);
>
> u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap);
> u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap);
> +void dw_pcie_remove_capability(struct dw_pcie *pci, u8 cap);
> +void dw_pcie_remove_ext_capability(struct dw_pcie *pci, u8 cap);
> u16 dw_pcie_find_rasdes_capability(struct dw_pcie *pci);
> u16 dw_pcie_find_ptm_capability(struct dw_pcie *pci);
>
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-12-26 21:07 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 6:59 [PATCH 0/5] PCI: Remove unsupported or incomplete PCIe Capabilities Qiang Yu
2025-11-10 6:59 ` [PATCH 1/5] PCI: Add preceding capability position support and update drivers Qiang Yu
2025-11-10 6:59 ` [PATCH 2/5] PCI: dwc: Add new APIs to remove standard and extended Capability Qiang Yu
2025-12-23 7:24 ` Niklas Cassel
2025-12-24 6:20 ` Qiang Yu
2025-12-26 21:07 ` Bjorn Helgaas [this message]
2025-12-27 5:10 ` Manivannan Sadhasivam
2025-12-28 7:49 ` Qiang Yu
2026-01-09 7:59 ` Qiang Yu
2025-11-10 6:59 ` [PATCH 3/5] PCI: dwc: Remove MSI/MSIX capability if iMSI-RX is used as MSI controller Qiang Yu
2025-11-20 11:18 ` Manivannan Sadhasivam
2025-11-20 14:06 ` Shawn Lin
2025-11-20 17:00 ` Manivannan Sadhasivam
2025-11-21 4:04 ` Shawn Lin
2025-11-21 7:56 ` Qiang Yu
2025-11-28 9:57 ` Qiang Yu
2025-11-28 10:02 ` Shawn Lin
2025-12-04 1:27 ` Brian Norris
2025-12-26 21:25 ` Bjorn Helgaas
2025-12-27 4:58 ` Manivannan Sadhasivam
2025-12-04 1:51 ` Brian Norris
2025-12-18 7:31 ` Manivannan Sadhasivam
2025-12-26 21:31 ` Bjorn Helgaas
2025-12-27 5:21 ` Manivannan Sadhasivam
2025-12-28 7:02 ` Qiang Yu
2025-11-10 6:59 ` [PATCH 4/5] PCI: qcom: Remove MSI-X Capability for Root Ports Qiang Yu
2025-11-10 6:59 ` [PATCH 5/5] PCI: qcom: Remove DPC Extended Capability Qiang Yu
2025-12-18 7:35 ` [PATCH 0/5] PCI: Remove unsupported or incomplete PCIe Capabilities Manivannan Sadhasivam
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=20251226210741.GA4141010@bhelgaas \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=jingoohan1@gmail.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=qiang.yu@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=wenbin.yao@oss.qualcomm.com \
/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