98 uint16_t rx_ring_size,
99 uint16_t tx_ring_size,
100 std::map<
int, std::unique_ptr<rte_mempool>>& mbuf_pool,
103 bool check_link_status)
106 uint16_t nb_rxd = rx_ring_size;
107 uint16_t nb_txd = tx_ring_size;
110 struct rte_eth_dev_info dev_info;
111 struct rte_eth_txconf txconf;
112 struct rte_eth_link link;
115 if (!rte_eth_dev_is_valid_port(iface)) {
116 TLOG() <<
"Specified interface " << iface <<
" is not valid in EAL!";
117 throw InvalidEALPort(
ERS_HERE, iface);
121 if ((retval = rte_eth_dev_info_get(iface, &dev_info)) != 0) {
122 TLOG() <<
"Error during getting device (iface " << iface <<
") retval: " << retval;
123 throw FailedToRetrieveInterfaceInfo(
ERS_HERE, iface, retval);
126 TLOG() <<
"Iface " << iface <<
" RX Ring info :"
127 <<
" min " << dev_info.rx_desc_lim.nb_min <<
" max " << dev_info.rx_desc_lim.nb_max <<
" align "
128 << dev_info.rx_desc_lim.nb_align;
132 if ((retval = rte_eth_dev_reset(iface)) != 0) {
133 throw FailedToResetInterface(
ERS_HERE, iface, retval);
141 if ((iface_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) != 0) {
142 TLOG() <<
"Ethdev port config prepared with RX RSS mq_mode!";
143 if ((iface_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) != 0) {
144 TLOG() <<
"Ethdev port config prepared with RX RSS mq_mode with offloading is requested!";
149 TLOG() <<
"Configuring Iface " << iface <<
" rx rings: " << rx_rings <<
", tx rings " << tx_rings;
152 if ((retval = rte_eth_dev_configure(iface, rx_rings, tx_rings, &iface_conf)) != 0) {
153 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Device Configuration", retval);
160 rte_eth_dev_get_mtu(iface, &mtu);
161 TLOG() <<
"Interface: " << iface <<
" MTU: " << mtu;
169 rte_eth_dev_set_ptypes(iface, RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK | RTE_PTYPE_L4_MASK, NULL, 0);
176 if ((retval = rte_eth_dev_adjust_nb_rx_tx_desc(iface, &nb_rxd, &nb_txd)) != 0) {
177 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Adjust tx/rx descriptors", retval);
181 for (q = 0; q < rx_rings; q++) {
183 if ((retval = rte_eth_rx_queue_setup(iface, q, nb_rxd, rte_eth_dev_socket_id(iface), NULL, mbuf_pool[q].get())) <
186 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Rx queues setup", retval);
190 txconf = dev_info.default_txconf;
191 txconf.offloads = iface_conf.txmode.offloads;
194 txconf.tx_rs_thresh = 32;
195 txconf.tx_free_thresh = 32;
196 txconf.tx_thresh.wthresh = 0;
199 for (q = 0; q < tx_rings; q++) {
200 if ((retval = rte_eth_tx_queue_setup(iface, q, nb_txd, rte_eth_dev_socket_id(iface), &txconf)) < 0) {
201 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Tx queues setup", retval);
206 if ((retval = rte_eth_dev_start(iface)) < 0) {
207 throw FailedToConfigureInterface(
ERS_HERE, iface,
"MAC address retrival", retval);
210 if ((retval = rte_eth_link_get(iface, &link)) != 0) {
211 throw FailedToRetrieveLinkStatus(
ERS_HERE, iface, retval);
214 TLOG() <<
"Link: speed=" << link.link_speed <<
" duplex=" << link.link_duplex <<
" autoneg=" << link.link_autoneg
215 <<
" status=" << link.link_status;
217 if (check_link_status && link.link_status == 0) {
222 struct rte_ether_addr addr;
223 if ((retval = rte_eth_macaddr_get(iface, &addr)) == 0) {
226 throw FailedToConfigureInterface(
ERS_HERE, iface,
"MAC address retrival", retval);
230 if ((retval = rte_eth_dev_info_get(iface, &dev_info)) != 0) {
231 TLOG() <<
"Error during getting device (iface " << iface <<
") retval: " << retval;
232 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Device information retrival", retval);
235 TLOG() <<
"Iface[" << iface <<
"] Rx Ring info:"
236 <<
" min=" << dev_info.rx_desc_lim.nb_min <<
" max=" << dev_info.rx_desc_lim.nb_max
237 <<
" align=" << dev_info.rx_desc_lim.nb_align;
238 TLOG() <<
"Iface[" << iface <<
"] Tx Ring info:"
239 <<
" min=" << dev_info.rx_desc_lim.nb_min <<
" max=" << dev_info.rx_desc_lim.nb_max
240 <<
" align=" << dev_info.rx_desc_lim.nb_align;
242 for (
size_t j = 0; j < dev_info.nb_rx_queues; j++) {
244 struct rte_eth_rxq_info queue_info;
247 retval = rte_eth_rx_queue_info_get(iface, j, &queue_info);
251 count = rte_eth_rx_queue_count(iface, j);
252 TLOG() <<
"rx[" << j <<
"] descriptors=" << count <<
"/" << queue_info.nb_desc
253 <<
" scattered=" << (queue_info.scattered_rx ?
"yes" :
"no")
254 <<
" conf.drop_en=" << (queue_info.conf.rx_drop_en ?
"yes" :
"no")
255 <<
" conf.rx_deferred_start=" << (queue_info.conf.rx_deferred_start ?
"yes" :
"no")
256 <<
" rx_buf_size=" << queue_info.rx_buf_size;