1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2021 Marvell International Ltd.
3 * Copyright(c) 2017-2021 Semihalf.
7 #include <rte_string_fns.h>
8 #include <ethdev_driver.h>
9 #include <rte_kvargs.h>
11 #include <rte_malloc.h>
12 #include <rte_bus_vdev.h>
15 #include <linux/ethtool.h>
16 #include <linux/sockios.h>
18 #include <net/if_arp.h>
19 #include <sys/ioctl.h>
20 #include <sys/socket.h>
22 #include <sys/types.h>
24 #include <rte_mvep_common.h>
25 #include "mrvl_ethdev.h"
27 #include "mrvl_flow.h"
31 /* bitmask with reserved hifs */
32 #define MRVL_MUSDK_HIFS_RESERVED 0x0F
33 /* bitmask with reserved bpools */
34 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07
35 /* bitmask with reserved kernel RSS tables */
36 #define MRVL_MUSDK_RSS_RESERVED 0x0F
37 /* maximum number of available hifs */
38 #define MRVL_MUSDK_HIFS_MAX 9
41 #define MRVL_MUSDK_PREFETCH_SHIFT 2
43 /* TCAM has 25 entries reserved for uc/mc filter entries
44 * + 1 for primary mac address
46 #define MRVL_MAC_ADDRS_MAX (1 + 25)
47 #define MRVL_MATCH_LEN 16
48 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
49 /* Maximum allowable packet size */
50 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
52 #define MRVL_IFACE_NAME_ARG "iface"
53 #define MRVL_CFG_ARG "cfg"
55 #define MRVL_ARP_LENGTH 28
57 #define MRVL_COOKIE_ADDR_INVALID ~0ULL
58 #define MRVL_COOKIE_HIGH_ADDR_MASK 0xffffff0000000000
60 /** Port Rx offload capabilities */
61 #define MRVL_RX_OFFLOADS (DEV_RX_OFFLOAD_VLAN_FILTER | \
62 DEV_RX_OFFLOAD_CHECKSUM)
64 /** Port Tx offloads capabilities */
65 #define MRVL_TX_OFFLOAD_CHECKSUM (DEV_TX_OFFLOAD_IPV4_CKSUM | \
66 DEV_TX_OFFLOAD_UDP_CKSUM | \
67 DEV_TX_OFFLOAD_TCP_CKSUM)
68 #define MRVL_TX_OFFLOADS (MRVL_TX_OFFLOAD_CHECKSUM | \
69 DEV_TX_OFFLOAD_MULTI_SEGS)
71 #define MRVL_TX_PKT_OFFLOADS (PKT_TX_IP_CKSUM | \
75 static const char * const valid_args[] = {
81 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
82 static struct pp2_hif *hifs[RTE_MAX_LCORE];
83 static int used_bpools[PP2_NUM_PKT_PROC] = {
84 [0 ... PP2_NUM_PKT_PROC - 1] = MRVL_MUSDK_BPOOLS_RESERVED
87 static struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
88 static int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
89 static uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
90 static int dummy_pool_id[PP2_NUM_PKT_PROC];
91 struct pp2_bpool *dummy_pool[PP2_NUM_PKT_PROC] = {0};
94 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
99 * To use buffer harvesting based on loopback port shadow queue structure
100 * was introduced for buffers information bookkeeping.
102 * Before sending the packet, related buffer information (pp2_buff_inf) is
103 * stored in shadow queue. After packet is transmitted no longer used
104 * packet buffer is released back to it's original hardware pool,
105 * on condition it originated from interface.
106 * In case it was generated by application itself i.e: mbuf->port field is
107 * 0xff then its released to software mempool.
109 struct mrvl_shadow_txq {
110 int head; /* write index - used when sending buffers */
111 int tail; /* read index - used when releasing buffers */
112 u16 size; /* queue occupied size */
113 u16 num_to_release; /* number of descriptors sent, that can be
116 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
120 struct mrvl_priv *priv;
121 struct rte_mempool *mp;
130 struct mrvl_priv *priv;
134 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
135 int tx_deferred_start;
138 static int mrvl_lcore_first;
139 static int mrvl_lcore_last;
140 static int mrvl_dev_num;
142 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
143 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
144 struct pp2_hif *hif, unsigned int core_id,
145 struct mrvl_shadow_txq *sq, int qid, int force);
147 static uint16_t mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
149 static uint16_t mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
151 static int rte_pmd_mrvl_remove(struct rte_vdev_device *vdev);
152 static void mrvl_deinit_pp2(void);
153 static void mrvl_deinit_hifs(void);
156 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
157 uint32_t index, uint32_t vmdq __rte_unused);
159 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
161 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
162 static int mrvl_promiscuous_enable(struct rte_eth_dev *dev);
163 static int mrvl_allmulticast_enable(struct rte_eth_dev *dev);
165 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf);
167 #define MRVL_XSTATS_TBL_ENTRY(name) { \
168 #name, offsetof(struct pp2_ppio_statistics, name), \
169 sizeof(((struct pp2_ppio_statistics *)0)->name) \
172 /* Table with xstats data */
177 } mrvl_xstats_tbl[] = {
178 MRVL_XSTATS_TBL_ENTRY(rx_bytes),
179 MRVL_XSTATS_TBL_ENTRY(rx_packets),
180 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets),
181 MRVL_XSTATS_TBL_ENTRY(rx_errors),
182 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped),
183 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped),
184 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped),
185 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped),
186 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped),
187 MRVL_XSTATS_TBL_ENTRY(tx_bytes),
188 MRVL_XSTATS_TBL_ENTRY(tx_packets),
189 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets),
190 MRVL_XSTATS_TBL_ENTRY(tx_errors)
194 mrvl_reserve_bit(int *bitmap, int max)
196 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
207 mrvl_pp2_fixup_init(void)
209 struct pp2_bpool_params bpool_params;
213 memset(dummy_pool, 0, sizeof(dummy_pool));
214 for (i = 0; i < pp2_get_num_inst(); i++) {
215 dummy_pool_id[i] = mrvl_reserve_bit(&used_bpools[i],
216 PP2_BPOOL_NUM_POOLS);
217 if (dummy_pool_id[i] < 0) {
218 MRVL_LOG(ERR, "Can't find free pool\n");
222 memset(name, 0, sizeof(name));
223 snprintf(name, sizeof(name), "pool-%d:%d", i, dummy_pool_id[i]);
224 memset(&bpool_params, 0, sizeof(bpool_params));
225 bpool_params.match = name;
226 bpool_params.buff_len = MRVL_PKT_OFFS;
227 bpool_params.dummy_short_pool = 1;
228 err = pp2_bpool_init(&bpool_params, &dummy_pool[i]);
229 if (err != 0 || !dummy_pool[i]) {
230 MRVL_LOG(ERR, "BPool init failed!\n");
231 used_bpools[i] &= ~(1 << dummy_pool_id[i]);
240 * Initialize packet processor.
243 * 0 on success, negative error value otherwise.
248 struct pp2_init_params init_params;
251 memset(&init_params, 0, sizeof(init_params));
252 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
253 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
254 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
255 if (mrvl_cfg && mrvl_cfg->pp2_cfg.prs_udfs.num_udfs)
256 memcpy(&init_params.prs_udfs, &mrvl_cfg->pp2_cfg.prs_udfs,
257 sizeof(struct pp2_parse_udfs));
258 err = pp2_init(&init_params);
260 MRVL_LOG(ERR, "PP2 init failed");
264 err = mrvl_pp2_fixup_init();
266 MRVL_LOG(ERR, "PP2 fixup init failed");
274 mrvl_pp2_fixup_deinit(void)
278 for (i = 0; i < PP2_NUM_PKT_PROC; i++) {
281 pp2_bpool_deinit(dummy_pool[i]);
282 used_bpools[i] &= ~(1 << dummy_pool_id[i]);
287 * Deinitialize packet processor.
290 * 0 on success, negative error value otherwise.
293 mrvl_deinit_pp2(void)
295 mrvl_pp2_fixup_deinit();
300 mrvl_fill_shadowq(struct mrvl_shadow_txq *sq, struct rte_mbuf *buf)
302 sq->ent[sq->head].buff.cookie = (uint64_t)buf;
303 sq->ent[sq->head].buff.addr = buf ?
304 rte_mbuf_data_iova_default(buf) : 0;
306 sq->ent[sq->head].bpool =
307 (unlikely(!buf || buf->port >= RTE_MAX_ETHPORTS ||
308 buf->refcnt > 1)) ? NULL :
309 mrvl_port_to_bpool_lookup[buf->port];
311 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
316 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
319 mrvl_deinit_hifs(void)
323 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
325 pp2_hif_deinit(hifs[i]);
327 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
328 memset(hifs, 0, sizeof(hifs));
332 mrvl_fill_desc(struct pp2_ppio_desc *desc, struct rte_mbuf *buf)
334 pp2_ppio_outq_desc_reset(desc);
335 pp2_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf));
336 pp2_ppio_outq_desc_set_pkt_offset(desc, 0);
337 pp2_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf));
341 mrvl_get_bpool_size(int pp2_id, int pool_id)
346 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
347 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
353 mrvl_init_hif(int core_id)
355 struct pp2_hif_params params;
356 char match[MRVL_MATCH_LEN];
359 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
361 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
365 snprintf(match, sizeof(match), "hif-%d", ret);
366 memset(¶ms, 0, sizeof(params));
367 params.match = match;
368 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
369 ret = pp2_hif_init(¶ms, &hifs[core_id]);
371 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id);
378 static inline struct pp2_hif*
379 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
383 if (likely(hifs[core_id] != NULL))
384 return hifs[core_id];
386 rte_spinlock_lock(&priv->lock);
388 ret = mrvl_init_hif(core_id);
390 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
394 if (core_id < mrvl_lcore_first)
395 mrvl_lcore_first = core_id;
397 if (core_id > mrvl_lcore_last)
398 mrvl_lcore_last = core_id;
400 rte_spinlock_unlock(&priv->lock);
402 return hifs[core_id];
406 * Set tx burst function according to offload flag
409 * Pointer to Ethernet device structure.
412 mrvl_set_tx_function(struct rte_eth_dev *dev)
414 struct mrvl_priv *priv = dev->data->dev_private;
416 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
417 if (priv->multiseg) {
418 RTE_LOG(INFO, PMD, "Using multi-segment tx callback\n");
419 dev->tx_pkt_burst = mrvl_tx_sg_pkt_burst;
421 RTE_LOG(INFO, PMD, "Using single-segment tx callback\n");
422 dev->tx_pkt_burst = mrvl_tx_pkt_burst;
427 * Configure rss based on dpdk rss configuration.
430 * Pointer to private structure.
432 * Pointer to RSS configuration.
435 * 0 on success, negative error value otherwise.
438 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
440 if (rss_conf->rss_key)
441 MRVL_LOG(WARNING, "Changing hash key is not supported");
443 if (rss_conf->rss_hf == 0) {
444 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
445 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
446 priv->ppio_params.inqs_params.hash_type =
447 PP2_PPIO_HASH_T_2_TUPLE;
448 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
449 priv->ppio_params.inqs_params.hash_type =
450 PP2_PPIO_HASH_T_5_TUPLE;
451 priv->rss_hf_tcp = 1;
452 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
453 priv->ppio_params.inqs_params.hash_type =
454 PP2_PPIO_HASH_T_5_TUPLE;
455 priv->rss_hf_tcp = 0;
464 * Ethernet device configuration.
466 * Prepare the driver for a given number of TX and RX queues and
470 * Pointer to Ethernet device structure.
473 * 0 on success, negative error value otherwise.
476 mrvl_dev_configure(struct rte_eth_dev *dev)
478 struct mrvl_priv *priv = dev->data->dev_private;
482 MRVL_LOG(INFO, "Device reconfiguration is not supported");
486 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
487 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
488 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d",
489 dev->data->dev_conf.rxmode.mq_mode);
493 if (dev->data->dev_conf.rxmode.split_hdr_size) {
494 MRVL_LOG(INFO, "Split headers not supported");
498 if (dev->data->dev_conf.rxmode.mtu > priv->max_mtu) {
499 MRVL_LOG(ERR, "MTU %u is larger than max_mtu %u\n",
500 dev->data->dev_conf.rxmode.mtu,
505 if (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
508 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
509 dev->data->nb_rx_queues);
513 ret = mrvl_configure_txqs(priv, dev->data->port_id,
514 dev->data->nb_tx_queues);
518 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
519 priv->ppio_params.maintain_stats = 1;
520 priv->nb_rx_queues = dev->data->nb_rx_queues;
522 ret = mrvl_tm_init(dev);
526 if (dev->data->nb_rx_queues == 1 &&
527 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
528 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue");
529 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
530 priv->configured = 1;
534 ret = mrvl_configure_rss(priv,
535 &dev->data->dev_conf.rx_adv_conf.rss_conf);
539 priv->configured = 1;
545 * DPDK callback to change the MTU.
547 * Setting the MTU affects hardware MRU (packets larger than the MRU
551 * Pointer to Ethernet device structure.
556 * 0 on success, negative error value otherwise.
559 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
561 struct mrvl_priv *priv = dev->data->dev_private;
563 uint16_t mbuf_data_size = 0; /* SW buffer size */
566 mru = MRVL_PP2_MTU_TO_MRU(mtu);
568 * min_rx_buf_size is equal to mbuf data size
569 * if pmd didn't set it differently
571 mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
573 * - setting mru greater than the mbuf size resulting in
574 * hw and sw buffer size mismatch
575 * - setting mtu that requires the support of scattered packets
576 * when this feature has not been enabled/supported so far
577 * (TODO check scattered_rx flag here once scattered RX is supported).
579 if (mru - RTE_ETHER_CRC_LEN + MRVL_PKT_OFFS > mbuf_data_size) {
580 mru = mbuf_data_size + RTE_ETHER_CRC_LEN - MRVL_PKT_OFFS;
581 mtu = MRVL_PP2_MRU_TO_MTU(mru);
582 MRVL_LOG(WARNING, "MTU too big, max MTU possible limitted "
583 "by current mbuf size: %u. Set MTU to %u, MRU to %u",
584 mbuf_data_size, mtu, mru);
587 if (mtu < RTE_ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX) {
588 MRVL_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru);
595 ret = pp2_ppio_set_mru(priv->ppio, mru);
597 MRVL_LOG(ERR, "Failed to change MRU");
601 ret = pp2_ppio_set_mtu(priv->ppio, mtu);
603 MRVL_LOG(ERR, "Failed to change MTU");
611 * DPDK callback to bring the link up.
614 * Pointer to Ethernet device structure.
617 * 0 on success, negative error value otherwise.
620 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
622 struct mrvl_priv *priv = dev->data->dev_private;
626 dev->data->dev_link.link_status = ETH_LINK_UP;
630 ret = pp2_ppio_enable(priv->ppio);
635 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
636 * as pp2_ppio_enable() changes port->t_mode from default 0 to
637 * PP2_TRAFFIC_INGRESS_EGRESS.
639 * Set mtu to default DPDK value here.
641 ret = mrvl_mtu_set(dev, dev->data->mtu);
643 pp2_ppio_disable(priv->ppio);
647 dev->data->dev_link.link_status = ETH_LINK_UP;
652 * DPDK callback to bring the link down.
655 * Pointer to Ethernet device structure.
658 * 0 on success, negative error value otherwise.
661 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
663 struct mrvl_priv *priv = dev->data->dev_private;
667 dev->data->dev_link.link_status = ETH_LINK_DOWN;
670 ret = pp2_ppio_disable(priv->ppio);
674 dev->data->dev_link.link_status = ETH_LINK_DOWN;
679 * DPDK callback to start tx queue.
682 * Pointer to Ethernet device structure.
684 * Transmit queue index.
687 * 0 on success, negative error value otherwise.
690 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
692 struct mrvl_priv *priv = dev->data->dev_private;
698 /* passing 1 enables given tx queue */
699 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1);
701 MRVL_LOG(ERR, "Failed to start txq %d", queue_id);
705 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
711 * DPDK callback to stop tx queue.
714 * Pointer to Ethernet device structure.
716 * Transmit queue index.
719 * 0 on success, negative error value otherwise.
722 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
724 struct mrvl_priv *priv = dev->data->dev_private;
730 /* passing 0 disables given tx queue */
731 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0);
733 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id);
737 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
743 * Populate VLAN Filter configuration.
746 * Pointer to Ethernet device structure.
751 * 0 on success, negative error value otherwise.
753 static int mrvl_populate_vlan_table(struct rte_eth_dev *dev, int on)
757 struct rte_vlan_filter_conf *vfc;
759 vfc = &dev->data->vlan_filter_conf;
760 for (j = 0; j < RTE_DIM(vfc->ids); j++) {
763 uint64_t ids = vfc->ids[j];
770 /* count trailing zeroes */
771 vbit = ~ids & (ids - 1);
772 /* clear least significant bit set */
773 ids ^= (ids ^ (ids - 1)) ^ vbit;
776 ret = mrvl_vlan_filter_set(dev, vlan, on);
778 MRVL_LOG(ERR, "Failed to setup VLAN filter\n");
788 * DPDK callback to start the device.
791 * Pointer to Ethernet device structure.
794 * 0 on success, negative errno value on failure.
797 mrvl_dev_start(struct rte_eth_dev *dev)
799 struct mrvl_priv *priv = dev->data->dev_private;
800 char match[MRVL_MATCH_LEN];
801 int ret = 0, i, def_init_size;
802 struct rte_ether_addr *mac_addr;
805 return mrvl_dev_set_link_up(dev);
807 snprintf(match, sizeof(match), "ppio-%d:%d",
808 priv->pp_id, priv->ppio_id);
809 priv->ppio_params.match = match;
810 priv->ppio_params.eth_start_hdr = PP2_PPIO_HDR_ETH;
811 priv->forward_bad_frames = 0;
812 priv->fill_bpool_buffs = MRVL_BURST_SIZE;
815 priv->ppio_params.eth_start_hdr =
816 mrvl_cfg->port[dev->data->port_id].eth_start_hdr;
817 priv->forward_bad_frames =
818 mrvl_cfg->port[dev->data->port_id].forward_bad_frames;
819 priv->fill_bpool_buffs =
820 mrvl_cfg->port[dev->data->port_id].fill_bpool_buffs;
824 * Calculate the minimum bpool size for refill feature as follows:
825 * 2 default burst sizes multiply by number of rx queues.
826 * If the bpool size will be below this value, new buffers will
827 * be added to the pool.
829 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
831 /* In case initial bpool size configured in queues setup is
832 * smaller than minimum size add more buffers
834 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
835 if (priv->bpool_init_size < def_init_size) {
836 int buffs_to_add = def_init_size - priv->bpool_init_size;
838 priv->bpool_init_size += buffs_to_add;
839 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
841 MRVL_LOG(ERR, "Failed to add buffers to bpool");
845 * Calculate the maximum bpool size for refill feature as follows:
846 * maximum number of descriptors in rx queue multiply by number
847 * of rx queues plus minimum bpool size.
848 * In case the bpool size will exceed this value, superfluous buffers
851 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
852 priv->bpool_min_size;
854 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
856 MRVL_LOG(ERR, "Failed to init ppio");
861 * In case there are some some stale uc/mc mac addresses flush them
862 * here. It cannot be done during mrvl_dev_close() as port information
863 * is already gone at that point (due to pp2_ppio_deinit() in
866 if (!priv->uc_mc_flushed) {
867 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
870 "Failed to flush uc/mc filter list");
873 priv->uc_mc_flushed = 1;
876 ret = mrvl_mtu_set(dev, dev->data->mtu);
878 MRVL_LOG(ERR, "Failed to set MTU to %d", dev->data->mtu);
880 if (!rte_is_zero_ether_addr(&dev->data->mac_addrs[0]))
881 mrvl_mac_addr_set(dev, &dev->data->mac_addrs[0]);
883 for (i = 1; i < MRVL_MAC_ADDRS_MAX; i++) {
884 mac_addr = &dev->data->mac_addrs[i];
886 /* skip zero address */
887 if (rte_is_zero_ether_addr(mac_addr))
890 mrvl_mac_addr_add(dev, mac_addr, i, 0);
893 if (dev->data->all_multicast == 1)
894 mrvl_allmulticast_enable(dev);
896 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
897 ret = mrvl_populate_vlan_table(dev, 1);
899 MRVL_LOG(ERR, "Failed to populate VLAN table");
904 /* For default QoS config, don't start classifier. */
906 mrvl_cfg->port[dev->data->port_id].use_qos_global_defaults == 0) {
907 ret = mrvl_start_qos_mapping(priv);
909 MRVL_LOG(ERR, "Failed to setup QoS mapping");
914 ret = pp2_ppio_set_loopback(priv->ppio, dev->data->dev_conf.lpbk_mode);
916 MRVL_LOG(ERR, "Failed to set loopback");
920 if (dev->data->promiscuous == 1)
921 mrvl_promiscuous_enable(dev);
923 if (priv->flow_ctrl) {
924 ret = mrvl_flow_ctrl_set(dev, &priv->fc_conf);
926 MRVL_LOG(ERR, "Failed to configure flow control");
932 if (dev->data->dev_link.link_status == ETH_LINK_UP) {
933 ret = mrvl_dev_set_link_up(dev);
935 MRVL_LOG(ERR, "Failed to set link up");
936 dev->data->dev_link.link_status = ETH_LINK_DOWN;
941 /* start tx queues */
942 for (i = 0; i < dev->data->nb_tx_queues; i++) {
943 struct mrvl_txq *txq = dev->data->tx_queues[i];
945 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
947 if (!txq->tx_deferred_start)
951 * All txqs are started by default. Stop them
952 * so that tx_deferred_start works as expected.
954 ret = mrvl_tx_queue_stop(dev, i);
961 mrvl_set_tx_function(dev);
965 MRVL_LOG(ERR, "Failed to start device");
966 pp2_ppio_deinit(priv->ppio);
971 * Flush receive queues.
974 * Pointer to Ethernet device structure.
977 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
981 MRVL_LOG(INFO, "Flushing rx queues");
982 for (i = 0; i < dev->data->nb_rx_queues; i++) {
986 struct mrvl_rxq *q = dev->data->rx_queues[i];
987 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
989 num = MRVL_PP2_RXD_MAX;
990 ret = pp2_ppio_recv(q->priv->ppio,
991 q->priv->rxq_map[q->queue_id].tc,
992 q->priv->rxq_map[q->queue_id].inq,
993 descs, (uint16_t *)&num);
994 } while (ret == 0 && num);
999 * Flush transmit shadow queues.
1002 * Pointer to Ethernet device structure.
1005 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
1008 struct mrvl_txq *txq;
1010 MRVL_LOG(INFO, "Flushing tx shadow queues");
1011 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1012 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
1014 for (j = 0; j < RTE_MAX_LCORE; j++) {
1015 struct mrvl_shadow_txq *sq;
1020 sq = &txq->shadow_txqs[j];
1021 mrvl_free_sent_buffers(txq->priv->ppio,
1022 hifs[j], j, sq, txq->queue_id, 1);
1023 while (sq->tail != sq->head) {
1024 uint64_t addr = cookie_addr_high |
1025 sq->ent[sq->tail].buff.cookie;
1027 (struct rte_mbuf *)addr);
1028 sq->tail = (sq->tail + 1) &
1029 MRVL_PP2_TX_SHADOWQ_MASK;
1031 memset(sq, 0, sizeof(*sq));
1037 * Flush hardware bpool (buffer-pool).
1040 * Pointer to Ethernet device structure.
1043 mrvl_flush_bpool(struct rte_eth_dev *dev)
1045 struct mrvl_priv *priv = dev->data->dev_private;
1046 struct pp2_hif *hif;
1049 unsigned int core_id = rte_lcore_id();
1051 if (core_id == LCORE_ID_ANY)
1052 core_id = rte_get_main_lcore();
1054 hif = mrvl_get_hif(priv, core_id);
1056 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
1058 MRVL_LOG(ERR, "Failed to get bpool buffers number");
1063 struct pp2_buff_inf inf;
1066 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
1070 addr = cookie_addr_high | inf.cookie;
1071 rte_pktmbuf_free((struct rte_mbuf *)addr);
1076 * DPDK callback to stop the device.
1079 * Pointer to Ethernet device structure.
1082 mrvl_dev_stop(struct rte_eth_dev *dev)
1084 return mrvl_dev_set_link_down(dev);
1088 * DPDK callback to close the device.
1091 * Pointer to Ethernet device structure.
1094 mrvl_dev_close(struct rte_eth_dev *dev)
1096 struct mrvl_priv *priv = dev->data->dev_private;
1099 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1102 mrvl_flush_rx_queues(dev);
1103 mrvl_flush_tx_shadow_queues(dev);
1104 mrvl_flow_deinit(dev);
1105 mrvl_mtr_deinit(dev);
1107 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
1108 struct pp2_ppio_tc_params *tc_params =
1109 &priv->ppio_params.inqs_params.tcs_params[i];
1111 if (tc_params->inqs_params) {
1112 rte_free(tc_params->inqs_params);
1113 tc_params->inqs_params = NULL;
1117 if (priv->cls_tbl) {
1118 pp2_cls_tbl_deinit(priv->cls_tbl);
1119 priv->cls_tbl = NULL;
1122 if (priv->qos_tbl) {
1123 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
1124 priv->qos_tbl = NULL;
1127 mrvl_flush_bpool(dev);
1128 mrvl_tm_deinit(dev);
1131 pp2_ppio_deinit(priv->ppio);
1135 /* policer must be released after ppio deinitialization */
1136 if (priv->default_policer) {
1137 pp2_cls_plcr_deinit(priv->default_policer);
1138 priv->default_policer = NULL;
1143 pp2_bpool_deinit(priv->bpool);
1144 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
1150 if (mrvl_dev_num == 0) {
1151 MRVL_LOG(INFO, "Perform MUSDK deinit");
1154 rte_mvep_deinit(MVEP_MOD_T_PP2);
1161 * DPDK callback to retrieve physical link information.
1164 * Pointer to Ethernet device structure.
1165 * @param wait_to_complete
1166 * Wait for request completion (ignored).
1169 * 0 on success, negative error value otherwise.
1172 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
1176 * once MUSDK provides necessary API use it here
1178 struct mrvl_priv *priv = dev->data->dev_private;
1179 struct ethtool_cmd edata;
1181 int ret, fd, link_up;
1186 edata.cmd = ETHTOOL_GSET;
1188 strcpy(req.ifr_name, dev->data->name);
1189 req.ifr_data = (void *)&edata;
1191 fd = socket(AF_INET, SOCK_DGRAM, 0);
1195 ret = ioctl(fd, SIOCETHTOOL, &req);
1203 switch (ethtool_cmd_speed(&edata)) {
1205 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
1208 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
1211 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
1214 dev->data->dev_link.link_speed = ETH_SPEED_NUM_2_5G;
1217 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
1220 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
1223 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
1224 ETH_LINK_HALF_DUPLEX;
1225 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
1227 pp2_ppio_get_link_state(priv->ppio, &link_up);
1228 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
1234 * DPDK callback to enable promiscuous mode.
1237 * Pointer to Ethernet device structure.
1240 * 0 on success, negative error value otherwise.
1243 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
1245 struct mrvl_priv *priv = dev->data->dev_private;
1254 ret = pp2_ppio_set_promisc(priv->ppio, 1);
1256 MRVL_LOG(ERR, "Failed to enable promiscuous mode");
1264 * DPDK callback to enable allmulti mode.
1267 * Pointer to Ethernet device structure.
1270 * 0 on success, negative error value otherwise.
1273 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
1275 struct mrvl_priv *priv = dev->data->dev_private;
1284 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
1286 MRVL_LOG(ERR, "Failed enable all-multicast mode");
1294 * DPDK callback to disable promiscuous mode.
1297 * Pointer to Ethernet device structure.
1300 * 0 on success, negative error value otherwise.
1303 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
1305 struct mrvl_priv *priv = dev->data->dev_private;
1314 ret = pp2_ppio_set_promisc(priv->ppio, 0);
1316 MRVL_LOG(ERR, "Failed to disable promiscuous mode");
1324 * DPDK callback to disable allmulticast mode.
1327 * Pointer to Ethernet device structure.
1330 * 0 on success, negative error value otherwise.
1333 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
1335 struct mrvl_priv *priv = dev->data->dev_private;
1344 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
1346 MRVL_LOG(ERR, "Failed to disable all-multicast mode");
1354 * DPDK callback to remove a MAC address.
1357 * Pointer to Ethernet device structure.
1359 * MAC address index.
1362 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1364 struct mrvl_priv *priv = dev->data->dev_private;
1365 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1374 ret = pp2_ppio_remove_mac_addr(priv->ppio,
1375 dev->data->mac_addrs[index].addr_bytes);
1377 rte_ether_format_addr(buf, sizeof(buf),
1378 &dev->data->mac_addrs[index]);
1379 MRVL_LOG(ERR, "Failed to remove mac %s", buf);
1384 * DPDK callback to add a MAC address.
1387 * Pointer to Ethernet device structure.
1389 * MAC address to register.
1391 * MAC address index.
1393 * VMDq pool index to associate address with (unused).
1396 * 0 on success, negative error value otherwise.
1399 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1400 uint32_t index, uint32_t vmdq __rte_unused)
1402 struct mrvl_priv *priv = dev->data->dev_private;
1403 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1413 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
1417 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
1418 * parameter uc_filter_max. Maximum number of mc addresses is then
1419 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
1422 * If more than uc_filter_max uc addresses were added to filter list
1423 * then NIC will switch to promiscuous mode automatically.
1425 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
1426 * were added to filter list then NIC will switch to all-multicast mode
1429 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
1431 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1432 MRVL_LOG(ERR, "Failed to add mac %s", buf);
1440 * DPDK callback to set the primary MAC address.
1443 * Pointer to Ethernet device structure.
1445 * MAC address to register.
1448 * 0 on success, negative error value otherwise.
1451 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1453 struct mrvl_priv *priv = dev->data->dev_private;
1462 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
1464 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1465 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1466 MRVL_LOG(ERR, "Failed to set mac to %s", buf);
1473 * DPDK callback to get device statistics.
1476 * Pointer to Ethernet device structure.
1478 * Stats structure output buffer.
1481 * 0 on success, negative error value otherwise.
1484 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1486 struct mrvl_priv *priv = dev->data->dev_private;
1487 struct pp2_ppio_statistics ppio_stats;
1488 uint64_t drop_mac = 0;
1489 unsigned int i, idx, ret;
1494 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1495 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1496 struct pp2_ppio_inq_statistics rx_stats;
1501 idx = rxq->queue_id;
1502 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1504 "rx queue %d stats out of range (0 - %d)",
1505 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1509 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1510 priv->rxq_map[idx].tc,
1511 priv->rxq_map[idx].inq,
1513 if (unlikely(ret)) {
1515 "Failed to update rx queue %d stats", idx);
1519 stats->q_ibytes[idx] = rxq->bytes_recv;
1520 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1521 stats->q_errors[idx] = rx_stats.drop_early +
1522 rx_stats.drop_fullq +
1525 stats->ibytes += rxq->bytes_recv;
1526 drop_mac += rxq->drop_mac;
1529 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1530 struct mrvl_txq *txq = dev->data->tx_queues[i];
1531 struct pp2_ppio_outq_statistics tx_stats;
1536 idx = txq->queue_id;
1537 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1539 "tx queue %d stats out of range (0 - %d)",
1540 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1543 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1545 if (unlikely(ret)) {
1547 "Failed to update tx queue %d stats", idx);
1551 stats->q_opackets[idx] = tx_stats.deq_desc;
1552 stats->q_obytes[idx] = txq->bytes_sent;
1553 stats->obytes += txq->bytes_sent;
1556 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1557 if (unlikely(ret)) {
1558 MRVL_LOG(ERR, "Failed to update port statistics");
1562 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1563 stats->opackets += ppio_stats.tx_packets;
1564 stats->imissed += ppio_stats.rx_fullq_dropped +
1565 ppio_stats.rx_bm_dropped +
1566 ppio_stats.rx_early_dropped +
1567 ppio_stats.rx_fifo_dropped +
1568 ppio_stats.rx_cls_dropped;
1569 stats->ierrors = drop_mac;
1575 * DPDK callback to clear device statistics.
1578 * Pointer to Ethernet device structure.
1581 * 0 on success, negative error value otherwise.
1584 mrvl_stats_reset(struct rte_eth_dev *dev)
1586 struct mrvl_priv *priv = dev->data->dev_private;
1592 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1593 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1595 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1596 priv->rxq_map[i].inq, NULL, 1);
1597 rxq->bytes_recv = 0;
1601 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1602 struct mrvl_txq *txq = dev->data->tx_queues[i];
1604 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1605 txq->bytes_sent = 0;
1608 return pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1612 * DPDK callback to get extended statistics.
1615 * Pointer to Ethernet device structure.
1617 * Pointer to xstats table.
1619 * Number of entries in xstats table.
1621 * Negative value on error, number of read xstats otherwise.
1624 mrvl_xstats_get(struct rte_eth_dev *dev,
1625 struct rte_eth_xstat *stats, unsigned int n)
1627 struct mrvl_priv *priv = dev->data->dev_private;
1628 struct pp2_ppio_statistics ppio_stats;
1634 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1635 for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
1638 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
1639 val = *(uint32_t *)((uint8_t *)&ppio_stats +
1640 mrvl_xstats_tbl[i].offset);
1641 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t))
1642 val = *(uint64_t *)((uint8_t *)&ppio_stats +
1643 mrvl_xstats_tbl[i].offset);
1648 stats[i].value = val;
1655 * DPDK callback to reset extended statistics.
1658 * Pointer to Ethernet device structure.
1661 * 0 on success, negative error value otherwise.
1664 mrvl_xstats_reset(struct rte_eth_dev *dev)
1666 return mrvl_stats_reset(dev);
1670 * DPDK callback to get extended statistics names.
1672 * @param dev (unused)
1673 * Pointer to Ethernet device structure.
1674 * @param xstats_names
1675 * Pointer to xstats names table.
1677 * Size of the xstats names table.
1679 * Number of read names.
1682 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1683 struct rte_eth_xstat_name *xstats_names,
1689 return RTE_DIM(mrvl_xstats_tbl);
1691 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
1692 strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name,
1693 RTE_ETH_XSTATS_NAME_SIZE);
1699 * DPDK callback to get information about the device.
1702 * Pointer to Ethernet device structure (unused).
1704 * Info structure output buffer.
1707 mrvl_dev_infos_get(struct rte_eth_dev *dev,
1708 struct rte_eth_dev_info *info)
1710 struct mrvl_priv *priv = dev->data->dev_private;
1712 info->speed_capa = ETH_LINK_SPEED_10M |
1713 ETH_LINK_SPEED_100M |
1715 ETH_LINK_SPEED_2_5G |
1718 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1719 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1720 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1722 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1723 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1724 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1726 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1727 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1728 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1730 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1731 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1733 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1734 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1736 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1737 ETH_RSS_NONFRAG_IPV4_TCP |
1738 ETH_RSS_NONFRAG_IPV4_UDP;
1740 /* By default packets are dropped if no descriptors are available */
1741 info->default_rxconf.rx_drop_en = 1;
1743 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1744 info->max_mtu = priv->max_mtu;
1750 * Return supported packet types.
1753 * Pointer to Ethernet device structure (unused).
1756 * Const pointer to the table with supported packet types.
1758 static const uint32_t *
1759 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1761 static const uint32_t ptypes[] = {
1763 RTE_PTYPE_L2_ETHER_VLAN,
1764 RTE_PTYPE_L2_ETHER_QINQ,
1766 RTE_PTYPE_L3_IPV4_EXT,
1767 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1769 RTE_PTYPE_L3_IPV6_EXT,
1770 RTE_PTYPE_L2_ETHER_ARP,
1779 * DPDK callback to get information about specific receive queue.
1782 * Pointer to Ethernet device structure.
1783 * @param rx_queue_id
1784 * Receive queue index.
1786 * Receive queue information structure.
1788 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1789 struct rte_eth_rxq_info *qinfo)
1791 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1792 struct mrvl_priv *priv = dev->data->dev_private;
1793 int inq = priv->rxq_map[rx_queue_id].inq;
1794 int tc = priv->rxq_map[rx_queue_id].tc;
1795 struct pp2_ppio_tc_params *tc_params =
1796 &priv->ppio_params.inqs_params.tcs_params[tc];
1799 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1803 * DPDK callback to get information about specific transmit queue.
1806 * Pointer to Ethernet device structure.
1807 * @param tx_queue_id
1808 * Transmit queue index.
1810 * Transmit queue information structure.
1812 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1813 struct rte_eth_txq_info *qinfo)
1815 struct mrvl_priv *priv = dev->data->dev_private;
1816 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id];
1819 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1820 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1824 * DPDK callback to Configure a VLAN filter.
1827 * Pointer to Ethernet device structure.
1829 * VLAN ID to filter.
1834 * 0 on success, negative error value otherwise.
1837 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1839 struct mrvl_priv *priv = dev->data->dev_private;
1847 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1848 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1852 * DPDK callback to Configure VLAN offload.
1855 * Pointer to Ethernet device structure.
1857 * VLAN offload mask.
1860 * 0 on success, negative error value otherwise.
1862 static int mrvl_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1864 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
1867 if (mask & ETH_VLAN_STRIP_MASK) {
1868 MRVL_LOG(ERR, "VLAN stripping is not supported\n");
1872 if (mask & ETH_VLAN_FILTER_MASK) {
1873 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1874 ret = mrvl_populate_vlan_table(dev, 1);
1876 ret = mrvl_populate_vlan_table(dev, 0);
1882 if (mask & ETH_VLAN_EXTEND_MASK) {
1883 MRVL_LOG(ERR, "Extend VLAN not supported\n");
1891 * Release buffers to hardware bpool (buffer-pool)
1894 * Receive queue pointer.
1896 * Number of buffers to release to bpool.
1899 * 0 on success, negative error value otherwise.
1902 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1904 struct buff_release_entry entries[num];
1905 struct rte_mbuf *mbufs[num];
1907 unsigned int core_id;
1908 struct pp2_hif *hif;
1909 struct pp2_bpool *bpool;
1911 core_id = rte_lcore_id();
1912 if (core_id == LCORE_ID_ANY)
1913 core_id = rte_get_main_lcore();
1915 hif = mrvl_get_hif(rxq->priv, core_id);
1919 bpool = rxq->priv->bpool;
1921 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1925 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1927 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1929 for (i = 0; i < num; i++) {
1930 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1931 != cookie_addr_high) {
1933 "mbuf virtual addr high is out of range "
1934 "0x%x instead of 0x%x\n",
1935 (uint32_t)((uint64_t)mbufs[i] >> 32),
1936 (uint32_t)(cookie_addr_high >> 32));
1940 entries[i].buff.addr =
1941 rte_mbuf_data_iova_default(mbufs[i]);
1942 entries[i].buff.cookie = (uintptr_t)mbufs[i];
1943 entries[i].bpool = bpool;
1946 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1947 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1954 for (; i < num; i++)
1955 rte_pktmbuf_free(mbufs[i]);
1961 * DPDK callback to configure the receive queue.
1964 * Pointer to Ethernet device structure.
1968 * Number of descriptors to configure in queue.
1970 * NUMA socket on which memory must be allocated.
1972 * Thresholds parameters.
1974 * Memory pool for buffer allocations.
1977 * 0 on success, negative error value otherwise.
1980 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1981 unsigned int socket,
1982 const struct rte_eth_rxconf *conf,
1983 struct rte_mempool *mp)
1985 struct mrvl_priv *priv = dev->data->dev_private;
1986 struct mrvl_rxq *rxq;
1987 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
1988 uint32_t max_rx_pktlen = dev->data->mtu + RTE_ETHER_HDR_LEN;
1992 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1994 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1996 * Unknown TC mapping, mapping will not have a correct queue.
1998 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu",
1999 idx, priv->ppio_id);
2003 frame_size = buf_size - RTE_PKTMBUF_HEADROOM - MRVL_PKT_EFFEC_OFFS;
2004 if (frame_size < max_rx_pktlen) {
2006 "Mbuf size must be increased to %u bytes to hold up "
2007 "to %u bytes of data.",
2008 max_rx_pktlen + buf_size - frame_size,
2010 dev->data->mtu = frame_size - RTE_ETHER_HDR_LEN;
2011 MRVL_LOG(INFO, "Setting MTU to %u", dev->data->mtu);
2014 if (dev->data->rx_queues[idx]) {
2015 rte_free(dev->data->rx_queues[idx]);
2016 dev->data->rx_queues[idx] = NULL;
2019 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
2025 rxq->cksum_enabled = offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
2026 rxq->queue_id = idx;
2027 rxq->port_id = dev->data->port_id;
2028 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
2030 tc = priv->rxq_map[rxq->queue_id].tc,
2031 inq = priv->rxq_map[rxq->queue_id].inq;
2032 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
2035 ret = mrvl_fill_bpool(rxq, desc);
2041 priv->bpool_init_size += desc;
2043 dev->data->rx_queues[idx] = rxq;
2049 * DPDK callback to release the receive queue.
2052 * Pointer to Ethernet device structure.
2054 * Receive queue index.
2057 mrvl_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2059 struct mrvl_rxq *q = dev->data->rx_queues[qid];
2060 struct pp2_ppio_tc_params *tc_params;
2061 int i, num, tc, inq;
2062 struct pp2_hif *hif;
2063 unsigned int core_id = rte_lcore_id();
2065 if (core_id == LCORE_ID_ANY)
2066 core_id = rte_get_main_lcore();
2071 hif = mrvl_get_hif(q->priv, core_id);
2076 tc = q->priv->rxq_map[q->queue_id].tc;
2077 inq = q->priv->rxq_map[q->queue_id].inq;
2078 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
2079 num = tc_params->inqs_params[inq].size;
2080 for (i = 0; i < num; i++) {
2081 struct pp2_buff_inf inf;
2084 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
2085 addr = cookie_addr_high | inf.cookie;
2086 rte_pktmbuf_free((struct rte_mbuf *)addr);
2093 * DPDK callback to configure the transmit queue.
2096 * Pointer to Ethernet device structure.
2098 * Transmit queue index.
2100 * Number of descriptors to configure in the queue.
2102 * NUMA socket on which memory must be allocated.
2104 * Tx queue configuration parameters.
2107 * 0 on success, negative error value otherwise.
2110 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
2111 unsigned int socket,
2112 const struct rte_eth_txconf *conf)
2114 struct mrvl_priv *priv = dev->data->dev_private;
2115 struct mrvl_txq *txq;
2117 if (dev->data->tx_queues[idx]) {
2118 rte_free(dev->data->tx_queues[idx]);
2119 dev->data->tx_queues[idx] = NULL;
2122 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
2127 txq->queue_id = idx;
2128 txq->port_id = dev->data->port_id;
2129 txq->tx_deferred_start = conf->tx_deferred_start;
2130 dev->data->tx_queues[idx] = txq;
2132 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
2138 * DPDK callback to release the transmit queue.
2141 * Pointer to Ethernet device structure.
2143 * Transmit queue index.
2146 mrvl_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2148 struct mrvl_txq *q = dev->data->tx_queues[qid];
2157 * DPDK callback to get flow control configuration.
2160 * Pointer to Ethernet device structure.
2162 * Pointer to the flow control configuration.
2165 * 0 on success, negative error value otherwise.
2168 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2170 struct mrvl_priv *priv = dev->data->dev_private;
2174 memcpy(fc_conf, &priv->fc_conf, sizeof(struct rte_eth_fc_conf));
2178 fc_conf->autoneg = 1;
2179 ret = pp2_ppio_get_rx_pause(priv->ppio, &en);
2181 MRVL_LOG(ERR, "Failed to read rx pause state");
2185 fc_conf->mode = en ? RTE_FC_RX_PAUSE : RTE_FC_NONE;
2187 ret = pp2_ppio_get_tx_pause(priv->ppio, &en);
2189 MRVL_LOG(ERR, "Failed to read tx pause state");
2194 if (fc_conf->mode == RTE_FC_NONE)
2195 fc_conf->mode = RTE_FC_TX_PAUSE;
2197 fc_conf->mode = RTE_FC_FULL;
2204 * DPDK callback to set flow control configuration.
2207 * Pointer to Ethernet device structure.
2209 * Pointer to the flow control configuration.
2212 * 0 on success, negative error value otherwise.
2215 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2217 struct mrvl_priv *priv = dev->data->dev_private;
2218 struct pp2_ppio_tx_pause_params mrvl_pause_params;
2222 if (fc_conf->high_water ||
2223 fc_conf->low_water ||
2224 fc_conf->pause_time ||
2225 fc_conf->mac_ctrl_frame_fwd) {
2226 MRVL_LOG(ERR, "Flowctrl parameter is not supported");
2231 if (fc_conf->autoneg == 0) {
2232 MRVL_LOG(ERR, "Flowctrl Autoneg disable is not supported");
2237 memcpy(&priv->fc_conf, fc_conf, sizeof(struct rte_eth_fc_conf));
2238 priv->flow_ctrl = 1;
2242 switch (fc_conf->mode) {
2247 case RTE_FC_TX_PAUSE:
2251 case RTE_FC_RX_PAUSE:
2260 MRVL_LOG(ERR, "Incorrect Flow control flag (%d)",
2265 /* Set RX flow control */
2266 ret = pp2_ppio_set_rx_pause(priv->ppio, rx_en);
2268 MRVL_LOG(ERR, "Failed to change RX flowctrl");
2272 /* Set TX flow control */
2273 mrvl_pause_params.en = tx_en;
2274 /* all inqs participate in xon/xoff decision */
2275 mrvl_pause_params.use_tc_pause_inqs = 0;
2276 ret = pp2_ppio_set_tx_pause(priv->ppio, &mrvl_pause_params);
2278 MRVL_LOG(ERR, "Failed to change TX flowctrl");
2286 * Update RSS hash configuration
2289 * Pointer to Ethernet device structure.
2291 * Pointer to RSS configuration.
2294 * 0 on success, negative error value otherwise.
2297 mrvl_rss_hash_update(struct rte_eth_dev *dev,
2298 struct rte_eth_rss_conf *rss_conf)
2300 struct mrvl_priv *priv = dev->data->dev_private;
2305 return mrvl_configure_rss(priv, rss_conf);
2309 * DPDK callback to get RSS hash configuration.
2312 * Pointer to Ethernet device structure.
2314 * Pointer to RSS configuration.
2320 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
2321 struct rte_eth_rss_conf *rss_conf)
2323 struct mrvl_priv *priv = dev->data->dev_private;
2324 enum pp2_ppio_hash_type hash_type =
2325 priv->ppio_params.inqs_params.hash_type;
2327 rss_conf->rss_key = NULL;
2329 if (hash_type == PP2_PPIO_HASH_T_NONE)
2330 rss_conf->rss_hf = 0;
2331 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
2332 rss_conf->rss_hf = ETH_RSS_IPV4;
2333 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
2334 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
2335 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
2336 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
2342 * DPDK callback to get rte_flow callbacks.
2345 * Pointer to the device structure.
2347 * Pointer to pass the flow ops.
2350 * 0 on success, negative error value otherwise.
2353 mrvl_eth_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
2354 const struct rte_flow_ops **ops)
2356 *ops = &mrvl_flow_ops;
2361 * DPDK callback to get rte_mtr callbacks.
2364 * Pointer to the device structure.
2366 * Pointer to pass the mtr ops.
2372 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2374 *(const void **)ops = &mrvl_mtr_ops;
2380 * DPDK callback to get rte_tm callbacks.
2383 * Pointer to the device structure.
2385 * Pointer to pass the tm ops.
2391 mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2393 *(const void **)ops = &mrvl_tm_ops;
2398 static const struct eth_dev_ops mrvl_ops = {
2399 .dev_configure = mrvl_dev_configure,
2400 .dev_start = mrvl_dev_start,
2401 .dev_stop = mrvl_dev_stop,
2402 .dev_set_link_up = mrvl_dev_set_link_up,
2403 .dev_set_link_down = mrvl_dev_set_link_down,
2404 .dev_close = mrvl_dev_close,
2405 .link_update = mrvl_link_update,
2406 .promiscuous_enable = mrvl_promiscuous_enable,
2407 .allmulticast_enable = mrvl_allmulticast_enable,
2408 .promiscuous_disable = mrvl_promiscuous_disable,
2409 .allmulticast_disable = mrvl_allmulticast_disable,
2410 .mac_addr_remove = mrvl_mac_addr_remove,
2411 .mac_addr_add = mrvl_mac_addr_add,
2412 .mac_addr_set = mrvl_mac_addr_set,
2413 .mtu_set = mrvl_mtu_set,
2414 .stats_get = mrvl_stats_get,
2415 .stats_reset = mrvl_stats_reset,
2416 .xstats_get = mrvl_xstats_get,
2417 .xstats_reset = mrvl_xstats_reset,
2418 .xstats_get_names = mrvl_xstats_get_names,
2419 .dev_infos_get = mrvl_dev_infos_get,
2420 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
2421 .rxq_info_get = mrvl_rxq_info_get,
2422 .txq_info_get = mrvl_txq_info_get,
2423 .vlan_filter_set = mrvl_vlan_filter_set,
2424 .vlan_offload_set = mrvl_vlan_offload_set,
2425 .tx_queue_start = mrvl_tx_queue_start,
2426 .tx_queue_stop = mrvl_tx_queue_stop,
2427 .rx_queue_setup = mrvl_rx_queue_setup,
2428 .rx_queue_release = mrvl_rx_queue_release,
2429 .tx_queue_setup = mrvl_tx_queue_setup,
2430 .tx_queue_release = mrvl_tx_queue_release,
2431 .flow_ctrl_get = mrvl_flow_ctrl_get,
2432 .flow_ctrl_set = mrvl_flow_ctrl_set,
2433 .rss_hash_update = mrvl_rss_hash_update,
2434 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
2435 .flow_ops_get = mrvl_eth_flow_ops_get,
2436 .mtr_ops_get = mrvl_mtr_ops_get,
2437 .tm_ops_get = mrvl_tm_ops_get,
2441 * Return packet type information and l3/l4 offsets.
2444 * Pointer to the received packet descriptor.
2451 * Packet type information.
2453 static inline uint64_t
2454 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
2455 uint8_t *l3_offset, uint8_t *l4_offset)
2457 enum pp2_inq_l3_type l3_type;
2458 enum pp2_inq_l4_type l4_type;
2459 enum pp2_inq_vlan_tag vlan_tag;
2460 uint64_t packet_type;
2462 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
2463 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
2464 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag);
2466 packet_type = RTE_PTYPE_L2_ETHER;
2469 case PP2_INQ_VLAN_TAG_SINGLE:
2470 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
2472 case PP2_INQ_VLAN_TAG_DOUBLE:
2473 case PP2_INQ_VLAN_TAG_TRIPLE:
2474 packet_type |= RTE_PTYPE_L2_ETHER_QINQ;
2481 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
2482 packet_type |= RTE_PTYPE_L3_IPV4;
2484 case PP2_INQ_L3_TYPE_IPV4_OK:
2485 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
2487 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
2488 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
2490 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
2491 packet_type |= RTE_PTYPE_L3_IPV6;
2493 case PP2_INQ_L3_TYPE_IPV6_EXT:
2494 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
2496 case PP2_INQ_L3_TYPE_ARP:
2497 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
2499 * In case of ARP l4_offset is set to wrong value.
2500 * Set it to proper one so that later on mbuf->l3_len can be
2501 * calculated subtracting l4_offset and l3_offset.
2503 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
2510 case PP2_INQ_L4_TYPE_TCP:
2511 packet_type |= RTE_PTYPE_L4_TCP;
2513 case PP2_INQ_L4_TYPE_UDP:
2514 packet_type |= RTE_PTYPE_L4_UDP;
2524 * Get offload information from the received packet descriptor.
2527 * Pointer to the received packet descriptor.
2530 * Mbuf offload flags.
2532 static inline uint64_t
2533 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc, uint64_t packet_type)
2536 enum pp2_inq_desc_status status;
2538 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
2539 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
2540 if (unlikely(status != PP2_DESC_ERR_OK))
2541 flags |= PKT_RX_IP_CKSUM_BAD;
2543 flags |= PKT_RX_IP_CKSUM_GOOD;
2546 if (((packet_type & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) ||
2547 ((packet_type & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP)) {
2548 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
2549 if (unlikely(status != PP2_DESC_ERR_OK))
2550 flags |= PKT_RX_L4_CKSUM_BAD;
2552 flags |= PKT_RX_L4_CKSUM_GOOD;
2559 * DPDK callback for receive.
2562 * Generic pointer to the receive queue.
2564 * Array to store received packets.
2566 * Maximum number of packets in array.
2569 * Number of packets successfully received.
2572 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2574 struct mrvl_rxq *q = rxq;
2575 struct pp2_ppio_desc descs[nb_pkts];
2576 struct pp2_bpool *bpool;
2577 int i, ret, rx_done = 0;
2579 struct pp2_hif *hif;
2580 unsigned int core_id = rte_lcore_id();
2582 hif = mrvl_get_hif(q->priv, core_id);
2584 if (unlikely(!q->priv->ppio || !hif))
2587 bpool = q->priv->bpool;
2589 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
2590 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
2591 if (unlikely(ret < 0))
2594 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
2596 for (i = 0; i < nb_pkts; i++) {
2597 struct rte_mbuf *mbuf;
2598 uint8_t l3_offset, l4_offset;
2599 enum pp2_inq_desc_status status;
2602 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2603 struct pp2_ppio_desc *pref_desc;
2606 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
2607 pref_addr = cookie_addr_high |
2608 pp2_ppio_inq_desc_get_cookie(pref_desc);
2609 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
2610 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
2613 addr = cookie_addr_high |
2614 pp2_ppio_inq_desc_get_cookie(&descs[i]);
2615 mbuf = (struct rte_mbuf *)addr;
2616 rte_pktmbuf_reset(mbuf);
2618 /* drop packet in case of mac, overrun or resource error */
2619 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
2620 if ((unlikely(status != PP2_DESC_ERR_OK)) &&
2621 !(q->priv->forward_bad_frames)) {
2622 struct pp2_buff_inf binf = {
2623 .addr = rte_mbuf_data_iova_default(mbuf),
2624 .cookie = (uint64_t)mbuf,
2627 pp2_bpool_put_buff(hif, bpool, &binf);
2628 mrvl_port_bpool_size
2629 [bpool->pp2_id][bpool->id][core_id]++;
2634 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
2635 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
2636 mbuf->data_len = mbuf->pkt_len;
2637 mbuf->port = q->port_id;
2639 mrvl_desc_to_packet_type_and_offset(&descs[i],
2642 mbuf->l2_len = l3_offset;
2643 mbuf->l3_len = l4_offset - l3_offset;
2645 if (likely(q->cksum_enabled))
2647 mrvl_desc_to_ol_flags(&descs[i],
2650 rx_pkts[rx_done++] = mbuf;
2651 q->bytes_recv += mbuf->pkt_len;
2654 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
2655 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
2657 if (unlikely(num <= q->priv->bpool_min_size ||
2658 (!rx_done && num < q->priv->bpool_init_size))) {
2659 mrvl_fill_bpool(q, q->priv->fill_bpool_buffs);
2660 } else if (unlikely(num > q->priv->bpool_max_size)) {
2662 int pkt_to_remove = num - q->priv->bpool_init_size;
2663 struct rte_mbuf *mbuf;
2664 struct pp2_buff_inf buff;
2666 for (i = 0; i < pkt_to_remove; i++) {
2667 ret = pp2_bpool_get_buff(hif, bpool, &buff);
2670 mbuf = (struct rte_mbuf *)
2671 (cookie_addr_high | buff.cookie);
2672 rte_pktmbuf_free(mbuf);
2674 mrvl_port_bpool_size
2675 [bpool->pp2_id][bpool->id][core_id] -= i;
2677 rte_spinlock_unlock(&q->priv->lock);
2684 * Prepare offload information.
2689 * Pointer to the pp2_ouq_l3_type structure.
2691 * Pointer to the pp2_outq_l4_type structure.
2692 * @param gen_l3_cksum
2693 * Will be set to 1 in case l3 checksum is computed.
2695 * Will be set to 1 in case l4 checksum is computed.
2698 mrvl_prepare_proto_info(uint64_t ol_flags,
2699 enum pp2_outq_l3_type *l3_type,
2700 enum pp2_outq_l4_type *l4_type,
2705 * Based on ol_flags prepare information
2706 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
2708 * in most of the checksum cases ipv4 must be set, so this is the
2711 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
2712 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
2714 if (ol_flags & PKT_TX_IPV6) {
2715 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
2716 /* no checksum for ipv6 header */
2720 if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM) {
2721 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
2723 } else if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM) {
2724 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
2727 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
2728 /* no checksum for other type */
2734 * Release already sent buffers to bpool (buffer-pool).
2737 * Pointer to the port structure.
2739 * Pointer to the MUSDK hardware interface.
2741 * Pointer to the shadow queue.
2745 * Force releasing packets.
2748 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2749 unsigned int core_id, struct mrvl_shadow_txq *sq,
2752 struct buff_release_entry *entry;
2753 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2756 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2758 sq->num_to_release += nb_done;
2760 if (likely(!force &&
2761 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2764 nb_done = sq->num_to_release;
2765 sq->num_to_release = 0;
2767 for (i = 0; i < nb_done; i++) {
2768 entry = &sq->ent[sq->tail + num];
2769 if (unlikely(!entry->buff.addr)) {
2771 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
2772 sq->tail, (u64)entry->buff.cookie,
2773 (u64)entry->buff.addr);
2778 if (unlikely(!entry->bpool)) {
2779 struct rte_mbuf *mbuf;
2781 mbuf = (struct rte_mbuf *)entry->buff.cookie;
2782 rte_pktmbuf_free(mbuf);
2787 mrvl_port_bpool_size
2788 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2790 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2795 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2797 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2804 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2805 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2811 * DPDK callback for transmit.
2814 * Generic pointer transmit queue.
2816 * Packets to transmit.
2818 * Number of packets in array.
2821 * Number of packets successfully transmitted.
2824 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2826 struct mrvl_txq *q = txq;
2827 struct mrvl_shadow_txq *sq;
2828 struct pp2_hif *hif;
2829 struct pp2_ppio_desc descs[nb_pkts];
2830 unsigned int core_id = rte_lcore_id();
2831 int i, bytes_sent = 0;
2832 uint16_t num, sq_free_size;
2835 hif = mrvl_get_hif(q->priv, core_id);
2836 sq = &q->shadow_txqs[core_id];
2838 if (unlikely(!q->priv->ppio || !hif))
2842 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2843 sq, q->queue_id, 0);
2845 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2846 if (unlikely(nb_pkts > sq_free_size))
2847 nb_pkts = sq_free_size;
2849 for (i = 0; i < nb_pkts; i++) {
2850 struct rte_mbuf *mbuf = tx_pkts[i];
2851 int gen_l3_cksum, gen_l4_cksum;
2852 enum pp2_outq_l3_type l3_type;
2853 enum pp2_outq_l4_type l4_type;
2855 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2856 struct rte_mbuf *pref_pkt_hdr;
2858 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2859 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2860 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2863 mrvl_fill_shadowq(sq, mbuf);
2864 mrvl_fill_desc(&descs[i], mbuf);
2866 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2868 * in case unsupported ol_flags were passed
2869 * do not update descriptor offload information
2871 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS))
2873 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
2874 &gen_l3_cksum, &gen_l4_cksum);
2876 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2878 mbuf->l2_len + mbuf->l3_len,
2879 gen_l3_cksum, gen_l4_cksum);
2883 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2884 /* number of packets that were not sent */
2885 if (unlikely(num > nb_pkts)) {
2886 for (i = nb_pkts; i < num; i++) {
2887 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2888 MRVL_PP2_TX_SHADOWQ_MASK;
2889 addr = sq->ent[sq->head].buff.cookie;
2891 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2893 sq->size -= num - nb_pkts;
2896 q->bytes_sent += bytes_sent;
2901 /** DPDK callback for S/G transmit.
2904 * Generic pointer transmit queue.
2906 * Packets to transmit.
2908 * Number of packets in array.
2911 * Number of packets successfully transmitted.
2914 mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
2917 struct mrvl_txq *q = txq;
2918 struct mrvl_shadow_txq *sq;
2919 struct pp2_hif *hif;
2920 struct pp2_ppio_desc descs[nb_pkts * PP2_PPIO_DESC_NUM_FRAGS];
2921 struct pp2_ppio_sg_pkts pkts;
2922 uint8_t frags[nb_pkts];
2923 unsigned int core_id = rte_lcore_id();
2924 int i, j, bytes_sent = 0;
2925 int tail, tail_first;
2926 uint16_t num, sq_free_size;
2927 uint16_t nb_segs, total_descs = 0;
2930 hif = mrvl_get_hif(q->priv, core_id);
2931 sq = &q->shadow_txqs[core_id];
2935 if (unlikely(!q->priv->ppio || !hif))
2939 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2940 sq, q->queue_id, 0);
2942 /* Save shadow queue free size */
2943 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2946 for (i = 0; i < nb_pkts; i++) {
2947 struct rte_mbuf *mbuf = tx_pkts[i];
2948 struct rte_mbuf *seg = NULL;
2949 int gen_l3_cksum, gen_l4_cksum;
2950 enum pp2_outq_l3_type l3_type;
2951 enum pp2_outq_l4_type l4_type;
2953 nb_segs = mbuf->nb_segs;
2955 total_descs += nb_segs;
2958 * Check if total_descs does not exceed
2959 * shadow queue free size
2961 if (unlikely(total_descs > sq_free_size)) {
2962 total_descs -= nb_segs;
2966 /* Check if nb_segs does not exceed the max nb of desc per
2969 if (nb_segs > PP2_PPIO_DESC_NUM_FRAGS) {
2970 total_descs -= nb_segs;
2972 "Too many segments. Packet won't be sent.\n");
2976 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2977 struct rte_mbuf *pref_pkt_hdr;
2979 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2980 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2981 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2984 pkts.frags[pkts.num] = nb_segs;
2988 for (j = 0; j < nb_segs - 1; j++) {
2989 /* For the subsequent segments, set shadow queue
2992 mrvl_fill_shadowq(sq, NULL);
2993 mrvl_fill_desc(&descs[tail], seg);
2998 /* Put first mbuf info in last shadow queue entry */
2999 mrvl_fill_shadowq(sq, mbuf);
3000 /* Update descriptor with last segment */
3001 mrvl_fill_desc(&descs[tail++], seg);
3003 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
3004 /* In case unsupported ol_flags were passed
3005 * do not update descriptor offload information
3007 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS))
3009 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
3010 &gen_l3_cksum, &gen_l4_cksum);
3012 pp2_ppio_outq_desc_set_proto_info(&descs[tail_first], l3_type,
3013 l4_type, mbuf->l2_len,
3014 mbuf->l2_len + mbuf->l3_len,
3015 gen_l3_cksum, gen_l4_cksum);
3019 pp2_ppio_send_sg(q->priv->ppio, hif, q->queue_id, descs,
3020 &total_descs, &pkts);
3021 /* number of packets that were not sent */
3022 if (unlikely(num > total_descs)) {
3023 for (i = total_descs; i < num; i++) {
3024 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
3025 MRVL_PP2_TX_SHADOWQ_MASK;
3027 addr = sq->ent[sq->head].buff.cookie;
3030 rte_pktmbuf_pkt_len((struct rte_mbuf *)
3031 (cookie_addr_high | addr));
3033 sq->size -= num - total_descs;
3037 q->bytes_sent += bytes_sent;
3043 * Create private device structure.
3046 * Pointer to the port name passed in the initialization parameters.
3049 * Pointer to the newly allocated private device structure.
3051 static struct mrvl_priv *
3052 mrvl_priv_create(const char *dev_name)
3054 struct pp2_bpool_params bpool_params;
3055 char match[MRVL_MATCH_LEN];
3056 struct mrvl_priv *priv;
3057 uint16_t max_frame_size;
3060 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
3064 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
3065 &priv->pp_id, &priv->ppio_id);
3069 ret = pp2_ppio_get_l4_cksum_max_frame_size(priv->pp_id, priv->ppio_id,
3074 priv->max_mtu = max_frame_size + RTE_ETHER_CRC_LEN -
3075 MRVL_PP2_ETH_HDRS_LEN;
3077 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
3078 PP2_BPOOL_NUM_POOLS);
3081 priv->bpool_bit = bpool_bit;
3083 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
3085 memset(&bpool_params, 0, sizeof(bpool_params));
3086 bpool_params.match = match;
3087 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
3088 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
3090 goto out_clear_bpool_bit;
3092 priv->ppio_params.type = PP2_PPIO_T_NIC;
3093 rte_spinlock_init(&priv->lock);
3096 out_clear_bpool_bit:
3097 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
3104 * Create device representing Ethernet port.
3107 * Pointer to the port's name.
3110 * 0 on success, negative error value otherwise.
3113 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
3115 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
3116 struct rte_eth_dev *eth_dev;
3117 struct mrvl_priv *priv;
3120 eth_dev = rte_eth_dev_allocate(name);
3124 priv = mrvl_priv_create(name);
3129 eth_dev->data->dev_private = priv;
3131 eth_dev->data->mac_addrs =
3132 rte_zmalloc("mac_addrs",
3133 RTE_ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
3134 if (!eth_dev->data->mac_addrs) {
3135 MRVL_LOG(ERR, "Failed to allocate space for eth addrs");
3140 memset(&req, 0, sizeof(req));
3141 strcpy(req.ifr_name, name);
3142 ret = ioctl(fd, SIOCGIFHWADDR, &req);
3146 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
3147 req.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN);
3149 eth_dev->device = &vdev->device;
3150 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
3151 mrvl_set_tx_function(eth_dev);
3152 eth_dev->dev_ops = &mrvl_ops;
3153 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
3155 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
3157 rte_eth_dev_probing_finish(eth_dev);
3160 rte_eth_dev_release_port(eth_dev);
3166 * Callback used by rte_kvargs_process() during argument parsing.
3169 * Pointer to the parsed key (unused).
3171 * Pointer to the parsed value.
3173 * Pointer to the extra arguments which contains address of the
3174 * table of pointers to parsed interface names.
3180 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
3183 struct mrvl_ifnames *ifnames = extra_args;
3185 ifnames->names[ifnames->idx++] = value;
3191 * DPDK callback to register the virtual device.
3194 * Pointer to the virtual device.
3197 * 0 on success, negative error value otherwise.
3200 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
3202 struct rte_kvargs *kvlist;
3203 struct mrvl_ifnames ifnames;
3205 uint32_t i, ifnum, cfgnum;
3208 params = rte_vdev_device_args(vdev);
3212 kvlist = rte_kvargs_parse(params, valid_args);
3216 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
3217 if (ifnum > RTE_DIM(ifnames.names))
3218 goto out_free_kvlist;
3221 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
3222 mrvl_get_ifnames, &ifnames);
3226 * The below system initialization should be done only once,
3227 * on the first provided configuration file
3230 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
3231 MRVL_LOG(INFO, "Parsing config file!");
3233 MRVL_LOG(ERR, "Cannot handle more than one config file!");
3234 goto out_free_kvlist;
3235 } else if (cfgnum == 1) {
3236 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
3237 mrvl_get_cfg, &mrvl_cfg);
3244 MRVL_LOG(INFO, "Perform MUSDK initializations");
3246 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist);
3248 goto out_free_kvlist;
3250 ret = mrvl_init_pp2();
3252 MRVL_LOG(ERR, "Failed to init PP!");
3253 rte_mvep_deinit(MVEP_MOD_T_PP2);
3254 goto out_free_kvlist;
3257 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
3258 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
3260 mrvl_lcore_first = RTE_MAX_LCORE;
3261 mrvl_lcore_last = 0;
3264 for (i = 0; i < ifnum; i++) {
3265 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]);
3266 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
3272 rte_kvargs_free(kvlist);
3276 rte_pmd_mrvl_remove(vdev);
3279 rte_kvargs_free(kvlist);
3285 * DPDK callback to remove virtual device.
3288 * Pointer to the removed virtual device.
3291 * 0 on success, negative error value otherwise.
3294 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
3299 RTE_ETH_FOREACH_DEV(port_id) {
3300 if (rte_eth_devices[port_id].device != &vdev->device)
3302 ret |= rte_eth_dev_close(port_id);
3305 return ret == 0 ? 0 : -EIO;
3308 static struct rte_vdev_driver pmd_mrvl_drv = {
3309 .probe = rte_pmd_mrvl_probe,
3310 .remove = rte_pmd_mrvl_remove,
3313 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv);
3314 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2);
3315 RTE_LOG_REGISTER_DEFAULT(mrvl_logtype, NOTICE);