Hi Dave, On 07/12/20 9:27 pm, Jiang, Dave wrote: > > >> -----Original Message----- >> From: Kishon Vijay Abraham I <kishon@xxxxxx> >> Sent: Wednesday, November 11, 2020 8:36 AM >> To: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>; Jonathan Corbet >> <corbet@xxxxxxx>; Kishon Vijay Abraham I <kishon@xxxxxx>; Lorenzo >> Pieralisi <lorenzo.pieralisi@xxxxxxx>; Arnd Bergmann <arnd@xxxxxxxx>; >> Jon Mason <jdmason@xxxxxxxx>; Jiang, Dave <dave.jiang@xxxxxxxxx>; >> Allen Hubbe <allenbh@xxxxxxxxx>; Tom Joseph <tjoseph@xxxxxxxxxxx>; >> Rob Herring <robh@xxxxxxxxxx> >> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; linux- >> pci@xxxxxxxxxxxxxxx; linux-doc@xxxxxxxxxxxxxxx; linux- >> kernel@xxxxxxxxxxxxxxx; linux-ntb@xxxxxxxxxxxxxxxx >> Subject: [PATCH v8 15/18] NTB: Add support for EPF PCI-Express Non- >> Transparent Bridge >> >> Add support for EPF PCI-Express Non-Transparent Bridge (NTB) device. >> This driver is platform independent and could be used by any platform which >> have multiple PCIe endpoint instances configured using the pci-epf-ntb >> driver. The driver connnects to the standard NTB sub-system interface. The >> EPF NTB device has configurable number of memory windows (Max 4), >> configurable number of doorbell (Max 32), and configurable number of >> scratch-pad registers. >> >> Signed-off-by: Kishon Vijay Abraham I <kishon@xxxxxx> >> --- >> drivers/ntb/hw/Kconfig | 1 + >> drivers/ntb/hw/Makefile | 1 + >> drivers/ntb/hw/epf/Kconfig | 6 + >> drivers/ntb/hw/epf/Makefile | 1 + >> drivers/ntb/hw/epf/ntb_hw_epf.c | 755 >> ++++++++++++++++++++++++++++++++ >> 5 files changed, 764 insertions(+) >> create mode 100644 drivers/ntb/hw/epf/Kconfig create mode 100644 >> drivers/ntb/hw/epf/Makefile create mode 100644 >> drivers/ntb/hw/epf/ntb_hw_epf.c >> >> diff --git a/drivers/ntb/hw/Kconfig b/drivers/ntb/hw/Kconfig index >> e77c587060ff..c325be526b80 100644 >> --- a/drivers/ntb/hw/Kconfig >> +++ b/drivers/ntb/hw/Kconfig >> @@ -2,4 +2,5 @@ >> source "drivers/ntb/hw/amd/Kconfig" >> source "drivers/ntb/hw/idt/Kconfig" >> source "drivers/ntb/hw/intel/Kconfig" >> +source "drivers/ntb/hw/epf/Kconfig" >> source "drivers/ntb/hw/mscc/Kconfig" >> diff --git a/drivers/ntb/hw/Makefile b/drivers/ntb/hw/Makefile index >> 4714d6238845..223ca592b5f9 100644 >> --- a/drivers/ntb/hw/Makefile >> +++ b/drivers/ntb/hw/Makefile >> @@ -2,4 +2,5 @@ >> obj-$(CONFIG_NTB_AMD) += amd/ >> obj-$(CONFIG_NTB_IDT) += idt/ >> obj-$(CONFIG_NTB_INTEL) += intel/ >> +obj-$(CONFIG_NTB_EPF) += epf/ >> obj-$(CONFIG_NTB_SWITCHTEC) += mscc/ >> diff --git a/drivers/ntb/hw/epf/Kconfig b/drivers/ntb/hw/epf/Kconfig new >> file mode 100644 index 000000000000..6197d1aab344 >> --- /dev/null >> +++ b/drivers/ntb/hw/epf/Kconfig >> @@ -0,0 +1,6 @@ >> +config NTB_EPF >> + tristate "Generic EPF Non-Transparent Bridge support" >> + depends on m >> + help >> + This driver supports EPF NTB on configurable endpoint. >> + If unsure, say N. >> diff --git a/drivers/ntb/hw/epf/Makefile b/drivers/ntb/hw/epf/Makefile >> new file mode 100644 index 000000000000..2f560a422bc6 >> --- /dev/null >> +++ b/drivers/ntb/hw/epf/Makefile >> @@ -0,0 +1 @@ >> +obj-$(CONFIG_NTB_EPF) += ntb_hw_epf.o >> diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c >> b/drivers/ntb/hw/epf/ntb_hw_epf.c new file mode 100644 index >> 000000000000..3855bb0ecacd >> --- /dev/null >> +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c >> @@ -0,0 +1,755 @@ . . <snip> . . >> +static void ntb_epf_cleanup_isr(struct ntb_epf_dev *ndev) { >> + struct pci_dev *pdev = ndev->ntb.pdev; >> + struct device *dev = &pdev->dev; >> + int i; >> + >> + ntb_epf_send_command(ndev, CMD_TEARDOWN_DOORBELL, >> ndev->db_count + 1); >> + >> + for (i = 0; i < ndev->db_count + 1; i++) >> + devm_free_irq(dev, pci_irq_vector(pdev, i), ndev); > > This is called during shutdown. Does that defeats the purpose of using devm API? Yeah, here devm_* API is not required since we have to invoke free_irq() before invoking pci_free_irq_vectors(). Will change this to non devm API. Thank You, Kishon > > - Dave > >> + pci_free_irq_vectors(pdev); >> +} >> + >> +static int ntb_epf_pci_probe(struct pci_dev *pdev, >> + const struct pci_device_id *id) { >> + enum pci_barno peer_spad_reg_bar = BAR_1; >> + enum pci_barno ctrl_reg_bar = BAR_0; >> + enum pci_barno db_reg_bar = BAR_2; >> + struct device *dev = &pdev->dev; >> + struct ntb_epf_data *data; >> + struct ntb_epf_dev *ndev; >> + int ret; >> + >> + if (pci_is_bridge(pdev)) >> + return -ENODEV; >> + >> + ndev = devm_kzalloc(dev, sizeof(*ndev), GFP_KERNEL); >> + if (!ndev) >> + return -ENOMEM; >> + >> + data = (struct ntb_epf_data *)id->driver_data; >> + if (data) { >> + if (data->peer_spad_reg_bar) >> + peer_spad_reg_bar = data->peer_spad_reg_bar; >> + if (data->ctrl_reg_bar) >> + ctrl_reg_bar = data->ctrl_reg_bar; >> + if (data->db_reg_bar) >> + db_reg_bar = data->db_reg_bar; >> + } >> + >> + ndev->peer_spad_reg_bar = peer_spad_reg_bar; >> + ndev->ctrl_reg_bar = ctrl_reg_bar; >> + ndev->db_reg_bar = db_reg_bar; >> + ndev->dev = dev; >> + >> + ntb_epf_init_struct(ndev, pdev); >> + mutex_init(&ndev->cmd_lock); >> + >> + ret = ntb_epf_init_pci(ndev, pdev); >> + if (ret) { >> + dev_err(dev, "Failed to init PCI\n"); >> + return ret; >> + } >> + >> + ret = ntb_epf_init_dev(ndev); >> + if (ret) { >> + dev_err(dev, "Failed to init device\n"); >> + goto err_init_dev; >> + } >> + >> + ret = ntb_register_device(&ndev->ntb); >> + if (ret) { >> + dev_err(dev, "Failed to register NTB device\n"); >> + goto err_register_dev; >> + } >> + >> + return 0; >> + >> +err_register_dev: >> + ntb_epf_cleanup_isr(ndev); >> + >> +err_init_dev: >> + ntb_epf_deinit_pci(ndev); >> + >> + return ret; >> +} >> + >> +static void ntb_epf_pci_remove(struct pci_dev *pdev) { >> + struct ntb_epf_dev *ndev = pci_get_drvdata(pdev); >> + >> + ntb_unregister_device(&ndev->ntb); >> + ntb_epf_cleanup_isr(ndev); >> + ntb_epf_deinit_pci(ndev); >> + kfree(ndev); >> +} >> + >> +static const struct ntb_epf_data j721e_data = { >> + .ctrl_reg_bar = BAR_0, >> + .peer_spad_reg_bar = BAR_1, >> + .db_reg_bar = BAR_2, >> +}; >> + >> +static const struct pci_device_id ntb_epf_pci_tbl[] = { >> + { >> + PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_J721E), >> + .class = PCI_CLASS_MEMORY_RAM << 8, .class_mask = >> 0xffff00, >> + .driver_data = (kernel_ulong_t)&j721e_data, >> + }, >> + { }, >> +}; >> + >> +static struct pci_driver ntb_epf_pci_driver = { >> + .name = KBUILD_MODNAME, >> + .id_table = ntb_epf_pci_tbl, >> + .probe = ntb_epf_pci_probe, >> + .remove = ntb_epf_pci_remove, >> +}; >> +module_pci_driver(ntb_epf_pci_driver); >> + >> +MODULE_DESCRIPTION("PCI ENDPOINT NTB HOST DRIVER"); >> +MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@xxxxxx>"); >> +MODULE_LICENSE("GPL v2"); >> -- >> 2.17.1 >