From: Tianfei Zhang Date: Thu, 14 Nov 2019 09:03:07 +0000 (+0800) Subject: raw/ifpga: introduce IRQ functions X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e0a1aafe2af9;p=dpdk.git raw/ifpga: introduce IRQ functions Introducing new register and unregister API for ifpga interrupt. 1. register FME and AFU interrupt ifpga_register_msix_irq() 2. unregister FME and AFU interrupt ifpga_unregister_msix_irq() On PAC N3000 card, there is one PCIe MSIX interrupt for FME management, like the error report, thermal management, we use this interrupt in ifpga_rawdev device driver. on the other hand, there are about 4 PCIe MSIX interrupts are reserved for AFU which end-user can use those interrupts in their AFU logic design. End-user can use those APIs to register interrupt handler in their AFU drivers. Signed-off-by: Tianfei Zhang Signed-off-by: Andy Pei --- diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 49bfaac2ad..b8701e155b 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -79,6 +79,10 @@ static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM]; static int ifpga_monitor_start; static pthread_t ifpga_monitor_start_thread; +#define IFPGA_MAX_IRQ 12 +/* 0 for FME interrupt, others are reserved for AFU irq */ +static struct rte_intr_handle ifpga_irq_handle[IFPGA_MAX_IRQ]; + static struct ifpga_rawdev * ifpga_rawdev_allocate(struct rte_rawdev *rawdev); static int set_surprise_link_check_aer( @@ -1328,52 +1332,89 @@ fme_interrupt_handler(void *param) fme_err_handle_catfatal_error(mgr); } -static struct rte_intr_handle fme_intr_handle; +int +ifpga_unregister_msix_irq(enum ifpga_irq_type type, + int vec_start, rte_intr_callback_fn handler, void *arg) +{ + struct rte_intr_handle intr_handle; + + if (type == IFPGA_FME_IRQ) + intr_handle = ifpga_irq_handle[0]; + else if (type == IFPGA_AFU_IRQ) + intr_handle = ifpga_irq_handle[vec_start + 1]; -static int ifpga_register_fme_interrupt(struct opae_manager *mgr) + rte_intr_efd_disable(&intr_handle); + + return rte_intr_callback_unregister(&intr_handle, + handler, arg); +} + +int +ifpga_register_msix_irq(struct rte_rawdev *dev, int port_id, + enum ifpga_irq_type type, int vec_start, int count, + rte_intr_callback_fn handler, const char *name, + void *arg) { int ret; - struct fpga_fme_err_irq_set err_irq_set; + struct rte_intr_handle intr_handle; + struct opae_adapter *adapter; + struct opae_manager *mgr; + struct opae_accelerator *acc; - fme_intr_handle.type = RTE_INTR_HANDLE_VFIO_MSIX; + adapter = ifpga_rawdev_get_priv(dev); + if (!adapter) + return -ENODEV; - ret = rte_intr_efd_enable(&fme_intr_handle, 1); - if (ret) - return -EINVAL; + mgr = opae_adapter_get_mgr(adapter); + if (!mgr) + return -ENODEV; - fme_intr_handle.fd = fme_intr_handle.efds[0]; + if (type == IFPGA_FME_IRQ) { + intr_handle = ifpga_irq_handle[0]; + count = 1; + } else if (type == IFPGA_AFU_IRQ) + intr_handle = ifpga_irq_handle[vec_start + 1]; - IFPGA_RAWDEV_PMD_DEBUG("vfio_dev_fd=%d, efd=%d, fd=%d\n", - fme_intr_handle.vfio_dev_fd, - fme_intr_handle.efds[0], fme_intr_handle.fd); + intr_handle.type = RTE_INTR_HANDLE_VFIO_MSIX; - err_irq_set.evtfd = fme_intr_handle.efds[0]; - ret = opae_manager_ifpga_set_err_irq(mgr, &err_irq_set); + ret = rte_intr_efd_enable(&intr_handle, count); if (ret) - return -EINVAL; + return -ENODEV; + + intr_handle.fd = intr_handle.efds[0]; + + IFPGA_RAWDEV_PMD_DEBUG("register %s irq, vfio_fd=%d, fd=%d\n", + name, intr_handle.vfio_dev_fd, + intr_handle.fd); + + if (type == IFPGA_FME_IRQ) { + struct fpga_fme_err_irq_set err_irq_set; + err_irq_set.evtfd = intr_handle.efds[0]; + + ret = opae_manager_ifpga_set_err_irq(mgr, &err_irq_set); + if (ret) + return -EINVAL; + } else if (type == IFPGA_AFU_IRQ) { + acc = opae_adapter_get_acc(adapter, port_id); + if (!acc) + return -EINVAL; - /* register FME interrupt using DPDK API */ - ret = rte_intr_callback_register(&fme_intr_handle, - fme_interrupt_handler, - (void *)mgr); + ret = opae_acc_set_irq(acc, vec_start, count, intr_handle.efds); + if (ret) + return -EINVAL; + } + + /* register interrupt handler using DPDK API */ + ret = rte_intr_callback_register(&intr_handle, + handler, (void *)arg); if (ret) return -EINVAL; - IFPGA_RAWDEV_PMD_INFO("success register fme interrupt\n"); + IFPGA_RAWDEV_PMD_INFO("success register %s interrupt\n", name); return 0; } -static int -ifpga_unregister_fme_interrupt(struct opae_manager *mgr) -{ - rte_intr_efd_disable(&fme_intr_handle); - - return rte_intr_callback_unregister(&fme_intr_handle, - fme_interrupt_handler, - (void *)mgr); -} - static int ifpga_rawdev_create(struct rte_pci_device *pci_dev, int socket_id) @@ -1463,7 +1504,8 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, IFPGA_RAWDEV_PMD_INFO("this is a PF function"); } - ret = ifpga_register_fme_interrupt(mgr); + ret = ifpga_register_msix_irq(rawdev, 0, IFPGA_FME_IRQ, 0, 0, + fme_interrupt_handler, "fme_irq", mgr); if (ret) goto free_adapter_data; @@ -1515,7 +1557,8 @@ ifpga_rawdev_destroy(struct rte_pci_device *pci_dev) if (!mgr) return -ENODEV; - if (ifpga_unregister_fme_interrupt(mgr)) + if (ifpga_unregister_msix_irq(IFPGA_FME_IRQ, 0, + fme_interrupt_handler, mgr)) return -EINVAL; opae_adapter_data_free(adapter->data); diff --git a/drivers/raw/ifpga/ifpga_rawdev.h b/drivers/raw/ifpga/ifpga_rawdev.h index bd42083fbb..7754beb02b 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.h +++ b/drivers/raw/ifpga/ifpga_rawdev.h @@ -62,4 +62,18 @@ struct ifpga_rawdev { struct ifpga_rawdev * ifpga_rawdev_get(const struct rte_rawdev *rawdev); +enum ifpga_irq_type { + IFPGA_FME_IRQ = 0, + IFPGA_AFU_IRQ = 1, +}; + +int +ifpga_register_msix_irq(struct rte_rawdev *dev, int port_id, + enum ifpga_irq_type type, int vec_start, int count, + rte_intr_callback_fn handler, const char *name, + void *arg); +int +ifpga_unregister_msix_irq(enum ifpga_irq_type type, + int vec_start, rte_intr_callback_fn handler, void *arg); + #endif /* _IFPGA_RAWDEV_H_ */