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 #define MRVL_MAC_ADDRS_MAX 25
45 #define MRVL_MATCH_LEN 16
46 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
47 /* Maximum allowable packet size */
48 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
50 #define MRVL_IFACE_NAME_ARG "iface"
51 #define MRVL_CFG_ARG "cfg"
53 #define MRVL_BURST_SIZE 64
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_JUMBO_FRAME | \
63 DEV_RX_OFFLOAD_CHECKSUM)
65 /** Port Tx offloads capabilities */
66 #define MRVL_TX_OFFLOAD_CHECKSUM (DEV_TX_OFFLOAD_IPV4_CKSUM | \
67 DEV_TX_OFFLOAD_UDP_CKSUM | \
68 DEV_TX_OFFLOAD_TCP_CKSUM)
69 #define MRVL_TX_OFFLOADS (MRVL_TX_OFFLOAD_CHECKSUM | \
70 DEV_TX_OFFLOAD_MULTI_SEGS)
72 #define MRVL_TX_PKT_OFFLOADS (PKT_TX_IP_CKSUM | \
76 static const char * const valid_args[] = {
82 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
83 static struct pp2_hif *hifs[RTE_MAX_LCORE];
84 static int used_bpools[PP2_NUM_PKT_PROC] = {
85 [0 ... PP2_NUM_PKT_PROC - 1] = MRVL_MUSDK_BPOOLS_RESERVED
88 static struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
89 static int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
90 static uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
93 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
98 * To use buffer harvesting based on loopback port shadow queue structure
99 * was introduced for buffers information bookkeeping.
101 * Before sending the packet, related buffer information (pp2_buff_inf) is
102 * stored in shadow queue. After packet is transmitted no longer used
103 * packet buffer is released back to it's original hardware pool,
104 * on condition it originated from interface.
105 * In case it was generated by application itself i.e: mbuf->port field is
106 * 0xff then its released to software mempool.
108 struct mrvl_shadow_txq {
109 int head; /* write index - used when sending buffers */
110 int tail; /* read index - used when releasing buffers */
111 u16 size; /* queue occupied size */
112 u16 num_to_release; /* number of descriptors sent, that can be
115 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
119 struct mrvl_priv *priv;
120 struct rte_mempool *mp;
129 struct mrvl_priv *priv;
133 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
134 int tx_deferred_start;
137 static int mrvl_lcore_first;
138 static int mrvl_lcore_last;
139 static int mrvl_dev_num;
141 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
142 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
143 struct pp2_hif *hif, unsigned int core_id,
144 struct mrvl_shadow_txq *sq, int qid, int force);
146 static uint16_t mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
148 static uint16_t mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
150 static int rte_pmd_mrvl_remove(struct rte_vdev_device *vdev);
151 static void mrvl_deinit_pp2(void);
152 static void mrvl_deinit_hifs(void);
155 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
156 uint32_t index, uint32_t vmdq __rte_unused);
158 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
160 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
161 static int mrvl_promiscuous_enable(struct rte_eth_dev *dev);
162 static int mrvl_allmulticast_enable(struct rte_eth_dev *dev);
164 #define MRVL_XSTATS_TBL_ENTRY(name) { \
165 #name, offsetof(struct pp2_ppio_statistics, name), \
166 sizeof(((struct pp2_ppio_statistics *)0)->name) \
169 /* Table with xstats data */
174 } mrvl_xstats_tbl[] = {
175 MRVL_XSTATS_TBL_ENTRY(rx_bytes),
176 MRVL_XSTATS_TBL_ENTRY(rx_packets),
177 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets),
178 MRVL_XSTATS_TBL_ENTRY(rx_errors),
179 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped),
180 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped),
181 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped),
182 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped),
183 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped),
184 MRVL_XSTATS_TBL_ENTRY(tx_bytes),
185 MRVL_XSTATS_TBL_ENTRY(tx_packets),
186 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets),
187 MRVL_XSTATS_TBL_ENTRY(tx_errors)
191 mrvl_fill_shadowq(struct mrvl_shadow_txq *sq, struct rte_mbuf *buf)
193 sq->ent[sq->head].buff.cookie = (uint64_t)buf;
194 sq->ent[sq->head].buff.addr = buf ?
195 rte_mbuf_data_iova_default(buf) : 0;
197 sq->ent[sq->head].bpool =
198 (unlikely(!buf || buf->port >= RTE_MAX_ETHPORTS ||
199 buf->refcnt > 1)) ? NULL :
200 mrvl_port_to_bpool_lookup[buf->port];
202 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
207 mrvl_fill_desc(struct pp2_ppio_desc *desc, struct rte_mbuf *buf)
209 pp2_ppio_outq_desc_reset(desc);
210 pp2_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf));
211 pp2_ppio_outq_desc_set_pkt_offset(desc, 0);
212 pp2_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf));
216 mrvl_get_bpool_size(int pp2_id, int pool_id)
221 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
222 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
228 mrvl_reserve_bit(int *bitmap, int max)
230 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
241 mrvl_init_hif(int core_id)
243 struct pp2_hif_params params;
244 char match[MRVL_MATCH_LEN];
247 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
249 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
253 snprintf(match, sizeof(match), "hif-%d", ret);
254 memset(¶ms, 0, sizeof(params));
255 params.match = match;
256 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
257 ret = pp2_hif_init(¶ms, &hifs[core_id]);
259 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id);
266 static inline struct pp2_hif*
267 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
271 if (likely(hifs[core_id] != NULL))
272 return hifs[core_id];
274 rte_spinlock_lock(&priv->lock);
276 ret = mrvl_init_hif(core_id);
278 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
282 if (core_id < mrvl_lcore_first)
283 mrvl_lcore_first = core_id;
285 if (core_id > mrvl_lcore_last)
286 mrvl_lcore_last = core_id;
288 rte_spinlock_unlock(&priv->lock);
290 return hifs[core_id];
294 * Set tx burst function according to offload flag
297 * Pointer to Ethernet device structure.
300 mrvl_set_tx_function(struct rte_eth_dev *dev)
302 struct mrvl_priv *priv = dev->data->dev_private;
304 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
305 if (priv->multiseg) {
306 RTE_LOG(INFO, PMD, "Using multi-segment tx callback\n");
307 dev->tx_pkt_burst = mrvl_tx_sg_pkt_burst;
309 RTE_LOG(INFO, PMD, "Using single-segment tx callback\n");
310 dev->tx_pkt_burst = mrvl_tx_pkt_burst;
315 * Configure rss based on dpdk rss configuration.
318 * Pointer to private structure.
320 * Pointer to RSS configuration.
323 * 0 on success, negative error value otherwise.
326 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
328 if (rss_conf->rss_key)
329 MRVL_LOG(WARNING, "Changing hash key is not supported");
331 if (rss_conf->rss_hf == 0) {
332 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
333 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
334 priv->ppio_params.inqs_params.hash_type =
335 PP2_PPIO_HASH_T_2_TUPLE;
336 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
337 priv->ppio_params.inqs_params.hash_type =
338 PP2_PPIO_HASH_T_5_TUPLE;
339 priv->rss_hf_tcp = 1;
340 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
341 priv->ppio_params.inqs_params.hash_type =
342 PP2_PPIO_HASH_T_5_TUPLE;
343 priv->rss_hf_tcp = 0;
352 * Ethernet device configuration.
354 * Prepare the driver for a given number of TX and RX queues and
358 * Pointer to Ethernet device structure.
361 * 0 on success, negative error value otherwise.
364 mrvl_dev_configure(struct rte_eth_dev *dev)
366 struct mrvl_priv *priv = dev->data->dev_private;
370 MRVL_LOG(INFO, "Device reconfiguration is not supported");
374 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
375 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
376 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d",
377 dev->data->dev_conf.rxmode.mq_mode);
381 if (dev->data->dev_conf.rxmode.split_hdr_size) {
382 MRVL_LOG(INFO, "Split headers not supported");
386 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
387 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
388 MRVL_PP2_ETH_HDRS_LEN;
390 if (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
393 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
394 dev->data->nb_rx_queues);
398 ret = mrvl_configure_txqs(priv, dev->data->port_id,
399 dev->data->nb_tx_queues);
403 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
404 priv->ppio_params.maintain_stats = 1;
405 priv->nb_rx_queues = dev->data->nb_rx_queues;
407 ret = mrvl_tm_init(dev);
411 if (dev->data->nb_rx_queues == 1 &&
412 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
413 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue");
414 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
419 return mrvl_configure_rss(priv,
420 &dev->data->dev_conf.rx_adv_conf.rss_conf);
424 * DPDK callback to change the MTU.
426 * Setting the MTU affects hardware MRU (packets larger than the MRU
430 * Pointer to Ethernet device structure.
435 * 0 on success, negative error value otherwise.
438 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
440 struct mrvl_priv *priv = dev->data->dev_private;
442 uint16_t mbuf_data_size = 0; /* SW buffer size */
445 mru = MRVL_PP2_MTU_TO_MRU(mtu);
447 * min_rx_buf_size is equal to mbuf data size
448 * if pmd didn't set it differently
450 mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
452 * - setting mru greater than the mbuf size resulting in
453 * hw and sw buffer size mismatch
454 * - setting mtu that requires the support of scattered packets
455 * when this feature has not been enabled/supported so far
456 * (TODO check scattered_rx flag here once scattered RX is supported).
458 if (mru - RTE_ETHER_CRC_LEN + MRVL_PKT_OFFS > mbuf_data_size) {
459 mru = mbuf_data_size + RTE_ETHER_CRC_LEN - MRVL_PKT_OFFS;
460 mtu = MRVL_PP2_MRU_TO_MTU(mru);
461 MRVL_LOG(WARNING, "MTU too big, max MTU possible limitted "
462 "by current mbuf size: %u. Set MTU to %u, MRU to %u",
463 mbuf_data_size, mtu, mru);
466 if (mtu < RTE_ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX) {
467 MRVL_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru);
471 dev->data->mtu = mtu;
472 dev->data->dev_conf.rxmode.max_rx_pkt_len = mru - MV_MH_SIZE;
477 ret = pp2_ppio_set_mru(priv->ppio, mru);
479 MRVL_LOG(ERR, "Failed to change MRU");
483 ret = pp2_ppio_set_mtu(priv->ppio, mtu);
485 MRVL_LOG(ERR, "Failed to change MTU");
493 * DPDK callback to bring the link up.
496 * Pointer to Ethernet device structure.
499 * 0 on success, negative error value otherwise.
502 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
504 struct mrvl_priv *priv = dev->data->dev_private;
508 dev->data->dev_link.link_status = ETH_LINK_UP;
512 ret = pp2_ppio_enable(priv->ppio);
517 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
518 * as pp2_ppio_enable() changes port->t_mode from default 0 to
519 * PP2_TRAFFIC_INGRESS_EGRESS.
521 * Set mtu to default DPDK value here.
523 ret = mrvl_mtu_set(dev, dev->data->mtu);
525 pp2_ppio_disable(priv->ppio);
529 dev->data->dev_link.link_status = ETH_LINK_UP;
534 * DPDK callback to bring the link down.
537 * Pointer to Ethernet device structure.
540 * 0 on success, negative error value otherwise.
543 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
545 struct mrvl_priv *priv = dev->data->dev_private;
549 dev->data->dev_link.link_status = ETH_LINK_DOWN;
552 ret = pp2_ppio_disable(priv->ppio);
556 dev->data->dev_link.link_status = ETH_LINK_DOWN;
561 * DPDK callback to start tx queue.
564 * Pointer to Ethernet device structure.
566 * Transmit queue index.
569 * 0 on success, negative error value otherwise.
572 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
574 struct mrvl_priv *priv = dev->data->dev_private;
580 /* passing 1 enables given tx queue */
581 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1);
583 MRVL_LOG(ERR, "Failed to start txq %d", queue_id);
587 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
593 * DPDK callback to stop tx queue.
596 * Pointer to Ethernet device structure.
598 * Transmit queue index.
601 * 0 on success, negative error value otherwise.
604 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
606 struct mrvl_priv *priv = dev->data->dev_private;
612 /* passing 0 disables given tx queue */
613 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0);
615 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id);
619 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
625 * Populate VLAN Filter configuration.
628 * Pointer to Ethernet device structure.
633 * 0 on success, negative error value otherwise.
635 static int mrvl_populate_vlan_table(struct rte_eth_dev *dev, int on)
639 struct rte_vlan_filter_conf *vfc;
641 vfc = &dev->data->vlan_filter_conf;
642 for (j = 0; j < RTE_DIM(vfc->ids); j++) {
645 uint64_t ids = vfc->ids[j];
652 /* count trailing zeroes */
653 vbit = ~ids & (ids - 1);
654 /* clear least significant bit set */
655 ids ^= (ids ^ (ids - 1)) ^ vbit;
658 ret = mrvl_vlan_filter_set(dev, vlan, on);
660 MRVL_LOG(ERR, "Failed to setup VLAN filter\n");
670 * DPDK callback to start the device.
673 * Pointer to Ethernet device structure.
676 * 0 on success, negative errno value on failure.
679 mrvl_dev_start(struct rte_eth_dev *dev)
681 struct mrvl_priv *priv = dev->data->dev_private;
682 char match[MRVL_MATCH_LEN];
683 int ret = 0, i, def_init_size;
684 struct rte_ether_addr *mac_addr;
687 return mrvl_dev_set_link_up(dev);
689 snprintf(match, sizeof(match), "ppio-%d:%d",
690 priv->pp_id, priv->ppio_id);
691 priv->ppio_params.match = match;
694 * Calculate the minimum bpool size for refill feature as follows:
695 * 2 default burst sizes multiply by number of rx queues.
696 * If the bpool size will be below this value, new buffers will
697 * be added to the pool.
699 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
701 /* In case initial bpool size configured in queues setup is
702 * smaller than minimum size add more buffers
704 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
705 if (priv->bpool_init_size < def_init_size) {
706 int buffs_to_add = def_init_size - priv->bpool_init_size;
708 priv->bpool_init_size += buffs_to_add;
709 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
711 MRVL_LOG(ERR, "Failed to add buffers to bpool");
715 * Calculate the maximum bpool size for refill feature as follows:
716 * maximum number of descriptors in rx queue multiply by number
717 * of rx queues plus minimum bpool size.
718 * In case the bpool size will exceed this value, superfluous buffers
721 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
722 priv->bpool_min_size;
724 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
726 MRVL_LOG(ERR, "Failed to init ppio");
731 * In case there are some some stale uc/mc mac addresses flush them
732 * here. It cannot be done during mrvl_dev_close() as port information
733 * is already gone at that point (due to pp2_ppio_deinit() in
736 if (!priv->uc_mc_flushed) {
737 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
740 "Failed to flush uc/mc filter list");
743 priv->uc_mc_flushed = 1;
746 ret = mrvl_mtu_set(dev, dev->data->mtu);
748 MRVL_LOG(ERR, "Failed to set MTU to %d", dev->data->mtu);
750 if (!rte_is_zero_ether_addr(&dev->data->mac_addrs[0]))
751 mrvl_mac_addr_set(dev, &dev->data->mac_addrs[0]);
753 for (i = 1; i < MRVL_MAC_ADDRS_MAX; i++) {
754 mac_addr = &dev->data->mac_addrs[i];
756 /* skip zero address */
757 if (rte_is_zero_ether_addr(mac_addr))
760 mrvl_mac_addr_add(dev, mac_addr, i, 0);
763 if (dev->data->all_multicast == 1)
764 mrvl_allmulticast_enable(dev);
766 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
767 ret = mrvl_populate_vlan_table(dev, 1);
769 MRVL_LOG(ERR, "Failed to populate VLAN table");
774 /* For default QoS config, don't start classifier. */
776 mrvl_qos_cfg->port[dev->data->port_id].use_global_defaults == 0) {
777 ret = mrvl_start_qos_mapping(priv);
779 MRVL_LOG(ERR, "Failed to setup QoS mapping");
784 ret = pp2_ppio_set_loopback(priv->ppio, dev->data->dev_conf.lpbk_mode);
786 MRVL_LOG(ERR, "Failed to set loopback");
790 if (dev->data->promiscuous == 1)
791 mrvl_promiscuous_enable(dev);
793 if (dev->data->dev_link.link_status == ETH_LINK_UP) {
794 ret = mrvl_dev_set_link_up(dev);
796 MRVL_LOG(ERR, "Failed to set link up");
797 dev->data->dev_link.link_status = ETH_LINK_DOWN;
802 /* start tx queues */
803 for (i = 0; i < dev->data->nb_tx_queues; i++) {
804 struct mrvl_txq *txq = dev->data->tx_queues[i];
806 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
808 if (!txq->tx_deferred_start)
812 * All txqs are started by default. Stop them
813 * so that tx_deferred_start works as expected.
815 ret = mrvl_tx_queue_stop(dev, i);
822 mrvl_set_tx_function(dev);
826 MRVL_LOG(ERR, "Failed to start device");
827 pp2_ppio_deinit(priv->ppio);
832 * Flush receive queues.
835 * Pointer to Ethernet device structure.
838 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
842 MRVL_LOG(INFO, "Flushing rx queues");
843 for (i = 0; i < dev->data->nb_rx_queues; i++) {
847 struct mrvl_rxq *q = dev->data->rx_queues[i];
848 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
850 num = MRVL_PP2_RXD_MAX;
851 ret = pp2_ppio_recv(q->priv->ppio,
852 q->priv->rxq_map[q->queue_id].tc,
853 q->priv->rxq_map[q->queue_id].inq,
854 descs, (uint16_t *)&num);
855 } while (ret == 0 && num);
860 * Flush transmit shadow queues.
863 * Pointer to Ethernet device structure.
866 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
869 struct mrvl_txq *txq;
871 MRVL_LOG(INFO, "Flushing tx shadow queues");
872 for (i = 0; i < dev->data->nb_tx_queues; i++) {
873 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
875 for (j = 0; j < RTE_MAX_LCORE; j++) {
876 struct mrvl_shadow_txq *sq;
881 sq = &txq->shadow_txqs[j];
882 mrvl_free_sent_buffers(txq->priv->ppio,
883 hifs[j], j, sq, txq->queue_id, 1);
884 while (sq->tail != sq->head) {
885 uint64_t addr = cookie_addr_high |
886 sq->ent[sq->tail].buff.cookie;
888 (struct rte_mbuf *)addr);
889 sq->tail = (sq->tail + 1) &
890 MRVL_PP2_TX_SHADOWQ_MASK;
892 memset(sq, 0, sizeof(*sq));
898 * Flush hardware bpool (buffer-pool).
901 * Pointer to Ethernet device structure.
904 mrvl_flush_bpool(struct rte_eth_dev *dev)
906 struct mrvl_priv *priv = dev->data->dev_private;
910 unsigned int core_id = rte_lcore_id();
912 if (core_id == LCORE_ID_ANY)
913 core_id = rte_get_main_lcore();
915 hif = mrvl_get_hif(priv, core_id);
917 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
919 MRVL_LOG(ERR, "Failed to get bpool buffers number");
924 struct pp2_buff_inf inf;
927 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
931 addr = cookie_addr_high | inf.cookie;
932 rte_pktmbuf_free((struct rte_mbuf *)addr);
937 * DPDK callback to stop the device.
940 * Pointer to Ethernet device structure.
943 mrvl_dev_stop(struct rte_eth_dev *dev)
945 return mrvl_dev_set_link_down(dev);
949 * DPDK callback to close the device.
952 * Pointer to Ethernet device structure.
955 mrvl_dev_close(struct rte_eth_dev *dev)
957 struct mrvl_priv *priv = dev->data->dev_private;
960 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
963 mrvl_flush_rx_queues(dev);
964 mrvl_flush_tx_shadow_queues(dev);
965 mrvl_flow_deinit(dev);
966 mrvl_mtr_deinit(dev);
968 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
969 struct pp2_ppio_tc_params *tc_params =
970 &priv->ppio_params.inqs_params.tcs_params[i];
972 if (tc_params->inqs_params) {
973 rte_free(tc_params->inqs_params);
974 tc_params->inqs_params = NULL;
979 pp2_cls_tbl_deinit(priv->cls_tbl);
980 priv->cls_tbl = NULL;
984 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
985 priv->qos_tbl = NULL;
988 mrvl_flush_bpool(dev);
992 pp2_ppio_deinit(priv->ppio);
996 /* policer must be released after ppio deinitialization */
997 if (priv->default_policer) {
998 pp2_cls_plcr_deinit(priv->default_policer);
999 priv->default_policer = NULL;
1004 pp2_bpool_deinit(priv->bpool);
1005 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
1011 if (mrvl_dev_num == 0) {
1012 MRVL_LOG(INFO, "Perform MUSDK deinit");
1015 rte_mvep_deinit(MVEP_MOD_T_PP2);
1022 * DPDK callback to retrieve physical link information.
1025 * Pointer to Ethernet device structure.
1026 * @param wait_to_complete
1027 * Wait for request completion (ignored).
1030 * 0 on success, negative error value otherwise.
1033 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
1037 * once MUSDK provides necessary API use it here
1039 struct mrvl_priv *priv = dev->data->dev_private;
1040 struct ethtool_cmd edata;
1042 int ret, fd, link_up;
1047 edata.cmd = ETHTOOL_GSET;
1049 strcpy(req.ifr_name, dev->data->name);
1050 req.ifr_data = (void *)&edata;
1052 fd = socket(AF_INET, SOCK_DGRAM, 0);
1056 ret = ioctl(fd, SIOCETHTOOL, &req);
1064 switch (ethtool_cmd_speed(&edata)) {
1066 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
1069 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
1072 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
1075 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
1078 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
1081 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
1082 ETH_LINK_HALF_DUPLEX;
1083 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
1085 pp2_ppio_get_link_state(priv->ppio, &link_up);
1086 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
1092 * DPDK callback to enable promiscuous mode.
1095 * Pointer to Ethernet device structure.
1098 * 0 on success, negative error value otherwise.
1101 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
1103 struct mrvl_priv *priv = dev->data->dev_private;
1112 ret = pp2_ppio_set_promisc(priv->ppio, 1);
1114 MRVL_LOG(ERR, "Failed to enable promiscuous mode");
1122 * DPDK callback to enable allmulti mode.
1125 * Pointer to Ethernet device structure.
1128 * 0 on success, negative error value otherwise.
1131 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
1133 struct mrvl_priv *priv = dev->data->dev_private;
1142 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
1144 MRVL_LOG(ERR, "Failed enable all-multicast mode");
1152 * DPDK callback to disable promiscuous mode.
1155 * Pointer to Ethernet device structure.
1158 * 0 on success, negative error value otherwise.
1161 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
1163 struct mrvl_priv *priv = dev->data->dev_private;
1172 ret = pp2_ppio_set_promisc(priv->ppio, 0);
1174 MRVL_LOG(ERR, "Failed to disable promiscuous mode");
1182 * DPDK callback to disable allmulticast mode.
1185 * Pointer to Ethernet device structure.
1188 * 0 on success, negative error value otherwise.
1191 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
1193 struct mrvl_priv *priv = dev->data->dev_private;
1202 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
1204 MRVL_LOG(ERR, "Failed to disable all-multicast mode");
1212 * DPDK callback to remove a MAC address.
1215 * Pointer to Ethernet device structure.
1217 * MAC address index.
1220 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1222 struct mrvl_priv *priv = dev->data->dev_private;
1223 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1232 ret = pp2_ppio_remove_mac_addr(priv->ppio,
1233 dev->data->mac_addrs[index].addr_bytes);
1235 rte_ether_format_addr(buf, sizeof(buf),
1236 &dev->data->mac_addrs[index]);
1237 MRVL_LOG(ERR, "Failed to remove mac %s", buf);
1242 * DPDK callback to add a MAC address.
1245 * Pointer to Ethernet device structure.
1247 * MAC address to register.
1249 * MAC address index.
1251 * VMDq pool index to associate address with (unused).
1254 * 0 on success, negative error value otherwise.
1257 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1258 uint32_t index, uint32_t vmdq __rte_unused)
1260 struct mrvl_priv *priv = dev->data->dev_private;
1261 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1271 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
1275 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
1276 * parameter uc_filter_max. Maximum number of mc addresses is then
1277 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
1280 * If more than uc_filter_max uc addresses were added to filter list
1281 * then NIC will switch to promiscuous mode automatically.
1283 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
1284 * were added to filter list then NIC will switch to all-multicast mode
1287 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
1289 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1290 MRVL_LOG(ERR, "Failed to add mac %s", buf);
1298 * DPDK callback to set the primary MAC address.
1301 * Pointer to Ethernet device structure.
1303 * MAC address to register.
1306 * 0 on success, negative error value otherwise.
1309 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1311 struct mrvl_priv *priv = dev->data->dev_private;
1320 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
1322 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1323 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1324 MRVL_LOG(ERR, "Failed to set mac to %s", buf);
1331 * DPDK callback to get device statistics.
1334 * Pointer to Ethernet device structure.
1336 * Stats structure output buffer.
1339 * 0 on success, negative error value otherwise.
1342 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1344 struct mrvl_priv *priv = dev->data->dev_private;
1345 struct pp2_ppio_statistics ppio_stats;
1346 uint64_t drop_mac = 0;
1347 unsigned int i, idx, ret;
1352 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1353 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1354 struct pp2_ppio_inq_statistics rx_stats;
1359 idx = rxq->queue_id;
1360 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1362 "rx queue %d stats out of range (0 - %d)",
1363 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1367 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1368 priv->rxq_map[idx].tc,
1369 priv->rxq_map[idx].inq,
1371 if (unlikely(ret)) {
1373 "Failed to update rx queue %d stats", idx);
1377 stats->q_ibytes[idx] = rxq->bytes_recv;
1378 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1379 stats->q_errors[idx] = rx_stats.drop_early +
1380 rx_stats.drop_fullq +
1383 stats->ibytes += rxq->bytes_recv;
1384 drop_mac += rxq->drop_mac;
1387 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1388 struct mrvl_txq *txq = dev->data->tx_queues[i];
1389 struct pp2_ppio_outq_statistics tx_stats;
1394 idx = txq->queue_id;
1395 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1397 "tx queue %d stats out of range (0 - %d)",
1398 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1401 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1403 if (unlikely(ret)) {
1405 "Failed to update tx queue %d stats", idx);
1409 stats->q_opackets[idx] = tx_stats.deq_desc;
1410 stats->q_obytes[idx] = txq->bytes_sent;
1411 stats->obytes += txq->bytes_sent;
1414 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1415 if (unlikely(ret)) {
1416 MRVL_LOG(ERR, "Failed to update port statistics");
1420 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1421 stats->opackets += ppio_stats.tx_packets;
1422 stats->imissed += ppio_stats.rx_fullq_dropped +
1423 ppio_stats.rx_bm_dropped +
1424 ppio_stats.rx_early_dropped +
1425 ppio_stats.rx_fifo_dropped +
1426 ppio_stats.rx_cls_dropped;
1427 stats->ierrors = drop_mac;
1433 * DPDK callback to clear device statistics.
1436 * Pointer to Ethernet device structure.
1439 * 0 on success, negative error value otherwise.
1442 mrvl_stats_reset(struct rte_eth_dev *dev)
1444 struct mrvl_priv *priv = dev->data->dev_private;
1450 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1451 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1453 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1454 priv->rxq_map[i].inq, NULL, 1);
1455 rxq->bytes_recv = 0;
1459 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1460 struct mrvl_txq *txq = dev->data->tx_queues[i];
1462 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1463 txq->bytes_sent = 0;
1466 return pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1470 * DPDK callback to get extended statistics.
1473 * Pointer to Ethernet device structure.
1475 * Pointer to xstats table.
1477 * Number of entries in xstats table.
1479 * Negative value on error, number of read xstats otherwise.
1482 mrvl_xstats_get(struct rte_eth_dev *dev,
1483 struct rte_eth_xstat *stats, unsigned int n)
1485 struct mrvl_priv *priv = dev->data->dev_private;
1486 struct pp2_ppio_statistics ppio_stats;
1492 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1493 for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
1496 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
1497 val = *(uint32_t *)((uint8_t *)&ppio_stats +
1498 mrvl_xstats_tbl[i].offset);
1499 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t))
1500 val = *(uint64_t *)((uint8_t *)&ppio_stats +
1501 mrvl_xstats_tbl[i].offset);
1506 stats[i].value = val;
1513 * DPDK callback to reset extended statistics.
1516 * Pointer to Ethernet device structure.
1519 * 0 on success, negative error value otherwise.
1522 mrvl_xstats_reset(struct rte_eth_dev *dev)
1524 return mrvl_stats_reset(dev);
1528 * DPDK callback to get extended statistics names.
1530 * @param dev (unused)
1531 * Pointer to Ethernet device structure.
1532 * @param xstats_names
1533 * Pointer to xstats names table.
1535 * Size of the xstats names table.
1537 * Number of read names.
1540 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1541 struct rte_eth_xstat_name *xstats_names,
1547 return RTE_DIM(mrvl_xstats_tbl);
1549 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
1550 strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name,
1551 RTE_ETH_XSTATS_NAME_SIZE);
1557 * DPDK callback to get information about the device.
1560 * Pointer to Ethernet device structure (unused).
1562 * Info structure output buffer.
1565 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1566 struct rte_eth_dev_info *info)
1568 info->speed_capa = ETH_LINK_SPEED_10M |
1569 ETH_LINK_SPEED_100M |
1573 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1574 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1575 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1577 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1578 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1579 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1581 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1582 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1583 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1585 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1586 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1588 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1589 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1591 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1592 ETH_RSS_NONFRAG_IPV4_TCP |
1593 ETH_RSS_NONFRAG_IPV4_UDP;
1595 /* By default packets are dropped if no descriptors are available */
1596 info->default_rxconf.rx_drop_en = 1;
1598 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1604 * Return supported packet types.
1607 * Pointer to Ethernet device structure (unused).
1610 * Const pointer to the table with supported packet types.
1612 static const uint32_t *
1613 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1615 static const uint32_t ptypes[] = {
1617 RTE_PTYPE_L2_ETHER_VLAN,
1618 RTE_PTYPE_L2_ETHER_QINQ,
1620 RTE_PTYPE_L3_IPV4_EXT,
1621 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1623 RTE_PTYPE_L3_IPV6_EXT,
1624 RTE_PTYPE_L2_ETHER_ARP,
1633 * DPDK callback to get information about specific receive queue.
1636 * Pointer to Ethernet device structure.
1637 * @param rx_queue_id
1638 * Receive queue index.
1640 * Receive queue information structure.
1642 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1643 struct rte_eth_rxq_info *qinfo)
1645 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1646 struct mrvl_priv *priv = dev->data->dev_private;
1647 int inq = priv->rxq_map[rx_queue_id].inq;
1648 int tc = priv->rxq_map[rx_queue_id].tc;
1649 struct pp2_ppio_tc_params *tc_params =
1650 &priv->ppio_params.inqs_params.tcs_params[tc];
1653 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1657 * DPDK callback to get information about specific transmit queue.
1660 * Pointer to Ethernet device structure.
1661 * @param tx_queue_id
1662 * Transmit queue index.
1664 * Transmit queue information structure.
1666 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1667 struct rte_eth_txq_info *qinfo)
1669 struct mrvl_priv *priv = dev->data->dev_private;
1670 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id];
1673 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1674 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1678 * DPDK callback to Configure a VLAN filter.
1681 * Pointer to Ethernet device structure.
1683 * VLAN ID to filter.
1688 * 0 on success, negative error value otherwise.
1691 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1693 struct mrvl_priv *priv = dev->data->dev_private;
1701 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1702 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1706 * DPDK callback to Configure VLAN offload.
1709 * Pointer to Ethernet device structure.
1711 * VLAN offload mask.
1714 * 0 on success, negative error value otherwise.
1716 static int mrvl_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1718 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
1721 if (mask & ETH_VLAN_STRIP_MASK)
1722 MRVL_LOG(ERR, "VLAN stripping is not supported\n");
1724 if (mask & ETH_VLAN_FILTER_MASK) {
1725 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1726 ret = mrvl_populate_vlan_table(dev, 1);
1728 ret = mrvl_populate_vlan_table(dev, 0);
1734 if (mask & ETH_VLAN_EXTEND_MASK)
1735 MRVL_LOG(ERR, "Extend VLAN not supported\n");
1741 * Release buffers to hardware bpool (buffer-pool)
1744 * Receive queue pointer.
1746 * Number of buffers to release to bpool.
1749 * 0 on success, negative error value otherwise.
1752 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1754 struct buff_release_entry entries[num];
1755 struct rte_mbuf *mbufs[num];
1757 unsigned int core_id;
1758 struct pp2_hif *hif;
1759 struct pp2_bpool *bpool;
1761 core_id = rte_lcore_id();
1762 if (core_id == LCORE_ID_ANY)
1763 core_id = rte_get_main_lcore();
1765 hif = mrvl_get_hif(rxq->priv, core_id);
1769 bpool = rxq->priv->bpool;
1771 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1775 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1777 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1779 for (i = 0; i < num; i++) {
1780 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1781 != cookie_addr_high) {
1783 "mbuf virtual addr high is out of range "
1784 "0x%x instead of 0x%x\n",
1785 (uint32_t)((uint64_t)mbufs[i] >> 32),
1786 (uint32_t)(cookie_addr_high >> 32));
1790 entries[i].buff.addr =
1791 rte_mbuf_data_iova_default(mbufs[i]);
1792 entries[i].buff.cookie = (uintptr_t)mbufs[i];
1793 entries[i].bpool = bpool;
1796 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1797 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1804 for (; i < num; i++)
1805 rte_pktmbuf_free(mbufs[i]);
1811 * DPDK callback to configure the receive queue.
1814 * Pointer to Ethernet device structure.
1818 * Number of descriptors to configure in queue.
1820 * NUMA socket on which memory must be allocated.
1822 * Thresholds parameters.
1824 * Memory pool for buffer allocations.
1827 * 0 on success, negative error value otherwise.
1830 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1831 unsigned int socket,
1832 const struct rte_eth_rxconf *conf,
1833 struct rte_mempool *mp)
1835 struct mrvl_priv *priv = dev->data->dev_private;
1836 struct mrvl_rxq *rxq;
1837 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
1838 uint32_t max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1842 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1844 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1846 * Unknown TC mapping, mapping will not have a correct queue.
1848 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu",
1849 idx, priv->ppio_id);
1853 frame_size = buf_size - RTE_PKTMBUF_HEADROOM -
1854 MRVL_PKT_EFFEC_OFFS + RTE_ETHER_CRC_LEN;
1855 if (frame_size < max_rx_pkt_len) {
1857 "Mbuf size must be increased to %u bytes to hold up "
1858 "to %u bytes of data.",
1859 buf_size + max_rx_pkt_len - frame_size,
1861 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1862 MRVL_LOG(INFO, "Setting max rx pkt len to %u",
1863 dev->data->dev_conf.rxmode.max_rx_pkt_len);
1866 if (dev->data->rx_queues[idx]) {
1867 rte_free(dev->data->rx_queues[idx]);
1868 dev->data->rx_queues[idx] = NULL;
1871 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1877 rxq->cksum_enabled = offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
1878 rxq->queue_id = idx;
1879 rxq->port_id = dev->data->port_id;
1880 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1882 tc = priv->rxq_map[rxq->queue_id].tc,
1883 inq = priv->rxq_map[rxq->queue_id].inq;
1884 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1887 ret = mrvl_fill_bpool(rxq, desc);
1893 priv->bpool_init_size += desc;
1895 dev->data->rx_queues[idx] = rxq;
1901 * DPDK callback to release the receive queue.
1904 * Generic receive queue pointer.
1907 mrvl_rx_queue_release(void *rxq)
1909 struct mrvl_rxq *q = rxq;
1910 struct pp2_ppio_tc_params *tc_params;
1911 int i, num, tc, inq;
1912 struct pp2_hif *hif;
1913 unsigned int core_id = rte_lcore_id();
1915 if (core_id == LCORE_ID_ANY)
1916 core_id = rte_get_main_lcore();
1921 hif = mrvl_get_hif(q->priv, core_id);
1926 tc = q->priv->rxq_map[q->queue_id].tc;
1927 inq = q->priv->rxq_map[q->queue_id].inq;
1928 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1929 num = tc_params->inqs_params[inq].size;
1930 for (i = 0; i < num; i++) {
1931 struct pp2_buff_inf inf;
1934 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1935 addr = cookie_addr_high | inf.cookie;
1936 rte_pktmbuf_free((struct rte_mbuf *)addr);
1943 * DPDK callback to configure the transmit queue.
1946 * Pointer to Ethernet device structure.
1948 * Transmit queue index.
1950 * Number of descriptors to configure in the queue.
1952 * NUMA socket on which memory must be allocated.
1954 * Tx queue configuration parameters.
1957 * 0 on success, negative error value otherwise.
1960 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1961 unsigned int socket,
1962 const struct rte_eth_txconf *conf)
1964 struct mrvl_priv *priv = dev->data->dev_private;
1965 struct mrvl_txq *txq;
1967 if (dev->data->tx_queues[idx]) {
1968 rte_free(dev->data->tx_queues[idx]);
1969 dev->data->tx_queues[idx] = NULL;
1972 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1977 txq->queue_id = idx;
1978 txq->port_id = dev->data->port_id;
1979 txq->tx_deferred_start = conf->tx_deferred_start;
1980 dev->data->tx_queues[idx] = txq;
1982 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1988 * DPDK callback to release the transmit queue.
1991 * Generic transmit queue pointer.
1994 mrvl_tx_queue_release(void *txq)
1996 struct mrvl_txq *q = txq;
2005 * DPDK callback to get flow control configuration.
2008 * Pointer to Ethernet device structure.
2010 * Pointer to the flow control configuration.
2013 * 0 on success, negative error value otherwise.
2016 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2018 struct mrvl_priv *priv = dev->data->dev_private;
2024 ret = pp2_ppio_get_rx_pause(priv->ppio, &en);
2026 MRVL_LOG(ERR, "Failed to read rx pause state");
2030 fc_conf->mode = en ? RTE_FC_RX_PAUSE : RTE_FC_NONE;
2036 * DPDK callback to set flow control configuration.
2039 * Pointer to Ethernet device structure.
2041 * Pointer to the flow control configuration.
2044 * 0 on success, negative error value otherwise.
2047 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2049 struct mrvl_priv *priv = dev->data->dev_private;
2054 if (fc_conf->high_water ||
2055 fc_conf->low_water ||
2056 fc_conf->pause_time ||
2057 fc_conf->mac_ctrl_frame_fwd ||
2059 MRVL_LOG(ERR, "Flowctrl parameter is not supported");
2064 if (fc_conf->mode == RTE_FC_NONE ||
2065 fc_conf->mode == RTE_FC_RX_PAUSE) {
2068 en = fc_conf->mode == RTE_FC_NONE ? 0 : 1;
2069 ret = pp2_ppio_set_rx_pause(priv->ppio, en);
2072 "Failed to change flowctrl on RX side");
2081 * Update RSS hash configuration
2084 * Pointer to Ethernet device structure.
2086 * Pointer to RSS configuration.
2089 * 0 on success, negative error value otherwise.
2092 mrvl_rss_hash_update(struct rte_eth_dev *dev,
2093 struct rte_eth_rss_conf *rss_conf)
2095 struct mrvl_priv *priv = dev->data->dev_private;
2100 return mrvl_configure_rss(priv, rss_conf);
2104 * DPDK callback to get RSS hash configuration.
2107 * Pointer to Ethernet device structure.
2109 * Pointer to RSS configuration.
2115 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
2116 struct rte_eth_rss_conf *rss_conf)
2118 struct mrvl_priv *priv = dev->data->dev_private;
2119 enum pp2_ppio_hash_type hash_type =
2120 priv->ppio_params.inqs_params.hash_type;
2122 rss_conf->rss_key = NULL;
2124 if (hash_type == PP2_PPIO_HASH_T_NONE)
2125 rss_conf->rss_hf = 0;
2126 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
2127 rss_conf->rss_hf = ETH_RSS_IPV4;
2128 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
2129 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
2130 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
2131 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
2137 * DPDK callback to get rte_flow callbacks.
2140 * Pointer to the device structure.
2144 * Flow filter operation.
2146 * Pointer to pass the flow ops.
2149 * 0 on success, negative error value otherwise.
2152 mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
2153 enum rte_filter_type filter_type,
2154 enum rte_filter_op filter_op, void *arg)
2156 switch (filter_type) {
2157 case RTE_ETH_FILTER_GENERIC:
2158 if (filter_op != RTE_ETH_FILTER_GET)
2160 *(const void **)arg = &mrvl_flow_ops;
2163 MRVL_LOG(WARNING, "Filter type (%d) not supported",
2170 * DPDK callback to get rte_mtr callbacks.
2173 * Pointer to the device structure.
2175 * Pointer to pass the mtr ops.
2181 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2183 *(const void **)ops = &mrvl_mtr_ops;
2189 * DPDK callback to get rte_tm callbacks.
2192 * Pointer to the device structure.
2194 * Pointer to pass the tm ops.
2200 mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2202 *(const void **)ops = &mrvl_tm_ops;
2207 static const struct eth_dev_ops mrvl_ops = {
2208 .dev_configure = mrvl_dev_configure,
2209 .dev_start = mrvl_dev_start,
2210 .dev_stop = mrvl_dev_stop,
2211 .dev_set_link_up = mrvl_dev_set_link_up,
2212 .dev_set_link_down = mrvl_dev_set_link_down,
2213 .dev_close = mrvl_dev_close,
2214 .link_update = mrvl_link_update,
2215 .promiscuous_enable = mrvl_promiscuous_enable,
2216 .allmulticast_enable = mrvl_allmulticast_enable,
2217 .promiscuous_disable = mrvl_promiscuous_disable,
2218 .allmulticast_disable = mrvl_allmulticast_disable,
2219 .mac_addr_remove = mrvl_mac_addr_remove,
2220 .mac_addr_add = mrvl_mac_addr_add,
2221 .mac_addr_set = mrvl_mac_addr_set,
2222 .mtu_set = mrvl_mtu_set,
2223 .stats_get = mrvl_stats_get,
2224 .stats_reset = mrvl_stats_reset,
2225 .xstats_get = mrvl_xstats_get,
2226 .xstats_reset = mrvl_xstats_reset,
2227 .xstats_get_names = mrvl_xstats_get_names,
2228 .dev_infos_get = mrvl_dev_infos_get,
2229 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
2230 .rxq_info_get = mrvl_rxq_info_get,
2231 .txq_info_get = mrvl_txq_info_get,
2232 .vlan_filter_set = mrvl_vlan_filter_set,
2233 .vlan_offload_set = mrvl_vlan_offload_set,
2234 .tx_queue_start = mrvl_tx_queue_start,
2235 .tx_queue_stop = mrvl_tx_queue_stop,
2236 .rx_queue_setup = mrvl_rx_queue_setup,
2237 .rx_queue_release = mrvl_rx_queue_release,
2238 .tx_queue_setup = mrvl_tx_queue_setup,
2239 .tx_queue_release = mrvl_tx_queue_release,
2240 .flow_ctrl_get = mrvl_flow_ctrl_get,
2241 .flow_ctrl_set = mrvl_flow_ctrl_set,
2242 .rss_hash_update = mrvl_rss_hash_update,
2243 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
2244 .filter_ctrl = mrvl_eth_filter_ctrl,
2245 .mtr_ops_get = mrvl_mtr_ops_get,
2246 .tm_ops_get = mrvl_tm_ops_get,
2250 * Return packet type information and l3/l4 offsets.
2253 * Pointer to the received packet descriptor.
2260 * Packet type information.
2262 static inline uint64_t
2263 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
2264 uint8_t *l3_offset, uint8_t *l4_offset)
2266 enum pp2_inq_l3_type l3_type;
2267 enum pp2_inq_l4_type l4_type;
2268 enum pp2_inq_vlan_tag vlan_tag;
2269 uint64_t packet_type;
2271 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
2272 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
2273 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag);
2275 packet_type = RTE_PTYPE_L2_ETHER;
2278 case PP2_INQ_VLAN_TAG_SINGLE:
2279 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
2281 case PP2_INQ_VLAN_TAG_DOUBLE:
2282 case PP2_INQ_VLAN_TAG_TRIPLE:
2283 packet_type |= RTE_PTYPE_L2_ETHER_QINQ;
2290 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
2291 packet_type |= RTE_PTYPE_L3_IPV4;
2293 case PP2_INQ_L3_TYPE_IPV4_OK:
2294 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
2296 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
2297 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
2299 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
2300 packet_type |= RTE_PTYPE_L3_IPV6;
2302 case PP2_INQ_L3_TYPE_IPV6_EXT:
2303 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
2305 case PP2_INQ_L3_TYPE_ARP:
2306 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
2308 * In case of ARP l4_offset is set to wrong value.
2309 * Set it to proper one so that later on mbuf->l3_len can be
2310 * calculated subtracting l4_offset and l3_offset.
2312 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
2319 case PP2_INQ_L4_TYPE_TCP:
2320 packet_type |= RTE_PTYPE_L4_TCP;
2322 case PP2_INQ_L4_TYPE_UDP:
2323 packet_type |= RTE_PTYPE_L4_UDP;
2333 * Get offload information from the received packet descriptor.
2336 * Pointer to the received packet descriptor.
2339 * Mbuf offload flags.
2341 static inline uint64_t
2342 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
2345 enum pp2_inq_desc_status status;
2347 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
2348 if (unlikely(status != PP2_DESC_ERR_OK))
2349 flags = PKT_RX_IP_CKSUM_BAD;
2351 flags = PKT_RX_IP_CKSUM_GOOD;
2353 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
2354 if (unlikely(status != PP2_DESC_ERR_OK))
2355 flags |= PKT_RX_L4_CKSUM_BAD;
2357 flags |= PKT_RX_L4_CKSUM_GOOD;
2363 * DPDK callback for receive.
2366 * Generic pointer to the receive queue.
2368 * Array to store received packets.
2370 * Maximum number of packets in array.
2373 * Number of packets successfully received.
2376 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2378 struct mrvl_rxq *q = rxq;
2379 struct pp2_ppio_desc descs[nb_pkts];
2380 struct pp2_bpool *bpool;
2381 int i, ret, rx_done = 0;
2383 struct pp2_hif *hif;
2384 unsigned int core_id = rte_lcore_id();
2386 hif = mrvl_get_hif(q->priv, core_id);
2388 if (unlikely(!q->priv->ppio || !hif))
2391 bpool = q->priv->bpool;
2393 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
2394 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
2395 if (unlikely(ret < 0))
2398 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
2400 for (i = 0; i < nb_pkts; i++) {
2401 struct rte_mbuf *mbuf;
2402 uint8_t l3_offset, l4_offset;
2403 enum pp2_inq_desc_status status;
2406 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2407 struct pp2_ppio_desc *pref_desc;
2410 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
2411 pref_addr = cookie_addr_high |
2412 pp2_ppio_inq_desc_get_cookie(pref_desc);
2413 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
2414 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
2417 addr = cookie_addr_high |
2418 pp2_ppio_inq_desc_get_cookie(&descs[i]);
2419 mbuf = (struct rte_mbuf *)addr;
2420 rte_pktmbuf_reset(mbuf);
2422 /* drop packet in case of mac, overrun or resource error */
2423 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
2424 if (unlikely(status != PP2_DESC_ERR_OK)) {
2425 struct pp2_buff_inf binf = {
2426 .addr = rte_mbuf_data_iova_default(mbuf),
2427 .cookie = (uint64_t)mbuf,
2430 pp2_bpool_put_buff(hif, bpool, &binf);
2431 mrvl_port_bpool_size
2432 [bpool->pp2_id][bpool->id][core_id]++;
2437 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
2438 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
2439 mbuf->data_len = mbuf->pkt_len;
2440 mbuf->port = q->port_id;
2442 mrvl_desc_to_packet_type_and_offset(&descs[i],
2445 mbuf->l2_len = l3_offset;
2446 mbuf->l3_len = l4_offset - l3_offset;
2448 if (likely(q->cksum_enabled))
2449 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
2451 rx_pkts[rx_done++] = mbuf;
2452 q->bytes_recv += mbuf->pkt_len;
2455 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
2456 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
2458 if (unlikely(num <= q->priv->bpool_min_size ||
2459 (!rx_done && num < q->priv->bpool_init_size))) {
2460 mrvl_fill_bpool(q, MRVL_BURST_SIZE);
2461 } else if (unlikely(num > q->priv->bpool_max_size)) {
2463 int pkt_to_remove = num - q->priv->bpool_init_size;
2464 struct rte_mbuf *mbuf;
2465 struct pp2_buff_inf buff;
2467 for (i = 0; i < pkt_to_remove; i++) {
2468 ret = pp2_bpool_get_buff(hif, bpool, &buff);
2471 mbuf = (struct rte_mbuf *)
2472 (cookie_addr_high | buff.cookie);
2473 rte_pktmbuf_free(mbuf);
2475 mrvl_port_bpool_size
2476 [bpool->pp2_id][bpool->id][core_id] -= i;
2478 rte_spinlock_unlock(&q->priv->lock);
2485 * Prepare offload information.
2490 * Pointer to the pp2_ouq_l3_type structure.
2492 * Pointer to the pp2_outq_l4_type structure.
2493 * @param gen_l3_cksum
2494 * Will be set to 1 in case l3 checksum is computed.
2496 * Will be set to 1 in case l4 checksum is computed.
2499 mrvl_prepare_proto_info(uint64_t ol_flags,
2500 enum pp2_outq_l3_type *l3_type,
2501 enum pp2_outq_l4_type *l4_type,
2506 * Based on ol_flags prepare information
2507 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
2509 * in most of the checksum cases ipv4 must be set, so this is the
2512 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
2513 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
2515 if (ol_flags & PKT_TX_IPV6) {
2516 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
2517 /* no checksum for ipv6 header */
2521 if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM) {
2522 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
2524 } else if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM) {
2525 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
2528 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
2529 /* no checksum for other type */
2535 * Release already sent buffers to bpool (buffer-pool).
2538 * Pointer to the port structure.
2540 * Pointer to the MUSDK hardware interface.
2542 * Pointer to the shadow queue.
2546 * Force releasing packets.
2549 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2550 unsigned int core_id, struct mrvl_shadow_txq *sq,
2553 struct buff_release_entry *entry;
2554 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2557 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2559 sq->num_to_release += nb_done;
2561 if (likely(!force &&
2562 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2565 nb_done = sq->num_to_release;
2566 sq->num_to_release = 0;
2568 for (i = 0; i < nb_done; i++) {
2569 entry = &sq->ent[sq->tail + num];
2570 if (unlikely(!entry->buff.addr)) {
2572 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
2573 sq->tail, (u64)entry->buff.cookie,
2574 (u64)entry->buff.addr);
2579 if (unlikely(!entry->bpool)) {
2580 struct rte_mbuf *mbuf;
2582 mbuf = (struct rte_mbuf *)entry->buff.cookie;
2583 rte_pktmbuf_free(mbuf);
2588 mrvl_port_bpool_size
2589 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2591 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2596 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2598 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2605 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2606 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2612 * DPDK callback for transmit.
2615 * Generic pointer transmit queue.
2617 * Packets to transmit.
2619 * Number of packets in array.
2622 * Number of packets successfully transmitted.
2625 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2627 struct mrvl_txq *q = txq;
2628 struct mrvl_shadow_txq *sq;
2629 struct pp2_hif *hif;
2630 struct pp2_ppio_desc descs[nb_pkts];
2631 unsigned int core_id = rte_lcore_id();
2632 int i, bytes_sent = 0;
2633 uint16_t num, sq_free_size;
2636 hif = mrvl_get_hif(q->priv, core_id);
2637 sq = &q->shadow_txqs[core_id];
2639 if (unlikely(!q->priv->ppio || !hif))
2643 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2644 sq, q->queue_id, 0);
2646 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2647 if (unlikely(nb_pkts > sq_free_size))
2648 nb_pkts = sq_free_size;
2650 for (i = 0; i < nb_pkts; i++) {
2651 struct rte_mbuf *mbuf = tx_pkts[i];
2652 int gen_l3_cksum, gen_l4_cksum;
2653 enum pp2_outq_l3_type l3_type;
2654 enum pp2_outq_l4_type l4_type;
2656 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2657 struct rte_mbuf *pref_pkt_hdr;
2659 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2660 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2661 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2664 mrvl_fill_shadowq(sq, mbuf);
2665 mrvl_fill_desc(&descs[i], mbuf);
2667 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2669 * in case unsupported ol_flags were passed
2670 * do not update descriptor offload information
2672 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS))
2674 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
2675 &gen_l3_cksum, &gen_l4_cksum);
2677 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2679 mbuf->l2_len + mbuf->l3_len,
2680 gen_l3_cksum, gen_l4_cksum);
2684 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2685 /* number of packets that were not sent */
2686 if (unlikely(num > nb_pkts)) {
2687 for (i = nb_pkts; i < num; i++) {
2688 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2689 MRVL_PP2_TX_SHADOWQ_MASK;
2690 addr = sq->ent[sq->head].buff.cookie;
2692 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2694 sq->size -= num - nb_pkts;
2697 q->bytes_sent += bytes_sent;
2702 /** DPDK callback for S/G transmit.
2705 * Generic pointer transmit queue.
2707 * Packets to transmit.
2709 * Number of packets in array.
2712 * Number of packets successfully transmitted.
2715 mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
2718 struct mrvl_txq *q = txq;
2719 struct mrvl_shadow_txq *sq;
2720 struct pp2_hif *hif;
2721 struct pp2_ppio_desc descs[nb_pkts * PP2_PPIO_DESC_NUM_FRAGS];
2722 struct pp2_ppio_sg_pkts pkts;
2723 uint8_t frags[nb_pkts];
2724 unsigned int core_id = rte_lcore_id();
2725 int i, j, bytes_sent = 0;
2726 int tail, tail_first;
2727 uint16_t num, sq_free_size;
2728 uint16_t nb_segs, total_descs = 0;
2731 hif = mrvl_get_hif(q->priv, core_id);
2732 sq = &q->shadow_txqs[core_id];
2736 if (unlikely(!q->priv->ppio || !hif))
2740 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2741 sq, q->queue_id, 0);
2743 /* Save shadow queue free size */
2744 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2747 for (i = 0; i < nb_pkts; i++) {
2748 struct rte_mbuf *mbuf = tx_pkts[i];
2749 struct rte_mbuf *seg = NULL;
2750 int gen_l3_cksum, gen_l4_cksum;
2751 enum pp2_outq_l3_type l3_type;
2752 enum pp2_outq_l4_type l4_type;
2754 nb_segs = mbuf->nb_segs;
2756 total_descs += nb_segs;
2759 * Check if total_descs does not exceed
2760 * shadow queue free size
2762 if (unlikely(total_descs > sq_free_size)) {
2763 total_descs -= nb_segs;
2767 /* Check if nb_segs does not exceed the max nb of desc per
2770 if (nb_segs > PP2_PPIO_DESC_NUM_FRAGS) {
2771 total_descs -= nb_segs;
2773 "Too many segments. Packet won't be sent.\n");
2777 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2778 struct rte_mbuf *pref_pkt_hdr;
2780 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2781 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2782 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2785 pkts.frags[pkts.num] = nb_segs;
2789 for (j = 0; j < nb_segs - 1; j++) {
2790 /* For the subsequent segments, set shadow queue
2793 mrvl_fill_shadowq(sq, NULL);
2794 mrvl_fill_desc(&descs[tail], seg);
2799 /* Put first mbuf info in last shadow queue entry */
2800 mrvl_fill_shadowq(sq, mbuf);
2801 /* Update descriptor with last segment */
2802 mrvl_fill_desc(&descs[tail++], seg);
2804 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2805 /* In case unsupported ol_flags were passed
2806 * do not update descriptor offload information
2808 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS))
2810 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
2811 &gen_l3_cksum, &gen_l4_cksum);
2813 pp2_ppio_outq_desc_set_proto_info(&descs[tail_first], l3_type,
2814 l4_type, mbuf->l2_len,
2815 mbuf->l2_len + mbuf->l3_len,
2816 gen_l3_cksum, gen_l4_cksum);
2820 pp2_ppio_send_sg(q->priv->ppio, hif, q->queue_id, descs,
2821 &total_descs, &pkts);
2822 /* number of packets that were not sent */
2823 if (unlikely(num > total_descs)) {
2824 for (i = total_descs; i < num; i++) {
2825 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2826 MRVL_PP2_TX_SHADOWQ_MASK;
2828 addr = sq->ent[sq->head].buff.cookie;
2831 rte_pktmbuf_pkt_len((struct rte_mbuf *)
2832 (cookie_addr_high | addr));
2834 sq->size -= num - total_descs;
2838 q->bytes_sent += bytes_sent;
2844 * Initialize packet processor.
2847 * 0 on success, negative error value otherwise.
2852 struct pp2_init_params init_params;
2854 memset(&init_params, 0, sizeof(init_params));
2855 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2856 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2857 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2859 return pp2_init(&init_params);
2863 * Deinitialize packet processor.
2866 * 0 on success, negative error value otherwise.
2869 mrvl_deinit_pp2(void)
2875 * Create private device structure.
2878 * Pointer to the port name passed in the initialization parameters.
2881 * Pointer to the newly allocated private device structure.
2883 static struct mrvl_priv *
2884 mrvl_priv_create(const char *dev_name)
2886 struct pp2_bpool_params bpool_params;
2887 char match[MRVL_MATCH_LEN];
2888 struct mrvl_priv *priv;
2891 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2895 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2896 &priv->pp_id, &priv->ppio_id);
2900 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2901 PP2_BPOOL_NUM_POOLS);
2904 priv->bpool_bit = bpool_bit;
2906 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2908 memset(&bpool_params, 0, sizeof(bpool_params));
2909 bpool_params.match = match;
2910 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2911 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2913 goto out_clear_bpool_bit;
2915 priv->ppio_params.type = PP2_PPIO_T_NIC;
2916 rte_spinlock_init(&priv->lock);
2919 out_clear_bpool_bit:
2920 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2927 * Create device representing Ethernet port.
2930 * Pointer to the port's name.
2933 * 0 on success, negative error value otherwise.
2936 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2938 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2939 struct rte_eth_dev *eth_dev;
2940 struct mrvl_priv *priv;
2943 eth_dev = rte_eth_dev_allocate(name);
2947 priv = mrvl_priv_create(name);
2952 eth_dev->data->dev_private = priv;
2954 eth_dev->data->mac_addrs =
2955 rte_zmalloc("mac_addrs",
2956 RTE_ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2957 if (!eth_dev->data->mac_addrs) {
2958 MRVL_LOG(ERR, "Failed to allocate space for eth addrs");
2963 memset(&req, 0, sizeof(req));
2964 strcpy(req.ifr_name, name);
2965 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2969 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2970 req.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN);
2972 eth_dev->device = &vdev->device;
2973 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2974 mrvl_set_tx_function(eth_dev);
2975 eth_dev->dev_ops = &mrvl_ops;
2976 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2978 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
2980 rte_eth_dev_probing_finish(eth_dev);
2983 rte_eth_dev_release_port(eth_dev);
2989 * Callback used by rte_kvargs_process() during argument parsing.
2992 * Pointer to the parsed key (unused).
2994 * Pointer to the parsed value.
2996 * Pointer to the extra arguments which contains address of the
2997 * table of pointers to parsed interface names.
3003 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
3006 struct mrvl_ifnames *ifnames = extra_args;
3008 ifnames->names[ifnames->idx++] = value;
3014 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
3017 mrvl_deinit_hifs(void)
3021 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
3023 pp2_hif_deinit(hifs[i]);
3025 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
3026 memset(hifs, 0, sizeof(hifs));
3030 * DPDK callback to register the virtual device.
3033 * Pointer to the virtual device.
3036 * 0 on success, negative error value otherwise.
3039 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
3041 struct rte_kvargs *kvlist;
3042 struct mrvl_ifnames ifnames;
3044 uint32_t i, ifnum, cfgnum;
3047 params = rte_vdev_device_args(vdev);
3051 kvlist = rte_kvargs_parse(params, valid_args);
3055 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
3056 if (ifnum > RTE_DIM(ifnames.names))
3057 goto out_free_kvlist;
3060 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
3061 mrvl_get_ifnames, &ifnames);
3065 * The below system initialization should be done only once,
3066 * on the first provided configuration file
3068 if (!mrvl_qos_cfg) {
3069 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
3070 MRVL_LOG(INFO, "Parsing config file!");
3072 MRVL_LOG(ERR, "Cannot handle more than one config file!");
3073 goto out_free_kvlist;
3074 } else if (cfgnum == 1) {
3075 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
3076 mrvl_get_qoscfg, &mrvl_qos_cfg);
3083 MRVL_LOG(INFO, "Perform MUSDK initializations");
3085 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist);
3087 goto out_free_kvlist;
3089 ret = mrvl_init_pp2();
3091 MRVL_LOG(ERR, "Failed to init PP!");
3092 rte_mvep_deinit(MVEP_MOD_T_PP2);
3093 goto out_free_kvlist;
3096 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
3097 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
3099 mrvl_lcore_first = RTE_MAX_LCORE;
3100 mrvl_lcore_last = 0;
3103 for (i = 0; i < ifnum; i++) {
3104 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]);
3105 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
3111 rte_kvargs_free(kvlist);
3115 rte_pmd_mrvl_remove(vdev);
3118 rte_kvargs_free(kvlist);
3124 * DPDK callback to remove virtual device.
3127 * Pointer to the removed virtual device.
3130 * 0 on success, negative error value otherwise.
3133 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
3138 RTE_ETH_FOREACH_DEV(port_id) {
3139 if (rte_eth_devices[port_id].device != &vdev->device)
3141 ret |= rte_eth_dev_close(port_id);
3144 return ret == 0 ? 0 : -EIO;
3147 static struct rte_vdev_driver pmd_mrvl_drv = {
3148 .probe = rte_pmd_mrvl_probe,
3149 .remove = rte_pmd_mrvl_remove,
3152 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv);
3153 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2);
3154 RTE_LOG_REGISTER(mrvl_logtype, pmd.net.mvpp2, NOTICE);