4 * Copyright(c) 2010-2013 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.
41 #include <rte_common.h>
42 #include <rte_errno.h>
43 #include <rte_ethdev.h>
44 #include <rte_memzone.h>
46 #include <rte_string_fns.h>
51 #include "../include/conf.h"
54 static const struct rte_eth_conf port_conf = {
57 .header_split = 0, /**< Header Split disabled */
58 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
59 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
60 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
61 .hw_strip_crc = 0, /**< CRC stripped by hardware */
64 .mq_mode = ETH_DCB_NONE,
68 static const struct rte_eth_rxconf rx_conf = {
76 static const struct rte_eth_txconf tx_conf = {
86 static struct rte_eth_fc_conf fc_conf = {
87 .mode = RTE_FC_TX_PAUSE,
88 .high_water = 80 * 510 / 100,
89 .low_water = 60 * 510 / 100,
95 void configure_eth_port(uint8_t port_id)
99 rte_eth_dev_stop(port_id);
101 ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf);
103 rte_exit(EXIT_FAILURE, "Cannot configure port %u (error %d)\n",
104 (unsigned) port_id, ret);
106 /* Initialize the port's RX queue */
107 ret = rte_eth_rx_queue_setup(port_id, 0, RX_DESC_PER_QUEUE,
108 rte_eth_dev_socket_id(port_id), &rx_conf,
111 rte_exit(EXIT_FAILURE, "Failed to setup RX queue on "
112 "port %u (error %d)\n", (unsigned) port_id, ret);
114 /* Initialize the port's TX queue */
115 ret = rte_eth_tx_queue_setup(port_id, 0, TX_DESC_PER_QUEUE,
116 rte_eth_dev_socket_id(port_id), &tx_conf);
118 rte_exit(EXIT_FAILURE, "Failed to setup TX queue on "
119 "port %u (error %d)\n", (unsigned) port_id, ret);
121 /* Initialize the port's flow control */
122 ret = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
124 rte_exit(EXIT_FAILURE, "Failed to setup hardware flow control on "
125 "port %u (error %d)\n", (unsigned) port_id, ret);
128 ret = rte_eth_dev_start(port_id);
130 rte_exit(EXIT_FAILURE, "Failed to start port %u (error %d)\n",
131 (unsigned) port_id, ret);
133 /* Put it in promiscuous mode */
134 rte_eth_promiscuous_enable(port_id);
142 /* Initialize the PMD */
143 ret = rte_pmd_init_all();
145 rte_exit(EXIT_FAILURE, "Failed to initialize poll mode drivers (error %d)\n", ret);
147 /* Bind the drivers to usable devices */
148 ret = rte_eal_pci_probe();
150 rte_exit(EXIT_FAILURE, "rte_eal_pci_probe(): error %d\n", ret);
152 if (rte_eth_dev_count() < 2)
153 rte_exit(EXIT_FAILURE, "Not enough ethernet port available\n");
156 void init_ring(int lcore_id, uint8_t port_id)
158 struct rte_ring *ring;
159 char ring_name[RTE_RING_NAMESIZE];
161 rte_snprintf(ring_name, RTE_RING_NAMESIZE,
162 "core%d_port%d", lcore_id, port_id);
163 ring = rte_ring_create(ring_name, RING_SIZE, rte_socket_id(),
164 RING_F_SP_ENQ | RING_F_SC_DEQ);
167 rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno));
169 rte_ring_set_water_mark(ring, 80 * RING_SIZE / 100);
171 rings[lcore_id][port_id] = ring;
179 /* Pair ports with their "closest neighbour" in the portmask */
180 for (i = 0; i < RTE_MAX_ETHPORTS; i++)
181 if (is_bit_set(i, portmask))
182 for (j = (uint8_t) (i + 1); j < RTE_MAX_ETHPORTS; j++)
183 if (is_bit_set(j, portmask)) {
192 setup_shared_variables(void)
194 const struct rte_memzone *qw_memzone;
196 qw_memzone = rte_memzone_reserve(QUOTA_WATERMARK_MEMZONE_NAME, 2 * sizeof(int),
197 rte_socket_id(), RTE_MEMZONE_2MB);
198 if (qw_memzone == NULL)
199 rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno));
201 quota = qw_memzone->addr;
202 low_watermark = (unsigned int *) qw_memzone->addr + sizeof(int);