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.
40 #include <rte_common.h>
41 #include <rte_errno.h>
42 #include <rte_ethdev.h>
43 #include <rte_memzone.h>
45 #include <rte_string_fns.h>
50 #include "../include/conf.h"
53 static const struct rte_eth_conf port_conf
= {
56 .header_split
= 0, /**< Header Split disabled */
57 .hw_ip_checksum
= 0, /**< IP csum offload disabled */
58 .hw_vlan_filter
= 0, /**< VLAN filtering disabled */
59 .jumbo_frame
= 0, /**< Jumbo Frame disabled */
60 .hw_strip_crc
= 1, /**< CRC stripped by hardware */
63 .mq_mode
= ETH_DCB_NONE
,
67 static struct rte_eth_fc_conf fc_conf
= {
68 .mode
= RTE_FC_TX_PAUSE
,
69 .high_water
= 80 * 510 / 100,
70 .low_water
= 60 * 510 / 100,
76 void configure_eth_port(uint8_t port_id
)
80 rte_eth_dev_stop(port_id
);
82 ret
= rte_eth_dev_configure(port_id
, 1, 1, &port_conf
);
84 rte_exit(EXIT_FAILURE
, "Cannot configure port %u (error %d)\n",
85 (unsigned int) port_id
, ret
);
87 /* Initialize the port's RX queue */
88 ret
= rte_eth_rx_queue_setup(port_id
, 0, RX_DESC_PER_QUEUE
,
89 rte_eth_dev_socket_id(port_id
),
93 rte_exit(EXIT_FAILURE
,
94 "Failed to setup RX queue on port %u (error %d)\n",
95 (unsigned int) port_id
, ret
);
97 /* Initialize the port's TX queue */
98 ret
= rte_eth_tx_queue_setup(port_id
, 0, TX_DESC_PER_QUEUE
,
99 rte_eth_dev_socket_id(port_id
),
102 rte_exit(EXIT_FAILURE
,
103 "Failed to setup TX queue on port %u (error %d)\n",
104 (unsigned int) port_id
, ret
);
106 /* Initialize the port's flow control */
107 ret
= rte_eth_dev_flow_ctrl_set(port_id
, &fc_conf
);
109 rte_exit(EXIT_FAILURE
,
110 "Failed to setup hardware flow control on port %u (error %d)\n",
111 (unsigned int) port_id
, ret
);
114 ret
= rte_eth_dev_start(port_id
);
116 rte_exit(EXIT_FAILURE
, "Failed to start port %u (error %d)\n",
117 (unsigned int) port_id
, ret
);
119 /* Put it in promiscuous mode */
120 rte_eth_promiscuous_enable(port_id
);
126 if (rte_eth_dev_count() < 2)
127 rte_exit(EXIT_FAILURE
, "Not enough ethernet port available\n");
130 void init_ring(int lcore_id
, uint8_t port_id
)
132 struct rte_ring
*ring
;
133 char ring_name
[RTE_RING_NAMESIZE
];
135 snprintf(ring_name
, RTE_RING_NAMESIZE
,
136 "core%d_port%d", lcore_id
, port_id
);
137 ring
= rte_ring_create(ring_name
, RING_SIZE
, rte_socket_id(),
138 RING_F_SP_ENQ
| RING_F_SC_DEQ
);
141 rte_exit(EXIT_FAILURE
, "%s\n", rte_strerror(rte_errno
));
143 *high_watermark
= 80 * RING_SIZE
/ 100;
145 rings
[lcore_id
][port_id
] = ring
;
153 /* Pair ports with their "closest neighbour" in the portmask */
154 for (i
= 0; i
< RTE_MAX_ETHPORTS
; i
++)
155 if (is_bit_set(i
, portmask
))
156 for (j
= (uint8_t) (i
+ 1); j
< RTE_MAX_ETHPORTS
; j
++)
157 if (is_bit_set(j
, portmask
)) {
166 setup_shared_variables(void)
168 const struct rte_memzone
*qw_memzone
;
170 qw_memzone
= rte_memzone_reserve(QUOTA_WATERMARK_MEMZONE_NAME
,
171 3 * sizeof(int), rte_socket_id(), 0);
172 if (qw_memzone
== NULL
)
173 rte_exit(EXIT_FAILURE
, "%s\n", rte_strerror(rte_errno
));
175 quota
= qw_memzone
->addr
;
176 low_watermark
= (unsigned int *) qw_memzone
->addr
+ 1;
177 high_watermark
= (unsigned int *) qw_memzone
->addr
+ 2;