1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Marvell International Ltd.
3 * Copyright(c) 2017 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 0x01
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_OFFLOADS (DEV_TX_OFFLOAD_IPV4_CKSUM | \
67 DEV_TX_OFFLOAD_UDP_CKSUM | \
68 DEV_TX_OFFLOAD_TCP_CKSUM | \
69 DEV_TX_OFFLOAD_MULTI_SEGS)
71 static const char * const valid_args[] = {
77 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
78 static struct pp2_hif *hifs[RTE_MAX_LCORE];
79 static int used_bpools[PP2_NUM_PKT_PROC] = {
80 [0 ... PP2_NUM_PKT_PROC - 1] = MRVL_MUSDK_BPOOLS_RESERVED
83 static struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
84 static int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
85 static uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
88 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
93 * To use buffer harvesting based on loopback port shadow queue structure
94 * was introduced for buffers information bookkeeping.
96 * Before sending the packet, related buffer information (pp2_buff_inf) is
97 * stored in shadow queue. After packet is transmitted no longer used
98 * packet buffer is released back to it's original hardware pool,
99 * on condition it originated from interface.
100 * In case it was generated by application itself i.e: mbuf->port field is
101 * 0xff then its released to software mempool.
103 struct mrvl_shadow_txq {
104 int head; /* write index - used when sending buffers */
105 int tail; /* read index - used when releasing buffers */
106 u16 size; /* queue occupied size */
107 u16 num_to_release; /* number of descriptors sent, that can be
110 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
114 struct mrvl_priv *priv;
115 struct rte_mempool *mp;
124 struct mrvl_priv *priv;
128 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
129 int tx_deferred_start;
132 static int mrvl_lcore_first;
133 static int mrvl_lcore_last;
134 static int mrvl_dev_num;
136 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
137 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
138 struct pp2_hif *hif, unsigned int core_id,
139 struct mrvl_shadow_txq *sq, int qid, int force);
141 static uint16_t mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
143 static uint16_t mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
145 static int rte_pmd_mrvl_remove(struct rte_vdev_device *vdev);
146 static void mrvl_deinit_pp2(void);
147 static void mrvl_deinit_hifs(void);
150 #define MRVL_XSTATS_TBL_ENTRY(name) { \
151 #name, offsetof(struct pp2_ppio_statistics, name), \
152 sizeof(((struct pp2_ppio_statistics *)0)->name) \
155 /* Table with xstats data */
160 } mrvl_xstats_tbl[] = {
161 MRVL_XSTATS_TBL_ENTRY(rx_bytes),
162 MRVL_XSTATS_TBL_ENTRY(rx_packets),
163 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets),
164 MRVL_XSTATS_TBL_ENTRY(rx_errors),
165 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped),
166 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped),
167 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped),
168 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped),
169 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped),
170 MRVL_XSTATS_TBL_ENTRY(tx_bytes),
171 MRVL_XSTATS_TBL_ENTRY(tx_packets),
172 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets),
173 MRVL_XSTATS_TBL_ENTRY(tx_errors)
177 mrvl_fill_shadowq(struct mrvl_shadow_txq *sq, struct rte_mbuf *buf)
179 sq->ent[sq->head].buff.cookie = (uint64_t)buf;
180 sq->ent[sq->head].buff.addr = buf ?
181 rte_mbuf_data_iova_default(buf) : 0;
183 sq->ent[sq->head].bpool =
184 (unlikely(!buf || buf->port >= RTE_MAX_ETHPORTS ||
185 buf->refcnt > 1)) ? NULL :
186 mrvl_port_to_bpool_lookup[buf->port];
188 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
193 mrvl_fill_desc(struct pp2_ppio_desc *desc, struct rte_mbuf *buf)
195 pp2_ppio_outq_desc_reset(desc);
196 pp2_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf));
197 pp2_ppio_outq_desc_set_pkt_offset(desc, 0);
198 pp2_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf));
202 mrvl_get_bpool_size(int pp2_id, int pool_id)
207 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
208 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
214 mrvl_reserve_bit(int *bitmap, int max)
216 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
227 mrvl_init_hif(int core_id)
229 struct pp2_hif_params params;
230 char match[MRVL_MATCH_LEN];
233 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
235 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
239 snprintf(match, sizeof(match), "hif-%d", ret);
240 memset(¶ms, 0, sizeof(params));
241 params.match = match;
242 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
243 ret = pp2_hif_init(¶ms, &hifs[core_id]);
245 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id);
252 static inline struct pp2_hif*
253 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
257 if (likely(hifs[core_id] != NULL))
258 return hifs[core_id];
260 rte_spinlock_lock(&priv->lock);
262 ret = mrvl_init_hif(core_id);
264 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
268 if (core_id < mrvl_lcore_first)
269 mrvl_lcore_first = core_id;
271 if (core_id > mrvl_lcore_last)
272 mrvl_lcore_last = core_id;
274 rte_spinlock_unlock(&priv->lock);
276 return hifs[core_id];
280 * Set tx burst function according to offload flag
283 * Pointer to Ethernet device structure.
286 mrvl_set_tx_function(struct rte_eth_dev *dev)
288 struct mrvl_priv *priv = dev->data->dev_private;
290 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
291 if (priv->multiseg) {
292 RTE_LOG(INFO, PMD, "Using multi-segment tx callback\n");
293 dev->tx_pkt_burst = mrvl_tx_sg_pkt_burst;
295 RTE_LOG(INFO, PMD, "Using single-segment tx callback\n");
296 dev->tx_pkt_burst = mrvl_tx_pkt_burst;
301 * Configure rss based on dpdk rss configuration.
304 * Pointer to private structure.
306 * Pointer to RSS configuration.
309 * 0 on success, negative error value otherwise.
312 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
314 if (rss_conf->rss_key)
315 MRVL_LOG(WARNING, "Changing hash key is not supported");
317 if (rss_conf->rss_hf == 0) {
318 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
319 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
320 priv->ppio_params.inqs_params.hash_type =
321 PP2_PPIO_HASH_T_2_TUPLE;
322 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
323 priv->ppio_params.inqs_params.hash_type =
324 PP2_PPIO_HASH_T_5_TUPLE;
325 priv->rss_hf_tcp = 1;
326 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
327 priv->ppio_params.inqs_params.hash_type =
328 PP2_PPIO_HASH_T_5_TUPLE;
329 priv->rss_hf_tcp = 0;
338 * Ethernet device configuration.
340 * Prepare the driver for a given number of TX and RX queues and
344 * Pointer to Ethernet device structure.
347 * 0 on success, negative error value otherwise.
350 mrvl_dev_configure(struct rte_eth_dev *dev)
352 struct mrvl_priv *priv = dev->data->dev_private;
356 MRVL_LOG(INFO, "Device reconfiguration is not supported");
360 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
361 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
362 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d",
363 dev->data->dev_conf.rxmode.mq_mode);
367 if (dev->data->dev_conf.rxmode.split_hdr_size) {
368 MRVL_LOG(INFO, "Split headers not supported");
372 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
373 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
374 MRVL_PP2_ETH_HDRS_LEN;
376 if (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
379 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
380 dev->data->nb_rx_queues);
384 ret = mrvl_configure_txqs(priv, dev->data->port_id,
385 dev->data->nb_tx_queues);
389 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
390 priv->ppio_params.maintain_stats = 1;
391 priv->nb_rx_queues = dev->data->nb_rx_queues;
393 ret = mrvl_tm_init(dev);
397 if (dev->data->nb_rx_queues == 1 &&
398 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
399 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue");
400 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
405 return mrvl_configure_rss(priv,
406 &dev->data->dev_conf.rx_adv_conf.rss_conf);
410 * DPDK callback to change the MTU.
412 * Setting the MTU affects hardware MRU (packets larger than the MRU
416 * Pointer to Ethernet device structure.
421 * 0 on success, negative error value otherwise.
424 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
426 struct mrvl_priv *priv = dev->data->dev_private;
428 uint16_t mbuf_data_size = 0; /* SW buffer size */
431 mru = MRVL_PP2_MTU_TO_MRU(mtu);
433 * min_rx_buf_size is equal to mbuf data size
434 * if pmd didn't set it differently
436 mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
438 * - setting mru greater than the mbuf size resulting in
439 * hw and sw buffer size mismatch
440 * - setting mtu that requires the support of scattered packets
441 * when this feature has not been enabled/supported so far
442 * (TODO check scattered_rx flag here once scattered RX is supported).
444 if (mru + MRVL_PKT_OFFS > mbuf_data_size) {
445 mru = mbuf_data_size - MRVL_PKT_OFFS;
446 mtu = MRVL_PP2_MRU_TO_MTU(mru);
447 MRVL_LOG(WARNING, "MTU too big, max MTU possible limitted "
448 "by current mbuf size: %u. Set MTU to %u, MRU to %u",
449 mbuf_data_size, mtu, mru);
452 if (mtu < RTE_ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX) {
453 MRVL_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru);
457 dev->data->mtu = mtu;
458 dev->data->dev_conf.rxmode.max_rx_pkt_len = mru - MV_MH_SIZE;
463 ret = pp2_ppio_set_mru(priv->ppio, mru);
465 MRVL_LOG(ERR, "Failed to change MRU");
469 ret = pp2_ppio_set_mtu(priv->ppio, mtu);
471 MRVL_LOG(ERR, "Failed to change MTU");
479 * DPDK callback to bring the link up.
482 * Pointer to Ethernet device structure.
485 * 0 on success, negative error value otherwise.
488 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
490 struct mrvl_priv *priv = dev->data->dev_private;
496 ret = pp2_ppio_enable(priv->ppio);
501 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
502 * as pp2_ppio_enable() changes port->t_mode from default 0 to
503 * PP2_TRAFFIC_INGRESS_EGRESS.
505 * Set mtu to default DPDK value here.
507 ret = mrvl_mtu_set(dev, dev->data->mtu);
509 pp2_ppio_disable(priv->ppio);
515 * DPDK callback to bring the link down.
518 * Pointer to Ethernet device structure.
521 * 0 on success, negative error value otherwise.
524 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
526 struct mrvl_priv *priv = dev->data->dev_private;
531 return pp2_ppio_disable(priv->ppio);
535 * DPDK callback to start tx queue.
538 * Pointer to Ethernet device structure.
540 * Transmit queue index.
543 * 0 on success, negative error value otherwise.
546 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
548 struct mrvl_priv *priv = dev->data->dev_private;
554 /* passing 1 enables given tx queue */
555 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1);
557 MRVL_LOG(ERR, "Failed to start txq %d", queue_id);
561 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
567 * DPDK callback to stop tx queue.
570 * Pointer to Ethernet device structure.
572 * Transmit queue index.
575 * 0 on success, negative error value otherwise.
578 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
580 struct mrvl_priv *priv = dev->data->dev_private;
586 /* passing 0 disables given tx queue */
587 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0);
589 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id);
593 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
599 * DPDK callback to start the device.
602 * Pointer to Ethernet device structure.
605 * 0 on success, negative errno value on failure.
608 mrvl_dev_start(struct rte_eth_dev *dev)
610 struct mrvl_priv *priv = dev->data->dev_private;
611 char match[MRVL_MATCH_LEN];
612 int ret = 0, i, def_init_size;
615 return mrvl_dev_set_link_up(dev);
617 snprintf(match, sizeof(match), "ppio-%d:%d",
618 priv->pp_id, priv->ppio_id);
619 priv->ppio_params.match = match;
622 * Calculate the minimum bpool size for refill feature as follows:
623 * 2 default burst sizes multiply by number of rx queues.
624 * If the bpool size will be below this value, new buffers will
625 * be added to the pool.
627 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
629 /* In case initial bpool size configured in queues setup is
630 * smaller than minimum size add more buffers
632 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
633 if (priv->bpool_init_size < def_init_size) {
634 int buffs_to_add = def_init_size - priv->bpool_init_size;
636 priv->bpool_init_size += buffs_to_add;
637 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
639 MRVL_LOG(ERR, "Failed to add buffers to bpool");
643 * Calculate the maximum bpool size for refill feature as follows:
644 * maximum number of descriptors in rx queue multiply by number
645 * of rx queues plus minimum bpool size.
646 * In case the bpool size will exceed this value, superfluous buffers
649 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
650 priv->bpool_min_size;
652 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
654 MRVL_LOG(ERR, "Failed to init ppio");
659 * In case there are some some stale uc/mc mac addresses flush them
660 * here. It cannot be done during mrvl_dev_close() as port information
661 * is already gone at that point (due to pp2_ppio_deinit() in
664 if (!priv->uc_mc_flushed) {
665 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
668 "Failed to flush uc/mc filter list");
671 priv->uc_mc_flushed = 1;
674 if (!priv->vlan_flushed) {
675 ret = pp2_ppio_flush_vlan(priv->ppio);
677 MRVL_LOG(ERR, "Failed to flush vlan list");
680 * once pp2_ppio_flush_vlan() is supported jump to out
684 priv->vlan_flushed = 1;
686 ret = mrvl_mtu_set(dev, dev->data->mtu);
688 MRVL_LOG(ERR, "Failed to set MTU to %d", dev->data->mtu);
690 /* For default QoS config, don't start classifier. */
692 mrvl_qos_cfg->port[dev->data->port_id].use_global_defaults == 0) {
693 ret = mrvl_start_qos_mapping(priv);
695 MRVL_LOG(ERR, "Failed to setup QoS mapping");
700 ret = mrvl_dev_set_link_up(dev);
702 MRVL_LOG(ERR, "Failed to set link up");
706 /* start tx queues */
707 for (i = 0; i < dev->data->nb_tx_queues; i++) {
708 struct mrvl_txq *txq = dev->data->tx_queues[i];
710 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
712 if (!txq->tx_deferred_start)
716 * All txqs are started by default. Stop them
717 * so that tx_deferred_start works as expected.
719 ret = mrvl_tx_queue_stop(dev, i);
726 mrvl_set_tx_function(dev);
730 MRVL_LOG(ERR, "Failed to start device");
731 pp2_ppio_deinit(priv->ppio);
736 * Flush receive queues.
739 * Pointer to Ethernet device structure.
742 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
746 MRVL_LOG(INFO, "Flushing rx queues");
747 for (i = 0; i < dev->data->nb_rx_queues; i++) {
751 struct mrvl_rxq *q = dev->data->rx_queues[i];
752 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
754 num = MRVL_PP2_RXD_MAX;
755 ret = pp2_ppio_recv(q->priv->ppio,
756 q->priv->rxq_map[q->queue_id].tc,
757 q->priv->rxq_map[q->queue_id].inq,
758 descs, (uint16_t *)&num);
759 } while (ret == 0 && num);
764 * Flush transmit shadow queues.
767 * Pointer to Ethernet device structure.
770 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
773 struct mrvl_txq *txq;
775 MRVL_LOG(INFO, "Flushing tx shadow queues");
776 for (i = 0; i < dev->data->nb_tx_queues; i++) {
777 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
779 for (j = 0; j < RTE_MAX_LCORE; j++) {
780 struct mrvl_shadow_txq *sq;
785 sq = &txq->shadow_txqs[j];
786 mrvl_free_sent_buffers(txq->priv->ppio,
787 hifs[j], j, sq, txq->queue_id, 1);
788 while (sq->tail != sq->head) {
789 uint64_t addr = cookie_addr_high |
790 sq->ent[sq->tail].buff.cookie;
792 (struct rte_mbuf *)addr);
793 sq->tail = (sq->tail + 1) &
794 MRVL_PP2_TX_SHADOWQ_MASK;
796 memset(sq, 0, sizeof(*sq));
802 * Flush hardware bpool (buffer-pool).
805 * Pointer to Ethernet device structure.
808 mrvl_flush_bpool(struct rte_eth_dev *dev)
810 struct mrvl_priv *priv = dev->data->dev_private;
814 unsigned int core_id = rte_lcore_id();
816 if (core_id == LCORE_ID_ANY)
817 core_id = rte_get_main_lcore();
819 hif = mrvl_get_hif(priv, core_id);
821 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
823 MRVL_LOG(ERR, "Failed to get bpool buffers number");
828 struct pp2_buff_inf inf;
831 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
835 addr = cookie_addr_high | inf.cookie;
836 rte_pktmbuf_free((struct rte_mbuf *)addr);
841 * DPDK callback to stop the device.
844 * Pointer to Ethernet device structure.
847 mrvl_dev_stop(struct rte_eth_dev *dev)
849 return mrvl_dev_set_link_down(dev);
853 * DPDK callback to close the device.
856 * Pointer to Ethernet device structure.
859 mrvl_dev_close(struct rte_eth_dev *dev)
861 struct mrvl_priv *priv = dev->data->dev_private;
864 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
867 mrvl_flush_rx_queues(dev);
868 mrvl_flush_tx_shadow_queues(dev);
869 mrvl_flow_deinit(dev);
870 mrvl_mtr_deinit(dev);
872 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
873 struct pp2_ppio_tc_params *tc_params =
874 &priv->ppio_params.inqs_params.tcs_params[i];
876 if (tc_params->inqs_params) {
877 rte_free(tc_params->inqs_params);
878 tc_params->inqs_params = NULL;
883 pp2_cls_tbl_deinit(priv->cls_tbl);
884 priv->cls_tbl = NULL;
888 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
889 priv->qos_tbl = NULL;
892 mrvl_flush_bpool(dev);
896 pp2_ppio_deinit(priv->ppio);
900 /* policer must be released after ppio deinitialization */
901 if (priv->default_policer) {
902 pp2_cls_plcr_deinit(priv->default_policer);
903 priv->default_policer = NULL;
908 pp2_bpool_deinit(priv->bpool);
909 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
915 if (mrvl_dev_num == 0) {
916 MRVL_LOG(INFO, "Perform MUSDK deinit");
919 rte_mvep_deinit(MVEP_MOD_T_PP2);
926 * DPDK callback to retrieve physical link information.
929 * Pointer to Ethernet device structure.
930 * @param wait_to_complete
931 * Wait for request completion (ignored).
934 * 0 on success, negative error value otherwise.
937 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
941 * once MUSDK provides necessary API use it here
943 struct mrvl_priv *priv = dev->data->dev_private;
944 struct ethtool_cmd edata;
946 int ret, fd, link_up;
951 edata.cmd = ETHTOOL_GSET;
953 strcpy(req.ifr_name, dev->data->name);
954 req.ifr_data = (void *)&edata;
956 fd = socket(AF_INET, SOCK_DGRAM, 0);
960 ret = ioctl(fd, SIOCETHTOOL, &req);
968 switch (ethtool_cmd_speed(&edata)) {
970 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
973 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
976 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
979 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
982 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
985 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
986 ETH_LINK_HALF_DUPLEX;
987 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
989 pp2_ppio_get_link_state(priv->ppio, &link_up);
990 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
996 * DPDK callback to enable promiscuous mode.
999 * Pointer to Ethernet device structure.
1002 * 0 on success, negative error value otherwise.
1005 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
1007 struct mrvl_priv *priv = dev->data->dev_private;
1016 ret = pp2_ppio_set_promisc(priv->ppio, 1);
1018 MRVL_LOG(ERR, "Failed to enable promiscuous mode");
1026 * DPDK callback to enable allmulti mode.
1029 * Pointer to Ethernet device structure.
1032 * 0 on success, negative error value otherwise.
1035 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
1037 struct mrvl_priv *priv = dev->data->dev_private;
1046 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
1048 MRVL_LOG(ERR, "Failed enable all-multicast mode");
1056 * DPDK callback to disable promiscuous mode.
1059 * Pointer to Ethernet device structure.
1062 * 0 on success, negative error value otherwise.
1065 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
1067 struct mrvl_priv *priv = dev->data->dev_private;
1073 ret = pp2_ppio_set_promisc(priv->ppio, 0);
1075 MRVL_LOG(ERR, "Failed to disable promiscuous mode");
1083 * DPDK callback to disable allmulticast mode.
1086 * Pointer to Ethernet device structure.
1089 * 0 on success, negative error value otherwise.
1092 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
1094 struct mrvl_priv *priv = dev->data->dev_private;
1100 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
1102 MRVL_LOG(ERR, "Failed to disable all-multicast mode");
1110 * DPDK callback to remove a MAC address.
1113 * Pointer to Ethernet device structure.
1115 * MAC address index.
1118 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1120 struct mrvl_priv *priv = dev->data->dev_private;
1121 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1130 ret = pp2_ppio_remove_mac_addr(priv->ppio,
1131 dev->data->mac_addrs[index].addr_bytes);
1133 rte_ether_format_addr(buf, sizeof(buf),
1134 &dev->data->mac_addrs[index]);
1135 MRVL_LOG(ERR, "Failed to remove mac %s", buf);
1140 * DPDK callback to add a MAC address.
1143 * Pointer to Ethernet device structure.
1145 * MAC address to register.
1147 * MAC address index.
1149 * VMDq pool index to associate address with (unused).
1152 * 0 on success, negative error value otherwise.
1155 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1156 uint32_t index, uint32_t vmdq __rte_unused)
1158 struct mrvl_priv *priv = dev->data->dev_private;
1159 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1166 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
1173 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
1174 * parameter uc_filter_max. Maximum number of mc addresses is then
1175 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
1178 * If more than uc_filter_max uc addresses were added to filter list
1179 * then NIC will switch to promiscuous mode automatically.
1181 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
1182 * were added to filter list then NIC will switch to all-multicast mode
1185 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
1187 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1188 MRVL_LOG(ERR, "Failed to add mac %s", buf);
1196 * DPDK callback to set the primary MAC address.
1199 * Pointer to Ethernet device structure.
1201 * MAC address to register.
1204 * 0 on success, negative error value otherwise.
1207 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1209 struct mrvl_priv *priv = dev->data->dev_private;
1218 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
1220 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1221 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1222 MRVL_LOG(ERR, "Failed to set mac to %s", buf);
1229 * DPDK callback to get device statistics.
1232 * Pointer to Ethernet device structure.
1234 * Stats structure output buffer.
1237 * 0 on success, negative error value otherwise.
1240 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1242 struct mrvl_priv *priv = dev->data->dev_private;
1243 struct pp2_ppio_statistics ppio_stats;
1244 uint64_t drop_mac = 0;
1245 unsigned int i, idx, ret;
1250 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1251 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1252 struct pp2_ppio_inq_statistics rx_stats;
1257 idx = rxq->queue_id;
1258 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1260 "rx queue %d stats out of range (0 - %d)",
1261 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1265 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1266 priv->rxq_map[idx].tc,
1267 priv->rxq_map[idx].inq,
1269 if (unlikely(ret)) {
1271 "Failed to update rx queue %d stats", idx);
1275 stats->q_ibytes[idx] = rxq->bytes_recv;
1276 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1277 stats->q_errors[idx] = rx_stats.drop_early +
1278 rx_stats.drop_fullq +
1281 stats->ibytes += rxq->bytes_recv;
1282 drop_mac += rxq->drop_mac;
1285 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1286 struct mrvl_txq *txq = dev->data->tx_queues[i];
1287 struct pp2_ppio_outq_statistics tx_stats;
1292 idx = txq->queue_id;
1293 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1295 "tx queue %d stats out of range (0 - %d)",
1296 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1299 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1301 if (unlikely(ret)) {
1303 "Failed to update tx queue %d stats", idx);
1307 stats->q_opackets[idx] = tx_stats.deq_desc;
1308 stats->q_obytes[idx] = txq->bytes_sent;
1309 stats->obytes += txq->bytes_sent;
1312 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1313 if (unlikely(ret)) {
1314 MRVL_LOG(ERR, "Failed to update port statistics");
1318 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1319 stats->opackets += ppio_stats.tx_packets;
1320 stats->imissed += ppio_stats.rx_fullq_dropped +
1321 ppio_stats.rx_bm_dropped +
1322 ppio_stats.rx_early_dropped +
1323 ppio_stats.rx_fifo_dropped +
1324 ppio_stats.rx_cls_dropped;
1325 stats->ierrors = drop_mac;
1331 * DPDK callback to clear device statistics.
1334 * Pointer to Ethernet device structure.
1337 * 0 on success, negative error value otherwise.
1340 mrvl_stats_reset(struct rte_eth_dev *dev)
1342 struct mrvl_priv *priv = dev->data->dev_private;
1348 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1349 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1351 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1352 priv->rxq_map[i].inq, NULL, 1);
1353 rxq->bytes_recv = 0;
1357 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1358 struct mrvl_txq *txq = dev->data->tx_queues[i];
1360 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1361 txq->bytes_sent = 0;
1364 return pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1368 * DPDK callback to get extended statistics.
1371 * Pointer to Ethernet device structure.
1373 * Pointer to xstats table.
1375 * Number of entries in xstats table.
1377 * Negative value on error, number of read xstats otherwise.
1380 mrvl_xstats_get(struct rte_eth_dev *dev,
1381 struct rte_eth_xstat *stats, unsigned int n)
1383 struct mrvl_priv *priv = dev->data->dev_private;
1384 struct pp2_ppio_statistics ppio_stats;
1390 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1391 for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
1394 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
1395 val = *(uint32_t *)((uint8_t *)&ppio_stats +
1396 mrvl_xstats_tbl[i].offset);
1397 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t))
1398 val = *(uint64_t *)((uint8_t *)&ppio_stats +
1399 mrvl_xstats_tbl[i].offset);
1404 stats[i].value = val;
1411 * DPDK callback to reset extended statistics.
1414 * Pointer to Ethernet device structure.
1417 * 0 on success, negative error value otherwise.
1420 mrvl_xstats_reset(struct rte_eth_dev *dev)
1422 return mrvl_stats_reset(dev);
1426 * DPDK callback to get extended statistics names.
1428 * @param dev (unused)
1429 * Pointer to Ethernet device structure.
1430 * @param xstats_names
1431 * Pointer to xstats names table.
1433 * Size of the xstats names table.
1435 * Number of read names.
1438 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1439 struct rte_eth_xstat_name *xstats_names,
1445 return RTE_DIM(mrvl_xstats_tbl);
1447 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
1448 strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name,
1449 RTE_ETH_XSTATS_NAME_SIZE);
1455 * DPDK callback to get information about the device.
1458 * Pointer to Ethernet device structure (unused).
1460 * Info structure output buffer.
1463 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1464 struct rte_eth_dev_info *info)
1466 info->speed_capa = ETH_LINK_SPEED_10M |
1467 ETH_LINK_SPEED_100M |
1471 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1472 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1473 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1475 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1476 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1477 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1479 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1480 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1481 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1483 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1484 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1486 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1487 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1489 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1490 ETH_RSS_NONFRAG_IPV4_TCP |
1491 ETH_RSS_NONFRAG_IPV4_UDP;
1493 /* By default packets are dropped if no descriptors are available */
1494 info->default_rxconf.rx_drop_en = 1;
1496 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1502 * Return supported packet types.
1505 * Pointer to Ethernet device structure (unused).
1508 * Const pointer to the table with supported packet types.
1510 static const uint32_t *
1511 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1513 static const uint32_t ptypes[] = {
1515 RTE_PTYPE_L2_ETHER_VLAN,
1516 RTE_PTYPE_L2_ETHER_QINQ,
1518 RTE_PTYPE_L3_IPV4_EXT,
1519 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1521 RTE_PTYPE_L3_IPV6_EXT,
1522 RTE_PTYPE_L2_ETHER_ARP,
1531 * DPDK callback to get information about specific receive queue.
1534 * Pointer to Ethernet device structure.
1535 * @param rx_queue_id
1536 * Receive queue index.
1538 * Receive queue information structure.
1540 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1541 struct rte_eth_rxq_info *qinfo)
1543 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1544 struct mrvl_priv *priv = dev->data->dev_private;
1545 int inq = priv->rxq_map[rx_queue_id].inq;
1546 int tc = priv->rxq_map[rx_queue_id].tc;
1547 struct pp2_ppio_tc_params *tc_params =
1548 &priv->ppio_params.inqs_params.tcs_params[tc];
1551 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1555 * DPDK callback to get information about specific transmit queue.
1558 * Pointer to Ethernet device structure.
1559 * @param tx_queue_id
1560 * Transmit queue index.
1562 * Transmit queue information structure.
1564 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1565 struct rte_eth_txq_info *qinfo)
1567 struct mrvl_priv *priv = dev->data->dev_private;
1568 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id];
1571 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1572 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1576 * DPDK callback to Configure a VLAN filter.
1579 * Pointer to Ethernet device structure.
1581 * VLAN ID to filter.
1586 * 0 on success, negative error value otherwise.
1589 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1591 struct mrvl_priv *priv = dev->data->dev_private;
1599 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1600 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1604 * Release buffers to hardware bpool (buffer-pool)
1607 * Receive queue pointer.
1609 * Number of buffers to release to bpool.
1612 * 0 on success, negative error value otherwise.
1615 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1617 struct buff_release_entry entries[num];
1618 struct rte_mbuf *mbufs[num];
1620 unsigned int core_id;
1621 struct pp2_hif *hif;
1622 struct pp2_bpool *bpool;
1624 core_id = rte_lcore_id();
1625 if (core_id == LCORE_ID_ANY)
1626 core_id = rte_get_main_lcore();
1628 hif = mrvl_get_hif(rxq->priv, core_id);
1632 bpool = rxq->priv->bpool;
1634 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1638 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1640 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1642 for (i = 0; i < num; i++) {
1643 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1644 != cookie_addr_high) {
1646 "mbuf virtual addr high 0x%lx out of range",
1647 (uint64_t)mbufs[i] >> 32);
1651 entries[i].buff.addr =
1652 rte_mbuf_data_iova_default(mbufs[i]);
1653 entries[i].buff.cookie = (uint64_t)mbufs[i];
1654 entries[i].bpool = bpool;
1657 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1658 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1665 for (; i < num; i++)
1666 rte_pktmbuf_free(mbufs[i]);
1672 * DPDK callback to configure the receive queue.
1675 * Pointer to Ethernet device structure.
1679 * Number of descriptors to configure in queue.
1681 * NUMA socket on which memory must be allocated.
1683 * Thresholds parameters.
1685 * Memory pool for buffer allocations.
1688 * 0 on success, negative error value otherwise.
1691 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1692 unsigned int socket,
1693 const struct rte_eth_rxconf *conf,
1694 struct rte_mempool *mp)
1696 struct mrvl_priv *priv = dev->data->dev_private;
1697 struct mrvl_rxq *rxq;
1698 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
1699 uint32_t max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1703 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1705 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1707 * Unknown TC mapping, mapping will not have a correct queue.
1709 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu",
1710 idx, priv->ppio_id);
1714 frame_size = buf_size - RTE_PKTMBUF_HEADROOM - MRVL_PKT_EFFEC_OFFS;
1715 if (frame_size < max_rx_pkt_len) {
1717 "Mbuf size must be increased to %u bytes to hold up "
1718 "to %u bytes of data.",
1719 buf_size + max_rx_pkt_len - frame_size,
1721 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1722 MRVL_LOG(INFO, "Setting max rx pkt len to %u",
1723 dev->data->dev_conf.rxmode.max_rx_pkt_len);
1726 if (dev->data->rx_queues[idx]) {
1727 rte_free(dev->data->rx_queues[idx]);
1728 dev->data->rx_queues[idx] = NULL;
1731 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1737 rxq->cksum_enabled = offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
1738 rxq->queue_id = idx;
1739 rxq->port_id = dev->data->port_id;
1740 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1742 tc = priv->rxq_map[rxq->queue_id].tc,
1743 inq = priv->rxq_map[rxq->queue_id].inq;
1744 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1747 ret = mrvl_fill_bpool(rxq, desc);
1753 priv->bpool_init_size += desc;
1755 dev->data->rx_queues[idx] = rxq;
1761 * DPDK callback to release the receive queue.
1764 * Generic receive queue pointer.
1767 mrvl_rx_queue_release(void *rxq)
1769 struct mrvl_rxq *q = rxq;
1770 struct pp2_ppio_tc_params *tc_params;
1771 int i, num, tc, inq;
1772 struct pp2_hif *hif;
1773 unsigned int core_id = rte_lcore_id();
1775 if (core_id == LCORE_ID_ANY)
1776 core_id = rte_get_main_lcore();
1781 hif = mrvl_get_hif(q->priv, core_id);
1786 tc = q->priv->rxq_map[q->queue_id].tc;
1787 inq = q->priv->rxq_map[q->queue_id].inq;
1788 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1789 num = tc_params->inqs_params[inq].size;
1790 for (i = 0; i < num; i++) {
1791 struct pp2_buff_inf inf;
1794 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1795 addr = cookie_addr_high | inf.cookie;
1796 rte_pktmbuf_free((struct rte_mbuf *)addr);
1803 * DPDK callback to configure the transmit queue.
1806 * Pointer to Ethernet device structure.
1808 * Transmit queue index.
1810 * Number of descriptors to configure in the queue.
1812 * NUMA socket on which memory must be allocated.
1814 * Tx queue configuration parameters.
1817 * 0 on success, negative error value otherwise.
1820 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1821 unsigned int socket,
1822 const struct rte_eth_txconf *conf)
1824 struct mrvl_priv *priv = dev->data->dev_private;
1825 struct mrvl_txq *txq;
1827 if (dev->data->tx_queues[idx]) {
1828 rte_free(dev->data->tx_queues[idx]);
1829 dev->data->tx_queues[idx] = NULL;
1832 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1837 txq->queue_id = idx;
1838 txq->port_id = dev->data->port_id;
1839 txq->tx_deferred_start = conf->tx_deferred_start;
1840 dev->data->tx_queues[idx] = txq;
1842 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1848 * DPDK callback to release the transmit queue.
1851 * Generic transmit queue pointer.
1854 mrvl_tx_queue_release(void *txq)
1856 struct mrvl_txq *q = txq;
1865 * DPDK callback to get flow control configuration.
1868 * Pointer to Ethernet device structure.
1870 * Pointer to the flow control configuration.
1873 * 0 on success, negative error value otherwise.
1876 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1878 struct mrvl_priv *priv = dev->data->dev_private;
1884 ret = pp2_ppio_get_rx_pause(priv->ppio, &en);
1886 MRVL_LOG(ERR, "Failed to read rx pause state");
1890 fc_conf->mode = en ? RTE_FC_RX_PAUSE : RTE_FC_NONE;
1896 * DPDK callback to set flow control configuration.
1899 * Pointer to Ethernet device structure.
1901 * Pointer to the flow control configuration.
1904 * 0 on success, negative error value otherwise.
1907 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1909 struct mrvl_priv *priv = dev->data->dev_private;
1914 if (fc_conf->high_water ||
1915 fc_conf->low_water ||
1916 fc_conf->pause_time ||
1917 fc_conf->mac_ctrl_frame_fwd ||
1919 MRVL_LOG(ERR, "Flowctrl parameter is not supported");
1924 if (fc_conf->mode == RTE_FC_NONE ||
1925 fc_conf->mode == RTE_FC_RX_PAUSE) {
1928 en = fc_conf->mode == RTE_FC_NONE ? 0 : 1;
1929 ret = pp2_ppio_set_rx_pause(priv->ppio, en);
1932 "Failed to change flowctrl on RX side");
1941 * Update RSS hash configuration
1944 * Pointer to Ethernet device structure.
1946 * Pointer to RSS configuration.
1949 * 0 on success, negative error value otherwise.
1952 mrvl_rss_hash_update(struct rte_eth_dev *dev,
1953 struct rte_eth_rss_conf *rss_conf)
1955 struct mrvl_priv *priv = dev->data->dev_private;
1960 return mrvl_configure_rss(priv, rss_conf);
1964 * DPDK callback to get RSS hash configuration.
1967 * Pointer to Ethernet device structure.
1969 * Pointer to RSS configuration.
1975 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
1976 struct rte_eth_rss_conf *rss_conf)
1978 struct mrvl_priv *priv = dev->data->dev_private;
1979 enum pp2_ppio_hash_type hash_type =
1980 priv->ppio_params.inqs_params.hash_type;
1982 rss_conf->rss_key = NULL;
1984 if (hash_type == PP2_PPIO_HASH_T_NONE)
1985 rss_conf->rss_hf = 0;
1986 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
1987 rss_conf->rss_hf = ETH_RSS_IPV4;
1988 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
1989 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
1990 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
1991 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
1997 * DPDK callback to get rte_flow callbacks.
2000 * Pointer to the device structure.
2004 * Flow filter operation.
2006 * Pointer to pass the flow ops.
2009 * 0 on success, negative error value otherwise.
2012 mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
2013 enum rte_filter_type filter_type,
2014 enum rte_filter_op filter_op, void *arg)
2016 switch (filter_type) {
2017 case RTE_ETH_FILTER_GENERIC:
2018 if (filter_op != RTE_ETH_FILTER_GET)
2020 *(const void **)arg = &mrvl_flow_ops;
2023 MRVL_LOG(WARNING, "Filter type (%d) not supported",
2030 * DPDK callback to get rte_mtr callbacks.
2033 * Pointer to the device structure.
2035 * Pointer to pass the mtr ops.
2041 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2043 *(const void **)ops = &mrvl_mtr_ops;
2049 * DPDK callback to get rte_tm callbacks.
2052 * Pointer to the device structure.
2054 * Pointer to pass the tm ops.
2060 mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2062 *(const void **)ops = &mrvl_tm_ops;
2067 static const struct eth_dev_ops mrvl_ops = {
2068 .dev_configure = mrvl_dev_configure,
2069 .dev_start = mrvl_dev_start,
2070 .dev_stop = mrvl_dev_stop,
2071 .dev_set_link_up = mrvl_dev_set_link_up,
2072 .dev_set_link_down = mrvl_dev_set_link_down,
2073 .dev_close = mrvl_dev_close,
2074 .link_update = mrvl_link_update,
2075 .promiscuous_enable = mrvl_promiscuous_enable,
2076 .allmulticast_enable = mrvl_allmulticast_enable,
2077 .promiscuous_disable = mrvl_promiscuous_disable,
2078 .allmulticast_disable = mrvl_allmulticast_disable,
2079 .mac_addr_remove = mrvl_mac_addr_remove,
2080 .mac_addr_add = mrvl_mac_addr_add,
2081 .mac_addr_set = mrvl_mac_addr_set,
2082 .mtu_set = mrvl_mtu_set,
2083 .stats_get = mrvl_stats_get,
2084 .stats_reset = mrvl_stats_reset,
2085 .xstats_get = mrvl_xstats_get,
2086 .xstats_reset = mrvl_xstats_reset,
2087 .xstats_get_names = mrvl_xstats_get_names,
2088 .dev_infos_get = mrvl_dev_infos_get,
2089 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
2090 .rxq_info_get = mrvl_rxq_info_get,
2091 .txq_info_get = mrvl_txq_info_get,
2092 .vlan_filter_set = mrvl_vlan_filter_set,
2093 .tx_queue_start = mrvl_tx_queue_start,
2094 .tx_queue_stop = mrvl_tx_queue_stop,
2095 .rx_queue_setup = mrvl_rx_queue_setup,
2096 .rx_queue_release = mrvl_rx_queue_release,
2097 .tx_queue_setup = mrvl_tx_queue_setup,
2098 .tx_queue_release = mrvl_tx_queue_release,
2099 .flow_ctrl_get = mrvl_flow_ctrl_get,
2100 .flow_ctrl_set = mrvl_flow_ctrl_set,
2101 .rss_hash_update = mrvl_rss_hash_update,
2102 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
2103 .filter_ctrl = mrvl_eth_filter_ctrl,
2104 .mtr_ops_get = mrvl_mtr_ops_get,
2105 .tm_ops_get = mrvl_tm_ops_get,
2109 * Return packet type information and l3/l4 offsets.
2112 * Pointer to the received packet descriptor.
2119 * Packet type information.
2121 static inline uint64_t
2122 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
2123 uint8_t *l3_offset, uint8_t *l4_offset)
2125 enum pp2_inq_l3_type l3_type;
2126 enum pp2_inq_l4_type l4_type;
2127 enum pp2_inq_vlan_tag vlan_tag;
2128 uint64_t packet_type;
2130 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
2131 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
2132 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag);
2134 packet_type = RTE_PTYPE_L2_ETHER;
2137 case PP2_INQ_VLAN_TAG_SINGLE:
2138 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
2140 case PP2_INQ_VLAN_TAG_DOUBLE:
2141 case PP2_INQ_VLAN_TAG_TRIPLE:
2142 packet_type |= RTE_PTYPE_L2_ETHER_QINQ;
2149 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
2150 packet_type |= RTE_PTYPE_L3_IPV4;
2152 case PP2_INQ_L3_TYPE_IPV4_OK:
2153 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
2155 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
2156 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
2158 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
2159 packet_type |= RTE_PTYPE_L3_IPV6;
2161 case PP2_INQ_L3_TYPE_IPV6_EXT:
2162 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
2164 case PP2_INQ_L3_TYPE_ARP:
2165 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
2167 * In case of ARP l4_offset is set to wrong value.
2168 * Set it to proper one so that later on mbuf->l3_len can be
2169 * calculated subtracting l4_offset and l3_offset.
2171 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
2174 MRVL_LOG(DEBUG, "Failed to recognise l3 packet type");
2179 case PP2_INQ_L4_TYPE_TCP:
2180 packet_type |= RTE_PTYPE_L4_TCP;
2182 case PP2_INQ_L4_TYPE_UDP:
2183 packet_type |= RTE_PTYPE_L4_UDP;
2186 MRVL_LOG(DEBUG, "Failed to recognise l4 packet type");
2194 * Get offload information from the received packet descriptor.
2197 * Pointer to the received packet descriptor.
2200 * Mbuf offload flags.
2202 static inline uint64_t
2203 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
2206 enum pp2_inq_desc_status status;
2208 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
2209 if (unlikely(status != PP2_DESC_ERR_OK))
2210 flags = PKT_RX_IP_CKSUM_BAD;
2212 flags = PKT_RX_IP_CKSUM_GOOD;
2214 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
2215 if (unlikely(status != PP2_DESC_ERR_OK))
2216 flags |= PKT_RX_L4_CKSUM_BAD;
2218 flags |= PKT_RX_L4_CKSUM_GOOD;
2224 * DPDK callback for receive.
2227 * Generic pointer to the receive queue.
2229 * Array to store received packets.
2231 * Maximum number of packets in array.
2234 * Number of packets successfully received.
2237 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2239 struct mrvl_rxq *q = rxq;
2240 struct pp2_ppio_desc descs[nb_pkts];
2241 struct pp2_bpool *bpool;
2242 int i, ret, rx_done = 0;
2244 struct pp2_hif *hif;
2245 unsigned int core_id = rte_lcore_id();
2247 hif = mrvl_get_hif(q->priv, core_id);
2249 if (unlikely(!q->priv->ppio || !hif))
2252 bpool = q->priv->bpool;
2254 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
2255 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
2256 if (unlikely(ret < 0)) {
2257 MRVL_LOG(ERR, "Failed to receive packets");
2260 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
2262 for (i = 0; i < nb_pkts; i++) {
2263 struct rte_mbuf *mbuf;
2264 uint8_t l3_offset, l4_offset;
2265 enum pp2_inq_desc_status status;
2268 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2269 struct pp2_ppio_desc *pref_desc;
2272 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
2273 pref_addr = cookie_addr_high |
2274 pp2_ppio_inq_desc_get_cookie(pref_desc);
2275 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
2276 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
2279 addr = cookie_addr_high |
2280 pp2_ppio_inq_desc_get_cookie(&descs[i]);
2281 mbuf = (struct rte_mbuf *)addr;
2282 rte_pktmbuf_reset(mbuf);
2284 /* drop packet in case of mac, overrun or resource error */
2285 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
2286 if (unlikely(status != PP2_DESC_ERR_OK)) {
2287 struct pp2_buff_inf binf = {
2288 .addr = rte_mbuf_data_iova_default(mbuf),
2289 .cookie = (uint64_t)mbuf,
2292 pp2_bpool_put_buff(hif, bpool, &binf);
2293 mrvl_port_bpool_size
2294 [bpool->pp2_id][bpool->id][core_id]++;
2299 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
2300 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
2301 mbuf->data_len = mbuf->pkt_len;
2302 mbuf->port = q->port_id;
2304 mrvl_desc_to_packet_type_and_offset(&descs[i],
2307 mbuf->l2_len = l3_offset;
2308 mbuf->l3_len = l4_offset - l3_offset;
2310 if (likely(q->cksum_enabled))
2311 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
2313 rx_pkts[rx_done++] = mbuf;
2314 q->bytes_recv += mbuf->pkt_len;
2317 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
2318 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
2320 if (unlikely(num <= q->priv->bpool_min_size ||
2321 (!rx_done && num < q->priv->bpool_init_size))) {
2322 ret = mrvl_fill_bpool(q, MRVL_BURST_SIZE);
2324 MRVL_LOG(ERR, "Failed to fill bpool");
2325 } else if (unlikely(num > q->priv->bpool_max_size)) {
2327 int pkt_to_remove = num - q->priv->bpool_init_size;
2328 struct rte_mbuf *mbuf;
2329 struct pp2_buff_inf buff;
2332 "port-%d:%d: bpool %d oversize - remove %d buffers (pool size: %d -> %d)",
2333 bpool->pp2_id, q->priv->ppio->port_id,
2334 bpool->id, pkt_to_remove, num,
2335 q->priv->bpool_init_size);
2337 for (i = 0; i < pkt_to_remove; i++) {
2338 ret = pp2_bpool_get_buff(hif, bpool, &buff);
2341 mbuf = (struct rte_mbuf *)
2342 (cookie_addr_high | buff.cookie);
2343 rte_pktmbuf_free(mbuf);
2345 mrvl_port_bpool_size
2346 [bpool->pp2_id][bpool->id][core_id] -= i;
2348 rte_spinlock_unlock(&q->priv->lock);
2355 * Prepare offload information.
2359 * @param packet_type
2360 * Packet type bitfield.
2362 * Pointer to the pp2_ouq_l3_type structure.
2364 * Pointer to the pp2_outq_l4_type structure.
2365 * @param gen_l3_cksum
2366 * Will be set to 1 in case l3 checksum is computed.
2368 * Will be set to 1 in case l4 checksum is computed.
2371 * 0 on success, negative error value otherwise.
2374 mrvl_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
2375 enum pp2_outq_l3_type *l3_type,
2376 enum pp2_outq_l4_type *l4_type,
2381 * Based on ol_flags prepare information
2382 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
2385 if (ol_flags & PKT_TX_IPV4) {
2386 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
2387 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
2388 } else if (ol_flags & PKT_TX_IPV6) {
2389 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
2390 /* no checksum for ipv6 header */
2393 /* if something different then stop processing */
2397 ol_flags &= PKT_TX_L4_MASK;
2398 if ((packet_type & RTE_PTYPE_L4_TCP) &&
2399 ol_flags == PKT_TX_TCP_CKSUM) {
2400 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
2402 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
2403 ol_flags == PKT_TX_UDP_CKSUM) {
2404 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
2407 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
2408 /* no checksum for other type */
2416 * Release already sent buffers to bpool (buffer-pool).
2419 * Pointer to the port structure.
2421 * Pointer to the MUSDK hardware interface.
2423 * Pointer to the shadow queue.
2427 * Force releasing packets.
2430 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2431 unsigned int core_id, struct mrvl_shadow_txq *sq,
2434 struct buff_release_entry *entry;
2435 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2438 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2440 sq->num_to_release += nb_done;
2442 if (likely(!force &&
2443 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2446 nb_done = sq->num_to_release;
2447 sq->num_to_release = 0;
2449 for (i = 0; i < nb_done; i++) {
2450 entry = &sq->ent[sq->tail + num];
2451 if (unlikely(!entry->buff.addr)) {
2453 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
2454 sq->tail, (u64)entry->buff.cookie,
2455 (u64)entry->buff.addr);
2460 if (unlikely(!entry->bpool)) {
2461 struct rte_mbuf *mbuf;
2463 mbuf = (struct rte_mbuf *)
2464 (cookie_addr_high | entry->buff.cookie);
2465 rte_pktmbuf_free(mbuf);
2470 mrvl_port_bpool_size
2471 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2473 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2478 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2480 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2487 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2488 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2494 * DPDK callback for transmit.
2497 * Generic pointer transmit queue.
2499 * Packets to transmit.
2501 * Number of packets in array.
2504 * Number of packets successfully transmitted.
2507 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2509 struct mrvl_txq *q = txq;
2510 struct mrvl_shadow_txq *sq;
2511 struct pp2_hif *hif;
2512 struct pp2_ppio_desc descs[nb_pkts];
2513 unsigned int core_id = rte_lcore_id();
2514 int i, ret, bytes_sent = 0;
2515 uint16_t num, sq_free_size;
2518 hif = mrvl_get_hif(q->priv, core_id);
2519 sq = &q->shadow_txqs[core_id];
2521 if (unlikely(!q->priv->ppio || !hif))
2525 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2526 sq, q->queue_id, 0);
2528 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2529 if (unlikely(nb_pkts > sq_free_size)) {
2531 "No room in shadow queue for %d packets! %d packets will be sent.",
2532 nb_pkts, sq_free_size);
2533 nb_pkts = sq_free_size;
2536 for (i = 0; i < nb_pkts; i++) {
2537 struct rte_mbuf *mbuf = tx_pkts[i];
2538 int gen_l3_cksum, gen_l4_cksum;
2539 enum pp2_outq_l3_type l3_type;
2540 enum pp2_outq_l4_type l4_type;
2542 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2543 struct rte_mbuf *pref_pkt_hdr;
2545 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2546 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2547 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2550 mrvl_fill_shadowq(sq, mbuf);
2551 mrvl_fill_desc(&descs[i], mbuf);
2553 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2555 * in case unsupported ol_flags were passed
2556 * do not update descriptor offload information
2558 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2559 &l3_type, &l4_type, &gen_l3_cksum,
2564 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2566 mbuf->l2_len + mbuf->l3_len,
2567 gen_l3_cksum, gen_l4_cksum);
2571 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2572 /* number of packets that were not sent */
2573 if (unlikely(num > nb_pkts)) {
2574 for (i = nb_pkts; i < num; i++) {
2575 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2576 MRVL_PP2_TX_SHADOWQ_MASK;
2577 addr = cookie_addr_high | sq->ent[sq->head].buff.cookie;
2579 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2581 sq->size -= num - nb_pkts;
2584 q->bytes_sent += bytes_sent;
2589 /** DPDK callback for S/G transmit.
2592 * Generic pointer transmit queue.
2594 * Packets to transmit.
2596 * Number of packets in array.
2599 * Number of packets successfully transmitted.
2602 mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
2605 struct mrvl_txq *q = txq;
2606 struct mrvl_shadow_txq *sq;
2607 struct pp2_hif *hif;
2608 struct pp2_ppio_desc descs[nb_pkts * PP2_PPIO_DESC_NUM_FRAGS];
2609 struct pp2_ppio_sg_pkts pkts;
2610 uint8_t frags[nb_pkts];
2611 unsigned int core_id = rte_lcore_id();
2612 int i, j, ret, bytes_sent = 0;
2613 int tail, tail_first;
2614 uint16_t num, sq_free_size;
2615 uint16_t nb_segs, total_descs = 0;
2618 hif = mrvl_get_hif(q->priv, core_id);
2619 sq = &q->shadow_txqs[core_id];
2623 if (unlikely(!q->priv->ppio || !hif))
2627 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2628 sq, q->queue_id, 0);
2630 /* Save shadow queue free size */
2631 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2634 for (i = 0; i < nb_pkts; i++) {
2635 struct rte_mbuf *mbuf = tx_pkts[i];
2636 struct rte_mbuf *seg = NULL;
2637 int gen_l3_cksum, gen_l4_cksum;
2638 enum pp2_outq_l3_type l3_type;
2639 enum pp2_outq_l4_type l4_type;
2641 nb_segs = mbuf->nb_segs;
2643 total_descs += nb_segs;
2646 * Check if total_descs does not exceed
2647 * shadow queue free size
2649 if (unlikely(total_descs > sq_free_size)) {
2650 total_descs -= nb_segs;
2652 "No room in shadow queue for %d packets! "
2653 "%d packets will be sent.\n",
2658 /* Check if nb_segs does not exceed the max nb of desc per
2661 if (nb_segs > PP2_PPIO_DESC_NUM_FRAGS) {
2662 total_descs -= nb_segs;
2664 "Too many segments. Packet won't be sent.\n");
2668 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2669 struct rte_mbuf *pref_pkt_hdr;
2671 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2672 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2673 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2676 pkts.frags[pkts.num] = nb_segs;
2680 for (j = 0; j < nb_segs - 1; j++) {
2681 /* For the subsequent segments, set shadow queue
2684 mrvl_fill_shadowq(sq, NULL);
2685 mrvl_fill_desc(&descs[tail], seg);
2690 /* Put first mbuf info in last shadow queue entry */
2691 mrvl_fill_shadowq(sq, mbuf);
2692 /* Update descriptor with last segment */
2693 mrvl_fill_desc(&descs[tail++], seg);
2695 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2696 /* In case unsupported ol_flags were passed
2697 * do not update descriptor offload information
2699 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2700 &l3_type, &l4_type, &gen_l3_cksum,
2705 pp2_ppio_outq_desc_set_proto_info(&descs[tail_first], l3_type,
2706 l4_type, mbuf->l2_len,
2707 mbuf->l2_len + mbuf->l3_len,
2708 gen_l3_cksum, gen_l4_cksum);
2712 pp2_ppio_send_sg(q->priv->ppio, hif, q->queue_id, descs,
2713 &total_descs, &pkts);
2714 /* number of packets that were not sent */
2715 if (unlikely(num > total_descs)) {
2716 for (i = total_descs; i < num; i++) {
2717 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2718 MRVL_PP2_TX_SHADOWQ_MASK;
2720 addr = sq->ent[sq->head].buff.cookie;
2723 rte_pktmbuf_pkt_len((struct rte_mbuf *)
2724 (cookie_addr_high | addr));
2726 sq->size -= num - total_descs;
2730 q->bytes_sent += bytes_sent;
2736 * Initialize packet processor.
2739 * 0 on success, negative error value otherwise.
2744 struct pp2_init_params init_params;
2746 memset(&init_params, 0, sizeof(init_params));
2747 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2748 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2749 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2751 return pp2_init(&init_params);
2755 * Deinitialize packet processor.
2758 * 0 on success, negative error value otherwise.
2761 mrvl_deinit_pp2(void)
2767 * Create private device structure.
2770 * Pointer to the port name passed in the initialization parameters.
2773 * Pointer to the newly allocated private device structure.
2775 static struct mrvl_priv *
2776 mrvl_priv_create(const char *dev_name)
2778 struct pp2_bpool_params bpool_params;
2779 char match[MRVL_MATCH_LEN];
2780 struct mrvl_priv *priv;
2783 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2787 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2788 &priv->pp_id, &priv->ppio_id);
2792 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2793 PP2_BPOOL_NUM_POOLS);
2796 priv->bpool_bit = bpool_bit;
2798 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2800 memset(&bpool_params, 0, sizeof(bpool_params));
2801 bpool_params.match = match;
2802 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2803 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2805 goto out_clear_bpool_bit;
2807 priv->ppio_params.type = PP2_PPIO_T_NIC;
2808 rte_spinlock_init(&priv->lock);
2811 out_clear_bpool_bit:
2812 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2819 * Create device representing Ethernet port.
2822 * Pointer to the port's name.
2825 * 0 on success, negative error value otherwise.
2828 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2830 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2831 struct rte_eth_dev *eth_dev;
2832 struct mrvl_priv *priv;
2835 eth_dev = rte_eth_dev_allocate(name);
2839 priv = mrvl_priv_create(name);
2844 eth_dev->data->dev_private = priv;
2846 eth_dev->data->mac_addrs =
2847 rte_zmalloc("mac_addrs",
2848 RTE_ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2849 if (!eth_dev->data->mac_addrs) {
2850 MRVL_LOG(ERR, "Failed to allocate space for eth addrs");
2855 memset(&req, 0, sizeof(req));
2856 strcpy(req.ifr_name, name);
2857 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2861 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2862 req.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN);
2864 eth_dev->device = &vdev->device;
2865 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2866 mrvl_set_tx_function(eth_dev);
2867 eth_dev->dev_ops = &mrvl_ops;
2868 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2870 rte_eth_dev_probing_finish(eth_dev);
2873 rte_eth_dev_release_port(eth_dev);
2879 * Callback used by rte_kvargs_process() during argument parsing.
2882 * Pointer to the parsed key (unused).
2884 * Pointer to the parsed value.
2886 * Pointer to the extra arguments which contains address of the
2887 * table of pointers to parsed interface names.
2893 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
2896 struct mrvl_ifnames *ifnames = extra_args;
2898 ifnames->names[ifnames->idx++] = value;
2904 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
2907 mrvl_deinit_hifs(void)
2911 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
2913 pp2_hif_deinit(hifs[i]);
2915 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
2916 memset(hifs, 0, sizeof(hifs));
2920 * DPDK callback to register the virtual device.
2923 * Pointer to the virtual device.
2926 * 0 on success, negative error value otherwise.
2929 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
2931 struct rte_kvargs *kvlist;
2932 struct mrvl_ifnames ifnames;
2934 uint32_t i, ifnum, cfgnum;
2937 params = rte_vdev_device_args(vdev);
2941 kvlist = rte_kvargs_parse(params, valid_args);
2945 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
2946 if (ifnum > RTE_DIM(ifnames.names))
2947 goto out_free_kvlist;
2950 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
2951 mrvl_get_ifnames, &ifnames);
2955 * The below system initialization should be done only once,
2956 * on the first provided configuration file
2958 if (!mrvl_qos_cfg) {
2959 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
2960 MRVL_LOG(INFO, "Parsing config file!");
2962 MRVL_LOG(ERR, "Cannot handle more than one config file!");
2963 goto out_free_kvlist;
2964 } else if (cfgnum == 1) {
2965 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
2966 mrvl_get_qoscfg, &mrvl_qos_cfg);
2973 MRVL_LOG(INFO, "Perform MUSDK initializations");
2975 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist);
2977 goto out_free_kvlist;
2979 ret = mrvl_init_pp2();
2981 MRVL_LOG(ERR, "Failed to init PP!");
2982 rte_mvep_deinit(MVEP_MOD_T_PP2);
2983 goto out_free_kvlist;
2986 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
2987 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
2989 mrvl_lcore_first = RTE_MAX_LCORE;
2990 mrvl_lcore_last = 0;
2993 for (i = 0; i < ifnum; i++) {
2994 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]);
2995 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
3001 rte_kvargs_free(kvlist);
3005 rte_pmd_mrvl_remove(vdev);
3008 rte_kvargs_free(kvlist);
3014 * DPDK callback to remove virtual device.
3017 * Pointer to the removed virtual device.
3020 * 0 on success, negative error value otherwise.
3023 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
3028 RTE_ETH_FOREACH_DEV(port_id) {
3029 if (rte_eth_devices[port_id].device != &vdev->device)
3031 ret |= rte_eth_dev_close(port_id);
3034 return ret == 0 ? 0 : -EIO;
3037 static struct rte_vdev_driver pmd_mrvl_drv = {
3038 .probe = rte_pmd_mrvl_probe,
3039 .remove = rte_pmd_mrvl_remove,
3042 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv);
3043 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2);
3044 RTE_LOG_REGISTER(mrvl_logtype, pmd.net.mvpp2, NOTICE);