1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Marvell International Ltd.
3 * Copyright(c) 2017 Semihalf.
7 #include <rte_ethdev_driver.h>
8 #include <rte_kvargs.h>
10 #include <rte_malloc.h>
11 #include <rte_bus_vdev.h>
14 #include <linux/ethtool.h>
15 #include <linux/sockios.h>
17 #include <net/if_arp.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
21 #include <sys/types.h>
23 #include <rte_mvep_common.h>
24 #include "mrvl_ethdev.h"
28 /* bitmask with reserved hifs */
29 #define MRVL_MUSDK_HIFS_RESERVED 0x0F
30 /* bitmask with reserved bpools */
31 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07
32 /* bitmask with reserved kernel RSS tables */
33 #define MRVL_MUSDK_RSS_RESERVED 0x01
34 /* maximum number of available hifs */
35 #define MRVL_MUSDK_HIFS_MAX 9
38 #define MRVL_MUSDK_PREFETCH_SHIFT 2
40 /* TCAM has 25 entries reserved for uc/mc filter entries */
41 #define MRVL_MAC_ADDRS_MAX 25
42 #define MRVL_MATCH_LEN 16
43 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
44 /* Maximum allowable packet size */
45 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
47 #define MRVL_IFACE_NAME_ARG "iface"
48 #define MRVL_CFG_ARG "cfg"
50 #define MRVL_BURST_SIZE 64
52 #define MRVL_ARP_LENGTH 28
54 #define MRVL_COOKIE_ADDR_INVALID ~0ULL
56 #define MRVL_COOKIE_HIGH_ADDR_SHIFT (sizeof(pp2_cookie_t) * 8)
57 #define MRVL_COOKIE_HIGH_ADDR_MASK (~0ULL << MRVL_COOKIE_HIGH_ADDR_SHIFT)
59 /** Port Rx offload capabilities */
60 #define MRVL_RX_OFFLOADS (DEV_RX_OFFLOAD_VLAN_FILTER | \
61 DEV_RX_OFFLOAD_JUMBO_FRAME | \
62 DEV_RX_OFFLOAD_CHECKSUM)
64 /** Port Tx offloads capabilities */
65 #define MRVL_TX_OFFLOADS (DEV_TX_OFFLOAD_IPV4_CKSUM | \
66 DEV_TX_OFFLOAD_UDP_CKSUM | \
67 DEV_TX_OFFLOAD_TCP_CKSUM)
69 static const char * const valid_args[] = {
75 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
76 static struct pp2_hif *hifs[RTE_MAX_LCORE];
77 static int used_bpools[PP2_NUM_PKT_PROC] = {
78 [0 ... PP2_NUM_PKT_PROC - 1] = MRVL_MUSDK_BPOOLS_RESERVED
81 static struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
82 static int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
83 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 buffers sent, that can be released */
108 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
112 struct mrvl_priv *priv;
113 struct rte_mempool *mp;
122 struct mrvl_priv *priv;
126 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
127 int tx_deferred_start;
130 static int mrvl_lcore_first;
131 static int mrvl_lcore_last;
132 static int mrvl_dev_num;
134 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
135 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
136 struct pp2_hif *hif, unsigned int core_id,
137 struct mrvl_shadow_txq *sq, int qid, int force);
139 #define MRVL_XSTATS_TBL_ENTRY(name) { \
140 #name, offsetof(struct pp2_ppio_statistics, name), \
141 sizeof(((struct pp2_ppio_statistics *)0)->name) \
144 /* Table with xstats data */
149 } mrvl_xstats_tbl[] = {
150 MRVL_XSTATS_TBL_ENTRY(rx_bytes),
151 MRVL_XSTATS_TBL_ENTRY(rx_packets),
152 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets),
153 MRVL_XSTATS_TBL_ENTRY(rx_errors),
154 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped),
155 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped),
156 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped),
157 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped),
158 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped),
159 MRVL_XSTATS_TBL_ENTRY(tx_bytes),
160 MRVL_XSTATS_TBL_ENTRY(tx_packets),
161 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets),
162 MRVL_XSTATS_TBL_ENTRY(tx_errors)
166 mrvl_get_bpool_size(int pp2_id, int pool_id)
171 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
172 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
178 mrvl_reserve_bit(int *bitmap, int max)
180 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
191 mrvl_init_hif(int core_id)
193 struct pp2_hif_params params;
194 char match[MRVL_MATCH_LEN];
197 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
199 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
203 snprintf(match, sizeof(match), "hif-%d", ret);
204 memset(¶ms, 0, sizeof(params));
205 params.match = match;
206 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
207 ret = pp2_hif_init(¶ms, &hifs[core_id]);
209 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id);
216 static inline struct pp2_hif*
217 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
221 if (likely(hifs[core_id] != NULL))
222 return hifs[core_id];
224 rte_spinlock_lock(&priv->lock);
226 ret = mrvl_init_hif(core_id);
228 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id);
232 if (core_id < mrvl_lcore_first)
233 mrvl_lcore_first = core_id;
235 if (core_id > mrvl_lcore_last)
236 mrvl_lcore_last = core_id;
238 rte_spinlock_unlock(&priv->lock);
240 return hifs[core_id];
244 * Configure rss based on dpdk rss configuration.
247 * Pointer to private structure.
249 * Pointer to RSS configuration.
252 * 0 on success, negative error value otherwise.
255 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
257 if (rss_conf->rss_key)
258 MRVL_LOG(WARNING, "Changing hash key is not supported");
260 if (rss_conf->rss_hf == 0) {
261 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
262 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
263 priv->ppio_params.inqs_params.hash_type =
264 PP2_PPIO_HASH_T_2_TUPLE;
265 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
266 priv->ppio_params.inqs_params.hash_type =
267 PP2_PPIO_HASH_T_5_TUPLE;
268 priv->rss_hf_tcp = 1;
269 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
270 priv->ppio_params.inqs_params.hash_type =
271 PP2_PPIO_HASH_T_5_TUPLE;
272 priv->rss_hf_tcp = 0;
281 * Ethernet device configuration.
283 * Prepare the driver for a given number of TX and RX queues and
287 * Pointer to Ethernet device structure.
290 * 0 on success, negative error value otherwise.
293 mrvl_dev_configure(struct rte_eth_dev *dev)
295 struct mrvl_priv *priv = dev->data->dev_private;
299 MRVL_LOG(INFO, "Device reconfiguration is not supported");
303 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
304 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
305 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d",
306 dev->data->dev_conf.rxmode.mq_mode);
310 if (dev->data->dev_conf.rxmode.split_hdr_size) {
311 MRVL_LOG(INFO, "Split headers not supported");
315 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
316 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
317 ETHER_HDR_LEN - ETHER_CRC_LEN;
319 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
320 dev->data->nb_rx_queues);
324 ret = mrvl_configure_txqs(priv, dev->data->port_id,
325 dev->data->nb_tx_queues);
329 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
330 priv->ppio_params.maintain_stats = 1;
331 priv->nb_rx_queues = dev->data->nb_rx_queues;
333 if (dev->data->nb_rx_queues == 1 &&
334 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
335 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue");
336 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
341 return mrvl_configure_rss(priv,
342 &dev->data->dev_conf.rx_adv_conf.rss_conf);
346 * DPDK callback to change the MTU.
348 * Setting the MTU affects hardware MRU (packets larger than the MRU
352 * Pointer to Ethernet device structure.
357 * 0 on success, negative error value otherwise.
360 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
362 struct mrvl_priv *priv = dev->data->dev_private;
363 /* extra MV_MH_SIZE bytes are required for Marvell tag */
364 uint16_t mru = mtu + MV_MH_SIZE + ETHER_HDR_LEN + ETHER_CRC_LEN;
367 if (mtu < ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX)
373 ret = pp2_ppio_set_mru(priv->ppio, mru);
377 return pp2_ppio_set_mtu(priv->ppio, mtu);
381 * DPDK callback to bring the link up.
384 * Pointer to Ethernet device structure.
387 * 0 on success, negative error value otherwise.
390 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
392 struct mrvl_priv *priv = dev->data->dev_private;
398 ret = pp2_ppio_enable(priv->ppio);
403 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
404 * as pp2_ppio_enable() changes port->t_mode from default 0 to
405 * PP2_TRAFFIC_INGRESS_EGRESS.
407 * Set mtu to default DPDK value here.
409 ret = mrvl_mtu_set(dev, dev->data->mtu);
411 pp2_ppio_disable(priv->ppio);
417 * DPDK callback to bring the link down.
420 * Pointer to Ethernet device structure.
423 * 0 on success, negative error value otherwise.
426 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
428 struct mrvl_priv *priv = dev->data->dev_private;
433 return pp2_ppio_disable(priv->ppio);
437 * DPDK callback to start tx queue.
440 * Pointer to Ethernet device structure.
442 * Transmit queue index.
445 * 0 on success, negative error value otherwise.
448 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
450 struct mrvl_priv *priv = dev->data->dev_private;
456 /* passing 1 enables given tx queue */
457 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1);
459 MRVL_LOG(ERR, "Failed to start txq %d", queue_id);
463 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
469 * DPDK callback to stop tx queue.
472 * Pointer to Ethernet device structure.
474 * Transmit queue index.
477 * 0 on success, negative error value otherwise.
480 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
482 struct mrvl_priv *priv = dev->data->dev_private;
488 /* passing 0 disables given tx queue */
489 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0);
491 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id);
495 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
501 * DPDK callback to start the device.
504 * Pointer to Ethernet device structure.
507 * 0 on success, negative errno value on failure.
510 mrvl_dev_start(struct rte_eth_dev *dev)
512 struct mrvl_priv *priv = dev->data->dev_private;
513 char match[MRVL_MATCH_LEN];
514 int ret = 0, i, def_init_size;
517 return mrvl_dev_set_link_up(dev);
519 snprintf(match, sizeof(match), "ppio-%d:%d",
520 priv->pp_id, priv->ppio_id);
521 priv->ppio_params.match = match;
524 * Calculate the minimum bpool size for refill feature as follows:
525 * 2 default burst sizes multiply by number of rx queues.
526 * If the bpool size will be below this value, new buffers will
527 * be added to the pool.
529 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
531 /* In case initial bpool size configured in queues setup is
532 * smaller than minimum size add more buffers
534 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
535 if (priv->bpool_init_size < def_init_size) {
536 int buffs_to_add = def_init_size - priv->bpool_init_size;
538 priv->bpool_init_size += buffs_to_add;
539 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
541 MRVL_LOG(ERR, "Failed to add buffers to bpool");
545 * Calculate the maximum bpool size for refill feature as follows:
546 * maximum number of descriptors in rx queue multiply by number
547 * of rx queues plus minimum bpool size.
548 * In case the bpool size will exceed this value, superfluous buffers
551 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
552 priv->bpool_min_size;
554 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
556 MRVL_LOG(ERR, "Failed to init ppio");
561 * In case there are some some stale uc/mc mac addresses flush them
562 * here. It cannot be done during mrvl_dev_close() as port information
563 * is already gone at that point (due to pp2_ppio_deinit() in
566 if (!priv->uc_mc_flushed) {
567 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
570 "Failed to flush uc/mc filter list");
573 priv->uc_mc_flushed = 1;
576 if (!priv->vlan_flushed) {
577 ret = pp2_ppio_flush_vlan(priv->ppio);
579 MRVL_LOG(ERR, "Failed to flush vlan list");
582 * once pp2_ppio_flush_vlan() is supported jump to out
586 priv->vlan_flushed = 1;
589 /* For default QoS config, don't start classifier. */
591 ret = mrvl_start_qos_mapping(priv);
593 MRVL_LOG(ERR, "Failed to setup QoS mapping");
598 ret = mrvl_dev_set_link_up(dev);
600 MRVL_LOG(ERR, "Failed to set link up");
604 /* start tx queues */
605 for (i = 0; i < dev->data->nb_tx_queues; i++) {
606 struct mrvl_txq *txq = dev->data->tx_queues[i];
608 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
610 if (!txq->tx_deferred_start)
614 * All txqs are started by default. Stop them
615 * so that tx_deferred_start works as expected.
617 ret = mrvl_tx_queue_stop(dev, i);
626 MRVL_LOG(ERR, "Failed to start device");
627 pp2_ppio_deinit(priv->ppio);
632 * Flush receive queues.
635 * Pointer to Ethernet device structure.
638 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
642 MRVL_LOG(INFO, "Flushing rx queues");
643 for (i = 0; i < dev->data->nb_rx_queues; i++) {
647 struct mrvl_rxq *q = dev->data->rx_queues[i];
648 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
650 num = MRVL_PP2_RXD_MAX;
651 ret = pp2_ppio_recv(q->priv->ppio,
652 q->priv->rxq_map[q->queue_id].tc,
653 q->priv->rxq_map[q->queue_id].inq,
654 descs, (uint16_t *)&num);
655 } while (ret == 0 && num);
660 * Flush transmit shadow queues.
663 * Pointer to Ethernet device structure.
666 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
669 struct mrvl_txq *txq;
671 MRVL_LOG(INFO, "Flushing tx shadow queues");
672 for (i = 0; i < dev->data->nb_tx_queues; i++) {
673 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
675 for (j = 0; j < RTE_MAX_LCORE; j++) {
676 struct mrvl_shadow_txq *sq;
681 sq = &txq->shadow_txqs[j];
682 mrvl_free_sent_buffers(txq->priv->ppio,
683 hifs[j], j, sq, txq->queue_id, 1);
684 while (sq->tail != sq->head) {
685 uint64_t addr = cookie_addr_high |
686 sq->ent[sq->tail].buff.cookie;
688 (struct rte_mbuf *)addr);
689 sq->tail = (sq->tail + 1) &
690 MRVL_PP2_TX_SHADOWQ_MASK;
692 memset(sq, 0, sizeof(*sq));
698 * Flush hardware bpool (buffer-pool).
701 * Pointer to Ethernet device structure.
704 mrvl_flush_bpool(struct rte_eth_dev *dev)
706 struct mrvl_priv *priv = dev->data->dev_private;
710 unsigned int core_id = rte_lcore_id();
712 if (core_id == LCORE_ID_ANY)
715 hif = mrvl_get_hif(priv, core_id);
717 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
719 MRVL_LOG(ERR, "Failed to get bpool buffers number");
724 struct pp2_buff_inf inf;
727 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
731 addr = cookie_addr_high | inf.cookie;
732 rte_pktmbuf_free((struct rte_mbuf *)addr);
737 * DPDK callback to stop the device.
740 * Pointer to Ethernet device structure.
743 mrvl_dev_stop(struct rte_eth_dev *dev)
745 mrvl_dev_set_link_down(dev);
749 * DPDK callback to close the device.
752 * Pointer to Ethernet device structure.
755 mrvl_dev_close(struct rte_eth_dev *dev)
757 struct mrvl_priv *priv = dev->data->dev_private;
760 mrvl_flush_rx_queues(dev);
761 mrvl_flush_tx_shadow_queues(dev);
762 mrvl_mtr_deinit(dev);
764 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
765 struct pp2_ppio_tc_params *tc_params =
766 &priv->ppio_params.inqs_params.tcs_params[i];
768 if (tc_params->inqs_params) {
769 rte_free(tc_params->inqs_params);
770 tc_params->inqs_params = NULL;
775 pp2_cls_tbl_deinit(priv->cls_tbl);
776 priv->cls_tbl = NULL;
780 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
781 priv->qos_tbl = NULL;
784 mrvl_flush_bpool(dev);
787 pp2_ppio_deinit(priv->ppio);
791 /* policer must be released after ppio deinitialization */
792 if (priv->default_policer) {
793 pp2_cls_plcr_deinit(priv->default_policer);
794 priv->default_policer = NULL;
799 * DPDK callback to retrieve physical link information.
802 * Pointer to Ethernet device structure.
803 * @param wait_to_complete
804 * Wait for request completion (ignored).
807 * 0 on success, negative error value otherwise.
810 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
814 * once MUSDK provides necessary API use it here
816 struct mrvl_priv *priv = dev->data->dev_private;
817 struct ethtool_cmd edata;
819 int ret, fd, link_up;
824 edata.cmd = ETHTOOL_GSET;
826 strcpy(req.ifr_name, dev->data->name);
827 req.ifr_data = (void *)&edata;
829 fd = socket(AF_INET, SOCK_DGRAM, 0);
833 ret = ioctl(fd, SIOCETHTOOL, &req);
841 switch (ethtool_cmd_speed(&edata)) {
843 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
846 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
849 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
852 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
855 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
858 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
859 ETH_LINK_HALF_DUPLEX;
860 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
862 pp2_ppio_get_link_state(priv->ppio, &link_up);
863 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
869 * DPDK callback to enable promiscuous mode.
872 * Pointer to Ethernet device structure.
875 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
877 struct mrvl_priv *priv = dev->data->dev_private;
886 ret = pp2_ppio_set_promisc(priv->ppio, 1);
888 MRVL_LOG(ERR, "Failed to enable promiscuous mode");
892 * DPDK callback to enable allmulti mode.
895 * Pointer to Ethernet device structure.
898 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
900 struct mrvl_priv *priv = dev->data->dev_private;
909 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
911 MRVL_LOG(ERR, "Failed enable all-multicast mode");
915 * DPDK callback to disable promiscuous mode.
918 * Pointer to Ethernet device structure.
921 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
923 struct mrvl_priv *priv = dev->data->dev_private;
929 ret = pp2_ppio_set_promisc(priv->ppio, 0);
931 MRVL_LOG(ERR, "Failed to disable promiscuous mode");
935 * DPDK callback to disable allmulticast mode.
938 * Pointer to Ethernet device structure.
941 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
943 struct mrvl_priv *priv = dev->data->dev_private;
949 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
951 MRVL_LOG(ERR, "Failed to disable all-multicast mode");
955 * DPDK callback to remove a MAC address.
958 * Pointer to Ethernet device structure.
963 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
965 struct mrvl_priv *priv = dev->data->dev_private;
966 char buf[ETHER_ADDR_FMT_SIZE];
975 ret = pp2_ppio_remove_mac_addr(priv->ppio,
976 dev->data->mac_addrs[index].addr_bytes);
978 ether_format_addr(buf, sizeof(buf),
979 &dev->data->mac_addrs[index]);
980 MRVL_LOG(ERR, "Failed to remove mac %s", buf);
985 * DPDK callback to add a MAC address.
988 * Pointer to Ethernet device structure.
990 * MAC address to register.
994 * VMDq pool index to associate address with (unused).
997 * 0 on success, negative error value otherwise.
1000 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
1001 uint32_t index, uint32_t vmdq __rte_unused)
1003 struct mrvl_priv *priv = dev->data->dev_private;
1004 char buf[ETHER_ADDR_FMT_SIZE];
1011 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
1018 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
1019 * parameter uc_filter_max. Maximum number of mc addresses is then
1020 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
1023 * If more than uc_filter_max uc addresses were added to filter list
1024 * then NIC will switch to promiscuous mode automatically.
1026 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
1027 * were added to filter list then NIC will switch to all-multicast mode
1030 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
1032 ether_format_addr(buf, sizeof(buf), mac_addr);
1033 MRVL_LOG(ERR, "Failed to add mac %s", buf);
1041 * DPDK callback to set the primary MAC address.
1044 * Pointer to Ethernet device structure.
1046 * MAC address to register.
1049 * 0 on success, negative error value otherwise.
1052 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
1054 struct mrvl_priv *priv = dev->data->dev_private;
1063 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
1065 char buf[ETHER_ADDR_FMT_SIZE];
1066 ether_format_addr(buf, sizeof(buf), mac_addr);
1067 MRVL_LOG(ERR, "Failed to set mac to %s", buf);
1074 * DPDK callback to get device statistics.
1077 * Pointer to Ethernet device structure.
1079 * Stats structure output buffer.
1082 * 0 on success, negative error value otherwise.
1085 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1087 struct mrvl_priv *priv = dev->data->dev_private;
1088 struct pp2_ppio_statistics ppio_stats;
1089 uint64_t drop_mac = 0;
1090 unsigned int i, idx, ret;
1095 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1096 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1097 struct pp2_ppio_inq_statistics rx_stats;
1102 idx = rxq->queue_id;
1103 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1105 "rx queue %d stats out of range (0 - %d)",
1106 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1110 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1111 priv->rxq_map[idx].tc,
1112 priv->rxq_map[idx].inq,
1114 if (unlikely(ret)) {
1116 "Failed to update rx queue %d stats", idx);
1120 stats->q_ibytes[idx] = rxq->bytes_recv;
1121 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1122 stats->q_errors[idx] = rx_stats.drop_early +
1123 rx_stats.drop_fullq +
1126 stats->ibytes += rxq->bytes_recv;
1127 drop_mac += rxq->drop_mac;
1130 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1131 struct mrvl_txq *txq = dev->data->tx_queues[i];
1132 struct pp2_ppio_outq_statistics tx_stats;
1137 idx = txq->queue_id;
1138 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1140 "tx queue %d stats out of range (0 - %d)",
1141 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1144 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1146 if (unlikely(ret)) {
1148 "Failed to update tx queue %d stats", idx);
1152 stats->q_opackets[idx] = tx_stats.deq_desc;
1153 stats->q_obytes[idx] = txq->bytes_sent;
1154 stats->obytes += txq->bytes_sent;
1157 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1158 if (unlikely(ret)) {
1159 MRVL_LOG(ERR, "Failed to update port statistics");
1163 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1164 stats->opackets += ppio_stats.tx_packets;
1165 stats->imissed += ppio_stats.rx_fullq_dropped +
1166 ppio_stats.rx_bm_dropped +
1167 ppio_stats.rx_early_dropped +
1168 ppio_stats.rx_fifo_dropped +
1169 ppio_stats.rx_cls_dropped;
1170 stats->ierrors = drop_mac;
1176 * DPDK callback to clear device statistics.
1179 * Pointer to Ethernet device structure.
1182 mrvl_stats_reset(struct rte_eth_dev *dev)
1184 struct mrvl_priv *priv = dev->data->dev_private;
1190 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1191 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1193 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1194 priv->rxq_map[i].inq, NULL, 1);
1195 rxq->bytes_recv = 0;
1199 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1200 struct mrvl_txq *txq = dev->data->tx_queues[i];
1202 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1203 txq->bytes_sent = 0;
1206 pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1210 * DPDK callback to get extended statistics.
1213 * Pointer to Ethernet device structure.
1215 * Pointer to xstats table.
1217 * Number of entries in xstats table.
1219 * Negative value on error, number of read xstats otherwise.
1222 mrvl_xstats_get(struct rte_eth_dev *dev,
1223 struct rte_eth_xstat *stats, unsigned int n)
1225 struct mrvl_priv *priv = dev->data->dev_private;
1226 struct pp2_ppio_statistics ppio_stats;
1232 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1233 for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) {
1236 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t))
1237 val = *(uint32_t *)((uint8_t *)&ppio_stats +
1238 mrvl_xstats_tbl[i].offset);
1239 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t))
1240 val = *(uint64_t *)((uint8_t *)&ppio_stats +
1241 mrvl_xstats_tbl[i].offset);
1246 stats[i].value = val;
1253 * DPDK callback to reset extended statistics.
1256 * Pointer to Ethernet device structure.
1259 mrvl_xstats_reset(struct rte_eth_dev *dev)
1261 mrvl_stats_reset(dev);
1265 * DPDK callback to get extended statistics names.
1267 * @param dev (unused)
1268 * Pointer to Ethernet device structure.
1269 * @param xstats_names
1270 * Pointer to xstats names table.
1272 * Size of the xstats names table.
1274 * Number of read names.
1277 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1278 struct rte_eth_xstat_name *xstats_names,
1284 return RTE_DIM(mrvl_xstats_tbl);
1286 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
1287 snprintf(xstats_names[i].name, RTE_ETH_XSTATS_NAME_SIZE, "%s",
1288 mrvl_xstats_tbl[i].name);
1294 * DPDK callback to get information about the device.
1297 * Pointer to Ethernet device structure (unused).
1299 * Info structure output buffer.
1302 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1303 struct rte_eth_dev_info *info)
1305 info->speed_capa = ETH_LINK_SPEED_10M |
1306 ETH_LINK_SPEED_100M |
1310 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1311 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1312 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1314 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1315 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1316 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1318 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1319 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1320 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1322 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1323 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1325 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1326 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1328 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1329 ETH_RSS_NONFRAG_IPV4_TCP |
1330 ETH_RSS_NONFRAG_IPV4_UDP;
1332 /* By default packets are dropped if no descriptors are available */
1333 info->default_rxconf.rx_drop_en = 1;
1335 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1339 * Return supported packet types.
1342 * Pointer to Ethernet device structure (unused).
1345 * Const pointer to the table with supported packet types.
1347 static const uint32_t *
1348 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1350 static const uint32_t ptypes[] = {
1352 RTE_PTYPE_L2_ETHER_VLAN,
1353 RTE_PTYPE_L2_ETHER_QINQ,
1355 RTE_PTYPE_L3_IPV4_EXT,
1356 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1358 RTE_PTYPE_L3_IPV6_EXT,
1359 RTE_PTYPE_L2_ETHER_ARP,
1368 * DPDK callback to get information about specific receive queue.
1371 * Pointer to Ethernet device structure.
1372 * @param rx_queue_id
1373 * Receive queue index.
1375 * Receive queue information structure.
1377 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1378 struct rte_eth_rxq_info *qinfo)
1380 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1381 struct mrvl_priv *priv = dev->data->dev_private;
1382 int inq = priv->rxq_map[rx_queue_id].inq;
1383 int tc = priv->rxq_map[rx_queue_id].tc;
1384 struct pp2_ppio_tc_params *tc_params =
1385 &priv->ppio_params.inqs_params.tcs_params[tc];
1388 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1392 * DPDK callback to get information about specific transmit queue.
1395 * Pointer to Ethernet device structure.
1396 * @param tx_queue_id
1397 * Transmit queue index.
1399 * Transmit queue information structure.
1401 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1402 struct rte_eth_txq_info *qinfo)
1404 struct mrvl_priv *priv = dev->data->dev_private;
1405 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id];
1408 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1409 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1413 * DPDK callback to Configure a VLAN filter.
1416 * Pointer to Ethernet device structure.
1418 * VLAN ID to filter.
1423 * 0 on success, negative error value otherwise.
1426 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1428 struct mrvl_priv *priv = dev->data->dev_private;
1436 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1437 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1441 * Release buffers to hardware bpool (buffer-pool)
1444 * Receive queue pointer.
1446 * Number of buffers to release to bpool.
1449 * 0 on success, negative error value otherwise.
1452 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1454 struct buff_release_entry entries[MRVL_PP2_RXD_MAX];
1455 struct rte_mbuf *mbufs[MRVL_PP2_RXD_MAX];
1457 unsigned int core_id;
1458 struct pp2_hif *hif;
1459 struct pp2_bpool *bpool;
1461 core_id = rte_lcore_id();
1462 if (core_id == LCORE_ID_ANY)
1465 hif = mrvl_get_hif(rxq->priv, core_id);
1469 bpool = rxq->priv->bpool;
1471 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1475 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1477 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1479 for (i = 0; i < num; i++) {
1480 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1481 != cookie_addr_high) {
1483 "mbuf virtual addr high 0x%lx out of range",
1484 (uint64_t)mbufs[i] >> 32);
1488 entries[i].buff.addr =
1489 rte_mbuf_data_iova_default(mbufs[i]);
1490 entries[i].buff.cookie = (pp2_cookie_t)(uint64_t)mbufs[i];
1491 entries[i].bpool = bpool;
1494 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1495 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1502 for (; i < num; i++)
1503 rte_pktmbuf_free(mbufs[i]);
1509 * DPDK callback to configure the receive queue.
1512 * Pointer to Ethernet device structure.
1516 * Number of descriptors to configure in queue.
1518 * NUMA socket on which memory must be allocated.
1520 * Thresholds parameters.
1522 * Memory pool for buffer allocations.
1525 * 0 on success, negative error value otherwise.
1528 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1529 unsigned int socket,
1530 const struct rte_eth_rxconf *conf,
1531 struct rte_mempool *mp)
1533 struct mrvl_priv *priv = dev->data->dev_private;
1534 struct mrvl_rxq *rxq;
1536 max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1540 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1542 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1544 * Unknown TC mapping, mapping will not have a correct queue.
1546 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu",
1547 idx, priv->ppio_id);
1551 min_size = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM -
1552 MRVL_PKT_EFFEC_OFFS;
1553 if (min_size < max_rx_pkt_len) {
1555 "Mbuf size must be increased to %u bytes to hold up to %u bytes of data.",
1556 max_rx_pkt_len + RTE_PKTMBUF_HEADROOM +
1557 MRVL_PKT_EFFEC_OFFS,
1562 if (dev->data->rx_queues[idx]) {
1563 rte_free(dev->data->rx_queues[idx]);
1564 dev->data->rx_queues[idx] = NULL;
1567 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1573 rxq->cksum_enabled = offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
1574 rxq->queue_id = idx;
1575 rxq->port_id = dev->data->port_id;
1576 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1578 tc = priv->rxq_map[rxq->queue_id].tc,
1579 inq = priv->rxq_map[rxq->queue_id].inq;
1580 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1583 ret = mrvl_fill_bpool(rxq, desc);
1589 priv->bpool_init_size += desc;
1591 dev->data->rx_queues[idx] = rxq;
1597 * DPDK callback to release the receive queue.
1600 * Generic receive queue pointer.
1603 mrvl_rx_queue_release(void *rxq)
1605 struct mrvl_rxq *q = rxq;
1606 struct pp2_ppio_tc_params *tc_params;
1607 int i, num, tc, inq;
1608 struct pp2_hif *hif;
1609 unsigned int core_id = rte_lcore_id();
1611 if (core_id == LCORE_ID_ANY)
1617 hif = mrvl_get_hif(q->priv, core_id);
1622 tc = q->priv->rxq_map[q->queue_id].tc;
1623 inq = q->priv->rxq_map[q->queue_id].inq;
1624 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1625 num = tc_params->inqs_params[inq].size;
1626 for (i = 0; i < num; i++) {
1627 struct pp2_buff_inf inf;
1630 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1631 addr = cookie_addr_high | inf.cookie;
1632 rte_pktmbuf_free((struct rte_mbuf *)addr);
1639 * DPDK callback to configure the transmit queue.
1642 * Pointer to Ethernet device structure.
1644 * Transmit queue index.
1646 * Number of descriptors to configure in the queue.
1648 * NUMA socket on which memory must be allocated.
1650 * Tx queue configuration parameters.
1653 * 0 on success, negative error value otherwise.
1656 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1657 unsigned int socket,
1658 const struct rte_eth_txconf *conf)
1660 struct mrvl_priv *priv = dev->data->dev_private;
1661 struct mrvl_txq *txq;
1663 if (dev->data->tx_queues[idx]) {
1664 rte_free(dev->data->tx_queues[idx]);
1665 dev->data->tx_queues[idx] = NULL;
1668 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1673 txq->queue_id = idx;
1674 txq->port_id = dev->data->port_id;
1675 txq->tx_deferred_start = conf->tx_deferred_start;
1676 dev->data->tx_queues[idx] = txq;
1678 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1684 * DPDK callback to release the transmit queue.
1687 * Generic transmit queue pointer.
1690 mrvl_tx_queue_release(void *txq)
1692 struct mrvl_txq *q = txq;
1701 * DPDK callback to get flow control configuration.
1704 * Pointer to Ethernet device structure.
1706 * Pointer to the flow control configuration.
1709 * 0 on success, negative error value otherwise.
1712 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1714 struct mrvl_priv *priv = dev->data->dev_private;
1720 ret = pp2_ppio_get_rx_pause(priv->ppio, &en);
1722 MRVL_LOG(ERR, "Failed to read rx pause state");
1726 fc_conf->mode = en ? RTE_FC_RX_PAUSE : RTE_FC_NONE;
1732 * DPDK callback to set flow control configuration.
1735 * Pointer to Ethernet device structure.
1737 * Pointer to the flow control configuration.
1740 * 0 on success, negative error value otherwise.
1743 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1745 struct mrvl_priv *priv = dev->data->dev_private;
1750 if (fc_conf->high_water ||
1751 fc_conf->low_water ||
1752 fc_conf->pause_time ||
1753 fc_conf->mac_ctrl_frame_fwd ||
1755 MRVL_LOG(ERR, "Flowctrl parameter is not supported");
1760 if (fc_conf->mode == RTE_FC_NONE ||
1761 fc_conf->mode == RTE_FC_RX_PAUSE) {
1764 en = fc_conf->mode == RTE_FC_NONE ? 0 : 1;
1765 ret = pp2_ppio_set_rx_pause(priv->ppio, en);
1768 "Failed to change flowctrl on RX side");
1777 * Update RSS hash configuration
1780 * Pointer to Ethernet device structure.
1782 * Pointer to RSS configuration.
1785 * 0 on success, negative error value otherwise.
1788 mrvl_rss_hash_update(struct rte_eth_dev *dev,
1789 struct rte_eth_rss_conf *rss_conf)
1791 struct mrvl_priv *priv = dev->data->dev_private;
1796 return mrvl_configure_rss(priv, rss_conf);
1800 * DPDK callback to get RSS hash configuration.
1803 * Pointer to Ethernet device structure.
1805 * Pointer to RSS configuration.
1811 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
1812 struct rte_eth_rss_conf *rss_conf)
1814 struct mrvl_priv *priv = dev->data->dev_private;
1815 enum pp2_ppio_hash_type hash_type =
1816 priv->ppio_params.inqs_params.hash_type;
1818 rss_conf->rss_key = NULL;
1820 if (hash_type == PP2_PPIO_HASH_T_NONE)
1821 rss_conf->rss_hf = 0;
1822 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
1823 rss_conf->rss_hf = ETH_RSS_IPV4;
1824 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
1825 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
1826 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
1827 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
1833 * DPDK callback to get rte_flow callbacks.
1836 * Pointer to the device structure.
1840 * Flow filter operation.
1842 * Pointer to pass the flow ops.
1845 * 0 on success, negative error value otherwise.
1848 mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
1849 enum rte_filter_type filter_type,
1850 enum rte_filter_op filter_op, void *arg)
1852 switch (filter_type) {
1853 case RTE_ETH_FILTER_GENERIC:
1854 if (filter_op != RTE_ETH_FILTER_GET)
1856 *(const void **)arg = &mrvl_flow_ops;
1859 MRVL_LOG(WARNING, "Filter type (%d) not supported",
1866 * DPDK callback to get rte_mtr callbacks.
1869 * Pointer to the device structure.
1871 * Pointer to pass the mtr ops.
1877 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
1879 *(const void **)ops = &mrvl_mtr_ops;
1884 static const struct eth_dev_ops mrvl_ops = {
1885 .dev_configure = mrvl_dev_configure,
1886 .dev_start = mrvl_dev_start,
1887 .dev_stop = mrvl_dev_stop,
1888 .dev_set_link_up = mrvl_dev_set_link_up,
1889 .dev_set_link_down = mrvl_dev_set_link_down,
1890 .dev_close = mrvl_dev_close,
1891 .link_update = mrvl_link_update,
1892 .promiscuous_enable = mrvl_promiscuous_enable,
1893 .allmulticast_enable = mrvl_allmulticast_enable,
1894 .promiscuous_disable = mrvl_promiscuous_disable,
1895 .allmulticast_disable = mrvl_allmulticast_disable,
1896 .mac_addr_remove = mrvl_mac_addr_remove,
1897 .mac_addr_add = mrvl_mac_addr_add,
1898 .mac_addr_set = mrvl_mac_addr_set,
1899 .mtu_set = mrvl_mtu_set,
1900 .stats_get = mrvl_stats_get,
1901 .stats_reset = mrvl_stats_reset,
1902 .xstats_get = mrvl_xstats_get,
1903 .xstats_reset = mrvl_xstats_reset,
1904 .xstats_get_names = mrvl_xstats_get_names,
1905 .dev_infos_get = mrvl_dev_infos_get,
1906 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
1907 .rxq_info_get = mrvl_rxq_info_get,
1908 .txq_info_get = mrvl_txq_info_get,
1909 .vlan_filter_set = mrvl_vlan_filter_set,
1910 .tx_queue_start = mrvl_tx_queue_start,
1911 .tx_queue_stop = mrvl_tx_queue_stop,
1912 .rx_queue_setup = mrvl_rx_queue_setup,
1913 .rx_queue_release = mrvl_rx_queue_release,
1914 .tx_queue_setup = mrvl_tx_queue_setup,
1915 .tx_queue_release = mrvl_tx_queue_release,
1916 .flow_ctrl_get = mrvl_flow_ctrl_get,
1917 .flow_ctrl_set = mrvl_flow_ctrl_set,
1918 .rss_hash_update = mrvl_rss_hash_update,
1919 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
1920 .filter_ctrl = mrvl_eth_filter_ctrl,
1921 .mtr_ops_get = mrvl_mtr_ops_get,
1925 * Return packet type information and l3/l4 offsets.
1928 * Pointer to the received packet descriptor.
1935 * Packet type information.
1937 static inline uint64_t
1938 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
1939 uint8_t *l3_offset, uint8_t *l4_offset)
1941 enum pp2_inq_l3_type l3_type;
1942 enum pp2_inq_l4_type l4_type;
1943 enum pp2_inq_vlan_tag vlan_tag;
1944 uint64_t packet_type;
1946 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
1947 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
1948 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag);
1950 packet_type = RTE_PTYPE_L2_ETHER;
1953 case PP2_INQ_VLAN_TAG_SINGLE:
1954 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
1956 case PP2_INQ_VLAN_TAG_DOUBLE:
1957 case PP2_INQ_VLAN_TAG_TRIPLE:
1958 packet_type |= RTE_PTYPE_L2_ETHER_QINQ;
1965 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
1966 packet_type |= RTE_PTYPE_L3_IPV4;
1968 case PP2_INQ_L3_TYPE_IPV4_OK:
1969 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
1971 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
1972 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
1974 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
1975 packet_type |= RTE_PTYPE_L3_IPV6;
1977 case PP2_INQ_L3_TYPE_IPV6_EXT:
1978 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
1980 case PP2_INQ_L3_TYPE_ARP:
1981 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
1983 * In case of ARP l4_offset is set to wrong value.
1984 * Set it to proper one so that later on mbuf->l3_len can be
1985 * calculated subtracting l4_offset and l3_offset.
1987 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
1990 MRVL_LOG(DEBUG, "Failed to recognise l3 packet type");
1995 case PP2_INQ_L4_TYPE_TCP:
1996 packet_type |= RTE_PTYPE_L4_TCP;
1998 case PP2_INQ_L4_TYPE_UDP:
1999 packet_type |= RTE_PTYPE_L4_UDP;
2002 MRVL_LOG(DEBUG, "Failed to recognise l4 packet type");
2010 * Get offload information from the received packet descriptor.
2013 * Pointer to the received packet descriptor.
2016 * Mbuf offload flags.
2018 static inline uint64_t
2019 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
2022 enum pp2_inq_desc_status status;
2024 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
2025 if (unlikely(status != PP2_DESC_ERR_OK))
2026 flags = PKT_RX_IP_CKSUM_BAD;
2028 flags = PKT_RX_IP_CKSUM_GOOD;
2030 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
2031 if (unlikely(status != PP2_DESC_ERR_OK))
2032 flags |= PKT_RX_L4_CKSUM_BAD;
2034 flags |= PKT_RX_L4_CKSUM_GOOD;
2040 * DPDK callback for receive.
2043 * Generic pointer to the receive queue.
2045 * Array to store received packets.
2047 * Maximum number of packets in array.
2050 * Number of packets successfully received.
2053 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2055 struct mrvl_rxq *q = rxq;
2056 struct pp2_ppio_desc descs[nb_pkts];
2057 struct pp2_bpool *bpool;
2058 int i, ret, rx_done = 0;
2060 struct pp2_hif *hif;
2061 unsigned int core_id = rte_lcore_id();
2063 hif = mrvl_get_hif(q->priv, core_id);
2065 if (unlikely(!q->priv->ppio || !hif))
2068 bpool = q->priv->bpool;
2070 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
2071 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
2072 if (unlikely(ret < 0)) {
2073 MRVL_LOG(ERR, "Failed to receive packets");
2076 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
2078 for (i = 0; i < nb_pkts; i++) {
2079 struct rte_mbuf *mbuf;
2080 uint8_t l3_offset, l4_offset;
2081 enum pp2_inq_desc_status status;
2084 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2085 struct pp2_ppio_desc *pref_desc;
2088 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
2089 pref_addr = cookie_addr_high |
2090 pp2_ppio_inq_desc_get_cookie(pref_desc);
2091 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
2092 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
2095 addr = cookie_addr_high |
2096 pp2_ppio_inq_desc_get_cookie(&descs[i]);
2097 mbuf = (struct rte_mbuf *)addr;
2098 rte_pktmbuf_reset(mbuf);
2100 /* drop packet in case of mac, overrun or resource error */
2101 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
2102 if (unlikely(status != PP2_DESC_ERR_OK)) {
2103 struct pp2_buff_inf binf = {
2104 .addr = rte_mbuf_data_iova_default(mbuf),
2105 .cookie = (pp2_cookie_t)(uint64_t)mbuf,
2108 pp2_bpool_put_buff(hif, bpool, &binf);
2109 mrvl_port_bpool_size
2110 [bpool->pp2_id][bpool->id][core_id]++;
2115 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
2116 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
2117 mbuf->data_len = mbuf->pkt_len;
2118 mbuf->port = q->port_id;
2120 mrvl_desc_to_packet_type_and_offset(&descs[i],
2123 mbuf->l2_len = l3_offset;
2124 mbuf->l3_len = l4_offset - l3_offset;
2126 if (likely(q->cksum_enabled))
2127 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
2129 rx_pkts[rx_done++] = mbuf;
2130 q->bytes_recv += mbuf->pkt_len;
2133 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
2134 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
2136 if (unlikely(num <= q->priv->bpool_min_size ||
2137 (!rx_done && num < q->priv->bpool_init_size))) {
2138 ret = mrvl_fill_bpool(q, MRVL_BURST_SIZE);
2140 MRVL_LOG(ERR, "Failed to fill bpool");
2141 } else if (unlikely(num > q->priv->bpool_max_size)) {
2143 int pkt_to_remove = num - q->priv->bpool_init_size;
2144 struct rte_mbuf *mbuf;
2145 struct pp2_buff_inf buff;
2148 "port-%d:%d: bpool %d oversize - remove %d buffers (pool size: %d -> %d)",
2149 bpool->pp2_id, q->priv->ppio->port_id,
2150 bpool->id, pkt_to_remove, num,
2151 q->priv->bpool_init_size);
2153 for (i = 0; i < pkt_to_remove; i++) {
2154 ret = pp2_bpool_get_buff(hif, bpool, &buff);
2157 mbuf = (struct rte_mbuf *)
2158 (cookie_addr_high | buff.cookie);
2159 rte_pktmbuf_free(mbuf);
2161 mrvl_port_bpool_size
2162 [bpool->pp2_id][bpool->id][core_id] -= i;
2164 rte_spinlock_unlock(&q->priv->lock);
2171 * Prepare offload information.
2175 * @param packet_type
2176 * Packet type bitfield.
2178 * Pointer to the pp2_ouq_l3_type structure.
2180 * Pointer to the pp2_outq_l4_type structure.
2181 * @param gen_l3_cksum
2182 * Will be set to 1 in case l3 checksum is computed.
2184 * Will be set to 1 in case l4 checksum is computed.
2187 * 0 on success, negative error value otherwise.
2190 mrvl_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
2191 enum pp2_outq_l3_type *l3_type,
2192 enum pp2_outq_l4_type *l4_type,
2197 * Based on ol_flags prepare information
2198 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
2201 if (ol_flags & PKT_TX_IPV4) {
2202 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
2203 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
2204 } else if (ol_flags & PKT_TX_IPV6) {
2205 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
2206 /* no checksum for ipv6 header */
2209 /* if something different then stop processing */
2213 ol_flags &= PKT_TX_L4_MASK;
2214 if ((packet_type & RTE_PTYPE_L4_TCP) &&
2215 ol_flags == PKT_TX_TCP_CKSUM) {
2216 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
2218 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
2219 ol_flags == PKT_TX_UDP_CKSUM) {
2220 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
2223 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
2224 /* no checksum for other type */
2232 * Release already sent buffers to bpool (buffer-pool).
2235 * Pointer to the port structure.
2237 * Pointer to the MUSDK hardware interface.
2239 * Pointer to the shadow queue.
2243 * Force releasing packets.
2246 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2247 unsigned int core_id, struct mrvl_shadow_txq *sq,
2250 struct buff_release_entry *entry;
2251 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2254 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2256 sq->num_to_release += nb_done;
2258 if (likely(!force &&
2259 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2262 nb_done = sq->num_to_release;
2263 sq->num_to_release = 0;
2265 for (i = 0; i < nb_done; i++) {
2266 entry = &sq->ent[sq->tail + num];
2267 if (unlikely(!entry->buff.addr)) {
2269 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
2270 sq->tail, (u64)entry->buff.cookie,
2271 (u64)entry->buff.addr);
2276 if (unlikely(!entry->bpool)) {
2277 struct rte_mbuf *mbuf;
2279 mbuf = (struct rte_mbuf *)
2280 (cookie_addr_high | entry->buff.cookie);
2281 rte_pktmbuf_free(mbuf);
2286 mrvl_port_bpool_size
2287 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2289 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2294 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2296 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2303 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2304 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2310 * DPDK callback for transmit.
2313 * Generic pointer transmit queue.
2315 * Packets to transmit.
2317 * Number of packets in array.
2320 * Number of packets successfully transmitted.
2323 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2325 struct mrvl_txq *q = txq;
2326 struct mrvl_shadow_txq *sq;
2327 struct pp2_hif *hif;
2328 struct pp2_ppio_desc descs[nb_pkts];
2329 unsigned int core_id = rte_lcore_id();
2330 int i, ret, bytes_sent = 0;
2331 uint16_t num, sq_free_size;
2334 hif = mrvl_get_hif(q->priv, core_id);
2335 sq = &q->shadow_txqs[core_id];
2337 if (unlikely(!q->priv->ppio || !hif))
2341 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2342 sq, q->queue_id, 0);
2344 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2345 if (unlikely(nb_pkts > sq_free_size)) {
2347 "No room in shadow queue for %d packets! %d packets will be sent.",
2348 nb_pkts, sq_free_size);
2349 nb_pkts = sq_free_size;
2352 for (i = 0; i < nb_pkts; i++) {
2353 struct rte_mbuf *mbuf = tx_pkts[i];
2354 int gen_l3_cksum, gen_l4_cksum;
2355 enum pp2_outq_l3_type l3_type;
2356 enum pp2_outq_l4_type l4_type;
2358 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2359 struct rte_mbuf *pref_pkt_hdr;
2361 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2362 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2363 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2366 sq->ent[sq->head].buff.cookie = (pp2_cookie_t)(uint64_t)mbuf;
2367 sq->ent[sq->head].buff.addr =
2368 rte_mbuf_data_iova_default(mbuf);
2369 sq->ent[sq->head].bpool =
2370 (unlikely(mbuf->port >= RTE_MAX_ETHPORTS ||
2371 mbuf->refcnt > 1)) ? NULL :
2372 mrvl_port_to_bpool_lookup[mbuf->port];
2373 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
2376 pp2_ppio_outq_desc_reset(&descs[i]);
2377 pp2_ppio_outq_desc_set_phys_addr(&descs[i],
2378 rte_pktmbuf_iova(mbuf));
2379 pp2_ppio_outq_desc_set_pkt_offset(&descs[i], 0);
2380 pp2_ppio_outq_desc_set_pkt_len(&descs[i],
2381 rte_pktmbuf_pkt_len(mbuf));
2383 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2385 * in case unsupported ol_flags were passed
2386 * do not update descriptor offload information
2388 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2389 &l3_type, &l4_type, &gen_l3_cksum,
2394 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2396 mbuf->l2_len + mbuf->l3_len,
2397 gen_l3_cksum, gen_l4_cksum);
2401 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2402 /* number of packets that were not sent */
2403 if (unlikely(num > nb_pkts)) {
2404 for (i = nb_pkts; i < num; i++) {
2405 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2406 MRVL_PP2_TX_SHADOWQ_MASK;
2407 addr = cookie_addr_high | sq->ent[sq->head].buff.cookie;
2409 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2411 sq->size -= num - nb_pkts;
2414 q->bytes_sent += bytes_sent;
2420 * Initialize packet processor.
2423 * 0 on success, negative error value otherwise.
2428 struct pp2_init_params init_params;
2430 memset(&init_params, 0, sizeof(init_params));
2431 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2432 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2433 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2435 return pp2_init(&init_params);
2439 * Deinitialize packet processor.
2442 * 0 on success, negative error value otherwise.
2445 mrvl_deinit_pp2(void)
2451 * Create private device structure.
2454 * Pointer to the port name passed in the initialization parameters.
2457 * Pointer to the newly allocated private device structure.
2459 static struct mrvl_priv *
2460 mrvl_priv_create(const char *dev_name)
2462 struct pp2_bpool_params bpool_params;
2463 char match[MRVL_MATCH_LEN];
2464 struct mrvl_priv *priv;
2467 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2471 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2472 &priv->pp_id, &priv->ppio_id);
2476 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2477 PP2_BPOOL_NUM_POOLS);
2480 priv->bpool_bit = bpool_bit;
2482 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2484 memset(&bpool_params, 0, sizeof(bpool_params));
2485 bpool_params.match = match;
2486 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2487 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2489 goto out_clear_bpool_bit;
2491 priv->ppio_params.type = PP2_PPIO_T_NIC;
2492 rte_spinlock_init(&priv->lock);
2495 out_clear_bpool_bit:
2496 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2503 * Create device representing Ethernet port.
2506 * Pointer to the port's name.
2509 * 0 on success, negative error value otherwise.
2512 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2514 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2515 struct rte_eth_dev *eth_dev;
2516 struct mrvl_priv *priv;
2519 eth_dev = rte_eth_dev_allocate(name);
2523 priv = mrvl_priv_create(name);
2529 eth_dev->data->mac_addrs =
2530 rte_zmalloc("mac_addrs",
2531 ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2532 if (!eth_dev->data->mac_addrs) {
2533 MRVL_LOG(ERR, "Failed to allocate space for eth addrs");
2538 memset(&req, 0, sizeof(req));
2539 strcpy(req.ifr_name, name);
2540 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2544 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2545 req.ifr_addr.sa_data, ETHER_ADDR_LEN);
2547 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2548 eth_dev->tx_pkt_burst = mrvl_tx_pkt_burst;
2549 eth_dev->data->kdrv = RTE_KDRV_NONE;
2550 eth_dev->data->dev_private = priv;
2551 eth_dev->device = &vdev->device;
2552 eth_dev->dev_ops = &mrvl_ops;
2554 rte_eth_dev_probing_finish(eth_dev);
2557 rte_free(eth_dev->data->mac_addrs);
2559 rte_eth_dev_release_port(eth_dev);
2567 * Cleanup previously created device representing Ethernet port.
2570 * Pointer to the port name.
2573 mrvl_eth_dev_destroy(const char *name)
2575 struct rte_eth_dev *eth_dev;
2576 struct mrvl_priv *priv;
2578 eth_dev = rte_eth_dev_allocated(name);
2582 priv = eth_dev->data->dev_private;
2583 pp2_bpool_deinit(priv->bpool);
2584 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2586 rte_free(eth_dev->data->mac_addrs);
2587 rte_eth_dev_release_port(eth_dev);
2591 * Callback used by rte_kvargs_process() during argument parsing.
2594 * Pointer to the parsed key (unused).
2596 * Pointer to the parsed value.
2598 * Pointer to the extra arguments which contains address of the
2599 * table of pointers to parsed interface names.
2605 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
2608 struct mrvl_ifnames *ifnames = extra_args;
2610 ifnames->names[ifnames->idx++] = value;
2616 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
2619 mrvl_deinit_hifs(void)
2623 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
2625 pp2_hif_deinit(hifs[i]);
2627 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
2628 memset(hifs, 0, sizeof(hifs));
2632 * DPDK callback to register the virtual device.
2635 * Pointer to the virtual device.
2638 * 0 on success, negative error value otherwise.
2641 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
2643 struct rte_kvargs *kvlist;
2644 struct mrvl_ifnames ifnames;
2646 uint32_t i, ifnum, cfgnum;
2649 params = rte_vdev_device_args(vdev);
2653 kvlist = rte_kvargs_parse(params, valid_args);
2657 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
2658 if (ifnum > RTE_DIM(ifnames.names))
2659 goto out_free_kvlist;
2662 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
2663 mrvl_get_ifnames, &ifnames);
2667 * The below system initialization should be done only once,
2668 * on the first provided configuration file
2670 if (!mrvl_qos_cfg) {
2671 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
2672 MRVL_LOG(INFO, "Parsing config file!");
2674 MRVL_LOG(ERR, "Cannot handle more than one config file!");
2675 goto out_free_kvlist;
2676 } else if (cfgnum == 1) {
2677 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
2678 mrvl_get_qoscfg, &mrvl_qos_cfg);
2685 MRVL_LOG(INFO, "Perform MUSDK initializations");
2687 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist);
2689 goto out_free_kvlist;
2691 ret = mrvl_init_pp2();
2693 MRVL_LOG(ERR, "Failed to init PP!");
2694 rte_mvep_deinit(MVEP_MOD_T_PP2);
2695 goto out_free_kvlist;
2698 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
2699 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
2701 mrvl_lcore_first = RTE_MAX_LCORE;
2702 mrvl_lcore_last = 0;
2705 for (i = 0; i < ifnum; i++) {
2706 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]);
2707 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
2711 mrvl_dev_num += ifnum;
2713 rte_kvargs_free(kvlist);
2718 mrvl_eth_dev_destroy(ifnames.names[i]);
2720 if (mrvl_dev_num == 0) {
2722 rte_mvep_deinit(MVEP_MOD_T_PP2);
2725 rte_kvargs_free(kvlist);
2731 * DPDK callback to remove virtual device.
2734 * Pointer to the removed virtual device.
2737 * 0 on success, negative error value otherwise.
2740 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
2745 name = rte_vdev_device_name(vdev);
2749 MRVL_LOG(INFO, "Removing %s", name);
2751 RTE_ETH_FOREACH_DEV(i) { /* FIXME: removing all devices! */
2752 char ifname[RTE_ETH_NAME_MAX_LEN];
2754 rte_eth_dev_get_name_by_port(i, ifname);
2755 mrvl_eth_dev_destroy(ifname);
2759 if (mrvl_dev_num == 0) {
2760 MRVL_LOG(INFO, "Perform MUSDK deinit");
2763 rte_mvep_deinit(MVEP_MOD_T_PP2);
2769 static struct rte_vdev_driver pmd_mrvl_drv = {
2770 .probe = rte_pmd_mrvl_probe,
2771 .remove = rte_pmd_mrvl_remove,
2774 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv);
2775 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2);
2777 RTE_INIT(mrvl_init_log)
2779 mrvl_logtype = rte_log_register("pmd.net.mvpp2");
2780 if (mrvl_logtype >= 0)
2781 rte_log_set_level(mrvl_logtype, RTE_LOG_NOTICE);