1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_eth_ring.h>
9 #include <rte_ethdev.h>
11 #include <rte_bus_vdev.h>
12 #include "rte_lcore.h"
13 #include "rte_mempool.h"
16 #include "sample_packet_forward.h"
19 * heper function: configure and start test device
22 test_dev_start(uint16_t port, struct rte_mempool *mp)
25 struct rte_eth_conf pconf;
27 memset(&pconf, 0, sizeof(pconf));
29 rc = rte_eth_dev_configure(port, NUM_QUEUES, NUM_QUEUES, &pconf);
33 rc = rte_eth_rx_queue_setup(port, 0, RING_SIZE, SOCKET_ID_ANY,
38 rc = rte_eth_tx_queue_setup(port, 0, RING_SIZE, SOCKET_ID_ANY,
43 rc = rte_eth_dev_start(port);
47 /* Sample test to create virtual rings and tx,rx portid from rings */
49 test_ring_setup(struct rte_ring **ring, uint16_t *portid)
51 *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(),
52 RING_F_SP_ENQ | RING_F_SC_DEQ);
54 printf("%s() line %u: rte_ring_create R0 failed",
58 *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES,
59 ring, NUM_QUEUES, rte_socket_id());
64 /* Sample test to free the mempool */
66 test_mp_free(struct rte_mempool *mp)
71 /* Sample test to free the virtual rings */
73 test_ring_free(struct rte_ring *rxtx)
78 /* Sample test to release the vdev */
80 test_vdev_uninit(const char *vdev)
82 rte_vdev_uninit(vdev);
85 /* sample test to allocate the mempool */
87 test_get_mempool(struct rte_mempool **mp, char *poolname)
89 *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0,
90 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
96 /* sample test to allocate buffer for pkts */
98 test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf,
103 ret = test_get_mempool(mp, poolname);
106 if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) {
107 printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__,
114 /* sample test to deallocate the allocated buffers and mempool */
116 test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf)
120 for (itr = 0; itr < NUM_PACKETS; itr++)
121 rte_pktmbuf_free(pbuf[itr]);
122 rte_mempool_free(mp);
125 /* Sample test to forward packets using virtual portids */
127 test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id)
129 /* send and receive packet and check for stats update */
130 if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS)
132 printf("%s() line %u: Error sending packet to"
133 " port %d\n", __func__, __LINE__, portid);
136 if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS)
138 printf("%s() line %u: Error receiving packet from"
139 " port %d\n", __func__, __LINE__, portid);