summaryrefslogtreecommitdiffstats
path: root/src/vnet/dev/bus/pci.h
blob: ce9a53aa2737af91917be0a3e53d7a2a3ce7c1ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* SPDX-License-Identifier: Apache-2.0
 * Copyright (c) 2023 Cisco Systems, Inc.
 */

#ifndef _VNET_DEV_PCI_H_
#define _VNET_DEV_PCI_H_

#include <vppinfra/clib.h>
#include <vlib/pci/pci.h>
#include <vnet/dev/dev.h>

typedef void (vnet_dev_pci_intx_handler_fn_t) (vlib_main_t *vm,
					       vnet_dev_t *dev);
typedef void (vnet_dev_pci_msix_handler_fn_t) (vlib_main_t *vm,
					       vnet_dev_t *dev, u16 line);

typedef struct
{
  vlib_pci_addr_t addr;
  u16 vendor_id;
  u16 device_id;
  u8 revision;
} vnet_dev_bus_pci_device_info_t;

typedef struct
{
  u8 pci_handle_valid : 1;
  u16 n_msix_int;
  vlib_pci_addr_t addr;
  vlib_pci_dev_handle_t handle;
  vnet_dev_pci_intx_handler_fn_t *intx_handler;
  vnet_dev_pci_msix_handler_fn_t **msix_handlers;
} vnet_dev_bus_pci_device_data_t;

static_always_inline vnet_dev_bus_pci_device_data_t *
vnet_dev_get_bus_pci_device_data (vnet_dev_t *dev)
{
  return (void *) dev->bus_data;
}
static_always_inline vlib_pci_dev_handle_t
vnet_dev_get_pci_handle (vnet_dev_t *dev)
{
  return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->handle;
}

static_always_inline vlib_pci_addr_t
vnet_dev_get_pci_addr (vnet_dev_t *dev)
{
  return ((vnet_dev_bus_pci_device_data_t *) (dev->bus_data))->addr;
}

static_always_inline vlib_pci_dev_handle_t
vnet_dev_get_pci_n_msix_interrupts (vnet_dev_t *dev)
{
  return vnet_dev_get_bus_pci_device_data (dev)->n_msix_int;
}

vnet_dev_rv_t vnet_dev_pci_read_config_header (vlib_main_t *, vnet_dev_t *,
					       vlib_pci_config_hdr_t *);

vnet_dev_rv_t vnet_dev_pci_map_region (vlib_main_t *, vnet_dev_t *, u8,
				       void **);
vnet_dev_rv_t vnet_dev_pci_function_level_reset (vlib_main_t *, vnet_dev_t *);
vnet_dev_rv_t vnet_dev_pci_bus_master_enable (vlib_main_t *, vnet_dev_t *);
vnet_dev_rv_t vnet_dev_pci_bus_master_disable (vlib_main_t *, vnet_dev_t *);
vnet_dev_rv_t vnet_dev_pci_intx_add_handler (vlib_main_t *, vnet_dev_t *,
					     vnet_dev_pci_intx_handler_fn_t *);
vnet_dev_rv_t vnet_dev_pci_intx_remove_handler (vlib_main_t *, vnet_dev_t *);
vnet_dev_rv_t vnet_dev_pci_msix_add_handler (vlib_main_t *, vnet_dev_t *,
					     vnet_dev_pci_msix_handler_fn_t *,
					     u16, u16);
vnet_dev_rv_t vnet_dev_pci_msix_remove_handler (vlib_main_t *, vnet_dev_t *,
						u16, u16);
vnet_dev_rv_t vnet_dev_pci_msix_enable (vlib_main_t *, vnet_dev_t *, u16, u16);
vnet_dev_rv_t vnet_dev_pci_msix_disable (vlib_main_t *, vnet_dev_t *, u16,
					 u16);
void vnet_dev_pci_msix_set_polling_thread (vlib_main_t *, vnet_dev_t *, u16,
					   u16);

#endif /* _VNET_DEV_PCI_H_ */