1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #ifndef __OTX2_ETHDEV_H__
6 #define __OTX2_ETHDEV_H__
10 #include <rte_common.h>
11 #include <rte_ethdev.h>
12 #include <rte_kvargs.h>
14 #include <rte_mempool.h>
15 #include <rte_string_fns.h>
18 #include "otx2_common.h"
20 #include "otx2_flow.h"
22 #include "otx2_mempool.h"
27 #define OTX2_ETH_DEV_PMD_VERSION "1.0"
29 /* Ethdev HWCAP and Fixup flags. Use from MSB bits to avoid conflict with dev */
31 /* Minimum CQ size should be 4K */
32 #define OTX2_FIXUP_F_MIN_4K_Q BIT_ULL(63)
33 #define otx2_ethdev_fixup_is_min_4k_q(dev) \
34 ((dev)->hwcap & OTX2_FIXUP_F_MIN_4K_Q)
35 /* Limit CQ being full */
36 #define OTX2_FIXUP_F_LIMIT_CQ_FULL BIT_ULL(62)
37 #define otx2_ethdev_fixup_is_limit_cq_full(dev) \
38 ((dev)->hwcap & OTX2_FIXUP_F_LIMIT_CQ_FULL)
40 /* Used for struct otx2_eth_dev::flags */
41 #define OTX2_LINK_CFG_IN_PROGRESS_F BIT_ULL(0)
43 /* VLAN tag inserted by NIX_TX_VTAG_ACTION.
44 * In Tx space is always reserved for this in FRS.
46 #define NIX_MAX_VTAG_INS 2
47 #define NIX_MAX_VTAG_ACT_SIZE (4 * NIX_MAX_VTAG_INS)
49 /* ETH_HLEN+ETH_FCS+2*VLAN_HLEN */
50 #define NIX_L2_OVERHEAD \
51 (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 8)
53 /* HW config of frame size doesn't include FCS */
54 #define NIX_MAX_HW_FRS 9212
55 #define NIX_MIN_HW_FRS 60
57 /* Since HW FRS includes NPC VTAG insertion space, user has reduced FRS */
59 (NIX_MAX_HW_FRS + RTE_ETHER_CRC_LEN - NIX_MAX_VTAG_ACT_SIZE)
62 (NIX_MIN_HW_FRS + RTE_ETHER_CRC_LEN)
65 (NIX_MAX_FRS - NIX_L2_OVERHEAD)
67 #define NIX_MAX_SQB 512
68 #define NIX_MIN_SQB 32
69 #define NIX_SQB_LIST_SPACE 2
70 #define NIX_RSS_RETA_SIZE_MAX 256
71 /* Group 0 will be used for RSS, 1 -7 will be used for rte_flow RSS action*/
72 #define NIX_RSS_GRPS 8
73 #define NIX_HASH_KEY_SIZE 48 /* 352 Bits */
74 #define NIX_RSS_RETA_SIZE 64
75 #define NIX_RX_MIN_DESC 16
76 #define NIX_RX_MIN_DESC_ALIGN 16
77 #define NIX_RX_NB_SEG_MAX 6
78 #define NIX_CQ_ENTRY_SZ 128
79 #define NIX_CQ_ALIGN 512
80 #define NIX_SQB_LOWER_THRESH 90
81 #define LMT_SLOT_MASK 0x7f
83 /* If PTP is enabled additional SEND MEM DESC is required which
84 * takes 2 words, hence max 7 iova address are possible
86 #if defined(RTE_LIBRTE_IEEE1588)
87 #define NIX_TX_NB_SEG_MAX 7
89 #define NIX_TX_NB_SEG_MAX 9
92 #define NIX_TX_MSEG_SG_DWORDS \
93 ((RTE_ALIGN_MUL_CEIL(NIX_TX_NB_SEG_MAX, 3) / 3) \
96 /* Apply BP when CQ is 75% full */
97 #define NIX_CQ_BP_LEVEL (25 * 256 / 100)
99 #define CQ_OP_STAT_OP_ERR 63
100 #define CQ_OP_STAT_CQ_ERR 46
102 #define OP_ERR BIT_ULL(CQ_OP_STAT_OP_ERR)
103 #define CQ_ERR BIT_ULL(CQ_OP_STAT_CQ_ERR)
105 #define NIX_RSS_OFFLOAD (ETH_RSS_PORT | ETH_RSS_IP | ETH_RSS_UDP |\
106 ETH_RSS_TCP | ETH_RSS_SCTP | \
107 ETH_RSS_TUNNEL | ETH_RSS_L2_PAYLOAD)
109 #define NIX_TX_OFFLOAD_CAPA ( \
110 DEV_TX_OFFLOAD_MBUF_FAST_FREE | \
111 DEV_TX_OFFLOAD_MT_LOCKFREE | \
112 DEV_TX_OFFLOAD_VLAN_INSERT | \
113 DEV_TX_OFFLOAD_QINQ_INSERT | \
114 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
115 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM | \
116 DEV_TX_OFFLOAD_TCP_CKSUM | \
117 DEV_TX_OFFLOAD_UDP_CKSUM | \
118 DEV_TX_OFFLOAD_SCTP_CKSUM | \
119 DEV_TX_OFFLOAD_MULTI_SEGS | \
120 DEV_TX_OFFLOAD_IPV4_CKSUM)
122 #define NIX_RX_OFFLOAD_CAPA ( \
123 DEV_RX_OFFLOAD_CHECKSUM | \
124 DEV_RX_OFFLOAD_SCTP_CKSUM | \
125 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
126 DEV_RX_OFFLOAD_SCATTER | \
127 DEV_RX_OFFLOAD_JUMBO_FRAME | \
128 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM | \
129 DEV_RX_OFFLOAD_VLAN_STRIP | \
130 DEV_RX_OFFLOAD_VLAN_FILTER | \
131 DEV_RX_OFFLOAD_QINQ_STRIP | \
132 DEV_RX_OFFLOAD_TIMESTAMP)
134 #define NIX_DEFAULT_RSS_CTX_GROUP 0
135 #define NIX_DEFAULT_RSS_MCAM_IDX -1
137 #define otx2_ethdev_is_ptp_en(dev) ((dev)->ptp_en)
139 #define NIX_TIMESYNC_TX_CMD_LEN 8
140 /* Additional timesync values. */
141 #define OTX2_CYCLECOUNTER_MASK 0xffffffffffffffffULL
144 nix_q_size_16, /* 16 entries */
145 nix_q_size_64, /* 64 entries */
152 nix_q_size_1M, /* Million entries */
157 struct rte_eth_dev *eth_dev;
161 struct otx2_rss_info {
163 uint32_t flowkey_cfg;
166 uint8_t alg_idx; /* Selected algo index */
167 uint16_t ind_tbl[NIX_RSS_RETA_SIZE_MAX];
168 uint8_t key[NIX_HASH_KEY_SIZE];
171 struct otx2_eth_qconf {
173 struct rte_eth_txconf tx;
174 struct rte_eth_rxconf rx;
181 struct otx2_fc_info {
182 enum rte_eth_fc_mode mode; /**< Link flow control mode */
186 uint16_t bpid[NIX_MAX_CHAN];
189 struct vlan_mkex_info {
190 struct npc_xtract_info la_xtract;
191 struct npc_xtract_info lb_xtract;
192 uint64_t lb_lt_offset;
198 TAILQ_ENTRY(vlan_entry) next;
201 TAILQ_HEAD(otx2_vlan_filter_tbl, vlan_entry);
203 struct otx2_vlan_info {
204 struct otx2_vlan_filter_tbl fltr_tbl;
205 /* MKEX layer info */
206 struct mcam_entry def_tx_mcam_ent;
207 struct mcam_entry def_rx_mcam_ent;
208 struct vlan_mkex_info mkex;
209 /* Default mcam entry that matches vlan packets */
210 uint32_t def_rx_mcam_idx;
211 uint32_t def_tx_mcam_idx;
212 /* MCAM entry that matches double vlan packets */
213 uint32_t qinq_mcam_idx;
214 /* Indices of tx_vtag def registers */
215 uint32_t outer_vlan_idx;
216 uint32_t inner_vlan_idx;
217 uint16_t outer_vlan_tpid;
218 uint16_t inner_vlan_tpid;
220 /* QinQ entry allocated before default one */
221 uint8_t qinq_before_def;
222 uint8_t pvid_insert_on;
223 /* Rx vtag action type */
224 uint8_t vtag_type_idx;
231 struct otx2_eth_dev {
232 OTX2_DEV; /* Base class */
233 MARKER otx2_eth_dev_data_start;
235 uint16_t rx_chan_base;
236 uint16_t tx_chan_base;
239 uint8_t lso_tsov4_idx;
240 uint8_t lso_tsov6_idx;
241 uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
242 uint8_t mkex_pfl_name[MKEX_NAME_LEN];
243 uint8_t max_mac_entries;
250 uint8_t configured_qints;
251 uint8_t configured_nb_rx_qs;
252 uint8_t configured_nb_tx_qs;
253 uint16_t nix_msixoff;
257 uint16_t max_sqb_count;
258 uint16_t rx_offload_flags; /* Selected Rx offload flags(NIX_RX_*_F) */
259 uint64_t rx_offloads;
260 uint16_t tx_offload_flags; /* Selected Tx offload flags(NIX_TX_*_F) */
261 uint64_t tx_offloads;
262 uint64_t rx_offload_capa;
263 uint64_t tx_offload_capa;
264 struct otx2_qint qints_mem[RTE_MAX_QUEUES_PER_PORT];
265 uint16_t txschq[NIX_TXSCH_LVL_CNT];
266 uint16_t txschq_contig[NIX_TXSCH_LVL_CNT];
267 uint16_t txschq_index[NIX_TXSCH_LVL_CNT];
268 uint16_t txschq_contig_index[NIX_TXSCH_LVL_CNT];
269 /* Dis-contiguous queues */
270 uint16_t txschq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
271 /* Contiguous queues */
272 uint16_t txschq_contig_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
273 uint16_t otx2_tm_root_lvl;
275 uint16_t tm_leaf_cnt;
276 struct otx2_nix_tm_node_list node_list;
277 struct otx2_nix_tm_shaper_profile_list shaper_profile_list;
278 struct otx2_rss_info rss_info;
279 struct otx2_fc_info fc_info;
280 uint32_t txmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
281 uint32_t rxmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
282 struct otx2_npc_flow_info npc_flow;
283 struct otx2_vlan_info vlan_info;
284 struct otx2_eth_qconf *tx_qconf;
285 struct otx2_eth_qconf *rx_qconf;
286 struct rte_eth_dev *eth_dev;
287 eth_rx_burst_t rx_pkt_burst_no_offload;
290 struct otx2_timesync_info tstamp;
291 struct rte_timecounter systime_tc;
292 struct rte_timecounter rx_tstamp_tc;
293 struct rte_timecounter tx_tstamp_tc;
294 } __rte_cache_aligned;
296 struct otx2_eth_txq {
298 int64_t fc_cache_pkts;
303 uint16_t sqes_per_sqb_log2;
304 int16_t nb_sqb_bufs_adj;
305 MARKER slow_path_start;
306 uint16_t nb_sqb_bufs;
309 struct otx2_eth_dev *dev;
310 struct rte_mempool *sqb_pool;
311 struct otx2_eth_qconf qconf;
312 } __rte_cache_aligned;
314 struct otx2_eth_rxq {
315 uint64_t mbuf_initializer;
326 struct otx2_timesync_info *tstamp;
327 MARKER slow_path_start;
331 struct rte_mempool *pool;
332 enum nix_q_size_e qsize;
333 struct rte_eth_dev *eth_dev;
334 struct otx2_eth_qconf qconf;
335 } __rte_cache_aligned;
337 static inline struct otx2_eth_dev *
338 otx2_eth_pmd_priv(struct rte_eth_dev *eth_dev)
340 return eth_dev->data->dev_private;
344 void otx2_nix_info_get(struct rte_eth_dev *eth_dev,
345 struct rte_eth_dev_info *dev_info);
346 int otx2_nix_dev_filter_ctrl(struct rte_eth_dev *eth_dev,
347 enum rte_filter_type filter_type,
348 enum rte_filter_op filter_op, void *arg);
349 int otx2_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
351 int otx2_nix_get_module_info(struct rte_eth_dev *eth_dev,
352 struct rte_eth_dev_module_info *modinfo);
353 int otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
354 struct rte_dev_eeprom_info *info);
355 int otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool);
356 void otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
357 struct rte_eth_rxq_info *qinfo);
358 void otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
359 struct rte_eth_txq_info *qinfo);
360 uint32_t otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t qidx);
361 int otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt);
362 int otx2_nix_rx_descriptor_done(void *rxq, uint16_t offset);
363 int otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset);
365 void otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en);
366 void otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev);
367 void otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev);
368 void otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev);
369 void otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev);
370 int otx2_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx);
371 int otx2_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx);
372 uint64_t otx2_nix_rxq_mbuf_setup(struct otx2_eth_dev *dev, uint16_t port_id);
375 void otx2_nix_toggle_flag_link_cfg(struct otx2_eth_dev *dev, bool set);
376 int otx2_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete);
377 void otx2_eth_dev_link_status_update(struct otx2_dev *dev,
378 struct cgx_link_user_info *link);
381 int otx2_nix_register_irqs(struct rte_eth_dev *eth_dev);
382 int oxt2_nix_register_queue_irqs(struct rte_eth_dev *eth_dev);
383 void otx2_nix_unregister_irqs(struct rte_eth_dev *eth_dev);
384 void oxt2_nix_unregister_queue_irqs(struct rte_eth_dev *eth_dev);
387 int otx2_nix_reg_dump(struct otx2_eth_dev *dev, uint64_t *data);
388 int otx2_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
389 struct rte_dev_reg_info *regs);
390 int otx2_nix_queues_ctx_dump(struct rte_eth_dev *eth_dev);
391 void otx2_nix_cqe_dump(const struct nix_cqe_hdr_s *cq);
394 int otx2_nix_dev_stats_get(struct rte_eth_dev *eth_dev,
395 struct rte_eth_stats *stats);
396 void otx2_nix_dev_stats_reset(struct rte_eth_dev *eth_dev);
398 int otx2_nix_queue_stats_mapping(struct rte_eth_dev *dev,
399 uint16_t queue_id, uint8_t stat_idx,
401 int otx2_nix_xstats_get(struct rte_eth_dev *eth_dev,
402 struct rte_eth_xstat *xstats, unsigned int n);
403 int otx2_nix_xstats_get_names(struct rte_eth_dev *eth_dev,
404 struct rte_eth_xstat_name *xstats_names,
406 void otx2_nix_xstats_reset(struct rte_eth_dev *eth_dev);
408 int otx2_nix_xstats_get_by_id(struct rte_eth_dev *eth_dev,
410 uint64_t *values, unsigned int n);
411 int otx2_nix_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
412 struct rte_eth_xstat_name *xstats_names,
413 const uint64_t *ids, unsigned int limit);
416 void otx2_nix_rss_set_key(struct otx2_eth_dev *dev,
417 uint8_t *key, uint32_t key_len);
418 uint32_t otx2_rss_ethdev_to_nix(struct otx2_eth_dev *dev,
419 uint64_t ethdev_rss, uint8_t rss_level);
420 int otx2_rss_set_hf(struct otx2_eth_dev *dev,
421 uint32_t flowkey_cfg, uint8_t *alg_idx,
422 uint8_t group, int mcam_index);
423 int otx2_nix_rss_tbl_init(struct otx2_eth_dev *dev, uint8_t group,
425 int otx2_nix_rss_config(struct rte_eth_dev *eth_dev);
427 int otx2_nix_dev_reta_update(struct rte_eth_dev *eth_dev,
428 struct rte_eth_rss_reta_entry64 *reta_conf,
430 int otx2_nix_dev_reta_query(struct rte_eth_dev *eth_dev,
431 struct rte_eth_rss_reta_entry64 *reta_conf,
433 int otx2_nix_rss_hash_update(struct rte_eth_dev *eth_dev,
434 struct rte_eth_rss_conf *rss_conf);
436 int otx2_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
437 struct rte_eth_rss_conf *rss_conf);
440 int otx2_cgx_rxtx_start(struct otx2_eth_dev *dev);
441 int otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev);
442 int otx2_cgx_mac_addr_set(struct rte_eth_dev *eth_dev,
443 struct rte_ether_addr *addr);
446 int otx2_nix_flow_ctrl_get(struct rte_eth_dev *eth_dev,
447 struct rte_eth_fc_conf *fc_conf);
449 int otx2_nix_flow_ctrl_set(struct rte_eth_dev *eth_dev,
450 struct rte_eth_fc_conf *fc_conf);
452 int otx2_nix_rxchan_bpid_cfg(struct rte_eth_dev *eth_dev, bool enb);
454 int otx2_nix_update_flow_ctrl_mode(struct rte_eth_dev *eth_dev);
457 int otx2_nix_vlan_offload_init(struct rte_eth_dev *eth_dev);
458 int otx2_nix_vlan_fini(struct rte_eth_dev *eth_dev);
459 int otx2_nix_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask);
460 void otx2_nix_vlan_update_promisc(struct rte_eth_dev *eth_dev, int enable);
461 int otx2_nix_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
463 void otx2_nix_vlan_strip_queue_set(struct rte_eth_dev *dev,
464 uint16_t queue, int on);
465 int otx2_nix_vlan_tpid_set(struct rte_eth_dev *eth_dev,
466 enum rte_vlan_type type, uint16_t tpid);
467 int otx2_nix_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
469 /* Lookup configuration */
470 void *otx2_nix_fastpath_lookup_mem_get(void);
473 const uint32_t *otx2_nix_supported_ptypes_get(struct rte_eth_dev *dev);
475 /* Mac address handling */
476 int otx2_nix_mac_addr_set(struct rte_eth_dev *eth_dev,
477 struct rte_ether_addr *addr);
478 int otx2_nix_mac_addr_get(struct rte_eth_dev *eth_dev, uint8_t *addr);
479 int otx2_nix_mac_addr_add(struct rte_eth_dev *eth_dev,
480 struct rte_ether_addr *addr,
481 uint32_t index, uint32_t pool);
482 void otx2_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index);
483 int otx2_cgx_mac_max_entries_get(struct otx2_eth_dev *dev);
486 int otx2_ethdev_parse_devargs(struct rte_devargs *devargs,
487 struct otx2_eth_dev *dev);
489 /* Rx and Tx routines */
490 void otx2_eth_set_rx_function(struct rte_eth_dev *eth_dev);
491 void otx2_eth_set_tx_function(struct rte_eth_dev *eth_dev);
492 void otx2_nix_form_default_desc(struct otx2_eth_txq *txq);
494 /* Timesync - PTP routines */
495 int otx2_nix_timesync_enable(struct rte_eth_dev *eth_dev);
496 int otx2_nix_timesync_disable(struct rte_eth_dev *eth_dev);
497 int otx2_nix_timesync_read_rx_timestamp(struct rte_eth_dev *eth_dev,
498 struct timespec *timestamp,
500 int otx2_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev,
501 struct timespec *timestamp);
502 int otx2_nix_timesync_adjust_time(struct rte_eth_dev *eth_dev, int64_t delta);
503 int otx2_nix_timesync_write_time(struct rte_eth_dev *eth_dev,
504 const struct timespec *ts);
505 int otx2_nix_timesync_read_time(struct rte_eth_dev *eth_dev,
506 struct timespec *ts);
507 int otx2_eth_dev_ptp_info_update(struct otx2_dev *dev, bool ptp_en);
509 #endif /* __OTX2_ETHDEV_H__ */