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_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 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
151 uint32_t index, uint32_t vmdq __rte_unused);
153 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
155 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
156 static int mrvl_promiscuous_enable(struct rte_eth_dev *dev);
157 static int mrvl_allmulticast_enable(struct rte_eth_dev *dev);
159 #define MRVL_XSTATS_TBL_ENTRY(name) { \
160 #name, offsetof(struct pp2_ppio_statistics, name), \
161 sizeof(((struct pp2_ppio_statistics *)0)->name) \
164 /* Table with xstats data */
169 } mrvl_xstats_tbl[] = {
170 MRVL_XSTATS_TBL_ENTRY(rx_bytes),
171 MRVL_XSTATS_TBL_ENTRY(rx_packets),
172 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets),
173 MRVL_XSTATS_TBL_ENTRY(rx_errors),
174 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped),
175 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped),
176 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped),
177 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped),
178 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped),
179 MRVL_XSTATS_TBL_ENTRY(tx_bytes),
180 MRVL_XSTATS_TBL_ENTRY(tx_packets),
181 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets),
182 MRVL_XSTATS_TBL_ENTRY(tx_errors)
186 mrvl_fill_shadowq(struct mrvl_shadow_txq *sq, struct rte_mbuf *buf)
188 sq->ent[sq->head].buff.cookie = (uint64_t)buf;
189 sq->ent[sq->head].buff.addr = buf ?
190 rte_mbuf_data_iova_default(buf) : 0;
192 sq->ent[sq->head].bpool =
193 (unlikely(!buf || buf->port >= RTE_MAX_ETHPORTS ||
194 buf->refcnt > 1)) ? NULL :
195 mrvl_port_to_bpool_lookup[buf->port];
197 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
202 mrvl_fill_desc(struct pp2_ppio_desc *desc, struct rte_mbuf *buf)
204 pp2_ppio_outq_desc_reset(desc);
205 pp2_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf));
206 pp2_ppio_outq_desc_set_pkt_offset(desc, 0);
207 pp2_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf));
211 mrvl_get_bpool_size(int pp2_id, int pool_id)
216 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
217 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
223 mrvl_reserve_bit(int *bitmap, int max)
225 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
236 mrvl_init_hif(int core_id)
238 struct pp2_hif_params params;
239 char match[MRVL_MATCH_LEN];
242 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
244 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
248 snprintf(match, sizeof(match), "hif-%d", ret);
249 memset(¶ms, 0, sizeof(params));
250 params.match = match;
251 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
252 ret = pp2_hif_init(¶ms, &hifs[core_id]);
254 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id);
261 static inline struct pp2_hif*
262 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
266 if (likely(hifs[core_id] != NULL))
267 return hifs[core_id];
269 rte_spinlock_lock(&priv->lock);
271 ret = mrvl_init_hif(core_id);
273 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
277 if (core_id < mrvl_lcore_first)
278 mrvl_lcore_first = core_id;
280 if (core_id > mrvl_lcore_last)
281 mrvl_lcore_last = core_id;
283 rte_spinlock_unlock(&priv->lock);
285 return hifs[core_id];
289 * Set tx burst function according to offload flag
292 * Pointer to Ethernet device structure.
295 mrvl_set_tx_function(struct rte_eth_dev *dev)
297 struct mrvl_priv *priv = dev->data->dev_private;
299 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
300 if (priv->multiseg) {
301 RTE_LOG(INFO, PMD, "Using multi-segment tx callback\n");
302 dev->tx_pkt_burst = mrvl_tx_sg_pkt_burst;
304 RTE_LOG(INFO, PMD, "Using single-segment tx callback\n");
305 dev->tx_pkt_burst = mrvl_tx_pkt_burst;
310 * Configure rss based on dpdk rss configuration.
313 * Pointer to private structure.
315 * Pointer to RSS configuration.
318 * 0 on success, negative error value otherwise.
321 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
323 if (rss_conf->rss_key)
324 MRVL_LOG(WARNING, "Changing hash key is not supported");
326 if (rss_conf->rss_hf == 0) {
327 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
328 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
329 priv->ppio_params.inqs_params.hash_type =
330 PP2_PPIO_HASH_T_2_TUPLE;
331 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
332 priv->ppio_params.inqs_params.hash_type =
333 PP2_PPIO_HASH_T_5_TUPLE;
334 priv->rss_hf_tcp = 1;
335 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
336 priv->ppio_params.inqs_params.hash_type =
337 PP2_PPIO_HASH_T_5_TUPLE;
338 priv->rss_hf_tcp = 0;
347 * Ethernet device configuration.
349 * Prepare the driver for a given number of TX and RX queues and
353 * Pointer to Ethernet device structure.
356 * 0 on success, negative error value otherwise.
359 mrvl_dev_configure(struct rte_eth_dev *dev)
361 struct mrvl_priv *priv = dev->data->dev_private;
365 MRVL_LOG(INFO, "Device reconfiguration is not supported");
369 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
370 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
371 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d",
372 dev->data->dev_conf.rxmode.mq_mode);
376 if (dev->data->dev_conf.rxmode.split_hdr_size) {
377 MRVL_LOG(INFO, "Split headers not supported");
381 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
382 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
383 MRVL_PP2_ETH_HDRS_LEN;
385 if (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
388 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
389 dev->data->nb_rx_queues);
393 ret = mrvl_configure_txqs(priv, dev->data->port_id,
394 dev->data->nb_tx_queues);
398 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
399 priv->ppio_params.maintain_stats = 1;
400 priv->nb_rx_queues = dev->data->nb_rx_queues;
402 ret = mrvl_tm_init(dev);
406 if (dev->data->nb_rx_queues == 1 &&
407 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
408 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue");
409 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
414 return mrvl_configure_rss(priv,
415 &dev->data->dev_conf.rx_adv_conf.rss_conf);
419 * DPDK callback to change the MTU.
421 * Setting the MTU affects hardware MRU (packets larger than the MRU
425 * Pointer to Ethernet device structure.
430 * 0 on success, negative error value otherwise.
433 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
435 struct mrvl_priv *priv = dev->data->dev_private;
437 uint16_t mbuf_data_size = 0; /* SW buffer size */
440 mru = MRVL_PP2_MTU_TO_MRU(mtu);
442 * min_rx_buf_size is equal to mbuf data size
443 * if pmd didn't set it differently
445 mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
447 * - setting mru greater than the mbuf size resulting in
448 * hw and sw buffer size mismatch
449 * - setting mtu that requires the support of scattered packets
450 * when this feature has not been enabled/supported so far
451 * (TODO check scattered_rx flag here once scattered RX is supported).
453 if (mru - RTE_ETHER_CRC_LEN + MRVL_PKT_OFFS > mbuf_data_size) {
454 mru = mbuf_data_size + RTE_ETHER_CRC_LEN - MRVL_PKT_OFFS;
455 mtu = MRVL_PP2_MRU_TO_MTU(mru);
456 MRVL_LOG(WARNING, "MTU too big, max MTU possible limitted "
457 "by current mbuf size: %u. Set MTU to %u, MRU to %u",
458 mbuf_data_size, mtu, mru);
461 if (mtu < RTE_ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX) {
462 MRVL_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru);
466 dev->data->mtu = mtu;
467 dev->data->dev_conf.rxmode.max_rx_pkt_len = mru - MV_MH_SIZE;
472 ret = pp2_ppio_set_mru(priv->ppio, mru);
474 MRVL_LOG(ERR, "Failed to change MRU");
478 ret = pp2_ppio_set_mtu(priv->ppio, mtu);
480 MRVL_LOG(ERR, "Failed to change MTU");
488 * DPDK callback to bring the link up.
491 * Pointer to Ethernet device structure.
494 * 0 on success, negative error value otherwise.
497 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
499 struct mrvl_priv *priv = dev->data->dev_private;
503 dev->data->dev_link.link_status = ETH_LINK_UP;
507 ret = pp2_ppio_enable(priv->ppio);
512 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
513 * as pp2_ppio_enable() changes port->t_mode from default 0 to
514 * PP2_TRAFFIC_INGRESS_EGRESS.
516 * Set mtu to default DPDK value here.
518 ret = mrvl_mtu_set(dev, dev->data->mtu);
520 pp2_ppio_disable(priv->ppio);
524 dev->data->dev_link.link_status = ETH_LINK_UP;
529 * DPDK callback to bring the link down.
532 * Pointer to Ethernet device structure.
535 * 0 on success, negative error value otherwise.
538 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
540 struct mrvl_priv *priv = dev->data->dev_private;
544 dev->data->dev_link.link_status = ETH_LINK_DOWN;
547 ret = pp2_ppio_disable(priv->ppio);
551 dev->data->dev_link.link_status = ETH_LINK_DOWN;
556 * DPDK callback to start tx queue.
559 * Pointer to Ethernet device structure.
561 * Transmit queue index.
564 * 0 on success, negative error value otherwise.
567 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
569 struct mrvl_priv *priv = dev->data->dev_private;
575 /* passing 1 enables given tx queue */
576 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1);
578 MRVL_LOG(ERR, "Failed to start txq %d", queue_id);
582 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
588 * DPDK callback to stop tx queue.
591 * Pointer to Ethernet device structure.
593 * Transmit queue index.
596 * 0 on success, negative error value otherwise.
599 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
601 struct mrvl_priv *priv = dev->data->dev_private;
607 /* passing 0 disables given tx queue */
608 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0);
610 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id);
614 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
620 * Populate VLAN Filter configuration.
623 * Pointer to Ethernet device structure.
628 * 0 on success, negative error value otherwise.
630 static int mrvl_populate_vlan_table(struct rte_eth_dev *dev, int on)
634 struct rte_vlan_filter_conf *vfc;
636 vfc = &dev->data->vlan_filter_conf;
637 for (j = 0; j < RTE_DIM(vfc->ids); j++) {
640 uint64_t ids = vfc->ids[j];
647 /* count trailing zeroes */
648 vbit = ~ids & (ids - 1);
649 /* clear least significant bit set */
650 ids ^= (ids ^ (ids - 1)) ^ vbit;
653 ret = mrvl_vlan_filter_set(dev, vlan, on);
655 MRVL_LOG(ERR, "Failed to setup VLAN filter\n");
665 * DPDK callback to start the device.
668 * Pointer to Ethernet device structure.
671 * 0 on success, negative errno value on failure.
674 mrvl_dev_start(struct rte_eth_dev *dev)
676 struct mrvl_priv *priv = dev->data->dev_private;
677 char match[MRVL_MATCH_LEN];
678 int ret = 0, i, def_init_size;
679 struct rte_ether_addr *mac_addr;
682 return mrvl_dev_set_link_up(dev);
684 snprintf(match, sizeof(match), "ppio-%d:%d",
685 priv->pp_id, priv->ppio_id);
686 priv->ppio_params.match = match;
689 * Calculate the minimum bpool size for refill feature as follows:
690 * 2 default burst sizes multiply by number of rx queues.
691 * If the bpool size will be below this value, new buffers will
692 * be added to the pool.
694 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
696 /* In case initial bpool size configured in queues setup is
697 * smaller than minimum size add more buffers
699 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
700 if (priv->bpool_init_size < def_init_size) {
701 int buffs_to_add = def_init_size - priv->bpool_init_size;
703 priv->bpool_init_size += buffs_to_add;
704 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
706 MRVL_LOG(ERR, "Failed to add buffers to bpool");
710 * Calculate the maximum bpool size for refill feature as follows:
711 * maximum number of descriptors in rx queue multiply by number
712 * of rx queues plus minimum bpool size.
713 * In case the bpool size will exceed this value, superfluous buffers
716 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
717 priv->bpool_min_size;
719 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
721 MRVL_LOG(ERR, "Failed to init ppio");
726 * In case there are some some stale uc/mc mac addresses flush them
727 * here. It cannot be done during mrvl_dev_close() as port information
728 * is already gone at that point (due to pp2_ppio_deinit() in
731 if (!priv->uc_mc_flushed) {
732 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
735 "Failed to flush uc/mc filter list");
738 priv->uc_mc_flushed = 1;
741 ret = mrvl_mtu_set(dev, dev->data->mtu);
743 MRVL_LOG(ERR, "Failed to set MTU to %d", dev->data->mtu);
745 if (!rte_is_zero_ether_addr(&dev->data->mac_addrs[0]))
746 mrvl_mac_addr_set(dev, &dev->data->mac_addrs[0]);
748 for (i = 1; i < MRVL_MAC_ADDRS_MAX; i++) {
749 mac_addr = &dev->data->mac_addrs[i];
751 /* skip zero address */
752 if (rte_is_zero_ether_addr(mac_addr))
755 mrvl_mac_addr_add(dev, mac_addr, i, 0);
758 if (dev->data->all_multicast == 1)
759 mrvl_allmulticast_enable(dev);
761 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
762 ret = mrvl_populate_vlan_table(dev, 1);
764 MRVL_LOG(ERR, "Failed to populate VLAN table");
769 /* For default QoS config, don't start classifier. */
771 mrvl_qos_cfg->port[dev->data->port_id].use_global_defaults == 0) {
772 ret = mrvl_start_qos_mapping(priv);
774 MRVL_LOG(ERR, "Failed to setup QoS mapping");
779 ret = pp2_ppio_set_loopback(priv->ppio, dev->data->dev_conf.lpbk_mode);
781 MRVL_LOG(ERR, "Failed to set loopback");
785 if (dev->data->promiscuous == 1)
786 mrvl_promiscuous_enable(dev);
788 if (dev->data->dev_link.link_status == ETH_LINK_UP) {
789 ret = mrvl_dev_set_link_up(dev);
791 MRVL_LOG(ERR, "Failed to set link up");
792 dev->data->dev_link.link_status = ETH_LINK_DOWN;
797 /* start tx queues */
798 for (i = 0; i < dev->data->nb_tx_queues; i++) {
799 struct mrvl_txq *txq = dev->data->tx_queues[i];
801 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
803 if (!txq->tx_deferred_start)
807 * All txqs are started by default. Stop them
808 * so that tx_deferred_start works as expected.
810 ret = mrvl_tx_queue_stop(dev, i);
817 mrvl_set_tx_function(dev);
821 MRVL_LOG(ERR, "Failed to start device");
822 pp2_ppio_deinit(priv->ppio);
827 * Flush receive queues.
830 * Pointer to Ethernet device structure.
833 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
837 MRVL_LOG(INFO, "Flushing rx queues");
838 for (i = 0; i < dev->data->nb_rx_queues; i++) {
842 struct mrvl_rxq *q = dev->data->rx_queues[i];
843 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
845 num = MRVL_PP2_RXD_MAX;
846 ret = pp2_ppio_recv(q->priv->ppio,
847 q->priv->rxq_map[q->queue_id].tc,
848 q->priv->rxq_map[q->queue_id].inq,
849 descs, (uint16_t *)&num);
850 } while (ret == 0 && num);
855 * Flush transmit shadow queues.
858 * Pointer to Ethernet device structure.
861 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
864 struct mrvl_txq *txq;
866 MRVL_LOG(INFO, "Flushing tx shadow queues");
867 for (i = 0; i < dev->data->nb_tx_queues; i++) {
868 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
870 for (j = 0; j < RTE_MAX_LCORE; j++) {
871 struct mrvl_shadow_txq *sq;
876 sq = &txq->shadow_txqs[j];
877 mrvl_free_sent_buffers(txq->priv->ppio,
878 hifs[j], j, sq, txq->queue_id, 1);
879 while (sq->tail != sq->head) {
880 uint64_t addr = cookie_addr_high |
881 sq->ent[sq->tail].buff.cookie;
883 (struct rte_mbuf *)addr);
884 sq->tail = (sq->tail + 1) &
885 MRVL_PP2_TX_SHADOWQ_MASK;
887 memset(sq, 0, sizeof(*sq));
893 * Flush hardware bpool (buffer-pool).
896 * Pointer to Ethernet device structure.
899 mrvl_flush_bpool(struct rte_eth_dev *dev)
901 struct mrvl_priv *priv = dev->data->dev_private;
905 unsigned int core_id = rte_lcore_id();
907 if (core_id == LCORE_ID_ANY)
908 core_id = rte_get_main_lcore();
910 hif = mrvl_get_hif(priv, core_id);
912 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
914 MRVL_LOG(ERR, "Failed to get bpool buffers number");
919 struct pp2_buff_inf inf;
922 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
926 addr = cookie_addr_high | inf.cookie;
927 rte_pktmbuf_free((struct rte_mbuf *)addr);
932 * DPDK callback to stop the device.
935 * Pointer to Ethernet device structure.
938 mrvl_dev_stop(struct rte_eth_dev *dev)
940 return mrvl_dev_set_link_down(dev);
944 * DPDK callback to close the device.
947 * Pointer to Ethernet device structure.
950 mrvl_dev_close(struct rte_eth_dev *dev)
952 struct mrvl_priv *priv = dev->data->dev_private;
955 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
958 mrvl_flush_rx_queues(dev);
959 mrvl_flush_tx_shadow_queues(dev);
960 mrvl_flow_deinit(dev);
961 mrvl_mtr_deinit(dev);
963 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
964 struct pp2_ppio_tc_params *tc_params =
965 &priv->ppio_params.inqs_params.tcs_params[i];
967 if (tc_params->inqs_params) {
968 rte_free(tc_params->inqs_params);
969 tc_params->inqs_params = NULL;
974 pp2_cls_tbl_deinit(priv->cls_tbl);
975 priv->cls_tbl = NULL;
979 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
980 priv->qos_tbl = NULL;
983 mrvl_flush_bpool(dev);
987 pp2_ppio_deinit(priv->ppio);
991 /* policer must be released after ppio deinitialization */
992 if (priv->default_policer) {
993 pp2_cls_plcr_deinit(priv->default_policer);
994 priv->default_policer = NULL;
999 pp2_bpool_deinit(priv->bpool);
1000 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
1006 if (mrvl_dev_num == 0) {
1007 MRVL_LOG(INFO, "Perform MUSDK deinit");
1010 rte_mvep_deinit(MVEP_MOD_T_PP2);
1017 * DPDK callback to retrieve physical link information.
1020 * Pointer to Ethernet device structure.
1021 * @param wait_to_complete
1022 * Wait for request completion (ignored).
1025 * 0 on success, negative error value otherwise.
1028 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
1032 * once MUSDK provides necessary API use it here
1034 struct mrvl_priv *priv = dev->data->dev_private;
1035 struct ethtool_cmd edata;
1037 int ret, fd, link_up;
1042 edata.cmd = ETHTOOL_GSET;
1044 strcpy(req.ifr_name, dev->data->name);
1045 req.ifr_data = (void *)&edata;
1047 fd = socket(AF_INET, SOCK_DGRAM, 0);
1051 ret = ioctl(fd, SIOCETHTOOL, &req);
1059 switch (ethtool_cmd_speed(&edata)) {
1061 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
1064 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
1067 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
1070 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
1073 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
1076 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
1077 ETH_LINK_HALF_DUPLEX;
1078 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
1080 pp2_ppio_get_link_state(priv->ppio, &link_up);
1081 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
1087 * DPDK callback to enable promiscuous mode.
1090 * Pointer to Ethernet device structure.
1093 * 0 on success, negative error value otherwise.
1096 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
1098 struct mrvl_priv *priv = dev->data->dev_private;
1107 ret = pp2_ppio_set_promisc(priv->ppio, 1);
1109 MRVL_LOG(ERR, "Failed to enable promiscuous mode");
1117 * DPDK callback to enable allmulti mode.
1120 * Pointer to Ethernet device structure.
1123 * 0 on success, negative error value otherwise.
1126 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
1128 struct mrvl_priv *priv = dev->data->dev_private;
1137 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
1139 MRVL_LOG(ERR, "Failed enable all-multicast mode");
1147 * DPDK callback to disable promiscuous mode.
1150 * Pointer to Ethernet device structure.
1153 * 0 on success, negative error value otherwise.
1156 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
1158 struct mrvl_priv *priv = dev->data->dev_private;
1167 ret = pp2_ppio_set_promisc(priv->ppio, 0);
1169 MRVL_LOG(ERR, "Failed to disable promiscuous mode");
1177 * DPDK callback to disable allmulticast mode.
1180 * Pointer to Ethernet device structure.
1183 * 0 on success, negative error value otherwise.
1186 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
1188 struct mrvl_priv *priv = dev->data->dev_private;
1197 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
1199 MRVL_LOG(ERR, "Failed to disable all-multicast mode");
1207 * DPDK callback to remove a MAC address.
1210 * Pointer to Ethernet device structure.
1212 * MAC address index.
1215 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1217 struct mrvl_priv *priv = dev->data->dev_private;
1218 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1227 ret = pp2_ppio_remove_mac_addr(priv->ppio,
1228 dev->data->mac_addrs[index].addr_bytes);
1230 rte_ether_format_addr(buf, sizeof(buf),
1231 &dev->data->mac_addrs[index]);
1232 MRVL_LOG(ERR, "Failed to remove mac %s", buf);
1237 * DPDK callback to add a MAC address.
1240 * Pointer to Ethernet device structure.
1242 * MAC address to register.
1244 * MAC address index.
1246 * VMDq pool index to associate address with (unused).
1249 * 0 on success, negative error value otherwise.
1252 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1253 uint32_t index, uint32_t vmdq __rte_unused)
1255 struct mrvl_priv *priv = dev->data->dev_private;
1256 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1266 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
1270 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
1271 * parameter uc_filter_max. Maximum number of mc addresses is then
1272 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
1275 * If more than uc_filter_max uc addresses were added to filter list
1276 * then NIC will switch to promiscuous mode automatically.
1278 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
1279 * were added to filter list then NIC will switch to all-multicast mode
1282 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
1284 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1285 MRVL_LOG(ERR, "Failed to add mac %s", buf);
1293 * DPDK callback to set the primary MAC address.
1296 * Pointer to Ethernet device structure.
1298 * MAC address to register.
1301 * 0 on success, negative error value otherwise.
1304 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1306 struct mrvl_priv *priv = dev->data->dev_private;
1315 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
1317 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1318 rte_ether_format_addr(buf, sizeof(buf), mac_addr);
1319 MRVL_LOG(ERR, "Failed to set mac to %s", buf);
1326 * DPDK callback to get device statistics.
1329 * Pointer to Ethernet device structure.
1331 * Stats structure output buffer.
1334 * 0 on success, negative error value otherwise.
1337 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1339 struct mrvl_priv *priv = dev->data->dev_private;
1340 struct pp2_ppio_statistics ppio_stats;
1341 uint64_t drop_mac = 0;
1342 unsigned int i, idx, ret;
1347 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1348 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1349 struct pp2_ppio_inq_statistics rx_stats;
1354 idx = rxq->queue_id;
1355 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1357 "rx queue %d stats out of range (0 - %d)",
1358 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1362 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1363 priv->rxq_map[idx].tc,
1364 priv->rxq_map[idx].inq,
1366 if (unlikely(ret)) {
1368 "Failed to update rx queue %d stats", idx);
1372 stats->q_ibytes[idx] = rxq->bytes_recv;
1373 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1374 stats->q_errors[idx] = rx_stats.drop_early +
1375 rx_stats.drop_fullq +
1378 stats->ibytes += rxq->bytes_recv;
1379 drop_mac += rxq->drop_mac;
1382 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1383 struct mrvl_txq *txq = dev->data->tx_queues[i];
1384 struct pp2_ppio_outq_statistics tx_stats;
1389 idx = txq->queue_id;
1390 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1392 "tx queue %d stats out of range (0 - %d)",
1393 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1396 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1398 if (unlikely(ret)) {
1400 "Failed to update tx queue %d stats", idx);
1404 stats->q_opackets[idx] = tx_stats.deq_desc;
1405 stats->q_obytes[idx] = txq->bytes_sent;
1406 stats->obytes += txq->bytes_sent;
1409 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1410 if (unlikely(ret)) {
1411 MRVL_LOG(ERR, "Failed to update port statistics");
1415 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1416 stats->opackets += ppio_stats.tx_packets;
1417 stats->imissed += ppio_stats.rx_fullq_dropped +
1418 ppio_stats.rx_bm_dropped +
1419 ppio_stats.rx_early_dropped +
1420 ppio_stats.rx_fifo_dropped +
1421 ppio_stats.rx_cls_dropped;
1422 stats->ierrors = drop_mac;
1428 * DPDK callback to clear device statistics.
1431 * Pointer to Ethernet device structure.
1434 * 0 on success, negative error value otherwise.
1437 mrvl_stats_reset(struct rte_eth_dev *dev)
1439 struct mrvl_priv *priv = dev->data->dev_private;
1445 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1446 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1448 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1449 priv->rxq_map[i].inq, NULL, 1);
1450 rxq->bytes_recv = 0;
1454 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1455 struct mrvl_txq *txq = dev->data->tx_queues[i];
1457 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1458 txq->bytes_sent = 0;
1461 return pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1465 * DPDK callback to get extended statistics.
1468 * Pointer to Ethernet device structure.
1470 * Pointer to xstats table.
1472 * Number of entries in xstats table.
1474 * Negative value on error, number of read xstats otherwise.
1477 mrvl_xstats_get(struct rte_eth_dev *dev,
1478 struct rte_eth_xstat *stats, unsigned int n)
1480 struct mrvl_priv *priv = dev->data->dev_private;
1481 struct pp2_ppio_statistics ppio_stats;
1487 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1488 for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
1491 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
1492 val = *(uint32_t *)((uint8_t *)&ppio_stats +
1493 mrvl_xstats_tbl[i].offset);
1494 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t))
1495 val = *(uint64_t *)((uint8_t *)&ppio_stats +
1496 mrvl_xstats_tbl[i].offset);
1501 stats[i].value = val;
1508 * DPDK callback to reset extended statistics.
1511 * Pointer to Ethernet device structure.
1514 * 0 on success, negative error value otherwise.
1517 mrvl_xstats_reset(struct rte_eth_dev *dev)
1519 return mrvl_stats_reset(dev);
1523 * DPDK callback to get extended statistics names.
1525 * @param dev (unused)
1526 * Pointer to Ethernet device structure.
1527 * @param xstats_names
1528 * Pointer to xstats names table.
1530 * Size of the xstats names table.
1532 * Number of read names.
1535 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1536 struct rte_eth_xstat_name *xstats_names,
1542 return RTE_DIM(mrvl_xstats_tbl);
1544 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
1545 strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name,
1546 RTE_ETH_XSTATS_NAME_SIZE);
1552 * DPDK callback to get information about the device.
1555 * Pointer to Ethernet device structure (unused).
1557 * Info structure output buffer.
1560 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1561 struct rte_eth_dev_info *info)
1563 info->speed_capa = ETH_LINK_SPEED_10M |
1564 ETH_LINK_SPEED_100M |
1568 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1569 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1570 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1572 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1573 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1574 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1576 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1577 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1578 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1580 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1581 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1583 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1584 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1586 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1587 ETH_RSS_NONFRAG_IPV4_TCP |
1588 ETH_RSS_NONFRAG_IPV4_UDP;
1590 /* By default packets are dropped if no descriptors are available */
1591 info->default_rxconf.rx_drop_en = 1;
1593 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1599 * Return supported packet types.
1602 * Pointer to Ethernet device structure (unused).
1605 * Const pointer to the table with supported packet types.
1607 static const uint32_t *
1608 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1610 static const uint32_t ptypes[] = {
1612 RTE_PTYPE_L2_ETHER_VLAN,
1613 RTE_PTYPE_L2_ETHER_QINQ,
1615 RTE_PTYPE_L3_IPV4_EXT,
1616 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1618 RTE_PTYPE_L3_IPV6_EXT,
1619 RTE_PTYPE_L2_ETHER_ARP,
1628 * DPDK callback to get information about specific receive queue.
1631 * Pointer to Ethernet device structure.
1632 * @param rx_queue_id
1633 * Receive queue index.
1635 * Receive queue information structure.
1637 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1638 struct rte_eth_rxq_info *qinfo)
1640 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1641 struct mrvl_priv *priv = dev->data->dev_private;
1642 int inq = priv->rxq_map[rx_queue_id].inq;
1643 int tc = priv->rxq_map[rx_queue_id].tc;
1644 struct pp2_ppio_tc_params *tc_params =
1645 &priv->ppio_params.inqs_params.tcs_params[tc];
1648 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1652 * DPDK callback to get information about specific transmit queue.
1655 * Pointer to Ethernet device structure.
1656 * @param tx_queue_id
1657 * Transmit queue index.
1659 * Transmit queue information structure.
1661 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1662 struct rte_eth_txq_info *qinfo)
1664 struct mrvl_priv *priv = dev->data->dev_private;
1665 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id];
1668 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1669 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1673 * DPDK callback to Configure a VLAN filter.
1676 * Pointer to Ethernet device structure.
1678 * VLAN ID to filter.
1683 * 0 on success, negative error value otherwise.
1686 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1688 struct mrvl_priv *priv = dev->data->dev_private;
1696 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1697 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1701 * DPDK callback to Configure VLAN offload.
1704 * Pointer to Ethernet device structure.
1706 * VLAN offload mask.
1709 * 0 on success, negative error value otherwise.
1711 static int mrvl_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1713 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
1716 if (mask & ETH_VLAN_STRIP_MASK)
1717 MRVL_LOG(ERR, "VLAN stripping is not supported\n");
1719 if (mask & ETH_VLAN_FILTER_MASK) {
1720 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1721 ret = mrvl_populate_vlan_table(dev, 1);
1723 ret = mrvl_populate_vlan_table(dev, 0);
1729 if (mask & ETH_VLAN_EXTEND_MASK)
1730 MRVL_LOG(ERR, "Extend VLAN not supported\n");
1736 * Release buffers to hardware bpool (buffer-pool)
1739 * Receive queue pointer.
1741 * Number of buffers to release to bpool.
1744 * 0 on success, negative error value otherwise.
1747 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1749 struct buff_release_entry entries[num];
1750 struct rte_mbuf *mbufs[num];
1752 unsigned int core_id;
1753 struct pp2_hif *hif;
1754 struct pp2_bpool *bpool;
1756 core_id = rte_lcore_id();
1757 if (core_id == LCORE_ID_ANY)
1758 core_id = rte_get_main_lcore();
1760 hif = mrvl_get_hif(rxq->priv, core_id);
1764 bpool = rxq->priv->bpool;
1766 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1770 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1772 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1774 for (i = 0; i < num; i++) {
1775 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1776 != cookie_addr_high) {
1778 "mbuf virtual addr high is out of range "
1779 "0x%x instead of 0x%x\n",
1780 (uint32_t)((uint64_t)mbufs[i] >> 32),
1781 (uint32_t)(cookie_addr_high >> 32));
1785 entries[i].buff.addr =
1786 rte_mbuf_data_iova_default(mbufs[i]);
1787 entries[i].buff.cookie = (uintptr_t)mbufs[i];
1788 entries[i].bpool = bpool;
1791 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1792 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1799 for (; i < num; i++)
1800 rte_pktmbuf_free(mbufs[i]);
1806 * DPDK callback to configure the receive queue.
1809 * Pointer to Ethernet device structure.
1813 * Number of descriptors to configure in queue.
1815 * NUMA socket on which memory must be allocated.
1817 * Thresholds parameters.
1819 * Memory pool for buffer allocations.
1822 * 0 on success, negative error value otherwise.
1825 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1826 unsigned int socket,
1827 const struct rte_eth_rxconf *conf,
1828 struct rte_mempool *mp)
1830 struct mrvl_priv *priv = dev->data->dev_private;
1831 struct mrvl_rxq *rxq;
1832 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
1833 uint32_t max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1837 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1839 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1841 * Unknown TC mapping, mapping will not have a correct queue.
1843 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu",
1844 idx, priv->ppio_id);
1848 frame_size = buf_size - RTE_PKTMBUF_HEADROOM -
1849 MRVL_PKT_EFFEC_OFFS + RTE_ETHER_CRC_LEN;
1850 if (frame_size < max_rx_pkt_len) {
1852 "Mbuf size must be increased to %u bytes to hold up "
1853 "to %u bytes of data.",
1854 buf_size + max_rx_pkt_len - frame_size,
1856 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1857 MRVL_LOG(INFO, "Setting max rx pkt len to %u",
1858 dev->data->dev_conf.rxmode.max_rx_pkt_len);
1861 if (dev->data->rx_queues[idx]) {
1862 rte_free(dev->data->rx_queues[idx]);
1863 dev->data->rx_queues[idx] = NULL;
1866 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1872 rxq->cksum_enabled = offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
1873 rxq->queue_id = idx;
1874 rxq->port_id = dev->data->port_id;
1875 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1877 tc = priv->rxq_map[rxq->queue_id].tc,
1878 inq = priv->rxq_map[rxq->queue_id].inq;
1879 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1882 ret = mrvl_fill_bpool(rxq, desc);
1888 priv->bpool_init_size += desc;
1890 dev->data->rx_queues[idx] = rxq;
1896 * DPDK callback to release the receive queue.
1899 * Generic receive queue pointer.
1902 mrvl_rx_queue_release(void *rxq)
1904 struct mrvl_rxq *q = rxq;
1905 struct pp2_ppio_tc_params *tc_params;
1906 int i, num, tc, inq;
1907 struct pp2_hif *hif;
1908 unsigned int core_id = rte_lcore_id();
1910 if (core_id == LCORE_ID_ANY)
1911 core_id = rte_get_main_lcore();
1916 hif = mrvl_get_hif(q->priv, core_id);
1921 tc = q->priv->rxq_map[q->queue_id].tc;
1922 inq = q->priv->rxq_map[q->queue_id].inq;
1923 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1924 num = tc_params->inqs_params[inq].size;
1925 for (i = 0; i < num; i++) {
1926 struct pp2_buff_inf inf;
1929 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1930 addr = cookie_addr_high | inf.cookie;
1931 rte_pktmbuf_free((struct rte_mbuf *)addr);
1938 * DPDK callback to configure the transmit queue.
1941 * Pointer to Ethernet device structure.
1943 * Transmit queue index.
1945 * Number of descriptors to configure in the queue.
1947 * NUMA socket on which memory must be allocated.
1949 * Tx queue configuration parameters.
1952 * 0 on success, negative error value otherwise.
1955 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1956 unsigned int socket,
1957 const struct rte_eth_txconf *conf)
1959 struct mrvl_priv *priv = dev->data->dev_private;
1960 struct mrvl_txq *txq;
1962 if (dev->data->tx_queues[idx]) {
1963 rte_free(dev->data->tx_queues[idx]);
1964 dev->data->tx_queues[idx] = NULL;
1967 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1972 txq->queue_id = idx;
1973 txq->port_id = dev->data->port_id;
1974 txq->tx_deferred_start = conf->tx_deferred_start;
1975 dev->data->tx_queues[idx] = txq;
1977 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1983 * DPDK callback to release the transmit queue.
1986 * Generic transmit queue pointer.
1989 mrvl_tx_queue_release(void *txq)
1991 struct mrvl_txq *q = txq;
2000 * DPDK callback to get flow control configuration.
2003 * Pointer to Ethernet device structure.
2005 * Pointer to the flow control configuration.
2008 * 0 on success, negative error value otherwise.
2011 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2013 struct mrvl_priv *priv = dev->data->dev_private;
2019 ret = pp2_ppio_get_rx_pause(priv->ppio, &en);
2021 MRVL_LOG(ERR, "Failed to read rx pause state");
2025 fc_conf->mode = en ? RTE_FC_RX_PAUSE : RTE_FC_NONE;
2031 * DPDK callback to set flow control configuration.
2034 * Pointer to Ethernet device structure.
2036 * Pointer to the flow control configuration.
2039 * 0 on success, negative error value otherwise.
2042 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2044 struct mrvl_priv *priv = dev->data->dev_private;
2049 if (fc_conf->high_water ||
2050 fc_conf->low_water ||
2051 fc_conf->pause_time ||
2052 fc_conf->mac_ctrl_frame_fwd ||
2054 MRVL_LOG(ERR, "Flowctrl parameter is not supported");
2059 if (fc_conf->mode == RTE_FC_NONE ||
2060 fc_conf->mode == RTE_FC_RX_PAUSE) {
2063 en = fc_conf->mode == RTE_FC_NONE ? 0 : 1;
2064 ret = pp2_ppio_set_rx_pause(priv->ppio, en);
2067 "Failed to change flowctrl on RX side");
2076 * Update RSS hash configuration
2079 * Pointer to Ethernet device structure.
2081 * Pointer to RSS configuration.
2084 * 0 on success, negative error value otherwise.
2087 mrvl_rss_hash_update(struct rte_eth_dev *dev,
2088 struct rte_eth_rss_conf *rss_conf)
2090 struct mrvl_priv *priv = dev->data->dev_private;
2095 return mrvl_configure_rss(priv, rss_conf);
2099 * DPDK callback to get RSS hash configuration.
2102 * Pointer to Ethernet device structure.
2104 * Pointer to RSS configuration.
2110 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
2111 struct rte_eth_rss_conf *rss_conf)
2113 struct mrvl_priv *priv = dev->data->dev_private;
2114 enum pp2_ppio_hash_type hash_type =
2115 priv->ppio_params.inqs_params.hash_type;
2117 rss_conf->rss_key = NULL;
2119 if (hash_type == PP2_PPIO_HASH_T_NONE)
2120 rss_conf->rss_hf = 0;
2121 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
2122 rss_conf->rss_hf = ETH_RSS_IPV4;
2123 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
2124 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
2125 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
2126 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
2132 * DPDK callback to get rte_flow callbacks.
2135 * Pointer to the device structure.
2139 * Flow filter operation.
2141 * Pointer to pass the flow ops.
2144 * 0 on success, negative error value otherwise.
2147 mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
2148 enum rte_filter_type filter_type,
2149 enum rte_filter_op filter_op, void *arg)
2151 switch (filter_type) {
2152 case RTE_ETH_FILTER_GENERIC:
2153 if (filter_op != RTE_ETH_FILTER_GET)
2155 *(const void **)arg = &mrvl_flow_ops;
2158 MRVL_LOG(WARNING, "Filter type (%d) not supported",
2165 * DPDK callback to get rte_mtr callbacks.
2168 * Pointer to the device structure.
2170 * Pointer to pass the mtr ops.
2176 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2178 *(const void **)ops = &mrvl_mtr_ops;
2184 * DPDK callback to get rte_tm callbacks.
2187 * Pointer to the device structure.
2189 * Pointer to pass the tm ops.
2195 mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2197 *(const void **)ops = &mrvl_tm_ops;
2202 static const struct eth_dev_ops mrvl_ops = {
2203 .dev_configure = mrvl_dev_configure,
2204 .dev_start = mrvl_dev_start,
2205 .dev_stop = mrvl_dev_stop,
2206 .dev_set_link_up = mrvl_dev_set_link_up,
2207 .dev_set_link_down = mrvl_dev_set_link_down,
2208 .dev_close = mrvl_dev_close,
2209 .link_update = mrvl_link_update,
2210 .promiscuous_enable = mrvl_promiscuous_enable,
2211 .allmulticast_enable = mrvl_allmulticast_enable,
2212 .promiscuous_disable = mrvl_promiscuous_disable,
2213 .allmulticast_disable = mrvl_allmulticast_disable,
2214 .mac_addr_remove = mrvl_mac_addr_remove,
2215 .mac_addr_add = mrvl_mac_addr_add,
2216 .mac_addr_set = mrvl_mac_addr_set,
2217 .mtu_set = mrvl_mtu_set,
2218 .stats_get = mrvl_stats_get,
2219 .stats_reset = mrvl_stats_reset,
2220 .xstats_get = mrvl_xstats_get,
2221 .xstats_reset = mrvl_xstats_reset,
2222 .xstats_get_names = mrvl_xstats_get_names,
2223 .dev_infos_get = mrvl_dev_infos_get,
2224 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
2225 .rxq_info_get = mrvl_rxq_info_get,
2226 .txq_info_get = mrvl_txq_info_get,
2227 .vlan_filter_set = mrvl_vlan_filter_set,
2228 .vlan_offload_set = mrvl_vlan_offload_set,
2229 .tx_queue_start = mrvl_tx_queue_start,
2230 .tx_queue_stop = mrvl_tx_queue_stop,
2231 .rx_queue_setup = mrvl_rx_queue_setup,
2232 .rx_queue_release = mrvl_rx_queue_release,
2233 .tx_queue_setup = mrvl_tx_queue_setup,
2234 .tx_queue_release = mrvl_tx_queue_release,
2235 .flow_ctrl_get = mrvl_flow_ctrl_get,
2236 .flow_ctrl_set = mrvl_flow_ctrl_set,
2237 .rss_hash_update = mrvl_rss_hash_update,
2238 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
2239 .filter_ctrl = mrvl_eth_filter_ctrl,
2240 .mtr_ops_get = mrvl_mtr_ops_get,
2241 .tm_ops_get = mrvl_tm_ops_get,
2245 * Return packet type information and l3/l4 offsets.
2248 * Pointer to the received packet descriptor.
2255 * Packet type information.
2257 static inline uint64_t
2258 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
2259 uint8_t *l3_offset, uint8_t *l4_offset)
2261 enum pp2_inq_l3_type l3_type;
2262 enum pp2_inq_l4_type l4_type;
2263 enum pp2_inq_vlan_tag vlan_tag;
2264 uint64_t packet_type;
2266 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
2267 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
2268 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag);
2270 packet_type = RTE_PTYPE_L2_ETHER;
2273 case PP2_INQ_VLAN_TAG_SINGLE:
2274 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
2276 case PP2_INQ_VLAN_TAG_DOUBLE:
2277 case PP2_INQ_VLAN_TAG_TRIPLE:
2278 packet_type |= RTE_PTYPE_L2_ETHER_QINQ;
2285 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
2286 packet_type |= RTE_PTYPE_L3_IPV4;
2288 case PP2_INQ_L3_TYPE_IPV4_OK:
2289 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
2291 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
2292 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
2294 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
2295 packet_type |= RTE_PTYPE_L3_IPV6;
2297 case PP2_INQ_L3_TYPE_IPV6_EXT:
2298 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
2300 case PP2_INQ_L3_TYPE_ARP:
2301 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
2303 * In case of ARP l4_offset is set to wrong value.
2304 * Set it to proper one so that later on mbuf->l3_len can be
2305 * calculated subtracting l4_offset and l3_offset.
2307 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
2314 case PP2_INQ_L4_TYPE_TCP:
2315 packet_type |= RTE_PTYPE_L4_TCP;
2317 case PP2_INQ_L4_TYPE_UDP:
2318 packet_type |= RTE_PTYPE_L4_UDP;
2328 * Get offload information from the received packet descriptor.
2331 * Pointer to the received packet descriptor.
2334 * Mbuf offload flags.
2336 static inline uint64_t
2337 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
2340 enum pp2_inq_desc_status status;
2342 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
2343 if (unlikely(status != PP2_DESC_ERR_OK))
2344 flags = PKT_RX_IP_CKSUM_BAD;
2346 flags = PKT_RX_IP_CKSUM_GOOD;
2348 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
2349 if (unlikely(status != PP2_DESC_ERR_OK))
2350 flags |= PKT_RX_L4_CKSUM_BAD;
2352 flags |= PKT_RX_L4_CKSUM_GOOD;
2358 * DPDK callback for receive.
2361 * Generic pointer to the receive queue.
2363 * Array to store received packets.
2365 * Maximum number of packets in array.
2368 * Number of packets successfully received.
2371 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2373 struct mrvl_rxq *q = rxq;
2374 struct pp2_ppio_desc descs[nb_pkts];
2375 struct pp2_bpool *bpool;
2376 int i, ret, rx_done = 0;
2378 struct pp2_hif *hif;
2379 unsigned int core_id = rte_lcore_id();
2381 hif = mrvl_get_hif(q->priv, core_id);
2383 if (unlikely(!q->priv->ppio || !hif))
2386 bpool = q->priv->bpool;
2388 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
2389 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
2390 if (unlikely(ret < 0))
2393 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
2395 for (i = 0; i < nb_pkts; i++) {
2396 struct rte_mbuf *mbuf;
2397 uint8_t l3_offset, l4_offset;
2398 enum pp2_inq_desc_status status;
2401 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2402 struct pp2_ppio_desc *pref_desc;
2405 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
2406 pref_addr = cookie_addr_high |
2407 pp2_ppio_inq_desc_get_cookie(pref_desc);
2408 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
2409 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
2412 addr = cookie_addr_high |
2413 pp2_ppio_inq_desc_get_cookie(&descs[i]);
2414 mbuf = (struct rte_mbuf *)addr;
2415 rte_pktmbuf_reset(mbuf);
2417 /* drop packet in case of mac, overrun or resource error */
2418 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
2419 if (unlikely(status != PP2_DESC_ERR_OK)) {
2420 struct pp2_buff_inf binf = {
2421 .addr = rte_mbuf_data_iova_default(mbuf),
2422 .cookie = (uint64_t)mbuf,
2425 pp2_bpool_put_buff(hif, bpool, &binf);
2426 mrvl_port_bpool_size
2427 [bpool->pp2_id][bpool->id][core_id]++;
2432 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
2433 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
2434 mbuf->data_len = mbuf->pkt_len;
2435 mbuf->port = q->port_id;
2437 mrvl_desc_to_packet_type_and_offset(&descs[i],
2440 mbuf->l2_len = l3_offset;
2441 mbuf->l3_len = l4_offset - l3_offset;
2443 if (likely(q->cksum_enabled))
2444 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
2446 rx_pkts[rx_done++] = mbuf;
2447 q->bytes_recv += mbuf->pkt_len;
2450 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
2451 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
2453 if (unlikely(num <= q->priv->bpool_min_size ||
2454 (!rx_done && num < q->priv->bpool_init_size))) {
2455 mrvl_fill_bpool(q, MRVL_BURST_SIZE);
2456 } else if (unlikely(num > q->priv->bpool_max_size)) {
2458 int pkt_to_remove = num - q->priv->bpool_init_size;
2459 struct rte_mbuf *mbuf;
2460 struct pp2_buff_inf buff;
2462 for (i = 0; i < pkt_to_remove; i++) {
2463 ret = pp2_bpool_get_buff(hif, bpool, &buff);
2466 mbuf = (struct rte_mbuf *)
2467 (cookie_addr_high | buff.cookie);
2468 rte_pktmbuf_free(mbuf);
2470 mrvl_port_bpool_size
2471 [bpool->pp2_id][bpool->id][core_id] -= i;
2473 rte_spinlock_unlock(&q->priv->lock);
2480 * Prepare offload information.
2484 * @param packet_type
2485 * Packet type bitfield.
2487 * Pointer to the pp2_ouq_l3_type structure.
2489 * Pointer to the pp2_outq_l4_type structure.
2490 * @param gen_l3_cksum
2491 * Will be set to 1 in case l3 checksum is computed.
2493 * Will be set to 1 in case l4 checksum is computed.
2496 * 0 on success, negative error value otherwise.
2499 mrvl_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
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
2510 if (ol_flags & PKT_TX_IPV4) {
2511 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
2512 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
2513 } else if (ol_flags & PKT_TX_IPV6) {
2514 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
2515 /* no checksum for ipv6 header */
2518 /* if something different then stop processing */
2522 ol_flags &= PKT_TX_L4_MASK;
2523 if ((packet_type & RTE_PTYPE_L4_TCP) &&
2524 ol_flags == PKT_TX_TCP_CKSUM) {
2525 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
2527 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
2528 ol_flags == PKT_TX_UDP_CKSUM) {
2529 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
2532 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
2533 /* no checksum for other type */
2541 * Release already sent buffers to bpool (buffer-pool).
2544 * Pointer to the port structure.
2546 * Pointer to the MUSDK hardware interface.
2548 * Pointer to the shadow queue.
2552 * Force releasing packets.
2555 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2556 unsigned int core_id, struct mrvl_shadow_txq *sq,
2559 struct buff_release_entry *entry;
2560 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2563 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2565 sq->num_to_release += nb_done;
2567 if (likely(!force &&
2568 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2571 nb_done = sq->num_to_release;
2572 sq->num_to_release = 0;
2574 for (i = 0; i < nb_done; i++) {
2575 entry = &sq->ent[sq->tail + num];
2576 if (unlikely(!entry->buff.addr)) {
2578 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
2579 sq->tail, (u64)entry->buff.cookie,
2580 (u64)entry->buff.addr);
2585 if (unlikely(!entry->bpool)) {
2586 struct rte_mbuf *mbuf;
2588 mbuf = (struct rte_mbuf *)entry->buff.cookie;
2589 rte_pktmbuf_free(mbuf);
2594 mrvl_port_bpool_size
2595 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2597 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2602 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2604 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2611 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2612 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2618 * DPDK callback for transmit.
2621 * Generic pointer transmit queue.
2623 * Packets to transmit.
2625 * Number of packets in array.
2628 * Number of packets successfully transmitted.
2631 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2633 struct mrvl_txq *q = txq;
2634 struct mrvl_shadow_txq *sq;
2635 struct pp2_hif *hif;
2636 struct pp2_ppio_desc descs[nb_pkts];
2637 unsigned int core_id = rte_lcore_id();
2638 int i, ret, bytes_sent = 0;
2639 uint16_t num, sq_free_size;
2642 hif = mrvl_get_hif(q->priv, core_id);
2643 sq = &q->shadow_txqs[core_id];
2645 if (unlikely(!q->priv->ppio || !hif))
2649 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2650 sq, q->queue_id, 0);
2652 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2653 if (unlikely(nb_pkts > sq_free_size))
2654 nb_pkts = sq_free_size;
2656 for (i = 0; i < nb_pkts; i++) {
2657 struct rte_mbuf *mbuf = tx_pkts[i];
2658 int gen_l3_cksum, gen_l4_cksum;
2659 enum pp2_outq_l3_type l3_type;
2660 enum pp2_outq_l4_type l4_type;
2662 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2663 struct rte_mbuf *pref_pkt_hdr;
2665 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2666 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2667 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2670 mrvl_fill_shadowq(sq, mbuf);
2671 mrvl_fill_desc(&descs[i], mbuf);
2673 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2675 * in case unsupported ol_flags were passed
2676 * do not update descriptor offload information
2678 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2679 &l3_type, &l4_type, &gen_l3_cksum,
2684 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2686 mbuf->l2_len + mbuf->l3_len,
2687 gen_l3_cksum, gen_l4_cksum);
2691 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2692 /* number of packets that were not sent */
2693 if (unlikely(num > nb_pkts)) {
2694 for (i = nb_pkts; i < num; i++) {
2695 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2696 MRVL_PP2_TX_SHADOWQ_MASK;
2697 addr = sq->ent[sq->head].buff.cookie;
2699 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2701 sq->size -= num - nb_pkts;
2704 q->bytes_sent += bytes_sent;
2709 /** DPDK callback for S/G transmit.
2712 * Generic pointer transmit queue.
2714 * Packets to transmit.
2716 * Number of packets in array.
2719 * Number of packets successfully transmitted.
2722 mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
2725 struct mrvl_txq *q = txq;
2726 struct mrvl_shadow_txq *sq;
2727 struct pp2_hif *hif;
2728 struct pp2_ppio_desc descs[nb_pkts * PP2_PPIO_DESC_NUM_FRAGS];
2729 struct pp2_ppio_sg_pkts pkts;
2730 uint8_t frags[nb_pkts];
2731 unsigned int core_id = rte_lcore_id();
2732 int i, j, ret, bytes_sent = 0;
2733 int tail, tail_first;
2734 uint16_t num, sq_free_size;
2735 uint16_t nb_segs, total_descs = 0;
2738 hif = mrvl_get_hif(q->priv, core_id);
2739 sq = &q->shadow_txqs[core_id];
2743 if (unlikely(!q->priv->ppio || !hif))
2747 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2748 sq, q->queue_id, 0);
2750 /* Save shadow queue free size */
2751 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2754 for (i = 0; i < nb_pkts; i++) {
2755 struct rte_mbuf *mbuf = tx_pkts[i];
2756 struct rte_mbuf *seg = NULL;
2757 int gen_l3_cksum, gen_l4_cksum;
2758 enum pp2_outq_l3_type l3_type;
2759 enum pp2_outq_l4_type l4_type;
2761 nb_segs = mbuf->nb_segs;
2763 total_descs += nb_segs;
2766 * Check if total_descs does not exceed
2767 * shadow queue free size
2769 if (unlikely(total_descs > sq_free_size)) {
2770 total_descs -= nb_segs;
2774 /* Check if nb_segs does not exceed the max nb of desc per
2777 if (nb_segs > PP2_PPIO_DESC_NUM_FRAGS) {
2778 total_descs -= nb_segs;
2780 "Too many segments. Packet won't be sent.\n");
2784 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2785 struct rte_mbuf *pref_pkt_hdr;
2787 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2788 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2789 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2792 pkts.frags[pkts.num] = nb_segs;
2796 for (j = 0; j < nb_segs - 1; j++) {
2797 /* For the subsequent segments, set shadow queue
2800 mrvl_fill_shadowq(sq, NULL);
2801 mrvl_fill_desc(&descs[tail], seg);
2806 /* Put first mbuf info in last shadow queue entry */
2807 mrvl_fill_shadowq(sq, mbuf);
2808 /* Update descriptor with last segment */
2809 mrvl_fill_desc(&descs[tail++], seg);
2811 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2812 /* In case unsupported ol_flags were passed
2813 * do not update descriptor offload information
2815 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2816 &l3_type, &l4_type, &gen_l3_cksum,
2821 pp2_ppio_outq_desc_set_proto_info(&descs[tail_first], l3_type,
2822 l4_type, mbuf->l2_len,
2823 mbuf->l2_len + mbuf->l3_len,
2824 gen_l3_cksum, gen_l4_cksum);
2828 pp2_ppio_send_sg(q->priv->ppio, hif, q->queue_id, descs,
2829 &total_descs, &pkts);
2830 /* number of packets that were not sent */
2831 if (unlikely(num > total_descs)) {
2832 for (i = total_descs; i < num; i++) {
2833 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2834 MRVL_PP2_TX_SHADOWQ_MASK;
2836 addr = sq->ent[sq->head].buff.cookie;
2839 rte_pktmbuf_pkt_len((struct rte_mbuf *)
2840 (cookie_addr_high | addr));
2842 sq->size -= num - total_descs;
2846 q->bytes_sent += bytes_sent;
2852 * Initialize packet processor.
2855 * 0 on success, negative error value otherwise.
2860 struct pp2_init_params init_params;
2862 memset(&init_params, 0, sizeof(init_params));
2863 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2864 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2865 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2867 return pp2_init(&init_params);
2871 * Deinitialize packet processor.
2874 * 0 on success, negative error value otherwise.
2877 mrvl_deinit_pp2(void)
2883 * Create private device structure.
2886 * Pointer to the port name passed in the initialization parameters.
2889 * Pointer to the newly allocated private device structure.
2891 static struct mrvl_priv *
2892 mrvl_priv_create(const char *dev_name)
2894 struct pp2_bpool_params bpool_params;
2895 char match[MRVL_MATCH_LEN];
2896 struct mrvl_priv *priv;
2899 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2903 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2904 &priv->pp_id, &priv->ppio_id);
2908 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2909 PP2_BPOOL_NUM_POOLS);
2912 priv->bpool_bit = bpool_bit;
2914 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2916 memset(&bpool_params, 0, sizeof(bpool_params));
2917 bpool_params.match = match;
2918 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2919 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2921 goto out_clear_bpool_bit;
2923 priv->ppio_params.type = PP2_PPIO_T_NIC;
2924 rte_spinlock_init(&priv->lock);
2927 out_clear_bpool_bit:
2928 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2935 * Create device representing Ethernet port.
2938 * Pointer to the port's name.
2941 * 0 on success, negative error value otherwise.
2944 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2946 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2947 struct rte_eth_dev *eth_dev;
2948 struct mrvl_priv *priv;
2951 eth_dev = rte_eth_dev_allocate(name);
2955 priv = mrvl_priv_create(name);
2960 eth_dev->data->dev_private = priv;
2962 eth_dev->data->mac_addrs =
2963 rte_zmalloc("mac_addrs",
2964 RTE_ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2965 if (!eth_dev->data->mac_addrs) {
2966 MRVL_LOG(ERR, "Failed to allocate space for eth addrs");
2971 memset(&req, 0, sizeof(req));
2972 strcpy(req.ifr_name, name);
2973 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2977 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2978 req.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN);
2980 eth_dev->device = &vdev->device;
2981 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2982 mrvl_set_tx_function(eth_dev);
2983 eth_dev->dev_ops = &mrvl_ops;
2984 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2986 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
2988 rte_eth_dev_probing_finish(eth_dev);
2991 rte_eth_dev_release_port(eth_dev);
2997 * Callback used by rte_kvargs_process() during argument parsing.
3000 * Pointer to the parsed key (unused).
3002 * Pointer to the parsed value.
3004 * Pointer to the extra arguments which contains address of the
3005 * table of pointers to parsed interface names.
3011 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
3014 struct mrvl_ifnames *ifnames = extra_args;
3016 ifnames->names[ifnames->idx++] = value;
3022 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
3025 mrvl_deinit_hifs(void)
3029 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
3031 pp2_hif_deinit(hifs[i]);
3033 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
3034 memset(hifs, 0, sizeof(hifs));
3038 * DPDK callback to register the virtual device.
3041 * Pointer to the virtual device.
3044 * 0 on success, negative error value otherwise.
3047 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
3049 struct rte_kvargs *kvlist;
3050 struct mrvl_ifnames ifnames;
3052 uint32_t i, ifnum, cfgnum;
3055 params = rte_vdev_device_args(vdev);
3059 kvlist = rte_kvargs_parse(params, valid_args);
3063 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
3064 if (ifnum > RTE_DIM(ifnames.names))
3065 goto out_free_kvlist;
3068 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
3069 mrvl_get_ifnames, &ifnames);
3073 * The below system initialization should be done only once,
3074 * on the first provided configuration file
3076 if (!mrvl_qos_cfg) {
3077 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
3078 MRVL_LOG(INFO, "Parsing config file!");
3080 MRVL_LOG(ERR, "Cannot handle more than one config file!");
3081 goto out_free_kvlist;
3082 } else if (cfgnum == 1) {
3083 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
3084 mrvl_get_qoscfg, &mrvl_qos_cfg);
3091 MRVL_LOG(INFO, "Perform MUSDK initializations");
3093 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist);
3095 goto out_free_kvlist;
3097 ret = mrvl_init_pp2();
3099 MRVL_LOG(ERR, "Failed to init PP!");
3100 rte_mvep_deinit(MVEP_MOD_T_PP2);
3101 goto out_free_kvlist;
3104 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
3105 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
3107 mrvl_lcore_first = RTE_MAX_LCORE;
3108 mrvl_lcore_last = 0;
3111 for (i = 0; i < ifnum; i++) {
3112 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]);
3113 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
3119 rte_kvargs_free(kvlist);
3123 rte_pmd_mrvl_remove(vdev);
3126 rte_kvargs_free(kvlist);
3132 * DPDK callback to remove virtual device.
3135 * Pointer to the removed virtual device.
3138 * 0 on success, negative error value otherwise.
3141 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
3146 RTE_ETH_FOREACH_DEV(port_id) {
3147 if (rte_eth_devices[port_id].device != &vdev->device)
3149 ret |= rte_eth_dev_close(port_id);
3152 return ret == 0 ? 0 : -EIO;
3155 static struct rte_vdev_driver pmd_mrvl_drv = {
3156 .probe = rte_pmd_mrvl_probe,
3157 .remove = rte_pmd_mrvl_remove,
3160 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv);
3161 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2);
3162 RTE_LOG_REGISTER(mrvl_logtype, pmd.net.mvpp2, NOTICE);