public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
* [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword()
@ 2025-11-01 16:22 Hans Zhang
  2025-11-01 16:22 ` [RESEND PATCH v4 1/2] " Hans Zhang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Hans Zhang @ 2025-11-01 16:22 UTC (permalink / raw)
  To: mahesh, bhelgaas
  Cc: oohall, mani, lukas, linuxppc-dev, linux-pci, linux-kernel,
	Hans Zhang

This series introduces auxiliary functions for the PCI configuration space
and simplifies the read and write operations of the AER driver, reducing a
lot of repetitive code.

Patch 1 adds pci_clear_config_dword() and pci_set_config_dword() helpers
to reduce repetitive read-modify-write sequences when modifying PCI config
space. These helpers improve code readability and maintainability.

Patch 2 refactors the PCIe AER driver to use these new helpers,
eliminating manual read-modify-write patterns and intermediate variable
in several functions. This results in cleaner and more concise code.

---
Changes for v4:
- Introduce pci_clear/set_config_dword()

Changes for v3:
https://patchwork.kernel.org/project/linux-pci/patch/20250816161743.340684-1-18255117159@163.com/

- Rebase to v6.17-rc1.
- The patch commit message were modified.
- Add Acked-by: Manivannan Sadhasivam <mani@kernel.org>

Changes for v2:
- The patch commit message were modified.
- New optimizations for the functions disable_ecrc_checking, aer_enable_irq, and aer_disable_irq have been added.
---

Hans Zhang (2):
  PCI: Introduce pci_clear/set_config_dword()
  PCI/AER: Use pci_clear/set_config_dword to simplify code

 drivers/pci/pcie/aer.c | 29 ++++++++++-------------------
 include/linux/pci.h    | 12 ++++++++++++
 2 files changed, 22 insertions(+), 19 deletions(-)


base-commit: 8742b2d8935f476449ef37e263bc4da3295c7b58
-- 
2.25.1



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

* [RESEND PATCH v4 1/2] PCI: Introduce pci_clear/set_config_dword()
  2025-11-01 16:22 [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
@ 2025-11-01 16:22 ` Hans Zhang
  2025-11-01 16:22 ` [RESEND PATCH v4 2/2] PCI/AER: Use pci_clear/set_config_dword to simplify code Hans Zhang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2025-11-01 16:22 UTC (permalink / raw)
  To: mahesh, bhelgaas
  Cc: oohall, mani, lukas, linuxppc-dev, linux-pci, linux-kernel,
	Hans Zhang

Add helper functions to clear or set bits in PCI config space.
These helpers reduce code duplication and improve readability for config
space modifications by encapsulating common read-modify-write patterns.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 include/linux/pci.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index 59876de13860..bb0dba2b7aee 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1341,6 +1341,18 @@ static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
 	return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
 }
 
+static inline void pci_clear_config_dword(const struct pci_dev *dev, int pos,
+					  u32 clear)
+{
+	pci_clear_and_set_config_dword(dev, pos, clear, 0);
+}
+
+static inline void pci_set_config_dword(const struct pci_dev *dev, int pos,
+					u32 set)
+{
+	pci_clear_and_set_config_dword(dev, pos, 0, set);
+}
+
 /* User-space driven config access */
 int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
 int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
-- 
2.25.1



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

* [RESEND PATCH v4 2/2] PCI/AER: Use pci_clear/set_config_dword to simplify code
  2025-11-01 16:22 [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
  2025-11-01 16:22 ` [RESEND PATCH v4 1/2] " Hans Zhang
@ 2025-11-01 16:22 ` Hans Zhang
  2026-01-18 13:47 ` [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
  2026-03-06 15:50 ` Hans Zhang
  3 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2025-11-01 16:22 UTC (permalink / raw)
  To: mahesh, bhelgaas
  Cc: oohall, mani, lukas, linuxppc-dev, linux-pci, linux-kernel,
	Hans Zhang

Replace manual read-modify-write sequences in multiple functions with
pci_clear/set_config_dword helper to reduce code duplication.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/pcie/aer.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index e286c197d716..468d4a726a20 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -176,14 +176,12 @@ static int enable_ecrc_checking(struct pci_dev *dev)
 static int disable_ecrc_checking(struct pci_dev *dev)
 {
 	int aer = dev->aer_cap;
-	u32 reg32;
 
 	if (!aer)
 		return -ENODEV;
 
-	pci_read_config_dword(dev, aer + PCI_ERR_CAP, &reg32);
-	reg32 &= ~(PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
-	pci_write_config_dword(dev, aer + PCI_ERR_CAP, reg32);
+	pci_clear_config_dword(dev, aer + PCI_ERR_CAP,
+			       PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
 
 	return 0;
 }
@@ -1102,15 +1100,12 @@ static bool find_source_device(struct pci_dev *parent,
 static void pci_aer_unmask_internal_errors(struct pci_dev *dev)
 {
 	int aer = dev->aer_cap;
-	u32 mask;
 
-	pci_read_config_dword(dev, aer + PCI_ERR_UNCOR_MASK, &mask);
-	mask &= ~PCI_ERR_UNC_INTN;
-	pci_write_config_dword(dev, aer + PCI_ERR_UNCOR_MASK, mask);
+	pci_clear_config_dword(dev, aer + PCI_ERR_UNCOR_MASK,
+			       PCI_ERR_UNC_INTN);
 
-	pci_read_config_dword(dev, aer + PCI_ERR_COR_MASK, &mask);
-	mask &= ~PCI_ERR_COR_INTERNAL;
-	pci_write_config_dword(dev, aer + PCI_ERR_COR_MASK, mask);
+	pci_clear_config_dword(dev, aer + PCI_ERR_COR_MASK,
+			       PCI_ERR_COR_INTERNAL);
 }
 
 static bool is_cxl_mem_dev(struct pci_dev *dev)
@@ -1556,23 +1551,19 @@ static irqreturn_t aer_irq(int irq, void *context)
 static void aer_enable_irq(struct pci_dev *pdev)
 {
 	int aer = pdev->aer_cap;
-	u32 reg32;
 
 	/* Enable Root Port's interrupt in response to error messages */
-	pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-	reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
-	pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+	pci_set_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND,
+			     ROOT_PORT_INTR_ON_MESG_MASK);
 }
 
 static void aer_disable_irq(struct pci_dev *pdev)
 {
 	int aer = pdev->aer_cap;
-	u32 reg32;
 
 	/* Disable Root Port's interrupt in response to error messages */
-	pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-	reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
-	pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+	pci_clear_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND,
+			       ROOT_PORT_INTR_ON_MESG_MASK);
 }
 
 /**
-- 
2.25.1



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

* Re: [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword()
  2025-11-01 16:22 [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
  2025-11-01 16:22 ` [RESEND PATCH v4 1/2] " Hans Zhang
  2025-11-01 16:22 ` [RESEND PATCH v4 2/2] PCI/AER: Use pci_clear/set_config_dword to simplify code Hans Zhang
@ 2026-01-18 13:47 ` Hans Zhang
  2026-03-06 15:50 ` Hans Zhang
  3 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2026-01-18 13:47 UTC (permalink / raw)
  To: mahesh, bhelgaas
  Cc: oohall, mani, lukas, linuxppc-dev, linux-pci, linux-kernel

Hi,

Gentle ping.

Best regards,
Hans

On 2025/11/2 00:22, Hans Zhang wrote:
> This series introduces auxiliary functions for the PCI configuration space
> and simplifies the read and write operations of the AER driver, reducing a
> lot of repetitive code.
> 
> Patch 1 adds pci_clear_config_dword() and pci_set_config_dword() helpers
> to reduce repetitive read-modify-write sequences when modifying PCI config
> space. These helpers improve code readability and maintainability.
> 
> Patch 2 refactors the PCIe AER driver to use these new helpers,
> eliminating manual read-modify-write patterns and intermediate variable
> in several functions. This results in cleaner and more concise code.
> 
> ---
> Changes for v4:
> - Introduce pci_clear/set_config_dword()
> 
> Changes for v3:
> https://patchwork.kernel.org/project/linux-pci/patch/20250816161743.340684-1-18255117159@163.com/
> 
> - Rebase to v6.17-rc1.
> - The patch commit message were modified.
> - Add Acked-by: Manivannan Sadhasivam <mani@kernel.org>
> 
> Changes for v2:
> - The patch commit message were modified.
> - New optimizations for the functions disable_ecrc_checking, aer_enable_irq, and aer_disable_irq have been added.
> ---
> 
> Hans Zhang (2):
>    PCI: Introduce pci_clear/set_config_dword()
>    PCI/AER: Use pci_clear/set_config_dword to simplify code
> 
>   drivers/pci/pcie/aer.c | 29 ++++++++++-------------------
>   include/linux/pci.h    | 12 ++++++++++++
>   2 files changed, 22 insertions(+), 19 deletions(-)
> 
> 
> base-commit: 8742b2d8935f476449ef37e263bc4da3295c7b58



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

* Re: [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword()
  2025-11-01 16:22 [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
                   ` (2 preceding siblings ...)
  2026-01-18 13:47 ` [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
@ 2026-03-06 15:50 ` Hans Zhang
  3 siblings, 0 replies; 5+ messages in thread
From: Hans Zhang @ 2026-03-06 15:50 UTC (permalink / raw)
  To: mahesh, bhelgaas
  Cc: oohall, mani, lukas, linuxppc-dev, linux-pci, linux-kernel

Hi,

Gentle ping.

Best regards,
Hans

On 2025/11/2 00:22, Hans Zhang wrote:
> This series introduces auxiliary functions for the PCI configuration space
> and simplifies the read and write operations of the AER driver, reducing a
> lot of repetitive code.
> 
> Patch 1 adds pci_clear_config_dword() and pci_set_config_dword() helpers
> to reduce repetitive read-modify-write sequences when modifying PCI config
> space. These helpers improve code readability and maintainability.
> 
> Patch 2 refactors the PCIe AER driver to use these new helpers,
> eliminating manual read-modify-write patterns and intermediate variable
> in several functions. This results in cleaner and more concise code.
> 
> ---
> Changes for v4:
> - Introduce pci_clear/set_config_dword()
> 
> Changes for v3:
> https://patchwork.kernel.org/project/linux-pci/patch/20250816161743.340684-1-18255117159@163.com/
> 
> - Rebase to v6.17-rc1.
> - The patch commit message were modified.
> - Add Acked-by: Manivannan Sadhasivam <mani@kernel.org>
> 
> Changes for v2:
> - The patch commit message were modified.
> - New optimizations for the functions disable_ecrc_checking, aer_enable_irq, and aer_disable_irq have been added.
> ---
> 
> Hans Zhang (2):
>    PCI: Introduce pci_clear/set_config_dword()
>    PCI/AER: Use pci_clear/set_config_dword to simplify code
> 
>   drivers/pci/pcie/aer.c | 29 ++++++++++-------------------
>   include/linux/pci.h    | 12 ++++++++++++
>   2 files changed, 22 insertions(+), 19 deletions(-)
> 
> 
> base-commit: 8742b2d8935f476449ef37e263bc4da3295c7b58



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

end of thread, other threads:[~2026-03-06 15:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-01 16:22 [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
2025-11-01 16:22 ` [RESEND PATCH v4 1/2] " Hans Zhang
2025-11-01 16:22 ` [RESEND PATCH v4 2/2] PCI/AER: Use pci_clear/set_config_dword to simplify code Hans Zhang
2026-01-18 13:47 ` [RESEND PATCH v4 0/2] PCI: Introduce pci_clear/set_config_dword() Hans Zhang
2026-03-06 15:50 ` Hans Zhang

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