1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
6 #ifndef _NGBE_ETHDEV_H_
7 #define _NGBE_ETHDEV_H_
9 #include "ngbe_ptypes.h"
11 #include <rte_ethdev.h>
12 #include <rte_ethdev_core.h>
14 /* need update link, bit flag */
15 #define NGBE_FLAG_NEED_LINK_UPDATE ((uint32_t)(1 << 0))
16 #define NGBE_FLAG_MAILBOX ((uint32_t)(1 << 1))
17 #define NGBE_FLAG_PHY_INTERRUPT ((uint32_t)(1 << 2))
18 #define NGBE_FLAG_MACSEC ((uint32_t)(1 << 3))
19 #define NGBE_FLAG_NEED_LINK_CONFIG ((uint32_t)(1 << 4))
21 #define NGBE_VFTA_SIZE 128
22 #define NGBE_HKEY_MAX_INDEX 10
23 /*Default value of Max Rx Queue*/
24 #define NGBE_MAX_RX_QUEUE_NUM 8
27 #define NBBY 8 /* number of bits in a byte */
29 #define NGBE_HWSTRIP_BITMAP_SIZE \
30 (NGBE_MAX_RX_QUEUE_NUM / (sizeof(uint32_t) * NBBY))
32 #define NGBE_QUEUE_ITR_INTERVAL_DEFAULT 500 /* 500us */
34 /* The overhead from MTU to max frame size. */
35 #define NGBE_ETH_OVERHEAD (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
37 #define NGBE_RSS_OFFLOAD_ALL ( \
39 RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
40 RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
42 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
43 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
44 RTE_ETH_RSS_IPV6_EX | \
45 RTE_ETH_RSS_IPV6_TCP_EX | \
46 RTE_ETH_RSS_IPV6_UDP_EX)
48 #define NGBE_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
49 #define NGBE_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
51 /* structure for interrupt relative data */
52 struct ngbe_interrupt {
55 uint32_t mask_misc_orig; /* save mask during delayed handler */
57 uint64_t mask_orig; /* save mask during delayed handler */
60 #define NGBE_NB_STAT_MAPPING 32
61 #define NB_QMAP_FIELDS_PER_QSM_REG 4
62 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
63 struct ngbe_stat_mappings {
64 uint32_t tqsm[NGBE_NB_STAT_MAPPING];
65 uint32_t rqsm[NGBE_NB_STAT_MAPPING];
69 uint32_t vfta[NGBE_VFTA_SIZE];
73 uint32_t bitmap[NGBE_HWSTRIP_BITMAP_SIZE];
77 * Response sent back to ngbe driver from user app after callback
79 enum ngbe_mb_event_rsp {
80 NGBE_MB_EVENT_NOOP_ACK, /**< skip mbox request and ACK */
81 NGBE_MB_EVENT_NOOP_NACK, /**< skip mbox request and NACK */
82 NGBE_MB_EVENT_PROCEED, /**< proceed with mbox request */
83 NGBE_MB_EVENT_MAX /**< max value of this enum */
87 * Data sent to the user application when the callback is executed.
89 struct ngbe_mb_event_param {
90 uint16_t vfid; /**< Virtual Function number */
91 uint16_t msg_type; /**< VF to PF message type, defined in ngbe_mbx.h */
92 uint16_t retval; /**< return value */
93 void *msg; /**< pointer to message */
97 * VF data which used by PF host only
99 #define NGBE_MAX_VF_MC_ENTRIES 30
101 struct ngbe_uta_info {
102 uint8_t uc_filter_type;
104 uint32_t uta_shadow[NGBE_MAX_UTA];
107 struct ngbe_vf_info {
108 uint8_t vf_mac_addresses[RTE_ETHER_ADDR_LEN];
109 uint16_t vf_mc_hashes[NGBE_MAX_VF_MC_ENTRIES];
110 uint16_t num_vf_mc_hashes;
114 uint16_t switch_domain_id;
120 * Structure to store private data for each driver instance (for each port).
122 struct ngbe_adapter {
124 struct ngbe_hw_stats stats;
125 struct ngbe_interrupt intr;
126 struct ngbe_stat_mappings stat_mappings;
127 struct ngbe_vfta shadow_vfta;
128 struct ngbe_hwstrip hwstrip;
129 struct ngbe_vf_info *vfdata;
130 struct ngbe_uta_info uta_info;
131 bool rx_bulk_alloc_allowed;
132 struct rte_timecounter systime_tc;
133 struct rte_timecounter rx_tstamp_tc;
134 struct rte_timecounter tx_tstamp_tc;
136 /* For RSS reta table update */
137 uint8_t rss_reta_updated;
140 static inline struct ngbe_adapter *
141 ngbe_dev_adapter(struct rte_eth_dev *dev)
143 struct ngbe_adapter *ad = dev->data->dev_private;
148 static inline struct ngbe_hw *
149 ngbe_dev_hw(struct rte_eth_dev *dev)
151 struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
152 struct ngbe_hw *hw = &ad->hw;
157 #define NGBE_DEV_STATS(dev) \
158 (&((struct ngbe_adapter *)(dev)->data->dev_private)->stats)
160 static inline struct ngbe_interrupt *
161 ngbe_dev_intr(struct rte_eth_dev *dev)
163 struct ngbe_adapter *ad = ngbe_dev_adapter(dev);
164 struct ngbe_interrupt *intr = &ad->intr;
169 #define NGBE_DEV_STAT_MAPPINGS(dev) \
170 (&((struct ngbe_adapter *)(dev)->data->dev_private)->stat_mappings)
172 #define NGBE_DEV_VFTA(dev) \
173 (&((struct ngbe_adapter *)(dev)->data->dev_private)->shadow_vfta)
175 #define NGBE_DEV_HWSTRIP(dev) \
176 (&((struct ngbe_adapter *)(dev)->data->dev_private)->hwstrip)
178 #define NGBE_DEV_VFDATA(dev) \
179 (&((struct ngbe_adapter *)(dev)->data->dev_private)->vfdata)
181 #define NGBE_DEV_UTA_INFO(dev) \
182 (&((struct ngbe_adapter *)(dev)->data->dev_private)->uta_info)
185 * Rx/Tx function prototypes
187 void ngbe_dev_clear_queues(struct rte_eth_dev *dev);
189 void ngbe_dev_free_queues(struct rte_eth_dev *dev);
191 void ngbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
193 void ngbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
195 int ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
196 uint16_t nb_rx_desc, unsigned int socket_id,
197 const struct rte_eth_rxconf *rx_conf,
198 struct rte_mempool *mb_pool);
200 int ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
201 uint16_t nb_tx_desc, unsigned int socket_id,
202 const struct rte_eth_txconf *tx_conf);
204 uint32_t ngbe_dev_rx_queue_count(void *rx_queue);
206 int ngbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);
207 int ngbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);
209 int ngbe_dev_rx_init(struct rte_eth_dev *dev);
211 void ngbe_dev_tx_init(struct rte_eth_dev *dev);
213 int ngbe_dev_rxtx_start(struct rte_eth_dev *dev);
215 void ngbe_dev_save_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
216 void ngbe_dev_store_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id);
217 void ngbe_dev_save_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
218 void ngbe_dev_store_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id);
220 int ngbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
222 int ngbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
224 int ngbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
226 int ngbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
228 void ngbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
229 struct rte_eth_rxq_info *qinfo);
231 void ngbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
232 struct rte_eth_txq_info *qinfo);
235 ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
236 struct rte_eth_burst_mode *mode);
238 ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
239 struct rte_eth_burst_mode *mode);
241 uint16_t ngbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
244 uint16_t ngbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
247 uint16_t ngbe_recv_pkts_sc_single_alloc(void *rx_queue,
248 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
249 uint16_t ngbe_recv_pkts_sc_bulk_alloc(void *rx_queue,
250 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
252 uint16_t ngbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
255 uint16_t ngbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
258 uint16_t ngbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
261 int ngbe_dev_rss_hash_update(struct rte_eth_dev *dev,
262 struct rte_eth_rss_conf *rss_conf);
264 int ngbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
265 struct rte_eth_rss_conf *rss_conf);
267 void ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
268 uint8_t queue, uint8_t msix_vector);
270 void ngbe_configure_port(struct rte_eth_dev *dev);
273 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
274 int wait_to_complete);
277 * misc function prototypes
279 void ngbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
281 void ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
283 void ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
285 int ngbe_pf_host_init(struct rte_eth_dev *eth_dev);
287 void ngbe_pf_host_uninit(struct rte_eth_dev *eth_dev);
289 void ngbe_pf_mbx_process(struct rte_eth_dev *eth_dev);
291 int ngbe_pf_host_configure(struct rte_eth_dev *eth_dev);
293 /* High threshold controlling when to start sending XOFF frames. */
294 #define NGBE_FC_XOFF_HITH 128 /*KB*/
295 /* Low threshold controlling when to start sending XON frames. */
296 #define NGBE_FC_XON_LOTH 64 /*KB*/
298 /* Timer value included in XOFF frames. */
299 #define NGBE_FC_PAUSE_TIME 0x680
301 #define NGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
302 #define NGBE_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
303 #define NGBE_VMDQ_NUM_UC_MAC 4096 /* Maximum nb. of UC MAC addr. */
306 * Default values for Rx/Tx configuration
308 #define NGBE_DEFAULT_RX_FREE_THRESH 32
309 #define NGBE_DEFAULT_RX_PTHRESH 8
310 #define NGBE_DEFAULT_RX_HTHRESH 8
311 #define NGBE_DEFAULT_RX_WTHRESH 0
313 #define NGBE_DEFAULT_TX_FREE_THRESH 32
314 #define NGBE_DEFAULT_TX_PTHRESH 32
315 #define NGBE_DEFAULT_TX_HTHRESH 0
316 #define NGBE_DEFAULT_TX_WTHRESH 0
318 /* Additional timesync values. */
319 #define NGBE_INCVAL_1GB 0x2000000 /* all speed is same in Emerald */
320 #define NGBE_INCVAL_SHIFT_1GB 22 /* all speed is same in Emerald */
322 #define NGBE_CYCLECOUNTER_MASK 0xffffffffffffffffULL
324 /* store statistics names and its offset in stats structure */
325 struct rte_ngbe_xstats_name_off {
326 char name[RTE_ETH_XSTATS_NAME_SIZE];
330 const uint32_t *ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
331 int ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
332 struct rte_ether_addr *mc_addr_set,
333 uint32_t nb_mc_addr);
334 int ngbe_dev_rss_reta_update(struct rte_eth_dev *dev,
335 struct rte_eth_rss_reta_entry64 *reta_conf,
337 int ngbe_dev_rss_reta_query(struct rte_eth_dev *dev,
338 struct rte_eth_rss_reta_entry64 *reta_conf,
340 void ngbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
341 uint16_t queue, bool on);
342 void ngbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
344 void ngbe_dev_setup_link_alarm_handler(void *param);
345 void ngbe_read_stats_registers(struct ngbe_hw *hw,
346 struct ngbe_hw_stats *hw_stats);
348 #endif /* _NGBE_ETHDEV_H_ */