4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/types.h>
40 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
52 #include <rte_per_lcore.h>
53 #include <rte_launch.h>
54 #include <rte_atomic.h>
55 #include <rte_cycles.h>
56 #include <rte_prefetch.h>
57 #include <rte_lcore.h>
58 #include <rte_per_lcore.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_interrupts.h>
62 #include <rte_random.h>
63 #include <rte_debug.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
67 #include <rte_mempool.h>
69 #include <rte_string_fns.h>
77 struct app_params app = {
79 .n_ports = APP_MAX_PORTS,
80 .port_rx_ring_size = 128,
81 .port_tx_ring_size = 512,
88 .pool_buffer_size = 2048 + RTE_PKTMBUF_HEADROOM,
89 .pool_size = 32 * 1024,
90 .pool_cache_size = 256,
93 .burst_size_rx_read = 64,
94 .burst_size_rx_write = 64,
95 .burst_size_worker_read = 64,
96 .burst_size_worker_write = 64,
97 .burst_size_tx_read = 64,
98 .burst_size_tx_write = 64,
101 static struct rte_eth_conf port_conf = {
104 .header_split = 0, /* Header Split disabled */
105 .hw_ip_checksum = 1, /* IP checksum offload enabled */
106 .hw_vlan_filter = 0, /* VLAN filtering disabled */
107 .jumbo_frame = 0, /* Jumbo Frame Support disabled */
108 .hw_strip_crc = 0, /* CRC stripped by hardware */
113 .rss_hf = ETH_RSS_IP,
117 .mq_mode = ETH_MQ_TX_NONE,
121 static struct rte_eth_rxconf rx_conf = {
127 .rx_free_thresh = 64,
131 static struct rte_eth_txconf tx_conf = {
142 app_init_mbuf_pools(void)
144 /* Init the buffer pool */
145 RTE_LOG(INFO, USER1, "Creating the mbuf pool ...\n");
146 app.pool = rte_pktmbuf_pool_create("mempool", app.pool_size,
147 app.pool_cache_size, 0, app.pool_buffer_size, rte_socket_id());
148 if (app.pool == NULL)
149 rte_panic("Cannot create mbuf pool\n");
157 for (i = 0; i < app.n_ports; i++) {
160 snprintf(name, sizeof(name), "app_ring_rx_%u", i);
162 app.rings_rx[i] = rte_ring_create(
166 RING_F_SP_ENQ | RING_F_SC_DEQ);
168 if (app.rings_rx[i] == NULL)
169 rte_panic("Cannot create RX ring %u\n", i);
172 for (i = 0; i < app.n_ports; i++) {
175 snprintf(name, sizeof(name), "app_ring_tx_%u", i);
177 app.rings_tx[i] = rte_ring_create(
181 RING_F_SP_ENQ | RING_F_SC_DEQ);
183 if (app.rings_tx[i] == NULL)
184 rte_panic("Cannot create TX ring %u\n", i);
190 app_ports_check_link(void)
192 uint32_t all_ports_up, i;
196 for (i = 0; i < app.n_ports; i++) {
197 struct rte_eth_link link;
200 port = (uint8_t) app.ports[i];
201 memset(&link, 0, sizeof(link));
202 rte_eth_link_get_nowait(port, &link);
203 RTE_LOG(INFO, USER1, "Port %u (%u Gbps) %s\n",
205 link.link_speed / 1000,
206 link.link_status ? "UP" : "DOWN");
208 if (link.link_status == 0)
212 if (all_ports_up == 0)
213 rte_panic("Some NIC ports are DOWN\n");
221 /* Init NIC ports, then start the ports */
222 for (i = 0; i < app.n_ports; i++) {
226 port = (uint8_t) app.ports[i];
227 RTE_LOG(INFO, USER1, "Initializing NIC port %u ...\n", port);
230 ret = rte_eth_dev_configure(
236 rte_panic("Cannot init NIC port %u (%d)\n", port, ret);
238 rte_eth_promiscuous_enable(port);
241 ret = rte_eth_rx_queue_setup(
244 app.port_rx_ring_size,
245 rte_eth_dev_socket_id(port),
249 rte_panic("Cannot init RX for port %u (%d)\n",
250 (uint32_t) port, ret);
253 ret = rte_eth_tx_queue_setup(
256 app.port_tx_ring_size,
257 rte_eth_dev_socket_id(port),
260 rte_panic("Cannot init TX for port %u (%d)\n",
261 (uint32_t) port, ret);
264 ret = rte_eth_dev_start(port);
266 rte_panic("Cannot start port %u (%d)\n", port, ret);
269 app_ports_check_link();
275 app_init_mbuf_pools();
279 RTE_LOG(INFO, USER1, "Initialization completed\n");