[v17,19/19] raw/ifpga: introducing new irq API
diff mbox series

Message ID 1573715667-192995-20-git-send-email-rosen.xu@intel.com
State Superseded, archived
Delegated to: xiaolong ye
Headers show
Series
  • add PCIe AER disable and IRQ support for ipn3ke
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Xu, Rosen Nov. 14, 2019, 7:14 a.m. UTC
From: Tianfei zhang <tianfei.zhang@intel.com>

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 managerment,
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 <tianfei.zhang@intel.com>
Signed-off-by: Andy Pei <andy.pei@intel.com>
---
 drivers/raw/ifpga/ifpga_rawdev.c | 105 +++++++++++++++++++++++++++------------
 drivers/raw/ifpga/ifpga_rawdev.h |  14 ++++++
 2 files changed, 88 insertions(+), 31 deletions(-)

Patch
diff mbox series

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index fb5d9b1..a79b581 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -79,6 +79,10 @@ 
 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,53 +1332,90 @@  static int fme_clean_fme_error(struct opae_manager *mgr)
 	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 @@  static int ifpga_register_fme_interrupt(struct opae_manager *mgr)
 		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 @@  static int ifpga_register_fme_interrupt(struct opae_manager *mgr)
 	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 bd42083..7754beb 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_ */