blob: ce9a53aa2737af91917be0a3e53d7a2a3ce7c1ab [file] [log] [blame]
Damjan Marion38c61912023-10-17 16:06:26 +00001/* 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
12typedef void (vnet_dev_pci_intx_handler_fn_t) (vlib_main_t *vm,
13 vnet_dev_t *dev);
14typedef void (vnet_dev_pci_msix_handler_fn_t) (vlib_main_t *vm,
15 vnet_dev_t *dev, u16 line);
16
17typedef 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
25typedef 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
35static_always_inline vnet_dev_bus_pci_device_data_t *
36vnet_dev_get_bus_pci_device_data (vnet_dev_t *dev)
37{
38 return (void *) dev->bus_data;
39}
40static_always_inline vlib_pci_dev_handle_t
41vnet_dev_get_pci_handle (vnet_dev_t *dev)
42{
43 return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->handle;
44}
45
46static_always_inline vlib_pci_addr_t
47vnet_dev_get_pci_addr (vnet_dev_t *dev)
48{
49 return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->addr;
50}
51
52static_always_inline vlib_pci_dev_handle_t
53vnet_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
58vnet_dev_rv_t vnet_dev_pci_read_config_header (vlib_main_t *, vnet_dev_t *,
59 vlib_pci_config_hdr_t *);
60
61vnet_dev_rv_t vnet_dev_pci_map_region (vlib_main_t *, vnet_dev_t *, u8,
62 void **);
63vnet_dev_rv_t vnet_dev_pci_function_level_reset (vlib_main_t *, vnet_dev_t *);
64vnet_dev_rv_t vnet_dev_pci_bus_master_enable (vlib_main_t *, vnet_dev_t *);
65vnet_dev_rv_t vnet_dev_pci_bus_master_disable (vlib_main_t *, vnet_dev_t *);
66vnet_dev_rv_t vnet_dev_pci_intx_add_handler (vlib_main_t *, vnet_dev_t *,
67 vnet_dev_pci_intx_handler_fn_t *);
68vnet_dev_rv_t vnet_dev_pci_intx_remove_handler (vlib_main_t *, vnet_dev_t *);
69vnet_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);
72vnet_dev_rv_t vnet_dev_pci_msix_remove_handler (vlib_main_t *, vnet_dev_t *,
73 u16, u16);
74vnet_dev_rv_t vnet_dev_pci_msix_enable (vlib_main_t *, vnet_dev_t *, u16, u16);
75vnet_dev_rv_t vnet_dev_pci_msix_disable (vlib_main_t *, vnet_dev_t *, u16,
76 u16);
Damjan Marionb8dd9812023-11-03 13:47:05 +000077void vnet_dev_pci_msix_set_polling_thread (vlib_main_t *, vnet_dev_t *, u16,
78 u16);
Damjan Marion38c61912023-10-17 16:06:26 +000079
80#endif /* _VNET_DEV_PCI_H_ */