99ca6aa9d98b5877572d32e598341eb8b2e9c7be
[dpdk.git] / drivers / net / txgbe / txgbe_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #ifndef _TXGBE_ETHDEV_H_
6 #define _TXGBE_ETHDEV_H_
7
8 #include "base/txgbe.h"
9 #include "txgbe_ptypes.h"
10
11 /* need update link, bit flag */
12 #define TXGBE_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)
13 #define TXGBE_FLAG_MAILBOX          (uint32_t)(1 << 1)
14 #define TXGBE_FLAG_PHY_INTERRUPT    (uint32_t)(1 << 2)
15 #define TXGBE_FLAG_MACSEC           (uint32_t)(1 << 3)
16 #define TXGBE_FLAG_NEED_LINK_CONFIG (uint32_t)(1 << 4)
17
18 /*
19  * Defines that were not part of txgbe_type.h as they are not used by the
20  * FreeBSD driver.
21  */
22 #define TXGBE_VFTA_SIZE 128
23 #define TXGBE_VLAN_TAG_SIZE 4
24 #define TXGBE_HKEY_MAX_INDEX 10
25 /*Default value of Max Rx Queue*/
26 #define TXGBE_MAX_RX_QUEUE_NUM  128
27 #define TXGBE_VMDQ_DCB_NB_QUEUES     TXGBE_MAX_RX_QUEUE_NUM
28
29 #ifndef NBBY
30 #define NBBY    8       /* number of bits in a byte */
31 #endif
32 #define TXGBE_HWSTRIP_BITMAP_SIZE \
33         (TXGBE_MAX_RX_QUEUE_NUM / (sizeof(uint32_t) * NBBY))
34
35 #define TXGBE_QUEUE_ITR_INTERVAL_DEFAULT        500 /* 500us */
36
37 #define TXGBE_MAX_QUEUE_NUM_PER_VF  8
38
39 #define TXGBE_RSS_OFFLOAD_ALL ( \
40         ETH_RSS_IPV4 | \
41         ETH_RSS_NONFRAG_IPV4_TCP | \
42         ETH_RSS_NONFRAG_IPV4_UDP | \
43         ETH_RSS_IPV6 | \
44         ETH_RSS_NONFRAG_IPV6_TCP | \
45         ETH_RSS_NONFRAG_IPV6_UDP | \
46         ETH_RSS_IPV6_EX | \
47         ETH_RSS_IPV6_TCP_EX | \
48         ETH_RSS_IPV6_UDP_EX)
49
50 #define TXGBE_MISC_VEC_ID               RTE_INTR_VEC_ZERO_OFFSET
51 #define TXGBE_RX_VEC_START              RTE_INTR_VEC_RXTX_OFFSET
52
53 /* structure for interrupt relative data */
54 struct txgbe_interrupt {
55         uint32_t flags;
56         uint32_t mask_misc;
57         /* to save original mask during delayed handler */
58         uint32_t mask_misc_orig;
59         uint32_t mask[2];
60 };
61
62 #define TXGBE_NB_STAT_MAPPING  32
63 #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
64 #define NB_QMAP_FIELDS_PER_QSM_REG 4
65 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
66 struct txgbe_stat_mappings {
67         uint32_t tqsm[TXGBE_NB_STAT_MAPPING];
68         uint32_t rqsm[TXGBE_NB_STAT_MAPPING];
69 };
70
71 struct txgbe_vfta {
72         uint32_t vfta[TXGBE_VFTA_SIZE];
73 };
74
75 struct txgbe_hwstrip {
76         uint32_t bitmap[TXGBE_HWSTRIP_BITMAP_SIZE];
77 };
78
79 /*
80  * VF data which used by PF host only
81  */
82 #define TXGBE_MAX_VF_MC_ENTRIES      30
83
84 struct txgbe_uta_info {
85         uint8_t  uc_filter_type;
86         uint16_t uta_in_use;
87         uint32_t uta_shadow[TXGBE_MAX_UTA];
88 };
89
90 #define TXGBE_MAX_MIRROR_RULES 4  /* Maximum nb. of mirror rules. */
91
92 struct txgbe_mirror_info {
93         struct rte_eth_mirror_conf mr_conf[TXGBE_MAX_MIRROR_RULES];
94         /* store PF mirror rules configuration */
95 };
96
97 struct txgbe_vf_info {
98         uint8_t vf_mac_addresses[RTE_ETHER_ADDR_LEN];
99         uint16_t vf_mc_hashes[TXGBE_MAX_VF_MC_ENTRIES];
100         uint16_t num_vf_mc_hashes;
101         bool clear_to_send;
102         uint16_t tx_rate[TXGBE_MAX_QUEUE_NUM_PER_VF];
103         uint16_t vlan_count;
104         uint8_t api_version;
105         uint16_t switch_domain_id;
106         uint16_t xcast_mode;
107         uint16_t mac_count;
108 };
109
110 struct txgbe_ethertype_filter {
111         uint16_t ethertype;
112         uint32_t etqf;
113         uint32_t etqs;
114         /**
115          * If this filter is added by configuration,
116          * it should not be removed.
117          */
118         bool     conf;
119 };
120
121 /*
122  * Structure to store filters' info.
123  */
124 struct txgbe_filter_info {
125         uint8_t ethertype_mask;  /* Bit mask for every used ethertype filter */
126         /* store used ethertype filters*/
127         struct txgbe_ethertype_filter ethertype_filters[TXGBE_ETF_ID_MAX];
128 };
129
130 /* The configuration of bandwidth */
131 struct txgbe_bw_conf {
132         uint8_t tc_num; /* Number of TCs. */
133 };
134
135 /*
136  * Structure to store private data for each driver instance (for each port).
137  */
138 struct txgbe_adapter {
139         struct txgbe_hw             hw;
140         struct txgbe_hw_stats       stats;
141         struct txgbe_interrupt      intr;
142         struct txgbe_stat_mappings  stat_mappings;
143         struct txgbe_vfta           shadow_vfta;
144         struct txgbe_hwstrip        hwstrip;
145         struct txgbe_dcb_config     dcb_config;
146         struct txgbe_mirror_info    mr_data;
147         struct txgbe_vf_info        *vfdata;
148         struct txgbe_uta_info       uta_info;
149         struct txgbe_filter_info    filter;
150         struct txgbe_bw_conf        bw_conf;
151         bool rx_bulk_alloc_allowed;
152         /* For RSS reta table update */
153         uint8_t rss_reta_updated;
154 };
155
156 #define TXGBE_DEV_ADAPTER(dev) \
157         ((struct txgbe_adapter *)(dev)->data->dev_private)
158
159 #define TXGBE_DEV_HW(dev) \
160         (&((struct txgbe_adapter *)(dev)->data->dev_private)->hw)
161
162 #define TXGBE_DEV_STATS(dev) \
163         (&((struct txgbe_adapter *)(dev)->data->dev_private)->stats)
164
165 #define TXGBE_DEV_INTR(dev) \
166         (&((struct txgbe_adapter *)(dev)->data->dev_private)->intr)
167
168 #define TXGBE_DEV_STAT_MAPPINGS(dev) \
169         (&((struct txgbe_adapter *)(dev)->data->dev_private)->stat_mappings)
170
171 #define TXGBE_DEV_VFTA(dev) \
172         (&((struct txgbe_adapter *)(dev)->data->dev_private)->shadow_vfta)
173
174 #define TXGBE_DEV_HWSTRIP(dev) \
175         (&((struct txgbe_adapter *)(dev)->data->dev_private)->hwstrip)
176
177 #define TXGBE_DEV_DCB_CONFIG(dev) \
178         (&((struct txgbe_adapter *)(dev)->data->dev_private)->dcb_config)
179
180 #define TXGBE_DEV_VFDATA(dev) \
181         (&((struct txgbe_adapter *)(dev)->data->dev_private)->vfdata)
182
183 #define TXGBE_DEV_MR_INFO(dev) \
184         (&((struct txgbe_adapter *)(dev)->data->dev_private)->mr_data)
185
186 #define TXGBE_DEV_UTA_INFO(dev) \
187         (&((struct txgbe_adapter *)(dev)->data->dev_private)->uta_info)
188
189 #define TXGBE_DEV_FILTER(dev) \
190         (&((struct txgbe_adapter *)(dev)->data->dev_private)->filter)
191 #define TXGBE_DEV_BW_CONF(dev) \
192         (&((struct txgbe_adapter *)(dev)->data->dev_private)->bw_conf)
193
194
195 /*
196  * RX/TX function prototypes
197  */
198 void txgbe_dev_clear_queues(struct rte_eth_dev *dev);
199
200 void txgbe_dev_free_queues(struct rte_eth_dev *dev);
201
202 void txgbe_dev_rx_queue_release(void *rxq);
203
204 void txgbe_dev_tx_queue_release(void *txq);
205
206 int  txgbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
207                 uint16_t nb_rx_desc, unsigned int socket_id,
208                 const struct rte_eth_rxconf *rx_conf,
209                 struct rte_mempool *mb_pool);
210
211 int  txgbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
212                 uint16_t nb_tx_desc, unsigned int socket_id,
213                 const struct rte_eth_txconf *tx_conf);
214
215 int txgbe_dev_rx_init(struct rte_eth_dev *dev);
216
217 void txgbe_dev_tx_init(struct rte_eth_dev *dev);
218
219 int txgbe_dev_rxtx_start(struct rte_eth_dev *dev);
220
221 void txgbe_dev_save_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id);
222 void txgbe_dev_store_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id);
223 void txgbe_dev_save_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id);
224 void txgbe_dev_store_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id);
225
226 int txgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
227
228 int txgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
229
230 int txgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
231
232 int txgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
233
234 void txgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
235         struct rte_eth_rxq_info *qinfo);
236
237 void txgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
238         struct rte_eth_txq_info *qinfo);
239
240 uint16_t txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
241                 uint16_t nb_pkts);
242
243 uint16_t txgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
244                                     uint16_t nb_pkts);
245
246 uint16_t txgbe_recv_pkts_lro_single_alloc(void *rx_queue,
247                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
248 uint16_t txgbe_recv_pkts_lro_bulk_alloc(void *rx_queue,
249                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
250
251 uint16_t txgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
252                 uint16_t nb_pkts);
253
254 uint16_t txgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
255                 uint16_t nb_pkts);
256
257 uint16_t txgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
258                 uint16_t nb_pkts);
259
260 int txgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
261                               struct rte_eth_rss_conf *rss_conf);
262
263 int txgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
264                                 struct rte_eth_rss_conf *rss_conf);
265
266 bool txgbe_rss_update_sp(enum txgbe_mac_type mac_type);
267
268 void txgbe_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
269                                uint8_t queue, uint8_t msix_vector);
270
271 void txgbe_configure_pb(struct rte_eth_dev *dev);
272 void txgbe_configure_port(struct rte_eth_dev *dev);
273 void txgbe_configure_dcb(struct rte_eth_dev *dev);
274
275 int
276 txgbe_dev_link_update_share(struct rte_eth_dev *dev,
277                 int wait_to_complete);
278 void txgbe_pf_host_init(struct rte_eth_dev *eth_dev);
279
280 void txgbe_pf_host_uninit(struct rte_eth_dev *eth_dev);
281
282 void txgbe_pf_mbx_process(struct rte_eth_dev *eth_dev);
283
284 int txgbe_pf_host_configure(struct rte_eth_dev *eth_dev);
285
286 uint32_t txgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val);
287
288 int txgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
289                             uint16_t tx_rate, uint64_t q_msk);
290 int txgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
291                                uint16_t tx_rate);
292 static inline int
293 txgbe_ethertype_filter_lookup(struct txgbe_filter_info *filter_info,
294                               uint16_t ethertype)
295 {
296         int i;
297
298         for (i = 0; i < TXGBE_ETF_ID_MAX; i++) {
299                 if (filter_info->ethertype_filters[i].ethertype == ethertype &&
300                     (filter_info->ethertype_mask & (1 << i)))
301                         return i;
302         }
303         return -1;
304 }
305
306 static inline int
307 txgbe_ethertype_filter_insert(struct txgbe_filter_info *filter_info,
308                               struct txgbe_ethertype_filter *ethertype_filter)
309 {
310         int i;
311
312         for (i = 0; i < TXGBE_ETF_ID_MAX; i++) {
313                 if (filter_info->ethertype_mask & (1 << i))
314                         continue;
315
316                 filter_info->ethertype_mask |= 1 << i;
317                 filter_info->ethertype_filters[i].ethertype =
318                                 ethertype_filter->ethertype;
319                 filter_info->ethertype_filters[i].etqf =
320                                 ethertype_filter->etqf;
321                 filter_info->ethertype_filters[i].etqs =
322                                 ethertype_filter->etqs;
323                 filter_info->ethertype_filters[i].conf =
324                                 ethertype_filter->conf;
325                 break;
326         }
327         return (i < TXGBE_ETF_ID_MAX ? i : -1);
328 }
329
330 /* High threshold controlling when to start sending XOFF frames. */
331 #define TXGBE_FC_XOFF_HITH              128 /*KB*/
332 /* Low threshold controlling when to start sending XON frames. */
333 #define TXGBE_FC_XON_LOTH               64 /*KB*/
334
335 /* Timer value included in XOFF frames. */
336 #define TXGBE_FC_PAUSE_TIME 0x680
337
338 #define TXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
339 #define TXGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
340 #define TXGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
341
342 /*
343  *  Default values for RX/TX configuration
344  */
345 #define TXGBE_DEFAULT_RX_FREE_THRESH  32
346 #define TXGBE_DEFAULT_RX_PTHRESH      8
347 #define TXGBE_DEFAULT_RX_HTHRESH      8
348 #define TXGBE_DEFAULT_RX_WTHRESH      0
349
350 #define TXGBE_DEFAULT_TX_FREE_THRESH  32
351 #define TXGBE_DEFAULT_TX_PTHRESH      32
352 #define TXGBE_DEFAULT_TX_HTHRESH      0
353 #define TXGBE_DEFAULT_TX_WTHRESH      0
354
355 /* store statistics names and its offset in stats structure */
356 struct rte_txgbe_xstats_name_off {
357         char name[RTE_ETH_XSTATS_NAME_SIZE];
358         unsigned int offset;
359 };
360
361 const uint32_t *txgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
362 int txgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
363                                       struct rte_ether_addr *mc_addr_set,
364                                       uint32_t nb_mc_addr);
365 int txgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
366                         struct rte_eth_rss_reta_entry64 *reta_conf,
367                         uint16_t reta_size);
368 int txgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
369                         struct rte_eth_rss_reta_entry64 *reta_conf,
370                         uint16_t reta_size);
371 void txgbe_dev_setup_link_alarm_handler(void *param);
372 void txgbe_read_stats_registers(struct txgbe_hw *hw,
373                            struct txgbe_hw_stats *hw_stats);
374
375 void txgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
376 void txgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
377 void txgbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
378 void txgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
379                 uint16_t queue, bool on);
380 void txgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
381                                                   int mask);
382
383 #endif /* _TXGBE_ETHDEV_H_ */