net/ngbe: support SR-IOV
[dpdk.git] / drivers / net / ngbe / ngbe_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3  * Copyright(c) 2010-2017 Intel Corporation
4  */
5
6 #ifndef _NGBE_ETHDEV_H_
7 #define _NGBE_ETHDEV_H_
8
9 #include "ngbe_ptypes.h"
10 #include <rte_ethdev.h>
11 #include <rte_ethdev_core.h>
12
13 /* need update link, bit flag */
14 #define NGBE_FLAG_NEED_LINK_UPDATE  ((uint32_t)(1 << 0))
15 #define NGBE_FLAG_MAILBOX           ((uint32_t)(1 << 1))
16 #define NGBE_FLAG_PHY_INTERRUPT     ((uint32_t)(1 << 2))
17 #define NGBE_FLAG_MACSEC            ((uint32_t)(1 << 3))
18 #define NGBE_FLAG_NEED_LINK_CONFIG  ((uint32_t)(1 << 4))
19
20 #define NGBE_VFTA_SIZE 128
21 #define NGBE_VLAN_TAG_SIZE 4
22 #define NGBE_HKEY_MAX_INDEX 10
23 /*Default value of Max Rx Queue*/
24 #define NGBE_MAX_RX_QUEUE_NUM   8
25
26 #ifndef NBBY
27 #define NBBY    8       /* number of bits in a byte */
28 #endif
29 #define NGBE_HWSTRIP_BITMAP_SIZE \
30         (NGBE_MAX_RX_QUEUE_NUM / (sizeof(uint32_t) * NBBY))
31
32 #define NGBE_QUEUE_ITR_INTERVAL_DEFAULT 500 /* 500us */
33
34 /* The overhead from MTU to max frame size. */
35 #define NGBE_ETH_OVERHEAD (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
36
37 #define NGBE_RSS_OFFLOAD_ALL ( \
38         RTE_ETH_RSS_IPV4 | \
39         RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
40         RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
41         RTE_ETH_RSS_IPV6 | \
42         RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
43         RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
44         RTE_ETH_RSS_IPV6_EX | \
45         RTE_ETH_RSS_IPV6_TCP_EX | \
46         RTE_ETH_RSS_IPV6_UDP_EX)
47
48 #define NGBE_MISC_VEC_ID               RTE_INTR_VEC_ZERO_OFFSET
49 #define NGBE_RX_VEC_START              RTE_INTR_VEC_RXTX_OFFSET
50
51 /* structure for interrupt relative data */
52 struct ngbe_interrupt {
53         uint32_t flags;
54         uint32_t mask_misc;
55         uint32_t mask_misc_orig; /* save mask during delayed handler */
56         uint64_t mask;
57         uint64_t mask_orig; /* save mask during delayed handler */
58 };
59
60 #define NGBE_NB_STAT_MAPPING  32
61 #define NB_QMAP_FIELDS_PER_QSM_REG 4
62 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
63 struct ngbe_stat_mappings {
64         uint32_t tqsm[NGBE_NB_STAT_MAPPING];
65         uint32_t rqsm[NGBE_NB_STAT_MAPPING];
66 };
67
68 struct ngbe_vfta {
69         uint32_t vfta[NGBE_VFTA_SIZE];
70 };
71
72 struct ngbe_hwstrip {
73         uint32_t bitmap[NGBE_HWSTRIP_BITMAP_SIZE];
74 };
75
76 struct ngbe_uta_info {
77         uint8_t  uc_filter_type;
78         uint16_t uta_in_use;
79         uint32_t uta_shadow[NGBE_MAX_UTA];
80 };
81
82 struct ngbe_vf_info {
83         uint8_t vf_mac_addresses[RTE_ETHER_ADDR_LEN];
84         bool clear_to_send;
85         uint16_t switch_domain_id;
86 };
87
88 /*
89  * Structure to store private data for each driver instance (for each port).
90  */
91 struct ngbe_adapter {
92         struct ngbe_hw             hw;
93         struct ngbe_hw_stats       stats;
94         struct ngbe_interrupt      intr;
95         struct ngbe_stat_mappings  stat_mappings;
96         struct ngbe_vfta           shadow_vfta;
97         struct ngbe_hwstrip        hwstrip;
98         struct ngbe_vf_info        *vfdata;
99         struct ngbe_uta_info       uta_info;
100         bool                       rx_bulk_alloc_allowed;
101
102         /* For RSS reta table update */
103         uint8_t rss_reta_updated;
104 };
105
106 static inline struct ngbe_adapter *
107 ngbe_dev_adapter(struct rte_eth_dev *dev)
108 {
109         struct ngbe_adapter *ad = dev->data->dev_private;
110
111         return ad;
112 }
113
114 static inline struct ngbe_hw *
115 ngbe_dev_hw(struct rte_eth_dev *dev)
116 {
117         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
118         struct ngbe_hw *hw = &ad->hw;
119
120         return hw;
121 }
122
123 #define NGBE_DEV_STATS(dev) \
124         (&((struct ngbe_adapter *)(dev)->data->dev_private)->stats)
125
126 static inline struct ngbe_interrupt *
127 ngbe_dev_intr(struct rte_eth_dev *dev)
128 {
129         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
130         struct ngbe_interrupt *intr = &ad->intr;
131
132         return intr;
133 }
134
135 #define NGBE_DEV_STAT_MAPPINGS(dev) \
136         (&((struct ngbe_adapter *)(dev)->data->dev_private)->stat_mappings)
137
138 #define NGBE_DEV_VFTA(dev) \
139         (&((struct ngbe_adapter *)(dev)->data->dev_private)->shadow_vfta)
140
141 #define NGBE_DEV_HWSTRIP(dev) \
142         (&((struct ngbe_adapter *)(dev)->data->dev_private)->hwstrip)
143
144 #define NGBE_DEV_VFDATA(dev) \
145         (&((struct ngbe_adapter *)(dev)->data->dev_private)->vfdata)
146
147 #define NGBE_DEV_UTA_INFO(dev) \
148         (&((struct ngbe_adapter *)(dev)->data->dev_private)->uta_info)
149
150 /*
151  * Rx/Tx function prototypes
152  */
153 void ngbe_dev_clear_queues(struct rte_eth_dev *dev);
154
155 void ngbe_dev_free_queues(struct rte_eth_dev *dev);
156
157 void ngbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
158
159 void ngbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
160
161 int  ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
162                 uint16_t nb_rx_desc, unsigned int socket_id,
163                 const struct rte_eth_rxconf *rx_conf,
164                 struct rte_mempool *mb_pool);
165
166 int  ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
167                 uint16_t nb_tx_desc, unsigned int socket_id,
168                 const struct rte_eth_txconf *tx_conf);
169
170 int ngbe_dev_rx_init(struct rte_eth_dev *dev);
171
172 void ngbe_dev_tx_init(struct rte_eth_dev *dev);
173
174 int ngbe_dev_rxtx_start(struct rte_eth_dev *dev);
175
176 void ngbe_dev_save_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
177 void ngbe_dev_store_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
178 void ngbe_dev_save_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
179 void ngbe_dev_store_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
180
181 int ngbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
182
183 int ngbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
184
185 int ngbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
186
187 int ngbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
188
189 int
190 ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
191                       struct rte_eth_burst_mode *mode);
192 int
193 ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
194                       struct rte_eth_burst_mode *mode);
195
196 uint16_t ngbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
197                 uint16_t nb_pkts);
198
199 uint16_t ngbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
200                                     uint16_t nb_pkts);
201
202 uint16_t ngbe_recv_pkts_sc_single_alloc(void *rx_queue,
203                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
204 uint16_t ngbe_recv_pkts_sc_bulk_alloc(void *rx_queue,
205                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
206
207 uint16_t ngbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
208                 uint16_t nb_pkts);
209
210 uint16_t ngbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
211                 uint16_t nb_pkts);
212
213 uint16_t ngbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
214                 uint16_t nb_pkts);
215
216 int ngbe_dev_rss_hash_update(struct rte_eth_dev *dev,
217                               struct rte_eth_rss_conf *rss_conf);
218
219 int ngbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
220                                 struct rte_eth_rss_conf *rss_conf);
221
222 void ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
223                                uint8_t queue, uint8_t msix_vector);
224
225 void ngbe_configure_port(struct rte_eth_dev *dev);
226
227 int
228 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
229                 int wait_to_complete);
230
231 /*
232  * misc function prototypes
233  */
234 void ngbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
235
236 void ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
237
238 void ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
239
240 int ngbe_pf_host_init(struct rte_eth_dev *eth_dev);
241
242 void ngbe_pf_host_uninit(struct rte_eth_dev *eth_dev);
243
244 int ngbe_pf_host_configure(struct rte_eth_dev *eth_dev);
245
246 #define NGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
247 #define NGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
248 #define NGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
249
250 /*
251  *  Default values for Rx/Tx configuration
252  */
253 #define NGBE_DEFAULT_RX_FREE_THRESH  32
254 #define NGBE_DEFAULT_RX_PTHRESH      8
255 #define NGBE_DEFAULT_RX_HTHRESH      8
256 #define NGBE_DEFAULT_RX_WTHRESH      0
257
258 #define NGBE_DEFAULT_TX_FREE_THRESH  32
259 #define NGBE_DEFAULT_TX_PTHRESH      32
260 #define NGBE_DEFAULT_TX_HTHRESH      0
261 #define NGBE_DEFAULT_TX_WTHRESH      0
262
263 /* store statistics names and its offset in stats structure */
264 struct rte_ngbe_xstats_name_off {
265         char name[RTE_ETH_XSTATS_NAME_SIZE];
266         unsigned int offset;
267 };
268
269 const uint32_t *ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
270 int ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
271                                       struct rte_ether_addr *mc_addr_set,
272                                       uint32_t nb_mc_addr);
273 int ngbe_dev_rss_reta_update(struct rte_eth_dev *dev,
274                         struct rte_eth_rss_reta_entry64 *reta_conf,
275                         uint16_t reta_size);
276 int ngbe_dev_rss_reta_query(struct rte_eth_dev *dev,
277                         struct rte_eth_rss_reta_entry64 *reta_conf,
278                         uint16_t reta_size);
279 void ngbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
280                 uint16_t queue, bool on);
281 void ngbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
282                                                   int mask);
283 void ngbe_read_stats_registers(struct ngbe_hw *hw,
284                            struct ngbe_hw_stats *hw_stats);
285
286 #endif /* _NGBE_ETHDEV_H_ */