* [PATCH v4 1/6] PCI: dwc: Export the multiplexed MSI interrupt handler
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Allow modular host glue with a combined application interrupt to dispatch
the internal MSI receiver without installing a second chained handler.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index bbb02458a..1d076bb62 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -85,6 +85,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)
generic_handle_demux_domain_irq(pp->msi_irq_domain, irq_off + pos);
}
}
+EXPORT_SYMBOL_GPL(dw_handle_msi_irq);
/* Chained MSI interrupt service routine */
static void dw_chained_msi_isr(struct irq_desc *desc)
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 1/6] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
2026-12-04 22:33 ` sashiko-bot
2026-12-04 22:22 ` [PATCH v4 3/6] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Describe three Snow Bush lanes, their shared status bank, global reset
controls and 24 MHz reference. PCIe is the only supported operating mode.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
.../bindings/phy/cortina,cs7542-pcie-phy.yaml | 67 ++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
new file mode 100644
index 000000000..9ccde6e05
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/cortina,cs7542-pcie-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 PCIe SerDes
+
+maintainers:
+ - Fil Dunsky <filipp.dunsky@gmail.com>
+
+description: |
+ Three Snow Bush SerDes lanes shared by PCIe and SATA. Only PCIe mode
+ with a 24 MHz reference is described. The PHY specifier is the lane
+ number, 0 through 2. The status resource contains the shared PHY
+ status registers, with a stride of 0x80 bytes per lane.
+
+properties:
+ compatible:
+ const: cortina,cs7542-pcie-phy
+
+ reg:
+ items:
+ - description: Lane 0 programming registers
+ - description: Lane 1 programming registers
+ - description: Lane 2 programming registers
+ - description: Shared PHY status registers
+
+ reg-names:
+ items:
+ - const: phy0
+ - const: phy1
+ - const: phy2
+ - const: status
+
+ clocks:
+ maxItems: 1
+ description: 24 MHz SerDes reference clock
+
+ cortina,global-syscon:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description: Global control syscon providing lane reset and mode selection
+
+ "#phy-cells":
+ const: 1
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - clocks
+ - cortina,global-syscon
+ - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+ - |
+ phy@f00a1000 {
+ compatible = "cortina,cs7542-pcie-phy";
+ reg = <0xf00a1000 0x400>, <0xf00a5000 0x400>,
+ <0xf00a9000 0x400>, <0xf00a0e00 0x180>;
+ reg-names = "phy0", "phy1", "phy2", "status";
+ clocks = <&ref24>;
+ cortina,global-syscon = <&global>;
+ #phy-cells = <1>;
+ };
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes
2026-12-04 22:22 ` [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
@ 2026-12-04 22:33 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 22:33 UTC (permalink / raw)
To: Fil Dunsky
Cc: linux-pci, linux-phy, devicetree, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: phy: PCIe-only compatible for shared PCIe/SATA
CS7542 SerDes
--
commit ab0f5c945bd0055d9e1269a6a87dd8ad9ed65cf6
Author: Fil Dunsky <filipp.dunsky@gmail.com>
dt-bindings: phy: Describe CS7542 PCIe SerDes
This commit adds a Device Tree binding schema for the Cortina Systems
CS7542 PCIe SerDes PHY, describing its three lane register blocks, shared
status registers, 24 MHz reference clock, and global control syscon.
> diff --git a/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
> new file mode 100644
> index 0000000000000..9ccde6e054ec5
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
> @@ -0,0 +1,67 @@
[ ... ]
> +description: |
> + Three Snow Bush SerDes lanes shared by PCIe and SATA. Only PCIe mode
> + with a 24 MHz reference is described. The PHY specifier is the lane
> + number, 0 through 2. The status resource contains the shared PHY
> + status registers, with a stride of 0x80 bytes per lane.
> +
> +properties:
> + compatible:
> + const: cortina,cs7542-pcie-phy
[Severity: Low]
Should the compatible string and binding scope be protocol-agnostic rather
than cortina,cs7542-pcie-phy?
This node owns all three Snow Bush SerDes lanes shared by PCIe and SATA and
controls lane mode selection via cortina,global-syscon. Restricting the
binding to PCIe mode with a 24 MHz reference documents current driver
support rather than the hardware, contrary to writing-bindings.rst.
Once DTBs ship with cortina,cs7542-pcie-phy, future SATA consumers will
have to reference a PCIe-named compatible or require deprecation and
dual-compatible maintenance. Using a protocol-agnostic name such as
cortina,cs7542-serdes avoids baking driver limits into the DT ABI.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-cs7542-pcie-v4-0-6d0101b281b4@gmail.com?part=2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 3/6] phy: Add CS7542 PCIe SerDes support
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 1/6] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 2/6] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Provide per-lane generic PHYs using the vendor 24 MHz programming table
and revision-dependent value. Sequence power and reset through the shared
global regmap and fail on CMU lock timeout with balanced power cleanup.
Use the shared PHY status bank without overlapping PCIe wrapper resources.
Release the reference clock if power-on fails, including when the
power-down register write used for cleanup also fails.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
drivers/phy/Kconfig | 11 ++
drivers/phy/Makefile | 2 +
drivers/phy/phy-cs7542-pcie.c | 236 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 249 insertions(+)
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 105fbe408..77cff94fe 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -204,4 +204,15 @@ source "drivers/phy/tegra/Kconfig"
source "drivers/phy/ti/Kconfig"
source "drivers/phy/xilinx/Kconfig"
+config PHY_CS7542_PCIE
+ tristate "Cortina Systems CS7542 PCIe SerDes"
+ depends on OF && HAS_IOMEM && COMMON_CLK
+ select GENERIC_PHY
+ select MFD_SYSCON
+ help
+ Support the three CS7542 Snow Bush SerDes lanes in PCIe mode
+ with a 24 MHz reference clock. Lane resets share the global syscon.
+ SATA mode and other reference frequencies are not supported.
+ The module is called phy-cs7542-pcie.
+
endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index c6dd02003..54df29e74 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -55,3 +55,5 @@ obj-$(CONFIG_GENERIC_PHY) += allwinner/ \
tegra/ \
ti/ \
xilinx/
+
+obj-$(CONFIG_PHY_CS7542_PCIE) += phy-cs7542-pcie.o
diff --git a/drivers/phy/phy-cs7542-pcie.c b/drivers/phy/phy-cs7542-pcie.c
new file mode 100644
index 000000000..71490885e
--- /dev/null
+++ b/drivers/phy/phy-cs7542-pcie.c
@@ -0,0 +1,236 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* CS7542 Snow Bush SerDes, PCIe mode with a 24 MHz reference clock. */
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define GLOBAL_JTAG_ID 0x00
+#define GLOBAL_PHY_CONTROL 0x14
+#define PHY_REFCLK_MASK(p) (3U << ((p) * 2))
+#define PHY_REFCLK_24MHZ(p) (2U << ((p) * 2))
+#define PHY_PD(p) BIT(8 + (p))
+#define PHY_CMU_RESETN(p) BIT(16 + (p) * 4)
+#define PHY_LN0_RESETN(p) BIT(17 + (p) * 4)
+#define PHY_POR_N(p) BIT(19 + (p) * 4)
+#define PHY_CMU_OK BIT(18)
+#define PHY_STATUS_STRIDE 0x80
+#define SNOW_COM_REG0 0x00
+#define SNOW_REG0_CFG 0x00090006
+#define SNOW_REG0_AHB_RESETN BIT(0)
+#define SNOW_REV_REG 96
+#define SNOW_REV_REG_A0 0x5e082e00
+#define SNOW_REV_REG_A1 0x5e080600
+#define SNOW_COM_LANE_REG0 0xc8
+#define SNOW_LANE_REG0_CFG 0x400290c0
+#define SNOW_LANE_REG0_MASTER_RESETN BIT(1)
+#define CS7542_PORTS 3
+
+struct cs7542_serdes;
+struct cs7542_lane {
+ struct cs7542_serdes *serdes;
+ void __iomem *base;
+ struct phy *phy;
+ unsigned int id;
+};
+
+struct cs7542_serdes {
+ struct device *dev;
+ struct regmap *global;
+ void __iomem *status;
+ struct clk *ref;
+ struct cs7542_lane lanes[CS7542_PORTS];
+ u32 revision_value;
+};
+
+struct snow_reg {
+ u16 off;
+ u32 val;
+};
+
+static const struct snow_reg snow_phy_24mhz[] = {
+ { 0, SNOW_REG0_CFG }, { 4, 0x000e0960 }, { 32, 0x68a00000 },
+ { 44, 0x50040000 }, { 48, 0x40250270 }, { 52, 0x00004001 },
+ { 100, 0xf0914200 }, { 104, 0x4c0c9048 }, { 108, 0x00000373 },
+ { 124, 0x04841000 }, { 128, 0x000000e0 }, { 132, 0x04000023 },
+ { 136, 0x68001038 }, { 140, 0x0d181ea2 }, { 144, 0x0000000c },
+ { 196, 0x0f600000 }, { 200, SNOW_LANE_REG0_CFG }, { 204, 0x0000003c },
+ { 208, 0xc68b8300 }, { 212, 0x98280301 }, { 216, 0xe1782819 },
+ { 220, 0x00f410f0 }, { 232, 0xa0a0a000 }, { 236, 0xa0a0a0a0 },
+ { 240, 0x9fc00068 }, { 244, 0x00000001 }, { 248, 0x00000000 },
+ { 252, 0xd07e4130 }, { 256, 0x935285cc }, { 260, 0xb0dd49e0 },
+ { 264, 0x0000020b }, { 300, 0xd8000000 }, { 304, 0x0001ff1a },
+ { 308, 0xf0000000 }, { 312, 0xffffffff }, { 316, 0x3fc3c21c },
+ { 320, 0x0000000a }, { 324, 0x00f80000 },
+};
+
+static int cs7542_phy_power_off(struct phy *phy)
+{
+ struct cs7542_lane *lane = phy_get_drvdata(phy);
+ unsigned int p = lane->id;
+ u32 mask = PHY_PD(p) | PHY_CMU_RESETN(p) | PHY_LN0_RESETN(p) | PHY_POR_N(p);
+ int ret;
+
+ ret = regmap_update_bits(lane->serdes->global, GLOBAL_PHY_CONTROL, mask, PHY_PD(p));
+ if (ret)
+ return ret;
+ clk_disable_unprepare(lane->serdes->ref);
+ return ret;
+}
+
+static int cs7542_phy_power_on(struct phy *phy)
+{
+ struct cs7542_lane *lane = phy_get_drvdata(phy);
+ struct cs7542_serdes *sd = lane->serdes;
+ unsigned int p = lane->id;
+ u32 mask, value;
+ int ret, i;
+
+ ret = clk_prepare_enable(sd->ref);
+ if (ret)
+ return ret;
+ mask = PHY_PD(p) | PHY_CMU_RESETN(p) | PHY_LN0_RESETN(p) | PHY_POR_N(p) |
+ PHY_REFCLK_MASK(p);
+ ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, mask,
+ PHY_PD(p) | PHY_REFCLK_24MHZ(p));
+ if (ret)
+ goto power_off;
+ msleep(100);
+ ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_PD(p) | PHY_POR_N(p),
+ PHY_POR_N(p));
+ if (ret)
+ goto power_off;
+ usleep_range(10, 20);
+ for (i = 0; i < ARRAY_SIZE(snow_phy_24mhz); i++) {
+ if (snow_phy_24mhz[i].off == SNOW_REV_REG + 4)
+ writel(sd->revision_value, lane->base + SNOW_REV_REG);
+ writel(snow_phy_24mhz[i].val, lane->base + snow_phy_24mhz[i].off);
+ }
+ writel(SNOW_REG0_CFG | SNOW_REG0_AHB_RESETN, lane->base + SNOW_COM_REG0);
+ ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_CMU_RESETN(p),
+ PHY_CMU_RESETN(p));
+ if (ret)
+ goto power_off;
+ ret = readl_poll_timeout(sd->status + p * PHY_STATUS_STRIDE, value,
+ value & PHY_CMU_OK, 100, 100000);
+ if (ret) {
+ dev_err(sd->dev, "lane %u CMU did not lock\n", p);
+ goto power_off;
+ }
+ writel(SNOW_LANE_REG0_CFG | SNOW_LANE_REG0_MASTER_RESETN,
+ lane->base + SNOW_COM_LANE_REG0);
+ ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_LN0_RESETN(p),
+ PHY_LN0_RESETN(p));
+ if (ret)
+ goto power_off;
+ msleep(100);
+ return 0;
+
+power_off:
+ /* Failed power_on has no generic PHY power reference to retain. */
+ if (cs7542_phy_power_off(phy))
+ clk_disable_unprepare(sd->ref);
+ return ret;
+}
+
+static int cs7542_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+ return mode == PHY_MODE_PCIE && !submode ? 0 : -EINVAL;
+}
+
+static const struct phy_ops cs7542_phy_ops = {
+ .power_on = cs7542_phy_power_on,
+ .power_off = cs7542_phy_power_off,
+ .set_mode = cs7542_phy_set_mode,
+ .owner = THIS_MODULE,
+};
+
+static struct phy *cs7542_phy_xlate(struct device *dev, const struct of_phandle_args *args)
+{
+ struct cs7542_serdes *sd = dev_get_drvdata(dev);
+
+ if (args->args_count != 1 || args->args[0] >= CS7542_PORTS)
+ return ERR_PTR(-EINVAL);
+ return sd->lanes[args->args[0]].phy;
+}
+
+static int cs7542_phy_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct phy_provider *provider;
+ struct cs7542_serdes *sd;
+ unsigned int id;
+ int ret, i;
+
+ sd = devm_kzalloc(dev, sizeof(*sd), GFP_KERNEL);
+ if (!sd)
+ return -ENOMEM;
+ sd->dev = dev;
+ sd->global = syscon_regmap_lookup_by_phandle(dev->of_node, "cortina,global-syscon");
+ if (IS_ERR(sd->global))
+ return dev_err_probe(dev, PTR_ERR(sd->global), "global register map\n");
+ sd->ref = devm_clk_get(dev, NULL);
+ if (IS_ERR(sd->ref))
+ return dev_err_probe(dev, PTR_ERR(sd->ref), "reference clock\n");
+ if (clk_get_rate(sd->ref) != 24000000)
+ return dev_err_probe(dev, -EINVAL, "only 24 MHz reference supported\n");
+ ret = regmap_read(sd->global, GLOBAL_JTAG_ID, &id);
+ if (ret)
+ return ret;
+ switch (FIELD_GET(GENMASK(15, 12), id)) {
+ case 0:
+ case 1:
+ sd->revision_value = SNOW_REV_REG_A0;
+ break;
+ case 8:
+ case 9:
+ sd->revision_value = SNOW_REV_REG_A1;
+ break;
+ default:
+ return dev_err_probe(dev, -ENODEV, "unsupported silicon revision %#x\n", id);
+ }
+ sd->status = devm_platform_ioremap_resource(pdev, CS7542_PORTS);
+ if (IS_ERR(sd->status))
+ return PTR_ERR(sd->status);
+ for (i = 0; i < CS7542_PORTS; i++) {
+ struct cs7542_lane *lane = &sd->lanes[i];
+
+ lane->id = i;
+ lane->serdes = sd;
+ lane->base = devm_platform_ioremap_resource(pdev, i);
+ if (IS_ERR(lane->base))
+ return PTR_ERR(lane->base);
+ lane->phy = devm_phy_create(dev, NULL, &cs7542_phy_ops);
+ if (IS_ERR(lane->phy))
+ return PTR_ERR(lane->phy);
+ phy_set_drvdata(lane->phy, lane);
+ }
+ platform_set_drvdata(pdev, sd);
+ provider = devm_of_phy_provider_register(dev, cs7542_phy_xlate);
+ return PTR_ERR_OR_ZERO(provider);
+}
+
+static const struct of_device_id cs7542_phy_match[] = {
+ { .compatible = "cortina,cs7542-pcie-phy" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, cs7542_phy_match);
+
+static struct platform_driver cs7542_phy_driver = {
+ .probe = cs7542_phy_probe,
+ .driver = {
+ .name = "cs7542-pcie-phy",
+ .of_match_table = cs7542_phy_match,
+ },
+};
+module_platform_driver(cs7542_phy_driver);
+
+MODULE_DESCRIPTION("Cortina Systems CS7542 PCIe SerDes");
+MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
` (2 preceding siblings ...)
2026-12-04 22:22 ` [PATCH v4 3/6] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
2026-12-04 22:33 ` sashiko-bot
2026-12-04 22:22 ` [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
2026-12-04 22:22 ` [PATCH v4 6/6] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay
5 siblings, 1 reply; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Describe the DesignWare host wrapper, clock/reset/PHY consumers, combined
interrupt and INTx domain. Document the root configuration access limit.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
.../bindings/pci/cortina,cs7542-pcie.yaml | 157 +++++++++++++++++++++
1 file changed, 157 insertions(+)
diff --git a/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
new file mode 100644
index 000000000..64cd7c744
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
@@ -0,0 +1,157 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/cortina,cs7542-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 PCIe host controller
+
+maintainers:
+ - Fil Dunsky <filipp.dunsky@gmail.com>
+
+description: |
+ DesignWare host with a Cortina application wrapper. A single interrupt
+ multiplexes four INTx lines, the internal MSI receiver and link errors.
+ Root-port configuration is accessible only below offset 0x200; the
+ DesignWare private register bank starts at offset 0x700.
+
+allOf:
+ - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+ compatible:
+ const: cortina,cs7542-pcie
+
+ reg:
+ items:
+ - description: DBI registers including the viewport iATU
+ - description: Downstream configuration window
+ - description: Application wrapper registers
+
+ reg-names:
+ items:
+ - const: dbi
+ - const: config
+ - const: app
+
+ clocks:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ interrupt-names:
+ const: msi
+
+ resets:
+ maxItems: 1
+
+ phys:
+ maxItems: 1
+
+ phy-names:
+ const: pcie
+
+ num-lanes:
+ const: 1
+
+ reset-gpios: false
+
+ interrupt-controller:
+ type: object
+ additionalProperties: false
+ properties:
+ "#address-cells":
+ const: 0
+ "#interrupt-cells":
+ const: 1
+ interrupt-controller: true
+ required:
+ - "#address-cells"
+ - "#interrupt-cells"
+ - interrupt-controller
+
+patternProperties:
+ "^pcie@[0-9a-f]+,[0-7]$":
+ type: object
+ $ref: /schemas/pci/pci-pci-bridge.yaml#
+ additionalProperties: true
+ description: |
+ The single Root Port of this controller. Endpoint PERST# belongs to
+ this port, rather than the host bridge.
+ properties:
+ reset-gpios:
+ maxItems: 1
+ description: Optional active-low endpoint PERST#
+ required:
+ - compatible
+ - reg
+ - device_type
+ - '#address-cells'
+ - '#size-cells'
+ - ranges
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - clocks
+ - interrupts
+ - interrupt-names
+ - resets
+ - phys
+ - phy-names
+ - num-lanes
+ - pcie@0,0
+ - interrupt-controller
+ - interrupt-map
+ - interrupt-map-mask
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/cortina,cs7542-clock.h>
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+ #include <dt-bindings/reset/cortina,cs7542-reset.h>
+
+ pcie@80000000 {
+ compatible = "cortina,cs7542-pcie";
+ reg = <0x80000000 0x1000>, <0x80001000 0x1000>,
+ <0xf00a0000 0x100>;
+ reg-names = "dbi", "config", "app";
+ #address-cells = <3>;
+ #size-cells = <2>;
+ device_type = "pci";
+ bus-range = <0 0xff>;
+ num-lanes = <1>;
+ ranges = <0x82000000 0 0x80200000 0x80200000 0 0x1fe00000>;
+ clocks = <&global CS7542_CLK_PCIE0>;
+ interrupt-parent = <&gic>;
+ interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "msi";
+ resets = <&global CS7542_RESET_PCIE0>;
+ phys = <&serdes 0>;
+ phy-names = "pcie";
+ #interrupt-cells = <1>;
+ interrupt-map-mask = <0 0 0 7>;
+ interrupt-map = <0 0 0 1 &pcie_intc 1>,
+ <0 0 0 2 &pcie_intc 2>,
+ <0 0 0 3 &pcie_intc 3>,
+ <0 0 0 4 &pcie_intc 4>;
+
+ pcie@0,0 {
+ compatible = "pciclass,0604";
+ reg = <0 0 0 0 0>;
+ device_type = "pci";
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+ };
+
+ pcie_intc: interrupt-controller {
+ #address-cells = <0>;
+ #interrupt-cells = <1>;
+ interrupt-controller;
+ };
+ };
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller
2026-12-04 22:22 ` [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
@ 2026-12-04 22:33 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 22:33 UTC (permalink / raw)
To: Fil Dunsky
Cc: linux-pci, linux-phy, devicetree, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] dt-bindings: pci: Root Port uses additionalProperties: true
- [Low] dt-bindings: pci: Root Port regex allows extra non-existent
ports
- [Low] dt-bindings: pci: redundant legacy phy-names for single PHY
--
commit 79b55635355834a2edd3875ad0c012643b49ab39
Author: Fil Dunsky <filipp.dunsky@gmail.com>
dt-bindings: PCI: Describe the CS7542 host controller
This commit adds the Device Tree binding schema for the Cortina Systems
CS7542 DesignWare-based PCIe host controller, documenting its register
windows, clock, reset, PHY, combined interrupt, INTx domain, and single
Root Port node.
> diff --git a/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
> new file mode 100644
> index 0000000000000..64cd7c7448513
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
> @@ -0,0 +1,157 @@
[ ... ]
> + phys:
> + maxItems: 1
> +
> + phy-names:
> + const: pcie
[Severity: Low]
Is phy-names needed here for a single PHY?
The single clock and reset properties in this binding omit -names, and
devm_phy_get(dev, NULL) resolves index 0 without it. In addition,
snps,dw-pcie-common.yaml categorizes "pcie" as a vendor-specific name to
avoid in new bindings in favor of generic names like "pcie0".
Consider dropping phy-names, or using "pcie0" if it is kept.
[ ... ]
> +patternProperties:
> + "^pcie@[0-9a-f]+,[0-7]$":
[Severity: Low]
Does this pattern allow extra non-existent Root Port nodes and invalid
PCI device numbers above 0x1f to pass dtbs_check?
The description states there is a single Root Port and required already
fixes it to pcie@0,0. Defining pcie@0,0 directly under properties (or
narrowing the pattern to ^pcie@0,0$) would match the hardware topology.
> + type: object
> + $ref: /schemas/pci/pci-pci-bridge.yaml#
> + additionalProperties: true
[Severity: Low]
Should this use unevaluatedProperties: false instead of
additionalProperties: true?
Setting additionalProperties: true disables schema validation of unknown
or misspelled properties (such as a typoed reset-gpio) inside the Root
Port node. With unevaluatedProperties: false, all properties from
pci-pci-bridge.yaml remain allowed while unexpected ones are caught.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-cs7542-pcie-v4-0-6d0101b281b4@gmail.com?part=4
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
` (3 preceding siblings ...)
2026-12-04 22:22 ` [PATCH v4 4/6] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
2026-12-04 22:51 ` sashiko-bot
2026-12-04 22:22 ` [PATCH v4 6/6] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay
5 siblings, 1 reply; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Add DesignWare host glue consuming separate clock, reset and PHY
providers. Use live link status and stop previous training before
enumeration. Finish endpoint teardown before draining the shared IRQ and
freeing MSI domains. Dispatch enabled INTx/MSI sources through one
application interrupt and use its MSI target window.
Prevent root configuration accesses at and above 0x200, including direct
DesignWare DBI reads, while preserving the private CSR bank and separate
iATU callback base. Unwind power and IRQ domains on failure and removal.
Read live link/LTSSM state through the application wrapper. After link
loss, block configuration and DBI accesses until controller reset and
reprobe.
Hold the controller reset throughout PHY power-up. After the PHY is
ready, wait 10 ms before releasing the reset and another 10 ms before
accessing the host registers. The host uses the reset consumer API.
A secondary bus reset can leave the DBI aperture inaccessible even after
Link Active is set. Block configuration accesses and mask application
interrupts before asserting secondary bus reset. Reset the controller,
restore Root Port windows and MSI programming, then unmask interrupts
once the link is active again. Preserve INTx mask changes made while
reset is in progress. A failed reset keeps accesses blocked until reprobe.
Save the current Root Port configuration under the reset mutex so the
PCI core can restore the bridge state that was active before the reset.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
drivers/pci/controller/dwc/Kconfig | 12 +
drivers/pci/controller/dwc/Makefile | 1 +
drivers/pci/controller/dwc/pcie-cs7542.c | 803 +++++++++++++++++++++++++++++++
3 files changed, 816 insertions(+)
diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
index 0a0d56fcf..a9b489801 100644
--- a/drivers/pci/controller/dwc/Kconfig
+++ b/drivers/pci/controller/dwc/Kconfig
@@ -95,6 +95,17 @@ config PCIE_ARTPEC6_EP
Enables support for the PCIe controller in the ARTPEC-6 SoC to work in
endpoint mode. This uses the DesignWare core.
+config PCIE_CS7542
+ tristate "Cortina Systems CS7542 PCIe controller"
+ depends on OF && HAS_IOMEM && PCI_MSI && COMMON_CLK
+ select PCIE_DW_HOST
+ select GENERIC_PHY
+ help
+ Enable the DesignWare PCIe host controllers on Cortina CS7542.
+ The global clock/reset provider and a generic PHY are required.
+ The application interrupt handles both legacy INTx and MSI.
+ The module is called pcie-cs7542.
+
config PCIE_ESWIN
tristate "ESWIN PCIe controller"
depends on ARCH_ESWIN || COMPILE_TEST
@@ -577,4 +588,5 @@ config PCIE_ULTRARISC
By default, this symbol is enabled when ARCH_ULTRARISC is active,
requiring no further configuration on that platform.
+
endmenu
diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile
index d4f88cfc6..185a9fa43 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_PCIE_DW_EP) += pcie-designware-ep.o
obj-$(CONFIG_PCIE_DW_PLAT) += pcie-designware-plat.o
obj-$(CONFIG_PCIE_AMD_MDB) += pcie-amd-mdb.o
obj-$(CONFIG_PCIE_ANDES_QILAI) += pcie-andes-qilai.o
+obj-$(CONFIG_PCIE_CS7542) += pcie-cs7542.o
obj-$(CONFIG_PCIE_ESWIN) += pcie-eswin.o
obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
new file mode 100644
index 000000000..4be7a99f0
--- /dev/null
+++ b/drivers/pci/controller/dwc/pcie-cs7542.c
@@ -0,0 +1,803 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_pci.h>
+#include <linux/pci.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/resource.h>
+
+#include "../../pci.h"
+
+#include "pcie-designware.h"
+
+#define APP_INT_STATUS 0x00
+#define APP_INT_ENABLE 0x04
+#define APP_CORE_CONFIG 0x1c
+#define APP_PM_STATUS 0x20
+#define APP_LINK_ACTIVE BIT(18)
+#define APP_LTSSM_STATE GENMASK(9, 4)
+#define APP_CFG_START 0x80
+#define APP_CFG_END 0x84
+
+#define INT_INTX_ASSERT(x) BIT((x) * 2)
+#define INT_INTX_ASSERT_MASK (BIT(0) | BIT(2) | BIT(4) | BIT(6))
+#define INT_MSI BIT(8)
+#define INT_LINK_UP BIT(9)
+#define INT_RADM_NONFATAL_ERR BIT(12)
+#define INT_RADM_FATAL_ERR BIT(13)
+#define INT_GM_COMPOSER_ERR BIT(16)
+#define INT_RADMX_COMPOSER_ERR BIT(17)
+#define INT_ELASTIC_OVF BIT(18)
+#define INT_ELASTIC_UNF BIT(19)
+#define INT_LINK_DOWN BIT(22)
+#define INT_ERR_MASK (INT_RADM_NONFATAL_ERR | INT_RADM_FATAL_ERR | \
+ INT_GM_COMPOSER_ERR | \
+ INT_RADMX_COMPOSER_ERR | \
+ INT_ELASTIC_OVF | INT_ELASTIC_UNF | \
+ INT_LINK_DOWN)
+
+#define CORE_CFG_LTSSM_EN BIT(0)
+#define CORE_CFG_AXI_UR_MASK BIT(5)
+
+#define APP_PORT_STRIDE 0x400
+#define APP_PHYS_BASE 0xF00A0000
+#define APP_CFG_WINDOW_LEN 0x1000
+#define APP_MSI_BUS_BASE 0xf00a00c0
+#define APP_CFG_POLL_US 10
+#define APP_CFG_TIMEOUT_US 10000
+#define RC_CFG_LIMIT 0x200
+#define DWC_PRIVATE_REG_BASE 0x700
+
+struct cortina_pcie_port {
+ struct gpio_desc *perst;
+};
+
+struct cortina_pcie {
+ struct dw_pcie pci;
+ void __iomem *app;
+ struct clk *clk;
+ struct phy *phy;
+ struct reset_control *reset;
+ struct cortina_pcie_port port;
+ int irq;
+ bool msi_ready;
+ bool link_lost;
+ bool resetting;
+ bool dbi_blocked;
+ u32 intx_enabled;
+ struct irq_domain *intx_domain;
+ /* Serialize state snapshots and controller resets. */
+ struct mutex reset_lock;
+ raw_spinlock_t lock;
+ resource_size_t dbi_phys;
+ int index;
+};
+
+#define to_cortina_pcie(x) container_of((x), struct cortina_pcie, pci)
+
+static int cortina_pcie_port_init(struct cortina_pcie *cp)
+{
+ u32 value;
+ int ret;
+
+ writel(cp->dbi_phys, cp->app + APP_CFG_START);
+ writel(cp->dbi_phys + APP_CFG_WINDOW_LEN - 1, cp->app + APP_CFG_END);
+ ret = readl_poll_timeout(cp->app + APP_CFG_END, value,
+ value == cp->dbi_phys + APP_CFG_WINDOW_LEN - 1,
+ APP_CFG_POLL_US, APP_CFG_TIMEOUT_US);
+ if (ret)
+ return ret;
+ writel(0, cp->app + APP_INT_ENABLE);
+ writel(readl(cp->app + APP_INT_STATUS), cp->app + APP_INT_STATUS);
+ return 0;
+}
+
+/* APP remains accessible after link loss, unlike the DBI port debug bank. */
+static bool cortina_pcie_link_up(struct dw_pcie *pci)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+
+ return !READ_ONCE(cp->link_lost) && !READ_ONCE(cp->resetting) &&
+ !!(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE);
+}
+
+static enum dw_pcie_ltssm cortina_pcie_get_ltssm(struct dw_pcie *pci)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+
+ return FIELD_GET(APP_LTSSM_STATE, readl(cp->app + APP_PM_STATUS));
+}
+
+static int cortina_pcie_start_link(struct dw_pcie *pci)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ u32 value;
+
+ /* DesignWare calls this after programming the Root Port. */
+ gpiod_set_value_cansleep(cp->port.perst, 0);
+ msleep(PCIE_RESET_CONFIG_WAIT_MS);
+
+ value = readl(cp->app + APP_CORE_CONFIG);
+ value |= CORE_CFG_LTSSM_EN | CORE_CFG_AXI_UR_MASK;
+ writel(value, cp->app + APP_CORE_CONFIG);
+ return 0;
+}
+
+static void cortina_pcie_stop_link(struct dw_pcie *pci)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ u32 value = readl(cp->app + APP_CORE_CONFIG);
+
+ writel(value & ~CORE_CFG_LTSSM_EN, cp->app + APP_CORE_CONFIG);
+}
+
+static void cortina_pcie_irq_handler(struct irq_desc *desc)
+{
+ struct cortina_pcie *cp = irq_desc_get_handler_data(desc);
+ struct irq_chip *chip = irq_desc_get_chip(desc);
+ u32 status, clear;
+ bool resetting;
+ int i;
+
+ chained_irq_enter(chip, desc);
+
+ status = readl(cp->app + APP_INT_STATUS);
+ status &= readl(cp->app + APP_INT_ENABLE);
+ clear = status & ~INT_LINK_UP;
+ if (status & INT_LINK_DOWN)
+ clear |= INT_LINK_UP;
+ writel(clear, cp->app + APP_INT_STATUS);
+
+ if (status & INT_LINK_DOWN) {
+ /* No in-place link recovery; reject MMIO until reprobe. */
+ raw_spin_lock(&cp->lock);
+ resetting = cp->resetting;
+ if (!resetting) {
+ WRITE_ONCE(cp->link_lost, true);
+ writel(0, cp->app + APP_INT_ENABLE);
+ }
+ raw_spin_unlock(&cp->lock);
+ if (!resetting)
+ dev_warn_ratelimited(cp->pci.dev,
+ "link lost; controller reprobe required\n");
+ goto out;
+ }
+
+ if (status & INT_ERR_MASK)
+ dev_err_ratelimited(cp->pci.dev, "port %d: PCIe error, status %#x\n",
+ cp->index, status);
+
+ for (i = 0; i < PCI_NUM_INTX; i++)
+ if (status & INT_INTX_ASSERT(i))
+ generic_handle_domain_irq(cp->intx_domain, i);
+ if ((status & INT_MSI) && cp->msi_ready)
+ dw_handle_msi_irq(&cp->pci.pp);
+
+out:
+ chained_irq_exit(chip, desc);
+}
+
+static void cortina_intx_mask(struct irq_data *d)
+{
+ struct cortina_pcie *cp = irq_data_get_irq_chip_data(d);
+ u32 bit = INT_INTX_ASSERT(d->hwirq);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ cp->intx_enabled &= ~bit;
+ if (!cp->resetting && !cp->link_lost)
+ writel(readl(cp->app + APP_INT_ENABLE) & ~bit,
+ cp->app + APP_INT_ENABLE);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+}
+
+static void cortina_intx_unmask(struct irq_data *d)
+{
+ struct cortina_pcie *cp = irq_data_get_irq_chip_data(d);
+ u32 bit = INT_INTX_ASSERT(d->hwirq);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ cp->intx_enabled |= bit;
+ /* Do not undo link-loss or teardown masking from an INTx callback. */
+ if (!cp->resetting && !cp->link_lost)
+ writel(readl(cp->app + APP_INT_ENABLE) | bit,
+ cp->app + APP_INT_ENABLE);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+}
+
+static struct irq_chip cortina_intx_chip = {
+ .name = "cortina-INTx",
+ .irq_mask = cortina_intx_mask,
+ .irq_unmask = cortina_intx_unmask,
+};
+
+static int cortina_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
+ irq_hw_number_t hwirq)
+{
+ irq_set_chip_and_handler(irq, &cortina_intx_chip, handle_simple_irq);
+ irq_set_chip_data(irq, domain->host_data);
+ return 0;
+}
+
+static const struct irq_domain_ops cortina_intx_domain_ops = {
+ .map = cortina_pcie_intx_map,
+ .xlate = pci_irqd_intx_xlate,
+};
+
+static int cortina_pcie_init_irq_domain(struct cortina_pcie *cp)
+{
+ struct device *dev = cp->pci.dev;
+ struct device_node *intc;
+ struct fwnode_handle *fwnode;
+
+ intc = of_get_child_by_name(dev->of_node, "interrupt-controller");
+ if (!intc)
+ return dev_err_probe(dev, -ENODEV, "no interrupt-controller child\n");
+
+ fwnode = of_fwnode_handle(intc);
+ cp->intx_domain = irq_domain_create_linear(fwnode, PCI_NUM_INTX,
+ &cortina_intx_domain_ops, cp);
+ of_node_put(intc);
+ if (!cp->intx_domain)
+ return dev_err_probe(dev, -ENOMEM, "cannot create INTx domain\n");
+ return 0;
+}
+
+static int cortina_pcie_rd_own_conf(struct pci_bus *bus, unsigned int devfn,
+ int where, int size, u32 *val)
+{
+ struct dw_pcie *pci = to_dw_pcie_from_pp(bus->sysdata);
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ unsigned long flags;
+ int ret;
+
+ PCI_SET_ERROR_RESPONSE(val);
+ if (where < 0 || (size != 1 && size != 2 && size != 4) ||
+ (where & (size - 1)))
+ return PCIBIOS_BAD_REGISTER_NUMBER;
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (cp->link_lost || cp->resetting) {
+ ret = PCIBIOS_DEVICE_NOT_FOUND;
+ } else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) {
+ *val = 0;
+ ret = PCIBIOS_SUCCESSFUL;
+ } else {
+ ret = pci_generic_config_read(bus, devfn, where, size, val);
+ }
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ return ret;
+}
+
+static int cortina_pcie_wr_own_conf(struct pci_bus *bus, unsigned int devfn,
+ int where, int size, u32 val)
+{
+ struct dw_pcie *pci = to_dw_pcie_from_pp(bus->sysdata);
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ unsigned long flags;
+ int ret;
+
+ if (where < 0 || (size != 1 && size != 2 && size != 4) ||
+ (where & (size - 1)))
+ return PCIBIOS_BAD_REGISTER_NUMBER;
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (cp->link_lost || cp->resetting)
+ ret = PCIBIOS_DEVICE_NOT_FOUND;
+ else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where)
+ ret = PCIBIOS_SUCCESSFUL;
+ else
+ ret = pci_generic_config_write(bus, devfn, where, size, val);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ return ret;
+}
+
+static struct pci_ops cortina_own_pci_ops = {
+ .map_bus = dw_pcie_own_conf_map_bus,
+ .read = cortina_pcie_rd_own_conf,
+ .write = cortina_pcie_wr_own_conf,
+};
+
+static void __iomem *cortina_reset_map_bus(struct pci_bus *bus,
+ unsigned int devfn, int where)
+{
+ return NULL;
+}
+
+static struct pci_ops cortina_reset_pci_ops = {
+ .map_bus = cortina_reset_map_bus,
+ .read = pci_generic_config_read,
+ .write = pci_generic_config_write,
+};
+
+static void cortina_pcie_program_msi(struct dw_pcie_rp *pp)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(pp));
+ unsigned long flags;
+ u32 ctrl, offset;
+
+ raw_spin_lock_irqsave(&pp->lock, flags);
+ for (ctrl = 0; ctrl < pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; ctrl++) {
+ offset = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
+ dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_INTR0_MASK + offset,
+ pp->irq_mask[ctrl]);
+ dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_INTR0_ENABLE + offset,
+ ~0);
+ }
+ dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_ADDR_LO, lower_32_bits(pp->msi_data));
+ dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_ADDR_HI, upper_32_bits(pp->msi_data));
+ raw_spin_unlock_irqrestore(&pp->lock, flags);
+}
+
+static void cortina_pcie_enable_msi(struct dw_pcie_rp *pp)
+{
+ struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ u8 cap;
+ u16 flags;
+
+ /* pci=nomsi skips receiver initialization; preserve that policy. */
+ if (!cp->msi_ready)
+ return;
+
+ cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI);
+ /* PCI enumeration clears MSI enable while initializing capabilities. */
+ if (cap) {
+ flags = dw_pcie_readw_dbi(pci, cap + PCI_MSI_FLAGS);
+ dw_pcie_writew_dbi(pci, cap + PCI_MSI_FLAGS,
+ flags | PCI_MSI_FLAGS_ENABLE);
+ }
+}
+
+/*
+ * A standard hot reset can leave the CS7542 DBI aperture inaccessible
+ * until the controller is reset, even after APP reports Link Active.
+ * Send the downstream reset and reinitialize only this controller.
+ */
+static int cortina_pcie_reset_root_port(struct pci_host_bridge *bridge,
+ struct pci_dev *root)
+{
+ struct dw_pcie_rp *pp = bridge->bus->sysdata;
+ struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ struct pci_ops *saved_ops;
+ unsigned long flags;
+ u32 mask, status;
+ u16 control;
+ int ret;
+
+ guard(mutex)(&cp->reset_lock);
+ if (READ_ONCE(cp->link_lost))
+ return -ENOLINK;
+
+ /* The PCI core restores the Root Port state after the callback. */
+ ret = pci_save_state(root);
+ if (ret)
+ return ret;
+
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (cp->link_lost) {
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ return -ENOLINK;
+ }
+ WRITE_ONCE(cp->resetting, true);
+ cp->dbi_blocked = true;
+ mask = readl(cp->app + APP_INT_ENABLE) & ~INT_INTX_ASSERT_MASK;
+ writel(0, cp->app + APP_INT_ENABLE);
+ readl(cp->app + APP_INT_ENABLE);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+
+ synchronize_irq(cp->irq);
+ /* Drain in-flight PCI config access before resetting the DBI aperture. */
+ saved_ops = pci_bus_set_ops(root->bus, &cortina_reset_pci_ops);
+ if (!(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE)) {
+ ret = -ENOLINK;
+ goto finish;
+ }
+ control = readw(pci->dbi_base + PCI_BRIDGE_CONTROL);
+ writew(control | PCI_BRIDGE_CTL_BUS_RESET,
+ pci->dbi_base + PCI_BRIDGE_CONTROL);
+ /* PCI requires at least 1 ms assertion time for secondary bus reset. */
+ usleep_range(2000, 3000);
+ writew(control & ~PCI_BRIDGE_CTL_BUS_RESET,
+ pci->dbi_base + PCI_BRIDGE_CONTROL);
+
+ cortina_pcie_stop_link(pci);
+ ret = reset_control_assert(cp->reset);
+ if (ret)
+ goto finish;
+ usleep_range(10000, 12000);
+ ret = reset_control_deassert(cp->reset);
+ if (ret)
+ goto finish;
+ usleep_range(10000, 12000);
+
+ cortina_pcie_stop_link(pci);
+ ret = cortina_pcie_port_init(cp);
+ if (ret)
+ goto finish;
+ /* Internal DBI is ready. External config stays blocked until link-up. */
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ cp->dbi_blocked = false;
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ ret = dw_pcie_setup_rc(pp);
+ if (ret)
+ goto finish;
+
+ if (cp->msi_ready) {
+ cortina_pcie_program_msi(pp);
+ cortina_pcie_enable_msi(pp);
+ }
+
+ ret = cortina_pcie_start_link(pci);
+ if (ret)
+ goto finish;
+ ret = readl_poll_timeout(cp->app + APP_PM_STATUS, status,
+ status & APP_LINK_ACTIVE,
+ USEC_PER_MSEC, USEC_PER_SEC);
+finish:
+ pci_bus_set_ops(root->bus, saved_ops);
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (!ret) {
+ writel(INT_LINK_DOWN | INT_LINK_UP, cp->app + APP_INT_STATUS);
+ if (cp->link_lost ||
+ !(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE))
+ ret = -ENOLINK;
+ }
+ if (ret)
+ WRITE_ONCE(cp->link_lost, true);
+ else
+ writel(mask | cp->intx_enabled, cp->app + APP_INT_ENABLE);
+ cp->dbi_blocked = false;
+ WRITE_ONCE(cp->resetting, false);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+
+ return ret;
+}
+
+static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
+{
+ pp->bridge->ops = &cortina_own_pci_ops;
+ pp->keep_rp_msi_en = true;
+ pp->bridge->reset_root_port = cortina_pcie_reset_root_port;
+ return 0;
+}
+
+static int cortina_pcie_msi_init(struct dw_pcie_rp *pp)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(pp));
+ struct resource_entry *win;
+ u64 msi_addr = APP_MSI_BUS_BASE + cp->index * APP_PORT_STRIDE;
+ int ret;
+
+ /*
+ * iMSI-RX matches the PCI bus address before AXI translation. Keep the
+ * vendor-reserved bus token; it is not a CPU/DMA destination address.
+ */
+ resource_list_for_each_entry(win, &pp->bridge->windows) {
+ if (resource_type(win->res) == IORESOURCE_MEM &&
+ msi_addr >= win->res->start - win->offset &&
+ msi_addr <= win->res->end - win->offset)
+ return dev_err_probe(cp->pci.dev, -EINVAL,
+ "MSI token overlaps a PCI memory window\n");
+ }
+
+ /* The application IRQ multiplexes MSI and INTx; chain it once. */
+ pp->msi_irq[0] = -ENODEV;
+ ret = dw_pcie_msi_host_init(pp);
+ if (ret)
+ return ret;
+
+ pp->msi_data = msi_addr;
+ /* This custom hook owns setup and teardown of the shared receiver. */
+ cortina_pcie_program_msi(pp);
+ cp->msi_ready = true;
+ return 0;
+}
+
+static void cortina_pcie_quiesce(struct cortina_pcie *cp)
+{
+ unsigned long flags;
+
+ /* Serialize with config/DBI MMIO and prevent interrupt re-enables. */
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ WRITE_ONCE(cp->link_lost, true);
+ writel(0, cp->app + APP_INT_ENABLE);
+ readl(cp->app + APP_INT_ENABLE);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ /* The custom chained handler can still be dispatching MSI or INTx. */
+ synchronize_irq(cp->irq);
+}
+
+static void cortina_pcie_remove_irq_domain(struct cortina_pcie *cp)
+{
+ unsigned int i;
+
+ irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
+ synchronize_irq(cp->irq);
+ for (i = 0; i < PCI_NUM_INTX; i++)
+ irq_dispose_mapping(irq_find_mapping(cp->intx_domain, i));
+ irq_domain_remove(cp->intx_domain);
+}
+
+static void cortina_pcie_host_deinit(struct dw_pcie_rp *pp)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(pp));
+
+ /* Endpoints have stopped; drain the shared IRQ before freeing domains. */
+ cortina_pcie_quiesce(cp);
+ if (cp->msi_ready) {
+ cp->msi_ready = false;
+ dw_pcie_free_msi(pp);
+ pp->msi_irq_domain = NULL;
+ }
+}
+
+static const struct dw_pcie_host_ops cortina_pcie_host_ops = {
+ .init = cortina_pcie_host_init,
+ .post_init = cortina_pcie_enable_msi,
+ .deinit = cortina_pcie_host_deinit,
+ .msi_init = cortina_pcie_msi_init,
+};
+
+/*
+ * Standard RC configuration above 512 bytes wedges the CS7542 bus.
+ * The DesignWare private register bank at 0x700 remains accessible.
+ * The lock serializes MMIO against the link-loss IRQ latch, not against
+ * physical link loss itself. The latch is a conservative no-retrain
+ * policy, not evidence that the RC requires a live downstream link.
+ */
+static u32 cortina_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
+ u32 reg, size_t size)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ unsigned long flags;
+ u32 value = 0;
+
+ /* Zero also makes the iATU enable poll fail after link loss. */
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (!cp->link_lost && !cp->dbi_blocked &&
+ !(base == pci->dbi_base && reg < DWC_PRIVATE_REG_BASE &&
+ reg + size > RC_CFG_LIMIT))
+ dw_pcie_read(base + reg, size, &value);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+ return value;
+}
+
+static void cortina_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base,
+ u32 reg, size_t size, u32 value)
+{
+ struct cortina_pcie *cp = to_cortina_pcie(pci);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&cp->lock, flags);
+ if (!cp->link_lost && !cp->dbi_blocked &&
+ !(base == pci->dbi_base && reg < DWC_PRIVATE_REG_BASE &&
+ reg + size > RC_CFG_LIMIT))
+ dw_pcie_write(base + reg, size, value);
+ raw_spin_unlock_irqrestore(&cp->lock, flags);
+}
+
+static const struct dw_pcie_ops cortina_dw_pcie_ops = {
+ .read_dbi = cortina_pcie_read_dbi,
+ .write_dbi = cortina_pcie_write_dbi,
+ .link_up = cortina_pcie_link_up,
+ .get_ltssm = cortina_pcie_get_ltssm,
+ .start_link = cortina_pcie_start_link,
+ .stop_link = cortina_pcie_stop_link,
+};
+
+static void cortina_pcie_power_off(struct cortina_pcie *cp)
+{
+ gpiod_set_value_cansleep(cp->port.perst, 1);
+ reset_control_assert(cp->reset);
+ phy_power_off(cp->phy);
+ phy_exit(cp->phy);
+ clk_disable_unprepare(cp->clk);
+}
+
+static int cortina_pcie_parse_port(struct cortina_pcie *cp)
+{
+ struct device *dev = cp->pci.dev;
+ struct gpio_desc *perst;
+ struct fwnode_handle *fwnode;
+ bool found = false;
+
+ /* CS7542 has one Root Port per controller; keep PERST# per port. */
+ for_each_available_child_of_node_scoped(dev->of_node, node) {
+ if (!of_device_is_compatible(node, "pciclass,0604"))
+ continue;
+ if (found || of_pci_get_devfn(node) != 0)
+ return dev_err_probe(dev, -EINVAL,
+ "expected one Root Port at devfn 0\n");
+ found = true;
+ /* A port without PERST# must also work with GPIOLIB disabled. */
+ if (!of_find_property(node, "reset-gpios", NULL))
+ continue;
+
+ fwnode = of_fwnode_handle(node);
+ perst = devm_fwnode_gpiod_get(dev, fwnode, "reset",
+ GPIOD_OUT_HIGH, "PERST#");
+ if (IS_ERR(perst)) {
+ if (PTR_ERR(perst) != -ENOENT)
+ return dev_err_probe(dev,
+ PTR_ERR(perst),
+ "PERST# GPIO\n");
+ perst = NULL;
+ }
+ cp->port.perst = perst;
+ }
+
+ if (!found)
+ return dev_err_probe(dev, -ENODEV, "missing Root Port node\n");
+
+ return 0;
+}
+
+static int cortina_pcie_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cortina_pcie *cp;
+ struct dw_pcie *pci;
+ struct resource *res;
+ int ret;
+
+ cp = devm_kzalloc(dev, sizeof(*cp), GFP_KERNEL);
+ if (!cp)
+ return -ENOMEM;
+
+ pci = &cp->pci;
+ pci->dev = dev;
+ pci->ops = &cortina_dw_pcie_ops;
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
+ if (!res)
+ return -EINVAL;
+
+ cp->dbi_phys = res->start;
+ cp->app = devm_platform_ioremap_resource_byname(pdev, "app");
+ if (IS_ERR(cp->app))
+ return PTR_ERR(cp->app);
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "app");
+ if (res->start < APP_PHYS_BASE ||
+ (res->start - APP_PHYS_BASE) % APP_PORT_STRIDE ||
+ (res->start - APP_PHYS_BASE) / APP_PORT_STRIDE >= 3)
+ return -EINVAL;
+
+ cp->index = (res->start - APP_PHYS_BASE) / APP_PORT_STRIDE;
+ mutex_init(&cp->reset_lock);
+ raw_spin_lock_init(&cp->lock);
+ cp->clk = devm_clk_get(dev, NULL);
+ if (IS_ERR(cp->clk))
+ return dev_err_probe(dev, PTR_ERR(cp->clk), "controller clock\n");
+
+ cp->reset = devm_reset_control_get_exclusive(dev, NULL);
+ if (IS_ERR(cp->reset))
+ return dev_err_probe(dev, PTR_ERR(cp->reset), "controller reset\n");
+
+ cp->phy = devm_phy_get(dev, "pcie");
+ if (IS_ERR(cp->phy))
+ return dev_err_probe(dev, PTR_ERR(cp->phy), "SerDes\n");
+
+ ret = cortina_pcie_parse_port(cp);
+ if (ret)
+ return ret;
+
+ cp->irq = platform_get_irq(pdev, 0);
+ if (cp->irq < 0)
+ return cp->irq;
+
+ /* Hold the endpoint and core in reset while stabilizing the PHY. */
+ ret = reset_control_assert(cp->reset);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(cp->clk);
+ if (ret)
+ return ret;
+
+ ret = phy_init(cp->phy);
+ if (ret)
+ goto disable_clk;
+
+ ret = phy_set_mode(cp->phy, PHY_MODE_PCIE);
+ if (ret)
+ goto exit_phy;
+
+ ret = phy_power_on(cp->phy);
+ if (ret)
+ goto exit_phy;
+
+ /* The controller has remained asserted throughout PHY setup. */
+ usleep_range(10000, 12000);
+ ret = reset_control_deassert(cp->reset);
+ if (ret)
+ goto power_off;
+ usleep_range(10000, 12000);
+
+ writel(0, cp->app + APP_INT_ENABLE);
+ cortina_pcie_stop_link(pci);
+ writel(readl(cp->app + APP_INT_STATUS), cp->app + APP_INT_STATUS);
+ ret = cortina_pcie_port_init(cp);
+ if (ret)
+ goto power_off;
+
+ ret = cortina_pcie_init_irq_domain(cp);
+ if (ret)
+ goto power_off;
+
+ irq_set_chained_handler_and_data(cp->irq, cortina_pcie_irq_handler, cp);
+ writel(INT_MSI | INT_ERR_MASK, cp->app + APP_INT_ENABLE);
+ pci->pp.ops = &cortina_pcie_host_ops;
+ ret = dw_pcie_host_init(&pci->pp);
+ if (ret)
+ goto remove_irq_domain;
+
+ platform_set_drvdata(pdev, cp);
+ return 0;
+
+remove_irq_domain:
+ cortina_pcie_quiesce(cp);
+ cortina_pcie_remove_irq_domain(cp);
+power_off:
+ gpiod_set_value_cansleep(cp->port.perst, 1);
+ reset_control_assert(cp->reset);
+ phy_power_off(cp->phy);
+exit_phy:
+ phy_exit(cp->phy);
+disable_clk:
+ reset_control_assert(cp->reset);
+ clk_disable_unprepare(cp->clk);
+ return dev_err_probe(dev, ret, "host initialization\n");
+}
+
+static void cortina_pcie_remove(struct platform_device *pdev)
+{
+ struct cortina_pcie *cp = platform_get_drvdata(pdev);
+
+ dw_pcie_host_deinit(&cp->pci.pp);
+ cortina_pcie_remove_irq_domain(cp);
+ cortina_pcie_power_off(cp);
+}
+
+static void cortina_pcie_shutdown(struct platform_device *pdev)
+{
+ struct cortina_pcie *cp = platform_get_drvdata(pdev);
+
+ cortina_pcie_quiesce(cp);
+ cortina_pcie_stop_link(&cp->pci);
+ gpiod_set_value_cansleep(cp->port.perst, 1);
+ reset_control_assert(cp->reset);
+}
+
+static const struct of_device_id cortina_pcie_of_match[] = {
+ { .compatible = "cortina,cs7542-pcie" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, cortina_pcie_of_match);
+
+static struct platform_driver cortina_pcie_driver = {
+ .probe = cortina_pcie_probe,
+ .remove = cortina_pcie_remove,
+ .shutdown = cortina_pcie_shutdown,
+ .driver = {
+ .name = "cs7542-pcie",
+ .of_match_table = cortina_pcie_of_match,
+ },
+};
+module_platform_driver(cortina_pcie_driver);
+
+MODULE_DESCRIPTION("Cortina Systems CS7542 PCIe host controller");
+MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support
2026-12-04 22:22 ` [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
@ 2026-12-04 22:51 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 22:51 UTC (permalink / raw)
To: Fil Dunsky
Cc: linux-pci, linux-phy, devicetree, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] PCI: cs7542: Root Port MSI enable deferred until after endpoint
probe
- [High] PCI: cs7542: cortina_pcie_intx_map() registers
handle_simple_irq() for INTx
- [Medium] PCI: cs7542: cortina_pcie_shutdown() races with
cortina_pcie_reset_root_port()
- [Medium] PCI: cs7542: INT_LINK_DOWN enabled before initial link
training in probe
- [Medium] PCI: cs7542: cortina_pcie_host_init() ignores
pp->ecam_enabled
- [Medium] PCI: cs7542: blocking DBI before pci_bus_set_ops() stalls
pci_lock 45 ms
- [Low] PCI: cs7542: INT_LINK_DOWN remains unmasked when
dw_pcie_stop_link() runs
- [Low] PCI: cs7542: own config ops bypass slot check at offsets >=
0x200
- [Low] PCI: cs7542: cortina_pcie_reset_root_port() unmasks IRQs before
clearing resetting
- [Low] PCI: cs7542: cortina_pcie_reset_root_port() mixes guard(mutex)
and goto
- [Low] PCI: dwc: stray extra blank line before endmenu in Kconfig
--
commit cd74c745d5af7edb29d42308afe716ec1276fe81
Author: Fil Dunsky <filipp.dunsky@gmail.com>
PCI: cs7542: Add CS7542 PCIe host support
This commit adds the DesignWare PCIe host controller driver for Cortina
Systems CS7542 SoCs, including shared INTx/MSI interrupt dispatch,
DBI/configuration-space filtering, and custom Root Port reset handling.
> diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
> index 0a0d56fcf0ac9..a9b4898017706 100644
> --- a/drivers/pci/controller/dwc/Kconfig
> +++ b/drivers/pci/controller/dwc/Kconfig
[ ... ]
> @@ -577,4 +588,5 @@ config PCIE_ULTRARISC
> By default, this symbol is enabled when ARCH_ULTRARISC is active,
> requiring no further configuration on that platform.
>
> +
> endmenu
[Severity: Low]
This isn't a bug, but this adds an unrelated blank line before endmenu.
[ ... ]
> diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
> new file mode 100644
> index 0000000000000..4be7a99f006d0
> --- /dev/null
> +++ b/drivers/pci/controller/dwc/pcie-cs7542.c
[ ... ]
> +static void cortina_pcie_stop_link(struct dw_pcie *pci)
> +{
> + struct cortina_pcie *cp = to_cortina_pcie(pci);
> + u32 value = readl(cp->app + APP_CORE_CONFIG);
> +
> + writel(value & ~CORE_CFG_LTSSM_EN, cp->app + APP_CORE_CONFIG);
> +}
[Severity: Low]
Can cortina_pcie_stop_link() trigger a spurious INT_LINK_DOWN interrupt
during driver removal or probe error unwind?
dw_pcie_host_deinit() and the err_stop_link path of dw_pcie_host_init()
call dw_pcie_stop_link() before pp->ops->deinit() runs
cortina_pcie_quiesce(). Because INT_LINK_DOWN is still unmasked and
cp->resetting is false, cortina_pcie_irq_handler() logs a spurious
link-lost warning and latches cp->link_lost before dw_pcie_edma_remove().
[ ... ]
> +static struct irq_chip cortina_intx_chip = {
> + .name = "cortina-INTx",
> + .irq_mask = cortina_intx_mask,
> + .irq_unmask = cortina_intx_unmask,
> +};
> +
> +static int cortina_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
> + irq_hw_number_t hwirq)
> +{
> + irq_set_chip_and_handler(irq, &cortina_intx_chip, handle_simple_irq);
> + irq_set_chip_data(irq, domain->host_data);
> + return 0;
> +}
[Severity: High]
Should cortina_pcie_intx_map() register handle_level_irq() instead of
handle_simple_irq()?
cortina_intx_chip provides hardware irq_mask and irq_unmask callbacks
without irq_disable or IRQCHIP_ONESHOT_SAFE, and cortina_pcie_irq_handler()
does not mask APP_INT_ENABLE before dispatching. Unlike handle_level_irq(),
handle_simple_irq() never calls mask_ack_irq() or mask_irq().
For IRQF_ONESHOT threaded handlers (or any PCI INTx handler under
threadirqs or CONFIG_PREEMPT_RT), INT_INTX_ASSERT remains unmasked in
APP_INT_ENABLE while the handler thread runs, allowing an interrupt storm
or re-entry on shared INTx lines. It also breaks lazy disable_irq(),
because handle_simple_irq() returns without masking hardware when an INTx
arrives while disabled.
[ ... ]
> + if (cp->link_lost || cp->resetting) {
> + ret = PCIBIOS_DEVICE_NOT_FOUND;
> + } else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) {
> + *val = 0;
> + ret = PCIBIOS_SUCCESSFUL;
> + } else {
> + ret = pci_generic_config_read(bus, devfn, where, size, val);
> + }
[ ... ]
> + if (cp->link_lost || cp->resetting)
> + ret = PCIBIOS_DEVICE_NOT_FOUND;
> + else if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where)
> + ret = PCIBIOS_SUCCESSFUL;
> + else
> + ret = pci_generic_config_write(bus, devfn, where, size, val);
[Severity: Low]
Do cortina_pcie_rd_own_conf() and cortina_pcie_wr_own_conf() bypass the
PCI_SLOT(devfn) > 0 check for offsets at or above RC_CFG_LIMIT?
Slot validation only happens inside dw_pcie_own_conf_map_bus(). Checking
RC_CFG_LIMIT first causes config reads to absent root-bus slots at offsets
>= 0x200 to return 0 and PCIBIOS_SUCCESSFUL (and writes to return
PCIBIOS_SUCCESSFUL) instead of PCIBIOS_DEVICE_NOT_FOUND.
[ ... ]
> +static int cortina_pcie_reset_root_port(struct pci_host_bridge *bridge,
> + struct pci_dev *root)
> +{
> + struct dw_pcie_rp *pp = bridge->bus->sysdata;
> + struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> + struct cortina_pcie *cp = to_cortina_pcie(pci);
> + struct pci_ops *saved_ops;
> + unsigned long flags;
> + u32 mask, status;
> + u16 control;
> + int ret;
> +
> + guard(mutex)(&cp->reset_lock);
[Severity: Low]
This isn't a bug, but cortina_pcie_reset_root_port() mixes scope-based
guard(mutex) with goto finish error unwinding in the same function. Using
mutex_lock()/mutex_unlock() or converting the cleanup avoids mixing the two
styles.
[ ... ]
> + WRITE_ONCE(cp->resetting, true);
> + cp->dbi_blocked = true;
> + mask = readl(cp->app + APP_INT_ENABLE) & ~INT_INTX_ASSERT_MASK;
> + writel(0, cp->app + APP_INT_ENABLE);
> + readl(cp->app + APP_INT_ENABLE);
> + raw_spin_unlock_irqrestore(&cp->lock, flags);
> +
> + synchronize_irq(cp->irq);
> + /* Drain in-flight PCI config access before resetting the DBI aperture. */
> + saved_ops = pci_bus_set_ops(root->bus, &cortina_reset_pci_ops);
[Severity: Medium]
Can setting cp->dbi_blocked before pci_bus_set_ops() stall global pci_lock
for 45 ms with interrupts disabled?
On ARM, PCI config accesses take raw_spin_lock_irqsave(&pci_lock). A
concurrent downstream config reader such as current_link_speed_show() does
not check dev->block_cfg_access and can race with reset entry:
CPU0 CPU1
pci_bus_read_config_word()
lock(&pci_lock)
dw_pcie_other_conf_map_bus()
dw_pcie_link_up() -> true
cortina_pcie_reset_root_port()
cp->resetting = true
cp->dbi_blocked = true
pci_bus_set_ops()
lock(&pci_lock) <-- spins 45 ms
dw_pcie_prog_outbound_atu()
mdelay(9) x 5 <-- DBI returns 0
Because cortina_pcie_read_dbi() returns 0 while cp->dbi_blocked is set,
dw_pcie_prog_outbound_atu() busy-waits 45 ms under pci_lock while CPU0
spins waiting for it. Setting cp->dbi_blocked only after synchronize_irq()
and pci_bus_set_ops() return avoids blocking in-flight config accesses.
[ ... ]
> +finish:
> + pci_bus_set_ops(root->bus, saved_ops);
> + raw_spin_lock_irqsave(&cp->lock, flags);
> + if (!ret) {
> + writel(INT_LINK_DOWN | INT_LINK_UP, cp->app + APP_INT_STATUS);
> + if (cp->link_lost ||
> + !(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE))
> + ret = -ENOLINK;
> + }
> + if (ret)
> + WRITE_ONCE(cp->link_lost, true);
> + else
> + writel(mask | cp->intx_enabled, cp->app + APP_INT_ENABLE);
> + cp->dbi_blocked = false;
> + WRITE_ONCE(cp->resetting, false);
> + raw_spin_unlock_irqrestore(&cp->lock, flags);
[Severity: Low]
Can unmasking APP_INT_ENABLE before clearing cp->resetting cause an INTx
handler on another CPU to fail downstream config accesses?
CPU0 CPU1
writel(..., cp->app + APP_INT_ENABLE)
cortina_pcie_irq_handler()
generic_handle_domain_irq()
...
cortina_pcie_link_up()
READ_ONCE(cp->resetting)
<-- sees true, fails config
WRITE_ONCE(cp->resetting, false)
INTx dispatch runs without cp->lock, and cortina_pcie_link_up() reads
cp->resetting locklessly. Clearing cp->dbi_blocked and cp->resetting
before writing APP_INT_ENABLE prevents this window.
[ ... ]
> +static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
> +{
> + pp->bridge->ops = &cortina_own_pci_ops;
> + pp->keep_rp_msi_en = true;
> + pp->bridge->reset_root_port = cortina_pcie_reset_root_port;
> + return 0;
> +}
[Severity: Medium]
Does cortina_pcie_host_init() cause type confusion on bus->sysdata if
dw_pcie_host_get_resources() enables ECAM?
When the DT config window is 256 MiB-aligned and covers bus-range,
dw_pcie_host_get_resources() sets pp->ecam_enabled = true and assigns
pp->bridge->sysdata = pp->cfg (a struct pci_config_window *). Overriding
pp->bridge->ops and reset_root_port without checking pp->ecam_enabled then
makes cortina_pcie_rd_own_conf(), cortina_pcie_wr_own_conf(), and
cortina_pcie_reset_root_port() pass that pointer to to_dw_pcie_from_pp()
and lock cp->lock out of bounds, corrupting memory or panicking during
probe. Rejecting pp->ecam_enabled here (or handling ECAM) avoids this.
[ ... ]
> +static const struct dw_pcie_host_ops cortina_pcie_host_ops = {
> + .init = cortina_pcie_host_init,
> + .post_init = cortina_pcie_enable_msi,
> + .deinit = cortina_pcie_host_deinit,
> + .msi_init = cortina_pcie_msi_init,
> +};
[Severity: High]
Does wiring cortina_pcie_enable_msi() to post_init leave Root Port
PCI_MSI_FLAGS_ENABLE cleared while downstream endpoint drivers probe?
dw_pcie_host_init() runs pci_host_probe(bridge) before pp->ops->post_init().
Inside pci_host_probe(), pci_msi_init() clears PCI_MSI_FLAGS_ENABLE on the
Root Port, and pci_bus_add_devices() then synchronously probes downstream
endpoint drivers before cortina_pcie_enable_msi() ever runs.
If an endpoint driver allocates MSIs and waits for MSI completions during
probe (for example with CONFIG_PCIEPORTBUS disabled or pcie_pme=nomsi), it
receives no MSIs and times out. Similarly, unbinding a Root Port driver
later can clear PCI_MSI_FLAGS_ENABLE via cortina_pcie_wr_own_conf() and
break endpoint MSI delivery again.
[ ... ]
> + irq_set_chained_handler_and_data(cp->irq, cortina_pcie_irq_handler, cp);
> + writel(INT_MSI | INT_ERR_MASK, cp->app + APP_INT_ENABLE);
> + pci->pp.ops = &cortina_pcie_host_ops;
> + ret = dw_pcie_host_init(&pci->pp);
[Severity: Medium]
Can unmasking INT_LINK_DOWN before dw_pcie_host_init() permanently latch
cp->link_lost during initial link training?
INT_ERR_MASK includes INT_LINK_DOWN, and cp->resetting is false during
probe. If initial link training or SPEED_CHANGE retraining triggers a
transient INT_LINK_DOWN, cortina_pcie_irq_handler() sets cp->link_lost =
true and writes 0 to APP_INT_ENABLE, and nothing clears cp->link_lost.
Because dw_pcie_host_init() only aborts on -ETIMEDOUT from
dw_pcie_wait_for_link() (ignoring -ENODEV and -EIO), probe can either fail
or return 0 with a permanently dead host controller whose config/DBI
accesses and interrupts are all blocked.
[ ... ]
> +static void cortina_pcie_shutdown(struct platform_device *pdev)
> +{
> + struct cortina_pcie *cp = platform_get_drvdata(pdev);
> +
> + cortina_pcie_quiesce(cp);
> + cortina_pcie_stop_link(&cp->pci);
> + gpiod_set_value_cansleep(cp->port.perst, 1);
> + reset_control_assert(cp->reset);
> +}
[Severity: Medium]
Can cortina_pcie_shutdown() race with cortina_pcie_reset_root_port()
because it does not acquire cp->reset_lock?
device_shutdown() only holds device_lock() on the platform device and its
parent, so a concurrent secondary bus reset (for example via sysfs reset
or AER recovery) can interleave with shutdown:
CPU0 CPU1
cortina_pcie_reset_root_port()
lock(&cp->reset_lock)
writew(BUS_RESET, dbi_base + ...)
usleep_range(2000, 3000)
cortina_pcie_shutdown()
cortina_pcie_quiesce()
reset_control_assert(cp->reset)
writew(..., dbi_base + ...)
<-- DBI write while in reset
If shutdown finishes while reset_root_port() is sleeping across
reset_control_assert() or cortina_pcie_start_link(), reset_root_port()
can also deassert cp->reset and PERST# and re-enable LTSSM after shutdown
completes. Acquiring cp->reset_lock before cortina_pcie_quiesce() drains
any active reset and causes later resets to see cp->link_lost and return
-ENOLINK.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-cs7542-pcie-v4-0-6d0101b281b4@gmail.com?part=5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 6/6] MAINTAINERS: Add CS7542 PCIe support
2026-12-04 22:22 [PATCH v4 0/6] PCI: cortina: Add CS7542 PCIe host and PHY support Fil Dunsky via B4 Relay
` (4 preceding siblings ...)
2026-12-04 22:22 ` [PATCH v4 5/6] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
@ 2026-12-04 22:22 ` Fil Dunsky via B4 Relay
5 siblings, 0 replies; 10+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-12-04 22:22 UTC (permalink / raw)
To: Manivannan Sadhasivam, Vinod Koul, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Fil Dunsky
Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski,
Bjorn Helgaas, Neil Armstrong, Stephen Boyd, Philipp Zabel,
linux-pci, linux-phy, devicetree, linux-arm-kernel, linux-kernel
From: Fil Dunsky <filipp.dunsky@gmail.com>
Cover the PCIe host, SerDes PHY and their bindings under the existing
CS7542 global control entry. The shared clock/reset provider and reset
specifier header are already covered by the prerequisite series.
Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
MAINTAINERS | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 703e95e83..8921c91a7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2949,13 +2949,17 @@ F: tools/perf/tests/shell/coresight/*
F: tools/perf/util/cs-etm-decoder/*
F: tools/perf/util/cs-etm.*
-ARM/CORTINA SYSTEMS CS7542 GLOBAL CONTROL
+ARM/CORTINA SYSTEMS CS7542 GLOBAL CONTROL AND PCIE
M: Fil Dunsky <filipp.dunsky@gmail.com>
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
S: Maintained
+F: Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
+F: Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
F: Documentation/devicetree/bindings/pinctrl/cortina,cs7542-pinctrl.yaml
F: Documentation/devicetree/bindings/soc/cortina/
F: drivers/clk/clk-cs7542.c
+F: drivers/pci/controller/dwc/pcie-cs7542.c
+F: drivers/phy/phy-cs7542-pcie.c
F: drivers/pinctrl/pinctrl-cs7542.c
F: drivers/reset/reset-cs7542.c
F: include/dt-bindings/clock/cortina,cs7542-clock.h
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread