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