vdpa/sfc: support device initialization
[dpdk.git] / drivers / vdpa / sfc / sfc_vdpa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020-2021 Xilinx, Inc.
3  */
4
5 #ifndef _SFC_VDPA_H
6 #define _SFC_VDPA_H
7
8 #include <stdint.h>
9 #include <sys/queue.h>
10
11 #include <rte_bus_pci.h>
12
13 #include "sfc_efx.h"
14 #include "sfc_efx_mcdi.h"
15 #include "sfc_vdpa_debug.h"
16 #include "sfc_vdpa_log.h"
17 #include "sfc_vdpa_ops.h"
18
19 #define SFC_VDPA_DEFAULT_MCDI_IOVA              0x200000000000
20
21 /* Adapter private data */
22 struct sfc_vdpa_adapter {
23         TAILQ_ENTRY(sfc_vdpa_adapter)   next;
24         /*
25          * PMD setup and configuration is not thread safe. Since it is not
26          * performance sensitive, it is better to guarantee thread-safety
27          * and add device level lock. vDPA control operations which
28          * change its state should acquire the lock.
29          */
30         rte_spinlock_t                  lock;
31         struct rte_pci_device           *pdev;
32
33         efx_family_t                    family;
34         efx_nic_t                       *nic;
35         rte_spinlock_t                  nic_lock;
36
37         efsys_bar_t                     mem_bar;
38
39         struct sfc_efx_mcdi             mcdi;
40         size_t                          mcdi_buff_size;
41
42         uint32_t                        max_queue_count;
43
44         char                            log_prefix[SFC_VDPA_LOG_PREFIX_MAX];
45         uint32_t                        logtype_main;
46
47         int                             vfio_group_fd;
48         int                             vfio_dev_fd;
49         int                             vfio_container_fd;
50         int                             iommu_group_num;
51         struct sfc_vdpa_ops_data        *ops_data;
52 };
53
54 uint32_t
55 sfc_vdpa_register_logtype(const struct rte_pci_addr *pci_addr,
56                           const char *lt_prefix_str,
57                           uint32_t ll_default);
58
59 struct sfc_vdpa_adapter *
60 sfc_vdpa_get_adapter_by_dev(struct rte_pci_device *pdev);
61
62 int
63 sfc_vdpa_hw_init(struct sfc_vdpa_adapter *sva);
64 void
65 sfc_vdpa_hw_fini(struct sfc_vdpa_adapter *sva);
66
67 int
68 sfc_vdpa_mcdi_init(struct sfc_vdpa_adapter *sva);
69 void
70 sfc_vdpa_mcdi_fini(struct sfc_vdpa_adapter *sva);
71
72 int
73 sfc_vdpa_dma_alloc(struct sfc_vdpa_adapter *sva, const char *name,
74                    size_t len, efsys_mem_t *esmp);
75
76 void
77 sfc_vdpa_dma_free(struct sfc_vdpa_adapter *sva, efsys_mem_t *esmp);
78
79 static inline struct sfc_vdpa_adapter *
80 sfc_vdpa_adapter_by_dev_handle(void *dev_handle)
81 {
82         return (struct sfc_vdpa_adapter *)dev_handle;
83 }
84
85 #endif  /* _SFC_VDPA_H */