Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright (c) 2023 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #ifndef _VNET_DEV_PCI_H_ |
| 6 | #define _VNET_DEV_PCI_H_ |
| 7 | |
| 8 | #include <vppinfra/clib.h> |
| 9 | #include <vlib/pci/pci.h> |
| 10 | #include <vnet/dev/dev.h> |
| 11 | |
| 12 | typedef void (vnet_dev_pci_intx_handler_fn_t) (vlib_main_t *vm, |
| 13 | vnet_dev_t *dev); |
| 14 | typedef void (vnet_dev_pci_msix_handler_fn_t) (vlib_main_t *vm, |
| 15 | vnet_dev_t *dev, u16 line); |
| 16 | |
| 17 | typedef struct |
| 18 | { |
| 19 | vlib_pci_addr_t addr; |
| 20 | u16 vendor_id; |
| 21 | u16 device_id; |
| 22 | u8 revision; |
| 23 | } vnet_dev_bus_pci_device_info_t; |
| 24 | |
| 25 | typedef struct |
| 26 | { |
| 27 | u8 pci_handle_valid : 1; |
| 28 | u16 n_msix_int; |
| 29 | vlib_pci_addr_t addr; |
| 30 | vlib_pci_dev_handle_t handle; |
| 31 | vnet_dev_pci_intx_handler_fn_t *intx_handler; |
| 32 | vnet_dev_pci_msix_handler_fn_t **msix_handlers; |
| 33 | } vnet_dev_bus_pci_device_data_t; |
| 34 | |
| 35 | static_always_inline vnet_dev_bus_pci_device_data_t * |
| 36 | vnet_dev_get_bus_pci_device_data (vnet_dev_t *dev) |
| 37 | { |
| 38 | return (void *) dev->bus_data; |
| 39 | } |
| 40 | static_always_inline vlib_pci_dev_handle_t |
| 41 | vnet_dev_get_pci_handle (vnet_dev_t *dev) |
| 42 | { |
| 43 | return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->handle; |
| 44 | } |
| 45 | |
| 46 | static_always_inline vlib_pci_addr_t |
| 47 | vnet_dev_get_pci_addr (vnet_dev_t *dev) |
| 48 | { |
| 49 | return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->addr; |
| 50 | } |
| 51 | |
| 52 | static_always_inline vlib_pci_dev_handle_t |
| 53 | vnet_dev_get_pci_n_msix_interrupts (vnet_dev_t *dev) |
| 54 | { |
| 55 | return vnet_dev_get_bus_pci_device_data (dev)->n_msix_int; |
| 56 | } |
| 57 | |
| 58 | vnet_dev_rv_t vnet_dev_pci_read_config_header (vlib_main_t *, vnet_dev_t *, |
| 59 | vlib_pci_config_hdr_t *); |
| 60 | |
| 61 | vnet_dev_rv_t vnet_dev_pci_map_region (vlib_main_t *, vnet_dev_t *, u8, |
| 62 | void **); |
| 63 | vnet_dev_rv_t vnet_dev_pci_function_level_reset (vlib_main_t *, vnet_dev_t *); |
| 64 | vnet_dev_rv_t vnet_dev_pci_bus_master_enable (vlib_main_t *, vnet_dev_t *); |
| 65 | vnet_dev_rv_t vnet_dev_pci_bus_master_disable (vlib_main_t *, vnet_dev_t *); |
| 66 | vnet_dev_rv_t vnet_dev_pci_intx_add_handler (vlib_main_t *, vnet_dev_t *, |
| 67 | vnet_dev_pci_intx_handler_fn_t *); |
| 68 | vnet_dev_rv_t vnet_dev_pci_intx_remove_handler (vlib_main_t *, vnet_dev_t *); |
| 69 | vnet_dev_rv_t vnet_dev_pci_msix_add_handler (vlib_main_t *, vnet_dev_t *, |
| 70 | vnet_dev_pci_msix_handler_fn_t *, |
| 71 | u16, u16); |
| 72 | vnet_dev_rv_t vnet_dev_pci_msix_remove_handler (vlib_main_t *, vnet_dev_t *, |
| 73 | u16, u16); |
| 74 | vnet_dev_rv_t vnet_dev_pci_msix_enable (vlib_main_t *, vnet_dev_t *, u16, u16); |
| 75 | vnet_dev_rv_t vnet_dev_pci_msix_disable (vlib_main_t *, vnet_dev_t *, u16, |
| 76 | u16); |
| 77 | |
| 78 | #endif /* _VNET_DEV_PCI_H_ */ |