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