vdpa/sfc: support MAC filter config
[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_MAC_ADDR                       "mac"
20 #define SFC_VDPA_DEFAULT_MCDI_IOVA              0x200000000000
21
22 /* Broadcast & Unicast MAC filters are supported */
23 #define SFC_MAX_SUPPORTED_FILTERS               2
24
25 /*
26  * Get function-local index of the associated VI from the
27  * virtqueue number. Queue 0 is reserved for MCDI
28  */
29 #define SFC_VDPA_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1)
30
31 enum sfc_vdpa_filter_type {
32         SFC_VDPA_BCAST_MAC_FILTER = 0,
33         SFC_VDPA_UCAST_MAC_FILTER = 1,
34         SFC_VDPA_FILTER_NTYPE
35 };
36
37 typedef struct sfc_vdpa_filter_s {
38         int                             filter_cnt;
39         efx_filter_spec_t               spec[SFC_MAX_SUPPORTED_FILTERS];
40 } sfc_vdpa_filter_t;
41
42 /* Adapter private data */
43 struct sfc_vdpa_adapter {
44         TAILQ_ENTRY(sfc_vdpa_adapter)   next;
45         /*
46          * PMD setup and configuration is not thread safe. Since it is not
47          * performance sensitive, it is better to guarantee thread-safety
48          * and add device level lock. vDPA control operations which
49          * change its state should acquire the lock.
50          */
51         rte_spinlock_t                  lock;
52         struct rte_pci_device           *pdev;
53
54         struct rte_kvargs               *kvargs;
55
56         efx_family_t                    family;
57         efx_nic_t                       *nic;
58         rte_spinlock_t                  nic_lock;
59
60         efsys_bar_t                     mem_bar;
61
62         struct sfc_efx_mcdi             mcdi;
63         size_t                          mcdi_buff_size;
64
65         uint32_t                        max_queue_count;
66
67         char                            log_prefix[SFC_VDPA_LOG_PREFIX_MAX];
68         uint32_t                        logtype_main;
69
70         sfc_vdpa_filter_t               filters;
71
72         int                             vfio_group_fd;
73         int                             vfio_dev_fd;
74         int                             vfio_container_fd;
75         int                             iommu_group_num;
76         struct sfc_vdpa_ops_data        *ops_data;
77 };
78
79 uint32_t
80 sfc_vdpa_register_logtype(const struct rte_pci_addr *pci_addr,
81                           const char *lt_prefix_str,
82                           uint32_t ll_default);
83
84 struct sfc_vdpa_adapter *
85 sfc_vdpa_get_adapter_by_dev(struct rte_pci_device *pdev);
86 struct sfc_vdpa_ops_data *
87 sfc_vdpa_get_data_by_dev(struct rte_vdpa_device *vdpa_dev);
88
89 int
90 sfc_vdpa_hw_init(struct sfc_vdpa_adapter *sva);
91 void
92 sfc_vdpa_hw_fini(struct sfc_vdpa_adapter *sva);
93
94 int
95 sfc_vdpa_mcdi_init(struct sfc_vdpa_adapter *sva);
96 void
97 sfc_vdpa_mcdi_fini(struct sfc_vdpa_adapter *sva);
98
99 int
100 sfc_vdpa_dma_alloc(struct sfc_vdpa_adapter *sva, const char *name,
101                    size_t len, efsys_mem_t *esmp);
102
103 void
104 sfc_vdpa_dma_free(struct sfc_vdpa_adapter *sva, efsys_mem_t *esmp);
105
106 int
107 sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *vdpa_data, bool do_map);
108
109 int
110 sfc_vdpa_filter_remove(struct sfc_vdpa_ops_data *ops_data);
111 int
112 sfc_vdpa_filter_config(struct sfc_vdpa_ops_data *ops_data);
113
114 static inline struct sfc_vdpa_adapter *
115 sfc_vdpa_adapter_by_dev_handle(void *dev_handle)
116 {
117         return (struct sfc_vdpa_adapter *)dev_handle;
118 }
119
120 /*
121  * Add wrapper functions to acquire/release lock to be able to remove or
122  * change the lock in one place.
123  */
124 static inline void
125 sfc_vdpa_adapter_lock_init(struct sfc_vdpa_adapter *sva)
126 {
127         rte_spinlock_init(&sva->lock);
128 }
129
130 static inline int
131 sfc_vdpa_adapter_is_locked(struct sfc_vdpa_adapter *sva)
132 {
133         return rte_spinlock_is_locked(&sva->lock);
134 }
135
136 static inline void
137 sfc_vdpa_adapter_lock(struct sfc_vdpa_adapter *sva)
138 {
139         rte_spinlock_lock(&sva->lock);
140 }
141
142 static inline int
143 sfc_vdpa_adapter_trylock(struct sfc_vdpa_adapter *sva)
144 {
145         return rte_spinlock_trylock(&sva->lock);
146 }
147
148 static inline void
149 sfc_vdpa_adapter_unlock(struct sfc_vdpa_adapter *sva)
150 {
151         rte_spinlock_unlock(&sva->lock);
152 }
153
154 static inline void
155 sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva)
156 {
157         /* Just for symmetry of the API */
158 }
159
160 #endif  /* _SFC_VDPA_H */