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>
13 /* Unluckily, container_of is defined by both DPDK and MUSDK,
14 * we'll declare only one version.
16 * Note that it is not used in this PMD anyway.
23 #include <linux/ethtool.h>
24 #include <linux/sockios.h>
26 #include <net/if_arp.h>
27 #include <sys/ioctl.h>
28 #include <sys/socket.h>
30 #include <sys/types.h>
32 #include "mrvl_ethdev.h"
35 /* bitmask with reserved hifs */
36 #define MRVL_MUSDK_HIFS_RESERVED 0x0F
37 /* bitmask with reserved bpools */
38 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07
39 /* bitmask with reserved kernel RSS tables */
40 #define MRVL_MUSDK_RSS_RESERVED 0x01
41 /* maximum number of available hifs */
42 #define MRVL_MUSDK_HIFS_MAX 9
45 #define MRVL_MUSDK_PREFETCH_SHIFT 2
47 /* TCAM has 25 entries reserved for uc/mc filter entries */
48 #define MRVL_MAC_ADDRS_MAX 25
49 #define MRVL_MATCH_LEN 16
50 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
51 /* Maximum allowable packet size */
52 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
54 #define MRVL_IFACE_NAME_ARG "iface"
55 #define MRVL_CFG_ARG "cfg"
57 #define MRVL_BURST_SIZE 64
59 #define MRVL_ARP_LENGTH 28
61 #define MRVL_COOKIE_ADDR_INVALID ~0ULL
63 #define MRVL_COOKIE_HIGH_ADDR_SHIFT (sizeof(pp2_cookie_t) * 8)
64 #define MRVL_COOKIE_HIGH_ADDR_MASK (~0ULL << MRVL_COOKIE_HIGH_ADDR_SHIFT)
66 /* Memory size (in bytes) for MUSDK dma buffers */
67 #define MRVL_MUSDK_DMA_MEMSIZE 41943040
69 /** Port Rx offload capabilities */
70 #define MRVL_RX_OFFLOADS (DEV_RX_OFFLOAD_VLAN_FILTER | \
71 DEV_RX_OFFLOAD_JUMBO_FRAME | \
72 DEV_RX_OFFLOAD_CRC_STRIP | \
73 DEV_RX_OFFLOAD_CHECKSUM)
75 /** Port Tx offloads capabilities */
76 #define MRVL_TX_OFFLOADS (DEV_TX_OFFLOAD_IPV4_CKSUM | \
77 DEV_TX_OFFLOAD_UDP_CKSUM | \
78 DEV_TX_OFFLOAD_TCP_CKSUM)
80 static const char * const valid_args[] = {
86 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
87 static struct pp2_hif *hifs[RTE_MAX_LCORE];
88 static int used_bpools[PP2_NUM_PKT_PROC] = {
89 MRVL_MUSDK_BPOOLS_RESERVED,
90 MRVL_MUSDK_BPOOLS_RESERVED
93 struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
94 int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
95 uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
98 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
103 * To use buffer harvesting based on loopback port shadow queue structure
104 * was introduced for buffers information bookkeeping.
106 * Before sending the packet, related buffer information (pp2_buff_inf) is
107 * stored in shadow queue. After packet is transmitted no longer used
108 * packet buffer is released back to it's original hardware pool,
109 * on condition it originated from interface.
110 * In case it was generated by application itself i.e: mbuf->port field is
111 * 0xff then its released to software mempool.
113 struct mrvl_shadow_txq {
114 int head; /* write index - used when sending buffers */
115 int tail; /* read index - used when releasing buffers */
116 u16 size; /* queue occupied size */
117 u16 num_to_release; /* number of buffers sent, that can be released */
118 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
122 struct mrvl_priv *priv;
123 struct rte_mempool *mp;
132 struct mrvl_priv *priv;
136 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
139 static int mrvl_lcore_first;
140 static int mrvl_lcore_last;
141 static int mrvl_dev_num;
143 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
144 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
145 struct pp2_hif *hif, unsigned int core_id,
146 struct mrvl_shadow_txq *sq, int qid, int force);
149 mrvl_get_bpool_size(int pp2_id, int pool_id)
154 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
155 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
161 mrvl_reserve_bit(int *bitmap, int max)
163 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
174 mrvl_init_hif(int core_id)
176 struct pp2_hif_params params;
177 char match[MRVL_MATCH_LEN];
180 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
182 RTE_LOG(ERR, PMD, "Failed to allocate hif %d\n", core_id);
186 snprintf(match, sizeof(match), "hif-%d", ret);
187 memset(¶ms, 0, sizeof(params));
188 params.match = match;
189 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
190 ret = pp2_hif_init(¶ms, &hifs[core_id]);
192 RTE_LOG(ERR, PMD, "Failed to initialize hif %d\n", core_id);
199 static inline struct pp2_hif*
200 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
204 if (likely(hifs[core_id] != NULL))
205 return hifs[core_id];
207 rte_spinlock_lock(&priv->lock);
209 ret = mrvl_init_hif(core_id);
211 RTE_LOG(ERR, PMD, "Failed to allocate hif %d\n", core_id);
215 if (core_id < mrvl_lcore_first)
216 mrvl_lcore_first = core_id;
218 if (core_id > mrvl_lcore_last)
219 mrvl_lcore_last = core_id;
221 rte_spinlock_unlock(&priv->lock);
223 return hifs[core_id];
227 * Configure rss based on dpdk rss configuration.
230 * Pointer to private structure.
232 * Pointer to RSS configuration.
235 * 0 on success, negative error value otherwise.
238 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
240 if (rss_conf->rss_key)
241 RTE_LOG(WARNING, PMD, "Changing hash key is not supported\n");
243 if (rss_conf->rss_hf == 0) {
244 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
245 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
246 priv->ppio_params.inqs_params.hash_type =
247 PP2_PPIO_HASH_T_2_TUPLE;
248 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
249 priv->ppio_params.inqs_params.hash_type =
250 PP2_PPIO_HASH_T_5_TUPLE;
251 priv->rss_hf_tcp = 1;
252 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
253 priv->ppio_params.inqs_params.hash_type =
254 PP2_PPIO_HASH_T_5_TUPLE;
255 priv->rss_hf_tcp = 0;
264 * Ethernet device configuration.
266 * Prepare the driver for a given number of TX and RX queues and
270 * Pointer to Ethernet device structure.
273 * 0 on success, negative error value otherwise.
276 mrvl_dev_configure(struct rte_eth_dev *dev)
278 struct mrvl_priv *priv = dev->data->dev_private;
281 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
282 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
283 RTE_LOG(INFO, PMD, "Unsupported rx multi queue mode %d\n",
284 dev->data->dev_conf.rxmode.mq_mode);
288 if (!(dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_CRC_STRIP)) {
290 "L2 CRC stripping is always enabled in hw\n");
291 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
294 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
295 RTE_LOG(INFO, PMD, "VLAN stripping not supported\n");
299 if (dev->data->dev_conf.rxmode.split_hdr_size) {
300 RTE_LOG(INFO, PMD, "Split headers not supported\n");
304 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) {
305 RTE_LOG(INFO, PMD, "RX Scatter/Gather not supported\n");
309 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
310 RTE_LOG(INFO, PMD, "LRO not supported\n");
314 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
315 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
316 ETHER_HDR_LEN - ETHER_CRC_LEN;
318 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
319 dev->data->nb_rx_queues);
323 ret = mrvl_configure_txqs(priv, dev->data->port_id,
324 dev->data->nb_tx_queues);
328 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
329 priv->ppio_params.maintain_stats = 1;
330 priv->nb_rx_queues = dev->data->nb_rx_queues;
332 if (dev->data->nb_rx_queues == 1 &&
333 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
334 RTE_LOG(WARNING, PMD, "Disabling hash for 1 rx queue\n");
335 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
340 return mrvl_configure_rss(priv,
341 &dev->data->dev_conf.rx_adv_conf.rss_conf);
345 * DPDK callback to change the MTU.
347 * Setting the MTU affects hardware MRU (packets larger than the MRU
351 * Pointer to Ethernet device structure.
356 * 0 on success, negative error value otherwise.
359 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
361 struct mrvl_priv *priv = dev->data->dev_private;
362 /* extra MV_MH_SIZE bytes are required for Marvell tag */
363 uint16_t mru = mtu + MV_MH_SIZE + ETHER_HDR_LEN + ETHER_CRC_LEN;
366 if (mtu < ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX)
372 ret = pp2_ppio_set_mru(priv->ppio, mru);
376 return pp2_ppio_set_mtu(priv->ppio, mtu);
380 * DPDK callback to bring the link up.
383 * Pointer to Ethernet device structure.
386 * 0 on success, negative error value otherwise.
389 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
391 struct mrvl_priv *priv = dev->data->dev_private;
397 ret = pp2_ppio_enable(priv->ppio);
402 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
403 * as pp2_ppio_enable() changes port->t_mode from default 0 to
404 * PP2_TRAFFIC_INGRESS_EGRESS.
406 * Set mtu to default DPDK value here.
408 ret = mrvl_mtu_set(dev, dev->data->mtu);
410 pp2_ppio_disable(priv->ppio);
416 * DPDK callback to bring the link down.
419 * Pointer to Ethernet device structure.
422 * 0 on success, negative error value otherwise.
425 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
427 struct mrvl_priv *priv = dev->data->dev_private;
432 return pp2_ppio_disable(priv->ppio);
436 * DPDK callback to start the device.
439 * Pointer to Ethernet device structure.
442 * 0 on success, negative errno value on failure.
445 mrvl_dev_start(struct rte_eth_dev *dev)
447 struct mrvl_priv *priv = dev->data->dev_private;
448 char match[MRVL_MATCH_LEN];
449 int ret = 0, def_init_size;
451 snprintf(match, sizeof(match), "ppio-%d:%d",
452 priv->pp_id, priv->ppio_id);
453 priv->ppio_params.match = match;
456 * Calculate the minimum bpool size for refill feature as follows:
457 * 2 default burst sizes multiply by number of rx queues.
458 * If the bpool size will be below this value, new buffers will
459 * be added to the pool.
461 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
463 /* In case initial bpool size configured in queues setup is
464 * smaller than minimum size add more buffers
466 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
467 if (priv->bpool_init_size < def_init_size) {
468 int buffs_to_add = def_init_size - priv->bpool_init_size;
470 priv->bpool_init_size += buffs_to_add;
471 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
473 RTE_LOG(ERR, PMD, "Failed to add buffers to bpool\n");
477 * Calculate the maximum bpool size for refill feature as follows:
478 * maximum number of descriptors in rx queue multiply by number
479 * of rx queues plus minimum bpool size.
480 * In case the bpool size will exceed this value, superfluous buffers
483 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
484 priv->bpool_min_size;
486 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
488 RTE_LOG(ERR, PMD, "Failed to init ppio\n");
493 * In case there are some some stale uc/mc mac addresses flush them
494 * here. It cannot be done during mrvl_dev_close() as port information
495 * is already gone at that point (due to pp2_ppio_deinit() in
498 if (!priv->uc_mc_flushed) {
499 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
502 "Failed to flush uc/mc filter list\n");
505 priv->uc_mc_flushed = 1;
508 if (!priv->vlan_flushed) {
509 ret = pp2_ppio_flush_vlan(priv->ppio);
511 RTE_LOG(ERR, PMD, "Failed to flush vlan list\n");
514 * once pp2_ppio_flush_vlan() is supported jump to out
518 priv->vlan_flushed = 1;
521 /* For default QoS config, don't start classifier. */
523 ret = mrvl_start_qos_mapping(priv);
525 RTE_LOG(ERR, PMD, "Failed to setup QoS mapping\n");
530 ret = mrvl_dev_set_link_up(dev);
532 RTE_LOG(ERR, PMD, "Failed to set link up\n");
538 RTE_LOG(ERR, PMD, "Failed to start device\n");
539 pp2_ppio_deinit(priv->ppio);
544 * Flush receive queues.
547 * Pointer to Ethernet device structure.
550 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
554 RTE_LOG(INFO, PMD, "Flushing rx queues\n");
555 for (i = 0; i < dev->data->nb_rx_queues; i++) {
559 struct mrvl_rxq *q = dev->data->rx_queues[i];
560 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
562 num = MRVL_PP2_RXD_MAX;
563 ret = pp2_ppio_recv(q->priv->ppio,
564 q->priv->rxq_map[q->queue_id].tc,
565 q->priv->rxq_map[q->queue_id].inq,
566 descs, (uint16_t *)&num);
567 } while (ret == 0 && num);
572 * Flush transmit shadow queues.
575 * Pointer to Ethernet device structure.
578 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
581 struct mrvl_txq *txq;
583 RTE_LOG(INFO, PMD, "Flushing tx shadow queues\n");
584 for (i = 0; i < dev->data->nb_tx_queues; i++) {
585 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
587 for (j = 0; j < RTE_MAX_LCORE; j++) {
588 struct mrvl_shadow_txq *sq;
593 sq = &txq->shadow_txqs[j];
594 mrvl_free_sent_buffers(txq->priv->ppio,
595 hifs[j], j, sq, txq->queue_id, 1);
596 while (sq->tail != sq->head) {
597 uint64_t addr = cookie_addr_high |
598 sq->ent[sq->tail].buff.cookie;
600 (struct rte_mbuf *)addr);
601 sq->tail = (sq->tail + 1) &
602 MRVL_PP2_TX_SHADOWQ_MASK;
604 memset(sq, 0, sizeof(*sq));
610 * Flush hardware bpool (buffer-pool).
613 * Pointer to Ethernet device structure.
616 mrvl_flush_bpool(struct rte_eth_dev *dev)
618 struct mrvl_priv *priv = dev->data->dev_private;
622 unsigned int core_id = rte_lcore_id();
624 if (core_id == LCORE_ID_ANY)
627 hif = mrvl_get_hif(priv, core_id);
629 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
631 RTE_LOG(ERR, PMD, "Failed to get bpool buffers number\n");
636 struct pp2_buff_inf inf;
639 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
643 addr = cookie_addr_high | inf.cookie;
644 rte_pktmbuf_free((struct rte_mbuf *)addr);
649 * DPDK callback to stop the device.
652 * Pointer to Ethernet device structure.
655 mrvl_dev_stop(struct rte_eth_dev *dev)
657 struct mrvl_priv *priv = dev->data->dev_private;
659 mrvl_dev_set_link_down(dev);
660 mrvl_flush_rx_queues(dev);
661 mrvl_flush_tx_shadow_queues(dev);
663 pp2_cls_tbl_deinit(priv->cls_tbl);
664 priv->cls_tbl = NULL;
667 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
668 priv->qos_tbl = NULL;
671 pp2_ppio_deinit(priv->ppio);
674 /* policer must be released after ppio deinitialization */
676 pp2_cls_plcr_deinit(priv->policer);
677 priv->policer = NULL;
682 * DPDK callback to close the device.
685 * Pointer to Ethernet device structure.
688 mrvl_dev_close(struct rte_eth_dev *dev)
690 struct mrvl_priv *priv = dev->data->dev_private;
693 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
694 struct pp2_ppio_tc_params *tc_params =
695 &priv->ppio_params.inqs_params.tcs_params[i];
697 if (tc_params->inqs_params) {
698 rte_free(tc_params->inqs_params);
699 tc_params->inqs_params = NULL;
703 mrvl_flush_bpool(dev);
707 * DPDK callback to retrieve physical link information.
710 * Pointer to Ethernet device structure.
711 * @param wait_to_complete
712 * Wait for request completion (ignored).
715 * 0 on success, negative error value otherwise.
718 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
722 * once MUSDK provides necessary API use it here
724 struct mrvl_priv *priv = dev->data->dev_private;
725 struct ethtool_cmd edata;
727 int ret, fd, link_up;
732 edata.cmd = ETHTOOL_GSET;
734 strcpy(req.ifr_name, dev->data->name);
735 req.ifr_data = (void *)&edata;
737 fd = socket(AF_INET, SOCK_DGRAM, 0);
741 ret = ioctl(fd, SIOCETHTOOL, &req);
749 switch (ethtool_cmd_speed(&edata)) {
751 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
754 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
757 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
760 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
763 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
766 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
767 ETH_LINK_HALF_DUPLEX;
768 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
770 pp2_ppio_get_link_state(priv->ppio, &link_up);
771 dev->data->dev_link.link_status = link_up ? ETH_LINK_UP : ETH_LINK_DOWN;
777 * DPDK callback to enable promiscuous mode.
780 * Pointer to Ethernet device structure.
783 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
785 struct mrvl_priv *priv = dev->data->dev_private;
794 ret = pp2_ppio_set_promisc(priv->ppio, 1);
796 RTE_LOG(ERR, PMD, "Failed to enable promiscuous mode\n");
800 * DPDK callback to enable allmulti mode.
803 * Pointer to Ethernet device structure.
806 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
808 struct mrvl_priv *priv = dev->data->dev_private;
817 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
819 RTE_LOG(ERR, PMD, "Failed enable all-multicast mode\n");
823 * DPDK callback to disable promiscuous mode.
826 * Pointer to Ethernet device structure.
829 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
831 struct mrvl_priv *priv = dev->data->dev_private;
837 ret = pp2_ppio_set_promisc(priv->ppio, 0);
839 RTE_LOG(ERR, PMD, "Failed to disable promiscuous mode\n");
843 * DPDK callback to disable allmulticast mode.
846 * Pointer to Ethernet device structure.
849 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
851 struct mrvl_priv *priv = dev->data->dev_private;
857 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
859 RTE_LOG(ERR, PMD, "Failed to disable all-multicast mode\n");
863 * DPDK callback to remove a MAC address.
866 * Pointer to Ethernet device structure.
871 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
873 struct mrvl_priv *priv = dev->data->dev_private;
874 char buf[ETHER_ADDR_FMT_SIZE];
883 ret = pp2_ppio_remove_mac_addr(priv->ppio,
884 dev->data->mac_addrs[index].addr_bytes);
886 ether_format_addr(buf, sizeof(buf),
887 &dev->data->mac_addrs[index]);
888 RTE_LOG(ERR, PMD, "Failed to remove mac %s\n", buf);
893 * DPDK callback to add a MAC address.
896 * Pointer to Ethernet device structure.
898 * MAC address to register.
902 * VMDq pool index to associate address with (unused).
905 * 0 on success, negative error value otherwise.
908 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
909 uint32_t index, uint32_t vmdq __rte_unused)
911 struct mrvl_priv *priv = dev->data->dev_private;
912 char buf[ETHER_ADDR_FMT_SIZE];
919 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
926 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
927 * parameter uc_filter_max. Maximum number of mc addresses is then
928 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
931 * If more than uc_filter_max uc addresses were added to filter list
932 * then NIC will switch to promiscuous mode automatically.
934 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
935 * were added to filter list then NIC will switch to all-multicast mode
938 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
940 ether_format_addr(buf, sizeof(buf), mac_addr);
941 RTE_LOG(ERR, PMD, "Failed to add mac %s\n", buf);
949 * DPDK callback to set the primary MAC address.
952 * Pointer to Ethernet device structure.
954 * MAC address to register.
957 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
959 struct mrvl_priv *priv = dev->data->dev_private;
968 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
970 char buf[ETHER_ADDR_FMT_SIZE];
971 ether_format_addr(buf, sizeof(buf), mac_addr);
972 RTE_LOG(ERR, PMD, "Failed to set mac to %s\n", buf);
977 * DPDK callback to get device statistics.
980 * Pointer to Ethernet device structure.
982 * Stats structure output buffer.
985 * 0 on success, negative error value otherwise.
988 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
990 struct mrvl_priv *priv = dev->data->dev_private;
991 struct pp2_ppio_statistics ppio_stats;
992 uint64_t drop_mac = 0;
993 unsigned int i, idx, ret;
998 for (i = 0; i < dev->data->nb_rx_queues; i++) {
999 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1000 struct pp2_ppio_inq_statistics rx_stats;
1005 idx = rxq->queue_id;
1006 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1008 "rx queue %d stats out of range (0 - %d)\n",
1009 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1013 ret = pp2_ppio_inq_get_statistics(priv->ppio,
1014 priv->rxq_map[idx].tc,
1015 priv->rxq_map[idx].inq,
1017 if (unlikely(ret)) {
1019 "Failed to update rx queue %d stats\n", idx);
1023 stats->q_ibytes[idx] = rxq->bytes_recv;
1024 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
1025 stats->q_errors[idx] = rx_stats.drop_early +
1026 rx_stats.drop_fullq +
1029 stats->ibytes += rxq->bytes_recv;
1030 drop_mac += rxq->drop_mac;
1033 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1034 struct mrvl_txq *txq = dev->data->tx_queues[i];
1035 struct pp2_ppio_outq_statistics tx_stats;
1040 idx = txq->queue_id;
1041 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1043 "tx queue %d stats out of range (0 - %d)\n",
1044 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1047 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1049 if (unlikely(ret)) {
1051 "Failed to update tx queue %d stats\n", idx);
1055 stats->q_opackets[idx] = tx_stats.deq_desc;
1056 stats->q_obytes[idx] = txq->bytes_sent;
1057 stats->obytes += txq->bytes_sent;
1060 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1061 if (unlikely(ret)) {
1062 RTE_LOG(ERR, PMD, "Failed to update port statistics\n");
1066 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1067 stats->opackets += ppio_stats.tx_packets;
1068 stats->imissed += ppio_stats.rx_fullq_dropped +
1069 ppio_stats.rx_bm_dropped +
1070 ppio_stats.rx_early_dropped +
1071 ppio_stats.rx_fifo_dropped +
1072 ppio_stats.rx_cls_dropped;
1073 stats->ierrors = drop_mac;
1079 * DPDK callback to clear device statistics.
1082 * Pointer to Ethernet device structure.
1085 mrvl_stats_reset(struct rte_eth_dev *dev)
1087 struct mrvl_priv *priv = dev->data->dev_private;
1093 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1094 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1096 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1097 priv->rxq_map[i].inq, NULL, 1);
1098 rxq->bytes_recv = 0;
1102 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1103 struct mrvl_txq *txq = dev->data->tx_queues[i];
1105 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1106 txq->bytes_sent = 0;
1109 pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1113 * DPDK callback to get information about the device.
1116 * Pointer to Ethernet device structure (unused).
1118 * Info structure output buffer.
1121 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1122 struct rte_eth_dev_info *info)
1124 info->speed_capa = ETH_LINK_SPEED_10M |
1125 ETH_LINK_SPEED_100M |
1129 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1130 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1131 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1133 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1134 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1135 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1137 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1138 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1139 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1141 info->rx_offload_capa = MRVL_RX_OFFLOADS;
1142 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS;
1144 info->tx_offload_capa = MRVL_TX_OFFLOADS;
1145 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS;
1147 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1148 ETH_RSS_NONFRAG_IPV4_TCP |
1149 ETH_RSS_NONFRAG_IPV4_UDP;
1151 /* By default packets are dropped if no descriptors are available */
1152 info->default_rxconf.rx_drop_en = 1;
1153 info->default_rxconf.offloads = DEV_RX_OFFLOAD_CRC_STRIP;
1155 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1159 * Return supported packet types.
1162 * Pointer to Ethernet device structure (unused).
1165 * Const pointer to the table with supported packet types.
1167 static const uint32_t *
1168 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1170 static const uint32_t ptypes[] = {
1173 RTE_PTYPE_L3_IPV4_EXT,
1174 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1176 RTE_PTYPE_L3_IPV6_EXT,
1177 RTE_PTYPE_L2_ETHER_ARP,
1186 * DPDK callback to get information about specific receive queue.
1189 * Pointer to Ethernet device structure.
1190 * @param rx_queue_id
1191 * Receive queue index.
1193 * Receive queue information structure.
1195 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1196 struct rte_eth_rxq_info *qinfo)
1198 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1199 struct mrvl_priv *priv = dev->data->dev_private;
1200 int inq = priv->rxq_map[rx_queue_id].inq;
1201 int tc = priv->rxq_map[rx_queue_id].tc;
1202 struct pp2_ppio_tc_params *tc_params =
1203 &priv->ppio_params.inqs_params.tcs_params[tc];
1206 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1210 * DPDK callback to get information about specific transmit queue.
1213 * Pointer to Ethernet device structure.
1214 * @param tx_queue_id
1215 * Transmit queue index.
1217 * Transmit queue information structure.
1219 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1220 struct rte_eth_txq_info *qinfo)
1222 struct mrvl_priv *priv = dev->data->dev_private;
1225 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1229 * DPDK callback to Configure a VLAN filter.
1232 * Pointer to Ethernet device structure.
1234 * VLAN ID to filter.
1239 * 0 on success, negative error value otherwise.
1242 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1244 struct mrvl_priv *priv = dev->data->dev_private;
1252 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1253 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1257 * Release buffers to hardware bpool (buffer-pool)
1260 * Receive queue pointer.
1262 * Number of buffers to release to bpool.
1265 * 0 on success, negative error value otherwise.
1268 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1270 struct buff_release_entry entries[MRVL_PP2_TXD_MAX];
1271 struct rte_mbuf *mbufs[MRVL_PP2_TXD_MAX];
1273 unsigned int core_id;
1274 struct pp2_hif *hif;
1275 struct pp2_bpool *bpool;
1277 core_id = rte_lcore_id();
1278 if (core_id == LCORE_ID_ANY)
1281 hif = mrvl_get_hif(rxq->priv, core_id);
1285 bpool = rxq->priv->bpool;
1287 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1291 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1293 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1295 for (i = 0; i < num; i++) {
1296 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1297 != cookie_addr_high) {
1299 "mbuf virtual addr high 0x%lx out of range\n",
1300 (uint64_t)mbufs[i] >> 32);
1304 entries[i].buff.addr =
1305 rte_mbuf_data_iova_default(mbufs[i]);
1306 entries[i].buff.cookie = (pp2_cookie_t)(uint64_t)mbufs[i];
1307 entries[i].bpool = bpool;
1310 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1311 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1318 for (; i < num; i++)
1319 rte_pktmbuf_free(mbufs[i]);
1325 * Check whether requested rx queue offloads match port offloads.
1328 * dev Pointer to the device.
1330 * requested Bitmap of the requested offloads.
1333 * 1 if requested offloads are okay, 0 otherwise.
1336 mrvl_rx_queue_offloads_okay(struct rte_eth_dev *dev, uint64_t requested)
1338 uint64_t mandatory = dev->data->dev_conf.rxmode.offloads;
1339 uint64_t supported = MRVL_RX_OFFLOADS;
1340 uint64_t unsupported = requested & ~supported;
1341 uint64_t missing = mandatory & ~requested;
1344 RTE_LOG(ERR, PMD, "Some Rx offloads are not supported. "
1345 "Requested 0x%" PRIx64 " supported 0x%" PRIx64 ".\n",
1346 requested, supported);
1351 RTE_LOG(ERR, PMD, "Some Rx offloads are missing. "
1352 "Requested 0x%" PRIx64 " missing 0x%" PRIx64 ".\n",
1353 requested, missing);
1361 * DPDK callback to configure the receive queue.
1364 * Pointer to Ethernet device structure.
1368 * Number of descriptors to configure in queue.
1370 * NUMA socket on which memory must be allocated.
1372 * Thresholds parameters.
1374 * Memory pool for buffer allocations.
1377 * 0 on success, negative error value otherwise.
1380 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1381 unsigned int socket,
1382 const struct rte_eth_rxconf *conf,
1383 struct rte_mempool *mp)
1385 struct mrvl_priv *priv = dev->data->dev_private;
1386 struct mrvl_rxq *rxq;
1388 max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1391 if (!mrvl_rx_queue_offloads_okay(dev, conf->offloads))
1394 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1396 * Unknown TC mapping, mapping will not have a correct queue.
1398 RTE_LOG(ERR, PMD, "Unknown TC mapping for queue %hu eth%hhu\n",
1399 idx, priv->ppio_id);
1403 min_size = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM -
1404 MRVL_PKT_EFFEC_OFFS;
1405 if (min_size < max_rx_pkt_len) {
1407 "Mbuf size must be increased to %u bytes to hold up to %u bytes of data.\n",
1408 max_rx_pkt_len + RTE_PKTMBUF_HEADROOM +
1409 MRVL_PKT_EFFEC_OFFS,
1414 if (dev->data->rx_queues[idx]) {
1415 rte_free(dev->data->rx_queues[idx]);
1416 dev->data->rx_queues[idx] = NULL;
1419 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1425 rxq->cksum_enabled =
1426 dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_IPV4_CKSUM;
1427 rxq->queue_id = idx;
1428 rxq->port_id = dev->data->port_id;
1429 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1431 tc = priv->rxq_map[rxq->queue_id].tc,
1432 inq = priv->rxq_map[rxq->queue_id].inq;
1433 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1436 ret = mrvl_fill_bpool(rxq, desc);
1442 priv->bpool_init_size += desc;
1444 dev->data->rx_queues[idx] = rxq;
1450 * DPDK callback to release the receive queue.
1453 * Generic receive queue pointer.
1456 mrvl_rx_queue_release(void *rxq)
1458 struct mrvl_rxq *q = rxq;
1459 struct pp2_ppio_tc_params *tc_params;
1460 int i, num, tc, inq;
1461 struct pp2_hif *hif;
1462 unsigned int core_id = rte_lcore_id();
1464 if (core_id == LCORE_ID_ANY)
1467 hif = mrvl_get_hif(q->priv, core_id);
1472 tc = q->priv->rxq_map[q->queue_id].tc;
1473 inq = q->priv->rxq_map[q->queue_id].inq;
1474 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1475 num = tc_params->inqs_params[inq].size;
1476 for (i = 0; i < num; i++) {
1477 struct pp2_buff_inf inf;
1480 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1481 addr = cookie_addr_high | inf.cookie;
1482 rte_pktmbuf_free((struct rte_mbuf *)addr);
1489 * Check whether requested tx queue offloads match port offloads.
1492 * dev Pointer to the device.
1494 * requested Bitmap of the requested offloads.
1497 * 1 if requested offloads are okay, 0 otherwise.
1500 mrvl_tx_queue_offloads_okay(struct rte_eth_dev *dev, uint64_t requested)
1502 uint64_t mandatory = dev->data->dev_conf.txmode.offloads;
1503 uint64_t supported = MRVL_TX_OFFLOADS;
1504 uint64_t unsupported = requested & ~supported;
1505 uint64_t missing = mandatory & ~requested;
1508 RTE_LOG(ERR, PMD, "Some Rx offloads are not supported. "
1509 "Requested 0x%" PRIx64 " supported 0x%" PRIx64 ".\n",
1510 requested, supported);
1515 RTE_LOG(ERR, PMD, "Some Rx offloads are missing. "
1516 "Requested 0x%" PRIx64 " missing 0x%" PRIx64 ".\n",
1517 requested, missing);
1525 * DPDK callback to configure the transmit queue.
1528 * Pointer to Ethernet device structure.
1530 * Transmit queue index.
1532 * Number of descriptors to configure in the queue.
1534 * NUMA socket on which memory must be allocated.
1536 * Thresholds parameters.
1539 * 0 on success, negative error value otherwise.
1542 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1543 unsigned int socket,
1544 const struct rte_eth_txconf *conf)
1546 struct mrvl_priv *priv = dev->data->dev_private;
1547 struct mrvl_txq *txq;
1549 if (!mrvl_tx_queue_offloads_okay(dev, conf->offloads))
1552 if (dev->data->tx_queues[idx]) {
1553 rte_free(dev->data->tx_queues[idx]);
1554 dev->data->tx_queues[idx] = NULL;
1557 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1562 txq->queue_id = idx;
1563 txq->port_id = dev->data->port_id;
1564 dev->data->tx_queues[idx] = txq;
1566 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1572 * DPDK callback to release the transmit queue.
1575 * Generic transmit queue pointer.
1578 mrvl_tx_queue_release(void *txq)
1580 struct mrvl_txq *q = txq;
1589 * Update RSS hash configuration
1592 * Pointer to Ethernet device structure.
1594 * Pointer to RSS configuration.
1597 * 0 on success, negative error value otherwise.
1600 mrvl_rss_hash_update(struct rte_eth_dev *dev,
1601 struct rte_eth_rss_conf *rss_conf)
1603 struct mrvl_priv *priv = dev->data->dev_private;
1608 return mrvl_configure_rss(priv, rss_conf);
1612 * DPDK callback to get RSS hash configuration.
1615 * Pointer to Ethernet device structure.
1617 * Pointer to RSS configuration.
1623 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
1624 struct rte_eth_rss_conf *rss_conf)
1626 struct mrvl_priv *priv = dev->data->dev_private;
1627 enum pp2_ppio_hash_type hash_type =
1628 priv->ppio_params.inqs_params.hash_type;
1630 rss_conf->rss_key = NULL;
1632 if (hash_type == PP2_PPIO_HASH_T_NONE)
1633 rss_conf->rss_hf = 0;
1634 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
1635 rss_conf->rss_hf = ETH_RSS_IPV4;
1636 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
1637 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
1638 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
1639 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
1645 * DPDK callback to get rte_flow callbacks.
1648 * Pointer to the device structure.
1652 * Flow filter operation.
1654 * Pointer to pass the flow ops.
1657 * 0 on success, negative error value otherwise.
1660 mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
1661 enum rte_filter_type filter_type,
1662 enum rte_filter_op filter_op, void *arg)
1664 switch (filter_type) {
1665 case RTE_ETH_FILTER_GENERIC:
1666 if (filter_op != RTE_ETH_FILTER_GET)
1668 *(const void **)arg = &mrvl_flow_ops;
1671 RTE_LOG(WARNING, PMD, "Filter type (%d) not supported",
1677 static const struct eth_dev_ops mrvl_ops = {
1678 .dev_configure = mrvl_dev_configure,
1679 .dev_start = mrvl_dev_start,
1680 .dev_stop = mrvl_dev_stop,
1681 .dev_set_link_up = mrvl_dev_set_link_up,
1682 .dev_set_link_down = mrvl_dev_set_link_down,
1683 .dev_close = mrvl_dev_close,
1684 .link_update = mrvl_link_update,
1685 .promiscuous_enable = mrvl_promiscuous_enable,
1686 .allmulticast_enable = mrvl_allmulticast_enable,
1687 .promiscuous_disable = mrvl_promiscuous_disable,
1688 .allmulticast_disable = mrvl_allmulticast_disable,
1689 .mac_addr_remove = mrvl_mac_addr_remove,
1690 .mac_addr_add = mrvl_mac_addr_add,
1691 .mac_addr_set = mrvl_mac_addr_set,
1692 .mtu_set = mrvl_mtu_set,
1693 .stats_get = mrvl_stats_get,
1694 .stats_reset = mrvl_stats_reset,
1695 .dev_infos_get = mrvl_dev_infos_get,
1696 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
1697 .rxq_info_get = mrvl_rxq_info_get,
1698 .txq_info_get = mrvl_txq_info_get,
1699 .vlan_filter_set = mrvl_vlan_filter_set,
1700 .rx_queue_setup = mrvl_rx_queue_setup,
1701 .rx_queue_release = mrvl_rx_queue_release,
1702 .tx_queue_setup = mrvl_tx_queue_setup,
1703 .tx_queue_release = mrvl_tx_queue_release,
1704 .rss_hash_update = mrvl_rss_hash_update,
1705 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
1706 .filter_ctrl = mrvl_eth_filter_ctrl
1710 * Return packet type information and l3/l4 offsets.
1713 * Pointer to the received packet descriptor.
1720 * Packet type information.
1722 static inline uint64_t
1723 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
1724 uint8_t *l3_offset, uint8_t *l4_offset)
1726 enum pp2_inq_l3_type l3_type;
1727 enum pp2_inq_l4_type l4_type;
1728 uint64_t packet_type;
1730 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
1731 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
1733 packet_type = RTE_PTYPE_L2_ETHER;
1736 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
1737 packet_type |= RTE_PTYPE_L3_IPV4;
1739 case PP2_INQ_L3_TYPE_IPV4_OK:
1740 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
1742 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
1743 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
1745 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
1746 packet_type |= RTE_PTYPE_L3_IPV6;
1748 case PP2_INQ_L3_TYPE_IPV6_EXT:
1749 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
1751 case PP2_INQ_L3_TYPE_ARP:
1752 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
1754 * In case of ARP l4_offset is set to wrong value.
1755 * Set it to proper one so that later on mbuf->l3_len can be
1756 * calculated subtracting l4_offset and l3_offset.
1758 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
1761 RTE_LOG(DEBUG, PMD, "Failed to recognise l3 packet type\n");
1766 case PP2_INQ_L4_TYPE_TCP:
1767 packet_type |= RTE_PTYPE_L4_TCP;
1769 case PP2_INQ_L4_TYPE_UDP:
1770 packet_type |= RTE_PTYPE_L4_UDP;
1773 RTE_LOG(DEBUG, PMD, "Failed to recognise l4 packet type\n");
1781 * Get offload information from the received packet descriptor.
1784 * Pointer to the received packet descriptor.
1787 * Mbuf offload flags.
1789 static inline uint64_t
1790 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
1793 enum pp2_inq_desc_status status;
1795 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
1796 if (unlikely(status != PP2_DESC_ERR_OK))
1797 flags = PKT_RX_IP_CKSUM_BAD;
1799 flags = PKT_RX_IP_CKSUM_GOOD;
1801 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
1802 if (unlikely(status != PP2_DESC_ERR_OK))
1803 flags |= PKT_RX_L4_CKSUM_BAD;
1805 flags |= PKT_RX_L4_CKSUM_GOOD;
1811 * DPDK callback for receive.
1814 * Generic pointer to the receive queue.
1816 * Array to store received packets.
1818 * Maximum number of packets in array.
1821 * Number of packets successfully received.
1824 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1826 struct mrvl_rxq *q = rxq;
1827 struct pp2_ppio_desc descs[nb_pkts];
1828 struct pp2_bpool *bpool;
1829 int i, ret, rx_done = 0;
1831 struct pp2_hif *hif;
1832 unsigned int core_id = rte_lcore_id();
1834 hif = mrvl_get_hif(q->priv, core_id);
1836 if (unlikely(!q->priv->ppio || !hif))
1839 bpool = q->priv->bpool;
1841 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
1842 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
1843 if (unlikely(ret < 0)) {
1844 RTE_LOG(ERR, PMD, "Failed to receive packets\n");
1847 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
1849 for (i = 0; i < nb_pkts; i++) {
1850 struct rte_mbuf *mbuf;
1851 uint8_t l3_offset, l4_offset;
1852 enum pp2_inq_desc_status status;
1855 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
1856 struct pp2_ppio_desc *pref_desc;
1859 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
1860 pref_addr = cookie_addr_high |
1861 pp2_ppio_inq_desc_get_cookie(pref_desc);
1862 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
1863 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
1866 addr = cookie_addr_high |
1867 pp2_ppio_inq_desc_get_cookie(&descs[i]);
1868 mbuf = (struct rte_mbuf *)addr;
1869 rte_pktmbuf_reset(mbuf);
1871 /* drop packet in case of mac, overrun or resource error */
1872 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
1873 if (unlikely(status != PP2_DESC_ERR_OK)) {
1874 struct pp2_buff_inf binf = {
1875 .addr = rte_mbuf_data_iova_default(mbuf),
1876 .cookie = (pp2_cookie_t)(uint64_t)mbuf,
1879 pp2_bpool_put_buff(hif, bpool, &binf);
1880 mrvl_port_bpool_size
1881 [bpool->pp2_id][bpool->id][core_id]++;
1886 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
1887 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
1888 mbuf->data_len = mbuf->pkt_len;
1889 mbuf->port = q->port_id;
1891 mrvl_desc_to_packet_type_and_offset(&descs[i],
1894 mbuf->l2_len = l3_offset;
1895 mbuf->l3_len = l4_offset - l3_offset;
1897 if (likely(q->cksum_enabled))
1898 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
1900 rx_pkts[rx_done++] = mbuf;
1901 q->bytes_recv += mbuf->pkt_len;
1904 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
1905 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
1907 if (unlikely(num <= q->priv->bpool_min_size ||
1908 (!rx_done && num < q->priv->bpool_init_size))) {
1909 ret = mrvl_fill_bpool(q, MRVL_BURST_SIZE);
1911 RTE_LOG(ERR, PMD, "Failed to fill bpool\n");
1912 } else if (unlikely(num > q->priv->bpool_max_size)) {
1914 int pkt_to_remove = num - q->priv->bpool_init_size;
1915 struct rte_mbuf *mbuf;
1916 struct pp2_buff_inf buff;
1919 "\nport-%d:%d: bpool %d oversize - remove %d buffers (pool size: %d -> %d)\n",
1920 bpool->pp2_id, q->priv->ppio->port_id,
1921 bpool->id, pkt_to_remove, num,
1922 q->priv->bpool_init_size);
1924 for (i = 0; i < pkt_to_remove; i++) {
1925 ret = pp2_bpool_get_buff(hif, bpool, &buff);
1928 mbuf = (struct rte_mbuf *)
1929 (cookie_addr_high | buff.cookie);
1930 rte_pktmbuf_free(mbuf);
1932 mrvl_port_bpool_size
1933 [bpool->pp2_id][bpool->id][core_id] -= i;
1935 rte_spinlock_unlock(&q->priv->lock);
1942 * Prepare offload information.
1946 * @param packet_type
1947 * Packet type bitfield.
1949 * Pointer to the pp2_ouq_l3_type structure.
1951 * Pointer to the pp2_outq_l4_type structure.
1952 * @param gen_l3_cksum
1953 * Will be set to 1 in case l3 checksum is computed.
1955 * Will be set to 1 in case l4 checksum is computed.
1958 * 0 on success, negative error value otherwise.
1961 mrvl_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
1962 enum pp2_outq_l3_type *l3_type,
1963 enum pp2_outq_l4_type *l4_type,
1968 * Based on ol_flags prepare information
1969 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
1972 if (ol_flags & PKT_TX_IPV4) {
1973 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
1974 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
1975 } else if (ol_flags & PKT_TX_IPV6) {
1976 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
1977 /* no checksum for ipv6 header */
1980 /* if something different then stop processing */
1984 ol_flags &= PKT_TX_L4_MASK;
1985 if ((packet_type & RTE_PTYPE_L4_TCP) &&
1986 ol_flags == PKT_TX_TCP_CKSUM) {
1987 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
1989 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
1990 ol_flags == PKT_TX_UDP_CKSUM) {
1991 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
1994 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
1995 /* no checksum for other type */
2003 * Release already sent buffers to bpool (buffer-pool).
2006 * Pointer to the port structure.
2008 * Pointer to the MUSDK hardware interface.
2010 * Pointer to the shadow queue.
2014 * Force releasing packets.
2017 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
2018 unsigned int core_id, struct mrvl_shadow_txq *sq,
2021 struct buff_release_entry *entry;
2022 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
2025 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
2027 sq->num_to_release += nb_done;
2029 if (likely(!force &&
2030 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
2033 nb_done = sq->num_to_release;
2034 sq->num_to_release = 0;
2036 for (i = 0; i < nb_done; i++) {
2037 entry = &sq->ent[sq->tail + num];
2038 if (unlikely(!entry->buff.addr)) {
2040 "Shadow memory @%d: cookie(%lx), pa(%lx)!\n",
2041 sq->tail, (u64)entry->buff.cookie,
2042 (u64)entry->buff.addr);
2047 if (unlikely(!entry->bpool)) {
2048 struct rte_mbuf *mbuf;
2050 mbuf = (struct rte_mbuf *)
2051 (cookie_addr_high | entry->buff.cookie);
2052 rte_pktmbuf_free(mbuf);
2057 mrvl_port_bpool_size
2058 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
2060 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
2065 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2067 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2074 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
2075 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
2081 * DPDK callback for transmit.
2084 * Generic pointer transmit queue.
2086 * Packets to transmit.
2088 * Number of packets in array.
2091 * Number of packets successfully transmitted.
2094 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2096 struct mrvl_txq *q = txq;
2097 struct mrvl_shadow_txq *sq;
2098 struct pp2_hif *hif;
2099 struct pp2_ppio_desc descs[nb_pkts];
2100 unsigned int core_id = rte_lcore_id();
2101 int i, ret, bytes_sent = 0;
2102 uint16_t num, sq_free_size;
2105 hif = mrvl_get_hif(q->priv, core_id);
2106 sq = &q->shadow_txqs[core_id];
2108 if (unlikely(!q->priv->ppio || !hif))
2112 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
2113 sq, q->queue_id, 0);
2115 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
2116 if (unlikely(nb_pkts > sq_free_size)) {
2118 "No room in shadow queue for %d packets! %d packets will be sent.\n",
2119 nb_pkts, sq_free_size);
2120 nb_pkts = sq_free_size;
2123 for (i = 0; i < nb_pkts; i++) {
2124 struct rte_mbuf *mbuf = tx_pkts[i];
2125 int gen_l3_cksum, gen_l4_cksum;
2126 enum pp2_outq_l3_type l3_type;
2127 enum pp2_outq_l4_type l4_type;
2129 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
2130 struct rte_mbuf *pref_pkt_hdr;
2132 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
2133 rte_mbuf_prefetch_part1(pref_pkt_hdr);
2134 rte_mbuf_prefetch_part2(pref_pkt_hdr);
2137 sq->ent[sq->head].buff.cookie = (pp2_cookie_t)(uint64_t)mbuf;
2138 sq->ent[sq->head].buff.addr =
2139 rte_mbuf_data_iova_default(mbuf);
2140 sq->ent[sq->head].bpool =
2141 (unlikely(mbuf->port >= RTE_MAX_ETHPORTS ||
2142 mbuf->refcnt > 1)) ? NULL :
2143 mrvl_port_to_bpool_lookup[mbuf->port];
2144 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
2147 pp2_ppio_outq_desc_reset(&descs[i]);
2148 pp2_ppio_outq_desc_set_phys_addr(&descs[i],
2149 rte_pktmbuf_iova(mbuf));
2150 pp2_ppio_outq_desc_set_pkt_offset(&descs[i], 0);
2151 pp2_ppio_outq_desc_set_pkt_len(&descs[i],
2152 rte_pktmbuf_pkt_len(mbuf));
2154 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
2156 * in case unsupported ol_flags were passed
2157 * do not update descriptor offload information
2159 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
2160 &l3_type, &l4_type, &gen_l3_cksum,
2165 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2167 mbuf->l2_len + mbuf->l3_len,
2168 gen_l3_cksum, gen_l4_cksum);
2172 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2173 /* number of packets that were not sent */
2174 if (unlikely(num > nb_pkts)) {
2175 for (i = nb_pkts; i < num; i++) {
2176 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2177 MRVL_PP2_TX_SHADOWQ_MASK;
2178 addr = cookie_addr_high | sq->ent[sq->head].buff.cookie;
2180 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2182 sq->size -= num - nb_pkts;
2185 q->bytes_sent += bytes_sent;
2191 * Initialize packet processor.
2194 * 0 on success, negative error value otherwise.
2199 struct pp2_init_params init_params;
2201 memset(&init_params, 0, sizeof(init_params));
2202 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2203 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2204 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2206 return pp2_init(&init_params);
2210 * Deinitialize packet processor.
2213 * 0 on success, negative error value otherwise.
2216 mrvl_deinit_pp2(void)
2222 * Create private device structure.
2225 * Pointer to the port name passed in the initialization parameters.
2228 * Pointer to the newly allocated private device structure.
2230 static struct mrvl_priv *
2231 mrvl_priv_create(const char *dev_name)
2233 struct pp2_bpool_params bpool_params;
2234 char match[MRVL_MATCH_LEN];
2235 struct mrvl_priv *priv;
2238 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2242 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2243 &priv->pp_id, &priv->ppio_id);
2247 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2248 PP2_BPOOL_NUM_POOLS);
2251 priv->bpool_bit = bpool_bit;
2253 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2255 memset(&bpool_params, 0, sizeof(bpool_params));
2256 bpool_params.match = match;
2257 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2258 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2260 goto out_clear_bpool_bit;
2262 priv->ppio_params.type = PP2_PPIO_T_NIC;
2263 rte_spinlock_init(&priv->lock);
2266 out_clear_bpool_bit:
2267 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2274 * Create device representing Ethernet port.
2277 * Pointer to the port's name.
2280 * 0 on success, negative error value otherwise.
2283 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2285 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2286 struct rte_eth_dev *eth_dev;
2287 struct mrvl_priv *priv;
2290 eth_dev = rte_eth_dev_allocate(name);
2294 priv = mrvl_priv_create(name);
2300 eth_dev->data->mac_addrs =
2301 rte_zmalloc("mac_addrs",
2302 ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2303 if (!eth_dev->data->mac_addrs) {
2304 RTE_LOG(ERR, PMD, "Failed to allocate space for eth addrs\n");
2309 memset(&req, 0, sizeof(req));
2310 strcpy(req.ifr_name, name);
2311 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2315 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2316 req.ifr_addr.sa_data, ETHER_ADDR_LEN);
2318 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2319 eth_dev->tx_pkt_burst = mrvl_tx_pkt_burst;
2320 eth_dev->data->kdrv = RTE_KDRV_NONE;
2321 eth_dev->data->dev_private = priv;
2322 eth_dev->device = &vdev->device;
2323 eth_dev->dev_ops = &mrvl_ops;
2327 rte_free(eth_dev->data->mac_addrs);
2329 rte_eth_dev_release_port(eth_dev);
2337 * Cleanup previously created device representing Ethernet port.
2340 * Pointer to the port name.
2343 mrvl_eth_dev_destroy(const char *name)
2345 struct rte_eth_dev *eth_dev;
2346 struct mrvl_priv *priv;
2348 eth_dev = rte_eth_dev_allocated(name);
2352 priv = eth_dev->data->dev_private;
2353 pp2_bpool_deinit(priv->bpool);
2354 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2356 rte_free(eth_dev->data->mac_addrs);
2357 rte_eth_dev_release_port(eth_dev);
2361 * Callback used by rte_kvargs_process() during argument parsing.
2364 * Pointer to the parsed key (unused).
2366 * Pointer to the parsed value.
2368 * Pointer to the extra arguments which contains address of the
2369 * table of pointers to parsed interface names.
2375 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
2378 struct mrvl_ifnames *ifnames = extra_args;
2380 ifnames->names[ifnames->idx++] = value;
2386 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
2389 mrvl_deinit_hifs(void)
2393 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
2395 pp2_hif_deinit(hifs[i]);
2397 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
2398 memset(hifs, 0, sizeof(hifs));
2402 * DPDK callback to register the virtual device.
2405 * Pointer to the virtual device.
2408 * 0 on success, negative error value otherwise.
2411 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
2413 struct rte_kvargs *kvlist;
2414 struct mrvl_ifnames ifnames;
2416 uint32_t i, ifnum, cfgnum;
2419 params = rte_vdev_device_args(vdev);
2423 kvlist = rte_kvargs_parse(params, valid_args);
2427 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
2428 if (ifnum > RTE_DIM(ifnames.names))
2429 goto out_free_kvlist;
2432 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
2433 mrvl_get_ifnames, &ifnames);
2437 * The below system initialization should be done only once,
2438 * on the first provided configuration file
2440 if (!mrvl_qos_cfg) {
2441 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
2442 RTE_LOG(INFO, PMD, "Parsing config file!\n");
2444 RTE_LOG(ERR, PMD, "Cannot handle more than one config file!\n");
2445 goto out_free_kvlist;
2446 } else if (cfgnum == 1) {
2447 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
2448 mrvl_get_qoscfg, &mrvl_qos_cfg);
2455 RTE_LOG(INFO, PMD, "Perform MUSDK initializations\n");
2457 * ret == -EEXIST is correct, it means DMA
2458 * has been already initialized (by another PMD).
2460 ret = mv_sys_dma_mem_init(MRVL_MUSDK_DMA_MEMSIZE);
2463 goto out_free_kvlist;
2466 "DMA memory has been already initialized by a different driver.\n");
2469 ret = mrvl_init_pp2();
2471 RTE_LOG(ERR, PMD, "Failed to init PP!\n");
2472 goto out_deinit_dma;
2475 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
2476 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup));
2478 mrvl_lcore_first = RTE_MAX_LCORE;
2479 mrvl_lcore_last = 0;
2482 for (i = 0; i < ifnum; i++) {
2483 RTE_LOG(INFO, PMD, "Creating %s\n", ifnames.names[i]);
2484 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
2488 mrvl_dev_num += ifnum;
2490 rte_kvargs_free(kvlist);
2495 mrvl_eth_dev_destroy(ifnames.names[i]);
2497 if (mrvl_dev_num == 0)
2500 if (mrvl_dev_num == 0)
2501 mv_sys_dma_mem_destroy();
2503 rte_kvargs_free(kvlist);
2509 * DPDK callback to remove virtual device.
2512 * Pointer to the removed virtual device.
2515 * 0 on success, negative error value otherwise.
2518 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
2523 name = rte_vdev_device_name(vdev);
2527 RTE_LOG(INFO, PMD, "Removing %s\n", name);
2529 for (i = 0; i < rte_eth_dev_count(); i++) {
2530 char ifname[RTE_ETH_NAME_MAX_LEN];
2532 rte_eth_dev_get_name_by_port(i, ifname);
2533 mrvl_eth_dev_destroy(ifname);
2537 if (mrvl_dev_num == 0) {
2538 RTE_LOG(INFO, PMD, "Perform MUSDK deinit\n");
2541 mv_sys_dma_mem_destroy();
2547 static struct rte_vdev_driver pmd_mrvl_drv = {
2548 .probe = rte_pmd_mrvl_probe,
2549 .remove = rte_pmd_mrvl_remove,
2552 RTE_PMD_REGISTER_VDEV(net_mrvl, pmd_mrvl_drv);
2553 RTE_PMD_REGISTER_ALIAS(net_mrvl, eth_mrvl);