mbox series

[v8,0/22] Refactoring Microchip PCIe driver and add StarFive PCIe

Message ID 20231011110514.107528-1-minda.chen@starfivetech.com
Headers show
Series Refactoring Microchip PCIe driver and add StarFive PCIe | expand

Message

Minda Chen Oct. 11, 2023, 11:04 a.m. UTC
This patchset final purpose is add PCIe driver for StarFive JH7110 SoC.
JH7110 using PLDA XpressRICH PCIe IP. Microchip PolarFire Using the
same IP and have commit their codes, which are mixed with PLDA
controller codes and Microchip platform codes.

For re-use the PLDA controller codes, I request refactoring microchip
codes, move PLDA common codes to PLDA files.
Desigware and Cadence is good example for refactoring codes.

----------------------------------------------------------
The refactoring patches total number is 17,(patch 1-17)
which do NOT contain changing logic of codes.

These patches just contain three type basic operations.
(rename, modify codes to support starfive platform, and moving to common file)
If these patched are all be reviewed. They can be accepted first.

Refactoring patches can be devided to different groups
1. (patch 1- 3 is the prepare work of refactoring)
patch1 is move PLDA XpressRICH PCIe host common properties dt-binding
       docs from microchip,pcie-host.yaml
patch2 is move PolarFire codes to PLDA directory.
patch3 is move PLDA IP register macros to plda-pcie.h

2. (patch4 - 6 is processing and re-use PCIe host instance)
patch4 is add bridge_addr field to PCIe host instance.
patch5 is rename data structure in microchip codes.
patch6 is moving two data structures to head file

3. (patch 7 - 9 are for re-use two PCIe setup function)
patch7 is rename two setup functions in microchip codes, prepare to move
to common file.
patch8 is change the arguments of plda_pcie_setup_iomems()
patch9 is move the two setup functions to common file pcie-plda-host.c

4.(patch 10 - 17 are for re-use interupt processing codes)
patch10 add a plda default event handler function.
patch11 is rename the IRQ related functions, prepare to move to
pcie-plda-host.c
patch 12 - 16 is modify the interrupt event codes, preparing for support starfive
and microchip two platforms.
patch17 is move IRQ related functions to pcie-plda-host.c

------------------------------------------------------------
The remainder patches (patch 18 -22) are not refactoring patch.
They are for adding StarFive codes and dont modify the microchip's
codes.

patch18 is set plda_event_handler to static.
patch19 is Add PLDA event interrupt codes and IRQ domain ops.
patch20 is add StarFive JH7110 PCIe dt-binding doc.
patch21 is add StarFive JH7110 Soc PCIe codes.
patch22 is Starfive dts config

This patchset is base on v6.6-rc5

previous version:
v3:https://patchwork.kernel.org/project/linux-pci/cover/20230814082016.104181-1-minda.chen@starfivetech.com/
v4:https://patchwork.kernel.org/project/linux-pci/cover/20230825090129.65721-1-minda.chen@starfivetech.com/
v5:https://patchwork.kernel.org/project/linux-pci/cover/20230907091058.125630-1-minda.chen@starfivetech.com/
v6:https://patchwork.kernel.org/project/linux-pci/cover/20230915102243.59775-1-minda.chen@starfivetech.com/
v7:https://patchwork.kernel.org/project/linux-pci/cover/20230927100802.46620-1-minda.chen@starfivetech.com/

change:
  v8:
    The patch description in cover-letter has been changed.

    v7 patch 4 split to v8 patch 4 - 6.
        (It is patches about re-use pcie host data structure, new patches just contain one
	function modification. It is more reguluar and easier to review).

    patch 7- 9: modify the commit messages and add reason of
		modifcation.
    patch10 : just new add a default event handler.
              The PLDA event interrupt codes has been moved to patch19.
    patch11- 17 :
             Add review tag and add more commit messages to declear the
	     reason of modifying the codes.
    patch19: plda_handle_events() using bit mask macro. The function are
	     easier to read.

  v7:
    patch19: fix the build warning.
    patch21: Some format changes (Emil's comment)
    patch22: change the pcie node sequences by alphabetical
             delete the "interupt-parent" in pcie node.

  v6:
    v5 patch 4 split to patch 4 -9. New patches just contain one
function modification. It is more reguluar.
    patch 9: Just move the two setup functions only
    patch 19 : draw a graph of PLDA local register, make it easier to
review the codes.
    v5 patch 7 split to patch 11- 17. Each patch just contain one
function modification. It is more regular.
    patch 11: rename IRQ related functions.
    patch 12 - 16 : modify the events codes, total five patch.
    patch 17: move IRQ related functions to pcie-plda-host.c
    patch 18: Add new patch 18.
    patch 21- 22 using "linux,pci-domain" dts setting.

  v5:
    patch 10 -17:
    	- Some variables names changed (evt->event).
    	- plda_handle_event() using a unify callback function to get events
num.
	- Add plda_event_ops data structure.
    patch 21:
	Add plda_event_ops instances.

  v4:
    patch 3:
    	Copy the interrupt events macros to pcie-plda-host.c
    patch 15:
    	get_events() change in patch 7. Patch 8 is just move the codes.
    other change:
	All the functions in commit message add (). 
  v3:
    patch 2- 19:
      - splite refactoring patches to multiple patch.
      - rename plda_pcie to plda_pcie_rp. Maybe other vendor will
        upstream PLDA ep codes.
    patch 20:
      - Remove the redundant reference.
      - move the offset value to codes in starfive,stg-syscon
      - change reset-gpio to prest-gpio.
    patch 21:
      - Add 100ms delay after preset for PCIe 6.0 spec.
      - stg-syscon related modification.
    patch 22:
      - Add dts configure.


Minda Chen (22):
  dt-bindings: PCI: Add PLDA XpressRICH PCIe host common properties
  PCI: microchip: Move pcie-microchip-host.c to plda directory
  PCI: microchip: Move PLDA IP register macros to pcie-plda.h
  PCI: microchip: Add bridge_addr field to struct mc_pcie
  PCI: microchip: Rename two PCIe data structures
  PCI: microchip: Move PCIe host data structure to plda-pcie.h
  PCI: microchip: Rename two setup functions
  PCI: microchip: Change the argument of plda_pcie_setup_iomems()
  PCI: microchip: Move the setup functions to pcie-plda-host.c
  PCI: plda: Add PLDA default event IRQ handler
  PCI: microchip: Rename interrupt related functions
  PCI: microchip: Add num_events field to struct plda_pcie_rp
  PCI: microchip: Add request_event_irq() callback function
  PCI: microchip: Add INTx and MSI event num to struct plda_event
  PCI: microchip: Add get_events() callback function
  PCI: microchip: Add event IRQ domain ops to struct plda_event
  PCI: microchip: Move IRQ functions to pcie-plda-host.c
  PCI: plda: Set plda_event_handler() to static
  PCI: plda: Add event interrupt codes and IRQ domain ops
  dt-bindings: PCI: Add StarFive JH7110 PCIe controller
  PCI: starfive: Add JH7110 PCIe controller
  riscv: dts: starfive: add PCIe dts configuration for JH7110

 .../bindings/pci/microchip,pcie-host.yaml     |  55 +-
 .../pci/plda,xpressrich3-axi-common.yaml      |  75 ++
 .../bindings/pci/starfive,jh7110-pcie.yaml    | 120 ++++
 MAINTAINERS                                   |  19 +-
 .../jh7110-starfive-visionfive-2.dtsi         |  64 ++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  86 +++
 drivers/pci/controller/Kconfig                |   9 +-
 drivers/pci/controller/Makefile               |   2 +-
 drivers/pci/controller/plda/Kconfig           |  30 +
 drivers/pci/controller/plda/Makefile          |   4 +
 .../{ => plda}/pcie-microchip-host.c          | 602 ++--------------
 drivers/pci/controller/plda/pcie-plda-host.c  | 657 ++++++++++++++++++
 drivers/pci/controller/plda/pcie-plda.h       | 268 +++++++
 drivers/pci/controller/plda/pcie-starfive.c   | 448 ++++++++++++
 14 files changed, 1835 insertions(+), 604 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/plda,xpressrich3-axi-common.yaml
 create mode 100644 Documentation/devicetree/bindings/pci/starfive,jh7110-pcie.yaml
 create mode 100644 drivers/pci/controller/plda/Kconfig
 create mode 100644 drivers/pci/controller/plda/Makefile
 rename drivers/pci/controller/{ => plda}/pcie-microchip-host.c (54%)
 create mode 100644 drivers/pci/controller/plda/pcie-plda-host.c
 create mode 100644 drivers/pci/controller/plda/pcie-plda.h
 create mode 100644 drivers/pci/controller/plda/pcie-starfive.c


base-commit: 94f6f0550c625fab1f373bb86a6669b45e9748b3

Comments

Conor Dooley Oct. 18, 2023, 10:40 a.m. UTC | #1
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

Thanks,
Conor.
Conor Dooley Oct. 18, 2023, 10:41 a.m. UTC | #2
On Wed, Oct 11, 2023 at 07:04:58PM +0800, Minda Chen wrote:
> Move the common data structures definition to head file for

nit: "to a header file so that these data structures"

> these data structure can be re-used.
> 
> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>

Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

Thanks,
Conor.

> ---
>  .../pci/controller/plda/pcie-microchip-host.c | 20 ------------------
>  drivers/pci/controller/plda/pcie-plda.h       | 21 +++++++++++++++++++
>  2 files changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/pci/controller/plda/pcie-microchip-host.c b/drivers/pci/controller/plda/pcie-microchip-host.c
> index 3dc4d4ca9d0c..261147a0a446 100644
> --- a/drivers/pci/controller/plda/pcie-microchip-host.c
> +++ b/drivers/pci/controller/plda/pcie-microchip-host.c
> @@ -21,9 +21,6 @@
>  #include "../../pci.h"
>  #include "pcie-plda.h"
>  
> -/* Number of MSI IRQs */
> -#define PLDA_MAX_NUM_MSI_IRQS			32
> -
>  /* PCIe Bridge Phy and Controller Phy offsets */
>  #define MC_PCIE1_BRIDGE_ADDR			0x00008000u
>  #define MC_PCIE1_CTRL_ADDR			0x0000a000u
> @@ -179,23 +176,6 @@ struct event_map {
>  	u32 event_bit;
>  };
>  
> -struct plda_msi {
> -	struct mutex lock;		/* Protect used bitmap */
> -	struct irq_domain *msi_domain;
> -	struct irq_domain *dev_domain;
> -	u32 num_vectors;
> -	u64 vector_phy;
> -	DECLARE_BITMAP(used, PLDA_MAX_NUM_MSI_IRQS);
> -};
> -
> -struct plda_pcie_rp {
> -	struct device *dev;
> -	struct irq_domain *intx_domain;
> -	struct irq_domain *event_domain;
> -	raw_spinlock_t lock;
> -	struct plda_msi msi;
> -	void __iomem *bridge_addr;
> -};
>  
>  struct mc_pcie {
>  	struct plda_pcie_rp plda;
> diff --git a/drivers/pci/controller/plda/pcie-plda.h b/drivers/pci/controller/plda/pcie-plda.h
> index 727fc54312c9..363fcbbaf6ec 100644
> --- a/drivers/pci/controller/plda/pcie-plda.h
> +++ b/drivers/pci/controller/plda/pcie-plda.h
> @@ -6,6 +6,9 @@
>  #ifndef _PCIE_PLDA_H
>  #define _PCIE_PLDA_H
>  
> +/* Number of MSI IRQs */
> +#define PLDA_MAX_NUM_MSI_IRQS			32
> +
>  /* PCIe Bridge Phy Regs */
>  #define PCIE_PCI_IRQ_DW0			0xa8
>  #define  MSIX_CAP_MASK				BIT(31)
> @@ -99,4 +102,22 @@
>  #define EVENT_PM_MSI_INT_SYS_ERR		12
>  #define NUM_PLDA_EVENTS				13
>  
> +struct plda_msi {
> +	struct mutex lock;		/* Protect used bitmap */
> +	struct irq_domain *msi_domain;
> +	struct irq_domain *dev_domain;
> +	u32 num_vectors;
> +	u64 vector_phy;
> +	DECLARE_BITMAP(used, PLDA_MAX_NUM_MSI_IRQS);
> +};
> +
> +struct plda_pcie_rp {
> +	struct device *dev;
> +	struct irq_domain *intx_domain;
> +	struct irq_domain *event_domain;
> +	raw_spinlock_t lock;
> +	struct plda_msi msi;
> +	void __iomem *bridge_addr;
> +};
> +
>  #endif
> -- 
> 2.17.1
>
Conor Dooley Oct. 18, 2023, 11:27 a.m. UTC | #3
On Wed, Oct 11, 2023 at 07:05:07PM +0800, Minda Chen wrote:


> For different interrupts to event num mapping function,
> add get_events() function pointer.
> For extenting event ops in the fucture, Add struct
> plda_event_ops data structure.

I still think these commit messages are a bit weak and should point out
the reasons why these are needed, rather than handwaving about future
users.
Otherwise,
Acked-by: Conor Dooley <conor.dooley@microchip.com>

Thanks,
Conor.

> 
> plda_handle_events() will call the get_events() callback
> function pointer directly. For the robustness of codes,
> add checking in plda_init_interrupts().
> 
> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
> ---
>  drivers/pci/controller/plda/pcie-microchip-host.c | 14 +++++++++++++-
>  drivers/pci/controller/plda/pcie-plda.h           |  8 ++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/plda/pcie-microchip-host.c b/drivers/pci/controller/plda/pcie-microchip-host.c
> index e99498b5b563..fca1520d56c9 100644
> --- a/drivers/pci/controller/plda/pcie-microchip-host.c
> +++ b/drivers/pci/controller/plda/pcie-microchip-host.c
> @@ -647,7 +647,7 @@ static void plda_handle_event(struct irq_desc *desc)
>  
>  	chained_irq_enter(chip, desc);
>  
> -	events = mc_get_events(port);
> +	events = port->event_ops->get_events(port);
>  
>  	for_each_set_bit(bit, &events, port->num_events)
>  		generic_handle_domain_irq(port->event_domain, bit);
> @@ -806,7 +806,12 @@ static int mc_request_event_irq(struct plda_pcie_rp *plda, int event_irq,
>  				0, event_cause[event].sym, plda);
>  }
>  
> +static const struct plda_event_ops mc_event_ops = {
> +	.get_events = mc_get_events,
> +};
> +
>  static const struct plda_event mc_event = {
> +	.event_ops              = &mc_event_ops,
>  	.request_event_irq      = mc_request_event_irq,
>  	.intx_event             = EVENT_LOCAL_PM_MSI_INT_INTX,
>  	.msi_event              = EVENT_LOCAL_PM_MSI_INT_MSI,
> @@ -920,6 +925,11 @@ static int plda_init_interrupts(struct platform_device *pdev,
>  	int i, intx_irq, msi_irq, event_irq;
>  	int ret;
>  
> +	if (!event->event_ops || !event->event_ops->get_events) {
> +		dev_err(dev, "no get events ops\n");
> +		return -EINVAL;
> +	}
> +
>  	ret = plda_pcie_init_irq_domains(port);
>  	if (ret) {
>  		dev_err(dev, "failed creating IRQ domains\n");
> @@ -930,6 +940,8 @@ static int plda_init_interrupts(struct platform_device *pdev,
>  	if (irq < 0)
>  		return -ENODEV;
>  
> +	port->event_ops = event->event_ops;
> +
>  	for (i = 0; i < port->num_events; i++) {
>  		event_irq = irq_create_mapping(port->event_domain, i);
>  		if (!event_irq) {
> diff --git a/drivers/pci/controller/plda/pcie-plda.h b/drivers/pci/controller/plda/pcie-plda.h
> index 5ad1b81c0086..6571a4befac9 100644
> --- a/drivers/pci/controller/plda/pcie-plda.h
> +++ b/drivers/pci/controller/plda/pcie-plda.h
> @@ -102,6 +102,12 @@
>  #define EVENT_PM_MSI_INT_SYS_ERR		12
>  #define NUM_PLDA_EVENTS				13
>  
> +struct plda_pcie_rp;
> +
> +struct plda_event_ops {
> +	u32 (*get_events)(struct plda_pcie_rp *pcie);
> +};
> +
>  struct plda_msi {
>  	struct mutex lock;		/* Protect used bitmap */
>  	struct irq_domain *msi_domain;
> @@ -117,11 +123,13 @@ struct plda_pcie_rp {
>  	struct irq_domain *event_domain;
>  	raw_spinlock_t lock;
>  	struct plda_msi msi;
> +	const struct plda_event_ops *event_ops;
>  	void __iomem *bridge_addr;
>  	int num_events;
>  };
>  
>  struct plda_event {
> +	const struct plda_event_ops *event_ops;
>  	int (*request_event_irq)(struct plda_pcie_rp *pcie,
>  				 int event_irq, int event);
>  	int intx_event;
> -- 
> 2.17.1
>