99{
101 uint16_t nb_rxd = rx_ring_size;
102 uint16_t nb_txd = tx_ring_size;
103 int retval = -1;
104 uint16_t q;
105 struct rte_eth_dev_info dev_info;
106 struct rte_eth_txconf txconf;
107 struct rte_eth_link link;
108
109
110 if (!rte_eth_dev_is_valid_port(iface)) {
111 TLOG() <<
"Specified interface " << iface <<
" is not valid in EAL!";
112 throw InvalidEALPort(
ERS_HERE, iface);
113 }
114
115
116 if ((retval = rte_eth_dev_info_get(iface, &dev_info)) != 0) {
117 TLOG() <<
"Error during getting device (iface " << iface <<
") retval: " << retval;
118 throw FailedToRetrieveInterfaceInfo(
ERS_HERE, iface, retval);
119 }
120
121 TLOG() <<
"Iface " << iface <<
" RX Ring info :"
122 << " min " << dev_info.rx_desc_lim.nb_min
123 << " max " << dev_info.rx_desc_lim.nb_max
124 << " align " << dev_info.rx_desc_lim.nb_align
125 ;
126
127
128 if (with_reset) {
129 if ((retval = rte_eth_dev_reset(iface)) != 0) {
130 throw FailedToResetInterface(
ERS_HERE, iface, retval);
131 }
132 }
133
134
135 if (with_mq_rss) {
137
138 if ((iface_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) != 0) {
139 TLOG() <<
"Ethdev port config prepared with RX RSS mq_mode!";
140 if ((iface_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) != 0) {
141 TLOG() <<
"Ethdev port config prepared with RX RSS mq_mode with offloading is requested!";
142 }
143 }
144 }
145
146 TLOG() <<
"Configuring Iface " <<
iface <<
" rx rings: " << rx_rings <<
", tx rings " << tx_rings;
147
148
149 if ((retval = rte_eth_dev_configure(iface, rx_rings, tx_rings, &iface_conf)) != 0) {
150 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Device Configuration", retval);
151 }
152
153
155 {
156 uint16_t mtu;
157 rte_eth_dev_get_mtu(iface, &mtu);
158 TLOG() <<
"Interface: " <<
iface <<
" MTU: " << mtu;
159 }
160
161
162
163
164
165
166 if ((retval = rte_eth_dev_adjust_nb_rx_tx_desc(iface, &nb_rxd, &nb_txd)) != 0) {
167 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Adjust tx/rx descriptors", retval);
168 }
169
170
171 for (q = 0; q < rx_rings; q++) {
172
173 if ((retval = rte_eth_rx_queue_setup(iface, q, nb_rxd, rte_eth_dev_socket_id(iface), NULL, mbuf_pool[q].get())) < 0) {
174
175 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Rx queues setup", retval);
176 }
177 }
178
179 txconf = dev_info.default_txconf;
180 txconf.offloads = iface_conf.txmode.offloads;
181
182
183 txconf.tx_rs_thresh = 32;
184 txconf.tx_free_thresh = 32;
185 txconf.tx_thresh.wthresh = 0;
186
187
188 for (q = 0; q < tx_rings; q++) {
189 if ((retval = rte_eth_tx_queue_setup(iface, q, nb_txd, rte_eth_dev_socket_id(iface), &txconf)) < 0) {
190 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Tx queues setup", retval);
191 }
192 }
193
194
195 if ((retval = rte_eth_dev_start(iface)) < 0) {
196 throw FailedToConfigureInterface(
ERS_HERE, iface,
"MAC address retrival", retval);
197 }
198
199 if ((retval = rte_eth_link_get(iface, &link)) != 0) {
200 throw FailedToRetrieveLinkStatus(
ERS_HERE, iface, retval);
201 }
202
203 TLOG() <<
"Link: speed=" << link.link_speed <<
" duplex=" << link.link_duplex <<
" autoneg=" << link.link_autoneg <<
" status=" << link.link_status;
204
205 if ( check_link_status && link.link_status == 0 ) {
207 }
208
209
210 struct rte_ether_addr addr;
211 if ((retval = rte_eth_macaddr_get(iface, &addr)) == 0) {
213 } else {
214 throw FailedToConfigureInterface(
ERS_HERE, iface,
"MAC address retrival", retval);
215 }
216
217
218 if ((retval = rte_eth_dev_info_get(iface, &dev_info)) != 0) {
219 TLOG() <<
"Error during getting device (iface " <<
iface <<
") retval: " << retval;
220 throw FailedToConfigureInterface(
ERS_HERE, iface,
"Device information retrival", retval);
221 }
222
223 TLOG() <<
"Iface[" <<
iface <<
"] Rx Ring info:"
224 << " min=" << dev_info.rx_desc_lim.nb_min
225 << " max=" << dev_info.rx_desc_lim.nb_max
226 << " align=" << dev_info.rx_desc_lim.nb_align;
227 TLOG() <<
"Iface[" <<
iface <<
"] Tx Ring info:"
228 << " min=" << dev_info.rx_desc_lim.nb_min
229 << " max=" << dev_info.rx_desc_lim.nb_max
230 << " align=" << dev_info.rx_desc_lim.nb_align;
231
232 for (size_t j = 0; j < dev_info.nb_rx_queues; j++) {
233
234 struct rte_eth_rxq_info queue_info;
235 int count;
236
237 retval = rte_eth_rx_queue_info_get(iface, j, &queue_info);
238 if (retval != 0)
239 continue;
240
241 count = rte_eth_rx_queue_count(iface, j);
242 TLOG() <<
"rx[" << j <<
"] descriptors=" << count <<
"/" << queue_info.nb_desc
243 << " scattered=" << (queue_info.scattered_rx ? "yes" : "no")
244 << " conf.drop_en=" << (queue_info.conf.rx_drop_en ? "yes" : "no")
245 << " conf.rx_deferred_start=" << (queue_info.conf.rx_deferred_start ? "yes" : "no")
246 << " rx_buf_size=" << queue_info.rx_buf_size;
247 }
248
249 return 0;
250}
#define RTE_JUMBO_ETHER_MTU
static const struct rte_eth_conf iface_conf_default
void iface_conf_rss_mode(struct rte_eth_conf &iface_conf, bool mode=false, bool offload=false)
std::string get_mac_addr_str(const rte_ether_addr &addr)