public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie
@ 2026-05-01 16:10 Hans Zhang
  2026-05-01 16:10 ` [PATCH 1/4] PCI: dra7xx: " Hans Zhang
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hans Zhang @ 2026-05-01 16:10 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr
  Cc: xrobh, linux-pci, linux-kernel, Hans Zhang

Several DesignWare PCIe controller drivers (dra7xx, artpec6,
designware-plat, and keembay) duplicated the device mode field
in their private structures, while struct dw_pcie already contains
this field. This led to:
1. Data redundancy and potential inconsistencies
2. Increased maintenance complexity
3. Error-prone device type checks

This series fixes these issues by:
- Removing redundant mode fields from all four drivers
- Standardizing on dw_pcie->mode for device type detection
- Simplifying conditional logic in probe/suspend/resume paths
- Ensuring consistent error reporting

The changes improve code maintainability and eliminate class of bugs
related to mode synchronization.

Hans Zhang (4):
  PCI: dra7xx: Use common mode field in struct dw_pcie
  PCI: artpec6: Use common mode field in struct dw_pcie
  PCI: dwc: Use common mode field in struct dw_pcie
  PCI: keembay: Use common mode field in struct dw_pcie

 drivers/pci/controller/dwc/pci-dra7xx.c           | 11 +++++------
 drivers/pci/controller/dwc/pcie-artpec6.c         |  9 ++++-----
 drivers/pci/controller/dwc/pcie-designware-plat.c |  7 +++----
 drivers/pci/controller/dwc/pcie-keembay.c         |  9 ++++-----
 4 files changed, 16 insertions(+), 20 deletions(-)


base-commit: e75a43c7cec459a07d91ed17de4de13ede2b7758
-- 
2.34.1


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

* [PATCH 1/4] PCI: dra7xx: Use common mode field in struct dw_pcie
  2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
@ 2026-05-01 16:10 ` Hans Zhang
  2026-05-01 16:10 ` [PATCH 2/4] PCI: artpec6: " Hans Zhang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hans Zhang @ 2026-05-01 16:10 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr
  Cc: xrobh, linux-pci, linux-kernel, Hans Zhang

Remove the redundant mode field from struct dra7xx_pcie and use the
existing mode field in struct dw_pcie instead.

This avoids duplication and prevents potential inconsistencies between
the two mode fields.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/dwc/pci-dra7xx.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c
index cd904659c321..88b4c486ea66 100644
--- a/drivers/pci/controller/dwc/pci-dra7xx.c
+++ b/drivers/pci/controller/dwc/pci-dra7xx.c
@@ -92,7 +92,6 @@ struct dra7xx_pcie {
 	struct phy		**phy;
 	struct irq_domain	*irq_domain;
 	struct clk              *clk;
-	enum dw_pcie_device_mode mode;
 };
 
 struct dra7xx_pcie_of_data {
@@ -328,7 +327,7 @@ static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
 		dev_dbg(dev, "Link Request Reset\n");
 
 	if (reg & LINK_UP_EVT) {
-		if (dra7xx->mode == DW_PCIE_EP_TYPE)
+		if (dra7xx->pci->mode == DW_PCIE_EP_TYPE)
 			dw_pcie_ep_linkup(ep);
 		dev_dbg(dev, "Link-up state change\n");
 	}
@@ -828,7 +827,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	default:
 		dev_err(dev, "INVALID device type %d\n", mode);
 	}
-	dra7xx->mode = mode;
+	dra7xx->pci->mode = mode;
 
 	ret = devm_request_threaded_irq(dev, irq, NULL, dra7xx_pcie_irq_handler,
 					IRQF_SHARED | IRQF_ONESHOT,
@@ -841,7 +840,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	return 0;
 
 err_deinit:
-	if (dra7xx->mode == DW_PCIE_RC_TYPE)
+	if (dra7xx->pci->mode == DW_PCIE_RC_TYPE)
 		dw_pcie_host_deinit(&dra7xx->pci->pp);
 	else
 		dw_pcie_ep_deinit(&dra7xx->pci->ep);
@@ -865,7 +864,7 @@ static int dra7xx_pcie_suspend(struct device *dev)
 	struct dw_pcie *pci = dra7xx->pci;
 	u32 val;
 
-	if (dra7xx->mode != DW_PCIE_RC_TYPE)
+	if (pci->mode != DW_PCIE_RC_TYPE)
 		return 0;
 
 	/* clear MSE */
@@ -882,7 +881,7 @@ static int dra7xx_pcie_resume(struct device *dev)
 	struct dw_pcie *pci = dra7xx->pci;
 	u32 val;
 
-	if (dra7xx->mode != DW_PCIE_RC_TYPE)
+	if (pci->mode != DW_PCIE_RC_TYPE)
 		return 0;
 
 	/* set MSE */
-- 
2.34.1


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

* [PATCH 2/4] PCI: artpec6: Use common mode field in struct dw_pcie
  2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
  2026-05-01 16:10 ` [PATCH 1/4] PCI: dra7xx: " Hans Zhang
@ 2026-05-01 16:10 ` Hans Zhang
  2026-05-01 16:10 ` [PATCH 3/4] PCI: dwc: " Hans Zhang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hans Zhang @ 2026-05-01 16:10 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr
  Cc: xrobh, linux-pci, linux-kernel, Hans Zhang

Remove the redundant mode field from struct artpec6_pcie and use the
existing mode field in struct dw_pcie instead.

This avoids duplication and prevents potential inconsistencies between
the two mode fields.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/dwc/pcie-artpec6.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-artpec6.c b/drivers/pci/controller/dwc/pcie-artpec6.c
index 55cb957ae1f3..5cd227dda9a1 100644
--- a/drivers/pci/controller/dwc/pcie-artpec6.c
+++ b/drivers/pci/controller/dwc/pcie-artpec6.c
@@ -34,7 +34,6 @@ struct artpec6_pcie {
 	struct regmap		*regmap;	/* DT axis,syscon-pcie */
 	void __iomem		*phy_base;	/* DT phy */
 	enum artpec_pcie_variants variant;
-	enum dw_pcie_device_mode mode;
 };
 
 struct artpec_pcie_of_data {
@@ -100,7 +99,7 @@ static u64 artpec6_pcie_cpu_addr_fixup(struct dw_pcie *pci, u64 cpu_addr)
 	struct dw_pcie_rp *pp = &pci->pp;
 	struct dw_pcie_ep *ep = &pci->ep;
 
-	switch (artpec6_pcie->mode) {
+	switch (artpec6_pcie->pci->mode) {
 	case DW_PCIE_RC_TYPE:
 		return cpu_addr - pp->cfg0_base;
 	case DW_PCIE_EP_TYPE:
@@ -413,7 +412,7 @@ static int artpec6_pcie_probe(struct platform_device *pdev)
 
 	artpec6_pcie->pci = pci;
 	artpec6_pcie->variant = variant;
-	artpec6_pcie->mode = mode;
+	artpec6_pcie->pci->mode = mode;
 
 	artpec6_pcie->phy_base =
 		devm_platform_ioremap_resource_byname(pdev, "phy");
@@ -428,7 +427,7 @@ static int artpec6_pcie_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, artpec6_pcie);
 
-	switch (artpec6_pcie->mode) {
+	switch (artpec6_pcie->pci->mode) {
 	case DW_PCIE_RC_TYPE:
 		if (!IS_ENABLED(CONFIG_PCIE_ARTPEC6_HOST))
 			return -ENODEV;
@@ -464,7 +463,7 @@ static int artpec6_pcie_probe(struct platform_device *pdev)
 
 		break;
 	default:
-		dev_err(dev, "INVALID device type %d\n", artpec6_pcie->mode);
+		dev_err(dev, "INVALID device type %d\n", artpec6_pcie->pci->mode);
 	}
 
 	return 0;
-- 
2.34.1


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

* [PATCH 3/4] PCI: dwc: Use common mode field in struct dw_pcie
  2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
  2026-05-01 16:10 ` [PATCH 1/4] PCI: dra7xx: " Hans Zhang
  2026-05-01 16:10 ` [PATCH 2/4] PCI: artpec6: " Hans Zhang
@ 2026-05-01 16:10 ` Hans Zhang
  2026-05-01 16:10 ` [PATCH 4/4] PCI: keembay: " Hans Zhang
  2026-05-01 16:48 ` [PATCH 0/4] PCI: dwc: designware-plat: " Bjorn Helgaas
  4 siblings, 0 replies; 6+ messages in thread
From: Hans Zhang @ 2026-05-01 16:10 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr
  Cc: xrobh, linux-pci, linux-kernel, Hans Zhang

Remove the redundant mode field from struct dw_plat_pcie and use the
existing mode field in struct dw_pcie instead.

This avoids duplication and prevents potential inconsistencies between
the two mode fields.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/dwc/pcie-designware-plat.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-plat.c b/drivers/pci/controller/dwc/pcie-designware-plat.c
index d103ab759c4e..d02286678a0a 100644
--- a/drivers/pci/controller/dwc/pcie-designware-plat.c
+++ b/drivers/pci/controller/dwc/pcie-designware-plat.c
@@ -22,7 +22,6 @@
 
 struct dw_plat_pcie {
 	struct dw_pcie			*pci;
-	enum dw_pcie_device_mode	mode;
 };
 
 struct dw_plat_pcie_of_data {
@@ -118,11 +117,11 @@ static int dw_plat_pcie_probe(struct platform_device *pdev)
 	pci->dev = dev;
 
 	dw_plat_pcie->pci = pci;
-	dw_plat_pcie->mode = mode;
+	dw_plat_pcie->pci->mode = mode;
 
 	platform_set_drvdata(pdev, dw_plat_pcie);
 
-	switch (dw_plat_pcie->mode) {
+	switch (dw_plat_pcie->pci->mode) {
 	case DW_PCIE_RC_TYPE:
 		if (!IS_ENABLED(CONFIG_PCIE_DW_PLAT_HOST))
 			return -ENODEV;
@@ -148,7 +147,7 @@ static int dw_plat_pcie_probe(struct platform_device *pdev)
 
 		break;
 	default:
-		dev_err(dev, "INVALID device type %d\n", dw_plat_pcie->mode);
+		dev_err(dev, "INVALID device type %d\n", dw_plat_pcie->pci->mode);
 		ret = -EINVAL;
 		break;
 	}
-- 
2.34.1


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

* [PATCH 4/4] PCI: keembay: Use common mode field in struct dw_pcie
  2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
                   ` (2 preceding siblings ...)
  2026-05-01 16:10 ` [PATCH 3/4] PCI: dwc: " Hans Zhang
@ 2026-05-01 16:10 ` Hans Zhang
  2026-05-01 16:48 ` [PATCH 0/4] PCI: dwc: designware-plat: " Bjorn Helgaas
  4 siblings, 0 replies; 6+ messages in thread
From: Hans Zhang @ 2026-05-01 16:10 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr
  Cc: xrobh, linux-pci, linux-kernel, Hans Zhang

Remove the redundant mode field from struct keembay_pcie and use the
existing mode field in struct dw_pcie instead.

This avoids duplication and prevents potential inconsistencies between
the two mode fields.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/dwc/pcie-keembay.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-keembay.c b/drivers/pci/controller/dwc/pcie-keembay.c
index 7cf2c312ecec..2459c4d66b88 100644
--- a/drivers/pci/controller/dwc/pcie-keembay.c
+++ b/drivers/pci/controller/dwc/pcie-keembay.c
@@ -58,7 +58,6 @@
 struct keembay_pcie {
 	struct dw_pcie		pci;
 	void __iomem		*apb_base;
-	enum dw_pcie_device_mode mode;
 
 	struct clk		*clk_master;
 	struct clk		*clk_aux;
@@ -117,7 +116,7 @@ static int keembay_pcie_start_link(struct dw_pcie *pci)
 	u32 val;
 	int ret;
 
-	if (pcie->mode == DW_PCIE_EP_TYPE)
+	if (pcie->pci.mode == DW_PCIE_EP_TYPE)
 		return 0;
 
 	keembay_pcie_ltssm_set(pcie, false);
@@ -409,7 +408,7 @@ static int keembay_pcie_probe(struct platform_device *pdev)
 	pci->dev = dev;
 	pci->ops = &keembay_pcie_ops;
 
-	pcie->mode = mode;
+	pcie->pci.mode = mode;
 
 	pcie->apb_base = devm_platform_ioremap_resource_byname(pdev, "apb");
 	if (IS_ERR(pcie->apb_base))
@@ -417,7 +416,7 @@ static int keembay_pcie_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, pcie);
 
-	switch (pcie->mode) {
+	switch (pcie->pci.mode) {
 	case DW_PCIE_RC_TYPE:
 		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_HOST))
 			return -ENODEV;
@@ -443,7 +442,7 @@ static int keembay_pcie_probe(struct platform_device *pdev)
 
 		break;
 	default:
-		dev_err(dev, "Invalid device type %d\n", pcie->mode);
+		dev_err(dev, "Invalid device type %d\n", pcie->pci.mode);
 		return -ENODEV;
 	}
 
-- 
2.34.1


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

* Re: [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie
  2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
                   ` (3 preceding siblings ...)
  2026-05-01 16:10 ` [PATCH 4/4] PCI: keembay: " Hans Zhang
@ 2026-05-01 16:48 ` Bjorn Helgaas
  4 siblings, 0 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2026-05-01 16:48 UTC (permalink / raw)
  To: Hans Zhang
  Cc: lpieralisi, kwilczynski, bhelgaas, jingoohan1, mani, vigneshr,
	Rob Herring, linux-pci, linux-kernel

[cc: xrobh->robh@kernel.org]

On Sat, May 02, 2026 at 12:10:06AM +0800, Hans Zhang wrote:
> Several DesignWare PCIe controller drivers (dra7xx, artpec6,
> designware-plat, and keembay) duplicated the device mode field
> in their private structures, while struct dw_pcie already contains
> this field. This led to:
> 1. Data redundancy and potential inconsistencies
> 2. Increased maintenance complexity
> 3. Error-prone device type checks
> 
> This series fixes these issues by:
> - Removing redundant mode fields from all four drivers
> - Standardizing on dw_pcie->mode for device type detection
> - Simplifying conditional logic in probe/suspend/resume paths
> - Ensuring consistent error reporting
> 
> The changes improve code maintainability and eliminate class of bugs
> related to mode synchronization.
> 
> Hans Zhang (4):
>   PCI: dra7xx: Use common mode field in struct dw_pcie
>   PCI: artpec6: Use common mode field in struct dw_pcie
>   PCI: dwc: Use common mode field in struct dw_pcie
>   PCI: keembay: Use common mode field in struct dw_pcie
> 
>  drivers/pci/controller/dwc/pci-dra7xx.c           | 11 +++++------
>  drivers/pci/controller/dwc/pcie-artpec6.c         |  9 ++++-----
>  drivers/pci/controller/dwc/pcie-designware-plat.c |  7 +++----
>  drivers/pci/controller/dwc/pcie-keembay.c         |  9 ++++-----
>  4 files changed, 16 insertions(+), 20 deletions(-)

Thanks for doing this!

Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>

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

end of thread, other threads:[~2026-05-01 16:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-01 16:10 [PATCH 0/4] PCI: dwc: designware-plat: Use common mode field in struct dw_pcie Hans Zhang
2026-05-01 16:10 ` [PATCH 1/4] PCI: dra7xx: " Hans Zhang
2026-05-01 16:10 ` [PATCH 2/4] PCI: artpec6: " Hans Zhang
2026-05-01 16:10 ` [PATCH 3/4] PCI: dwc: " Hans Zhang
2026-05-01 16:10 ` [PATCH 4/4] PCI: keembay: " Hans Zhang
2026-05-01 16:48 ` [PATCH 0/4] PCI: dwc: designware-plat: " Bjorn Helgaas

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