Skip to contentSkip to conversation

PCI: keembay: Add support for Intel Keem Bay

PATCH Superseded [email protected] 4 participants 12 messages Jun 7, 2021 – Jul 27, 2021

Subsystems (4)

v10 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v10 cover PCI: keembay: Add support for Intel Keem Bay

From: Srikanth Thokala <[email protected]>

Hi,

The first patch is to document DT bindings for Keem Bay PCIe controller for both Root Complex and Endpoint modes.

The second patch is the driver file, a glue driver. Keem Bay PCIe controller is based on DesignWare PCIe IP.

The patch was tested with Keem Bay evaluation module board, with B0 stepping.

Kindly review.

Thanks!
Srikanth

Changes since v9:
- Add 'Reviewed-by: Krzysztof Wilczyński <[email protected]>', thanks to Krzysztof.
- Rebased to v5.13-rc5.

Changes since v8:
- Use chained IRQ to handle MSIs, as suggested by Lorenzo Pieralisi.
- Rename *_setup_irq() to *_setup_msi_irq() to be more meaningful.
- Move *_setup_msi_irq() call to *_add_pcie_port() to make it invoke only when controller is in Root Complex mode. In Endpoint mode, IRQ will be setup by the respective driver which will be based on PCIe End Point Framework.

Changes since v7:
- Rename keembay_pcie_ltssm_enable() to align to its functionality.
- Fix other minor comments from "Krzysztof Wilczyński <[email protected]>"

Changes since v6:
- Arrange SoB in chronological order.
- Alphabetized and modified status of entry in MAINTAINERS.
- Added a comment to specify the PCIe spec section about the delay.

Changes since v5:
- Rebased to v5.11-rc4.
- Updated maintainers to add myself in DT binding documents.
- Fix checkpatch issues.

Changes since v4:
- Rebased to v5.11-rc1 and retest.

Changes since v3:
- Add Reviewed-by: Rob Herring <[email protected]> tag in dt-bindings patch.
- Remove the keembay_pcie_{readl,writel} wrappers. And replace them with readl() and writel().
- Remove the dead code related to unused irqs.
- Remove unused definition for unused irqs.
- In keembay_pcie_ep_init(), initialize enabled interrupts to known state.
- Rebased to next-20201215.

Changes since v2:
- In keembay_pcie_probe(), use return keembay_pcie_add_pcie_port(pcie, pdev); statement and remove return 0; at the end of the function.

Changes since v1:
- In dt-bindings patch.
- Fixed indent warning for compatible property.
- Rename interrupt-names to pcie, pcie_ev, pcie_err and pcie_mem_access, similar to the name used in datasheet.
- Remove device_type, #address-cells and #size-cells property.
- Remove num-viewport, num-ib-windows and num-ob-windows property.
- Replace additionalProperties with unevaluatedProperties, for RC only.
- Add dbi2 and atu property.
- Remove description for regs and interrupts property.
- Change enum value for num-lanes to 1 and 2 only.
- In driver patch.
- In Kconfig file, remove dependency on ARM64.
- Add new define, PCIE_REGS_PCIE_SII_LINK_UP.
- Remove PCIE_DBI2_MASK.
- In struct keembay_pcie, declare pci member as struct, not pointer. And remove irq number members.
- Rename and rework keembay_pcie_establish_link(), to keembay_pcie_start_link().
- Remove unneeded BAR disable steps.
- Remove unused interrupt handlers; keembay_pcie_ev_irq_handler(), keembay_pcie_err_irq_handler().
- Remove keembay_pcie_enable_interrupts().
- Rework keembay_pcie_setup_irq() and call it from keembay_pcie_probe().
- Remove keembay_pcie_host_init() and make keembay_pcie_host_ops empty.
- Keep and rework keembay_pcie_add_pcie_port() a little.
- Remove keembay_pcie_add_pcie_ep() and call dw_pcie_ep_init() from keembay_pcie_probe().
- In keembay_pcie_probe(), remove dbi setup as it will be handled in dwc common code.
- In keembay_pcie_link_up(), use return (val &

    PCIE_REGS_PCIE_SII_LINK_UP) == PCIE_REGS_PCIE_SII_LINK_UP.

- In keembay_pcie_ep_raise_irq(), rework error message for PCI_EPC_IRQ_LEGACY and default cases.
- Rebased to next-20201124, that has dwc pci refactoring,
https://lore.kernel.org/linux-pci/[email protected]/.

Srikanth Thokala (2):
dt-bindings: PCI: Add Intel Keem Bay PCIe controller
PCI: keembay: Add support for Intel Keem Bay

 .../bindings/pci/intel,keembay-pcie-ep.yaml   |  69 +++
 .../bindings/pci/intel,keembay-pcie.yaml      |  97 ++++
 MAINTAINERS                                   |   7 +
 drivers/pci/controller/dwc/Kconfig            |  28 ++
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-keembay.c     | 451 ++++++++++++++++++
 6 files changed, 653 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-pcie-ep.yaml
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-pcie.yaml
 create mode 100644 drivers/pci/controller/dwc/pcie-keembay.c

base-commit: 614124bea77e452aa6df7a8714e8bc820b489922

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v10 1/2 dt-bindings: PCI: Add Intel Keem Bay PCIe controller

From: Srikanth Thokala <[email protected]>

Document DT bindings for PCIe controller found on Intel Keem Bay SoC.

---
 .../bindings/pci/intel,keembay-pcie-ep.yaml   | 69 +++++++++++++
 .../bindings/pci/intel,keembay-pcie.yaml      | 97 +++++++++++++++++++
 2 files changed, 166 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-pcie-ep.yaml
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-pcie.yaml
Documentation/devicetree/bindings/pci/intel,keembay-pcie-ep.yaml new file +69 -0
new file mode 100644
index 000000000000..e87ff27526ff
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/pci/intel,keembay-pcie-ep.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Intel Keem Bay PCIe controller Endpoint mode
+
+maintainers:
+  - Wan Ahmad Zainie <[email protected]>
+  - Srikanth Thokala <[email protected]>
+
+properties:
+  compatible:
+    const: intel,keembay-pcie-ep
+
+  reg:
+    maxItems: 5
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: dbi2
+      - const: atu
+      - const: addr_space
+      - const: apb
+
+  interrupts:
+    maxItems: 4
+
+  interrupt-names:
+    items:
+      - const: pcie
+      - const: pcie_ev
+      - const: pcie_err
+      - const: pcie_mem_access
+
+  num-lanes:
+    description: Number of lanes to use.
+    enum: [ 1, 2 ]
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    pcie-ep@37000000 {
+          compatible = "intel,keembay-pcie-ep";
+          reg = <0x37000000 0x00001000>,
+                <0x37100000 0x00001000>,
+                <0x37300000 0x00001000>,
+                <0x36000000 0x01000000>,
+                <0x37800000 0x00000200>;
+          reg-names = "dbi", "dbi2", "atu", "addr_space", "apb";
+          interrupts = <GIC_SPI 107 IRQ_TYPE_LEVEL_HIGH>,
+                       <GIC_SPI 108 IRQ_TYPE_EDGE_RISING>,
+                       <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>,
+                       <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
+          interrupt-names = "pcie", "pcie_ev", "pcie_err", "pcie_mem_access";
+          num-lanes = <2>;
+    };
Documentation/devicetree/bindings/pci/intel,keembay-pcie.yaml new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH v10 2/2 PCI: keembay: Add support for Intel Keem Bay

In reply to [email protected]

From: Srikanth Thokala <[email protected]>

Add driver for Intel Keem Bay SoC PCIe controller. This controller is based on DesignWare PCIe core.

In Root Complex mode, only internal reference clock is possible for Keem Bay A0. For Keem Bay B0, external reference clock can be used and will be the default configuration. Currently, keembay_pcie_of_data structure has one member. It will be expanded later to handle this difference.

Endpoint mode link initialization is handled by the boot firmware.

---
 MAINTAINERS                               |   7 +
 drivers/pci/controller/dwc/Kconfig        |  28 ++
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-keembay.c | 451 ++++++++++++++++++++++
 4 files changed, 487 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-keembay.c
MAINTAINERS +7 -0
index b706dd20ff2b..40d1fa0b0a0d 100644
@@ -14244,6 +14244,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt
 F:	drivers/pci/controller/dwc/pcie-histb.c
 
+PCIE DRIVER FOR INTEL KEEM BAY
+M:	Srikanth Thokala <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/pci/intel,keembay-pcie*
+F:	drivers/pci/controller/dwc/pcie-keembay.c
+
 PCIE DRIVER FOR MEDIATEK
 M:	Ryder Lee <[email protected]>
 M:	Jianjun Wang <[email protected]>
drivers/pci/controller/dwc/Kconfig +28 -0
index 423d35872ce4..04430ddde8c4 100644
@@ -225,6 +225,34 @@ config PCIE_INTEL_GW
 	  The PCIe controller uses the DesignWare core plus Intel-specific
 	  hardware wrappers.
 
+config PCIE_KEEMBAY
+	bool
+
+config PCIE_KEEMBAY_HOST
+	bool "Intel Keem Bay PCIe controller - Host mode"
+	depends on ARCH_KEEMBAY || COMPILE_TEST
+	depends on PCI && PCI_MSI_IRQ_DOMAIN
+	select PCIE_DW_HOST
+	select PCIE_KEEMBAY
+	help
+	  Say 'Y' here to enable support for the PCIe controller in Keem Bay
+	  to work in host mode.
+	  The PCIe controller is based on DesignWare Hardware and uses
+	  DesignWare core functions.
+
+config PCIE_KEEMBAY_EP
+	bool "Intel Keem Bay PCIe controller - Endpoint mode"
+	depends on ARCH_KEEMBAY || COMPILE_TEST
+	depends on PCI && PCI_MSI_IRQ_DOMAIN
+	depends on PCI_ENDPOINT
+	select PCIE_DW_EP
+	select PCIE_KEEMBAY
+	help
+	  Say 'Y' here to enable support for the PCIe controller in Keem Bay
+	  to work in endpoint mode.
+	  The PCIe controller is based on DesignWare Hardware and uses
+	  DesignWare core functions.
+
 config PCIE_KIRIN
 	depends on OF && (ARM64 || COMPILE_TEST)
 	bool "HiSilicon Kirin series SoCs PCIe controllers"
drivers/pci/controller/dwc/Makefile +1 -0
index eca805c1a023..6932292b3f22 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
 obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
 obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o
 obj-$(CONFIG_PCIE_INTEL_GW) += pcie-intel-gw.o
+obj-$(CONFIG_PCIE_KEEMBAY) += pcie-keembay.o
 obj-$(CONFIG_PCIE_KIRIN) += pcie-kirin.o
 obj-$(CONFIG_PCIE_HISI_STB) += pcie-histb.o
 obj-$(CONFIG_PCI_MESON) += pci-meson.o
drivers/pci/controller/dwc/pcie-keembay.c new file +451 -0

451 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v10 2/2
#3 lore raw
Quoted 18 lines · On Mon, Jun 7, 2021 at 1:47 AM <[email protected]> wrote:

From: Srikanth Thokala <[email protected]>

Add driver for Intel Keem Bay SoC PCIe controller. This controller is based on DesignWare PCIe core.

In Root Complex mode, only internal reference clock is possible for Keem Bay A0. For Keem Bay B0, external reference clock can be used and will be the default configuration. Currently, keembay_pcie_of_data structure has one member. It will be expanded later to handle this difference.

Endpoint mode link initialization is handled by the boot firmware.

Quoted 7 lines
---
 MAINTAINERS                               |   7 +
 drivers/pci/controller/dwc/Kconfig        |  28 ++
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-keembay.c | 451 ++++++++++++++++++++++
 4 files changed, 487 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-keembay.c
author maintainer
#4 lore raw

Hi Rob,

Quoted 39 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Wednesday, June 16, 2021 2:39 AM
To: Thokala, Srikanth <[email protected]>
Cc: Lorenzo Pieralisi <[email protected]>; PCI <linux- [email protected]>; [email protected]; Andy Shevchenko <[email protected]>; Mark Gross <[email protected]>; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; Krzysztof Wilczynski <[email protected]>
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

Quoted 18 lines · On Mon, Jun 7, 2021 at 1:47 AM <[email protected]> wrote:

From: Srikanth Thokala <[email protected]>

Add driver for Intel Keem Bay SoC PCIe controller. This controller is based on DesignWare PCIe core.

In Root Complex mode, only internal reference clock is possible for Keem Bay A0. For Keem Bay B0, external reference clock can be used and will be the default configuration. Currently, keembay_pcie_of_data structure has one member. It will be expanded later to handle this difference.

Endpoint mode link initialization is handled by the boot firmware.

Quoted 7 lines
---
 MAINTAINERS                               |   7 +
 drivers/pci/controller/dwc/Kconfig        |  28 ++
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-keembay.c | 451 ++++++++++++++++++++++
 4 files changed, 487 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-keembay.c
Quoted 1 line

Thank you, Rob, for the "Reviewed-by".

Srikanth

#5 lore raw
In reply to [email protected]

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530, [email protected] wrote:
[...]

Quoted 27 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +27 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 10 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +10 -0
+	struct platform_device *pdev = to_platform_device(dev);
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq, keembay_pcie_msi_irq_handler,
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc worked hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}

Thanks,
Lorenzo

Quoted 186 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +183 -0
+static void keembay_pcie_ep_init(struct dw_pcie_ep *ep)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct keembay_pcie *pcie = dev_get_drvdata(pci->dev);
+
+	writel(EDMA_INT_EN, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+}
+
+static int keembay_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
+				     enum pci_epc_irq_type type,
+				     u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+
+	switch (type) {
+	case PCI_EPC_IRQ_LEGACY:
+		/* Legacy interrupts are not supported in Keem Bay */
+		dev_err(pci->dev, "Legacy IRQ is not supported\n");
+		return -EINVAL;
+	case PCI_EPC_IRQ_MSI:
+		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
+	case PCI_EPC_IRQ_MSIX:
+		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+	default:
+		dev_err(pci->dev, "Unknown IRQ type %d\n", type);
+		return -EINVAL;
+	}
+}
+
+static const struct pci_epc_features keembay_pcie_epc_features = {
+	.linkup_notifier	= false,
+	.msi_capable		= true,
+	.msix_capable		= true,
+	.reserved_bar		= BIT(BAR_1) | BIT(BAR_3) | BIT(BAR_5),
+	.bar_fixed_64bit	= BIT(BAR_0) | BIT(BAR_2) | BIT(BAR_4),
+	.align			= SZ_16K,
+};
+
+static const struct pci_epc_features *
+keembay_pcie_get_features(struct dw_pcie_ep *ep)
+{
+	return &keembay_pcie_epc_features;
+}
+
+static const struct dw_pcie_ep_ops keembay_pcie_ep_ops = {
+	.ep_init	= keembay_pcie_ep_init,
+	.raise_irq	= keembay_pcie_ep_raise_irq,
+	.get_features	= keembay_pcie_get_features,
+};
+
+static const struct dw_pcie_host_ops keembay_pcie_host_ops = {
+};
+
+static int keembay_pcie_add_pcie_port(struct keembay_pcie *pcie,
+				      struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct pcie_port *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	u32 val;
+	int ret;
+
+	pp->ops = &keembay_pcie_host_ops;
+	pp->msi_irq = -ENODEV;
+
+	ret = keembay_pcie_setup_msi_irq(pcie);
+	if (ret)
+		return ret;
+
+	pcie->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(pcie->reset))
+		return PTR_ERR(pcie->reset);
+
+	ret = keembay_pcie_probe_clocks(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+	val |= PHY0_SRAM_BYPASS;
+	writel(val, pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+
+	writel(PCIE_DEVICE_TYPE, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+
+	ret = keembay_pcie_pll_init(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	writel(val | PCIE_RSTN, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	keembay_ep_reset_deassert(pcie);
+
+	ret = dw_pcie_host_init(pp);
+	if (ret) {
+		keembay_ep_reset_assert(pcie);
+		dev_err(dev, "Failed to initialize host: %d\n", ret);
+		return ret;
+	}
+
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+	if (IS_ENABLED(CONFIG_PCI_MSI))
+		val |= MSI_CTRL_INT_EN;
+	writel(val, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	return 0;
+}
+
+static int keembay_pcie_probe(struct platform_device *pdev)
+{
+	const struct keembay_pcie_of_data *data;
+	struct device *dev = &pdev->dev;
+	struct keembay_pcie *pcie;
+	struct dw_pcie *pci;
+	enum dw_pcie_device_mode mode;
+
+	data = device_get_match_data(dev);
+	if (!data)
+		return -ENODEV;
+
+	mode = (enum dw_pcie_device_mode)data->mode;
+
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+	if (!pcie)
+		return -ENOMEM;
+
+	pci = &pcie->pci;
+	pci->dev = dev;
+	pci->ops = &keembay_pcie_ops;
+
+	pcie->mode = mode;
+
+	pcie->apb_base = devm_platform_ioremap_resource_byname(pdev, "apb");
+	if (IS_ERR(pcie->apb_base))
+		return PTR_ERR(pcie->apb_base);
+
+	platform_set_drvdata(pdev, pcie);
+
+	switch (pcie->mode) {
+	case DW_PCIE_RC_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_HOST))
+			return -ENODEV;
+
+		return keembay_pcie_add_pcie_port(pcie, pdev);
+	case DW_PCIE_EP_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_EP))
+			return -ENODEV;
+
+		pci->ep.ops = &keembay_pcie_ep_ops;
+		return dw_pcie_ep_init(&pci->ep);
+	default:
+		dev_err(dev, "Invalid device type %d\n", pcie->mode);
+		return -ENODEV;
+	}
+}
+
+static const struct keembay_pcie_of_data keembay_pcie_rc_of_data = {
+	.mode = DW_PCIE_RC_TYPE,
+};
+
+static const struct keembay_pcie_of_data keembay_pcie_ep_of_data = {
+	.mode = DW_PCIE_EP_TYPE,
+};
+
+static const struct of_device_id keembay_pcie_of_match[] = {
+	{
+		.compatible = "intel,keembay-pcie",
+		.data = &keembay_pcie_rc_of_data,
+	},
+	{
+		.compatible = "intel,keembay-pcie-ep",
+		.data = &keembay_pcie_ep_of_data,
+	},
+	{}
+};
+
+static struct platform_driver keembay_pcie_driver = {
+	.driver = {
+		.name = "keembay-pcie",
+		.of_match_table = keembay_pcie_of_match,
+		.suppress_bind_attrs = true,
+	},
+	.probe  = keembay_pcie_probe,
+};
+builtin_platform_driver(keembay_pcie_driver);
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

Hi Lorenzo,

Quoted 75 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: Monday, June 21, 2021 10:23 PM
To: Thokala, Srikanth <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530, [email protected] wrote:
[...]

Quoted 27 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +27 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 10 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +10 -0
+	struct platform_device *pdev = to_platform_device(dev);
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq, keembay_pcie_msi_irq_handler,
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc worked hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

Quoted 6 lines

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}

Yes, your understanding is correct.

Additional registers PCIE_REGS_INTERRUPT_ENABLE/_STATUS are provided by IP to control the interrupts.

To receive MSI interrupts, SW must enable bit '8' of _ENABLE register. And once a MSI is raised by the End point, bit '8' of _STATUS register will be set and it needs to be cleared after servicing the interrupt.

Thanks!
Srikanth

Quoted 190 lines

Thanks,
Lorenzo

Quoted 186 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +183 -1
+static void keembay_pcie_ep_init(struct dw_pcie_ep *ep)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct keembay_pcie *pcie = dev_get_drvdata(pci->dev);
+
+	writel(EDMA_INT_EN, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+}
+
+static int keembay_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
+				     enum pci_epc_irq_type type,
+				     u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+
+	switch (type) {
+	case PCI_EPC_IRQ_LEGACY:
+		/* Legacy interrupts are not supported in Keem Bay */
+		dev_err(pci->dev, "Legacy IRQ is not supported\n");
+		return -EINVAL;
+	case PCI_EPC_IRQ_MSI:
+		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
+	case PCI_EPC_IRQ_MSIX:
+		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+	default:
+		dev_err(pci->dev, "Unknown IRQ type %d\n", type);
+		return -EINVAL;
+	}
+}
+
+static const struct pci_epc_features keembay_pcie_epc_features = {
+	.linkup_notifier	= false,
+	.msi_capable		= true,
+	.msix_capable		= true,
+	.reserved_bar		= BIT(BAR_1) | BIT(BAR_3) | BIT(BAR_5),
+	.bar_fixed_64bit	= BIT(BAR_0) | BIT(BAR_2) | BIT(BAR_4),
+	.align			= SZ_16K,
+};
+
+static const struct pci_epc_features *
+keembay_pcie_get_features(struct dw_pcie_ep *ep)
+{
+	return &keembay_pcie_epc_features;
+}
+
+static const struct dw_pcie_ep_ops keembay_pcie_ep_ops = {
+	.ep_init	= keembay_pcie_ep_init,
+	.raise_irq	= keembay_pcie_ep_raise_irq,
+	.get_features	= keembay_pcie_get_features,
+};
+
+static const struct dw_pcie_host_ops keembay_pcie_host_ops = {
+};
+
+static int keembay_pcie_add_pcie_port(struct keembay_pcie *pcie,
+				      struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct pcie_port *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	u32 val;
+	int ret;
+
+	pp->ops = &keembay_pcie_host_ops;
+	pp->msi_irq = -ENODEV;
+
+	ret = keembay_pcie_setup_msi_irq(pcie);
+	if (ret)
+		return ret;
+
+	pcie->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(pcie->reset))
+		return PTR_ERR(pcie->reset);
+
+	ret = keembay_pcie_probe_clocks(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+	val |= PHY0_SRAM_BYPASS;
+	writel(val, pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+
+	writel(PCIE_DEVICE_TYPE, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+
+	ret = keembay_pcie_pll_init(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	writel(val | PCIE_RSTN, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	keembay_ep_reset_deassert(pcie);
+
+	ret = dw_pcie_host_init(pp);
+	if (ret) {
+		keembay_ep_reset_assert(pcie);
+		dev_err(dev, "Failed to initialize host: %d\n", ret);
+		return ret;
+	}
+
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+	if (IS_ENABLED(CONFIG_PCI_MSI))
+		val |= MSI_CTRL_INT_EN;
+	writel(val, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	return 0;
+}
+
+static int keembay_pcie_probe(struct platform_device *pdev)
+{
+	const struct keembay_pcie_of_data *data;
+	struct device *dev = &pdev->dev;
+	struct keembay_pcie *pcie;
+	struct dw_pcie *pci;
+	enum dw_pcie_device_mode mode;
+
+	data = device_get_match_data(dev);
+	if (!data)
+		return -ENODEV;
+
+	mode = (enum dw_pcie_device_mode)data->mode;
+
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+	if (!pcie)
+		return -ENOMEM;
+
+	pci = &pcie->pci;
+	pci->dev = dev;
+	pci->ops = &keembay_pcie_ops;
+
+	pcie->mode = mode;
+
+	pcie->apb_base = devm_platform_ioremap_resource_byname(pdev, "apb");
+	if (IS_ERR(pcie->apb_base))
+		return PTR_ERR(pcie->apb_base);
+
+	platform_set_drvdata(pdev, pcie);
+
+	switch (pcie->mode) {
+	case DW_PCIE_RC_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_HOST))
+			return -ENODEV;
+
+		return keembay_pcie_add_pcie_port(pcie, pdev);
+	case DW_PCIE_EP_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_EP))
+			return -ENODEV;
+
+		pci->ep.ops = &keembay_pcie_ep_ops;
+		return dw_pcie_ep_init(&pci->ep);
+	default:
+		dev_err(dev, "Invalid device type %d\n", pcie->mode);
+		return -ENODEV;
+	}
+}
+
+static const struct keembay_pcie_of_data keembay_pcie_rc_of_data = {
+	.mode = DW_PCIE_RC_TYPE,
+};
+
+static const struct keembay_pcie_of_data keembay_pcie_ep_of_data = {
+	.mode = DW_PCIE_EP_TYPE,
+};
+
+static const struct of_device_id keembay_pcie_of_match[] = {
+	{
+		.compatible = "intel,keembay-pcie",
+		.data = &keembay_pcie_rc_of_data,
+	},
+	{
+		.compatible = "intel,keembay-pcie-ep",
+		.data = &keembay_pcie_ep_of_data,
+	},
+	{}
+};
+
+static struct platform_driver keembay_pcie_driver = {
+	.driver = {
+		.name = "keembay-pcie",
+		.of_match_table = keembay_pcie_of_match,
+		.suppress_bind_attrs = true,
+	},
+	.probe  = keembay_pcie_probe,
+};
+builtin_platform_driver(keembay_pcie_driver);
--

2.17.1

author maintainer
#7 lore raw

Hi Lorenzo and Marc,

Quoted 100 lines

-----Original Message-----
From: Thokala, Srikanth
Sent: Friday, June 25, 2021 8:54 AM
To: Lorenzo Pieralisi <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]
Subject: RE: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

Hi Lorenzo,

Quoted 8 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: Monday, June 21, 2021 10:23 PM
To: Thokala, Srikanth <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar,

Mallikarjunappa

Quoted 2 lines

<[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem

Bay

Quoted 17 lines

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530, [email protected] wrote:
[...]

Quoted 10 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +10 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base +

PCIE_REGS_INTERRUPT_STATUS);

Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +9 -0
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	struct platform_device *pdev = to_platform_device(dev);
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq,

keembay_pcie_msi_irq_handler,

Quoted 23 lines

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 2 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +2 -0
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc worked hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

Quoted 6 lines

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}
Quoted 8 lines

Yes, your understanding is correct.

Additional registers PCIE_REGS_INTERRUPT_ENABLE/_STATUS are provided by IP to control the interrupts.

To receive MSI interrupts, SW must enable bit '8' of _ENABLE register. And once a MSI is raised by the End point, bit '8' of _STATUS register will be set and it needs to be cleared after servicing the interrupt.

Hope I have provided all the necessary information. Kindly feedback.

Thanks!
Srikanth

Quoted 200 lines

Thanks!
Srikanth

Quoted 4 lines

Thanks,
Lorenzo

Quoted 9 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 9 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +9 -0
+static void keembay_pcie_ep_init(struct dw_pcie_ep *ep)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct keembay_pcie *pcie = dev_get_drvdata(pci->dev);
+
+	writel(EDMA_INT_EN, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+}
+
+static int keembay_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8

func_no,

Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +4 -0
+				     enum pci_epc_irq_type type,
+				     u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+
+	switch (type) {
+	case PCI_EPC_IRQ_LEGACY:
+		/* Legacy interrupts are not supported in Keem Bay */
+		dev_err(pci->dev, "Legacy IRQ is not supported\n");
+		return -EINVAL;
+	case PCI_EPC_IRQ_MSI:
+		return dw_pcie_ep_raise_msi_irq(ep, func_no,

interrupt_num);

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	case PCI_EPC_IRQ_MSIX:
+		return dw_pcie_ep_raise_msix_irq(ep, func_no,

interrupt_num);

Quoted 100 lines
Quoted 100 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +100 -0
+	default:
+		dev_err(pci->dev, "Unknown IRQ type %d\n", type);
+		return -EINVAL;
+	}
+}
+
+static const struct pci_epc_features keembay_pcie_epc_features = {
+	.linkup_notifier	= false,
+	.msi_capable		= true,
+	.msix_capable		= true,
+	.reserved_bar		= BIT(BAR_1) | BIT(BAR_3) | BIT(BAR_5),
+	.bar_fixed_64bit	= BIT(BAR_0) | BIT(BAR_2) | BIT(BAR_4),
+	.align			= SZ_16K,
+};
+
+static const struct pci_epc_features *
+keembay_pcie_get_features(struct dw_pcie_ep *ep)
+{
+	return &keembay_pcie_epc_features;
+}
+
+static const struct dw_pcie_ep_ops keembay_pcie_ep_ops = {
+	.ep_init	= keembay_pcie_ep_init,
+	.raise_irq	= keembay_pcie_ep_raise_irq,
+	.get_features	= keembay_pcie_get_features,
+};
+
+static const struct dw_pcie_host_ops keembay_pcie_host_ops = {
+};
+
+static int keembay_pcie_add_pcie_port(struct keembay_pcie *pcie,
+				      struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct pcie_port *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	u32 val;
+	int ret;
+
+	pp->ops = &keembay_pcie_host_ops;
+	pp->msi_irq = -ENODEV;
+
+	ret = keembay_pcie_setup_msi_irq(pcie);
+	if (ret)
+		return ret;
+
+	pcie->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(pcie->reset))
+		return PTR_ERR(pcie->reset);
+
+	ret = keembay_pcie_probe_clocks(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+	val |= PHY0_SRAM_BYPASS;
+	writel(val, pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+
+	writel(PCIE_DEVICE_TYPE, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+
+	ret = keembay_pcie_pll_init(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	writel(val | PCIE_RSTN, pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	keembay_ep_reset_deassert(pcie);
+
+	ret = dw_pcie_host_init(pp);
+	if (ret) {
+		keembay_ep_reset_assert(pcie);
+		dev_err(dev, "Failed to initialize host: %d\n", ret);
+		return ret;
+	}
+
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+	if (IS_ENABLED(CONFIG_PCI_MSI))
+		val |= MSI_CTRL_INT_EN;
+	writel(val, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	return 0;
+}
+
+static int keembay_pcie_probe(struct platform_device *pdev)
+{
+	const struct keembay_pcie_of_data *data;
+	struct device *dev = &pdev->dev;
+	struct keembay_pcie *pcie;
+	struct dw_pcie *pci;
+	enum dw_pcie_device_mode mode;
+
+	data = device_get_match_data(dev);
+	if (!data)
+		return -ENODEV;
+
+	mode = (enum dw_pcie_device_mode)data->mode;
+
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+	if (!pcie)
+		return -ENOMEM;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+
+	pci = &pcie->pci;
+	pci->dev = dev;
+	pci->ops = &keembay_pcie_ops;
+
+	pcie->mode = mode;
+
+	pcie->apb_base = devm_platform_ioremap_resource_byname(pdev,

"apb");

Quoted 16 lines
Quoted 16 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +16 -0
+	if (IS_ERR(pcie->apb_base))
+		return PTR_ERR(pcie->apb_base);
+
+	platform_set_drvdata(pdev, pcie);
+
+	switch (pcie->mode) {
+	case DW_PCIE_RC_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_HOST))
+			return -ENODEV;
+
+		return keembay_pcie_add_pcie_port(pcie, pdev);
+	case DW_PCIE_EP_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_EP))
+			return -ENODEV;
+
+		pci->ep.ops = &keembay_pcie_ep_ops;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+		return dw_pcie_ep_init(&pci->ep);
+	default:
+		dev_err(dev, "Invalid device type %d\n", pcie->mode);
+		return -ENODEV;
+	}
+}
+
+static const struct keembay_pcie_of_data keembay_pcie_rc_of_data =

{

Quoted 4 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 4 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +4 -0
+	.mode = DW_PCIE_RC_TYPE,
+};
+
+static const struct keembay_pcie_of_data keembay_pcie_ep_of_data =

{

Quoted 27 lines
Quoted 27 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +24 -1
+	.mode = DW_PCIE_EP_TYPE,
+};
+
+static const struct of_device_id keembay_pcie_of_match[] = {
+	{
+		.compatible = "intel,keembay-pcie",
+		.data = &keembay_pcie_rc_of_data,
+	},
+	{
+		.compatible = "intel,keembay-pcie-ep",
+		.data = &keembay_pcie_ep_of_data,
+	},
+	{}
+};
+
+static struct platform_driver keembay_pcie_driver = {
+	.driver = {
+		.name = "keembay-pcie",
+		.of_match_table = keembay_pcie_of_match,
+		.suppress_bind_attrs = true,
+	},
+	.probe  = keembay_pcie_probe,
+};
+builtin_platform_driver(keembay_pcie_driver);
--

2.17.1

author maintainer
#8 lore raw

Hi Lorenzo and Marc,

Quoted 124 lines

-----Original Message-----
From: Thokala, Srikanth
Sent: Wednesday, July 7, 2021 5:25 PM
To: Lorenzo Pieralisi <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]
Subject: RE: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

Hi Lorenzo and Marc,

Quoted 8 lines

-----Original Message-----
From: Thokala, Srikanth
Sent: Friday, June 25, 2021 8:54 AM
To: Lorenzo Pieralisi <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar,

Mallikarjunappa

Quoted 14 lines

<[email protected]>; [email protected]
Subject: RE: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

Hi Lorenzo,

Quoted 8 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: Monday, June 21, 2021 10:23 PM
To: Thokala, Srikanth <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar,

Quoted 3 lines

Mallikarjunappa

Quoted 2 lines

<[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel

Keem

Quoted 5 lines

Bay

Quoted 4 lines

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530,

[email protected]

Quoted 6 lines
Quoted 6 lines

wrote:
[...]

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 3 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +3 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie =

irq_desc_get_handler_data(desc);

Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +7 -0
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base +

PCIE_REGS_INTERRUPT_STATUS);

Quoted 10 lines
Quoted 10 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +10 -0
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;
+	struct platform_device *pdev = to_platform_device(dev);
Quoted 12 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 7 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +7 -0
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq,

keembay_pcie_msi_irq_handler,

Quoted 4 lines

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 2 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +2 -0
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc

worked

Quoted 31 lines
Quoted 19 lines

hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

Quoted 6 lines

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}

Yes, your understanding is correct.

Additional registers PCIE_REGS_INTERRUPT_ENABLE/_STATUS are provided by IP to control the interrupts.

Quoted 8 lines
Quoted 1 line

To receive MSI interrupts, SW must enable bit '8' of _ENABLE

register.

Quoted 1 line

And once a MSI is raised by the End point, bit '8' of _STATUS

register

Quoted 1 line

will be set and it needs to be cleared after servicing the interrupt.

Hope I have provided all the necessary information. Kindly feedback.

Kindly feedback.

Thanks!
Srikanth

Quoted 212 lines

Thanks!
Srikanth

Quoted 8 lines

Thanks!
Srikanth

Quoted 4 lines

Thanks,
Lorenzo

Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 6 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +6 -0
+static void keembay_pcie_ep_init(struct dw_pcie_ep *ep)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct keembay_pcie *pcie = dev_get_drvdata(pci->dev);
+
+	writel(EDMA_INT_EN, pcie->apb_base +

PCIE_REGS_INTERRUPT_ENABLE);

Quoted 20 lines
Quoted 3 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 3 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +3 -0
+}
+
+static int keembay_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8

func_no,

Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +4 -0
+				     enum pci_epc_irq_type type,
+				     u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+
+	switch (type) {
+	case PCI_EPC_IRQ_LEGACY:
+		/* Legacy interrupts are not supported in Keem Bay */
+		dev_err(pci->dev, "Legacy IRQ is not supported\n");
+		return -EINVAL;
+	case PCI_EPC_IRQ_MSI:
+		return dw_pcie_ep_raise_msi_irq(ep, func_no,

interrupt_num);

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	case PCI_EPC_IRQ_MSIX:
+		return dw_pcie_ep_raise_msix_irq(ep, func_no,

interrupt_num);

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 7 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +7 -0
+	default:
+		dev_err(pci->dev, "Unknown IRQ type %d\n", type);
+		return -EINVAL;
+	}
+}
+
+static const struct pci_epc_features keembay_pcie_epc_features =

{

Quoted 4 lines
Quoted 4 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 4 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +4 -0
+	.linkup_notifier	= false,
+	.msi_capable		= true,
+	.msix_capable		= true,
+	.reserved_bar		= BIT(BAR_1) | BIT(BAR_3) |

BIT(BAR_5),

Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +40 -0
+	.bar_fixed_64bit	= BIT(BAR_0) | BIT(BAR_2) | BIT(BAR_4),
+	.align			= SZ_16K,
+};
+
+static const struct pci_epc_features *
+keembay_pcie_get_features(struct dw_pcie_ep *ep)
+{
+	return &keembay_pcie_epc_features;
+}
+
+static const struct dw_pcie_ep_ops keembay_pcie_ep_ops = {
+	.ep_init	= keembay_pcie_ep_init,
+	.raise_irq	= keembay_pcie_ep_raise_irq,
+	.get_features	= keembay_pcie_get_features,
+};
+
+static const struct dw_pcie_host_ops keembay_pcie_host_ops = {
+};
+
+static int keembay_pcie_add_pcie_port(struct keembay_pcie *pcie,
+				      struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct pcie_port *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	u32 val;
+	int ret;
+
+	pp->ops = &keembay_pcie_host_ops;
+	pp->msi_irq = -ENODEV;
+
+	ret = keembay_pcie_setup_msi_irq(pcie);
+	if (ret)
+		return ret;
+
+	pcie->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(pcie->reset))
+		return PTR_ERR(pcie->reset);
+
+	ret = keembay_pcie_probe_clocks(pcie);
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+	val |= PHY0_SRAM_BYPASS;
+	writel(val, pcie->apb_base + PCIE_REGS_PCIE_PHY_CNTL);
+
+	writel(PCIE_DEVICE_TYPE, pcie->apb_base +

PCIE_REGS_PCIE_CFG);

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 7 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +7 -0
+
+	ret = keembay_pcie_pll_init(pcie);
+	if (ret)
+		return ret;
+
+	val = readl(pcie->apb_base + PCIE_REGS_PCIE_CFG);
+	writel(val | PCIE_RSTN, pcie->apb_base +

PCIE_REGS_PCIE_CFG);

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +34 -0
+	keembay_ep_reset_deassert(pcie);
+
+	ret = dw_pcie_host_init(pp);
+	if (ret) {
+		keembay_ep_reset_assert(pcie);
+		dev_err(dev, "Failed to initialize host: %d\n", ret);
+		return ret;
+	}
+
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+	if (IS_ENABLED(CONFIG_PCI_MSI))
+		val |= MSI_CTRL_INT_EN;
+	writel(val, pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	return 0;
+}
+
+static int keembay_pcie_probe(struct platform_device *pdev)
+{
+	const struct keembay_pcie_of_data *data;
+	struct device *dev = &pdev->dev;
+	struct keembay_pcie *pcie;
+	struct dw_pcie *pci;
+	enum dw_pcie_device_mode mode;
+
+	data = device_get_match_data(dev);
+	if (!data)
+		return -ENODEV;
+
+	mode = (enum dw_pcie_device_mode)data->mode;
+
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+	if (!pcie)
+		return -ENOMEM;
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+
+	pci = &pcie->pci;
+	pci->dev = dev;
+	pci->ops = &keembay_pcie_ops;
+
+	pcie->mode = mode;
+
+	pcie->apb_base =

devm_platform_ioremap_resource_byname(pdev,

Quoted 17 lines

"apb");

Quoted 16 lines
Quoted 16 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +16 -0
+	if (IS_ERR(pcie->apb_base))
+		return PTR_ERR(pcie->apb_base);
+
+	platform_set_drvdata(pdev, pcie);
+
+	switch (pcie->mode) {
+	case DW_PCIE_RC_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_HOST))
+			return -ENODEV;
+
+		return keembay_pcie_add_pcie_port(pcie, pdev);
+	case DW_PCIE_EP_TYPE:
+		if (!IS_ENABLED(CONFIG_PCIE_KEEMBAY_EP))
+			return -ENODEV;
+
+		pci->ep.ops = &keembay_pcie_ep_ops;
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+		return dw_pcie_ep_init(&pci->ep);
+	default:
+		dev_err(dev, "Invalid device type %d\n", pcie->mode);
+		return -ENODEV;
+	}
+}
+
+static const struct keembay_pcie_of_data keembay_pcie_rc_of_data

=

Quoted 5 lines

{

Quoted 4 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 4 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +4 -0
+	.mode = DW_PCIE_RC_TYPE,
+};
+
+static const struct keembay_pcie_of_data keembay_pcie_ep_of_data

=

Quoted 28 lines

{

Quoted 27 lines
Quoted 27 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +24 -1
+	.mode = DW_PCIE_EP_TYPE,
+};
+
+static const struct of_device_id keembay_pcie_of_match[] = {
+	{
+		.compatible = "intel,keembay-pcie",
+		.data = &keembay_pcie_rc_of_data,
+	},
+	{
+		.compatible = "intel,keembay-pcie-ep",
+		.data = &keembay_pcie_ep_of_data,
+	},
+	{}
+};
+
+static struct platform_driver keembay_pcie_driver = {
+	.driver = {
+		.name = "keembay-pcie",
+		.of_match_table = keembay_pcie_of_match,
+		.suppress_bind_attrs = true,
+	},
+	.probe  = keembay_pcie_probe,
+};
+builtin_platform_driver(keembay_pcie_driver);
--

2.17.1

#9 lore raw
In reply to Thokala, Srikanth
Quoted 84 lines · Srikanth

Hi Lorenzo,

Quoted 75 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: Monday, June 21, 2021 10:23 PM
To: Thokala, Srikanth <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530, [email protected] wrote:
[...]

Quoted 27 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +27 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 10 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +10 -0
+	struct platform_device *pdev = to_platform_device(dev);
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq, keembay_pcie_msi_irq_handler,
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc worked hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

Quoted 6 lines

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}
Quoted 8 lines

Yes, your understanding is correct.

Additional registers PCIE_REGS_INTERRUPT_ENABLE/_STATUS are provided by IP to control the interrupts.

To receive MSI interrupts, SW must enable bit '8' of _ENABLE register. And once a MSI is raised by the End point, bit '8' of _STATUS register will be set and it needs to be cleared after servicing the interrupt.

What isn't clear here is whether the other bits that are written back are significant and have a side effect. If only bit 8 is required, shouldn't you *only* write this bit back?

Only you can know the answer to this, but it would be good if you could actually document this deviation from the already wonky DWC infrastructure.

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
author maintainer
#10 lore raw

Hi Marc,

Quoted 116 lines

-----Original Message-----
From: Marc Zyngier <[email protected]>
Sent: Monday, July 26, 2021 1:30 PM
To: Thokala, Srikanth <[email protected]>
Cc: Lorenzo Pieralisi <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel Keem Bay

Quoted 10 lines · Srikanth

Hi Lorenzo,

Quoted 8 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: Monday, June 21, 2021 10:23 PM
To: Thokala, Srikanth <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar,

Mallikarjunappa

Quoted 2 lines
Quoted 2 lines

<[email protected]>; [email protected]
Subject: Re: [PATCH v10 2/2] PCI: keembay: Add support for Intel

Keem

Quoted 11 lines
Quoted 11 lines

Bay

[+Marc]

On Mon, Jun 07, 2021 at 09:10:44PM +0530, [email protected] wrote:
[...]

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 3 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +3 -0
+static void keembay_pcie_msi_irq_handler(struct irq_desc *desc)
+{
+	struct keembay_pcie *pcie =

irq_desc_get_handler_data(desc);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +7 -0
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 val, mask, status;
+	struct pcie_port *pp;
+
+	chained_irq_enter(chip, desc);
+
+	pp = &pcie->pci.pp;
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
+	mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);
+
+	status = val & mask;
+
+	if (status & MSI_CTRL_INT) {
+		dw_handle_msi_irq(pp);
+		writel(status, pcie->apb_base +

PCIE_REGS_INTERRUPT_STATUS);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +9 -0
+	}
+
+	chained_irq_exit(chip, desc);
+}
+
+static int keembay_pcie_setup_msi_irq(struct keembay_pcie *pcie)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct device *dev = pci->dev;
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-keembay.c

Quoted 8 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +8 -0
+	struct platform_device *pdev = to_platform_device(dev);
+	int irq;
+
+	irq = platform_get_irq_byname(pdev, "pcie");
+	if (irq < 0)
+		return irq;
+
+	irq_set_chained_handler_and_data(irq,

keembay_pcie_msi_irq_handler,

Quoted 4 lines
Quoted 4 lines

drivers/pci/controller/dwc/pcie-keembay.c line 265

Quoted 2 lines
drivers/pci/controller/dwc/pcie-keembay.c new file +2 -0
+					 pcie);
+

Ok this is yet another DWC MSI incantation and given that Marc

worked

Quoted 26 lines
Quoted 19 lines

hard consolidating them let's have a look before we merge it.

IIUC - this IP relies on the DWC logic to handle MSIs + custom registers to detect a pending MSI IRQ because the logic in dw_chained_msi_irq() is *not* enough so you have to register a driver specific chained handler. This looks similar to the dra7xx driver MSI handling but I am not entirely convinced it is needed.

I assume this code in keembay_pcie_msi_irq_handler() is required owing to additional IP logic on top of the standard DWC IP, in particular the PCIE_REGS_INTERRUPT_STATUS write to "clear" the IRQ.

We need more insights before merging it so please provide them.

pp = &pcie->pci.pp;
val = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS); mask = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_ENABLE);

Quoted 6 lines

status = val & mask;

if (status & MSI_CTRL_INT) {
	dw_handle_msi_irq(pp);
	writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS);
}
Quoted 6 lines

Yes, your understanding is correct.

Additional registers PCIE_REGS_INTERRUPT_ENABLE/_STATUS are provided by IP to control the interrupts.

To receive MSI interrupts, SW must enable bit '8' of _ENABLE

register.

Quoted 1 line

And once a MSI is raised by the End point, bit '8' of _STATUS

register

Quoted 1 line

will be set and it needs to be cleared after servicing the interrupt.

Quoted 7 lines

What isn't clear here is whether the other bits that are written back are significant and have a side effect. If only bit 8 is required, shouldn't you *only* write this bit back?

Only you can know the answer to this, but it would be good if you could actually document this deviation from the already wonky DWC infrastructure.

SW will only unmask MSI Interrupt i.e. bit '8' in the 'INTERRUPT_ENABLE' register during the Root Port initialization, other bits of this register are not significant in this mode.

Thanks!
Srikanth

Quoted 6 lines

Thanks,

         M.

--
Jazz is not dead. It just smells funny...

author maintainer
#11 lore raw
In reply to [email protected]

Hi Lorenzo Pieralisi and Bjorn Helgaas,

Quoted 18 lines

-----Original Message-----
From: Thokala, Srikanth <[email protected]>
Sent: Monday, June 7, 2021 9:11 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; [email protected]; Thokala, Srikanth <[email protected]>
Subject: [PATCH v10 0/2] PCI: keembay: Add support for Intel Keem Bay

From: Srikanth Thokala <[email protected]>

Hi,

The first patch is to document DT bindings for Keem Bay PCIe controller for both Root Complex and Endpoint modes.

Quoted 7 lines

The second patch is the driver file, a glue driver. Keem Bay PCIe controller is based on DesignWare PCIe IP.

The patch was tested with Keem Bay evaluation module board, with B0 stepping.

Kindly review.

Kindly review the patch series.
I have got 'Reviewed-by' for both patches in the series and please let me know if you have any comments that I need to address further.

Thanks!
Srikanth

Quoted 110 lines

Thanks!
Srikanth

Changes since v9:
- Add 'Reviewed-by: Krzysztof Wilczyński <[email protected]>', thanks to Krzysztof.
- Rebased to v5.13-rc5.

Changes since v8:
- Use chained IRQ to handle MSIs, as suggested by Lorenzo Pieralisi.
- Rename *_setup_irq() to *_setup_msi_irq() to be more meaningful.
- Move *_setup_msi_irq() call to *_add_pcie_port() to make it invoke only when controller is in Root Complex mode. In Endpoint mode, IRQ will be setup by the respective driver which will be based on PCIe End Point Framework.

Changes since v7:
- Rename keembay_pcie_ltssm_enable() to align to its functionality.
- Fix other minor comments from "Krzysztof Wilczyński <[email protected]>"

Changes since v6:
- Arrange SoB in chronological order.
- Alphabetized and modified status of entry in MAINTAINERS.
- Added a comment to specify the PCIe spec section about the delay.

Changes since v5:
- Rebased to v5.11-rc4.
- Updated maintainers to add myself in DT binding documents.
- Fix checkpatch issues.

Changes since v4:
- Rebased to v5.11-rc1 and retest.

Changes since v3:
- Add Reviewed-by: Rob Herring <[email protected]> tag in dt-bindings patch.
- Remove the keembay_pcie_{readl,writel} wrappers. And replace them with readl() and writel().
- Remove the dead code related to unused irqs.
- Remove unused definition for unused irqs.
- In keembay_pcie_ep_init(), initialize enabled interrupts to known state.
- Rebased to next-20201215.

Changes since v2:
- In keembay_pcie_probe(), use return keembay_pcie_add_pcie_port(pcie, pdev); statement and remove return 0; at the end of the function.

Changes since v1:
- In dt-bindings patch.
- Fixed indent warning for compatible property.
- Rename interrupt-names to pcie, pcie_ev, pcie_err and pcie_mem_access, similar to the name used in datasheet.
- Remove device_type, #address-cells and #size-cells property.
- Remove num-viewport, num-ib-windows and num-ob-windows property.
- Replace additionalProperties with unevaluatedProperties, for RC only.
- Add dbi2 and atu property.
- Remove description for regs and interrupts property.
- Change enum value for num-lanes to 1 and 2 only.
- In driver patch.
- In Kconfig file, remove dependency on ARM64.
- Add new define, PCIE_REGS_PCIE_SII_LINK_UP.
- Remove PCIE_DBI2_MASK.
- In struct keembay_pcie, declare pci member as struct, not pointer. And remove irq number members.
- Rename and rework keembay_pcie_establish_link(), to keembay_pcie_start_link().
- Remove unneeded BAR disable steps.
- Remove unused interrupt handlers; keembay_pcie_ev_irq_handler(), keembay_pcie_err_irq_handler().
- Remove keembay_pcie_enable_interrupts().
- Rework keembay_pcie_setup_irq() and call it from keembay_pcie_probe().
- Remove keembay_pcie_host_init() and make keembay_pcie_host_ops empty.
- Keep and rework keembay_pcie_add_pcie_port() a little.
- Remove keembay_pcie_add_pcie_ep() and call dw_pcie_ep_init() from keembay_pcie_probe().
- In keembay_pcie_probe(), remove dbi setup as it will be handled in dwc common code.
- In keembay_pcie_link_up(), use return (val &

    PCIE_REGS_PCIE_SII_LINK_UP) == PCIE_REGS_PCIE_SII_LINK_UP.

- In keembay_pcie_ep_raise_irq(), rework error message for PCI_EPC_IRQ_LEGACY and default cases.
- Rebased to next-20201124, that has dwc pci refactoring,
https://lore.kernel.org/linux-pci/20201105211159.1814485-1-
[email protected]/.

Srikanth Thokala (2):
dt-bindings: PCI: Add Intel Keem Bay PCIe controller
PCI: keembay: Add support for Intel Keem Bay

 .../bindings/pci/intel,keembay-pcie-ep.yaml   |  69 +++
 .../bindings/pci/intel,keembay-pcie.yaml      |  97 ++++
 MAINTAINERS                                   |   7 +
 drivers/pci/controller/dwc/Kconfig            |  28 ++
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-keembay.c     | 451 ++++++++++++++++++
 6 files changed, 653 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-
pcie-ep.yaml
 create mode 100644 Documentation/devicetree/bindings/pci/intel,keembay-
pcie.yaml
 create mode 100644 drivers/pci/controller/dwc/pcie-keembay.c

base-commit: 614124bea77e452aa6df7a8714e8bc820b489922 --
2.17.1