net/ngbe: support VLAN offload and VLAN filter
[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
11 /* need update link, bit flag */
12 #define NGBE_FLAG_NEED_LINK_UPDATE  ((uint32_t)(1 << 0))
13 #define NGBE_FLAG_MAILBOX           ((uint32_t)(1 << 1))
14 #define NGBE_FLAG_PHY_INTERRUPT     ((uint32_t)(1 << 2))
15 #define NGBE_FLAG_MACSEC            ((uint32_t)(1 << 3))
16 #define NGBE_FLAG_NEED_LINK_CONFIG  ((uint32_t)(1 << 4))
17
18 #define NGBE_VFTA_SIZE 128
19 #define NGBE_VLAN_TAG_SIZE 4
20 /*Default value of Max Rx Queue*/
21 #define NGBE_MAX_RX_QUEUE_NUM   8
22
23 #ifndef NBBY
24 #define NBBY    8       /* number of bits in a byte */
25 #endif
26 #define NGBE_HWSTRIP_BITMAP_SIZE \
27         (NGBE_MAX_RX_QUEUE_NUM / (sizeof(uint32_t) * NBBY))
28
29 #define NGBE_QUEUE_ITR_INTERVAL_DEFAULT 500 /* 500us */
30
31 /* The overhead from MTU to max frame size. */
32 #define NGBE_ETH_OVERHEAD (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
33
34 #define NGBE_MISC_VEC_ID               RTE_INTR_VEC_ZERO_OFFSET
35 #define NGBE_RX_VEC_START              RTE_INTR_VEC_RXTX_OFFSET
36
37 /* structure for interrupt relative data */
38 struct ngbe_interrupt {
39         uint32_t flags;
40         uint32_t mask_misc;
41         uint32_t mask_misc_orig; /* save mask during delayed handler */
42         uint64_t mask;
43         uint64_t mask_orig; /* save mask during delayed handler */
44 };
45
46 struct ngbe_vfta {
47         uint32_t vfta[NGBE_VFTA_SIZE];
48 };
49
50 struct ngbe_hwstrip {
51         uint32_t bitmap[NGBE_HWSTRIP_BITMAP_SIZE];
52 };
53
54 /*
55  * Structure to store private data for each driver instance (for each port).
56  */
57 struct ngbe_adapter {
58         struct ngbe_hw             hw;
59         struct ngbe_interrupt      intr;
60         struct ngbe_vfta           shadow_vfta;
61         struct ngbe_hwstrip        hwstrip;
62         bool                       rx_bulk_alloc_allowed;
63 };
64
65 static inline struct ngbe_adapter *
66 ngbe_dev_adapter(struct rte_eth_dev *dev)
67 {
68         struct ngbe_adapter *ad = dev->data->dev_private;
69
70         return ad;
71 }
72
73 static inline struct ngbe_hw *
74 ngbe_dev_hw(struct rte_eth_dev *dev)
75 {
76         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
77         struct ngbe_hw *hw = &ad->hw;
78
79         return hw;
80 }
81
82 static inline struct ngbe_interrupt *
83 ngbe_dev_intr(struct rte_eth_dev *dev)
84 {
85         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
86         struct ngbe_interrupt *intr = &ad->intr;
87
88         return intr;
89 }
90
91 #define NGBE_DEV_VFTA(dev) \
92         (&((struct ngbe_adapter *)(dev)->data->dev_private)->shadow_vfta)
93
94 #define NGBE_DEV_HWSTRIP(dev) \
95         (&((struct ngbe_adapter *)(dev)->data->dev_private)->hwstrip)
96
97 /*
98  * Rx/Tx function prototypes
99  */
100 void ngbe_dev_clear_queues(struct rte_eth_dev *dev);
101
102 void ngbe_dev_free_queues(struct rte_eth_dev *dev);
103
104 void ngbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
105
106 void ngbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
107
108 int  ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
109                 uint16_t nb_rx_desc, unsigned int socket_id,
110                 const struct rte_eth_rxconf *rx_conf,
111                 struct rte_mempool *mb_pool);
112
113 int  ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
114                 uint16_t nb_tx_desc, unsigned int socket_id,
115                 const struct rte_eth_txconf *tx_conf);
116
117 int ngbe_dev_rx_init(struct rte_eth_dev *dev);
118
119 void ngbe_dev_tx_init(struct rte_eth_dev *dev);
120
121 int ngbe_dev_rxtx_start(struct rte_eth_dev *dev);
122
123 void ngbe_dev_save_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
124 void ngbe_dev_store_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
125 void ngbe_dev_save_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
126 void ngbe_dev_store_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
127
128 int ngbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
129
130 int ngbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
131
132 int ngbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
133
134 int ngbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
135
136 int
137 ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
138                       struct rte_eth_burst_mode *mode);
139 int
140 ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
141                       struct rte_eth_burst_mode *mode);
142
143 uint16_t ngbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
144                 uint16_t nb_pkts);
145
146 uint16_t ngbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
147                                     uint16_t nb_pkts);
148
149 uint16_t ngbe_recv_pkts_sc_single_alloc(void *rx_queue,
150                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
151 uint16_t ngbe_recv_pkts_sc_bulk_alloc(void *rx_queue,
152                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
153
154 uint16_t ngbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
155                 uint16_t nb_pkts);
156
157 uint16_t ngbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
158                 uint16_t nb_pkts);
159
160 uint16_t ngbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
161                 uint16_t nb_pkts);
162
163 void ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
164                                uint8_t queue, uint8_t msix_vector);
165
166 void ngbe_configure_port(struct rte_eth_dev *dev);
167
168 int
169 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
170                 int wait_to_complete);
171
172 /*
173  * misc function prototypes
174  */
175 void ngbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
176
177 void ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
178
179 void ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
180
181 #define NGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
182 #define NGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
183 #define NGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
184
185 /*
186  *  Default values for Rx/Tx configuration
187  */
188 #define NGBE_DEFAULT_RX_FREE_THRESH  32
189 #define NGBE_DEFAULT_RX_PTHRESH      8
190 #define NGBE_DEFAULT_RX_HTHRESH      8
191 #define NGBE_DEFAULT_RX_WTHRESH      0
192
193 #define NGBE_DEFAULT_TX_FREE_THRESH  32
194 #define NGBE_DEFAULT_TX_PTHRESH      32
195 #define NGBE_DEFAULT_TX_HTHRESH      0
196 #define NGBE_DEFAULT_TX_WTHRESH      0
197
198 const uint32_t *ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
199 void ngbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
200                 uint16_t queue, bool on);
201 void ngbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
202                                                   int mask);
203
204 #endif /* _NGBE_ETHDEV_H_ */