From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Bjorn Helgaas <helgaas@kernel.org>, Hans Zhang <18255117159@163.com>
Cc: lpieralisi@kernel.org, kwilczynski@kernel.org,
bhelgaas@google.com, jingoohan1@gmail.com, mani@kernel.org,
robh@kernel.org, ilpo.jarvinen@linux.intel.com,
gbayer@linux.ibm.com, lukas@wunner.de, arnd@kernel.org,
geert@linux-m68k.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v15 0/6] Refactor capability search into common macros
Date: Thu, 14 Aug 2025 22:37:03 +0200 [thread overview]
Message-ID: <fbc95b8020a152d487ada00e9751c2b3f602c11d.camel@linux.ibm.com> (raw)
In-Reply-To: <20250814202519.GA344690@bhelgaas>
On Thu, 2025-08-14 at 15:25 -0500, Bjorn Helgaas wrote:
> On Wed, Aug 13, 2025 at 10:45:23PM +0800, Hans Zhang wrote:
> > Dear Maintainers,
> >
> > This patch series addresses long-standing code duplication in PCI
> > capability discovery logic across the PCI core and controller drivers.
> > The existing implementation ties capability search to fully initialized
> > PCI device structures, limiting its usability during early controller
> > initialization phases where device/bus structures may not yet be
> > available.
> >
> > The primary goal is to decouple capability discovery from PCI device
> > dependencies by introducing a unified framework using config space
> > accessor-based macros. This enables:
> >
> > 1. Early Capability Discovery: Host controllers (e.g., Cadence, DWC)
> > can now perform capability searches during pre-initialization stages
> > using their native config accessors.
> >
> > 2. Code Consolidation: Common logic for standard and extended capability
> > searches is refactored into shared macros (`PCI_FIND_NEXT_CAP` and
> > `PCI_FIND_NEXT_EXT_CAP`), eliminating redundant implementations.
> >
> > 3. Safety and Maintainability: TTL checks are centralized within the
> > macros to prevent infinite loops, while hardcoded offsets in drivers
> > are replaced with dynamic discovery, reducing fragility.
> >
> > Key improvements include:
> > - Driver Conversions: DesignWare and Cadence drivers are migrated to
> > use the new macros, removing device-specific assumptions and ensuring
> > consistent error handling.
> >
> > - Enhanced Readability: Magic numbers are replaced with symbolic
> > constants, and config space accessors are standardized for clarity.
> >
> > - Backward Compatibility: Existing PCI core behavior remains unchanged.
> >
> > ---
> > Dear Niklas and Gerd,
> >
> > Can you test this series of patches on the s390?
> >
> > Thank you very much.
> > ---
> >
> > ---
> > Changes since v14:
> > - Delete the first patch in the v14 series.
> > - The functions that can obtain the values of the registers u8/u16/u32 are
> > directly called in PCI_FIND_NEXT_CAP() and PCI_FIND_NEXT_EXT_CAP().
> > Use the pci_bus_read_config_byte/word/dword function directly.
> > - Delete dw_pcie_read_cfg and redefine three functions: dw_pcie_read_cfg_byte/word/dword.
> > - Delete cdns_pcie_read_cfg and redefine three functions: cdns_pcie_read_cfg_byte/word/dword.
> >
> > Changes since v13:
> > - Split patch 3/6 into two patches for searching standard and extended capability. (Bjorn)
> > - Optimize the code based on the review comments from Bjorn.
> > - Patch 5/7 and 6/7 use simplified macro definitions: PCI_FIND_NEXT_CAP(), PCI_FIND_NEXT_EXT_CAP().
> > - The other patches have not been modified.
> >
> > Changes since v12:
> > - Modify some commit messages, code format issues, and optimize the function return values.
> >
> > Changes since v11:
> > - Resolved some compilation warning.
> > - Add some include.
> > - Add the *** BLURB HERE *** description(Corrected by Mani and Krzysztof).
> >
> > Changes since v10:
> > - The patch [v10 2/6] remove #include <uapi/linux/pci_regs.h> and add macro definition comments.
> > - The patch [v10 3/6] remove #include <uapi/linux/pci_regs.h> and commit message were modified.
> > - The other patches have not been modified.
> >
> > Changes since v9:
> > - Resolved [v9 4/6] compilation error.
> > The latest 6.15 rc1 merge __dw_pcie_find_vsec_capability, which uses
> > dw_pcie_find_next_ext_capability.
> > - The other patches have not been modified.
> >
> > Changes since v8:
> > - Split patch.
> > - The patch commit message were modified.
> > - Other patches(4/6, 5/6, 6/6) are unchanged.
> >
> > Changes since v7:
> > - Patch 2/5 and 3/5 compilation error resolved.
> > - Other patches are unchanged.
> >
> > Changes since v6:
> > - Refactor capability search into common macros.
> > - Delete pci-host-helpers.c and MAINTAINERS.
> >
> > Changes since v5:
> > - If you put the helpers in drivers/pci/pci.c, they unnecessarily enlarge
> > the kernel's .text section even if it's known already at compile time
> > that they're never going to be used (e.g. on x86).
> > - Move the API for find capabilitys to a new file called
> > pci-host-helpers.c.
> > - Add new patch for MAINTAINERS.
> >
> > Changes since v4:
> > - Resolved [v4 1/4] compilation warning.
> > - The patch subject and commit message were modified.
> >
> > Changes since v3:
> > - Resolved [v3 1/4] compilation error.
> > - Other patches are not modified.
> >
> > Changes since v2:
> > - Add and split into a series of patches.
> > ---
> >
> > Hans Zhang (6):
> > PCI: Clean up __pci_find_next_cap_ttl() readability
> > PCI: Refactor capability search into PCI_FIND_NEXT_CAP()
> > PCI: Refactor extended capability search into PCI_FIND_NEXT_EXT_CAP()
> > PCI: dwc: Use PCI core APIs to find capabilities
> > PCI: cadence: Use PCI core APIs to find capabilities
> > PCI: cadence: Use cdns_pcie_find_*capability() to avoid hardcoding
> > offsets
> >
> > .../pci/controller/cadence/pcie-cadence-ep.c | 38 +++++----
> > drivers/pci/controller/cadence/pcie-cadence.c | 14 +++
> > drivers/pci/controller/cadence/pcie-cadence.h | 39 +++++++--
> > drivers/pci/controller/dwc/pcie-designware.c | 77 ++---------------
> > drivers/pci/controller/dwc/pcie-designware.h | 21 +++++
> > drivers/pci/pci.c | 76 +++--------------
> > drivers/pci/pci.h | 85 +++++++++++++++++++
> > include/uapi/linux/pci_regs.h | 3 +
> > 8 files changed, 194 insertions(+), 159 deletions(-)
>
> I applied this on pci/capability-search for v6.18, thanks!
>
> Niklas, I added your Tested-by, omitting the dwc and cadence patches
> because I think you tested s390 and probably didn't exercise dwc or
> cadence. Thanks very much to you and Gerd for finding the issue and
> testing the resolution!
>
> Bjorn
Thanks, yes leaving out dwc and cadence makes sense. Though I do often
also test on my private x86 systems this one was s390 only. Since I
have you here and as you applied this one now and Lukas PCI/ERR stuff
yesterday, is it possible that my series titled "PCI/ERR: s390/pci: Use
pci_uevent_ers() in PCI recovery" somehow fell through your mail
filters maybe due to not having any "PCI:" in a subject?
Thanks,
Niklas
next prev parent reply other threads:[~2025-08-14 20:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 14:45 [PATCH v15 0/6] Refactor capability search into common macros Hans Zhang
2025-08-13 14:45 ` [PATCH v15 1/6] PCI: Clean up __pci_find_next_cap_ttl() readability Hans Zhang
2025-08-20 9:19 ` Gerd Bayer
2025-08-20 11:36 ` Ilpo Järvinen
2025-08-13 14:45 ` [PATCH v15 2/6] PCI: Refactor capability search into PCI_FIND_NEXT_CAP() Hans Zhang
2025-08-13 14:45 ` [PATCH v15 3/6] PCI: Refactor extended capability search into PCI_FIND_NEXT_EXT_CAP() Hans Zhang
2025-08-13 14:45 ` [PATCH v15 4/6] PCI: dwc: Use PCI core APIs to find capabilities Hans Zhang
2025-08-13 14:45 ` [PATCH v15 5/6] PCI: cadence: " Hans Zhang
2025-08-13 14:45 ` [PATCH v15 6/6] PCI: cadence: Use cdns_pcie_find_*capability() to avoid hardcoding offsets Hans Zhang
2025-08-14 8:32 ` [PATCH v15 0/6] Refactor capability search into common macros Niklas Schnelle
2025-08-14 14:51 ` Hans Zhang
2025-08-14 20:25 ` Bjorn Helgaas
2025-08-14 20:37 ` Niklas Schnelle [this message]
2025-08-14 20:51 ` Bjorn Helgaas
2025-08-14 22:21 ` Hans Zhang
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=fbc95b8020a152d487ada00e9751c2b3f602c11d.camel@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=18255117159@163.com \
--cc=arnd@kernel.org \
--cc=bhelgaas@google.com \
--cc=gbayer@linux.ibm.com \
--cc=geert@linux-m68k.org \
--cc=helgaas@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jingoohan1@gmail.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=lukas@wunner.de \
--cc=mani@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;
as well as URLs for NNTP newsgroup(s).