Skip to contentSkip to conversation

Altera PCIe host controller driver with MSI support

PATCH Superseded Ley Foon Tan 3 participants 13 messages Sep 1, 2015 – Sep 14, 2015

Subsystems (4)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover Altera PCIe host controller driver with MSI support

This is the 6th version of patch set to add support for Altera PCIe host controller with MSI feature on Altera FPGA device families. This patchset mainly resolve comments from Marc Zyngier in v5 and minor fixes.

It is based on patch series from Marc Zyngier "Per-device MSI domain & platform MSI" [1] to get rid of struct msi_controller.

v5->v6 changes:
- altera-msi: remove irq_enable and irq_disable
- pcie-altera: change to PCI_VENDOR_ID_ALTERA for fixup
- pcie-altera: change to use switch case method
- update interrupt handling
- include: pci: add Altera PCI vendor ID

[1]: https://lkml.org/lkml/2015/7/23/172

History:
-------
[v1]: https://lkml.org/lkml/2015/7/28/395
[v2]: https://lkml.org/lkml/2015/7/31/267
[v3]: http://www.kernelhub.org/?msg=811940&p=2
[v4]: https://lkml.org/lkml/2015/8/17/141
[v5]: https://lkml.org/lkml/2015/8/25/238

Ley Foon Tan (6):
arm: add msi.h to Kbuild
pci: add Altera PCI vendor ID
pci:host: Add Altera PCIe host controller driver
pci: altera: Add Altera PCIe MSI driver
Documentation: dt-bindings: pci: altera pcie device tree binding
MAINTAINERS: Add Altera PCIe and MSI drivers maintainer

 .../devicetree/bindings/pci/altera-pcie-msi.txt    |  28 +
 .../devicetree/bindings/pci/altera-pcie.txt        |  49 ++
 MAINTAINERS                                        |  16 +
 arch/arm/include/asm/Kbuild                        |   1 +
 drivers/pci/host/Kconfig                           |  16 +
 drivers/pci/host/Makefile                          |   2 +
 drivers/pci/host/pcie-altera-msi.c                 | 311 +++++++++++
 drivers/pci/host/pcie-altera.c                     | 593 +++++++++++++++++++++
 include/linux/pci_ids.h                            |   2 +
 9 files changed, 1018 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/altera-pcie-msi.txt
 create mode 100644 Documentation/devicetree/bindings/pci/altera-pcie.txt
 create mode 100644 drivers/pci/host/pcie-altera-msi.c
 create mode 100644 drivers/pci/host/pcie-altera.c
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v6 1/6 arm: add msi.h to Kbuild

Include asm-generic/msi.h to support CONFIG_GENERIC_MSI_IRQ_DOMAIN. This to fix compilation error:
"include/linux/msi.h:123:21: fatal error: asm/msi.h:
No such file or directory"

---
 arch/arm/include/asm/Kbuild | 1 +
 1 file changed, 1 insertion(+)
arch/arm/include/asm/Kbuild +1 -0
index 30b3bc1..362b053 100644
@@ -15,6 +15,7 @@ generic-y += local64.h
 generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += msgbuf.h
+generic-y += msi.h
 generic-y += param.h
 generic-y += parport.h
 generic-y += poll.h
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v6 2/6 pci: add Altera PCI vendor ID

In reply to Ley Foon Tan
---
 include/linux/pci_ids.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/pci_ids.h +2 -0
index fcff8f8..9e62bcc 100644
@@ -1550,6 +1550,8 @@
 #define PCI_DEVICE_ID_SERVERWORKS_CSB6LPC 0x0227
 #define PCI_DEVICE_ID_SERVERWORKS_HT1100LD 0x0408
 
+#define PCI_VENDOR_ID_ALTERA		0x1172
+
 #define PCI_VENDOR_ID_SBE		0x1176
 #define PCI_DEVICE_ID_SBE_WANXL100	0x0301
 #define PCI_DEVICE_ID_SBE_WANXL200	0x0302
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH v6 3/6 pci:host: Add Altera PCIe host controller driver

In reply to Ley Foon Tan

This patch adds the Altera PCIe host controller driver.

---
 drivers/pci/host/Kconfig       |   8 +
 drivers/pci/host/Makefile      |   1 +
 drivers/pci/host/pcie-altera.c | 593 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 602 insertions(+)
 create mode 100644 drivers/pci/host/pcie-altera.c
drivers/pci/host/Kconfig +8 -0
index 675c2d1..43867d7 100644
@@ -145,4 +145,12 @@ config PCIE_IPROC_BCMA
 	  Say Y here if you want to use the Broadcom iProc PCIe controller
 	  through the BCMA bus interface
 
+config PCIE_ALTERA
+	tristate "Altera PCIe controller"
+	depends on ARCH_SOCFPGA
+	select PCI_DOMAINS
+	help
+	  Say Y here if you want to enable PCIe controller support for Altera
+	  SoCFPGA family of SoCs.
+
 endmenu
drivers/pci/host/Makefile +1 -0
index 140d66f..6954f76 100644
@@ -17,3 +17,4 @@ obj-$(CONFIG_PCI_VERSATILE) += pci-versatile.o
 obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
 obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o
 obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o
+obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o
drivers/pci/host/pcie-altera.c new file +593 -0

593 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#4 lore raw

Re: [PATCH v6 3/6] pci:host: Add Altera PCIe host controller driver

On Tue, Sep 01, 2015 at 11:30:05AM +0100, Ley Foon Tan wrote:

[...]

Quoted 9 lines
drivers/pci/host/pcie-altera.c new file +9 -0
+static void altera_pcie_retrain(struct pci_dev *dev)
+{
+       u16 linkcap, linkstat;
+
+       /*
+        * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but
+        * current speed is 2.5 GB/s.
+        */
+       pcie_capability_read_word(dev, PCI_EXP_LNKCAP, &linkcap);

drivers/pci/host/pcie-altera.c line 101

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+
+       if ((linkcap & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB)
+               return;
+
+       pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &linkstat);
+       if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB)
+               pcie_capability_set_word(dev, PCI_EXP_LNKCTL,
+                                        PCI_EXP_LNKCTL_RL);
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ALTERA, PCI_ANY_ID, altera_pcie_retrain);

This filtering is still arguable, since it unconditionally applies to all Altera PCI devices (I guess there are not any apart from this host controller).

Quoted 8 lines
drivers/pci/host/pcie-altera.c new file +8 -0
+
+static void altera_pcie_fixup_res(struct pci_dev *dev)
+{
+       /*
+        * Prevent enumeration of root port.
+        */
+       if (!dev->bus->parent && dev->devfn == 0) {
+               int i;

drivers/pci/host/pcie-altera.c line 119

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+
+               for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+                       dev->resource[i].start = 0;
+                       dev->resource[i].end   = 0;
+                       dev->resource[i].flags   = 0;
+               }
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ALTERA, PCI_ANY_ID,
+                        altera_pcie_fixup_res);

Ditto, it is a quirk of your host controller, not a quirk for all Altera PCI devices.

Quoted 29 lines
drivers/pci/host/pcie-altera.c new file +29 -0
+static inline void cra_writel(struct altera_pcie *pcie, u32 value, u32 reg)
+{
+       writel_relaxed(value, pcie->cra_base + reg);
+}
+
+static inline u32 cra_readl(struct altera_pcie *pcie, u32 reg)
+{
+       return readl_relaxed(pcie->cra_base + reg);
+}
+
+static void tlp_read_rx(struct altera_pcie *pcie,
+                       struct tlp_rp_regpair_t *tlp_rp_regdata)
+{
+       tlp_rp_regdata->ctrl = cra_readl(pcie, RP_RXCPL_STATUS);
+       tlp_rp_regdata->reg0 = cra_readl(pcie, RP_RXCPL_REG0);
+       tlp_rp_regdata->reg1 = cra_readl(pcie, RP_RXCPL_REG1);
+}
+
+static void tlp_write_tx(struct altera_pcie *pcie,
+                        struct tlp_rp_regpair_t *tlp_rp_regdata)
+{
+       cra_writel(pcie, tlp_rp_regdata->reg0, RP_TX_REG0);
+       cra_writel(pcie, tlp_rp_regdata->reg1, RP_TX_REG1);
+       cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
+}
+
+static bool altera_pcie_link_is_up(struct altera_pcie *pcie)
+{
+       return !!(cra_readl(pcie, RP_LTSSM) & LTSSM_L0);

drivers/pci/host/pcie-altera.c line 159

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+}
+
+static bool altera_pcie_valid_config(struct altera_pcie *pcie,
+                                    struct pci_bus *bus, int dev)
+{
+       /* If there is no link, then there is no device */
+       if (bus->number != pcie->root_bus_nr) {
+               if (!altera_pcie_link_is_up(pcie))
+                       return false;
+       }

Can you explain to pls me why you have to check this for every config transaction ? Isn't it something that can prevent probing the host controller altogether ?

drivers/pci/host/pcie-altera.c line 167

Quoted 8 lines
drivers/pci/host/pcie-altera.c new file +8 -0
+
+       /* access only one slot on each root port */
+       if (bus->number == pcie->root_bus_nr && dev > 0)
+               return false;
+
+       /*
+        * Do not read more than one device on the bus directly attached
+        * to RC.

You should also explain why.

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+        */
+       if (bus->primary == pcie->root_bus_nr && dev > 0)
+               return false;
+
+        return true;
+}
+
+static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
+{
+       u8 loop;

drivers/pci/host/pcie-altera.c line 187

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       for (loop = 0; loop < TLP_LOOP; loop++) {
+               tlp_read_rx(pcie, &tlp_rp_regdata);
+               if (tlp_rp_regdata.ctrl & RP_RXCPL_EOP) {
+                       if (value)
+                               *value = tlp_rp_regdata.reg0;
+                       return PCIBIOS_SUCCESSFUL;
+               }
+               udelay(5);

Could you comment please on the chosen udelay/TLP_LOOP values (ie how did you come up with them) ?

Quoted 31 lines
drivers/pci/host/pcie-altera.c new file +31 -0
+       }
+
+       return -ENOENT;
+}
+
+static void tlp_write_packet_unaligned(struct altera_pcie *pcie, u32 *headers,
+                                      u32 data)
+{
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       tlp_rp_regdata.reg0 = headers[0];
+       tlp_rp_regdata.reg1 = headers[1];
+       tlp_rp_regdata.ctrl = RP_TX_SOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+
+       tlp_rp_regdata.reg0 = headers[2];
+       tlp_rp_regdata.reg1 = data;
+       tlp_rp_regdata.ctrl = RP_TX_EOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+}
+
+static void tlp_write_packet_aligned(struct altera_pcie *pcie, u32 *headers,
+                                    u32 data)
+{
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       tlp_rp_regdata.reg0 = headers[0];
+       tlp_rp_regdata.reg1 = headers[1];
+       tlp_rp_regdata.ctrl = RP_TX_SOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+

drivers/pci/host/pcie-altera.c line 228

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       tlp_rp_regdata.reg0 = headers[2];
+       tlp_rp_regdata.reg1 = 0;
+       tlp_rp_regdata.ctrl = 0;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+
+       tlp_rp_regdata.reg0 = data;
+       tlp_rp_regdata.reg1 = 0;
+       tlp_rp_regdata.ctrl = RP_TX_EOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+}

I do not think you need two functions here, a flag can do.

Quoted 42 lines
drivers/pci/host/pcie-altera.c new file +42 -0
+static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
+                             int where, u32 *value)
+{
+       int ret;
+       u32 headers[TLP_HDR_SIZE];
+
+       if (bus == pcie->root_bus_nr)
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD0);
+       else
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD1);
+
+       headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+                                       TLP_READ_TAG);
+       headers[2] = TLP_CFG_DW2(bus, devfn, where);
+
+       tlp_write_packet_unaligned(pcie, headers, 0);
+
+       ret = tlp_read_packet(pcie, value);
+       if (ret != PCIBIOS_SUCCESSFUL)
+               *value = ~0UL;  /* return 0xFFFFFFFF if error */
+
+       return ret;
+}
+
+static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
+                              int where, u32 value)
+{
+       u32 headers[TLP_HDR_SIZE];
+       int ret;
+
+       if (bus == pcie->root_bus_nr)
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR0);
+       else
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR1);
+
+       headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+                                       TLP_WRITE_TAG);
+       headers[2] = TLP_CFG_DW2(bus, devfn, where);
+
+       /* check alignment to Qword */
+       if ((where & 0x7) == 0)
+               tlp_write_packet_aligned(pcie, headers, value);

drivers/pci/host/pcie-altera.c line 281

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       else
+               tlp_write_packet_unaligned(pcie, headers, value);
+
+       ret = tlp_read_packet(pcie, NULL);
+       if (ret != PCIBIOS_SUCCESSFUL)
+               return ret;
+
+       /* Keep an eye out for changes to the root bus number */
+       if ((bus == pcie->root_bus_nr) && (where == PCI_PRIMARY_BUS))
+               pcie->root_bus_nr = (u8)(value);

Essentially you are polling the rootport bridge programming here, correct ? I think you should describe this a bit better along with the assumptions you are making.

Quoted 125 lines
drivers/pci/host/pcie-altera.c new file +125 -0
+
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn,
+                               int where, int size, u32 *value)
+{
+       struct altera_pcie *pcie = bus->sysdata;
+       int ret;
+       u32 data;
+
+       if (!altera_pcie_valid_config(pcie, bus, PCI_SLOT(devfn))) {
+               *value = ~0UL;
+               return PCIBIOS_DEVICE_NOT_FOUND;
+       }
+
+       ret = tlp_cfg_dword_read(pcie, bus->number, devfn,
+                                (where & ~DWORD_MASK), &data);
+       if (ret != PCIBIOS_SUCCESSFUL)
+               return ret;
+
+       switch (size) {
+       case 1:
+               *value = (data >> (8 * (where & 0x3))) & 0xff;
+               break;
+       case 2:
+               *value = (data >> (8 * (where & 0x2))) & 0xffff;
+               break;
+       default:
+               *value = data;
+               break;
+       }
+
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn,
+                                int where, int size, u32 value)
+{
+       struct altera_pcie *pcie = bus->sysdata;
+       u32 data32;
+       u32 shift = 8 * (where & 3);
+       int ret;
+
+       if (!altera_pcie_valid_config(pcie, bus, PCI_SLOT(devfn)))
+               return PCIBIOS_DEVICE_NOT_FOUND;
+
+       /* write partial */
+       if (size != sizeof(u32)) {
+               ret = tlp_cfg_dword_read(pcie, bus->number, devfn,
+                                        where & ~DWORD_MASK, &data32);
+               if (ret)
+                       return ret;
+       }
+
+       switch (size) {
+       case 1:
+               data32 = (data32 & ~(0xff << shift)) |
+                               ((value & 0xff) << shift);
+               break;
+       case 2:
+               data32 = (data32 & ~(0xffff << shift)) |
+                               ((value & 0xffff) << shift);
+               break;
+       default:
+               data32 = value;
+               break;
+       }
+
+       return tlp_cfg_dword_write(pcie, bus->number, devfn,
+               (where & ~DWORD_MASK), data32);
+}
+
+static struct pci_ops altera_pcie_ops = {
+       .read = altera_pcie_cfg_read,
+       .write = altera_pcie_cfg_write,
+};
+
+static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
+                               irq_hw_number_t hwirq)
+{
+       irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
+       irq_set_chip_data(irq, domain->host_data);
+       set_irq_flags(irq, IRQF_VALID);
+
+       return 0;
+}
+
+static const struct irq_domain_ops intx_domain_ops = {
+       .map = altera_pcie_intx_map,
+};
+
+static void altera_pcie_isr(unsigned int irq, struct irq_desc *desc)
+{
+       struct irq_chip *chip = irq_desc_get_chip(desc);
+       struct altera_pcie *pcie;
+       unsigned long status;
+       u32 bit;
+       u32 virq;
+
+       chained_irq_enter(chip, desc);
+       pcie = irq_desc_get_handler_data(desc);
+
+       while ((status = cra_readl(pcie, P2A_INT_STATUS)
+               & P2A_INT_STS_ALL) != 0) {
+               for_each_set_bit(bit, &status, INTX_NUM) {
+                       /* clear interrupts */
+                       cra_writel(pcie, 1 << bit, P2A_INT_STATUS);
+
+                       virq = irq_find_mapping(pcie->irq_domain, bit + 1);
+                       if (virq)
+                               generic_handle_irq(virq);
+                       else
+                               dev_err(&pcie->pdev->dev, "unexpected IRQ\n");
+               }
+       }
+
+       chained_irq_exit(chip, desc);
+}
+
+static void altera_pcie_release_of_pci_ranges(struct altera_pcie *pcie)
+{
+       pci_free_resource_list(&pcie->resources);
+}
+

drivers/pci/host/pcie-altera.c line 416

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
+{
+       int err, res_valid = 0;
+       struct device *dev = &pcie->pdev->dev;
+       struct device_node *np = dev->of_node;
+       resource_size_t iobase;
+       struct resource_entry *win;
+
+       err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pcie->resources,
+                                              &iobase);

Nit: I do not see the point of passing iobase. You do not support IO space, if there is an IO address space in DT you want the function to barf, you do not want the function to initialize iobase silently.

So, you should pass iobase as NULL, if there is an IO space in DT:

of_pci_get_host_bridge_resources()

will barf and that's what you want to flag FW misconfigurations up.

[...]

Quoted 23 lines
drivers/pci/host/pcie-altera.c new file +23 -0
+static int altera_pcie_probe(struct platform_device *pdev)
+{
+       struct altera_pcie *pcie;
+       struct pci_bus *bus;
+       int ret;
+
+       pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL);
+       if (!pcie)
+               return -ENOMEM;
+
+       pcie->pdev = pdev;
+
+       ret = altera_pcie_parse_dt(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Parsing DT failed\n");
+               return ret;
+       }
+
+       INIT_LIST_HEAD(&pcie->resources);
+
+       ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed add resources\n");

drivers/pci/host/pcie-altera.c line 545

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+               return ret;
+       }
+
+       ret = altera_pcie_init_irq_domain(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed creating IRQ Domain\n");
+               return ret;
+       }
+
+       pcie->root_bus_nr = 0;

Nit: It is already 0.

drivers/pci/host/pcie-altera.c line 558

Quoted 13 lines
drivers/pci/host/pcie-altera.c new file +13 -0
+
+       /* clear all interrupts */
+       cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);
+       /* enable all interrupts */
+       cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
+
+       bus = pci_scan_root_bus(&pdev->dev, pcie->root_bus_nr, &altera_pcie_ops,
+                               pcie, &pcie->resources);
+       if (!bus)
+               return -ENOMEM;
+
+       pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
+       pci_assign_unassigned_bus_resources(bus);

I think you are missing a call to pcie_bus_configure_settings(), see drivers/pci/host/pci-host-generic.c

Thanks,
Lorenzo

Quoted 45 lines
drivers/pci/host/pcie-altera.c new file +35 -1
+       pci_bus_add_devices(bus);
 
+
+       platform_set_drvdata(pdev, pcie);
+       return ret;
+}
+
+static int __exit altera_pcie_remove(struct platform_device *pdev)
+{
+       struct altera_pcie *pcie = platform_get_drvdata(pdev);
+
+       altera_pcie_free_irq_domain(pcie);
+       platform_set_drvdata(pdev, NULL);
+       return 0;
+}
+
+static const struct of_device_id altera_pcie_of_match[] = {
+       { .compatible = "altr,pcie-root-port-1.0", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, altera_pcie_of_match);
+
+static struct platform_driver altera_pcie_driver = {
+       .probe          = altera_pcie_probe,
+       .remove         = altera_pcie_remove,
+       .driver = {
+               .name   = "altera-pcie",
+               .of_match_table = altera_pcie_of_match,
+       },
+};
+
+module_platform_driver(altera_pcie_driver);
+
+MODULE_AUTHOR("Ley Foon Tan <[email protected]>");
+MODULE_DESCRIPTION("Altera PCIe host controller driver");
+MODULE_LICENSE("GPL v2");
--

1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw

Re: [PATCH v6 3/6] pci:host: Add Altera PCIe host controller driver

Quoted 20 lines · Lorenzo Pieralisi

On Tue, Sep 01, 2015 at 11:30:05AM +0100, Ley Foon Tan wrote:

[...]

Quoted 15 lines
drivers/pci/host/pcie-altera.c new file +15 -0
+static void altera_pcie_retrain(struct pci_dev *dev)
+{
+       u16 linkcap, linkstat;
+
+       /*
+        * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but
+        * current speed is 2.5 GB/s.
+        */
+       pcie_capability_read_word(dev, PCI_EXP_LNKCAP, &linkcap);
+
+       if ((linkcap & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB)
+               return;
+
+       pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &linkstat);
+       if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB)
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 101

Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+               pcie_capability_set_word(dev, PCI_EXP_LNKCTL,
+                                        PCI_EXP_LNKCTL_RL);
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ALTERA, PCI_ANY_ID, altera_pcie_retrain);

This filtering is still arguable, since it unconditionally applies to all Altera PCI devices (I guess there are not any apart from this host controller).

This fixup is required for all Altera PCIe controller in all device families.

Quoted 14 lines
Quoted 14 lines
drivers/pci/host/pcie-altera.c new file +13 -0
+
+static void altera_pcie_fixup_res(struct pci_dev *dev)
+{
+       /*
+        * Prevent enumeration of root port.
+        */
+       if (!dev->bus->parent && dev->devfn == 0) {
+               int i;
+
+               for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+                       dev->resource[i].start = 0;
+                       dev->resource[i].end   = 0;
+                       dev->resource[i].flags   = 0;
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 119

Quoted 5 lines
drivers/pci/host/pcie-altera.c new file +5 -0
+               }
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ALTERA, PCI_ANY_ID,
+                        altera_pcie_fixup_res);

Ditto, it is a quirk of your host controller, not a quirk for all Altera PCI devices.

Same here.

Quoted 36 lines
Quoted 36 lines
drivers/pci/host/pcie-altera.c new file +35 -0
+static inline void cra_writel(struct altera_pcie *pcie, u32 value, u32 reg)
+{
+       writel_relaxed(value, pcie->cra_base + reg);
+}
+
+static inline u32 cra_readl(struct altera_pcie *pcie, u32 reg)
+{
+       return readl_relaxed(pcie->cra_base + reg);
+}
+
+static void tlp_read_rx(struct altera_pcie *pcie,
+                       struct tlp_rp_regpair_t *tlp_rp_regdata)
+{
+       tlp_rp_regdata->ctrl = cra_readl(pcie, RP_RXCPL_STATUS);
+       tlp_rp_regdata->reg0 = cra_readl(pcie, RP_RXCPL_REG0);
+       tlp_rp_regdata->reg1 = cra_readl(pcie, RP_RXCPL_REG1);
+}
+
+static void tlp_write_tx(struct altera_pcie *pcie,
+                        struct tlp_rp_regpair_t *tlp_rp_regdata)
+{
+       cra_writel(pcie, tlp_rp_regdata->reg0, RP_TX_REG0);
+       cra_writel(pcie, tlp_rp_regdata->reg1, RP_TX_REG1);
+       cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
+}
+
+static bool altera_pcie_link_is_up(struct altera_pcie *pcie)
+{
+       return !!(cra_readl(pcie, RP_LTSSM) & LTSSM_L0);
+}
+
+static bool altera_pcie_valid_config(struct altera_pcie *pcie,
+                                    struct pci_bus *bus, int dev)
+{
+       /* If there is no link, then there is no device */
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 159

Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+       if (bus->number != pcie->root_bus_nr) {
+               if (!altera_pcie_link_is_up(pcie))
+                       return false;
+       }

Can you explain to pls me why you have to check this for every config transaction ? Isn't it something that can prevent probing the host controller altogether ?

In our PCIe hardware spec, it stated that software should check the link status before issuing a configuration request to downstream ports.
BTW, other pci controllers have similar implementation as well, eg: dw pci, mvebu pci.

Quoted 11 lines

drivers/pci/host/pcie-altera.c line 167

Quoted 9 lines
drivers/pci/host/pcie-altera.c new file +8 -0
+
+       /* access only one slot on each root port */
+       if (bus->number == pcie->root_bus_nr && dev > 0)
+               return false;
+
+       /*
+        * Do not read more than one device on the bus directly attached
+        * to RC.

You should also explain why.

Okay.

Quoted 16 lines
Quoted 16 lines
drivers/pci/host/pcie-altera.c new file +15 -0
+        */
+       if (bus->primary == pcie->root_bus_nr && dev > 0)
+               return false;
+
+        return true;
+}
+
+static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
+{
+       u8 loop;
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       for (loop = 0; loop < TLP_LOOP; loop++) {
+               tlp_read_rx(pcie, &tlp_rp_regdata);
+               if (tlp_rp_regdata.ctrl & RP_RXCPL_EOP) {
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 187

Quoted 5 lines
drivers/pci/host/pcie-altera.c new file +5 -0
+                       if (value)
+                               *value = tlp_rp_regdata.reg0;
+                       return PCIBIOS_SUCCESSFUL;
+               }
+               udelay(5);

Could you comment please on the chosen udelay/TLP_LOOP values (ie how did you come up with them) ?

For udelay value, we just want to have small delay between each read. For TLP_LOOP value, minimum 2 loops to read tlp headers and 1 loop to read data payload. So, we choose to poll 10 loops for maximum.

Quoted 36 lines
Quoted 36 lines
drivers/pci/host/pcie-altera.c new file +35 -0
+       }
+
+       return -ENOENT;
+}
+
+static void tlp_write_packet_unaligned(struct altera_pcie *pcie, u32 *headers,
+                                      u32 data)
+{
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       tlp_rp_regdata.reg0 = headers[0];
+       tlp_rp_regdata.reg1 = headers[1];
+       tlp_rp_regdata.ctrl = RP_TX_SOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+
+       tlp_rp_regdata.reg0 = headers[2];
+       tlp_rp_regdata.reg1 = data;
+       tlp_rp_regdata.ctrl = RP_TX_EOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+}
+
+static void tlp_write_packet_aligned(struct altera_pcie *pcie, u32 *headers,
+                                    u32 data)
+{
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       tlp_rp_regdata.reg0 = headers[0];
+       tlp_rp_regdata.reg1 = headers[1];
+       tlp_rp_regdata.ctrl = RP_TX_SOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+
+       tlp_rp_regdata.reg0 = headers[2];
+       tlp_rp_regdata.reg1 = 0;
+       tlp_rp_regdata.ctrl = 0;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 228

Quoted 6 lines
drivers/pci/host/pcie-altera.c new file +6 -0
+
+       tlp_rp_regdata.reg0 = data;
+       tlp_rp_regdata.reg1 = 0;
+       tlp_rp_regdata.ctrl = RP_TX_EOP;
+       tlp_write_tx(pcie, &tlp_rp_regdata);
+}

I do not think you need two functions here, a flag can do.

Okay, will merge these 2 functions.

Quoted 49 lines
Quoted 49 lines
drivers/pci/host/pcie-altera.c new file +48 -0
+static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
+                             int where, u32 *value)
+{
+       int ret;
+       u32 headers[TLP_HDR_SIZE];
+
+       if (bus == pcie->root_bus_nr)
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD0);
+       else
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD1);
+
+       headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+                                       TLP_READ_TAG);
+       headers[2] = TLP_CFG_DW2(bus, devfn, where);
+
+       tlp_write_packet_unaligned(pcie, headers, 0);
+
+       ret = tlp_read_packet(pcie, value);
+       if (ret != PCIBIOS_SUCCESSFUL)
+               *value = ~0UL;  /* return 0xFFFFFFFF if error */
+
+       return ret;
+}
+
+static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
+                              int where, u32 value)
+{
+       u32 headers[TLP_HDR_SIZE];
+       int ret;
+
+       if (bus == pcie->root_bus_nr)
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR0);
+       else
+               headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR1);
+
+       headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+                                       TLP_WRITE_TAG);
+       headers[2] = TLP_CFG_DW2(bus, devfn, where);
+
+       /* check alignment to Qword */
+       if ((where & 0x7) == 0)
+               tlp_write_packet_aligned(pcie, headers, value);
+       else
+               tlp_write_packet_unaligned(pcie, headers, value);
+
+       ret = tlp_read_packet(pcie, NULL);
+       if (ret != PCIBIOS_SUCCESSFUL)
+               return ret;
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 281

Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+
+       /* Keep an eye out for changes to the root bus number */
+       if ((bus == pcie->root_bus_nr) && (where == PCI_PRIMARY_BUS))
+               pcie->root_bus_nr = (u8)(value);

Essentially you are polling the rootport bridge programming here, correct ? I think you should describe this a bit better along with the assumptions you are making.

Yes, you are right. Will update description here.

Quoted 1 line

[...]

Quoted 21 lines
Quoted 6 lines
drivers/pci/host/pcie-altera.c new file +6 -0
+
+static void altera_pcie_release_of_pci_ranges(struct altera_pcie *pcie)
+{
+       pci_free_resource_list(&pcie->resources);
+}
+

drivers/pci/host/pcie-altera.c line 416

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
+{
+       int err, res_valid = 0;
+       struct device *dev = &pcie->pdev->dev;
+       struct device_node *np = dev->of_node;
+       resource_size_t iobase;
+       struct resource_entry *win;
+
+       err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pcie->resources,
+                                              &iobase);

Nit: I do not see the point of passing iobase. You do not support IO space, if there is an IO address space in DT you want the function to barf, you do not want the function to initialize iobase silently.

Quoted 5 lines

So, you should pass iobase as NULL, if there is an IO space in DT:

of_pci_get_host_bridge_resources()

will barf and that's what you want to flag FW misconfigurations up.

Okay, will pass in NULL for iobase.

Quoted 30 lines

[...]

Quoted 27 lines
drivers/pci/host/pcie-altera.c new file +27 -0
+static int altera_pcie_probe(struct platform_device *pdev)
+{
+       struct altera_pcie *pcie;
+       struct pci_bus *bus;
+       int ret;
+
+       pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL);
+       if (!pcie)
+               return -ENOMEM;
+
+       pcie->pdev = pdev;
+
+       ret = altera_pcie_parse_dt(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Parsing DT failed\n");
+               return ret;
+       }
+
+       INIT_LIST_HEAD(&pcie->resources);
+
+       ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed add resources\n");
+               return ret;
+       }
+
+       ret = altera_pcie_init_irq_domain(pcie);
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 545

Quoted 6 lines
drivers/pci/host/pcie-altera.c new file +6 -0
+       if (ret) {
+               dev_err(&pdev->dev, "Failed creating IRQ Domain\n");
+               return ret;
+       }
+
+       pcie->root_bus_nr = 0;

Nit: It is already 0.

Okay. Will remove it.

Quoted 17 lines
Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +3 -0
+
+       /* clear all interrupts */
+       cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);

drivers/pci/host/pcie-altera.c line 558

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       /* enable all interrupts */
+       cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
+
+       bus = pci_scan_root_bus(&pdev->dev, pcie->root_bus_nr, &altera_pcie_ops,
+                               pcie, &pcie->resources);
+       if (!bus)
+               return -ENOMEM;
+
+       pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
+       pci_assign_unassigned_bus_resources(bus);

I think you are missing a call to pcie_bus_configure_settings(), see drivers/pci/host/pci-host-generic.c

Other pci controller drivers like xgene and iproc don't call to this function, but it call in arch/arm/kernel/bios32.c:pci_common_init_dev().
Do we really need this?

Thanks for reviewing.

Regards
Ley Foon

#6 lore raw

Re: [PATCH v6 3/6] pci:host: Add Altera PCIe host controller driver

Quoted 2 lines · Ley Foon Tan

On Wed, Sep 2, 2015 at 12:33 AM, Lorenzo Pieralisi <[email protected]> wrote:

[...]

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+static bool altera_pcie_valid_config(struct altera_pcie *pcie,
+                                    struct pci_bus *bus, int dev)
+{
+       /* If there is no link, then there is no device */
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 159

Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+       if (bus->number != pcie->root_bus_nr) {
+               if (!altera_pcie_link_is_up(pcie))
+                       return false;
+       }

Can you explain to pls me why you have to check this for every config transaction ? Isn't it something that can prevent probing the host controller altogether ?

Quoted 5 lines

In our PCIe hardware spec, it stated that software should check the link status before issuing a configuration request to downstream ports.
BTW, other pci controllers have similar implementation as well, eg: dw pci, mvebu pci.

Understood, thanks.

[...]

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/host/pcie-altera.c new file +8 -0
+static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
+{
+       u8 loop;
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       for (loop = 0; loop < TLP_LOOP; loop++) {
+               tlp_read_rx(pcie, &tlp_rp_regdata);
+               if (tlp_rp_regdata.ctrl & RP_RXCPL_EOP) {
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 187

Quoted 5 lines
drivers/pci/host/pcie-altera.c new file +5 -0
+                       if (value)
+                               *value = tlp_rp_regdata.reg0;
+                       return PCIBIOS_SUCCESSFUL;
+               }
+               udelay(5);

Could you comment please on the chosen udelay/TLP_LOOP values (ie how did you come up with them) ?

Quoted 1 line

For udelay value, we just want to have small delay between each read.

I would explain how you chose the value, in particular if it can affect next generation hosts sharing the same driver.

Quoted 2 lines

For TLP_LOOP value, minimum 2 loops to read tlp headers and 1 loop to read data payload. So, we choose to poll 10 loops for maximum.

Add it to a comment.

[...]

Quoted 53 lines
Quoted 27 lines
Quoted 27 lines
drivers/pci/host/pcie-altera.c new file +27 -0
+static int altera_pcie_probe(struct platform_device *pdev)
+{
+       struct altera_pcie *pcie;
+       struct pci_bus *bus;
+       int ret;
+
+       pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL);
+       if (!pcie)
+               return -ENOMEM;
+
+       pcie->pdev = pdev;
+
+       ret = altera_pcie_parse_dt(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Parsing DT failed\n");
+               return ret;
+       }
+
+       INIT_LIST_HEAD(&pcie->resources);
+
+       ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed add resources\n");
+               return ret;
+       }
+
+       ret = altera_pcie_init_irq_domain(pcie);
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 545

Quoted 6 lines
drivers/pci/host/pcie-altera.c new file +6 -0
+       if (ret) {
+               dev_err(&pdev->dev, "Failed creating IRQ Domain\n");
+               return ret;
+       }
+
+       pcie->root_bus_nr = 0;

Nit: It is already 0.

Okay. Will remove it.

Quoted 17 lines
Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +3 -0
+
+       /* clear all interrupts */
+       cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);

drivers/pci/host/pcie-altera.c line 558

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       /* enable all interrupts */
+       cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
+
+       bus = pci_scan_root_bus(&pdev->dev, pcie->root_bus_nr, &altera_pcie_ops,
+                               pcie, &pcie->resources);
+       if (!bus)
+               return -ENOMEM;
+
+       pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
+       pci_assign_unassigned_bus_resources(bus);

I think you are missing a call to pcie_bus_configure_settings(), see drivers/pci/host/pci-host-generic.c

Quoted 4 lines

Other pci controller drivers like xgene and iproc don't call to this function, but it call in arch/arm/kernel/bios32.c:pci_common_init_dev().
Do we really need this?

It is there to provide a way to configure the system MPS, through command line parameters, it is always a good idea to have it and it should be part of your driver so that you can tune it in case the MPS is misconfigured or you want to apply a specific configuration for a given system.

Have a look at pcie_bus_config and how it is used in pcie_bus_configure_settings(), that would clarify further.

Thanks,
Lorenzo

#7 lore raw

Re: [PATCH v6 3/6] pci:host: Add Altera PCIe host controller driver

Quoted 44 lines · Lorenzo Pieralisi
Quoted 2 lines · Ley Foon Tan

On Wed, Sep 2, 2015 at 12:33 AM, Lorenzo Pieralisi <[email protected]> wrote:

[...]

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+static bool altera_pcie_valid_config(struct altera_pcie *pcie,
+                                    struct pci_bus *bus, int dev)
+{
+       /* If there is no link, then there is no device */
Quoted 8 lines

drivers/pci/host/pcie-altera.c line 159

Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +4 -0
+       if (bus->number != pcie->root_bus_nr) {
+               if (!altera_pcie_link_is_up(pcie))
+                       return false;
+       }

Can you explain to pls me why you have to check this for every config transaction ? Isn't it something that can prevent probing the host controller altogether ?

Quoted 5 lines

In our PCIe hardware spec, it stated that software should check the link status before issuing a configuration request to downstream ports.
BTW, other pci controllers have similar implementation as well, eg: dw pci, mvebu pci.

Understood, thanks.

[...]

Quoted 16 lines
Quoted 16 lines

drivers/pci/host/pcie-altera.c line 187

Quoted 13 lines
drivers/pci/host/pcie-altera.c new file +13 -0
+static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
+{
+       u8 loop;
+       struct tlp_rp_regpair_t tlp_rp_regdata;
+
+       for (loop = 0; loop < TLP_LOOP; loop++) {
+               tlp_read_rx(pcie, &tlp_rp_regdata);
+               if (tlp_rp_regdata.ctrl & RP_RXCPL_EOP) {
+                       if (value)
+                               *value = tlp_rp_regdata.reg0;
+                       return PCIBIOS_SUCCESSFUL;
+               }
+               udelay(5);

Could you comment please on the chosen udelay/TLP_LOOP values (ie how did you come up with them) ?

Quoted 4 lines
Quoted 1 line

For udelay value, we just want to have small delay between each read.

I would explain how you chose the value, in particular if it can affect next generation hosts sharing the same driver.

Actually, we don't have any calculation to choose the value. Just want to give small relaxation between each read.
It is request from Marc in previous review.

Quoted 5 lines
Quoted 3 lines

For TLP_LOOP value, minimum 2 loops to read tlp headers and 1 loop to read data payload. So, we choose to poll 10 loops for maximum.

Add it to a comment.

Okay.

Quoted 1 line

[...]

Quoted 22 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/pci/host/pcie-altera.c new file +3 -0
+
+       /* clear all interrupts */
+       cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);

drivers/pci/host/pcie-altera.c line 558

Quoted 10 lines
drivers/pci/host/pcie-altera.c new file +10 -0
+       /* enable all interrupts */
+       cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
+
+       bus = pci_scan_root_bus(&pdev->dev, pcie->root_bus_nr, &altera_pcie_ops,
+                               pcie, &pcie->resources);
+       if (!bus)
+               return -ENOMEM;
+
+       pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
+       pci_assign_unassigned_bus_resources(bus);

I think you are missing a call to pcie_bus_configure_settings(), see drivers/pci/host/pci-host-generic.c

Quoted 4 lines

Other pci controller drivers like xgene and iproc don't call to this function, but it call in arch/arm/kernel/bios32.c:pci_common_init_dev().
Do we really need this?

Quoted 8 lines

It is there to provide a way to configure the system MPS, through command line parameters, it is always a good idea to have it and it should be part of your driver so that you can tune it in case the MPS is misconfigured or you want to apply a specific configuration for a given system.

Have a look at pcie_bus_config and how it is used in pcie_bus_configure_settings(), that would clarify further.

Thanks for explanation. I will add it.

Thanks.

Regards
Ley Foon

#8 lore raw

PATCH v6 4/6 pci: altera: Add Altera PCIe MSI driver

In reply to Ley Foon Tan

This patch adds Altera PCIe MSI driver. This soft IP supports configurable number of vectors, which is a dts parameter.

---
 drivers/pci/host/Kconfig           |   8 +
 drivers/pci/host/Makefile          |   1 +
 drivers/pci/host/pcie-altera-msi.c | 311 +++++++++++++++++++++++++++++++++++++
 3 files changed, 320 insertions(+)
 create mode 100644 drivers/pci/host/pcie-altera-msi.c
drivers/pci/host/Kconfig +8 -0
index 43867d7..b50df1e 100644
@@ -153,4 +153,12 @@ config PCIE_ALTERA
 	  Say Y here if you want to enable PCIe controller support for Altera
 	  SoCFPGA family of SoCs.
 
+config PCIE_ALTERA_MSI
+	bool "Altera PCIe MSI feature"
+	depends on PCI_MSI
+	select PCI_MSI_IRQ_DOMAIN
+	help
+	  Say Y here if you want PCIe MSI support for the Altera SocFPGA SoC.
+	  This MSI driver supports Altera MSI to GIC controller IP.
+
 endmenu
drivers/pci/host/Makefile +1 -0
index 6954f76..6c4913d 100644
@@ -18,3 +18,4 @@ obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
 obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o
 obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o
 obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o
+obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o
drivers/pci/host/pcie-altera-msi.c new file +311 -0

311 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#9 lore raw

PATCH v6 5/6 Documentation: dt-bindings: pci: altera pcie device tree binding

In reply to Ley Foon Tan

This patch adds the bindings for Altera PCIe host controller driver and Altera PCIe MSI driver.

---
 .../devicetree/bindings/pci/altera-pcie-msi.txt    | 28 +++++++++++++
 .../devicetree/bindings/pci/altera-pcie.txt        | 49 ++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/altera-pcie-msi.txt
 create mode 100644 Documentation/devicetree/bindings/pci/altera-pcie.txt
Documentation/devicetree/bindings/pci/altera-pcie-msi.txt new file +28 -0
new file mode 100644
index 0000000..53ad2388
@@ -0,0 +1,28 @@
+* Altera PCIe MSI controller
+
+Required properties:
+- compatible:	should contain "altr,msi-1.0"
+- reg:		specifies the physical base address of the controller and
+		the length of the memory mapped region.
+- reg-names:	must include the following entries:
+		"csr": CSR registers
+		"vector_slave": vectors slave port region
+- interrupt-parent:	interrupt source phandle.
+- interrupts:	specifies the interrupt source of the parent interrupt
+		controller. The format of the interrupt specifier depends on the
+		parent interrupt controller.
+- num-vectors:	number of vectors, range 1 to 32.
+- msi-controller:	indicates that this is MSI controller node
+
+
+Example
+msi0: msi at 0xFF200000 {
+	compatible = "altr,msi-1.0";
+	reg = <0xFF200000 0x00000010
+		0xFF200010 0x00000080>;
+	reg-names = "csr", "vector_slave";
+	interrupt-parent = <&hps_0_arm_gic_0>;
+	interrupts = <0 42 4>;
+	msi-controller = <1>;
+	num-vectors = <32>;
+};
Documentation/devicetree/bindings/pci/altera-pcie.txt new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#10 lore raw

PATCH v6 6/6 MAINTAINERS: Add Altera PCIe and MSI drivers maintainer

In reply to Ley Foon Tan
---
 MAINTAINERS | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
MAINTAINERS +16 -0
index b60e2b2..d70fe18 100644
@@ -7780,6 +7780,14 @@ F:	include/linux/pci*
 F:	arch/x86/pci/
 F:	arch/x86/kernel/quirks.c
 
+PCI DRIVER FOR ALTERA PCIE IP
+M:	Ley Foon Tan <[email protected]>
+L:	rfi at lists.rocketboards.org (moderated for non-subscribers)
+L:	linux-pci at vger.kernel.org
+S:	Supported
+F:	Documentation/devicetree/bindings/pci/altera-pcie.txt
+F:	drivers/pci/host/pcie-altera.c
+
 PCI DRIVER FOR ARM VERSATILE PLATFORM
 M:	Rob Herring <[email protected]>
 L:	linux-pci at vger.kernel.org
@@ -7881,6 +7889,14 @@ L:	linux-pci at vger.kernel.org
 S:	Maintained
 F:	drivers/pci/host/*spear*
 
+PCI MSI DRIVER FOR ALTERA MSI IP
+M:	Ley Foon Tan <[email protected]>
+L:	rfi at lists.rocketboards.org (moderated for non-subscribers)
+L:	linux-pci at vger.kernel.org
+S:	Supported
+F:	Documentation/devicetree/bindings/pci/altera-pcie-msi.txt
+F:	drivers/pci/host/pcie-altera-msi.c
+
 PCI MSI DRIVER FOR APPLIEDMICRO XGENE
 M:	Duc Dang <[email protected]>
 L:	linux-pci at vger.kernel.org
Signature · 1 line
1.8.2.1
#11 lore raw
In reply to Ley Foon Tan
Quoted 3 lines · Ley Foon Tan

This is the 6th version of patch set to add support for Altera PCIe host controller with MSI feature on Altera FPGA device families. This patchset mainly resolve comments from Marc Zyngier in v5 and minor fixes.

The merge window has just started, and I'm not going to go through another review at that stage - too many things in flight.

Please ping me again once 4.3-rc1 is out.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#12 lore raw
Quoted 10 lines · Marc Zyngier
Quoted 3 lines · Ley Foon Tan

This is the 6th version of patch set to add support for Altera PCIe host controller with MSI feature on Altera FPGA device families. This patchset mainly resolve comments from Marc Zyngier in v5 and minor fixes.

The merge window has just started, and I'm not going to go through another review at that stage - too many things in flight.

Please ping me again once 4.3-rc1 is out.

Hi Marc

Do you have further comment on this patchset?
Thanks.

Regards
Ley Foon