4 * Copyright(c) 2017 Marvell International Ltd.
5 * Copyright(c) 2017 Semihalf.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Semihalf nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_ethdev.h>
36 #include <rte_kvargs.h>
38 #include <rte_malloc.h>
39 #include <rte_bus_vdev.h>
41 /* Unluckily, container_of is defined by both DPDK and MUSDK,
42 * we'll declare only one version.
44 * Note that it is not used in this PMD anyway.
50 #include <drivers/mv_pp2.h>
51 #include <drivers/mv_pp2_bpool.h>
52 #include <drivers/mv_pp2_hif.h>
55 #include <linux/ethtool.h>
56 #include <linux/sockios.h>
58 #include <net/if_arp.h>
59 #include <sys/ioctl.h>
60 #include <sys/socket.h>
62 #include <sys/types.h>
64 #include "mrvl_ethdev.h"
67 /* bitmask with reserved hifs */
68 #define MRVL_MUSDK_HIFS_RESERVED 0x0F
69 /* bitmask with reserved bpools */
70 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07
71 /* bitmask with reserved kernel RSS tables */
72 #define MRVL_MUSDK_RSS_RESERVED 0x01
73 /* maximum number of available hifs */
74 #define MRVL_MUSDK_HIFS_MAX 9
77 #define MRVL_MUSDK_PREFETCH_SHIFT 2
79 /* TCAM has 25 entries reserved for uc/mc filter entries */
80 #define MRVL_MAC_ADDRS_MAX 25
81 #define MRVL_MATCH_LEN 16
82 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
83 /* Maximum allowable packet size */
84 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
86 #define MRVL_IFACE_NAME_ARG "iface"
87 #define MRVL_CFG_ARG "cfg"
89 #define MRVL_BURST_SIZE 64
91 #define MRVL_ARP_LENGTH 28
93 #define MRVL_COOKIE_ADDR_INVALID ~0ULL
95 #define MRVL_COOKIE_HIGH_ADDR_SHIFT (sizeof(pp2_cookie_t) * 8)
96 #define MRVL_COOKIE_HIGH_ADDR_MASK (~0ULL << MRVL_COOKIE_HIGH_ADDR_SHIFT)
98 /* Memory size (in bytes) for MUSDK dma buffers */
99 #define MRVL_MUSDK_DMA_MEMSIZE 41943040
101 static const char * const valid_args[] = {
107 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
108 static struct pp2_hif *hifs[RTE_MAX_LCORE];
109 static int used_bpools[PP2_NUM_PKT_PROC] = {
110 MRVL_MUSDK_BPOOLS_RESERVED,
111 MRVL_MUSDK_BPOOLS_RESERVED
114 struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS];
115 int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE];
116 uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
118 struct mrvl_ifnames {
119 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
124 * To use buffer harvesting based on loopback port shadow queue structure
125 * was introduced for buffers information bookkeeping.
127 * Before sending the packet, related buffer information (pp2_buff_inf) is
128 * stored in shadow queue. After packet is transmitted no longer used
129 * packet buffer is released back to it's original hardware pool,
130 * on condition it originated from interface.
131 * In case it was generated by application itself i.e: mbuf->port field is
132 * 0xff then its released to software mempool.
134 struct mrvl_shadow_txq {
135 int head; /* write index - used when sending buffers */
136 int tail; /* read index - used when releasing buffers */
137 u16 size; /* queue occupied size */
138 u16 num_to_release; /* number of buffers sent, that can be released */
139 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */
143 struct mrvl_priv *priv;
144 struct rte_mempool *mp;
153 struct mrvl_priv *priv;
157 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE];
160 static int mrvl_lcore_first;
161 static int mrvl_lcore_last;
162 static int mrvl_dev_num;
164 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num);
165 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio,
166 struct pp2_hif *hif, unsigned int core_id,
167 struct mrvl_shadow_txq *sq, int qid, int force);
170 mrvl_get_bpool_size(int pp2_id, int pool_id)
175 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++)
176 size += mrvl_port_bpool_size[pp2_id][pool_id][i];
182 mrvl_reserve_bit(int *bitmap, int max)
184 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
195 mrvl_init_hif(int core_id)
197 struct pp2_hif_params params;
198 char match[MRVL_MATCH_LEN];
201 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
203 RTE_LOG(ERR, PMD, "Failed to allocate hif %d\n", core_id);
207 snprintf(match, sizeof(match), "hif-%d", ret);
208 memset(¶ms, 0, sizeof(params));
209 params.match = match;
210 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
211 ret = pp2_hif_init(¶ms, &hifs[core_id]);
213 RTE_LOG(ERR, PMD, "Failed to initialize hif %d\n", core_id);
220 static inline struct pp2_hif*
221 mrvl_get_hif(struct mrvl_priv *priv, int core_id)
225 if (likely(hifs[core_id] != NULL))
226 return hifs[core_id];
228 rte_spinlock_lock(&priv->lock);
230 ret = mrvl_init_hif(core_id);
232 RTE_LOG(ERR, PMD, "Failed to allocate hif %d\n", core_id);
236 if (core_id < mrvl_lcore_first)
237 mrvl_lcore_first = core_id;
239 if (core_id > mrvl_lcore_last)
240 mrvl_lcore_last = core_id;
242 rte_spinlock_unlock(&priv->lock);
244 return hifs[core_id];
248 * Configure rss based on dpdk rss configuration.
251 * Pointer to private structure.
253 * Pointer to RSS configuration.
256 * 0 on success, negative error value otherwise.
259 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf)
261 if (rss_conf->rss_key)
262 RTE_LOG(WARNING, PMD, "Changing hash key is not supported\n");
264 if (rss_conf->rss_hf == 0) {
265 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
266 } else if (rss_conf->rss_hf & ETH_RSS_IPV4) {
267 priv->ppio_params.inqs_params.hash_type =
268 PP2_PPIO_HASH_T_2_TUPLE;
269 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
270 priv->ppio_params.inqs_params.hash_type =
271 PP2_PPIO_HASH_T_5_TUPLE;
272 priv->rss_hf_tcp = 1;
273 } else if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
274 priv->ppio_params.inqs_params.hash_type =
275 PP2_PPIO_HASH_T_5_TUPLE;
276 priv->rss_hf_tcp = 0;
285 * Ethernet device configuration.
287 * Prepare the driver for a given number of TX and RX queues and
291 * Pointer to Ethernet device structure.
294 * 0 on success, negative error value otherwise.
297 mrvl_dev_configure(struct rte_eth_dev *dev)
299 struct mrvl_priv *priv = dev->data->dev_private;
302 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE &&
303 dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
304 RTE_LOG(INFO, PMD, "Unsupported rx multi queue mode %d\n",
305 dev->data->dev_conf.rxmode.mq_mode);
309 if (!dev->data->dev_conf.rxmode.hw_strip_crc) {
311 "L2 CRC stripping is always enabled in hw\n");
312 dev->data->dev_conf.rxmode.hw_strip_crc = 1;
315 if (dev->data->dev_conf.rxmode.hw_vlan_strip) {
316 RTE_LOG(INFO, PMD, "VLAN stripping not supported\n");
320 if (dev->data->dev_conf.rxmode.split_hdr_size) {
321 RTE_LOG(INFO, PMD, "Split headers not supported\n");
325 if (dev->data->dev_conf.rxmode.enable_scatter) {
326 RTE_LOG(INFO, PMD, "RX Scatter/Gather not supported\n");
330 if (dev->data->dev_conf.rxmode.enable_lro) {
331 RTE_LOG(INFO, PMD, "LRO not supported\n");
335 if (dev->data->dev_conf.rxmode.jumbo_frame)
336 dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
337 ETHER_HDR_LEN - ETHER_CRC_LEN;
339 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
340 dev->data->nb_rx_queues);
344 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
345 priv->ppio_params.maintain_stats = 1;
346 priv->nb_rx_queues = dev->data->nb_rx_queues;
348 if (dev->data->nb_rx_queues == 1 &&
349 dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
350 RTE_LOG(WARNING, PMD, "Disabling hash for 1 rx queue\n");
351 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE;
356 return mrvl_configure_rss(priv,
357 &dev->data->dev_conf.rx_adv_conf.rss_conf);
361 * DPDK callback to change the MTU.
363 * Setting the MTU affects hardware MRU (packets larger than the MRU
367 * Pointer to Ethernet device structure.
372 * 0 on success, negative error value otherwise.
375 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
377 struct mrvl_priv *priv = dev->data->dev_private;
378 /* extra MV_MH_SIZE bytes are required for Marvell tag */
379 uint16_t mru = mtu + MV_MH_SIZE + ETHER_HDR_LEN + ETHER_CRC_LEN;
382 if (mtu < ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX)
385 ret = pp2_ppio_set_mru(priv->ppio, mru);
389 return pp2_ppio_set_mtu(priv->ppio, mtu);
393 * DPDK callback to bring the link up.
396 * Pointer to Ethernet device structure.
399 * 0 on success, negative error value otherwise.
402 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
404 struct mrvl_priv *priv = dev->data->dev_private;
407 ret = pp2_ppio_enable(priv->ppio);
412 * mtu/mru can be updated if pp2_ppio_enable() was called at least once
413 * as pp2_ppio_enable() changes port->t_mode from default 0 to
414 * PP2_TRAFFIC_INGRESS_EGRESS.
416 * Set mtu to default DPDK value here.
418 ret = mrvl_mtu_set(dev, dev->data->mtu);
420 pp2_ppio_disable(priv->ppio);
422 dev->data->dev_link.link_status = ETH_LINK_UP;
428 * DPDK callback to bring the link down.
431 * Pointer to Ethernet device structure.
434 * 0 on success, negative error value otherwise.
437 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
439 struct mrvl_priv *priv = dev->data->dev_private;
442 ret = pp2_ppio_disable(priv->ppio);
446 dev->data->dev_link.link_status = ETH_LINK_DOWN;
452 * DPDK callback to start the device.
455 * Pointer to Ethernet device structure.
458 * 0 on success, negative errno value on failure.
461 mrvl_dev_start(struct rte_eth_dev *dev)
463 struct mrvl_priv *priv = dev->data->dev_private;
464 char match[MRVL_MATCH_LEN];
465 int ret = 0, def_init_size;
467 snprintf(match, sizeof(match), "ppio-%d:%d",
468 priv->pp_id, priv->ppio_id);
469 priv->ppio_params.match = match;
472 * Calculate the minimum bpool size for refill feature as follows:
473 * 2 default burst sizes multiply by number of rx queues.
474 * If the bpool size will be below this value, new buffers will
475 * be added to the pool.
477 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
479 /* In case initial bpool size configured in queues setup is
480 * smaller than minimum size add more buffers
482 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2;
483 if (priv->bpool_init_size < def_init_size) {
484 int buffs_to_add = def_init_size - priv->bpool_init_size;
486 priv->bpool_init_size += buffs_to_add;
487 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add);
489 RTE_LOG(ERR, PMD, "Failed to add buffers to bpool\n");
493 * Calculate the maximum bpool size for refill feature as follows:
494 * maximum number of descriptors in rx queue multiply by number
495 * of rx queues plus minimum bpool size.
496 * In case the bpool size will exceed this value, superfluous buffers
499 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) +
500 priv->bpool_min_size;
502 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
507 * In case there are some some stale uc/mc mac addresses flush them
508 * here. It cannot be done during mrvl_dev_close() as port information
509 * is already gone at that point (due to pp2_ppio_deinit() in
512 if (!priv->uc_mc_flushed) {
513 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1);
516 "Failed to flush uc/mc filter list\n");
519 priv->uc_mc_flushed = 1;
522 if (!priv->vlan_flushed) {
523 ret = pp2_ppio_flush_vlan(priv->ppio);
525 RTE_LOG(ERR, PMD, "Failed to flush vlan list\n");
528 * once pp2_ppio_flush_vlan() is supported jump to out
532 priv->vlan_flushed = 1;
535 /* For default QoS config, don't start classifier. */
537 ret = mrvl_start_qos_mapping(priv);
539 pp2_ppio_deinit(priv->ppio);
544 ret = mrvl_dev_set_link_up(dev);
550 pp2_ppio_deinit(priv->ppio);
555 * Flush receive queues.
558 * Pointer to Ethernet device structure.
561 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
565 RTE_LOG(INFO, PMD, "Flushing rx queues\n");
566 for (i = 0; i < dev->data->nb_rx_queues; i++) {
570 struct mrvl_rxq *q = dev->data->rx_queues[i];
571 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
573 num = MRVL_PP2_RXD_MAX;
574 ret = pp2_ppio_recv(q->priv->ppio,
575 q->priv->rxq_map[q->queue_id].tc,
576 q->priv->rxq_map[q->queue_id].inq,
577 descs, (uint16_t *)&num);
578 } while (ret == 0 && num);
583 * Flush transmit shadow queues.
586 * Pointer to Ethernet device structure.
589 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev)
592 struct mrvl_txq *txq;
594 RTE_LOG(INFO, PMD, "Flushing tx shadow queues\n");
595 for (i = 0; i < dev->data->nb_tx_queues; i++) {
596 txq = (struct mrvl_txq *)dev->data->tx_queues[i];
598 for (j = 0; j < RTE_MAX_LCORE; j++) {
599 struct mrvl_shadow_txq *sq;
604 sq = &txq->shadow_txqs[j];
605 mrvl_free_sent_buffers(txq->priv->ppio,
606 hifs[j], j, sq, txq->queue_id, 1);
607 while (sq->tail != sq->head) {
608 uint64_t addr = cookie_addr_high |
609 sq->ent[sq->tail].buff.cookie;
611 (struct rte_mbuf *)addr);
612 sq->tail = (sq->tail + 1) &
613 MRVL_PP2_TX_SHADOWQ_MASK;
615 memset(sq, 0, sizeof(*sq));
621 * Flush hardware bpool (buffer-pool).
624 * Pointer to Ethernet device structure.
627 mrvl_flush_bpool(struct rte_eth_dev *dev)
629 struct mrvl_priv *priv = dev->data->dev_private;
633 unsigned int core_id = rte_lcore_id();
635 if (core_id == LCORE_ID_ANY)
638 hif = mrvl_get_hif(priv, core_id);
640 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
642 RTE_LOG(ERR, PMD, "Failed to get bpool buffers number\n");
647 struct pp2_buff_inf inf;
650 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf);
654 addr = cookie_addr_high | inf.cookie;
655 rte_pktmbuf_free((struct rte_mbuf *)addr);
660 * DPDK callback to stop the device.
663 * Pointer to Ethernet device structure.
666 mrvl_dev_stop(struct rte_eth_dev *dev)
668 struct mrvl_priv *priv = dev->data->dev_private;
670 mrvl_dev_set_link_down(dev);
671 mrvl_flush_rx_queues(dev);
672 mrvl_flush_tx_shadow_queues(dev);
674 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
675 priv->qos_tbl = NULL;
678 pp2_ppio_deinit(priv->ppio);
683 * DPDK callback to close the device.
686 * Pointer to Ethernet device structure.
689 mrvl_dev_close(struct rte_eth_dev *dev)
691 struct mrvl_priv *priv = dev->data->dev_private;
694 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
695 struct pp2_ppio_tc_params *tc_params =
696 &priv->ppio_params.inqs_params.tcs_params[i];
698 if (tc_params->inqs_params) {
699 rte_free(tc_params->inqs_params);
700 tc_params->inqs_params = NULL;
704 mrvl_flush_bpool(dev);
708 * DPDK callback to retrieve physical link information.
711 * Pointer to Ethernet device structure.
712 * @param wait_to_complete
713 * Wait for request completion (ignored).
716 * 0 on success, negative error value otherwise.
719 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
723 * once MUSDK provides necessary API use it here
725 struct ethtool_cmd edata;
729 edata.cmd = ETHTOOL_GSET;
731 strcpy(req.ifr_name, dev->data->name);
732 req.ifr_data = (void *)&edata;
734 fd = socket(AF_INET, SOCK_DGRAM, 0);
738 ret = ioctl(fd, SIOCETHTOOL, &req);
746 switch (ethtool_cmd_speed(&edata)) {
748 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10M;
751 dev->data->dev_link.link_speed = ETH_SPEED_NUM_100M;
754 dev->data->dev_link.link_speed = ETH_SPEED_NUM_1G;
757 dev->data->dev_link.link_speed = ETH_SPEED_NUM_10G;
760 dev->data->dev_link.link_speed = ETH_SPEED_NUM_NONE;
763 dev->data->dev_link.link_duplex = edata.duplex ? ETH_LINK_FULL_DUPLEX :
764 ETH_LINK_HALF_DUPLEX;
765 dev->data->dev_link.link_autoneg = edata.autoneg ? ETH_LINK_AUTONEG :
772 * DPDK callback to enable promiscuous mode.
775 * Pointer to Ethernet device structure.
778 mrvl_promiscuous_enable(struct rte_eth_dev *dev)
780 struct mrvl_priv *priv = dev->data->dev_private;
783 ret = pp2_ppio_set_uc_promisc(priv->ppio, 1);
785 RTE_LOG(ERR, PMD, "Failed to enable promiscuous mode\n");
789 * DPDK callback to enable allmulti mode.
792 * Pointer to Ethernet device structure.
795 mrvl_allmulticast_enable(struct rte_eth_dev *dev)
797 struct mrvl_priv *priv = dev->data->dev_private;
800 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
802 RTE_LOG(ERR, PMD, "Failed enable all-multicast mode\n");
806 * DPDK callback to disable promiscuous mode.
809 * Pointer to Ethernet device structure.
812 mrvl_promiscuous_disable(struct rte_eth_dev *dev)
814 struct mrvl_priv *priv = dev->data->dev_private;
817 ret = pp2_ppio_set_uc_promisc(priv->ppio, 0);
819 RTE_LOG(ERR, PMD, "Failed to disable promiscuous mode\n");
823 * DPDK callback to disable allmulticast mode.
826 * Pointer to Ethernet device structure.
829 mrvl_allmulticast_disable(struct rte_eth_dev *dev)
831 struct mrvl_priv *priv = dev->data->dev_private;
834 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
836 RTE_LOG(ERR, PMD, "Failed to disable all-multicast mode\n");
840 * DPDK callback to remove a MAC address.
843 * Pointer to Ethernet device structure.
848 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
850 struct mrvl_priv *priv = dev->data->dev_private;
851 char buf[ETHER_ADDR_FMT_SIZE];
854 ret = pp2_ppio_remove_mac_addr(priv->ppio,
855 dev->data->mac_addrs[index].addr_bytes);
857 ether_format_addr(buf, sizeof(buf),
858 &dev->data->mac_addrs[index]);
859 RTE_LOG(ERR, PMD, "Failed to remove mac %s\n", buf);
864 * DPDK callback to add a MAC address.
867 * Pointer to Ethernet device structure.
869 * MAC address to register.
873 * VMDq pool index to associate address with (unused).
876 * 0 on success, negative error value otherwise.
879 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
880 uint32_t index, uint32_t vmdq __rte_unused)
882 struct mrvl_priv *priv = dev->data->dev_private;
883 char buf[ETHER_ADDR_FMT_SIZE];
887 /* For setting index 0, mrvl_mac_addr_set() should be used.*/
891 * Maximum number of uc addresses can be tuned via kernel module mvpp2x
892 * parameter uc_filter_max. Maximum number of mc addresses is then
893 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and
896 * If more than uc_filter_max uc addresses were added to filter list
897 * then NIC will switch to promiscuous mode automatically.
899 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses
900 * were added to filter list then NIC will switch to all-multicast mode
903 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes);
905 ether_format_addr(buf, sizeof(buf), mac_addr);
906 RTE_LOG(ERR, PMD, "Failed to add mac %s\n", buf);
914 * DPDK callback to set the primary MAC address.
917 * Pointer to Ethernet device structure.
919 * MAC address to register.
922 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
924 struct mrvl_priv *priv = dev->data->dev_private;
926 pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
929 * Port stops sending packets if pp2_ppio_set_mac_addr()
930 * was called after pp2_ppio_enable(). As a quick fix issue
931 * enable port once again.
933 pp2_ppio_enable(priv->ppio);
937 * DPDK callback to get device statistics.
940 * Pointer to Ethernet device structure.
942 * Stats structure output buffer.
945 * 0 on success, negative error value otherwise.
948 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
950 struct mrvl_priv *priv = dev->data->dev_private;
951 struct pp2_ppio_statistics ppio_stats;
952 uint64_t drop_mac = 0;
953 unsigned int i, idx, ret;
955 for (i = 0; i < dev->data->nb_rx_queues; i++) {
956 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
957 struct pp2_ppio_inq_statistics rx_stats;
963 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
965 "rx queue %d stats out of range (0 - %d)\n",
966 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
970 ret = pp2_ppio_inq_get_statistics(priv->ppio,
971 priv->rxq_map[idx].tc,
972 priv->rxq_map[idx].inq,
976 "Failed to update rx queue %d stats\n", idx);
980 stats->q_ibytes[idx] = rxq->bytes_recv;
981 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac;
982 stats->q_errors[idx] = rx_stats.drop_early +
983 rx_stats.drop_fullq +
986 stats->ibytes += rxq->bytes_recv;
987 drop_mac += rxq->drop_mac;
990 for (i = 0; i < dev->data->nb_tx_queues; i++) {
991 struct mrvl_txq *txq = dev->data->tx_queues[i];
992 struct pp2_ppio_outq_statistics tx_stats;
998 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) {
1000 "tx queue %d stats out of range (0 - %d)\n",
1001 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1004 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx,
1006 if (unlikely(ret)) {
1008 "Failed to update tx queue %d stats\n", idx);
1012 stats->q_opackets[idx] = tx_stats.deq_desc;
1013 stats->q_obytes[idx] = txq->bytes_sent;
1014 stats->obytes += txq->bytes_sent;
1017 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0);
1018 if (unlikely(ret)) {
1019 RTE_LOG(ERR, PMD, "Failed to update port statistics\n");
1023 stats->ipackets += ppio_stats.rx_packets - drop_mac;
1024 stats->opackets += ppio_stats.tx_packets;
1025 stats->imissed += ppio_stats.rx_fullq_dropped +
1026 ppio_stats.rx_bm_dropped +
1027 ppio_stats.rx_early_dropped +
1028 ppio_stats.rx_fifo_dropped +
1029 ppio_stats.rx_cls_dropped;
1030 stats->ierrors = drop_mac;
1036 * DPDK callback to clear device statistics.
1039 * Pointer to Ethernet device structure.
1042 mrvl_stats_reset(struct rte_eth_dev *dev)
1044 struct mrvl_priv *priv = dev->data->dev_private;
1047 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1048 struct mrvl_rxq *rxq = dev->data->rx_queues[i];
1050 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc,
1051 priv->rxq_map[i].inq, NULL, 1);
1052 rxq->bytes_recv = 0;
1056 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1057 struct mrvl_txq *txq = dev->data->tx_queues[i];
1059 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1);
1060 txq->bytes_sent = 0;
1063 pp2_ppio_get_statistics(priv->ppio, NULL, 1);
1067 * DPDK callback to get information about the device.
1070 * Pointer to Ethernet device structure (unused).
1072 * Info structure output buffer.
1075 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
1076 struct rte_eth_dev_info *info)
1078 info->speed_capa = ETH_LINK_SPEED_10M |
1079 ETH_LINK_SPEED_100M |
1083 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
1084 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
1085 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
1087 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
1088 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
1089 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
1091 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
1092 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
1093 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
1095 info->rx_offload_capa = DEV_RX_OFFLOAD_JUMBO_FRAME |
1096 DEV_RX_OFFLOAD_VLAN_FILTER |
1097 DEV_RX_OFFLOAD_IPV4_CKSUM |
1098 DEV_RX_OFFLOAD_UDP_CKSUM |
1099 DEV_RX_OFFLOAD_TCP_CKSUM;
1101 info->tx_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
1102 DEV_TX_OFFLOAD_UDP_CKSUM |
1103 DEV_TX_OFFLOAD_TCP_CKSUM;
1105 info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1106 ETH_RSS_NONFRAG_IPV4_TCP |
1107 ETH_RSS_NONFRAG_IPV4_UDP;
1109 /* By default packets are dropped if no descriptors are available */
1110 info->default_rxconf.rx_drop_en = 1;
1112 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
1116 * Return supported packet types.
1119 * Pointer to Ethernet device structure (unused).
1122 * Const pointer to the table with supported packet types.
1124 static const uint32_t *
1125 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1127 static const uint32_t ptypes[] = {
1130 RTE_PTYPE_L3_IPV4_EXT,
1131 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1133 RTE_PTYPE_L3_IPV6_EXT,
1134 RTE_PTYPE_L2_ETHER_ARP,
1143 * DPDK callback to get information about specific receive queue.
1146 * Pointer to Ethernet device structure.
1147 * @param rx_queue_id
1148 * Receive queue index.
1150 * Receive queue information structure.
1152 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1153 struct rte_eth_rxq_info *qinfo)
1155 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
1156 struct mrvl_priv *priv = dev->data->dev_private;
1157 int inq = priv->rxq_map[rx_queue_id].inq;
1158 int tc = priv->rxq_map[rx_queue_id].tc;
1159 struct pp2_ppio_tc_params *tc_params =
1160 &priv->ppio_params.inqs_params.tcs_params[tc];
1163 qinfo->nb_desc = tc_params->inqs_params[inq].size;
1167 * DPDK callback to get information about specific transmit queue.
1170 * Pointer to Ethernet device structure.
1171 * @param tx_queue_id
1172 * Transmit queue index.
1174 * Transmit queue information structure.
1176 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1177 struct rte_eth_txq_info *qinfo)
1179 struct mrvl_priv *priv = dev->data->dev_private;
1182 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
1186 * DPDK callback to Configure a VLAN filter.
1189 * Pointer to Ethernet device structure.
1191 * VLAN ID to filter.
1196 * 0 on success, negative error value otherwise.
1199 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1201 struct mrvl_priv *priv = dev->data->dev_private;
1203 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
1204 pp2_ppio_remove_vlan(priv->ppio, vlan_id);
1208 * Release buffers to hardware bpool (buffer-pool)
1211 * Receive queue pointer.
1213 * Number of buffers to release to bpool.
1216 * 0 on success, negative error value otherwise.
1219 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
1221 struct buff_release_entry entries[MRVL_PP2_RXD_MAX];
1222 struct rte_mbuf *mbufs[MRVL_PP2_RXD_MAX];
1224 unsigned int core_id;
1225 struct pp2_hif *hif;
1226 struct pp2_bpool *bpool;
1228 core_id = rte_lcore_id();
1229 if (core_id == LCORE_ID_ANY)
1232 hif = mrvl_get_hif(rxq->priv, core_id);
1236 bpool = rxq->priv->bpool;
1238 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
1242 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
1244 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
1246 for (i = 0; i < num; i++) {
1247 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
1248 != cookie_addr_high) {
1250 "mbuf virtual addr high 0x%lx out of range\n",
1251 (uint64_t)mbufs[i] >> 32);
1255 entries[i].buff.addr =
1256 rte_mbuf_data_iova_default(mbufs[i]);
1257 entries[i].buff.cookie = (pp2_cookie_t)(uint64_t)mbufs[i];
1258 entries[i].bpool = bpool;
1261 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
1262 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i;
1269 for (; i < num; i++)
1270 rte_pktmbuf_free(mbufs[i]);
1276 * DPDK callback to configure the receive queue.
1279 * Pointer to Ethernet device structure.
1283 * Number of descriptors to configure in queue.
1285 * NUMA socket on which memory must be allocated.
1287 * Thresholds parameters (unused_).
1289 * Memory pool for buffer allocations.
1292 * 0 on success, negative error value otherwise.
1295 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1296 unsigned int socket,
1297 const struct rte_eth_rxconf *conf __rte_unused,
1298 struct rte_mempool *mp)
1300 struct mrvl_priv *priv = dev->data->dev_private;
1301 struct mrvl_rxq *rxq;
1303 max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1306 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
1308 * Unknown TC mapping, mapping will not have a correct queue.
1310 RTE_LOG(ERR, PMD, "Unknown TC mapping for queue %hu eth%hhu\n",
1311 idx, priv->ppio_id);
1315 min_size = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM -
1316 MRVL_PKT_EFFEC_OFFS;
1317 if (min_size < max_rx_pkt_len) {
1319 "Mbuf size must be increased to %u bytes to hold up to %u bytes of data.\n",
1320 max_rx_pkt_len + RTE_PKTMBUF_HEADROOM +
1321 MRVL_PKT_EFFEC_OFFS,
1326 if (dev->data->rx_queues[idx]) {
1327 rte_free(dev->data->rx_queues[idx]);
1328 dev->data->rx_queues[idx] = NULL;
1331 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
1337 rxq->cksum_enabled = dev->data->dev_conf.rxmode.hw_ip_checksum;
1338 rxq->queue_id = idx;
1339 rxq->port_id = dev->data->port_id;
1340 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool;
1342 tc = priv->rxq_map[rxq->queue_id].tc,
1343 inq = priv->rxq_map[rxq->queue_id].inq;
1344 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
1347 ret = mrvl_fill_bpool(rxq, desc);
1353 priv->bpool_init_size += desc;
1355 dev->data->rx_queues[idx] = rxq;
1361 * DPDK callback to release the receive queue.
1364 * Generic receive queue pointer.
1367 mrvl_rx_queue_release(void *rxq)
1369 struct mrvl_rxq *q = rxq;
1370 struct pp2_ppio_tc_params *tc_params;
1371 int i, num, tc, inq;
1372 struct pp2_hif *hif;
1373 unsigned int core_id = rte_lcore_id();
1375 if (core_id == LCORE_ID_ANY)
1378 hif = mrvl_get_hif(q->priv, core_id);
1383 tc = q->priv->rxq_map[q->queue_id].tc;
1384 inq = q->priv->rxq_map[q->queue_id].inq;
1385 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
1386 num = tc_params->inqs_params[inq].size;
1387 for (i = 0; i < num; i++) {
1388 struct pp2_buff_inf inf;
1391 pp2_bpool_get_buff(hif, q->priv->bpool, &inf);
1392 addr = cookie_addr_high | inf.cookie;
1393 rte_pktmbuf_free((struct rte_mbuf *)addr);
1400 * DPDK callback to configure the transmit queue.
1403 * Pointer to Ethernet device structure.
1405 * Transmit queue index.
1407 * Number of descriptors to configure in the queue.
1409 * NUMA socket on which memory must be allocated.
1411 * Thresholds parameters (unused).
1414 * 0 on success, negative error value otherwise.
1417 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1418 unsigned int socket,
1419 const struct rte_eth_txconf *conf __rte_unused)
1421 struct mrvl_priv *priv = dev->data->dev_private;
1422 struct mrvl_txq *txq;
1424 if (dev->data->tx_queues[idx]) {
1425 rte_free(dev->data->tx_queues[idx]);
1426 dev->data->tx_queues[idx] = NULL;
1429 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
1434 txq->queue_id = idx;
1435 txq->port_id = dev->data->port_id;
1436 dev->data->tx_queues[idx] = txq;
1438 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
1439 priv->ppio_params.outqs_params.outqs_params[idx].weight = 1;
1445 * DPDK callback to release the transmit queue.
1448 * Generic transmit queue pointer.
1451 mrvl_tx_queue_release(void *txq)
1453 struct mrvl_txq *q = txq;
1462 * Update RSS hash configuration
1465 * Pointer to Ethernet device structure.
1467 * Pointer to RSS configuration.
1470 * 0 on success, negative error value otherwise.
1473 mrvl_rss_hash_update(struct rte_eth_dev *dev,
1474 struct rte_eth_rss_conf *rss_conf)
1476 struct mrvl_priv *priv = dev->data->dev_private;
1478 return mrvl_configure_rss(priv, rss_conf);
1482 * DPDK callback to get RSS hash configuration.
1485 * Pointer to Ethernet device structure.
1487 * Pointer to RSS configuration.
1493 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev,
1494 struct rte_eth_rss_conf *rss_conf)
1496 struct mrvl_priv *priv = dev->data->dev_private;
1497 enum pp2_ppio_hash_type hash_type =
1498 priv->ppio_params.inqs_params.hash_type;
1500 rss_conf->rss_key = NULL;
1502 if (hash_type == PP2_PPIO_HASH_T_NONE)
1503 rss_conf->rss_hf = 0;
1504 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE)
1505 rss_conf->rss_hf = ETH_RSS_IPV4;
1506 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp)
1507 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_TCP;
1508 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp)
1509 rss_conf->rss_hf = ETH_RSS_NONFRAG_IPV4_UDP;
1514 static const struct eth_dev_ops mrvl_ops = {
1515 .dev_configure = mrvl_dev_configure,
1516 .dev_start = mrvl_dev_start,
1517 .dev_stop = mrvl_dev_stop,
1518 .dev_set_link_up = mrvl_dev_set_link_up,
1519 .dev_set_link_down = mrvl_dev_set_link_down,
1520 .dev_close = mrvl_dev_close,
1521 .link_update = mrvl_link_update,
1522 .promiscuous_enable = mrvl_promiscuous_enable,
1523 .allmulticast_enable = mrvl_allmulticast_enable,
1524 .promiscuous_disable = mrvl_promiscuous_disable,
1525 .allmulticast_disable = mrvl_allmulticast_disable,
1526 .mac_addr_remove = mrvl_mac_addr_remove,
1527 .mac_addr_add = mrvl_mac_addr_add,
1528 .mac_addr_set = mrvl_mac_addr_set,
1529 .mtu_set = mrvl_mtu_set,
1530 .stats_get = mrvl_stats_get,
1531 .stats_reset = mrvl_stats_reset,
1532 .dev_infos_get = mrvl_dev_infos_get,
1533 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get,
1534 .rxq_info_get = mrvl_rxq_info_get,
1535 .txq_info_get = mrvl_txq_info_get,
1536 .vlan_filter_set = mrvl_vlan_filter_set,
1537 .rx_queue_setup = mrvl_rx_queue_setup,
1538 .rx_queue_release = mrvl_rx_queue_release,
1539 .tx_queue_setup = mrvl_tx_queue_setup,
1540 .tx_queue_release = mrvl_tx_queue_release,
1541 .rss_hash_update = mrvl_rss_hash_update,
1542 .rss_hash_conf_get = mrvl_rss_hash_conf_get,
1546 * Return packet type information and l3/l4 offsets.
1549 * Pointer to the received packet descriptor.
1556 * Packet type information.
1558 static inline uint64_t
1559 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc,
1560 uint8_t *l3_offset, uint8_t *l4_offset)
1562 enum pp2_inq_l3_type l3_type;
1563 enum pp2_inq_l4_type l4_type;
1564 uint64_t packet_type;
1566 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
1567 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
1569 packet_type = RTE_PTYPE_L2_ETHER;
1572 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS:
1573 packet_type |= RTE_PTYPE_L3_IPV4;
1575 case PP2_INQ_L3_TYPE_IPV4_OK:
1576 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
1578 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO:
1579 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
1581 case PP2_INQ_L3_TYPE_IPV6_NO_EXT:
1582 packet_type |= RTE_PTYPE_L3_IPV6;
1584 case PP2_INQ_L3_TYPE_IPV6_EXT:
1585 packet_type |= RTE_PTYPE_L3_IPV6_EXT;
1587 case PP2_INQ_L3_TYPE_ARP:
1588 packet_type |= RTE_PTYPE_L2_ETHER_ARP;
1590 * In case of ARP l4_offset is set to wrong value.
1591 * Set it to proper one so that later on mbuf->l3_len can be
1592 * calculated subtracting l4_offset and l3_offset.
1594 *l4_offset = *l3_offset + MRVL_ARP_LENGTH;
1597 RTE_LOG(DEBUG, PMD, "Failed to recognise l3 packet type\n");
1602 case PP2_INQ_L4_TYPE_TCP:
1603 packet_type |= RTE_PTYPE_L4_TCP;
1605 case PP2_INQ_L4_TYPE_UDP:
1606 packet_type |= RTE_PTYPE_L4_UDP;
1609 RTE_LOG(DEBUG, PMD, "Failed to recognise l4 packet type\n");
1617 * Get offload information from the received packet descriptor.
1620 * Pointer to the received packet descriptor.
1623 * Mbuf offload flags.
1625 static inline uint64_t
1626 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc)
1629 enum pp2_inq_desc_status status;
1631 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc);
1632 if (unlikely(status != PP2_DESC_ERR_OK))
1633 flags = PKT_RX_IP_CKSUM_BAD;
1635 flags = PKT_RX_IP_CKSUM_GOOD;
1637 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc);
1638 if (unlikely(status != PP2_DESC_ERR_OK))
1639 flags |= PKT_RX_L4_CKSUM_BAD;
1641 flags |= PKT_RX_L4_CKSUM_GOOD;
1647 * DPDK callback for receive.
1650 * Generic pointer to the receive queue.
1652 * Array to store received packets.
1654 * Maximum number of packets in array.
1657 * Number of packets successfully received.
1660 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1662 struct mrvl_rxq *q = rxq;
1663 struct pp2_ppio_desc descs[nb_pkts];
1664 struct pp2_bpool *bpool;
1665 int i, ret, rx_done = 0;
1667 struct pp2_hif *hif;
1668 unsigned int core_id = rte_lcore_id();
1670 hif = mrvl_get_hif(q->priv, core_id);
1672 if (unlikely(!q->priv->ppio || !hif))
1675 bpool = q->priv->bpool;
1677 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc,
1678 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts);
1679 if (unlikely(ret < 0)) {
1680 RTE_LOG(ERR, PMD, "Failed to receive packets\n");
1683 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts;
1685 for (i = 0; i < nb_pkts; i++) {
1686 struct rte_mbuf *mbuf;
1687 uint8_t l3_offset, l4_offset;
1688 enum pp2_inq_desc_status status;
1691 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
1692 struct pp2_ppio_desc *pref_desc;
1695 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT];
1696 pref_addr = cookie_addr_high |
1697 pp2_ppio_inq_desc_get_cookie(pref_desc);
1698 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr));
1699 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr));
1702 addr = cookie_addr_high |
1703 pp2_ppio_inq_desc_get_cookie(&descs[i]);
1704 mbuf = (struct rte_mbuf *)addr;
1705 rte_pktmbuf_reset(mbuf);
1707 /* drop packet in case of mac, overrun or resource error */
1708 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
1709 if (unlikely(status != PP2_DESC_ERR_OK)) {
1710 struct pp2_buff_inf binf = {
1711 .addr = rte_mbuf_data_iova_default(mbuf),
1712 .cookie = (pp2_cookie_t)(uint64_t)mbuf,
1715 pp2_bpool_put_buff(hif, bpool, &binf);
1716 mrvl_port_bpool_size
1717 [bpool->pp2_id][bpool->id][core_id]++;
1722 mbuf->data_off += MRVL_PKT_EFFEC_OFFS;
1723 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]);
1724 mbuf->data_len = mbuf->pkt_len;
1725 mbuf->port = q->port_id;
1727 mrvl_desc_to_packet_type_and_offset(&descs[i],
1730 mbuf->l2_len = l3_offset;
1731 mbuf->l3_len = l4_offset - l3_offset;
1733 if (likely(q->cksum_enabled))
1734 mbuf->ol_flags = mrvl_desc_to_ol_flags(&descs[i]);
1736 rx_pkts[rx_done++] = mbuf;
1737 q->bytes_recv += mbuf->pkt_len;
1740 if (rte_spinlock_trylock(&q->priv->lock) == 1) {
1741 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id);
1743 if (unlikely(num <= q->priv->bpool_min_size ||
1744 (!rx_done && num < q->priv->bpool_init_size))) {
1745 ret = mrvl_fill_bpool(q, MRVL_BURST_SIZE);
1747 RTE_LOG(ERR, PMD, "Failed to fill bpool\n");
1748 } else if (unlikely(num > q->priv->bpool_max_size)) {
1750 int pkt_to_remove = num - q->priv->bpool_init_size;
1751 struct rte_mbuf *mbuf;
1752 struct pp2_buff_inf buff;
1755 "\nport-%d:%d: bpool %d oversize - remove %d buffers (pool size: %d -> %d)\n",
1756 bpool->pp2_id, q->priv->ppio->port_id,
1757 bpool->id, pkt_to_remove, num,
1758 q->priv->bpool_init_size);
1760 for (i = 0; i < pkt_to_remove; i++) {
1761 ret = pp2_bpool_get_buff(hif, bpool, &buff);
1764 mbuf = (struct rte_mbuf *)
1765 (cookie_addr_high | buff.cookie);
1766 rte_pktmbuf_free(mbuf);
1768 mrvl_port_bpool_size
1769 [bpool->pp2_id][bpool->id][core_id] -= i;
1771 rte_spinlock_unlock(&q->priv->lock);
1778 * Prepare offload information.
1782 * @param packet_type
1783 * Packet type bitfield.
1785 * Pointer to the pp2_ouq_l3_type structure.
1787 * Pointer to the pp2_outq_l4_type structure.
1788 * @param gen_l3_cksum
1789 * Will be set to 1 in case l3 checksum is computed.
1791 * Will be set to 1 in case l4 checksum is computed.
1794 * 0 on success, negative error value otherwise.
1797 mrvl_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
1798 enum pp2_outq_l3_type *l3_type,
1799 enum pp2_outq_l4_type *l4_type,
1804 * Based on ol_flags prepare information
1805 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor
1808 if (ol_flags & PKT_TX_IPV4) {
1809 *l3_type = PP2_OUTQ_L3_TYPE_IPV4;
1810 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
1811 } else if (ol_flags & PKT_TX_IPV6) {
1812 *l3_type = PP2_OUTQ_L3_TYPE_IPV6;
1813 /* no checksum for ipv6 header */
1816 /* if something different then stop processing */
1820 ol_flags &= PKT_TX_L4_MASK;
1821 if ((packet_type & RTE_PTYPE_L4_TCP) &&
1822 ol_flags == PKT_TX_TCP_CKSUM) {
1823 *l4_type = PP2_OUTQ_L4_TYPE_TCP;
1825 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
1826 ol_flags == PKT_TX_UDP_CKSUM) {
1827 *l4_type = PP2_OUTQ_L4_TYPE_UDP;
1830 *l4_type = PP2_OUTQ_L4_TYPE_OTHER;
1831 /* no checksum for other type */
1839 * Release already sent buffers to bpool (buffer-pool).
1842 * Pointer to the port structure.
1844 * Pointer to the MUSDK hardware interface.
1846 * Pointer to the shadow queue.
1850 * Force releasing packets.
1853 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif,
1854 unsigned int core_id, struct mrvl_shadow_txq *sq,
1857 struct buff_release_entry *entry;
1858 uint16_t nb_done = 0, num = 0, skip_bufs = 0;
1861 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done);
1863 sq->num_to_release += nb_done;
1865 if (likely(!force &&
1866 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE))
1869 nb_done = sq->num_to_release;
1870 sq->num_to_release = 0;
1872 for (i = 0; i < nb_done; i++) {
1873 entry = &sq->ent[sq->tail + num];
1874 if (unlikely(!entry->buff.addr)) {
1876 "Shadow memory @%d: cookie(%lx), pa(%lx)!\n",
1877 sq->tail, (u64)entry->buff.cookie,
1878 (u64)entry->buff.addr);
1883 if (unlikely(!entry->bpool)) {
1884 struct rte_mbuf *mbuf;
1886 mbuf = (struct rte_mbuf *)
1887 (cookie_addr_high | entry->buff.cookie);
1888 rte_pktmbuf_free(mbuf);
1893 mrvl_port_bpool_size
1894 [entry->bpool->pp2_id][entry->bpool->id][core_id]++;
1896 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE))
1901 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
1903 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
1910 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num);
1911 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK;
1917 * DPDK callback for transmit.
1920 * Generic pointer transmit queue.
1922 * Packets to transmit.
1924 * Number of packets in array.
1927 * Number of packets successfully transmitted.
1930 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1932 struct mrvl_txq *q = txq;
1933 struct mrvl_shadow_txq *sq;
1934 struct pp2_hif *hif;
1935 struct pp2_ppio_desc descs[nb_pkts];
1936 unsigned int core_id = rte_lcore_id();
1937 int i, ret, bytes_sent = 0;
1938 uint16_t num, sq_free_size;
1941 hif = mrvl_get_hif(q->priv, core_id);
1942 sq = &q->shadow_txqs[core_id];
1944 if (unlikely(!q->priv->ppio || !hif))
1948 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id,
1949 sq, q->queue_id, 0);
1951 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1;
1952 if (unlikely(nb_pkts > sq_free_size)) {
1954 "No room in shadow queue for %d packets! %d packets will be sent.\n",
1955 nb_pkts, sq_free_size);
1956 nb_pkts = sq_free_size;
1959 for (i = 0; i < nb_pkts; i++) {
1960 struct rte_mbuf *mbuf = tx_pkts[i];
1961 int gen_l3_cksum, gen_l4_cksum;
1962 enum pp2_outq_l3_type l3_type;
1963 enum pp2_outq_l4_type l4_type;
1965 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) {
1966 struct rte_mbuf *pref_pkt_hdr;
1968 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT];
1969 rte_mbuf_prefetch_part1(pref_pkt_hdr);
1970 rte_mbuf_prefetch_part2(pref_pkt_hdr);
1973 sq->ent[sq->head].buff.cookie = (pp2_cookie_t)(uint64_t)mbuf;
1974 sq->ent[sq->head].buff.addr =
1975 rte_mbuf_data_iova_default(mbuf);
1976 sq->ent[sq->head].bpool =
1977 (unlikely(mbuf->port == 0xff || mbuf->refcnt > 1)) ?
1978 NULL : mrvl_port_to_bpool_lookup[mbuf->port];
1979 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK;
1982 pp2_ppio_outq_desc_reset(&descs[i]);
1983 pp2_ppio_outq_desc_set_phys_addr(&descs[i],
1984 rte_pktmbuf_iova(mbuf));
1985 pp2_ppio_outq_desc_set_pkt_offset(&descs[i], 0);
1986 pp2_ppio_outq_desc_set_pkt_len(&descs[i],
1987 rte_pktmbuf_pkt_len(mbuf));
1989 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
1991 * in case unsupported ol_flags were passed
1992 * do not update descriptor offload information
1994 ret = mrvl_prepare_proto_info(mbuf->ol_flags, mbuf->packet_type,
1995 &l3_type, &l4_type, &gen_l3_cksum,
2000 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
2002 mbuf->l2_len + mbuf->l3_len,
2003 gen_l3_cksum, gen_l4_cksum);
2007 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts);
2008 /* number of packets that were not sent */
2009 if (unlikely(num > nb_pkts)) {
2010 for (i = nb_pkts; i < num; i++) {
2011 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) &
2012 MRVL_PP2_TX_SHADOWQ_MASK;
2013 addr = cookie_addr_high | sq->ent[sq->head].buff.cookie;
2015 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
2017 sq->size -= num - nb_pkts;
2020 q->bytes_sent += bytes_sent;
2026 * Initialize packet processor.
2029 * 0 on success, negative error value otherwise.
2034 struct pp2_init_params init_params;
2036 memset(&init_params, 0, sizeof(init_params));
2037 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
2038 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
2039 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED;
2041 return pp2_init(&init_params);
2045 * Deinitialize packet processor.
2048 * 0 on success, negative error value otherwise.
2051 mrvl_deinit_pp2(void)
2057 * Create private device structure.
2060 * Pointer to the port name passed in the initialization parameters.
2063 * Pointer to the newly allocated private device structure.
2065 static struct mrvl_priv *
2066 mrvl_priv_create(const char *dev_name)
2068 struct pp2_bpool_params bpool_params;
2069 char match[MRVL_MATCH_LEN];
2070 struct mrvl_priv *priv;
2073 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
2077 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
2078 &priv->pp_id, &priv->ppio_id);
2082 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
2083 PP2_BPOOL_NUM_POOLS);
2086 priv->bpool_bit = bpool_bit;
2088 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
2090 memset(&bpool_params, 0, sizeof(bpool_params));
2091 bpool_params.match = match;
2092 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
2093 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
2095 goto out_clear_bpool_bit;
2097 priv->ppio_params.type = PP2_PPIO_T_NIC;
2098 rte_spinlock_init(&priv->lock);
2101 out_clear_bpool_bit:
2102 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2109 * Create device representing Ethernet port.
2112 * Pointer to the port's name.
2115 * 0 on success, negative error value otherwise.
2118 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
2120 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
2121 struct rte_eth_dev *eth_dev;
2122 struct mrvl_priv *priv;
2125 eth_dev = rte_eth_dev_allocate(name);
2129 priv = mrvl_priv_create(name);
2135 eth_dev->data->mac_addrs =
2136 rte_zmalloc("mac_addrs",
2137 ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
2138 if (!eth_dev->data->mac_addrs) {
2139 RTE_LOG(ERR, PMD, "Failed to allocate space for eth addrs\n");
2144 memset(&req, 0, sizeof(req));
2145 strcpy(req.ifr_name, name);
2146 ret = ioctl(fd, SIOCGIFHWADDR, &req);
2150 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
2151 req.ifr_addr.sa_data, ETHER_ADDR_LEN);
2153 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst;
2154 eth_dev->tx_pkt_burst = mrvl_tx_pkt_burst;
2155 eth_dev->data->kdrv = RTE_KDRV_NONE;
2156 eth_dev->data->dev_private = priv;
2157 eth_dev->device = &vdev->device;
2158 eth_dev->dev_ops = &mrvl_ops;
2162 rte_free(eth_dev->data->mac_addrs);
2164 rte_eth_dev_release_port(eth_dev);
2172 * Cleanup previously created device representing Ethernet port.
2175 * Pointer to the port name.
2178 mrvl_eth_dev_destroy(const char *name)
2180 struct rte_eth_dev *eth_dev;
2181 struct mrvl_priv *priv;
2183 eth_dev = rte_eth_dev_allocated(name);
2187 priv = eth_dev->data->dev_private;
2188 pp2_bpool_deinit(priv->bpool);
2189 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
2191 rte_free(eth_dev->data->mac_addrs);
2192 rte_eth_dev_release_port(eth_dev);
2196 * Callback used by rte_kvargs_process() during argument parsing.
2199 * Pointer to the parsed key (unused).
2201 * Pointer to the parsed value.
2203 * Pointer to the extra arguments which contains address of the
2204 * table of pointers to parsed interface names.
2210 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
2213 struct mrvl_ifnames *ifnames = extra_args;
2215 ifnames->names[ifnames->idx++] = value;
2221 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
2224 mrvl_deinit_hifs(void)
2228 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) {
2230 pp2_hif_deinit(hifs[i]);
2232 used_hifs = MRVL_MUSDK_HIFS_RESERVED;
2233 memset(hifs, 0, sizeof(hifs));
2237 * DPDK callback to register the virtual device.
2240 * Pointer to the virtual device.
2243 * 0 on success, negative error value otherwise.
2246 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
2248 struct rte_kvargs *kvlist;
2249 struct mrvl_ifnames ifnames;
2251 uint32_t i, ifnum, cfgnum;
2254 params = rte_vdev_device_args(vdev);
2258 kvlist = rte_kvargs_parse(params, valid_args);
2262 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
2263 if (ifnum > RTE_DIM(ifnames.names))
2264 goto out_free_kvlist;
2267 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
2268 mrvl_get_ifnames, &ifnames);
2272 * The below system initialization should be done only once,
2273 * on the first provided configuration file
2275 if (!mrvl_qos_cfg) {
2276 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
2277 RTE_LOG(INFO, PMD, "Parsing config file!\n");
2279 RTE_LOG(ERR, PMD, "Cannot handle more than one config file!\n");
2280 goto out_free_kvlist;
2281 } else if (cfgnum == 1) {
2282 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
2283 mrvl_get_qoscfg, &mrvl_qos_cfg);
2290 RTE_LOG(INFO, PMD, "Perform MUSDK initializations\n");
2292 * ret == -EEXIST is correct, it means DMA
2293 * has been already initialized (by another PMD).
2295 ret = mv_sys_dma_mem_init(MRVL_MUSDK_DMA_MEMSIZE);
2298 goto out_free_kvlist;
2301 "DMA memory has been already initialized by a different driver.\n");
2304 ret = mrvl_init_pp2();
2306 RTE_LOG(ERR, PMD, "Failed to init PP!\n");
2307 goto out_deinit_dma;
2310 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size));
2312 mrvl_lcore_first = RTE_MAX_LCORE;
2313 mrvl_lcore_last = 0;
2316 for (i = 0; i < ifnum; i++) {
2317 RTE_LOG(INFO, PMD, "Creating %s\n", ifnames.names[i]);
2318 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
2322 mrvl_dev_num += ifnum;
2324 rte_kvargs_free(kvlist);
2329 mrvl_eth_dev_destroy(ifnames.names[i]);
2331 if (mrvl_dev_num == 0)
2334 if (mrvl_dev_num == 0)
2335 mv_sys_dma_mem_destroy();
2337 rte_kvargs_free(kvlist);
2343 * DPDK callback to remove virtual device.
2346 * Pointer to the removed virtual device.
2349 * 0 on success, negative error value otherwise.
2352 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
2357 name = rte_vdev_device_name(vdev);
2361 RTE_LOG(INFO, PMD, "Removing %s\n", name);
2363 for (i = 0; i < rte_eth_dev_count(); i++) {
2364 char ifname[RTE_ETH_NAME_MAX_LEN];
2366 rte_eth_dev_get_name_by_port(i, ifname);
2367 mrvl_eth_dev_destroy(ifname);
2371 if (mrvl_dev_num == 0) {
2372 RTE_LOG(INFO, PMD, "Perform MUSDK deinit\n");
2375 mv_sys_dma_mem_destroy();
2381 static struct rte_vdev_driver pmd_mrvl_drv = {
2382 .probe = rte_pmd_mrvl_probe,
2383 .remove = rte_pmd_mrvl_remove,
2386 RTE_PMD_REGISTER_VDEV(net_mrvl, pmd_mrvl_drv);
2387 RTE_PMD_REGISTER_ALIAS(net_mrvl, eth_mrvl);