From 38c619115b0399bae8b0dcf66e57e623cc50809c Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Tue, 17 Oct 2023 16:06:26 +0000 Subject: dev: new device driver infra Type: feature Change-Id: I20c56e0d3103624407f18365c2bc1273dea5c199 Signed-off-by: Damjan Marion --- src/vlib/linux/pci.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/vlib/pci/pci.h | 5 +++++ 2 files changed, 53 insertions(+) (limited to 'src/vlib') diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c index 1a70c568176..69d26fd7d64 100644 --- a/src/vlib/linux/pci.c +++ b/src/vlib/linux/pci.c @@ -885,6 +885,27 @@ vlib_pci_register_intx_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, return 0; } +clib_error_t * +vlib_pci_unregister_intx_handler (vlib_main_t *vm, vlib_pci_dev_handle_t h) +{ + linux_pci_device_t *p = linux_pci_get_device (h); + linux_pci_irq_t *irq = &p->intx_irq; + + if (irq->intx_handler == 0) + return 0; + + clib_file_del_by_index (&file_main, irq->clib_file_index); + if (p->type == LINUX_PCI_DEVICE_TYPE_VFIO) + { + close (irq->fd); + irq->fd = -1; + } + + irq->intx_handler = 0; + + return 0; +} + clib_error_t * vlib_pci_register_msix_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u32 start, u32 count, @@ -942,6 +963,33 @@ error: return err; } +clib_error_t * +vlib_pci_unregister_msix_handler (vlib_main_t *vm, vlib_pci_dev_handle_t h, + u32 start, u32 count) +{ + clib_error_t *err = 0; + linux_pci_device_t *p = linux_pci_get_device (h); + u32 i; + + if (p->type != LINUX_PCI_DEVICE_TYPE_VFIO) + return clib_error_return (0, "vfio driver is needed for MSI-X interrupt " + "support"); + + for (i = start; i < start + count; i++) + { + linux_pci_irq_t *irq = vec_elt_at_index (p->msix_irqs, i); + + if (irq->fd != -1) + { + clib_file_del_by_index (&file_main, irq->clib_file_index); + close (irq->fd); + irq->fd = -1; + } + } + + return err; +} + clib_error_t * vlib_pci_enable_msix_irq (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 start, u16 count) diff --git a/src/vlib/pci/pci.h b/src/vlib/pci/pci.h index 627833d4dfc..06a2a176419 100644 --- a/src/vlib/pci/pci.h +++ b/src/vlib/pci/pci.h @@ -240,11 +240,16 @@ clib_error_t *vlib_pci_register_intx_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, pci_intx_handler_function_t * intx_handler); +clib_error_t *vlib_pci_unregister_intx_handler (vlib_main_t *vm, + vlib_pci_dev_handle_t h); clib_error_t *vlib_pci_register_msix_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u32 start, u32 count, pci_msix_handler_function_t * msix_handler); +clib_error_t *vlib_pci_unregister_msix_handler (vlib_main_t *vm, + vlib_pci_dev_handle_t h, + u32 start, u32 count); clib_error_t *vlib_pci_enable_msix_irq (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 start, u16 count); -- cgit 1.2.3-korg