PCI: microchip: Add host driver for Microchip PCIe controller
Subsystems (4)
[email protected]
maintainerv15 cover PCI: microchip: Add host driver for Microchip PCIe controller
This v15 patch adds support for the Microchip PCIe PolarFire PCIe controller when configured in host (Root Complex) mode.
Updates since v14:
* Removed cfg_read/cfg_write inline functions
* Updated to irq_data_get_irq_chip_data()
* Updated to use devm_platform_ioremap_resource()
* Replaced of_pci_range parsing to setup windows via bridge pointer.
Updates since v13:
* Refactored to use pci_host_common_probe()
Updates since v12:
* Capitalised commit messages. Use specific subject line for dt-bindings
Updates since v11:
* Adjusted so yaml file passses make dt_binding_check
Updates since v10:
* Adjusted driver as per Rob Herring's comments, notably:
- use common PCI_MSI_FLAGS defines
- reduce storage of unnecessary vars in mc_pcie struct
- switched to read/write relaxed variants
- extended lock in msi_domain_alloc routine
- improved 32bit safety, switched from find_first_bit() to ilog2()
- removed unnecessary twiddle of eCAM config space
Updates since v9:
* Adjusted commit logs
* make dt_bindings_check passes
Updates since v8:
* Refactored as per Rob Herring's comments:
- bindings in schema format
- Adjusted licence to GPLv2.0
- Refactored access to config space between driver and common eCAM code
- Adopted pci_host_probe()
- Miscellanous other improvements
Updates since v7:
* Build for 64bit RISCV architecture only
Updates since v6:
* Refactored to use common eCAM driver
* Updated to CONFIG_PCIE_MICROCHIP_HOST etc
* Formatting improvements
* Removed code for selection between bridge 0 and 1
Updates since v5:
* Fixed Kconfig typo noted by Randy Dunlap
* Updated with comments from Bjorn Helgaas
Updates since v4:
* Fix compile issues.
Updates since v3:
* Update all references to Microsemi to Microchip
* Separate MSI functionality from legacy PCIe interrupt handling functionality
Updates since v2:
* Split out DT bindings and Vendor ID updates into their own patch from PCIe driver.
* Updated Change Log
Updates since v1:
* Incorporate feedback from Bjorn Helgaas
Daire McNamara (2):
dt-bindings: PCI: microchip: Add Microchip PolarFire host binding
PCI: microchip: Add host driver for Microchip PCIe controller
Daire McNamara (2):
dt-bindings: PCI: microchip: Add Microchip PolarFire host binding
PCI: microchip: Add host driver for Microchip PCIe controller
.../bindings/pci/microchip,pcie-host.yaml | 93 +++ drivers/pci/controller/Kconfig | 9 + drivers/pci/controller/Makefile | 1 + drivers/pci/controller/pcie-microchip-host.c | 560 ++++++++++++++++++ 4 files changed, 663 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/microchip,pcie-host.yaml create mode 100644 drivers/pci/controller/pcie-microchip-host.c
base-commit: 18445bf405cb331117bc98427b1ba6f12418ad17
Signature · 1 line
2.17.1
[email protected]
maintainerPATCH v15 1/2 dt-bindings: PCI: microchip: Add Microchip PolarFire host binding
Add device tree bindings for the Microchip PolarFire PCIe controller when configured in host (Root Complex) mode.
--- .../bindings/pci/microchip,pcie-host.yaml | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/microchip,pcie-host.yaml
Documentation/devicetree/bindings/pci/microchip,pcie-host.yaml new file +93 -0
@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/microchip,pcie-host.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PCIe Root Port Bridge Controller Device Tree Bindings + +maintainers: + - Daire McNamara <[email protected]> + +allOf: + - $ref: /schemas/pci/pci-bus.yaml# + +properties: + compatible: + const: microchip,pcie-host-1.0 # PolarFire + + reg: + maxItems: 2 + + reg-names: + items: + - const: cfg + - const: apb + + interrupts: + minItems: 1 + maxItems: 2 + items: + - description: PCIe host controller + - description: builtin MSI controller + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + - const: pcie + - const: msi + + ranges: + maxItems: 1 + + dma-ranges: + maxItems: 1 + + msi-controller: + description: Identifies the node as an MSI controller. + + msi-parent: + description: MSI controller the device is capable of using. + +required: + - reg + - reg-names + - dma-ranges + - "#interrupt-cells" + - interrupts + - interrupt-map-mask + - interrupt-map + - msi-controller + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + pcie0: pcie@2030000000 { + compatible = "microchip,pcie-host-1.0"; + reg = <0x20 0x30000000 0x0 0x4000000>, + <0x20 0x0 0x0 0x100000>; + reg-names = "cfg", "apb"; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + #interrupt-cells = <1>; + interrupts = <32>; + interrupt-map-mask = <0x0 0x0 0x0 0x7>; + interrupt-map = <0 0 0 1 &pcie0 0>, + <0 0 0 2 &pcie0 1>, + <0 0 0 3 &pcie0 2>, + <0 0 0 4 &pcie0 3>; + interrupt-parent = <&plic0>; + interrupt-controller; + msi-parent = <&pcie0>; + msi-controller; + bus-range = <0x00 0x7f>; + ranges = <0x03000000 0x0 0x40000000 0x0 0x40000000 0x0 0x20000000>; + dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 0x1 0x00000000>; + }; + };
Signature · 1 line
2.17.1
Re: [PATCH v15 1/2] dt-bindings: PCI: microchip: Add Microchip PolarFire host binding
Quoted 9 lines · On Wed, 19 Aug 2020 16:32:01 +0000, [email protected] wrote:
Add device tree bindings for the Microchip PolarFire PCIe controller when configured in host (Root Complex) mode.
Signed-off-by Daire McNamara <[email protected]>--- .../bindings/pci/microchip,pcie-host.yaml | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/microchip,pcie-host.yaml
[email protected]
maintainerPATCH v15 2/2 PCI: microchip: Add host driver for Microchip PCIe controller
In reply to [email protected]Add support for the Microchip PolarFire PCIe controller when configured in host (Root Complex) mode.
--- drivers/pci/controller/Kconfig | 9 + drivers/pci/controller/Makefile | 1 + drivers/pci/controller/pcie-microchip-host.c | 560 +++++++++++++++++++ 3 files changed, 570 insertions(+) create mode 100644 drivers/pci/controller/pcie-microchip-host.c
drivers/pci/controller/Kconfig +9 -0
@@ -294,6 +294,15 @@ config PCI_LOONGSON Say Y here if you want to enable PCI controller support on Loongson systems. +config PCIE_MICROCHIP_HOST + bool "Microchip AXI PCIe host bridge support" + depends on PCI_MSI && OF + select PCI_MSI_IRQ_DOMAIN + select GENERIC_MSI_IRQ_DOMAIN + help + Say Y here if you want kernel to support the Microchip AXI PCIe + Host Bridge driver. + source "drivers/pci/controller/dwc/Kconfig" source "drivers/pci/controller/mobiveil/Kconfig" source "drivers/pci/controller/cadence/Kconfig"
drivers/pci/controller/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_PCIE_ROCKCHIP_EP) += pcie-rockchip-ep.o obj-$(CONFIG_PCIE_ROCKCHIP_HOST) += pcie-rockchip-host.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o +obj-$(CONFIG_PCIE_MICROCHIP_HOST) += pcie-microchip-host.o obj-$(CONFIG_VMD) += vmd.o obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o obj-$(CONFIG_PCI_LOONGSON) += pci-loongson.o
drivers/pci/controller/pcie-microchip-host.c new file +560 -0
560 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 2 lines · On Wed, Aug 19, 2020 at 04:33:10PM +0000, [email protected] wrote:
+ *
pcie-altera.c
+ */
Add a blank line here.
drivers/pci/controller/pcie-microchip-host.c
Quoted 4 lines
drivers/pci/controller/pcie-microchip-host.c new file +3
-0+#include <linux/irqchip/chained_irq.h> +#include <linux/module.h> +static struct mc_port *port;
This file scope item is not ideal. It might work in your situation if you can never have more than one device, but it's not a pattern we want other people to copy.
I think I sort of see how it works:
mc_pci_host_probe
pci_host_common_probe
ops = of_device_get_match_data() # mc_ecam_ops
gen_pci_init(..., ops)
pci_ecam_create(..., ops)
ops->init # mc_ecam_ops.init
mc_platform_init(pci_config_window *)
port = devm_kzalloc(...) # initialized
mc_setup_windows
bridge_base_addr = port->axi_base_addr + ... # usedAnd you're using the file scope "port" because mc_platform_init() doesn't have a pointer to the platform_device. But I think this abuses the pci_ecam_ops design to do host bridge initialization that it is not intended for.
I'd suggest copying the host bridge init design from somewhere else. tango_pcie_probe() also calls pci_host_common_probe(), so maybe that's a good place. But the fact that it's the *only* such caller makes me think it might not be the best thing to copy.
Rob has been working in this area and probably has better insight.
Quoted 10 lines
drivers/pci/controller/pcie-microchip-host.c new file +10
-0+static void mc_pcie_isr (struct irq_desc *desc) +{ +struct irq_chip *chip =irq_desc_get_chip (desc); +struct mc_port *port =irq_desc_get_handler_data (desc); +struct device *dev = port->dev; +struct mc_msi *msi = &port->msi; +void __iomem *bridge_base_addr = port->axi_base_addr +MC_PCIE1_BRIDGE_ADDR ; +unsigned long status; +unsigned long intx_status; +unsigned long msi_status;
drivers/pci/controller/pcie-microchip-host.c line 142
Quoted 10 lines
drivers/pci/controller/pcie-microchip-host.c new file +10
-0+u32 bit; +u32 virq; + +/* +* The core provides a single interrupt for both INTx/MSI messages. +* So we'll read both INTx and MSI status. +*/ +chained_irq_enter (chip, desc); + + status =readl_relaxed (bridge_base_addr +MC_ISTATUS_LOCAL );
readl_relaxed() is defined to return a u32, so you might as well declare "status" and related things as u32 instead of "unsigned long".
drivers/pci/controller/pcie-microchip-host.c line 184
Quoted 5 lines
drivers/pci/controller/pcie-microchip-host.c new file +5
-0+static void mc_pcie_enable_msi (struct mc_port *port,void __iomem *base) +{ +struct mc_msi *msi = &port->msi; +u32 cap_offset =MC_MSI_CAP_CTRL_OFFSET ; +
Remove this blank line. We usually just separate the automatic variables from the code with a blank line.
drivers/pci/controller/pcie-microchip-host.c line 323
Quoted 13 lines
drivers/pci/controller/pcie-microchip-host.c new file +12
-0+u16 msg_ctrl =readw_relaxed (base + cap_offset +PCI_MSI_FLAGS ); +static void mc_mask_intx_irq (struct irq_data *data) +{ +struct mc_port *port =irq_data_get_irq_chip_data (data); +void __iomem *bridge_base_addr = port->axi_base_addr +MC_PCIE1_BRIDGE_ADDR ; +unsigned long flags; +u32 mask, val; + + mask =PCIE_LOCAL_INT_ENABLE ; +raw_spin_lock_irqsave (&port->intx_mask_lock, flags); + val =readl_relaxed (bridge_base_addr +MC_IMASK_LOCAL ); + val &= ~mask;
Why bother with "mask" here? It's only used once; just use PCIE_LOCAL_INT_ENABLE directly.
Quoted 5 lines
drivers/pci/controller/pcie-microchip-host.c new file +5
-0+writel_relaxed (val, bridge_base_addr +MC_IMASK_LOCAL ); +raw_spin_unlock_irqrestore (&port->intx_mask_lock, flags); +} + +static void mc_unmask_intx_irq (struct irq_data *data)
drivers/pci/controller/pcie-microchip-host.c line 338
Quoted 10 lines
drivers/pci/controller/pcie-microchip-host.c new file +10
-0+{ +struct mc_port *port =irq_data_get_irq_chip_data (data); +void __iomem *bridge_base_addr = port->axi_base_addr +MC_PCIE1_BRIDGE_ADDR ; +unsigned long flags; +u32 mask, val; + + mask =PCIE_LOCAL_INT_ENABLE ; +raw_spin_lock_irqsave (&port->intx_mask_lock, flags); + val =readl_relaxed (bridge_base_addr +MC_IMASK_LOCAL ); + val |= mask;
Here also.
Quoted 22 lines
drivers/pci/controller/pcie-microchip-host.c new file +22
-0+static int mc_platform_init (struct pci_config_window *cfg) +{ +struct device *dev = cfg->parent; +struct platform_device *pdev =to_platform_device (dev); +void __iomem *bridge_base_addr; +void __iomem *ctrl_base_addr; +int ret; +u32 irq; +u32 val; + + port =devm_kzalloc (dev,sizeof (*port),GFP_KERNEL ); +if (!port) +return -ENOMEM ; + port->dev = dev; + + port->axi_base_addr =devm_platform_ioremap_resource (pdev,1 ); +if (IS_ERR (port->axi_base_addr)) +return PTR_ERR (port->axi_base_addr); + + bridge_base_addr = port->axi_base_addr +MC_PCIE1_BRIDGE_ADDR ; + ctrl_base_addr = port->axi_base_addr +MC_PCIE1_CTRL_ADDR ; +
drivers/pci/controller/pcie-microchip-host.c line 444
Quoted 10 lines
drivers/pci/controller/pcie-microchip-host.c new file +10
-0+ port->msi.vector_phy =MC_MSI_ADDR ; + port->msi.num_vectors =MC_NUM_MSI_IRQS ; + ret =mc_pcie_init_irq_domains (port); +if (ret) { +dev_err (dev,"failed creating IRQ domains\n" ); +return ret; + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) {
platform_get_irq() returns "int". You declared "irq" as "u32" above, so this check for failure won't work correctly.
Quoted 3 lines
drivers/pci/controller/pcie-microchip-host.c new file +3
-0+dev_err (dev,"unable to request IRQ%d\n" , irq); +return -ENODEV ; + }
Rob Herring
maintainerQuoted 8 lines · Bjorn Helgaas
Quoted 2 lines · On Wed, Aug 19, 2020 at 04:33:10PM +0000, [email protected] wrote:
+ *
pcie-altera.c
+ */Add a blank line here.
Quoted 8 lines
drivers/pci/controller/pcie-microchip-host.c
Quoted 4 lines
drivers/pci/controller/pcie-microchip-host.c new file +3
-0+#include <linux/irqchip/chained_irq.h> +#include <linux/module.h> +static struct mc_port *port;This file scope item is not ideal. It might work in your situation if you can never have more than one device, but it's not a pattern we want other people to copy.
Indeed.
Quoted 13 lines
I think I sort of see how it works:
mc_pci_host_probepci_host_common_probe ops = of_device_get_match_data() # mc_ecam_ops gen_pci_init(..., ops) pci_ecam_create(..., ops) ops->init # mc_ecam_ops.init mc_platform_init(pci_config_window *) port = devm_kzalloc(...) # initialized mc_setup_windows bridge_base_addr = port->axi_base_addr + ... # used
Quoted 2 lines
And you're using the file scope "port" because
mc_platform_init()doesn't have a pointer to theplatform_device.
This is a simple fix. Move platform_set_drvdata to just after devm_pci_alloc_host_bridge() in pci_host_common_probe(). (Don't fall into the 'platform problem'[1] and work-around the core code.)
Then pci_host_common_probe can be called directly and mc_setup_windows can be moved to mc_platform_init().
Quoted 3 lines
But I think this
abuses thepci_ecam_opsdesign to do host bridge initialization that it is not intended for.
What init should be done then? IMO, given this driver is using ECAM support already and it's all one time init that fits into init(), it seems like a fit to me.
Quoted 6 lines
I'd suggest copying the host bridge init design from somewhere else.
tango_pcie_probe()also callspci_host_common_probe(), so maybe that's a good place. But the fact that it's the *only* such caller makes me think it might not be the best thing to copy.Rob has been working in this area and probably has better insight.
It was my suggestion to move to the ECAM init. Prior versions had its own probe.
One question I've been wrestling with is if we can do all the firmware setup for 'generic ECAM' on the same h/w we have drivers for, then shouldn't we make the kernel driver create an ECAM setup? There's also the question of why do root port config accesses go thru standard ECAM config space in ECAM mode, but use different address space for non-ECAM setup? DWC for example can probably do ECAM on more platforms. There's some that can't which are generally ones w/o the iATU or enough iATU entries or not enough memory space. The difference from a config space standpoint is just DT configuration (in the case of DWC with an iATU, the config space and memory space DT entries are just iATU configuration not h/w constraints).
I think we have drivers too much in control of their initialization ordering and things should be more the other way around with core code calling h/w ops to do specific things. I don't have any grand plan yet, but perhaps the generic/common host stuff evolves beyond just ECAM and almost ECAM. The generic host would just have no h/w ops.
Rob
Quoted 35 lines · Rob Herring
Quoted 8 lines · Bjorn Helgaas
Quoted 1 line · On Wed, Aug 19, 2020 at 04:33:10PM +0000, [email protected] wrote:
+static struct
mc_port*port;This file scope item is not ideal. It might work in your situation if you can never have more than one device, but it's not a pattern we want other people to copy.
Indeed.
Quoted 13 lines
I think I sort of see how it works:
mc_pci_host_probepci_host_common_probe ops = of_device_get_match_data() # mc_ecam_ops gen_pci_init(..., ops) pci_ecam_create(..., ops) ops->init # mc_ecam_ops.init mc_platform_init(pci_config_window *) port = devm_kzalloc(...) # initialized mc_setup_windows bridge_base_addr = port->axi_base_addr + ... # usedQuoted 2 lines
And you're using the file scope "port" because
mc_platform_init()doesn't have a pointer to theplatform_device.This is a simple fix. Move
platform_set_drvdatato just afterdevm_pci_alloc_host_bridge()inpci_host_common_probe(). (Don't fall into the 'platform problem'[1] and work-around the core code.)Then
pci_host_common_probecan be called directly andmc_setup_windowscan be moved tomc_platform_init().
Quoted 7 lines
Quoted 3 lines
But I think this
abuses thepci_ecam_opsdesign to do host bridge initialization that it is not intended for.What init should be done then? IMO, given this driver is using ECAM support already and it's all one time init that fits into
init(), it seems like a fit to me.
Oh, OK. If you can solve this as you outlined above, that's fine with me. It didn't look like a common pattern yet, but maybe it will be.
Thanks for chiming in. I didn't have a good idea for how to fix the file-scope variable problem.
Bjorn