e08f2e4029e6dc5c4664daa9b1a0820facbeadfe
[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 #define NGBE_NB_STAT_MAPPING  32
47 #define NB_QMAP_FIELDS_PER_QSM_REG 4
48 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
49 struct ngbe_stat_mappings {
50         uint32_t tqsm[NGBE_NB_STAT_MAPPING];
51         uint32_t rqsm[NGBE_NB_STAT_MAPPING];
52 };
53
54 struct ngbe_vfta {
55         uint32_t vfta[NGBE_VFTA_SIZE];
56 };
57
58 struct ngbe_hwstrip {
59         uint32_t bitmap[NGBE_HWSTRIP_BITMAP_SIZE];
60 };
61
62 struct ngbe_uta_info {
63         uint8_t  uc_filter_type;
64         uint16_t uta_in_use;
65         uint32_t uta_shadow[NGBE_MAX_UTA];
66 };
67
68 /*
69  * Structure to store private data for each driver instance (for each port).
70  */
71 struct ngbe_adapter {
72         struct ngbe_hw             hw;
73         struct ngbe_hw_stats       stats;
74         struct ngbe_interrupt      intr;
75         struct ngbe_stat_mappings  stat_mappings;
76         struct ngbe_vfta           shadow_vfta;
77         struct ngbe_hwstrip        hwstrip;
78         struct ngbe_uta_info       uta_info;
79         bool                       rx_bulk_alloc_allowed;
80 };
81
82 static inline struct ngbe_adapter *
83 ngbe_dev_adapter(struct rte_eth_dev *dev)
84 {
85         struct ngbe_adapter *ad = dev->data->dev_private;
86
87         return ad;
88 }
89
90 static inline struct ngbe_hw *
91 ngbe_dev_hw(struct rte_eth_dev *dev)
92 {
93         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
94         struct ngbe_hw *hw = &ad->hw;
95
96         return hw;
97 }
98
99 #define NGBE_DEV_STATS(dev) \
100         (&((struct ngbe_adapter *)(dev)->data->dev_private)->stats)
101
102 static inline struct ngbe_interrupt *
103 ngbe_dev_intr(struct rte_eth_dev *dev)
104 {
105         struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
106         struct ngbe_interrupt *intr = &ad->intr;
107
108         return intr;
109 }
110
111 #define NGBE_DEV_STAT_MAPPINGS(dev) \
112         (&((struct ngbe_adapter *)(dev)->data->dev_private)->stat_mappings)
113
114 #define NGBE_DEV_VFTA(dev) \
115         (&((struct ngbe_adapter *)(dev)->data->dev_private)->shadow_vfta)
116
117 #define NGBE_DEV_HWSTRIP(dev) \
118         (&((struct ngbe_adapter *)(dev)->data->dev_private)->hwstrip)
119 #define NGBE_DEV_UTA_INFO(dev) \
120         (&((struct ngbe_adapter *)(dev)->data->dev_private)->uta_info)
121
122 /*
123  * Rx/Tx function prototypes
124  */
125 void ngbe_dev_clear_queues(struct rte_eth_dev *dev);
126
127 void ngbe_dev_free_queues(struct rte_eth_dev *dev);
128
129 void ngbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
130
131 void ngbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
132
133 int  ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
134                 uint16_t nb_rx_desc, unsigned int socket_id,
135                 const struct rte_eth_rxconf *rx_conf,
136                 struct rte_mempool *mb_pool);
137
138 int  ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
139                 uint16_t nb_tx_desc, unsigned int socket_id,
140                 const struct rte_eth_txconf *tx_conf);
141
142 int ngbe_dev_rx_init(struct rte_eth_dev *dev);
143
144 void ngbe_dev_tx_init(struct rte_eth_dev *dev);
145
146 int ngbe_dev_rxtx_start(struct rte_eth_dev *dev);
147
148 void ngbe_dev_save_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
149 void ngbe_dev_store_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
150 void ngbe_dev_save_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
151 void ngbe_dev_store_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
152
153 int ngbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
154
155 int ngbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
156
157 int ngbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
158
159 int ngbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
160
161 int
162 ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
163                       struct rte_eth_burst_mode *mode);
164 int
165 ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
166                       struct rte_eth_burst_mode *mode);
167
168 uint16_t ngbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
169                 uint16_t nb_pkts);
170
171 uint16_t ngbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
172                                     uint16_t nb_pkts);
173
174 uint16_t ngbe_recv_pkts_sc_single_alloc(void *rx_queue,
175                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
176 uint16_t ngbe_recv_pkts_sc_bulk_alloc(void *rx_queue,
177                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
178
179 uint16_t ngbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
180                 uint16_t nb_pkts);
181
182 uint16_t ngbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
183                 uint16_t nb_pkts);
184
185 uint16_t ngbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
186                 uint16_t nb_pkts);
187
188 void ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
189                                uint8_t queue, uint8_t msix_vector);
190
191 void ngbe_configure_port(struct rte_eth_dev *dev);
192
193 int
194 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
195                 int wait_to_complete);
196
197 /*
198  * misc function prototypes
199  */
200 void ngbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
201
202 void ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
203
204 void ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
205
206 #define NGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
207 #define NGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
208 #define NGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
209
210 /*
211  *  Default values for Rx/Tx configuration
212  */
213 #define NGBE_DEFAULT_RX_FREE_THRESH  32
214 #define NGBE_DEFAULT_RX_PTHRESH      8
215 #define NGBE_DEFAULT_RX_HTHRESH      8
216 #define NGBE_DEFAULT_RX_WTHRESH      0
217
218 #define NGBE_DEFAULT_TX_FREE_THRESH  32
219 #define NGBE_DEFAULT_TX_PTHRESH      32
220 #define NGBE_DEFAULT_TX_HTHRESH      0
221 #define NGBE_DEFAULT_TX_WTHRESH      0
222
223 /* store statistics names and its offset in stats structure */
224 struct rte_ngbe_xstats_name_off {
225         char name[RTE_ETH_XSTATS_NAME_SIZE];
226         unsigned int offset;
227 };
228
229 const uint32_t *ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
230 int ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
231                                       struct rte_ether_addr *mc_addr_set,
232                                       uint32_t nb_mc_addr);
233 void ngbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
234                 uint16_t queue, bool on);
235 void ngbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
236                                                   int mask);
237 void ngbe_read_stats_registers(struct ngbe_hw *hw,
238                            struct ngbe_hw_stats *hw_stats);
239
240 #endif /* _NGBE_ETHDEV_H_ */