[PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper

Hans Zhang posted 13 patches 6 months ago
There is a newer version of this series
drivers/pci/controller/dwc/pci-dra7xx.c       |  10 +-
drivers/pci/controller/dwc/pci-imx6.c         |  26 ++-
drivers/pci/controller/dwc/pci-meson.c        |  22 +--
drivers/pci/controller/dwc/pcie-armada8k.c    |  48 ++----
drivers/pci/controller/dwc/pcie-bt1.c         |   5 +-
.../controller/dwc/pcie-designware-debugfs.c  |  67 +++-----
.../pci/controller/dwc/pcie-designware-ep.c   |  20 +--
.../pci/controller/dwc/pcie-designware-host.c |  27 ++-
drivers/pci/controller/dwc/pcie-designware.c  |  74 ++++-----
drivers/pci/controller/dwc/pcie-designware.h  |  27 +--
drivers/pci/controller/dwc/pcie-dw-rockchip.c |   7 +-
drivers/pci/controller/dwc/pcie-fu740.c       |   5 +-
drivers/pci/controller/dwc/pcie-qcom-common.c |  59 ++++---
drivers/pci/controller/dwc/pcie-qcom-ep.c     |  14 +-
drivers/pci/controller/dwc/pcie-rcar-gen4.c   |  23 +--
drivers/pci/controller/dwc/pcie-tegra194.c    | 155 ++++++++----------
16 files changed, 239 insertions(+), 350 deletions(-)
[PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper
Posted by Hans Zhang 6 months ago
Register bit manipulation in DesignWare PCIe controllers currently
uses repetitive read-modify-write sequences across multiple drivers.
This pattern leads to code duplication and increases maintenance
complexity as each driver implements similar logic with minor variations.

This series introduces dw_pcie_clear_and_set_dword() to centralize atomic
register modification. The helper performs read-clear-set-write operations
in a single function, replacing open-coded implementations. Subsequent
patches refactor individual drivers to use this helper, eliminating
redundant code and ensuring consistent bit handling.

The change reduces overall code size by ~350 lines while improving
maintainability. Each controller driver is updated in a separate
patch to preserve bisectability and simplify review.

---
Hi all,

At the beginning, two patches were made, 0001*.patch, and the others were
one patch. After consideration, I still split the patches. If splitting
is not necessary, I will recombine them into two patches in future
versions.


Changes for v2:
- Re-send it in the company environment so that the entire patch series is in the 00/13 cover letter. (Bjorn)
- Modify the subject. (Bjorn and Frank)
---

Hans Zhang (13):
  PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit
    manipulation
  PCI: dwc: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: dra7xx: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: imx6: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: meson: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: armada8k: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: bt1: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: dw-rockchip: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: fu740: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: qcom: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: qcom-ep: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: rcar-gen4: Refactor code by using dw_pcie_clear_and_set_dword()
  PCI: tegra194: Refactor code by using dw_pcie_clear_and_set_dword()

 drivers/pci/controller/dwc/pci-dra7xx.c       |  10 +-
 drivers/pci/controller/dwc/pci-imx6.c         |  26 ++-
 drivers/pci/controller/dwc/pci-meson.c        |  22 +--
 drivers/pci/controller/dwc/pcie-armada8k.c    |  48 ++----
 drivers/pci/controller/dwc/pcie-bt1.c         |   5 +-
 .../controller/dwc/pcie-designware-debugfs.c  |  67 +++-----
 .../pci/controller/dwc/pcie-designware-ep.c   |  20 +--
 .../pci/controller/dwc/pcie-designware-host.c |  27 ++-
 drivers/pci/controller/dwc/pcie-designware.c  |  74 ++++-----
 drivers/pci/controller/dwc/pcie-designware.h  |  27 +--
 drivers/pci/controller/dwc/pcie-dw-rockchip.c |   7 +-
 drivers/pci/controller/dwc/pcie-fu740.c       |   5 +-
 drivers/pci/controller/dwc/pcie-qcom-common.c |  59 ++++---
 drivers/pci/controller/dwc/pcie-qcom-ep.c     |  14 +-
 drivers/pci/controller/dwc/pcie-rcar-gen4.c   |  23 +--
 drivers/pci/controller/dwc/pcie-tegra194.c    | 155 ++++++++----------
 16 files changed, 239 insertions(+), 350 deletions(-)


base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
-- 
2.25.1
Re: [PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper
Posted by Manivannan Sadhasivam 5 months, 3 weeks ago
On Wed, Jun 18, 2025 at 11:20:59PM +0800, Hans Zhang wrote:
> Register bit manipulation in DesignWare PCIe controllers currently
> uses repetitive read-modify-write sequences across multiple drivers.
> This pattern leads to code duplication and increases maintenance
> complexity as each driver implements similar logic with minor variations.
> 
> This series introduces dw_pcie_clear_and_set_dword() to centralize atomic
> register modification. The helper performs read-clear-set-write operations
> in a single function, replacing open-coded implementations. Subsequent
> patches refactor individual drivers to use this helper, eliminating
> redundant code and ensuring consistent bit handling.
> 
> The change reduces overall code size by ~350 lines while improving
> maintainability. Each controller driver is updated in a separate
> patch to preserve bisectability and simplify review.
> 

Thanks for the cleanup! I spotted a typo in patch 13/13. Apart from that, I only
have one comment. You are initializing the temp variable like 'val' to 0 and
then ORing it with some fields. Here the initialization part is not necessary.
You could just write the first field directly instead of ORing with a 0
initialized variable.

Rest LGTM!

- Mani

-- 
மணிவண்ணன் சதாசிவம்
Re: [PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper
Posted by Hans Zhang 5 months, 3 weeks ago

On 2025/6/26 05:00, Manivannan Sadhasivam wrote:
> On Wed, Jun 18, 2025 at 11:20:59PM +0800, Hans Zhang wrote:
>> Register bit manipulation in DesignWare PCIe controllers currently
>> uses repetitive read-modify-write sequences across multiple drivers.
>> This pattern leads to code duplication and increases maintenance
>> complexity as each driver implements similar logic with minor variations.
>>
>> This series introduces dw_pcie_clear_and_set_dword() to centralize atomic
>> register modification. The helper performs read-clear-set-write operations
>> in a single function, replacing open-coded implementations. Subsequent
>> patches refactor individual drivers to use this helper, eliminating
>> redundant code and ensuring consistent bit handling.
>>
>> The change reduces overall code size by ~350 lines while improving
>> maintainability. Each controller driver is updated in a separate
>> patch to preserve bisectability and simplify review.
>>
> 
> Thanks for the cleanup! I spotted a typo in patch 13/13. Apart from that, I only
> have one comment. You are initializing the temp variable like 'val' to 0 and
> then ORing it with some fields. Here the initialization part is not necessary.
> You could just write the first field directly instead of ORing with a 0
> initialized variable.
> 
> Rest LGTM!

Dear Mani,

Thank you very much for your reply and reminder.

Will fix.

Best regards,
Hans

> 
> - Mani
>