Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <stdarg.h>
6 : : #include <stdio.h>
7 : : #include <stdlib.h>
8 : : #include <signal.h>
9 : : #include <string.h>
10 : : #include <time.h>
11 : : #include <fcntl.h>
12 : : #ifndef RTE_EXEC_ENV_WINDOWS
13 : : #include <sys/mman.h>
14 : : #endif
15 : : #include <sys/types.h>
16 : : #include <errno.h>
17 : : #include <stdbool.h>
18 : :
19 : : #include <sys/queue.h>
20 : : #include <sys/stat.h>
21 : :
22 : : #include <stdint.h>
23 : : #include <unistd.h>
24 : : #include <inttypes.h>
25 : :
26 : : #include <rte_common.h>
27 : : #include <rte_errno.h>
28 : : #include <rte_byteorder.h>
29 : : #include <rte_log.h>
30 : : #include <rte_debug.h>
31 : : #include <rte_cycles.h>
32 : : #include <rte_memory.h>
33 : : #include <rte_memcpy.h>
34 : : #include <rte_launch.h>
35 : : #include <rte_bus.h>
36 : : #include <rte_eal.h>
37 : : #include <rte_alarm.h>
38 : : #include <rte_per_lcore.h>
39 : : #include <rte_lcore.h>
40 : : #include <rte_branch_prediction.h>
41 : : #include <rte_mempool.h>
42 : : #include <rte_malloc.h>
43 : : #include <rte_mbuf.h>
44 : : #include <rte_mbuf_pool_ops.h>
45 : : #include <rte_interrupts.h>
46 : : #include <rte_ether.h>
47 : : #include <rte_ethdev.h>
48 : : #include <rte_dev.h>
49 : : #include <rte_string_fns.h>
50 : : #include <rte_pci.h>
51 : : #ifdef RTE_NET_IXGBE
52 : : #include <rte_pmd_ixgbe.h>
53 : : #endif
54 : : #ifdef RTE_LIB_PDUMP
55 : : #include <rte_pdump.h>
56 : : #endif
57 : : #include <rte_flow.h>
58 : : #ifdef RTE_LIB_METRICS
59 : : #include <rte_metrics.h>
60 : : #endif
61 : : #ifdef RTE_LIB_BITRATESTATS
62 : : #include <rte_bitrate.h>
63 : : #endif
64 : : #ifdef RTE_LIB_LATENCYSTATS
65 : : #include <rte_latencystats.h>
66 : : #endif
67 : : #ifdef RTE_EXEC_ENV_WINDOWS
68 : : #include <process.h>
69 : : #endif
70 : : #ifdef RTE_NET_BOND
71 : : #include <rte_eth_bond.h>
72 : : #endif
73 : : #ifdef RTE_NET_MLX5
74 : : #include "mlx5_testpmd.h"
75 : : #endif
76 : :
77 : : #include "testpmd.h"
78 : :
79 : : #ifndef MAP_HUGETLB
80 : : /* FreeBSD may not have MAP_HUGETLB (in fact, it probably doesn't) */
81 : : #define HUGE_FLAG (0x40000)
82 : : #else
83 : : #define HUGE_FLAG MAP_HUGETLB
84 : : #endif
85 : :
86 : : #ifndef MAP_HUGE_SHIFT
87 : : /* older kernels (or FreeBSD) will not have this define */
88 : : #define HUGE_SHIFT (26)
89 : : #else
90 : : #define HUGE_SHIFT MAP_HUGE_SHIFT
91 : : #endif
92 : :
93 : : #define EXTMEM_HEAP_NAME "extmem"
94 : : /*
95 : : * Zone size with the malloc overhead (max of debug and release variants)
96 : : * must fit into the smallest supported hugepage size (2M),
97 : : * so that an IOVA-contiguous zone of this size can always be allocated
98 : : * if there are free 2M hugepages.
99 : : */
100 : : #define EXTBUF_ZONE_SIZE (RTE_PGSIZE_2M - 4 * RTE_CACHE_LINE_SIZE)
101 : :
102 : : uint16_t verbose_level = 0; /**< Silent by default. */
103 : : int testpmd_logtype; /**< Log type for testpmd logs */
104 : :
105 : : /* Maximum delay for exiting after primary process. */
106 : : #define MONITOR_INTERVAL (500 * 1000)
107 : :
108 : : /* use main core for command line ? */
109 : : uint8_t interactive = 0;
110 : : uint8_t auto_start = 0;
111 : : uint8_t tx_first;
112 : : struct cmdline_file_info cmdline_files[MAX_CMDLINE_FILENAMES] = {0};
113 : : unsigned int cmdline_file_count;
114 : :
115 : : /*
116 : : * NUMA support configuration.
117 : : * When set, the NUMA support attempts to dispatch the allocation of the
118 : : * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
119 : : * probed ports among the CPU sockets 0 and 1.
120 : : * Otherwise, all memory is allocated from CPU socket 0.
121 : : */
122 : : uint8_t numa_support = 1; /**< numa enabled by default */
123 : :
124 : : /*
125 : : * In UMA mode,all memory is allocated from socket 0 if --socket-num is
126 : : * not configured.
127 : : */
128 : : uint8_t socket_num = UMA_NO_CONFIG;
129 : :
130 : : /*
131 : : * Select mempool allocation type:
132 : : * - native: use regular DPDK memory
133 : : * - anon: use regular DPDK memory to create mempool, but populate using
134 : : * anonymous memory (may not be IOVA-contiguous)
135 : : * - xmem: use externally allocated hugepage memory
136 : : */
137 : : uint8_t mp_alloc_type = MP_ALLOC_NATIVE;
138 : :
139 : : /*
140 : : * Store specified sockets on which memory pool to be used by ports
141 : : * is allocated.
142 : : */
143 : : uint8_t port_numa[RTE_MAX_ETHPORTS];
144 : :
145 : : /*
146 : : * Store specified sockets on which RX ring to be used by ports
147 : : * is allocated.
148 : : */
149 : : uint8_t rxring_numa[RTE_MAX_ETHPORTS];
150 : :
151 : : /*
152 : : * Store specified sockets on which TX ring to be used by ports
153 : : * is allocated.
154 : : */
155 : : uint8_t txring_numa[RTE_MAX_ETHPORTS];
156 : :
157 : : /*
158 : : * Record the Ethernet address of peer target ports to which packets are
159 : : * forwarded.
160 : : * Must be instantiated with the ethernet addresses of peer traffic generator
161 : : * ports.
162 : : */
163 : : struct rte_ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
164 : : portid_t nb_peer_eth_addrs = 0;
165 : :
166 : : /*
167 : : * Probed Target Environment.
168 : : */
169 : : struct rte_port *ports; /**< For all probed ethernet ports. */
170 : : portid_t nb_ports; /**< Number of probed ethernet ports. */
171 : : struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
172 : : lcoreid_t nb_lcores; /**< Number of probed logical cores. */
173 : :
174 : : portid_t ports_ids[RTE_MAX_ETHPORTS]; /**< Store all port ids. */
175 : :
176 : : /*
177 : : * Test Forwarding Configuration.
178 : : * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
179 : : * nb_fwd_ports <= nb_cfg_ports <= nb_ports
180 : : */
181 : : lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
182 : : lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
183 : : portid_t nb_cfg_ports; /**< Number of configured ports. */
184 : : portid_t nb_fwd_ports; /**< Number of forwarding ports. */
185 : :
186 : : unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
187 : : portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
188 : :
189 : : struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
190 : : streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
191 : :
192 : : /*
193 : : * Forwarding engines.
194 : : */
195 : : struct fwd_engine * fwd_engines[] = {
196 : : &io_fwd_engine,
197 : : &mac_fwd_engine,
198 : : &mac_swap_engine,
199 : : &flow_gen_engine,
200 : : &rx_only_engine,
201 : : &tx_only_engine,
202 : : &csum_fwd_engine,
203 : : &icmp_echo_engine,
204 : : &noisy_vnf_engine,
205 : : &five_tuple_swap_fwd_engine,
206 : : &recycle_mbufs_engine,
207 : : #ifdef RTE_LIBRTE_IEEE1588
208 : : &ieee1588_fwd_engine,
209 : : #endif
210 : : &shared_rxq_engine,
211 : : NULL,
212 : : };
213 : :
214 : : /*
215 : : * Bitmask for control DCB forwarding for TCs.
216 : : * If bit-n in tc-mask is 1, then TC-n's forwarding is enabled, and vice versa.
217 : : */
218 : : uint8_t dcb_fwd_tc_mask = DEFAULT_DCB_FWD_TC_MASK;
219 : : /*
220 : : * Poll cores per TC when DCB forwarding.
221 : : * E.g. 1 indicates that one core process all queues of a TC.
222 : : * 2 indicates that two cores process all queues of a TC. If there
223 : : * is a TC with 8 queues, then [0, 3] belong to first core, and
224 : : * [4, 7] belong to second core.
225 : : * ...
226 : : */
227 : : uint8_t dcb_fwd_tc_cores = 1;
228 : :
229 : : struct rte_mempool *mempools[RTE_MAX_NUMA_NODES * MAX_SEGS_BUFFER_SPLIT];
230 : : uint16_t mempool_flags;
231 : :
232 : : struct fwd_config cur_fwd_config;
233 : : struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
234 : : uint32_t retry_enabled;
235 : : uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
236 : : uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
237 : :
238 : : uint32_t mbuf_data_size_n = 1; /* Number of specified mbuf sizes. */
239 : : uint16_t mbuf_data_size[MAX_SEGS_BUFFER_SPLIT] = {
240 : : DEFAULT_MBUF_DATA_SIZE
241 : : }; /**< Mbuf data space size. */
242 : : uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
243 : : * specified on command-line. */
244 : : uint16_t stats_period; /**< Period to show statistics (disabled by default) */
245 : :
246 : : /** Extended statistics to show. */
247 : : struct rte_eth_xstat_name *xstats_display;
248 : :
249 : : unsigned int xstats_display_num; /**< Size of extended statistics to show */
250 : :
251 : : /*
252 : : * In container, it cannot terminate the process which running with 'stats-period'
253 : : * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
254 : : */
255 : : volatile uint8_t f_quit;
256 : : uint8_t cl_quit; /* Quit testpmd from cmdline. */
257 : :
258 : : /*
259 : : * Max Rx frame size, set by '--max-pkt-len' parameter.
260 : : */
261 : : uint32_t max_rx_pkt_len;
262 : :
263 : : /*
264 : : * Configuration of packet segments used to scatter received packets
265 : : * if some of split features is configured.
266 : : */
267 : : uint16_t rx_pkt_seg_lengths[MAX_SEGS_BUFFER_SPLIT];
268 : : uint8_t rx_pkt_nb_segs; /**< Number of segments to split */
269 : : uint16_t rx_pkt_seg_offsets[MAX_SEGS_BUFFER_SPLIT];
270 : : uint8_t rx_pkt_nb_offs; /**< Number of specified offsets */
271 : : uint32_t rx_pkt_hdr_protos[MAX_SEGS_BUFFER_SPLIT];
272 : :
273 : : uint8_t multi_rx_mempool; /**< Enables multi-rx-mempool feature */
274 : :
275 : : /*
276 : : * Configuration of packet segments used by the "txonly" processing engine.
277 : : */
278 : : uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
279 : : uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
280 : : TXONLY_DEF_PACKET_LEN,
281 : : };
282 : : uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
283 : :
284 : : enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
285 : : /**< Split policy for packets to TX. */
286 : :
287 : : uint8_t txonly_multi_flow;
288 : : /**< Whether multiple flows are generated in TXONLY mode. */
289 : :
290 : : uint16_t txonly_flows = 64;
291 : : /**< Number of unique flows per lcore in TXONLY multi-flow mode. */
292 : :
293 : : uint32_t tx_pkt_times_inter;
294 : : /**< Timings for send scheduling in TXONLY mode, time between bursts. */
295 : :
296 : : uint32_t tx_pkt_times_intra;
297 : : /**< Timings for send scheduling in TXONLY mode, time between packets. */
298 : :
299 : : uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
300 : : uint16_t nb_pkt_flowgen_clones; /**< Number of Tx packet clones to send in flowgen mode. */
301 : : int nb_flows_flowgen = 1024; /**< Number of flows in flowgen mode. */
302 : : uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
303 : :
304 : : /* current configuration is in DCB or not,0 means it is not in DCB mode */
305 : : uint8_t dcb_config = 0;
306 : :
307 : : /*
308 : : * Configurable number of RX/TX queues.
309 : : */
310 : : queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
311 : : queueid_t nb_txq = 1; /**< Number of TX queues per port. */
312 : :
313 : : /*
314 : : * Configurable number of RX/TX ring descriptors.
315 : : * Defaults are supplied by drivers via ethdev.
316 : : */
317 : : #define RX_DESC_DEFAULT 0
318 : : #define TX_DESC_DEFAULT 0
319 : : uint16_t nb_rxd = RX_DESC_DEFAULT; /**< Number of RX descriptors. */
320 : : uint16_t nb_txd = TX_DESC_DEFAULT; /**< Number of TX descriptors. */
321 : :
322 : : #define RTE_PMD_PARAM_UNSET -1
323 : : /*
324 : : * Configurable values of RX and TX ring threshold registers.
325 : : */
326 : :
327 : : int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
328 : : int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
329 : : int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
330 : :
331 : : int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
332 : : int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
333 : : int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
334 : :
335 : : /*
336 : : * Configurable value of RX free threshold.
337 : : */
338 : : int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
339 : :
340 : : /*
341 : : * Configurable value of RX drop enable.
342 : : */
343 : : int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
344 : :
345 : : /*
346 : : * Configurable value of TX free threshold.
347 : : */
348 : : int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
349 : :
350 : : /*
351 : : * Configurable value of TX RS bit threshold.
352 : : */
353 : : int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
354 : :
355 : : /*
356 : : * Configurable sub-forwarding mode for the noisy_vnf forwarding mode.
357 : : */
358 : : enum noisy_fwd_mode noisy_fwd_mode;
359 : :
360 : : /* String version of enum noisy_fwd_mode */
361 : : const char * const noisy_fwd_mode_desc[] = {
362 : : [NOISY_FWD_MODE_IO] = "io",
363 : : [NOISY_FWD_MODE_MAC] = "mac",
364 : : [NOISY_FWD_MODE_MACSWAP] = "macswap",
365 : : [NOISY_FWD_MODE_5TSWAP] = "5tswap",
366 : : [NOISY_FWD_MODE_MAX] = NULL,
367 : : };
368 : :
369 : : /*
370 : : * Configurable value of buffered packets before sending.
371 : : */
372 : : uint16_t noisy_tx_sw_bufsz;
373 : :
374 : : /*
375 : : * Configurable value of packet buffer timeout.
376 : : */
377 : : uint16_t noisy_tx_sw_buf_flush_time;
378 : :
379 : : /*
380 : : * Configurable value for size of VNF internal memory area
381 : : * used for simulating noisy neighbour behaviour
382 : : */
383 : : uint64_t noisy_lkup_mem_sz;
384 : :
385 : : /*
386 : : * Configurable value of number of random writes done in
387 : : * VNF simulation memory area.
388 : : */
389 : : uint64_t noisy_lkup_num_writes;
390 : :
391 : : /*
392 : : * Configurable value of number of random reads done in
393 : : * VNF simulation memory area.
394 : : */
395 : : uint64_t noisy_lkup_num_reads;
396 : :
397 : : /*
398 : : * Configurable value of number of random reads/writes done in
399 : : * VNF simulation memory area.
400 : : */
401 : : uint64_t noisy_lkup_num_reads_writes;
402 : :
403 : : /*
404 : : * Receive Side Scaling (RSS) configuration.
405 : : */
406 : : uint64_t rss_hf = RTE_ETH_RSS_IP; /* RSS IP by default. */
407 : : bool force_rss; /* false == for single queue don't force rss */
408 : :
409 : : /*
410 : : * Port topology configuration
411 : : */
412 : : uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
413 : :
414 : : /*
415 : : * Avoids to flush all the RX streams before starts forwarding.
416 : : */
417 : : uint8_t no_flush_rx = 0; /* flush by default */
418 : :
419 : : /*
420 : : * Flow API isolated mode.
421 : : */
422 : : uint8_t flow_isolate_all;
423 : :
424 : : /*
425 : : * Disable port flow flush when stop port.
426 : : */
427 : : uint8_t no_flow_flush = 0; /* do flow flush by default */
428 : :
429 : : /*
430 : : * Avoids to check link status when starting/stopping a port.
431 : : */
432 : : uint8_t no_link_check = 0; /* check by default */
433 : :
434 : : /*
435 : : * Don't automatically start all ports in interactive mode.
436 : : */
437 : : uint8_t no_device_start = 0;
438 : :
439 : : /*
440 : : * Enable link status change notification
441 : : */
442 : : uint8_t lsc_interrupt = 1; /* enabled by default */
443 : :
444 : : /*
445 : : * Enable device removal notification.
446 : : */
447 : : uint8_t rmv_interrupt = 1; /* enabled by default */
448 : :
449 : : uint8_t hot_plug = 0; /**< hotplug disabled by default. */
450 : :
451 : : /* After attach, port setup is called on event or by iterator */
452 : : bool setup_on_probe_event = true;
453 : :
454 : : /* Clear ptypes on port initialization. */
455 : : uint8_t clear_ptypes = true;
456 : :
457 : : /* Pretty printing of ethdev events */
458 : : static const char * const eth_event_desc[] = {
459 : : [RTE_ETH_EVENT_UNKNOWN] = "unknown",
460 : : [RTE_ETH_EVENT_INTR_LSC] = "link state change",
461 : : [RTE_ETH_EVENT_QUEUE_STATE] = "queue state",
462 : : [RTE_ETH_EVENT_INTR_RESET] = "reset",
463 : : [RTE_ETH_EVENT_VF_MBOX] = "VF mbox",
464 : : [RTE_ETH_EVENT_IPSEC] = "IPsec",
465 : : [RTE_ETH_EVENT_MACSEC] = "MACsec",
466 : : [RTE_ETH_EVENT_INTR_RMV] = "device removal",
467 : : [RTE_ETH_EVENT_NEW] = "device probed",
468 : : [RTE_ETH_EVENT_DESTROY] = "device released",
469 : : [RTE_ETH_EVENT_FLOW_AGED] = "flow aged",
470 : : [RTE_ETH_EVENT_RX_AVAIL_THRESH] = "RxQ available descriptors threshold reached",
471 : : [RTE_ETH_EVENT_ERR_RECOVERING] = "error recovering",
472 : : [RTE_ETH_EVENT_RECOVERY_SUCCESS] = "error recovery successful",
473 : : [RTE_ETH_EVENT_RECOVERY_FAILED] = "error recovery failed",
474 : : [RTE_ETH_EVENT_MAX] = NULL,
475 : : };
476 : :
477 : : /*
478 : : * Display or mask ether events
479 : : * Default to all events except VF_MBOX
480 : : */
481 : : uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
482 : : (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
483 : : (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
484 : : (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
485 : : (UINT32_C(1) << RTE_ETH_EVENT_IPSEC) |
486 : : (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
487 : : (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV) |
488 : : (UINT32_C(1) << RTE_ETH_EVENT_FLOW_AGED) |
489 : : (UINT32_C(1) << RTE_ETH_EVENT_ERR_RECOVERING) |
490 : : (UINT32_C(1) << RTE_ETH_EVENT_RECOVERY_SUCCESS) |
491 : : (UINT32_C(1) << RTE_ETH_EVENT_RECOVERY_FAILED);
492 : : /*
493 : : * Decide if all memory are locked for performance.
494 : : */
495 : : int do_mlockall = 0;
496 : :
497 : : #ifdef RTE_LIB_LATENCYSTATS
498 : :
499 : : /*
500 : : * Set when latency stats is enabled in the commandline
501 : : */
502 : : uint8_t latencystats_enabled;
503 : :
504 : : /*
505 : : * Lcore ID to service latency statistics.
506 : : */
507 : : lcoreid_t latencystats_lcore_id = -1;
508 : :
509 : : #endif
510 : :
511 : : /*
512 : : * Ethernet device configuration.
513 : : */
514 : : struct rte_eth_rxmode rx_mode;
515 : :
516 : : struct rte_eth_txmode tx_mode = {
517 : : .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE,
518 : : };
519 : :
520 : : volatile int test_done = 1; /* stop packet forwarding when set to 1. */
521 : :
522 : : /*
523 : : * Display zero values by default for xstats
524 : : */
525 : : uint8_t xstats_hide_zero;
526 : :
527 : : /*
528 : : * Display of xstats without their state disabled by default
529 : : */
530 : : uint8_t xstats_show_state;
531 : :
532 : : /*
533 : : * Display disabled xstat by default for xstats
534 : : */
535 : : uint8_t xstats_hide_disabled;
536 : :
537 : : /*
538 : : * Measure of CPU cycles disabled by default
539 : : */
540 : : uint8_t record_core_cycles;
541 : :
542 : : /*
543 : : * Display of RX and TX bursts disabled by default
544 : : */
545 : : uint8_t record_burst_stats;
546 : :
547 : : /*
548 : : * Enable Rx queue sharing between ports in the same switch and Rx domain.
549 : : */
550 : : uint8_t rxq_share;
551 : :
552 : : struct share_group_slot {
553 : : uint16_t domain_id;
554 : : uint16_t rx_domain;
555 : : uint16_t share_group;
556 : : };
557 : :
558 : : static struct share_group_slot share_group_slots[RTE_MAX_ETHPORTS];
559 : :
560 : : unsigned int num_sockets = 0;
561 : : unsigned int socket_ids[RTE_MAX_NUMA_NODES];
562 : :
563 : : #ifdef RTE_LIB_BITRATESTATS
564 : : /* Bitrate statistics */
565 : : struct rte_stats_bitrates *bitrate_data;
566 : : lcoreid_t bitrate_lcore_id;
567 : : uint8_t bitrate_enabled;
568 : : #endif
569 : :
570 : : #ifdef RTE_LIB_GRO
571 : : struct gro_status gro_ports[RTE_MAX_ETHPORTS];
572 : : uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
573 : : #endif
574 : :
575 : : /*
576 : : * hexadecimal bitmask of RX mq mode can be enabled.
577 : : */
578 : : enum rte_eth_rx_mq_mode rx_mq_mode = RTE_ETH_MQ_RX_VMDQ_DCB_RSS;
579 : :
580 : : /*
581 : : * Used to set forced link speed
582 : : */
583 : : uint32_t eth_link_speed;
584 : :
585 : : /*
586 : : * ID of the current process in multi-process, used to
587 : : * configure the queues to be polled.
588 : : */
589 : : int proc_id;
590 : :
591 : : /*
592 : : * Number of processes in multi-process, used to
593 : : * configure the queues to be polled.
594 : : */
595 : : unsigned int num_procs = 1;
596 : :
597 : : static int
598 : 0 : assign_share_group(struct rte_eth_dev_info *dev_info, uint16_t *share_group)
599 : : {
600 : : unsigned int first_free = RTE_DIM(share_group_slots);
601 : : unsigned int i;
602 : :
603 : 0 : for (i = 0; i < RTE_DIM(share_group_slots); i++) {
604 : 0 : if (share_group_slots[i].share_group > 0) {
605 : 0 : if (dev_info->switch_info.domain_id == share_group_slots[i].domain_id &&
606 : 0 : dev_info->switch_info.rx_domain == share_group_slots[i].rx_domain) {
607 : 0 : *share_group = share_group_slots[i].share_group;
608 : 0 : return 0;
609 : : }
610 : 0 : } else if (first_free == RTE_DIM(share_group_slots)) {
611 : : first_free = i;
612 : : }
613 : : }
614 : :
615 : 0 : if (first_free == RTE_DIM(share_group_slots))
616 : : return -ENOSPC;
617 : :
618 : 0 : share_group_slots[first_free].domain_id = dev_info->switch_info.domain_id;
619 : 0 : share_group_slots[first_free].rx_domain = dev_info->switch_info.rx_domain;
620 : 0 : share_group_slots[first_free].share_group = first_free + 1;
621 : 0 : *share_group = share_group_slots[first_free].share_group;
622 : :
623 : 0 : return 0;
624 : : }
625 : :
626 : : static void
627 : 0 : try_release_share_group(struct share_group_slot *slot)
628 : : {
629 : : uint16_t pi;
630 : :
631 : : /* Check if any port still uses this share group. */
632 : 0 : RTE_ETH_FOREACH_DEV(pi) {
633 : 0 : if (ports[pi].dev_info.switch_info.domain_id == slot->domain_id &&
634 : 0 : ports[pi].dev_info.switch_info.rx_domain == slot->rx_domain) {
635 : : return;
636 : : }
637 : : }
638 : :
639 : 0 : slot->share_group = 0;
640 : 0 : slot->domain_id = 0;
641 : 0 : slot->rx_domain = 0;
642 : : }
643 : :
644 : : static void
645 : 0 : try_release_share_groups(void)
646 : : {
647 : : unsigned int i;
648 : :
649 : : /* Try release each used share group. */
650 : 0 : for (i = 0; i < RTE_DIM(share_group_slots); i++)
651 : 0 : if (share_group_slots[i].share_group > 0)
652 : 0 : try_release_share_group(&share_group_slots[i]);
653 : 0 : }
654 : :
655 : : static void
656 : 0 : eth_rx_metadata_negotiate_mp(uint16_t port_id)
657 : : {
658 : 0 : uint64_t rx_meta_features = 0;
659 : : int ret;
660 : :
661 : 0 : if (!is_proc_primary())
662 : 0 : return;
663 : :
664 : 0 : rx_meta_features |= RTE_ETH_RX_METADATA_USER_FLAG;
665 : 0 : rx_meta_features |= RTE_ETH_RX_METADATA_USER_MARK;
666 : 0 : rx_meta_features |= RTE_ETH_RX_METADATA_TUNNEL_ID;
667 : :
668 : 0 : ret = rte_eth_rx_metadata_negotiate(port_id, &rx_meta_features);
669 : 0 : if (ret == 0) {
670 : 0 : if (!(rx_meta_features & RTE_ETH_RX_METADATA_USER_FLAG)) {
671 : 0 : TESTPMD_LOG(DEBUG, "Flow action FLAG will not affect Rx mbufs on port %u\n",
672 : : port_id);
673 : : }
674 : :
675 : 0 : if (!(rx_meta_features & RTE_ETH_RX_METADATA_USER_MARK)) {
676 : 0 : TESTPMD_LOG(DEBUG, "Flow action MARK will not affect Rx mbufs on port %u\n",
677 : : port_id);
678 : : }
679 : :
680 : 0 : if (!(rx_meta_features & RTE_ETH_RX_METADATA_TUNNEL_ID)) {
681 : 0 : TESTPMD_LOG(DEBUG, "Flow tunnel offload support might be limited or unavailable on port %u\n",
682 : : port_id);
683 : : }
684 : 0 : } else if (ret != -ENOTSUP) {
685 : 0 : rte_exit(EXIT_FAILURE, "Error when negotiating Rx meta features on port %u: %s\n",
686 : : port_id, rte_strerror(-ret));
687 : : }
688 : : }
689 : :
690 : : static int
691 : : eth_dev_configure_mp(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
692 : : const struct rte_eth_conf *dev_conf)
693 : : {
694 : 0 : if (is_proc_primary())
695 : 0 : return rte_eth_dev_configure(port_id, nb_rx_q, nb_tx_q,
696 : : dev_conf);
697 : : return 0;
698 : : }
699 : :
700 : : static int
701 : 0 : change_bonding_member_port_status(portid_t bond_pid, bool is_stop)
702 : : {
703 : : #ifdef RTE_NET_BOND
704 : :
705 : : portid_t member_pids[RTE_MAX_ETHPORTS];
706 : : struct rte_port *port;
707 : : int num_members;
708 : : portid_t member_pid;
709 : : int i;
710 : :
711 : 0 : num_members = rte_eth_bond_members_get(bond_pid, member_pids,
712 : : RTE_MAX_ETHPORTS);
713 : 0 : if (num_members < 0) {
714 : 0 : fprintf(stderr, "Failed to get member list for port = %u\n",
715 : : bond_pid);
716 : 0 : return num_members;
717 : : }
718 : :
719 : 0 : for (i = 0; i < num_members; i++) {
720 : 0 : member_pid = member_pids[i];
721 : 0 : port = &ports[member_pid];
722 : 0 : port->port_status =
723 : 0 : is_stop ? RTE_PORT_STOPPED : RTE_PORT_STARTED;
724 : : }
725 : : #else
726 : : RTE_SET_USED(bond_pid);
727 : : RTE_SET_USED(is_stop);
728 : : #endif
729 : : return 0;
730 : : }
731 : :
732 : : static int
733 : 0 : eth_dev_start_mp(uint16_t port_id)
734 : : {
735 : : int ret;
736 : :
737 : 0 : if (is_proc_primary()) {
738 : 0 : ret = rte_eth_dev_start(port_id);
739 : 0 : if (ret != 0)
740 : : return ret;
741 : :
742 : 0 : struct rte_port *port = &ports[port_id];
743 : :
744 : : /*
745 : : * Starting a bonding port also starts all members under the bonding
746 : : * device. So if this port is bond device, we need to modify the
747 : : * port status of these members.
748 : : */
749 : 0 : if (port->bond_flag == 1)
750 : 0 : return change_bonding_member_port_status(port_id, false);
751 : : }
752 : :
753 : : return 0;
754 : : }
755 : :
756 : : static int
757 : 0 : eth_dev_stop_mp(uint16_t port_id)
758 : : {
759 : : int ret;
760 : :
761 : 0 : if (is_proc_primary()) {
762 : 0 : ret = rte_eth_dev_stop(port_id);
763 : 0 : if (ret != 0)
764 : : return ret;
765 : :
766 : 0 : struct rte_port *port = &ports[port_id];
767 : :
768 : : /*
769 : : * Stopping a bonding port also stops all members under the bonding
770 : : * device. So if this port is bond device, we need to modify the
771 : : * port status of these members.
772 : : */
773 : 0 : if (port->bond_flag == 1)
774 : 0 : return change_bonding_member_port_status(port_id, true);
775 : : }
776 : :
777 : : return 0;
778 : : }
779 : :
780 : : static void
781 : : mempool_free_mp(struct rte_mempool *mp)
782 : : {
783 : 0 : if (is_proc_primary())
784 : 0 : rte_mempool_free(mp);
785 : : }
786 : :
787 : : static int
788 : : eth_dev_set_mtu_mp(uint16_t port_id, uint16_t mtu)
789 : : {
790 : 0 : if (is_proc_primary())
791 : 0 : return rte_eth_dev_set_mtu(port_id, mtu);
792 : :
793 : : return 0;
794 : : }
795 : :
796 : : /* Forward function declarations */
797 : : static void setup_attached_port(portid_t pi);
798 : : static void check_all_ports_link_status(uint32_t port_mask);
799 : : static int eth_event_callback(portid_t port_id,
800 : : enum rte_eth_event_type type,
801 : : void *param, void *ret_param);
802 : : static void dev_event_callback(const char *device_name,
803 : : enum rte_dev_event_type type,
804 : : void *param);
805 : : static void fill_xstats_display_info(void);
806 : :
807 : : /*
808 : : * Check if all the ports are started.
809 : : * If yes, return positive value. If not, return zero.
810 : : */
811 : : static int all_ports_started(void);
812 : :
813 : : #ifdef RTE_LIB_GSO
814 : : struct gso_status gso_ports[RTE_MAX_ETHPORTS];
815 : : uint16_t gso_max_segment_size = RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN;
816 : : #endif
817 : :
818 : : /* Holds the registered mbuf dynamic flags names. */
819 : : char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
820 : :
821 : :
822 : : /*
823 : : * Helper function to check if socket is already discovered.
824 : : * If yes, return positive value. If not, return zero.
825 : : */
826 : : int
827 : 0 : new_socket_id(unsigned int socket_id)
828 : : {
829 : : unsigned int i;
830 : :
831 : 0 : for (i = 0; i < num_sockets; i++) {
832 : 0 : if (socket_ids[i] == socket_id)
833 : : return 0;
834 : : }
835 : : return 1;
836 : : }
837 : :
838 : : /*
839 : : * Setup default configuration.
840 : : */
841 : : static void
842 : 0 : set_default_fwd_lcores_config(void)
843 : : {
844 : : unsigned int i;
845 : : unsigned int nb_lc;
846 : : unsigned int sock_num;
847 : :
848 : : nb_lc = 0;
849 : 0 : for (i = 0; i < RTE_MAX_LCORE; i++) {
850 : 0 : if (!rte_lcore_is_enabled(i))
851 : 0 : continue;
852 : 0 : sock_num = rte_lcore_to_socket_id(i);
853 : 0 : if (new_socket_id(sock_num)) {
854 : 0 : if (num_sockets >= RTE_MAX_NUMA_NODES) {
855 : 0 : rte_exit(EXIT_FAILURE,
856 : : "Total sockets greater than %u\n",
857 : : RTE_MAX_NUMA_NODES);
858 : : }
859 : 0 : socket_ids[num_sockets++] = sock_num;
860 : : }
861 : 0 : if (i == rte_get_main_lcore())
862 : 0 : continue;
863 : 0 : fwd_lcores_cpuids[nb_lc++] = i;
864 : : }
865 : 0 : nb_lcores = (lcoreid_t) nb_lc;
866 : 0 : nb_cfg_lcores = nb_lcores;
867 : 0 : nb_fwd_lcores = 1;
868 : 0 : }
869 : :
870 : : static void
871 : : set_def_peer_eth_addrs(void)
872 : : {
873 : : portid_t i;
874 : :
875 : 0 : for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
876 : 0 : peer_eth_addrs[i].addr_bytes[0] = RTE_ETHER_LOCAL_ADMIN_ADDR;
877 : 0 : peer_eth_addrs[i].addr_bytes[5] = i;
878 : : }
879 : : }
880 : :
881 : : static void
882 : 0 : set_default_fwd_ports_config(void)
883 : : {
884 : : portid_t pt_id;
885 : : int i = 0;
886 : :
887 : 0 : RTE_ETH_FOREACH_DEV(pt_id) {
888 : 0 : fwd_ports_ids[i++] = pt_id;
889 : :
890 : : /* Update sockets info according to the attached device */
891 : 0 : int socket_id = rte_eth_dev_socket_id(pt_id);
892 : 0 : if (socket_id >= 0 && new_socket_id(socket_id)) {
893 : 0 : if (num_sockets >= RTE_MAX_NUMA_NODES) {
894 : 0 : rte_exit(EXIT_FAILURE,
895 : : "Total sockets greater than %u\n",
896 : : RTE_MAX_NUMA_NODES);
897 : : }
898 : 0 : socket_ids[num_sockets++] = socket_id;
899 : : }
900 : : }
901 : :
902 : 0 : nb_cfg_ports = nb_ports;
903 : 0 : nb_fwd_ports = nb_ports;
904 : 0 : }
905 : :
906 : : void
907 : 0 : set_def_fwd_config(void)
908 : : {
909 : 0 : set_default_fwd_lcores_config();
910 : : set_def_peer_eth_addrs();
911 : 0 : set_default_fwd_ports_config();
912 : 0 : }
913 : :
914 : : #ifndef RTE_EXEC_ENV_WINDOWS
915 : : /* extremely pessimistic estimation of memory required to create a mempool */
916 : : static int
917 : 0 : calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
918 : : {
919 : : unsigned int n_pages, mbuf_per_pg, leftover;
920 : : uint64_t total_mem, mbuf_mem, obj_sz;
921 : :
922 : : /* there is no good way to predict how much space the mempool will
923 : : * occupy because it will allocate chunks on the fly, and some of those
924 : : * will come from default DPDK memory while some will come from our
925 : : * external memory, so just assume 128MB will be enough for everyone.
926 : : */
927 : : uint64_t hdr_mem = 128 << 20;
928 : :
929 : : /* account for possible non-contiguousness */
930 : 0 : obj_sz = rte_mempool_calc_obj_size(mbuf_sz, 0, NULL);
931 : 0 : if (obj_sz > pgsz) {
932 : 0 : TESTPMD_LOG(ERR, "Object size is bigger than page size\n");
933 : 0 : return -1;
934 : : }
935 : :
936 : 0 : mbuf_per_pg = pgsz / obj_sz;
937 : 0 : leftover = (nb_mbufs % mbuf_per_pg) > 0;
938 : 0 : n_pages = (nb_mbufs / mbuf_per_pg) + leftover;
939 : :
940 : 0 : mbuf_mem = n_pages * pgsz;
941 : :
942 : 0 : total_mem = RTE_ALIGN(hdr_mem + mbuf_mem, pgsz);
943 : :
944 : : if (total_mem > SIZE_MAX) {
945 : : TESTPMD_LOG(ERR, "Memory size too big\n");
946 : : return -1;
947 : : }
948 : 0 : *out = (size_t)total_mem;
949 : :
950 : 0 : return 0;
951 : : }
952 : :
953 : : static int
954 : 0 : pagesz_flags(uint64_t page_sz)
955 : : {
956 : : /* as per mmap() manpage, all page sizes are log2 of page size
957 : : * shifted by MAP_HUGE_SHIFT
958 : : */
959 : 0 : int log2 = rte_log2_u64(page_sz);
960 : :
961 : 0 : return (log2 << HUGE_SHIFT);
962 : : }
963 : :
964 : : static void *
965 : 0 : alloc_mem(size_t memsz, size_t pgsz, bool huge)
966 : : {
967 : : void *addr;
968 : : int flags;
969 : :
970 : : /* allocate anonymous hugepages */
971 : : flags = MAP_ANONYMOUS | MAP_PRIVATE;
972 : 0 : if (huge)
973 : 0 : flags |= HUGE_FLAG | pagesz_flags(pgsz);
974 : :
975 : 0 : addr = mmap(NULL, memsz, PROT_READ | PROT_WRITE, flags, -1, 0);
976 : 0 : if (addr == MAP_FAILED)
977 : 0 : return NULL;
978 : :
979 : : return addr;
980 : : }
981 : :
982 : : struct extmem_param {
983 : : void *addr;
984 : : size_t len;
985 : : size_t pgsz;
986 : : rte_iova_t *iova_table;
987 : : unsigned int iova_table_len;
988 : : };
989 : :
990 : : static int
991 : 0 : create_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, struct extmem_param *param,
992 : : bool huge)
993 : : {
994 : 0 : uint64_t pgsizes[] = {RTE_PGSIZE_2M, RTE_PGSIZE_1G, /* x86_64, ARM */
995 : : RTE_PGSIZE_16M, RTE_PGSIZE_16G}; /* POWER */
996 : : unsigned int cur_page, n_pages, pgsz_idx;
997 : : size_t mem_sz, cur_pgsz;
998 : : rte_iova_t *iovas = NULL;
999 : : void *addr;
1000 : : int ret;
1001 : :
1002 : 0 : for (pgsz_idx = 0; pgsz_idx < RTE_DIM(pgsizes); pgsz_idx++) {
1003 : : /* skip anything that is too big */
1004 : : if (pgsizes[pgsz_idx] > SIZE_MAX)
1005 : : continue;
1006 : :
1007 : 0 : cur_pgsz = pgsizes[pgsz_idx];
1008 : :
1009 : : /* if we were told not to allocate hugepages, override */
1010 : 0 : if (!huge)
1011 : 0 : cur_pgsz = sysconf(_SC_PAGESIZE);
1012 : :
1013 : 0 : ret = calc_mem_size(nb_mbufs, mbuf_sz, cur_pgsz, &mem_sz);
1014 : 0 : if (ret < 0) {
1015 : 0 : TESTPMD_LOG(ERR, "Cannot calculate memory size\n");
1016 : 0 : return -1;
1017 : : }
1018 : :
1019 : : /* allocate our memory */
1020 : 0 : addr = alloc_mem(mem_sz, cur_pgsz, huge);
1021 : :
1022 : : /* if we couldn't allocate memory with a specified page size,
1023 : : * that doesn't mean we can't do it with other page sizes, so
1024 : : * try another one.
1025 : : */
1026 : 0 : if (addr == NULL)
1027 : : continue;
1028 : :
1029 : : /* store IOVA addresses for every page in this memory area */
1030 : 0 : n_pages = mem_sz / cur_pgsz;
1031 : :
1032 : 0 : iovas = malloc(sizeof(*iovas) * n_pages);
1033 : :
1034 : 0 : if (iovas == NULL) {
1035 : 0 : TESTPMD_LOG(ERR, "Cannot allocate memory for iova addresses\n");
1036 : 0 : goto fail;
1037 : : }
1038 : : /* lock memory if it's not huge pages */
1039 : 0 : if (!huge)
1040 : 0 : mlock(addr, mem_sz);
1041 : :
1042 : : /* populate IOVA addresses */
1043 : 0 : for (cur_page = 0; cur_page < n_pages; cur_page++) {
1044 : : rte_iova_t iova;
1045 : : size_t offset;
1046 : : void *cur;
1047 : :
1048 : 0 : offset = cur_pgsz * cur_page;
1049 : 0 : cur = RTE_PTR_ADD(addr, offset);
1050 : :
1051 : : /* touch the page before getting its IOVA */
1052 : 0 : *(volatile char *)cur = 0;
1053 : :
1054 : 0 : iova = rte_mem_virt2iova(cur);
1055 : :
1056 : 0 : iovas[cur_page] = iova;
1057 : : }
1058 : :
1059 : : break;
1060 : : }
1061 : : /* if we couldn't allocate anything */
1062 : 0 : if (iovas == NULL)
1063 : : return -1;
1064 : :
1065 : 0 : param->addr = addr;
1066 : 0 : param->len = mem_sz;
1067 : 0 : param->pgsz = cur_pgsz;
1068 : 0 : param->iova_table = iovas;
1069 : 0 : param->iova_table_len = n_pages;
1070 : :
1071 : 0 : return 0;
1072 : : fail:
1073 : : free(iovas);
1074 : : if (addr)
1075 : 0 : munmap(addr, mem_sz);
1076 : :
1077 : 0 : return -1;
1078 : : }
1079 : :
1080 : : static int
1081 : 0 : setup_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, bool huge)
1082 : : {
1083 : : struct extmem_param param;
1084 : : int socket_id, ret;
1085 : :
1086 : : memset(¶m, 0, sizeof(param));
1087 : :
1088 : : /* check if our heap exists */
1089 : 0 : socket_id = rte_malloc_heap_get_socket(EXTMEM_HEAP_NAME);
1090 : 0 : if (socket_id < 0) {
1091 : : /* create our heap */
1092 : 0 : ret = rte_malloc_heap_create(EXTMEM_HEAP_NAME);
1093 : 0 : if (ret < 0) {
1094 : 0 : TESTPMD_LOG(ERR, "Cannot create heap\n");
1095 : 0 : return -1;
1096 : : }
1097 : : }
1098 : :
1099 : 0 : ret = create_extmem(nb_mbufs, mbuf_sz, ¶m, huge);
1100 : 0 : if (ret < 0) {
1101 : 0 : TESTPMD_LOG(ERR, "Cannot create memory area\n");
1102 : 0 : return -1;
1103 : : }
1104 : :
1105 : : /* we now have a valid memory area, so add it to heap */
1106 : 0 : ret = rte_malloc_heap_memory_add(EXTMEM_HEAP_NAME,
1107 : : param.addr, param.len, param.iova_table,
1108 : : param.iova_table_len, param.pgsz);
1109 : :
1110 : : /* when using VFIO, memory is automatically mapped for DMA by EAL */
1111 : :
1112 : : /* not needed any more */
1113 : 0 : free(param.iova_table);
1114 : :
1115 : 0 : if (ret < 0) {
1116 : 0 : TESTPMD_LOG(ERR, "Cannot add memory to heap\n");
1117 : 0 : munmap(param.addr, param.len);
1118 : 0 : return -1;
1119 : : }
1120 : :
1121 : : /* success */
1122 : :
1123 : 0 : TESTPMD_LOG(DEBUG, "Allocated %zuMB of external memory\n",
1124 : : param.len >> 20);
1125 : :
1126 : 0 : return 0;
1127 : : }
1128 : : static void
1129 : 0 : dma_unmap_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
1130 : : struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused)
1131 : : {
1132 : : uint16_t pid = 0;
1133 : : int ret;
1134 : :
1135 : 0 : RTE_ETH_FOREACH_DEV(pid) {
1136 : : struct rte_eth_dev_info dev_info;
1137 : :
1138 : 0 : ret = eth_dev_info_get_print_err(pid, &dev_info);
1139 : 0 : if (ret != 0) {
1140 : 0 : TESTPMD_LOG(DEBUG,
1141 : : "unable to get device info for port %d on addr 0x%p,"
1142 : : "mempool unmapping will not be performed\n",
1143 : : pid, memhdr->addr);
1144 : 0 : continue;
1145 : : }
1146 : :
1147 : 0 : ret = rte_dev_dma_unmap(dev_info.device, memhdr->addr, 0, memhdr->len);
1148 : 0 : if (ret) {
1149 : 0 : TESTPMD_LOG(DEBUG,
1150 : : "unable to DMA unmap addr 0x%p "
1151 : : "for device %s\n",
1152 : : memhdr->addr, rte_dev_name(dev_info.device));
1153 : : }
1154 : : }
1155 : 0 : ret = rte_extmem_unregister(memhdr->addr, memhdr->len);
1156 : 0 : if (ret) {
1157 : 0 : TESTPMD_LOG(DEBUG,
1158 : : "unable to un-register addr 0x%p\n", memhdr->addr);
1159 : : }
1160 : 0 : }
1161 : :
1162 : : static void
1163 : 0 : dma_map_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
1164 : : struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused)
1165 : : {
1166 : : uint16_t pid = 0;
1167 : 0 : size_t page_size = sysconf(_SC_PAGESIZE);
1168 : : int ret;
1169 : :
1170 : 0 : ret = rte_extmem_register(memhdr->addr, memhdr->len, NULL, 0,
1171 : : page_size);
1172 : 0 : if (ret) {
1173 : 0 : TESTPMD_LOG(DEBUG,
1174 : : "unable to register addr 0x%p\n", memhdr->addr);
1175 : 0 : return;
1176 : : }
1177 : 0 : RTE_ETH_FOREACH_DEV(pid) {
1178 : : struct rte_eth_dev_info dev_info;
1179 : :
1180 : 0 : ret = eth_dev_info_get_print_err(pid, &dev_info);
1181 : 0 : if (ret != 0) {
1182 : 0 : TESTPMD_LOG(DEBUG,
1183 : : "unable to get device info for port %d on addr 0x%p,"
1184 : : "mempool mapping will not be performed\n",
1185 : : pid, memhdr->addr);
1186 : 0 : continue;
1187 : : }
1188 : 0 : ret = rte_dev_dma_map(dev_info.device, memhdr->addr, 0, memhdr->len);
1189 : 0 : if (ret) {
1190 : 0 : TESTPMD_LOG(DEBUG,
1191 : : "unable to DMA map addr 0x%p "
1192 : : "for device %s\n",
1193 : : memhdr->addr, rte_dev_name(dev_info.device));
1194 : : }
1195 : : }
1196 : : }
1197 : : #endif
1198 : :
1199 : : static unsigned int
1200 : 0 : setup_extbuf(uint32_t nb_mbufs, uint16_t mbuf_sz, unsigned int socket_id,
1201 : : char *pool_name, struct rte_pktmbuf_extmem **ext_mem)
1202 : : {
1203 : : struct rte_pktmbuf_extmem *xmem;
1204 : : unsigned int ext_num, zone_num, elt_num;
1205 : : uint16_t elt_size;
1206 : :
1207 : 0 : elt_size = RTE_ALIGN_CEIL(mbuf_sz, RTE_CACHE_LINE_SIZE);
1208 : 0 : elt_num = EXTBUF_ZONE_SIZE / elt_size;
1209 : 0 : zone_num = (nb_mbufs + elt_num - 1) / elt_num;
1210 : :
1211 : 0 : xmem = malloc(sizeof(struct rte_pktmbuf_extmem) * zone_num);
1212 : 0 : if (xmem == NULL) {
1213 : 0 : TESTPMD_LOG(ERR, "Cannot allocate memory for "
1214 : : "external buffer descriptors\n");
1215 : 0 : *ext_mem = NULL;
1216 : 0 : return 0;
1217 : : }
1218 : 0 : for (ext_num = 0; ext_num < zone_num; ext_num++) {
1219 : 0 : struct rte_pktmbuf_extmem *xseg = xmem + ext_num;
1220 : : const struct rte_memzone *mz;
1221 : : char mz_name[RTE_MEMZONE_NAMESIZE];
1222 : : int ret;
1223 : :
1224 : : ret = snprintf(mz_name, sizeof(mz_name),
1225 : : RTE_MEMPOOL_MZ_FORMAT "_xb_%u", pool_name, ext_num);
1226 : 0 : if (ret < 0 || ret >= (int)sizeof(mz_name)) {
1227 : 0 : errno = ENAMETOOLONG;
1228 : : ext_num = 0;
1229 : 0 : break;
1230 : : }
1231 : 0 : mz = rte_memzone_reserve(mz_name, EXTBUF_ZONE_SIZE,
1232 : : socket_id,
1233 : : RTE_MEMZONE_IOVA_CONTIG |
1234 : : RTE_MEMZONE_1GB |
1235 : : RTE_MEMZONE_SIZE_HINT_ONLY);
1236 : 0 : if (mz == NULL) {
1237 : : /*
1238 : : * The caller exits on external buffer creation
1239 : : * error, so there is no need to free memzones.
1240 : : */
1241 : 0 : errno = ENOMEM;
1242 : : ext_num = 0;
1243 : 0 : break;
1244 : : }
1245 : 0 : xseg->buf_ptr = mz->addr;
1246 : 0 : xseg->buf_iova = mz->iova;
1247 : 0 : xseg->buf_len = EXTBUF_ZONE_SIZE;
1248 : 0 : xseg->elt_size = elt_size;
1249 : : }
1250 : 0 : if (ext_num == 0 && xmem != NULL) {
1251 : 0 : free(xmem);
1252 : : xmem = NULL;
1253 : : }
1254 : 0 : *ext_mem = xmem;
1255 : 0 : return ext_num;
1256 : : }
1257 : :
1258 : : /*
1259 : : * Configuration initialisation done once at init time.
1260 : : */
1261 : : static struct rte_mempool *
1262 : 0 : mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
1263 : : unsigned int socket_id, uint16_t size_idx)
1264 : : {
1265 : : char pool_name[RTE_MEMPOOL_NAMESIZE];
1266 : : struct rte_mempool *rte_mp = NULL;
1267 : : #ifndef RTE_EXEC_ENV_WINDOWS
1268 : : uint32_t mb_size;
1269 : :
1270 : 0 : mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
1271 : : #endif
1272 : 0 : mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name), size_idx);
1273 : 0 : if (!is_proc_primary()) {
1274 : 0 : rte_mp = rte_mempool_lookup(pool_name);
1275 : 0 : if (rte_mp == NULL)
1276 : 0 : rte_exit(EXIT_FAILURE,
1277 : : "Get mbuf pool for socket %u failed: %s\n",
1278 : : socket_id, rte_strerror(rte_errno));
1279 : : return rte_mp;
1280 : : }
1281 : :
1282 : 0 : TESTPMD_LOG(INFO,
1283 : : "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
1284 : : pool_name, nb_mbuf, mbuf_seg_size, socket_id);
1285 : :
1286 : 0 : switch (mp_alloc_type) {
1287 : 0 : case MP_ALLOC_NATIVE:
1288 : : {
1289 : : /* wrapper to rte_mempool_create() */
1290 : 0 : TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
1291 : : rte_mbuf_best_mempool_ops());
1292 : 0 : rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
1293 : : mb_mempool_cache, 0, mbuf_seg_size, socket_id);
1294 : 0 : break;
1295 : : }
1296 : : #ifndef RTE_EXEC_ENV_WINDOWS
1297 : 0 : case MP_ALLOC_ANON:
1298 : : {
1299 : 0 : rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
1300 : : mb_size, (unsigned int) mb_mempool_cache,
1301 : : sizeof(struct rte_pktmbuf_pool_private),
1302 : : socket_id, mempool_flags);
1303 : 0 : if (rte_mp == NULL)
1304 : 0 : goto err;
1305 : :
1306 : 0 : if (rte_mempool_populate_anon(rte_mp) == 0) {
1307 : 0 : rte_mempool_free(rte_mp);
1308 : : rte_mp = NULL;
1309 : 0 : goto err;
1310 : : }
1311 : 0 : rte_pktmbuf_pool_init(rte_mp, NULL);
1312 : 0 : rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
1313 : 0 : rte_mempool_mem_iter(rte_mp, dma_map_cb, NULL);
1314 : 0 : break;
1315 : : }
1316 : 0 : case MP_ALLOC_XMEM:
1317 : : case MP_ALLOC_XMEM_HUGE:
1318 : : {
1319 : : int heap_socket;
1320 : 0 : bool huge = mp_alloc_type == MP_ALLOC_XMEM_HUGE;
1321 : :
1322 : 0 : if (setup_extmem(nb_mbuf, mbuf_seg_size, huge) < 0)
1323 : 0 : rte_exit(EXIT_FAILURE, "Could not create external memory\n");
1324 : :
1325 : : heap_socket =
1326 : 0 : rte_malloc_heap_get_socket(EXTMEM_HEAP_NAME);
1327 : 0 : if (heap_socket < 0)
1328 : 0 : rte_exit(EXIT_FAILURE, "Could not get external memory socket ID\n");
1329 : :
1330 : 0 : TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
1331 : : rte_mbuf_best_mempool_ops());
1332 : 0 : rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
1333 : : mb_mempool_cache, 0, mbuf_seg_size,
1334 : : heap_socket);
1335 : 0 : break;
1336 : : }
1337 : : #endif
1338 : 0 : case MP_ALLOC_XBUF:
1339 : : {
1340 : : struct rte_pktmbuf_extmem *ext_mem;
1341 : : unsigned int ext_num;
1342 : :
1343 : 0 : ext_num = setup_extbuf(nb_mbuf, mbuf_seg_size,
1344 : : socket_id, pool_name, &ext_mem);
1345 : 0 : if (ext_num == 0)
1346 : 0 : rte_exit(EXIT_FAILURE,
1347 : : "Can't create pinned data buffers\n");
1348 : :
1349 : 0 : TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
1350 : : rte_mbuf_best_mempool_ops());
1351 : 0 : rte_mp = rte_pktmbuf_pool_create_extbuf
1352 : : (pool_name, nb_mbuf, mb_mempool_cache,
1353 : : 0, mbuf_seg_size, socket_id,
1354 : : ext_mem, ext_num);
1355 : 0 : free(ext_mem);
1356 : : break;
1357 : : }
1358 : 0 : default:
1359 : : {
1360 : 0 : rte_exit(EXIT_FAILURE, "Invalid mempool creation mode\n");
1361 : : }
1362 : : }
1363 : :
1364 : : #ifndef RTE_EXEC_ENV_WINDOWS
1365 : 0 : err:
1366 : : #endif
1367 : 0 : if (rte_mp == NULL) {
1368 : 0 : rte_exit(EXIT_FAILURE,
1369 : : "Creation of mbuf pool for socket %u failed: %s\n",
1370 : : socket_id, rte_strerror(rte_errno));
1371 : 0 : } else if (verbose_level > 0) {
1372 : 0 : rte_mempool_dump(stdout, rte_mp);
1373 : : }
1374 : : return rte_mp;
1375 : : }
1376 : :
1377 : : /*
1378 : : * Check given socket id is valid or not with NUMA mode,
1379 : : * if valid, return 0, else return -1
1380 : : */
1381 : : static int
1382 : 0 : check_socket_id(const unsigned int socket_id)
1383 : : {
1384 : : static int warning_once = 0;
1385 : :
1386 : 0 : if (new_socket_id(socket_id)) {
1387 : 0 : if (!warning_once && numa_support)
1388 : 0 : fprintf(stderr,
1389 : : "Warning: NUMA should be configured manually by using --port-numa-config and --ring-numa-config parameters along with --numa.\n");
1390 : 0 : warning_once = 1;
1391 : 0 : return -1;
1392 : : }
1393 : : return 0;
1394 : : }
1395 : :
1396 : : /*
1397 : : * Get the allowed maximum number of RX queues.
1398 : : * *pid return the port id which has minimal value of
1399 : : * max_rx_queues in all ports.
1400 : : */
1401 : : queueid_t
1402 : 0 : get_allowed_max_nb_rxq(portid_t *pid)
1403 : : {
1404 : : queueid_t allowed_max_rxq = RTE_MAX_QUEUES_PER_PORT;
1405 : : bool max_rxq_valid = false;
1406 : : portid_t pi;
1407 : : struct rte_eth_dev_info dev_info;
1408 : :
1409 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1410 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1411 : 0 : continue;
1412 : :
1413 : : max_rxq_valid = true;
1414 : 0 : if (dev_info.max_rx_queues < allowed_max_rxq) {
1415 : : allowed_max_rxq = dev_info.max_rx_queues;
1416 : 0 : *pid = pi;
1417 : : }
1418 : : }
1419 : 0 : return max_rxq_valid ? allowed_max_rxq : 0;
1420 : : }
1421 : :
1422 : : /*
1423 : : * Check input rxq is valid or not.
1424 : : * If input rxq is not greater than any of maximum number
1425 : : * of RX queues of all ports, it is valid.
1426 : : * if valid, return 0, else return -1
1427 : : */
1428 : : int
1429 : 0 : check_nb_rxq(queueid_t rxq)
1430 : : {
1431 : : queueid_t allowed_max_rxq;
1432 : 0 : portid_t pid = 0;
1433 : :
1434 : 0 : allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
1435 : 0 : if (rxq > allowed_max_rxq) {
1436 : 0 : fprintf(stderr,
1437 : : "Fail: input rxq (%u) can't be greater than max_rx_queues (%u) of port %u\n",
1438 : : rxq, allowed_max_rxq, pid);
1439 : 0 : return -1;
1440 : : }
1441 : : return 0;
1442 : : }
1443 : :
1444 : : /*
1445 : : * Get the allowed maximum number of TX queues.
1446 : : * *pid return the port id which has minimal value of
1447 : : * max_tx_queues in all ports.
1448 : : */
1449 : : queueid_t
1450 : 0 : get_allowed_max_nb_txq(portid_t *pid)
1451 : : {
1452 : : queueid_t allowed_max_txq = RTE_MAX_QUEUES_PER_PORT;
1453 : : bool max_txq_valid = false;
1454 : : portid_t pi;
1455 : : struct rte_eth_dev_info dev_info;
1456 : :
1457 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1458 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1459 : 0 : continue;
1460 : :
1461 : : max_txq_valid = true;
1462 : 0 : if (dev_info.max_tx_queues < allowed_max_txq) {
1463 : : allowed_max_txq = dev_info.max_tx_queues;
1464 : 0 : *pid = pi;
1465 : : }
1466 : : }
1467 : 0 : return max_txq_valid ? allowed_max_txq : 0;
1468 : : }
1469 : :
1470 : : /*
1471 : : * Check input txq is valid or not.
1472 : : * If input txq is not greater than any of maximum number
1473 : : * of TX queues of all ports, it is valid.
1474 : : * if valid, return 0, else return -1
1475 : : */
1476 : : int
1477 : 0 : check_nb_txq(queueid_t txq)
1478 : : {
1479 : : queueid_t allowed_max_txq;
1480 : 0 : portid_t pid = 0;
1481 : :
1482 : 0 : allowed_max_txq = get_allowed_max_nb_txq(&pid);
1483 : 0 : if (txq > allowed_max_txq) {
1484 : 0 : fprintf(stderr,
1485 : : "Fail: input txq (%u) can't be greater than max_tx_queues (%u) of port %u\n",
1486 : : txq, allowed_max_txq, pid);
1487 : 0 : return -1;
1488 : : }
1489 : : return 0;
1490 : : }
1491 : :
1492 : : /*
1493 : : * Get the allowed maximum number of RXDs of every rx queue.
1494 : : * *pid return the port id which has minimal value of
1495 : : * max_rxd in all queues of all ports.
1496 : : */
1497 : : static uint16_t
1498 : 0 : get_allowed_max_nb_rxd(portid_t *pid)
1499 : : {
1500 : : uint16_t allowed_max_rxd = UINT16_MAX;
1501 : : portid_t pi;
1502 : : struct rte_eth_dev_info dev_info;
1503 : :
1504 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1505 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1506 : 0 : continue;
1507 : :
1508 : 0 : if (dev_info.rx_desc_lim.nb_max < allowed_max_rxd) {
1509 : : allowed_max_rxd = dev_info.rx_desc_lim.nb_max;
1510 : 0 : *pid = pi;
1511 : : }
1512 : : }
1513 : 0 : return allowed_max_rxd;
1514 : : }
1515 : :
1516 : : /*
1517 : : * Get the allowed minimal number of RXDs of every rx queue.
1518 : : * *pid return the port id which has minimal value of
1519 : : * min_rxd in all queues of all ports.
1520 : : */
1521 : : static uint16_t
1522 : 0 : get_allowed_min_nb_rxd(portid_t *pid)
1523 : : {
1524 : : uint16_t allowed_min_rxd = 0;
1525 : : portid_t pi;
1526 : : struct rte_eth_dev_info dev_info;
1527 : :
1528 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1529 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1530 : 0 : continue;
1531 : :
1532 : 0 : if (dev_info.rx_desc_lim.nb_min > allowed_min_rxd) {
1533 : : allowed_min_rxd = dev_info.rx_desc_lim.nb_min;
1534 : 0 : *pid = pi;
1535 : : }
1536 : : }
1537 : :
1538 : 0 : return allowed_min_rxd;
1539 : : }
1540 : :
1541 : : /*
1542 : : * Check input rxd is valid or not.
1543 : : * If input rxd is not greater than any of maximum number
1544 : : * of RXDs of every Rx queues and is not less than any of
1545 : : * minimal number of RXDs of every Rx queues, it is valid.
1546 : : * if valid, return 0, else return -1
1547 : : */
1548 : : int
1549 : 0 : check_nb_rxd(queueid_t rxd)
1550 : : {
1551 : : uint16_t allowed_max_rxd;
1552 : : uint16_t allowed_min_rxd;
1553 : 0 : portid_t pid = 0;
1554 : :
1555 : 0 : allowed_max_rxd = get_allowed_max_nb_rxd(&pid);
1556 : 0 : if (rxd > allowed_max_rxd) {
1557 : 0 : fprintf(stderr,
1558 : : "Fail: input rxd (%u) can't be greater than max_rxds (%u) of port %u\n",
1559 : : rxd, allowed_max_rxd, pid);
1560 : 0 : return -1;
1561 : : }
1562 : :
1563 : 0 : allowed_min_rxd = get_allowed_min_nb_rxd(&pid);
1564 : 0 : if (rxd < allowed_min_rxd) {
1565 : 0 : fprintf(stderr,
1566 : : "Fail: input rxd (%u) can't be less than min_rxds (%u) of port %u\n",
1567 : : rxd, allowed_min_rxd, pid);
1568 : 0 : return -1;
1569 : : }
1570 : :
1571 : : return 0;
1572 : : }
1573 : :
1574 : : /*
1575 : : * Get the allowed maximum number of TXDs of every rx queues.
1576 : : * *pid return the port id which has minimal value of
1577 : : * max_txd in every tx queue.
1578 : : */
1579 : : static uint16_t
1580 : 0 : get_allowed_max_nb_txd(portid_t *pid)
1581 : : {
1582 : : uint16_t allowed_max_txd = UINT16_MAX;
1583 : : portid_t pi;
1584 : : struct rte_eth_dev_info dev_info;
1585 : :
1586 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1587 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1588 : 0 : continue;
1589 : :
1590 : 0 : if (dev_info.tx_desc_lim.nb_max < allowed_max_txd) {
1591 : : allowed_max_txd = dev_info.tx_desc_lim.nb_max;
1592 : 0 : *pid = pi;
1593 : : }
1594 : : }
1595 : 0 : return allowed_max_txd;
1596 : : }
1597 : :
1598 : : /*
1599 : : * Get the allowed maximum number of TXDs of every tx queues.
1600 : : * *pid return the port id which has minimal value of
1601 : : * min_txd in every tx queue.
1602 : : */
1603 : : static uint16_t
1604 : 0 : get_allowed_min_nb_txd(portid_t *pid)
1605 : : {
1606 : : uint16_t allowed_min_txd = 0;
1607 : : portid_t pi;
1608 : : struct rte_eth_dev_info dev_info;
1609 : :
1610 : 0 : RTE_ETH_FOREACH_DEV(pi) {
1611 : 0 : if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1612 : 0 : continue;
1613 : :
1614 : 0 : if (dev_info.tx_desc_lim.nb_min > allowed_min_txd) {
1615 : : allowed_min_txd = dev_info.tx_desc_lim.nb_min;
1616 : 0 : *pid = pi;
1617 : : }
1618 : : }
1619 : :
1620 : 0 : return allowed_min_txd;
1621 : : }
1622 : :
1623 : : /*
1624 : : * Check input txd is valid or not.
1625 : : * If input txd is not greater than any of maximum number
1626 : : * of TXDs of every Rx queues, it is valid.
1627 : : * if valid, return 0, else return -1
1628 : : */
1629 : : int
1630 : 0 : check_nb_txd(queueid_t txd)
1631 : : {
1632 : : uint16_t allowed_max_txd;
1633 : : uint16_t allowed_min_txd;
1634 : 0 : portid_t pid = 0;
1635 : :
1636 : 0 : allowed_max_txd = get_allowed_max_nb_txd(&pid);
1637 : 0 : if (txd > allowed_max_txd) {
1638 : 0 : fprintf(stderr,
1639 : : "Fail: input txd (%u) can't be greater than max_txds (%u) of port %u\n",
1640 : : txd, allowed_max_txd, pid);
1641 : 0 : return -1;
1642 : : }
1643 : :
1644 : 0 : allowed_min_txd = get_allowed_min_nb_txd(&pid);
1645 : 0 : if (txd < allowed_min_txd) {
1646 : 0 : fprintf(stderr,
1647 : : "Fail: input txd (%u) can't be less than min_txds (%u) of port %u\n",
1648 : : txd, allowed_min_txd, pid);
1649 : 0 : return -1;
1650 : : }
1651 : : return 0;
1652 : : }
1653 : :
1654 : : static int
1655 : : get_eth_overhead(struct rte_eth_dev_info *dev_info)
1656 : : {
1657 : : uint32_t eth_overhead;
1658 : :
1659 : 0 : if (dev_info->max_mtu != UINT16_MAX &&
1660 : 0 : dev_info->max_rx_pktlen > dev_info->max_mtu)
1661 : 0 : eth_overhead = dev_info->max_rx_pktlen - dev_info->max_mtu;
1662 : : else
1663 : : eth_overhead = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1664 : :
1665 : : return eth_overhead;
1666 : : }
1667 : :
1668 : : static void
1669 : 0 : init_config_port_offloads(portid_t pid, uint32_t socket_id)
1670 : : {
1671 : 0 : struct rte_port *port = &ports[pid];
1672 : : int ret;
1673 : : int i;
1674 : :
1675 : 0 : eth_rx_metadata_negotiate_mp(pid);
1676 : :
1677 : 0 : port->dev_conf.txmode = tx_mode;
1678 : 0 : port->dev_conf.rxmode = rx_mode;
1679 : :
1680 : 0 : ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1681 : 0 : if (ret != 0)
1682 : 0 : rte_exit(EXIT_FAILURE, "rte_eth_dev_info_get() failed\n");
1683 : :
1684 : 0 : if (!(port->dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE))
1685 : 0 : port->dev_conf.txmode.offloads &=
1686 : : ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1687 : :
1688 : : /* Apply Rx offloads configuration */
1689 : 0 : for (i = 0; i < port->dev_info.max_rx_queues; i++)
1690 : 0 : port->rxq[i].conf.offloads = port->dev_conf.rxmode.offloads;
1691 : : /* Apply Tx offloads configuration */
1692 : 0 : for (i = 0; i < port->dev_info.max_tx_queues; i++)
1693 : 0 : port->txq[i].conf.offloads = port->dev_conf.txmode.offloads;
1694 : :
1695 : 0 : if (eth_link_speed)
1696 : 0 : port->dev_conf.link_speeds = eth_link_speed;
1697 : :
1698 : 0 : if (max_rx_pkt_len)
1699 : 0 : port->dev_conf.rxmode.mtu = max_rx_pkt_len -
1700 : : get_eth_overhead(&port->dev_info);
1701 : :
1702 : : /* set flag to initialize port/queue */
1703 : 0 : port->need_reconfig = 1;
1704 : 0 : port->need_reconfig_queues = 1;
1705 : 0 : port->socket_id = socket_id;
1706 : 0 : port->tx_metadata = 0;
1707 : :
1708 : : /*
1709 : : * Check for maximum number of segments per MTU.
1710 : : * Accordingly update the mbuf data size.
1711 : : */
1712 : 0 : if (port->dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
1713 : : port->dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
1714 : : uint32_t eth_overhead = get_eth_overhead(&port->dev_info);
1715 : : uint16_t mtu;
1716 : :
1717 : 0 : if (rte_eth_dev_get_mtu(pid, &mtu) == 0) {
1718 : 0 : uint16_t data_size = (mtu + eth_overhead) /
1719 : 0 : port->dev_info.rx_desc_lim.nb_mtu_seg_max;
1720 : 0 : uint16_t buffer_size = data_size + RTE_PKTMBUF_HEADROOM;
1721 : :
1722 : 0 : if (buffer_size > mbuf_data_size[0]) {
1723 : 0 : mbuf_data_size[0] = buffer_size;
1724 : 0 : TESTPMD_LOG(WARNING,
1725 : : "Configured mbuf size of the first segment %hu\n",
1726 : : mbuf_data_size[0]);
1727 : : }
1728 : : }
1729 : : }
1730 : 0 : }
1731 : :
1732 : : static void
1733 : 0 : init_config(void)
1734 : : {
1735 : : portid_t pid;
1736 : : struct rte_mempool *mbp;
1737 : : unsigned int nb_mbuf_per_pool;
1738 : : lcoreid_t lc_id;
1739 : : #ifdef RTE_LIB_GRO
1740 : : struct rte_gro_param gro_param;
1741 : : #endif
1742 : : #ifdef RTE_LIB_GSO
1743 : : uint32_t gso_types;
1744 : : #endif
1745 : :
1746 : : /* Configuration of logical cores. */
1747 : 0 : fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
1748 : : sizeof(struct fwd_lcore *) * nb_lcores,
1749 : : RTE_CACHE_LINE_SIZE);
1750 : 0 : if (fwd_lcores == NULL) {
1751 : 0 : rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
1752 : : "failed\n", nb_lcores);
1753 : : }
1754 : 0 : for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1755 : 0 : fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
1756 : : sizeof(struct fwd_lcore),
1757 : : RTE_CACHE_LINE_SIZE);
1758 : 0 : if (fwd_lcores[lc_id] == NULL) {
1759 : 0 : rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
1760 : : "failed\n");
1761 : : }
1762 : 0 : fwd_lcores[lc_id]->cpuid_idx = lc_id;
1763 : : }
1764 : :
1765 : 0 : RTE_ETH_FOREACH_DEV(pid) {
1766 : : uint32_t socket_id;
1767 : :
1768 : 0 : if (numa_support) {
1769 : 0 : socket_id = port_numa[pid];
1770 : 0 : if (port_numa[pid] == NUMA_NO_CONFIG) {
1771 : 0 : socket_id = rte_eth_dev_socket_id(pid);
1772 : :
1773 : : /*
1774 : : * if socket_id is invalid,
1775 : : * set to the first available socket.
1776 : : */
1777 : 0 : if (check_socket_id(socket_id) < 0)
1778 : 0 : socket_id = socket_ids[0];
1779 : : }
1780 : : } else {
1781 : 0 : socket_id = (socket_num == UMA_NO_CONFIG) ?
1782 : 0 : 0 : socket_num;
1783 : : }
1784 : : /* Apply default TxRx configuration for all ports */
1785 : 0 : init_config_port_offloads(pid, socket_id);
1786 : : }
1787 : : /*
1788 : : * Create pools of mbuf.
1789 : : * If NUMA support is disabled, create a single pool of mbuf in
1790 : : * socket 0 memory by default.
1791 : : * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
1792 : : *
1793 : : * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
1794 : : * nb_txd can be configured at run time.
1795 : : */
1796 : 0 : if (param_total_num_mbufs)
1797 : : nb_mbuf_per_pool = param_total_num_mbufs;
1798 : : else {
1799 : 0 : nb_mbuf_per_pool = RX_DESC_MAX +
1800 : 0 : (nb_lcores * mb_mempool_cache) +
1801 : : TX_DESC_MAX + MAX_PKT_BURST;
1802 : 0 : nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
1803 : : }
1804 : :
1805 : 0 : if (numa_support) {
1806 : : uint8_t i, j;
1807 : :
1808 : 0 : for (i = 0; i < num_sockets; i++)
1809 : 0 : for (j = 0; j < mbuf_data_size_n; j++)
1810 : 0 : mempools[i * MAX_SEGS_BUFFER_SPLIT + j] =
1811 : 0 : mbuf_pool_create(mbuf_data_size[j],
1812 : : nb_mbuf_per_pool,
1813 : : socket_ids[i], j);
1814 : : } else {
1815 : : uint8_t i;
1816 : :
1817 : 0 : for (i = 0; i < mbuf_data_size_n; i++)
1818 : 0 : mempools[i] = mbuf_pool_create
1819 : 0 : (mbuf_data_size[i],
1820 : : nb_mbuf_per_pool,
1821 : : SOCKET_ID_ANY, i);
1822 : : }
1823 : :
1824 : 0 : init_port_config();
1825 : :
1826 : : #ifdef RTE_LIB_GSO
1827 : : gso_types = RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
1828 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | RTE_ETH_TX_OFFLOAD_UDP_TSO;
1829 : : #endif
1830 : : /*
1831 : : * Records which Mbuf pool to use by each logical core, if needed.
1832 : : */
1833 : 0 : for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1834 : 0 : mbp = mbuf_pool_find(
1835 : : rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]), 0);
1836 : :
1837 : 0 : if (mbp == NULL)
1838 : : mbp = mbuf_pool_find(0, 0);
1839 : 0 : fwd_lcores[lc_id]->mbp = mbp;
1840 : : #ifdef RTE_LIB_GSO
1841 : : /* initialize GSO context */
1842 : 0 : fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
1843 : 0 : fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
1844 : 0 : fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
1845 : 0 : fwd_lcores[lc_id]->gso_ctx.gso_size = RTE_ETHER_MAX_LEN -
1846 : : RTE_ETHER_CRC_LEN;
1847 : 0 : fwd_lcores[lc_id]->gso_ctx.flag = 0;
1848 : : #endif
1849 : : }
1850 : :
1851 : 0 : fwd_config_setup();
1852 : :
1853 : : #ifdef RTE_LIB_GRO
1854 : : /* create a gro context for each lcore */
1855 : 0 : gro_param.gro_types = RTE_GRO_TCP_IPV4;
1856 : 0 : gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
1857 : 0 : gro_param.max_item_per_flow = MAX_PKT_BURST;
1858 : 0 : for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1859 : 0 : gro_param.socket_id = rte_lcore_to_socket_id(
1860 : : fwd_lcores_cpuids[lc_id]);
1861 : 0 : fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
1862 : 0 : if (fwd_lcores[lc_id]->gro_ctx == NULL) {
1863 : 0 : rte_exit(EXIT_FAILURE,
1864 : : "rte_gro_ctx_create() failed\n");
1865 : : }
1866 : : }
1867 : : #endif
1868 : 0 : }
1869 : :
1870 : :
1871 : : void
1872 : 0 : reconfig(portid_t new_port_id, unsigned socket_id)
1873 : : {
1874 : : /* Reconfiguration of Ethernet ports. */
1875 : 0 : init_config_port_offloads(new_port_id, socket_id);
1876 : 0 : init_port_config();
1877 : 0 : }
1878 : :
1879 : : int
1880 : 0 : init_fwd_streams(void)
1881 : : {
1882 : : portid_t pid;
1883 : : struct rte_port *port;
1884 : : streamid_t sm_id, nb_fwd_streams_new;
1885 : : queueid_t q;
1886 : :
1887 : : /* set socket id according to numa or not */
1888 : 0 : RTE_ETH_FOREACH_DEV(pid) {
1889 : 0 : port = &ports[pid];
1890 : 0 : if (nb_rxq > port->dev_info.max_rx_queues) {
1891 : 0 : fprintf(stderr,
1892 : : "Fail: nb_rxq(%d) is greater than max_rx_queues(%d)\n",
1893 : : nb_rxq, port->dev_info.max_rx_queues);
1894 : 0 : return -1;
1895 : : }
1896 : 0 : if (nb_txq > port->dev_info.max_tx_queues) {
1897 : 0 : fprintf(stderr,
1898 : : "Fail: nb_txq(%d) is greater than max_tx_queues(%d)\n",
1899 : : nb_txq, port->dev_info.max_tx_queues);
1900 : 0 : return -1;
1901 : : }
1902 : 0 : if (numa_support) {
1903 : 0 : if (port_numa[pid] != NUMA_NO_CONFIG)
1904 : 0 : port->socket_id = port_numa[pid];
1905 : : else {
1906 : 0 : port->socket_id = rte_eth_dev_socket_id(pid);
1907 : :
1908 : : /*
1909 : : * if socket_id is invalid,
1910 : : * set to the first available socket.
1911 : : */
1912 : 0 : if (check_socket_id(port->socket_id) < 0)
1913 : 0 : port->socket_id = socket_ids[0];
1914 : : }
1915 : : }
1916 : : else {
1917 : 0 : if (socket_num == UMA_NO_CONFIG)
1918 : 0 : port->socket_id = 0;
1919 : : else
1920 : 0 : port->socket_id = socket_num;
1921 : : }
1922 : : }
1923 : :
1924 : 0 : q = RTE_MAX(nb_rxq, nb_txq);
1925 : 0 : if (q == 0) {
1926 : 0 : fprintf(stderr,
1927 : : "Fail: Cannot allocate fwd streams as number of queues is 0\n");
1928 : 0 : return -1;
1929 : : }
1930 : 0 : nb_fwd_streams_new = (streamid_t)(nb_ports * q);
1931 : 0 : if (nb_fwd_streams_new == nb_fwd_streams)
1932 : : return 0;
1933 : : /* clear the old */
1934 : 0 : if (fwd_streams != NULL) {
1935 : 0 : for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
1936 : 0 : if (fwd_streams[sm_id] == NULL)
1937 : 0 : continue;
1938 : 0 : rte_free(fwd_streams[sm_id]);
1939 : 0 : fwd_streams[sm_id] = NULL;
1940 : : }
1941 : 0 : rte_free(fwd_streams);
1942 : 0 : fwd_streams = NULL;
1943 : : }
1944 : :
1945 : : /* init new */
1946 : 0 : nb_fwd_streams = nb_fwd_streams_new;
1947 : 0 : if (nb_fwd_streams) {
1948 : 0 : fwd_streams = rte_zmalloc("testpmd: fwd_streams",
1949 : : sizeof(struct fwd_stream *) * nb_fwd_streams,
1950 : : RTE_CACHE_LINE_SIZE);
1951 : 0 : if (fwd_streams == NULL)
1952 : 0 : rte_exit(EXIT_FAILURE, "rte_zmalloc(%d"
1953 : : " (struct fwd_stream *)) failed\n",
1954 : : nb_fwd_streams);
1955 : :
1956 : 0 : for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
1957 : 0 : fwd_streams[sm_id] = rte_zmalloc("testpmd:"
1958 : : " struct fwd_stream", sizeof(struct fwd_stream),
1959 : : RTE_CACHE_LINE_SIZE);
1960 : 0 : if (fwd_streams[sm_id] == NULL)
1961 : 0 : rte_exit(EXIT_FAILURE, "rte_zmalloc"
1962 : : "(struct fwd_stream) failed\n");
1963 : : }
1964 : : }
1965 : :
1966 : : return 0;
1967 : : }
1968 : :
1969 : : static void
1970 : 0 : pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
1971 : : {
1972 : : uint64_t total_burst, sburst;
1973 : : uint64_t nb_burst;
1974 : : uint64_t burst_stats[4];
1975 : : uint16_t pktnb_stats[4];
1976 : : uint16_t nb_pkt;
1977 : : int burst_percent[4], sburstp;
1978 : : int i;
1979 : :
1980 : : /*
1981 : : * First compute the total number of packet bursts and the
1982 : : * two highest numbers of bursts of the same number of packets.
1983 : : */
1984 : : memset(&burst_stats, 0x0, sizeof(burst_stats));
1985 : : memset(&pktnb_stats, 0x0, sizeof(pktnb_stats));
1986 : :
1987 : : /* Show stats for 0 burst size always */
1988 : 0 : total_burst = pbs->pkt_burst_spread[0];
1989 : 0 : burst_stats[0] = pbs->pkt_burst_spread[0];
1990 : : pktnb_stats[0] = 0;
1991 : :
1992 : : /* Find the next 2 burst sizes with highest occurrences. */
1993 : 0 : for (nb_pkt = 1; nb_pkt < MAX_PKT_BURST + 1; nb_pkt++) {
1994 : 0 : nb_burst = pbs->pkt_burst_spread[nb_pkt];
1995 : :
1996 : 0 : if (nb_burst == 0)
1997 : 0 : continue;
1998 : :
1999 : 0 : total_burst += nb_burst;
2000 : :
2001 : 0 : if (nb_burst > burst_stats[1]) {
2002 : 0 : burst_stats[2] = burst_stats[1];
2003 : 0 : pktnb_stats[2] = pktnb_stats[1];
2004 : 0 : burst_stats[1] = nb_burst;
2005 : 0 : pktnb_stats[1] = nb_pkt;
2006 : 0 : } else if (nb_burst > burst_stats[2]) {
2007 : 0 : burst_stats[2] = nb_burst;
2008 : 0 : pktnb_stats[2] = nb_pkt;
2009 : : }
2010 : : }
2011 : 0 : if (total_burst == 0)
2012 : 0 : return;
2013 : :
2014 : : printf(" %s-bursts : %"PRIu64" [", rx_tx, total_burst);
2015 : 0 : for (i = 0, sburst = 0, sburstp = 0; i < 4; i++) {
2016 : 0 : if (i == 3) {
2017 : 0 : printf("%d%% of other]\n", 100 - sburstp);
2018 : 0 : return;
2019 : : }
2020 : :
2021 : 0 : sburst += burst_stats[i];
2022 : 0 : if (sburst == total_burst) {
2023 : 0 : printf("%d%% of %d pkts]\n",
2024 : 0 : 100 - sburstp, (int) pktnb_stats[i]);
2025 : 0 : return;
2026 : : }
2027 : :
2028 : 0 : burst_percent[i] =
2029 : 0 : (double)burst_stats[i] / total_burst * 100;
2030 : 0 : printf("%d%% of %d pkts + ",
2031 : 0 : burst_percent[i], (int) pktnb_stats[i]);
2032 : 0 : sburstp += burst_percent[i];
2033 : : }
2034 : : }
2035 : :
2036 : : static void
2037 : 0 : fwd_stream_stats_display(streamid_t stream_id)
2038 : : {
2039 : : struct fwd_stream *fs;
2040 : : static const char *fwd_top_stats_border = "-------";
2041 : :
2042 : 0 : fs = fwd_streams[stream_id];
2043 : 0 : if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
2044 : 0 : (fs->fwd_dropped == 0))
2045 : : return;
2046 : 0 : printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
2047 : : "TX Port=%2d/Queue=%2d %s\n",
2048 : 0 : fwd_top_stats_border, fs->rx_port, fs->rx_queue,
2049 : 0 : fs->tx_port, fs->tx_queue, fwd_top_stats_border);
2050 : 0 : printf(" RX-packets: %-14"PRIu64" TX-packets: %-14"PRIu64
2051 : : " TX-dropped: %-14"PRIu64,
2052 : : fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
2053 : :
2054 : : /* if checksum mode */
2055 : 0 : if (cur_fwd_eng == &csum_fwd_engine) {
2056 : 0 : printf(" RX- bad IP checksum: %-14"PRIu64
2057 : : " Rx- bad L4 checksum: %-14"PRIu64
2058 : : " Rx- bad outer L4 checksum: %-14"PRIu64"\n",
2059 : : fs->rx_bad_ip_csum, fs->rx_bad_l4_csum,
2060 : : fs->rx_bad_outer_l4_csum);
2061 : 0 : printf(" RX- bad outer IP checksum: %-14"PRIu64"\n",
2062 : : fs->rx_bad_outer_ip_csum);
2063 : : } else {
2064 : : printf("\n");
2065 : : }
2066 : :
2067 : 0 : if (record_burst_stats) {
2068 : 0 : pkt_burst_stats_display("RX", &fs->rx_burst_stats);
2069 : 0 : pkt_burst_stats_display("TX", &fs->tx_burst_stats);
2070 : : }
2071 : : }
2072 : :
2073 : : void
2074 : 0 : fwd_stats_display(void)
2075 : : {
2076 : : static const char *fwd_stats_border = "----------------------";
2077 : : static const char *acc_stats_border = "+++++++++++++++";
2078 : : struct {
2079 : : struct fwd_stream *rx_stream;
2080 : : struct fwd_stream *tx_stream;
2081 : : uint64_t tx_dropped;
2082 : : uint64_t rx_bad_ip_csum;
2083 : : uint64_t rx_bad_l4_csum;
2084 : : uint64_t rx_bad_outer_l4_csum;
2085 : : uint64_t rx_bad_outer_ip_csum;
2086 : : } ports_stats[RTE_MAX_ETHPORTS];
2087 : : uint64_t total_rx_dropped = 0;
2088 : : uint64_t total_tx_dropped = 0;
2089 : : uint64_t total_rx_nombuf = 0;
2090 : : struct rte_eth_stats stats;
2091 : : uint64_t fwd_cycles = 0;
2092 : : uint64_t total_recv = 0;
2093 : : uint64_t total_xmit = 0;
2094 : : struct rte_port *port;
2095 : : streamid_t sm_id;
2096 : : portid_t pt_id;
2097 : : int ret;
2098 : : int i;
2099 : :
2100 : : memset(ports_stats, 0, sizeof(ports_stats));
2101 : :
2102 : 0 : for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2103 : 0 : struct fwd_stream *fs = fwd_streams[sm_id];
2104 : :
2105 : 0 : if (cur_fwd_config.nb_fwd_streams >
2106 : 0 : cur_fwd_config.nb_fwd_ports) {
2107 : 0 : fwd_stream_stats_display(sm_id);
2108 : : } else {
2109 : 0 : ports_stats[fs->tx_port].tx_stream = fs;
2110 : 0 : ports_stats[fs->rx_port].rx_stream = fs;
2111 : : }
2112 : :
2113 : 0 : ports_stats[fs->tx_port].tx_dropped += fs->fwd_dropped;
2114 : :
2115 : 0 : ports_stats[fs->rx_port].rx_bad_ip_csum += fs->rx_bad_ip_csum;
2116 : 0 : ports_stats[fs->rx_port].rx_bad_l4_csum += fs->rx_bad_l4_csum;
2117 : 0 : ports_stats[fs->rx_port].rx_bad_outer_l4_csum +=
2118 : 0 : fs->rx_bad_outer_l4_csum;
2119 : 0 : ports_stats[fs->rx_port].rx_bad_outer_ip_csum +=
2120 : 0 : fs->rx_bad_outer_ip_csum;
2121 : :
2122 : 0 : if (record_core_cycles)
2123 : 0 : fwd_cycles += fs->busy_cycles;
2124 : : }
2125 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2126 : : uint64_t tx_dropped = 0;
2127 : :
2128 : 0 : pt_id = fwd_ports_ids[i];
2129 : 0 : port = &ports[pt_id];
2130 : :
2131 : 0 : ret = rte_eth_stats_get(pt_id, &stats);
2132 : 0 : if (ret != 0) {
2133 : 0 : fprintf(stderr,
2134 : : "%s: Error: failed to get stats (port %u): %d",
2135 : : __func__, pt_id, ret);
2136 : 0 : continue;
2137 : : }
2138 : 0 : stats.ipackets -= port->stats.ipackets;
2139 : 0 : stats.opackets -= port->stats.opackets;
2140 : 0 : stats.ibytes -= port->stats.ibytes;
2141 : 0 : stats.obytes -= port->stats.obytes;
2142 : 0 : stats.imissed -= port->stats.imissed;
2143 : 0 : stats.oerrors -= port->stats.oerrors;
2144 : 0 : stats.rx_nombuf -= port->stats.rx_nombuf;
2145 : :
2146 : 0 : total_recv += stats.ipackets;
2147 : 0 : total_xmit += stats.opackets;
2148 : 0 : total_rx_dropped += stats.imissed;
2149 : 0 : tx_dropped += ports_stats[pt_id].tx_dropped;
2150 : 0 : tx_dropped += stats.oerrors;
2151 : 0 : total_tx_dropped += tx_dropped;
2152 : 0 : total_rx_nombuf += stats.rx_nombuf;
2153 : :
2154 : 0 : printf("\n %s Forward statistics for port %-2d %s\n",
2155 : : fwd_stats_border, pt_id, fwd_stats_border);
2156 : :
2157 : 0 : printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64
2158 : : "RX-total: %-"PRIu64"\n", stats.ipackets, stats.imissed,
2159 : 0 : stats.ipackets + stats.imissed);
2160 : :
2161 : 0 : if (cur_fwd_eng == &csum_fwd_engine) {
2162 : 0 : printf(" Bad-ipcsum: %-14"PRIu64
2163 : : " Bad-l4csum: %-14"PRIu64
2164 : : "Bad-outer-l4csum: %-14"PRIu64"\n",
2165 : : ports_stats[pt_id].rx_bad_ip_csum,
2166 : : ports_stats[pt_id].rx_bad_l4_csum,
2167 : : ports_stats[pt_id].rx_bad_outer_l4_csum);
2168 : 0 : printf(" Bad-outer-ipcsum: %-14"PRIu64"\n",
2169 : : ports_stats[pt_id].rx_bad_outer_ip_csum);
2170 : : }
2171 : 0 : if (stats.ierrors + stats.rx_nombuf > 0) {
2172 : : printf(" RX-error: %-"PRIu64"\n", stats.ierrors);
2173 : 0 : printf(" RX-nombufs: %-14"PRIu64"\n", stats.rx_nombuf);
2174 : : }
2175 : :
2176 : 0 : printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64
2177 : : "TX-total: %-"PRIu64"\n",
2178 : : stats.opackets, tx_dropped,
2179 : 0 : stats.opackets + tx_dropped);
2180 : :
2181 : 0 : if (record_burst_stats) {
2182 : 0 : if (ports_stats[pt_id].rx_stream)
2183 : 0 : pkt_burst_stats_display("RX",
2184 : : &ports_stats[pt_id].rx_stream->rx_burst_stats);
2185 : 0 : if (ports_stats[pt_id].tx_stream)
2186 : 0 : pkt_burst_stats_display("TX",
2187 : : &ports_stats[pt_id].tx_stream->tx_burst_stats);
2188 : : }
2189 : :
2190 : 0 : printf(" %s--------------------------------%s\n",
2191 : : fwd_stats_border, fwd_stats_border);
2192 : : }
2193 : :
2194 : 0 : printf("\n %s Accumulated forward statistics for all ports"
2195 : : "%s\n",
2196 : : acc_stats_border, acc_stats_border);
2197 : 0 : printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
2198 : : "%-"PRIu64"\n"
2199 : : " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
2200 : : "%-"PRIu64"\n",
2201 : : total_recv, total_rx_dropped, total_recv + total_rx_dropped,
2202 : : total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
2203 : 0 : if (total_rx_nombuf > 0)
2204 : : printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
2205 : 0 : printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
2206 : : "%s\n",
2207 : : acc_stats_border, acc_stats_border);
2208 : 0 : if (record_core_cycles) {
2209 : : #define CYC_PER_MHZ 1E6
2210 : 0 : if (total_recv > 0 || total_xmit > 0) {
2211 : : uint64_t total_pkts = 0;
2212 : 0 : if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 ||
2213 : 0 : strcmp(cur_fwd_eng->fwd_mode_name, "flowgen") == 0)
2214 : : total_pkts = total_xmit;
2215 : : else
2216 : : total_pkts = total_recv;
2217 : :
2218 : 0 : printf("\n CPU cycles/packet=%.2F (busy cycles="
2219 : : "%"PRIu64" / total %s packets=%"PRIu64") at %"PRIu64
2220 : : " MHz Clock\n",
2221 : 0 : (double) fwd_cycles / total_pkts,
2222 : 0 : fwd_cycles, cur_fwd_eng->fwd_mode_name, total_pkts,
2223 : 0 : (uint64_t)(rte_get_tsc_hz() / CYC_PER_MHZ));
2224 : : }
2225 : : }
2226 : 0 : }
2227 : :
2228 : : void
2229 : 0 : fwd_stats_reset(void)
2230 : : {
2231 : : streamid_t sm_id;
2232 : : portid_t pt_id;
2233 : : int ret;
2234 : : int i;
2235 : :
2236 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2237 : 0 : pt_id = fwd_ports_ids[i];
2238 : 0 : ret = rte_eth_stats_get(pt_id, &ports[pt_id].stats);
2239 : 0 : if (ret != 0)
2240 : 0 : fprintf(stderr,
2241 : : "%s: Error: failed to clear stats (port %u):%d",
2242 : : __func__, pt_id, ret);
2243 : : }
2244 : 0 : for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
2245 : 0 : struct fwd_stream *fs = fwd_streams[sm_id];
2246 : :
2247 : 0 : fs->rx_packets = 0;
2248 : 0 : fs->tx_packets = 0;
2249 : 0 : fs->fwd_dropped = 0;
2250 : 0 : fs->rx_bad_ip_csum = 0;
2251 : 0 : fs->rx_bad_l4_csum = 0;
2252 : 0 : fs->rx_bad_outer_l4_csum = 0;
2253 : 0 : fs->rx_bad_outer_ip_csum = 0;
2254 : :
2255 : 0 : memset(&fs->rx_burst_stats, 0, sizeof(fs->rx_burst_stats));
2256 : 0 : memset(&fs->tx_burst_stats, 0, sizeof(fs->tx_burst_stats));
2257 : 0 : fs->busy_cycles = 0;
2258 : : }
2259 : 0 : }
2260 : :
2261 : : static void
2262 : 0 : flush_fwd_rx_queues(void)
2263 : : {
2264 : : struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
2265 : : portid_t rxp;
2266 : : portid_t port_id;
2267 : : queueid_t rxq;
2268 : : uint16_t nb_rx;
2269 : : uint8_t j;
2270 : : uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
2271 : : uint64_t timer_period;
2272 : :
2273 : 0 : if (num_procs > 1) {
2274 : : printf("multi-process not support for flushing fwd Rx queues, skip the below lines and return.\n");
2275 : 0 : return;
2276 : : }
2277 : :
2278 : : /* convert to number of cycles */
2279 : : timer_period = rte_get_timer_hz(); /* 1 second timeout */
2280 : :
2281 : 0 : for (j = 0; j < 2; j++) {
2282 : 0 : for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
2283 : 0 : for (rxq = 0; rxq < nb_rxq; rxq++) {
2284 : 0 : port_id = fwd_ports_ids[rxp];
2285 : :
2286 : : /* Polling stopped queues is prohibited. */
2287 : 0 : if (ports[port_id].rxq[rxq].state ==
2288 : : RTE_ETH_QUEUE_STATE_STOPPED)
2289 : 0 : continue;
2290 : :
2291 : : /**
2292 : : * testpmd can stuck in the below do while loop
2293 : : * if rte_eth_rx_burst() always returns nonzero
2294 : : * packets. So timer is added to exit this loop
2295 : : * after 1sec timer expiry.
2296 : : */
2297 : : prev_tsc = rte_rdtsc();
2298 : : do {
2299 : 0 : nb_rx = rte_eth_rx_burst(port_id, rxq,
2300 : : pkts_burst, MAX_PKT_BURST);
2301 : 0 : rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
2302 : :
2303 : : cur_tsc = rte_rdtsc();
2304 : 0 : diff_tsc = cur_tsc - prev_tsc;
2305 : 0 : timer_tsc += diff_tsc;
2306 : 0 : } while ((nb_rx > 0) &&
2307 : 0 : (timer_tsc < timer_period));
2308 : : timer_tsc = 0;
2309 : : }
2310 : : }
2311 : : rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
2312 : : }
2313 : : }
2314 : :
2315 : : static void
2316 : 0 : run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
2317 : : {
2318 : : struct fwd_stream **fsm;
2319 : : uint64_t prev_tsc;
2320 : : streamid_t nb_fs;
2321 : : streamid_t sm_id;
2322 : : #ifdef RTE_LIB_BITRATESTATS
2323 : : uint64_t tics_per_1sec;
2324 : : uint64_t tics_datum;
2325 : : uint64_t tics_current;
2326 : : uint16_t i, cnt_ports;
2327 : :
2328 : 0 : cnt_ports = nb_ports;
2329 : : tics_datum = rte_rdtsc();
2330 : : tics_per_1sec = rte_get_timer_hz();
2331 : : #endif
2332 : 0 : fsm = &fwd_streams[fc->stream_idx];
2333 : 0 : nb_fs = fc->stream_nb;
2334 : : prev_tsc = rte_rdtsc();
2335 : : do {
2336 : 0 : for (sm_id = 0; sm_id < nb_fs; sm_id++) {
2337 : 0 : struct fwd_stream *fs = fsm[sm_id];
2338 : : uint64_t start_fs_tsc = 0;
2339 : : bool busy;
2340 : :
2341 : 0 : if (fs->disabled)
2342 : 0 : continue;
2343 : 0 : if (record_core_cycles)
2344 : : start_fs_tsc = rte_rdtsc();
2345 : 0 : busy = (*pkt_fwd)(fs);
2346 : 0 : if (record_core_cycles && busy)
2347 : 0 : fs->busy_cycles += rte_rdtsc() - start_fs_tsc;
2348 : : }
2349 : : #ifdef RTE_LIB_BITRATESTATS
2350 : 0 : if (bitrate_enabled != 0 &&
2351 : 0 : bitrate_lcore_id == rte_lcore_id()) {
2352 : : tics_current = rte_rdtsc();
2353 : 0 : if (tics_current - tics_datum >= tics_per_1sec) {
2354 : : /* Periodic bitrate calculation */
2355 : 0 : for (i = 0; i < cnt_ports; i++)
2356 : 0 : rte_stats_bitrate_calc(bitrate_data,
2357 : 0 : ports_ids[i]);
2358 : : tics_datum = tics_current;
2359 : : }
2360 : : }
2361 : : #endif
2362 : : #ifdef RTE_LIB_LATENCYSTATS
2363 : 0 : if (latencystats_enabled != 0 &&
2364 : 0 : latencystats_lcore_id == rte_lcore_id())
2365 : 0 : rte_latencystats_update();
2366 : : #endif
2367 : 0 : if (record_core_cycles) {
2368 : : uint64_t tsc = rte_rdtsc();
2369 : :
2370 : 0 : fc->total_cycles += tsc - prev_tsc;
2371 : : prev_tsc = tsc;
2372 : : }
2373 : 0 : } while (! fc->stopped);
2374 : 0 : }
2375 : :
2376 : : static int
2377 : 0 : lcore_usage_callback(unsigned int lcore_id, struct rte_lcore_usage *usage)
2378 : : {
2379 : : struct fwd_stream **fsm;
2380 : : struct fwd_lcore *fc;
2381 : : streamid_t nb_fs;
2382 : : streamid_t sm_id;
2383 : :
2384 : : fc = lcore_to_fwd_lcore(lcore_id);
2385 : 0 : if (fc == NULL)
2386 : : return -1;
2387 : :
2388 : 0 : fsm = &fwd_streams[fc->stream_idx];
2389 : 0 : nb_fs = fc->stream_nb;
2390 : 0 : usage->busy_cycles = 0;
2391 : 0 : usage->total_cycles = fc->total_cycles;
2392 : :
2393 : 0 : for (sm_id = 0; sm_id < nb_fs; sm_id++) {
2394 : 0 : if (!fsm[sm_id]->disabled)
2395 : 0 : usage->busy_cycles += fsm[sm_id]->busy_cycles;
2396 : : }
2397 : :
2398 : : return 0;
2399 : : }
2400 : :
2401 : : static int
2402 : 0 : start_pkt_forward_on_core(void *fwd_arg)
2403 : : {
2404 : 0 : run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
2405 : 0 : cur_fwd_config.fwd_eng->packet_fwd);
2406 : 0 : return 0;
2407 : : }
2408 : :
2409 : : /*
2410 : : * Run the TXONLY packet forwarding engine to send a single burst of packets.
2411 : : * Used to start communication flows in network loopback test configurations.
2412 : : */
2413 : : static int
2414 : 0 : run_one_txonly_burst_on_core(void *fwd_arg)
2415 : : {
2416 : : struct fwd_lcore *fwd_lc;
2417 : : struct fwd_lcore tmp_lcore;
2418 : :
2419 : : fwd_lc = (struct fwd_lcore *) fwd_arg;
2420 : 0 : tmp_lcore = *fwd_lc;
2421 : 0 : tmp_lcore.stopped = 1;
2422 : 0 : run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
2423 : 0 : return 0;
2424 : : }
2425 : :
2426 : : /*
2427 : : * Launch packet forwarding:
2428 : : * - Setup per-port forwarding context.
2429 : : * - launch logical cores with their forwarding configuration.
2430 : : */
2431 : : static void
2432 : 0 : launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
2433 : : {
2434 : : unsigned int i;
2435 : : unsigned int lc_id;
2436 : : int diag;
2437 : :
2438 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
2439 : 0 : lc_id = fwd_lcores_cpuids[i];
2440 : 0 : if ((interactive == 0) || (lc_id != rte_lcore_id())) {
2441 : 0 : fwd_lcores[i]->stopped = 0;
2442 : 0 : diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
2443 : : fwd_lcores[i], lc_id);
2444 : 0 : if (diag != 0)
2445 : 0 : fprintf(stderr,
2446 : : "launch lcore %u failed - diag=%d\n",
2447 : : lc_id, diag);
2448 : : }
2449 : : }
2450 : 0 : }
2451 : :
2452 : : void
2453 : 0 : common_fwd_stream_init(struct fwd_stream *fs)
2454 : : {
2455 : : bool rx_stopped, tx_stopped;
2456 : :
2457 : 0 : rx_stopped = (ports[fs->rx_port].rxq[fs->rx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
2458 : 0 : tx_stopped = (ports[fs->tx_port].txq[fs->tx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
2459 : 0 : fs->disabled = rx_stopped || tx_stopped;
2460 : 0 : }
2461 : :
2462 : : static void
2463 : 0 : update_rx_queue_state(uint16_t port_id, uint16_t queue_id)
2464 : : {
2465 : : struct rte_eth_rxq_info rx_qinfo;
2466 : : int32_t rc;
2467 : :
2468 : 0 : rc = rte_eth_rx_queue_info_get(port_id,
2469 : : queue_id, &rx_qinfo);
2470 : 0 : if (rc == 0) {
2471 : 0 : ports[port_id].rxq[queue_id].state =
2472 : 0 : rx_qinfo.queue_state;
2473 : 0 : } else if (rc == -ENOTSUP) {
2474 : : /*
2475 : : * Do not change the rxq state for primary process
2476 : : * to ensure that the PMDs do not implement
2477 : : * rte_eth_rx_queue_info_get can forward as before.
2478 : : */
2479 : 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2480 : 0 : return;
2481 : : /*
2482 : : * Set the rxq state to RTE_ETH_QUEUE_STATE_STARTED
2483 : : * to ensure that the PMDs do not implement
2484 : : * rte_eth_rx_queue_info_get can forward.
2485 : : */
2486 : 0 : ports[port_id].rxq[queue_id].state =
2487 : : RTE_ETH_QUEUE_STATE_STARTED;
2488 : : } else {
2489 : 0 : TESTPMD_LOG(WARNING,
2490 : : "Failed to get rx queue info\n");
2491 : : }
2492 : : }
2493 : :
2494 : : static void
2495 : 0 : update_tx_queue_state(uint16_t port_id, uint16_t queue_id)
2496 : : {
2497 : : struct rte_eth_txq_info tx_qinfo;
2498 : : int32_t rc;
2499 : :
2500 : 0 : rc = rte_eth_tx_queue_info_get(port_id,
2501 : : queue_id, &tx_qinfo);
2502 : 0 : if (rc == 0) {
2503 : 0 : ports[port_id].txq[queue_id].state =
2504 : 0 : tx_qinfo.queue_state;
2505 : 0 : } else if (rc == -ENOTSUP) {
2506 : : /*
2507 : : * Do not change the txq state for primary process
2508 : : * to ensure that the PMDs do not implement
2509 : : * rte_eth_tx_queue_info_get can forward as before.
2510 : : */
2511 : 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2512 : 0 : return;
2513 : : /*
2514 : : * Set the txq state to RTE_ETH_QUEUE_STATE_STARTED
2515 : : * to ensure that the PMDs do not implement
2516 : : * rte_eth_tx_queue_info_get can forward.
2517 : : */
2518 : 0 : ports[port_id].txq[queue_id].state =
2519 : : RTE_ETH_QUEUE_STATE_STARTED;
2520 : : } else {
2521 : 0 : TESTPMD_LOG(WARNING,
2522 : : "Failed to get tx queue info\n");
2523 : : }
2524 : : }
2525 : :
2526 : : static void
2527 : 0 : update_queue_state(portid_t pid)
2528 : : {
2529 : : portid_t pi;
2530 : : queueid_t qi;
2531 : :
2532 : 0 : RTE_ETH_FOREACH_DEV(pi) {
2533 : 0 : if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2534 : 0 : continue;
2535 : :
2536 : 0 : for (qi = 0; qi < nb_rxq; qi++)
2537 : 0 : update_rx_queue_state(pi, qi);
2538 : 0 : for (qi = 0; qi < nb_txq; qi++)
2539 : 0 : update_tx_queue_state(pi, qi);
2540 : : }
2541 : 0 : }
2542 : :
2543 : : /*
2544 : : * Launch packet forwarding configuration.
2545 : : */
2546 : : void
2547 : 0 : start_packet_forwarding(int with_tx_first)
2548 : : {
2549 : : port_fwd_begin_t port_fwd_begin;
2550 : : port_fwd_end_t port_fwd_end;
2551 : 0 : stream_init_t stream_init = cur_fwd_eng->stream_init;
2552 : : unsigned int i;
2553 : :
2554 : 0 : if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
2555 : 0 : rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
2556 : :
2557 : 0 : if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
2558 : 0 : rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
2559 : :
2560 : 0 : if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
2561 : 0 : strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
2562 : 0 : (!nb_rxq || !nb_txq))
2563 : 0 : rte_exit(EXIT_FAILURE,
2564 : : "Either rxq or txq are 0, cannot use %s fwd mode\n",
2565 : : cur_fwd_eng->fwd_mode_name);
2566 : :
2567 : 0 : if (all_ports_started() == 0) {
2568 : 0 : fprintf(stderr, "Not all ports were started\n");
2569 : 0 : return;
2570 : : }
2571 : 0 : if (test_done == 0) {
2572 : 0 : fprintf(stderr, "Packet forwarding already started\n");
2573 : 0 : return;
2574 : : }
2575 : :
2576 : 0 : fwd_config_setup();
2577 : :
2578 : 0 : pkt_fwd_config_display(&cur_fwd_config);
2579 : 0 : if (!pkt_fwd_shared_rxq_check())
2580 : : return;
2581 : :
2582 : 0 : if (stream_init != NULL) {
2583 : 0 : update_queue_state(RTE_PORT_ALL);
2584 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_streams; i++)
2585 : 0 : stream_init(fwd_streams[i]);
2586 : : }
2587 : :
2588 : 0 : port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
2589 : 0 : if (port_fwd_begin != NULL) {
2590 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2591 : 0 : if (port_fwd_begin(fwd_ports_ids[i])) {
2592 : 0 : fprintf(stderr,
2593 : : "Packet forwarding is not ready\n");
2594 : 0 : return;
2595 : : }
2596 : : }
2597 : : }
2598 : :
2599 : 0 : if (with_tx_first) {
2600 : 0 : port_fwd_begin = tx_only_engine.port_fwd_begin;
2601 : 0 : if (port_fwd_begin != NULL) {
2602 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2603 : 0 : if (port_fwd_begin(fwd_ports_ids[i])) {
2604 : 0 : fprintf(stderr,
2605 : : "Packet forwarding is not ready\n");
2606 : 0 : return;
2607 : : }
2608 : : }
2609 : : }
2610 : : }
2611 : :
2612 : 0 : test_done = 0;
2613 : :
2614 : 0 : if(!no_flush_rx)
2615 : 0 : flush_fwd_rx_queues();
2616 : :
2617 : 0 : rxtx_config_display();
2618 : :
2619 : 0 : fwd_stats_reset();
2620 : 0 : if (with_tx_first) {
2621 : 0 : while (with_tx_first--) {
2622 : 0 : launch_packet_forwarding(
2623 : : run_one_txonly_burst_on_core);
2624 : 0 : rte_eal_mp_wait_lcore();
2625 : : }
2626 : 0 : port_fwd_end = tx_only_engine.port_fwd_end;
2627 : 0 : if (port_fwd_end != NULL) {
2628 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2629 : 0 : (*port_fwd_end)(fwd_ports_ids[i]);
2630 : : }
2631 : : }
2632 : 0 : launch_packet_forwarding(start_pkt_forward_on_core);
2633 : : }
2634 : :
2635 : : void
2636 : 0 : stop_packet_forwarding(void)
2637 : : {
2638 : : port_fwd_end_t port_fwd_end;
2639 : : lcoreid_t lc_id;
2640 : : portid_t pt_id;
2641 : : int i;
2642 : :
2643 : 0 : if (test_done) {
2644 : 0 : fprintf(stderr, "Packet forwarding not started\n");
2645 : 0 : return;
2646 : : }
2647 : : printf("Telling cores to stop...");
2648 : 0 : for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
2649 : 0 : fwd_lcores[lc_id]->stopped = 1;
2650 : : printf("\nWaiting for lcores to finish...\n");
2651 : 0 : rte_eal_mp_wait_lcore();
2652 : 0 : port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
2653 : 0 : if (port_fwd_end != NULL) {
2654 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2655 : 0 : pt_id = fwd_ports_ids[i];
2656 : 0 : (*port_fwd_end)(pt_id);
2657 : : }
2658 : : }
2659 : :
2660 : 0 : fwd_stats_display();
2661 : :
2662 : : printf("\nDone.\n");
2663 : 0 : test_done = 1;
2664 : : }
2665 : :
2666 : : void
2667 : 0 : dev_set_link_up(portid_t pid)
2668 : : {
2669 : 0 : if (rte_eth_dev_set_link_up(pid) < 0)
2670 : 0 : fprintf(stderr, "\nSet link up fail.\n");
2671 : 0 : }
2672 : :
2673 : : void
2674 : 0 : dev_set_link_down(portid_t pid)
2675 : : {
2676 : 0 : if (rte_eth_dev_set_link_down(pid) < 0)
2677 : 0 : fprintf(stderr, "\nSet link down fail.\n");
2678 : 0 : }
2679 : :
2680 : : static int
2681 : 0 : all_ports_started(void)
2682 : : {
2683 : : portid_t pi;
2684 : : struct rte_port *port;
2685 : :
2686 : 0 : RTE_ETH_FOREACH_DEV(pi) {
2687 : 0 : port = &ports[pi];
2688 : : /* Check if there is a port which is not started */
2689 : 0 : if ((port->port_status != RTE_PORT_STARTED) &&
2690 : 0 : (port->member_flag == 0))
2691 : : return 0;
2692 : : }
2693 : :
2694 : : /* No port is not started */
2695 : : return 1;
2696 : : }
2697 : :
2698 : : int
2699 : 0 : port_is_stopped(portid_t port_id)
2700 : : {
2701 : 0 : struct rte_port *port = &ports[port_id];
2702 : :
2703 : 0 : if ((port->port_status != RTE_PORT_STOPPED) &&
2704 : 0 : (port->member_flag == 0))
2705 : 0 : return 0;
2706 : : return 1;
2707 : : }
2708 : :
2709 : : int
2710 : 0 : all_ports_stopped(void)
2711 : : {
2712 : : portid_t pi;
2713 : :
2714 : 0 : RTE_ETH_FOREACH_DEV(pi) {
2715 : : if (!port_is_stopped(pi))
2716 : : return 0;
2717 : : }
2718 : :
2719 : : return 1;
2720 : : }
2721 : :
2722 : : int
2723 : 0 : port_is_started(portid_t port_id)
2724 : : {
2725 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
2726 : : return 0;
2727 : :
2728 : 0 : if (ports[port_id].port_status != RTE_PORT_STARTED)
2729 : 0 : return 0;
2730 : :
2731 : : return 1;
2732 : : }
2733 : :
2734 : : /* Configure the Rx with optional split. */
2735 : : int
2736 : 0 : rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
2737 : : uint16_t nb_rx_desc, unsigned int socket_id,
2738 : : struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp)
2739 : : {
2740 : 0 : union rte_eth_rxseg rx_useg[MAX_SEGS_BUFFER_SPLIT] = {};
2741 : 0 : struct rte_mempool *rx_mempool[MAX_MEMPOOL] = {};
2742 : : struct rte_mempool *mpx;
2743 : : unsigned int i, mp_n;
2744 : : uint32_t prev_hdrs = 0;
2745 : : int ret;
2746 : :
2747 : 0 : if ((rx_pkt_nb_segs > 1) &&
2748 : 0 : (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
2749 : : /* multi-segment configuration */
2750 : 0 : for (i = 0; i < rx_pkt_nb_segs; i++) {
2751 : : struct rte_eth_rxseg_split *rx_seg = &rx_useg[i].split;
2752 : : /*
2753 : : * Use last valid pool for the segments with number
2754 : : * exceeding the pool index.
2755 : : */
2756 : 0 : mp_n = (i >= mbuf_data_size_n) ? mbuf_data_size_n - 1 : i;
2757 : 0 : mpx = mbuf_pool_find(socket_id, mp_n);
2758 : : /* Handle zero as mbuf data buffer size. */
2759 : 0 : rx_seg->offset = i < rx_pkt_nb_offs ?
2760 : : rx_pkt_seg_offsets[i] : 0;
2761 : 0 : rx_seg->mp = mpx ? mpx : mp;
2762 : 0 : if (rx_pkt_hdr_protos[i] != 0 && rx_pkt_seg_lengths[i] == 0) {
2763 : 0 : rx_seg->proto_hdr = rx_pkt_hdr_protos[i] & ~prev_hdrs;
2764 : 0 : prev_hdrs |= rx_seg->proto_hdr;
2765 : : } else {
2766 : 0 : rx_seg->length = rx_pkt_seg_lengths[i] ?
2767 : : rx_pkt_seg_lengths[i] :
2768 : : mbuf_data_size[mp_n];
2769 : : }
2770 : : }
2771 : 0 : rx_conf->rx_nseg = rx_pkt_nb_segs;
2772 : 0 : rx_conf->rx_seg = rx_useg;
2773 : 0 : rx_conf->rx_mempools = NULL;
2774 : 0 : rx_conf->rx_nmempool = 0;
2775 : 0 : ret = rte_eth_rx_queue_setup(port_id, rx_queue_id, nb_rx_desc,
2776 : : socket_id, rx_conf, NULL);
2777 : 0 : rx_conf->rx_seg = NULL;
2778 : 0 : rx_conf->rx_nseg = 0;
2779 : 0 : } else if (multi_rx_mempool == 1) {
2780 : : /* multi-pool configuration */
2781 : : struct rte_eth_dev_info dev_info;
2782 : :
2783 : 0 : if (mbuf_data_size_n <= 1) {
2784 : 0 : fprintf(stderr, "Invalid number of mempools %u\n",
2785 : : mbuf_data_size_n);
2786 : 0 : return -EINVAL;
2787 : : }
2788 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2789 : 0 : if (ret != 0)
2790 : : return ret;
2791 : 0 : if (dev_info.max_rx_mempools == 0) {
2792 : 0 : fprintf(stderr,
2793 : : "Port %u doesn't support requested multi-rx-mempool configuration.\n",
2794 : : port_id);
2795 : 0 : return -ENOTSUP;
2796 : : }
2797 : 0 : for (i = 0; i < mbuf_data_size_n; i++) {
2798 : 0 : mpx = mbuf_pool_find(socket_id, i);
2799 : 0 : rx_mempool[i] = mpx ? mpx : mp;
2800 : : }
2801 : 0 : rx_conf->rx_mempools = rx_mempool;
2802 : 0 : rx_conf->rx_nmempool = mbuf_data_size_n;
2803 : 0 : rx_conf->rx_seg = NULL;
2804 : 0 : rx_conf->rx_nseg = 0;
2805 : 0 : ret = rte_eth_rx_queue_setup(port_id, rx_queue_id, nb_rx_desc,
2806 : : socket_id, rx_conf, NULL);
2807 : 0 : rx_conf->rx_mempools = NULL;
2808 : 0 : rx_conf->rx_nmempool = 0;
2809 : : } else {
2810 : : /* Single pool/segment configuration */
2811 : 0 : rx_conf->rx_seg = NULL;
2812 : 0 : rx_conf->rx_nseg = 0;
2813 : 0 : rx_conf->rx_mempools = NULL;
2814 : 0 : rx_conf->rx_nmempool = 0;
2815 : 0 : ret = rte_eth_rx_queue_setup(port_id, rx_queue_id, nb_rx_desc,
2816 : : socket_id, rx_conf, mp);
2817 : : }
2818 : :
2819 : 0 : ports[port_id].rxq[rx_queue_id].state = rx_conf->rx_deferred_start ?
2820 : 0 : RTE_ETH_QUEUE_STATE_STOPPED :
2821 : : RTE_ETH_QUEUE_STATE_STARTED;
2822 : 0 : return ret;
2823 : : }
2824 : :
2825 : : static int
2826 : 0 : alloc_xstats_display_info(portid_t pi)
2827 : : {
2828 : 0 : uint64_t **ids_supp = &ports[pi].xstats_info.ids_supp;
2829 : : uint64_t **prev_values = &ports[pi].xstats_info.prev_values;
2830 : : uint64_t **curr_values = &ports[pi].xstats_info.curr_values;
2831 : :
2832 : 0 : if (xstats_display_num == 0)
2833 : : return 0;
2834 : :
2835 : 0 : *ids_supp = calloc(xstats_display_num, sizeof(**ids_supp));
2836 : 0 : if (*ids_supp == NULL)
2837 : 0 : goto fail_ids_supp;
2838 : :
2839 : 0 : *prev_values = calloc(xstats_display_num,
2840 : : sizeof(**prev_values));
2841 : 0 : if (*prev_values == NULL)
2842 : 0 : goto fail_prev_values;
2843 : :
2844 : 0 : *curr_values = calloc(xstats_display_num,
2845 : : sizeof(**curr_values));
2846 : 0 : if (*curr_values == NULL)
2847 : 0 : goto fail_curr_values;
2848 : :
2849 : 0 : ports[pi].xstats_info.allocated = true;
2850 : :
2851 : 0 : return 0;
2852 : :
2853 : : fail_curr_values:
2854 : 0 : free(*prev_values);
2855 : 0 : fail_prev_values:
2856 : 0 : free(*ids_supp);
2857 : : fail_ids_supp:
2858 : : return -ENOMEM;
2859 : : }
2860 : :
2861 : : static void
2862 : 0 : free_xstats_display_info(portid_t pi)
2863 : : {
2864 : 0 : if (!ports[pi].xstats_info.allocated)
2865 : : return;
2866 : 0 : free(ports[pi].xstats_info.ids_supp);
2867 : 0 : free(ports[pi].xstats_info.prev_values);
2868 : 0 : free(ports[pi].xstats_info.curr_values);
2869 : 0 : ports[pi].xstats_info.allocated = false;
2870 : : }
2871 : :
2872 : : /** Fill helper structures for specified port to show extended statistics. */
2873 : : static void
2874 : 0 : fill_xstats_display_info_for_port(portid_t pi)
2875 : : {
2876 : : unsigned int stat, stat_supp;
2877 : : const char *xstat_name;
2878 : : struct rte_port *port;
2879 : : uint64_t *ids_supp;
2880 : : int rc;
2881 : :
2882 : 0 : if (xstats_display_num == 0)
2883 : : return;
2884 : :
2885 : 0 : if (pi == (portid_t)RTE_PORT_ALL) {
2886 : 0 : fill_xstats_display_info();
2887 : 0 : return;
2888 : : }
2889 : :
2890 : 0 : port = &ports[pi];
2891 : 0 : if (port->port_status != RTE_PORT_STARTED)
2892 : : return;
2893 : :
2894 : 0 : if (!port->xstats_info.allocated && alloc_xstats_display_info(pi) != 0)
2895 : 0 : rte_exit(EXIT_FAILURE,
2896 : : "Failed to allocate xstats display memory\n");
2897 : :
2898 : 0 : ids_supp = port->xstats_info.ids_supp;
2899 : 0 : for (stat = stat_supp = 0; stat < xstats_display_num; stat++) {
2900 : 0 : xstat_name = xstats_display[stat].name;
2901 : 0 : rc = rte_eth_xstats_get_id_by_name(pi, xstat_name,
2902 : 0 : ids_supp + stat_supp);
2903 : 0 : if (rc != 0) {
2904 : 0 : fprintf(stderr, "No xstat '%s' on port %u - skip it %u\n",
2905 : : xstat_name, pi, stat);
2906 : 0 : continue;
2907 : : }
2908 : 0 : stat_supp++;
2909 : : }
2910 : :
2911 : 0 : port->xstats_info.ids_supp_sz = stat_supp;
2912 : : }
2913 : :
2914 : : /** Fill helper structures for all ports to show extended statistics. */
2915 : : static void
2916 : 0 : fill_xstats_display_info(void)
2917 : : {
2918 : : portid_t pi;
2919 : :
2920 : 0 : if (xstats_display_num == 0)
2921 : : return;
2922 : :
2923 : 0 : RTE_ETH_FOREACH_DEV(pi)
2924 : 0 : fill_xstats_display_info_for_port(pi);
2925 : : }
2926 : :
2927 : : /*
2928 : : * Some capabilities (like, rx_offload_capa and tx_offload_capa) of bonding
2929 : : * device in dev_info is zero when no member is added. And its capability
2930 : : * will be updated when add a new member device. So adding a member device need
2931 : : * to update the port configurations of bonding device.
2932 : : */
2933 : : static void
2934 : 0 : update_bonding_port_dev_conf(portid_t bond_pid)
2935 : : {
2936 : : #ifdef RTE_NET_BOND
2937 : 0 : struct rte_port *port = &ports[bond_pid];
2938 : : uint16_t i;
2939 : : int ret;
2940 : :
2941 : 0 : ret = eth_dev_info_get_print_err(bond_pid, &port->dev_info);
2942 : 0 : if (ret != 0) {
2943 : 0 : fprintf(stderr, "Failed to get dev info for port = %u\n",
2944 : : bond_pid);
2945 : 0 : return;
2946 : : }
2947 : :
2948 : 0 : if (port->dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
2949 : 0 : port->dev_conf.txmode.offloads |=
2950 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
2951 : : /* Apply Tx offloads configuration */
2952 : 0 : for (i = 0; i < port->dev_info.max_tx_queues; i++)
2953 : 0 : port->txq[i].conf.offloads = port->dev_conf.txmode.offloads;
2954 : :
2955 : 0 : port->dev_conf.rx_adv_conf.rss_conf.rss_hf &=
2956 : 0 : port->dev_info.flow_type_rss_offloads;
2957 : : #else
2958 : : RTE_SET_USED(bond_pid);
2959 : : #endif
2960 : : }
2961 : :
2962 : : int
2963 : 0 : start_port(portid_t pid)
2964 : : {
2965 : : int diag;
2966 : : portid_t pi;
2967 : : portid_t p_pi = RTE_MAX_ETHPORTS;
2968 : : portid_t pl[RTE_MAX_ETHPORTS];
2969 : : portid_t peer_pl[RTE_MAX_ETHPORTS];
2970 : : uint16_t cnt_pi = 0;
2971 : : uint16_t cfg_pi = 0;
2972 : : queueid_t qi;
2973 : : struct rte_port *port;
2974 : : struct rte_eth_hairpin_cap cap;
2975 : : bool at_least_one_port_exist = false;
2976 : : bool all_ports_already_started = true;
2977 : : bool at_least_one_port_successfully_started = false;
2978 : :
2979 : 0 : if (port_id_is_invalid(pid, ENABLED_WARN))
2980 : : return 0;
2981 : :
2982 : 0 : RTE_ETH_FOREACH_DEV(pi) {
2983 : 0 : if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2984 : 0 : continue;
2985 : :
2986 : 0 : if (port_is_bonding_member(pi)) {
2987 : 0 : fprintf(stderr,
2988 : : "Please remove port %d from bonding device.\n",
2989 : : pi);
2990 : 0 : continue;
2991 : : }
2992 : :
2993 : : at_least_one_port_exist = true;
2994 : :
2995 : 0 : port = &ports[pi];
2996 : 0 : if (port->port_status == RTE_PORT_STOPPED) {
2997 : 0 : port->port_status = RTE_PORT_HANDLING;
2998 : : all_ports_already_started = false;
2999 : : } else {
3000 : 0 : fprintf(stderr, "Port %d is now not stopped\n", pi);
3001 : 0 : continue;
3002 : : }
3003 : :
3004 : 0 : if (port->need_reconfig > 0) {
3005 : : struct rte_eth_conf dev_conf;
3006 : : int k;
3007 : :
3008 : 0 : port->need_reconfig = 0;
3009 : :
3010 : 0 : if (flow_isolate_all) {
3011 : 0 : int ret = port_flow_isolate(pi, 1);
3012 : 0 : if (ret) {
3013 : 0 : fprintf(stderr,
3014 : : "Failed to apply isolated mode on port %d\n",
3015 : : pi);
3016 : 0 : return -1;
3017 : : }
3018 : : }
3019 : 0 : configure_rxtx_dump_callbacks(0);
3020 : 0 : printf("Configuring Port %d (socket %u)\n", pi,
3021 : : port->socket_id);
3022 : 0 : if (nb_hairpinq > 0 &&
3023 : 0 : rte_eth_dev_hairpin_capability_get(pi, &cap)) {
3024 : 0 : fprintf(stderr,
3025 : : "Port %d doesn't support hairpin queues\n",
3026 : : pi);
3027 : 0 : return -1;
3028 : : }
3029 : :
3030 : 0 : if (port->bond_flag == 1 && port->update_conf == 1) {
3031 : 0 : update_bonding_port_dev_conf(pi);
3032 : 0 : port->update_conf = 0;
3033 : : }
3034 : :
3035 : : /* configure port */
3036 : 0 : diag = eth_dev_configure_mp(pi, nb_rxq + nb_hairpinq,
3037 : 0 : nb_txq + nb_hairpinq,
3038 : 0 : &(port->dev_conf));
3039 : 0 : if (diag != 0) {
3040 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3041 : 0 : port->port_status = RTE_PORT_STOPPED;
3042 : : else
3043 : 0 : fprintf(stderr,
3044 : : "Port %d can not be set back to stopped\n",
3045 : : pi);
3046 : 0 : fprintf(stderr, "Fail to configure port %d\n",
3047 : : pi);
3048 : : /* try to reconfigure port next time */
3049 : 0 : port->need_reconfig = 1;
3050 : 0 : return -1;
3051 : : }
3052 : : /* get device configuration*/
3053 : 0 : if (0 !=
3054 : 0 : eth_dev_conf_get_print_err(pi, &dev_conf)) {
3055 : 0 : fprintf(stderr,
3056 : : "port %d can not get device configuration\n",
3057 : : pi);
3058 : 0 : return -1;
3059 : : }
3060 : : /* Apply Rx offloads configuration */
3061 : 0 : if (dev_conf.rxmode.offloads !=
3062 : 0 : port->dev_conf.rxmode.offloads) {
3063 : 0 : port->dev_conf.rxmode.offloads |=
3064 : : dev_conf.rxmode.offloads;
3065 : 0 : for (k = 0;
3066 : 0 : k < port->dev_info.max_rx_queues;
3067 : 0 : k++)
3068 : 0 : port->rxq[k].conf.offloads |=
3069 : : dev_conf.rxmode.offloads;
3070 : : }
3071 : : /* Apply Tx offloads configuration */
3072 : 0 : if (dev_conf.txmode.offloads !=
3073 : 0 : port->dev_conf.txmode.offloads) {
3074 : 0 : port->dev_conf.txmode.offloads |=
3075 : : dev_conf.txmode.offloads;
3076 : 0 : for (k = 0;
3077 : 0 : k < port->dev_info.max_tx_queues;
3078 : 0 : k++)
3079 : 0 : port->txq[k].conf.offloads |=
3080 : : dev_conf.txmode.offloads;
3081 : : }
3082 : : }
3083 : 0 : if (port->need_reconfig_queues > 0 && is_proc_primary()) {
3084 : 0 : port->need_reconfig_queues = 0;
3085 : : /* setup tx queues */
3086 : 0 : for (qi = 0; qi < nb_txq; qi++) {
3087 : : struct rte_eth_txconf *conf =
3088 : 0 : &port->txq[qi].conf;
3089 : :
3090 : 0 : if ((numa_support) &&
3091 : 0 : (txring_numa[pi] != NUMA_NO_CONFIG))
3092 : 0 : diag = rte_eth_tx_queue_setup(pi, qi,
3093 : 0 : port->nb_tx_desc[qi],
3094 : : txring_numa[pi],
3095 : 0 : &(port->txq[qi].conf));
3096 : : else
3097 : 0 : diag = rte_eth_tx_queue_setup(pi, qi,
3098 : 0 : port->nb_tx_desc[qi],
3099 : : port->socket_id,
3100 : 0 : &(port->txq[qi].conf));
3101 : :
3102 : 0 : if (diag == 0) {
3103 : 0 : port->txq[qi].state =
3104 : 0 : conf->tx_deferred_start ?
3105 : 0 : RTE_ETH_QUEUE_STATE_STOPPED :
3106 : : RTE_ETH_QUEUE_STATE_STARTED;
3107 : : continue;
3108 : : }
3109 : :
3110 : : /* Fail to setup tx queue, return */
3111 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3112 : 0 : port->port_status = RTE_PORT_STOPPED;
3113 : : else
3114 : 0 : fprintf(stderr,
3115 : : "Port %d can not be set back to stopped\n",
3116 : : pi);
3117 : 0 : fprintf(stderr,
3118 : : "Fail to configure port %d tx queues\n",
3119 : : pi);
3120 : : /* try to reconfigure queues next time */
3121 : 0 : port->need_reconfig_queues = 1;
3122 : 0 : return -1;
3123 : : }
3124 : 0 : for (qi = 0; qi < nb_rxq; qi++) {
3125 : : /* setup rx queues */
3126 : 0 : if ((numa_support) &&
3127 : 0 : (rxring_numa[pi] != NUMA_NO_CONFIG)) {
3128 : : struct rte_mempool * mp =
3129 : 0 : mbuf_pool_find
3130 : : (rxring_numa[pi], 0);
3131 : 0 : if (mp == NULL) {
3132 : 0 : fprintf(stderr,
3133 : : "Failed to setup RX queue: No mempool allocation on the socket %d\n",
3134 : 0 : rxring_numa[pi]);
3135 : 0 : return -1;
3136 : : }
3137 : :
3138 : 0 : diag = rx_queue_setup(pi, qi,
3139 : 0 : port->nb_rx_desc[qi],
3140 : 0 : rxring_numa[pi],
3141 : 0 : &(port->rxq[qi].conf),
3142 : : mp);
3143 : : } else {
3144 : : struct rte_mempool *mp =
3145 : 0 : mbuf_pool_find
3146 : : ((numa_support ? port->socket_id :
3147 : : (unsigned int)SOCKET_ID_ANY), 0);
3148 : 0 : if (mp == NULL) {
3149 : 0 : fprintf(stderr,
3150 : : "Failed to setup RX queue: No mempool allocation on the socket %d\n",
3151 : : port->socket_id);
3152 : 0 : return -1;
3153 : : }
3154 : 0 : diag = rx_queue_setup(pi, qi,
3155 : 0 : port->nb_rx_desc[qi],
3156 : : port->socket_id,
3157 : 0 : &(port->rxq[qi].conf),
3158 : : mp);
3159 : : }
3160 : 0 : if (diag == 0)
3161 : : continue;
3162 : :
3163 : : /* Fail to setup rx queue, return */
3164 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3165 : 0 : port->port_status = RTE_PORT_STOPPED;
3166 : : else
3167 : 0 : fprintf(stderr,
3168 : : "Port %d can not be set back to stopped\n",
3169 : : pi);
3170 : 0 : fprintf(stderr,
3171 : : "Fail to configure port %d rx queues\n",
3172 : : pi);
3173 : : /* try to reconfigure queues next time */
3174 : 0 : port->need_reconfig_queues = 1;
3175 : 0 : return -1;
3176 : : }
3177 : : /* setup hairpin queues */
3178 : 0 : if (setup_hairpin_queues(pi, p_pi, cnt_pi) != 0)
3179 : : return -1;
3180 : : }
3181 : 0 : configure_rxtx_dump_callbacks(verbose_level);
3182 : 0 : if (clear_ptypes) {
3183 : 0 : diag = rte_eth_dev_set_ptypes(pi, RTE_PTYPE_UNKNOWN,
3184 : : NULL, 0);
3185 : 0 : if (diag < 0)
3186 : 0 : fprintf(stderr,
3187 : : "Port %d: Failed to disable Ptype parsing\n",
3188 : : pi);
3189 : : }
3190 : :
3191 : : p_pi = pi;
3192 : 0 : cnt_pi++;
3193 : :
3194 : : /* start port */
3195 : 0 : diag = eth_dev_start_mp(pi);
3196 : 0 : if (diag < 0) {
3197 : 0 : fprintf(stderr, "Fail to start port %d: %s\n",
3198 : : pi, rte_strerror(-diag));
3199 : :
3200 : : /* Fail to setup rx queue, return */
3201 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3202 : 0 : port->port_status = RTE_PORT_STOPPED;
3203 : : else
3204 : 0 : fprintf(stderr,
3205 : : "Port %d can not be set back to stopped\n",
3206 : : pi);
3207 : 0 : continue;
3208 : : }
3209 : :
3210 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3211 : 0 : port->port_status = RTE_PORT_STARTED;
3212 : : else
3213 : 0 : fprintf(stderr, "Port %d can not be set into started\n",
3214 : : pi);
3215 : :
3216 : 0 : if (eth_macaddr_get_print_err(pi, &port->eth_addr) == 0)
3217 : 0 : printf("Port %d: " RTE_ETHER_ADDR_PRT_FMT "\n", pi,
3218 : 0 : RTE_ETHER_ADDR_BYTES(&port->eth_addr));
3219 : :
3220 : : at_least_one_port_successfully_started = true;
3221 : :
3222 : 0 : pl[cfg_pi++] = pi;
3223 : : }
3224 : :
3225 : 0 : update_queue_state(pi);
3226 : :
3227 : 0 : if (at_least_one_port_successfully_started && !no_link_check)
3228 : 0 : check_all_ports_link_status(RTE_PORT_ALL);
3229 : 0 : else if (at_least_one_port_exist & all_ports_already_started)
3230 : 0 : fprintf(stderr, "Please stop the ports first\n");
3231 : :
3232 : 0 : if (hairpin_mode & 0xf) {
3233 : 0 : diag = hairpin_bind(cfg_pi, pl, peer_pl);
3234 : 0 : if (diag < 0)
3235 : : return -1;
3236 : : }
3237 : :
3238 : 0 : fill_xstats_display_info_for_port(pid);
3239 : :
3240 : : printf("Done\n");
3241 : 0 : return 0;
3242 : : }
3243 : :
3244 : : void
3245 : 0 : stop_port(portid_t pid)
3246 : : {
3247 : : portid_t pi;
3248 : : struct rte_port *port;
3249 : : int need_check_link_status = 0;
3250 : : portid_t peer_pl[RTE_MAX_ETHPORTS];
3251 : : int peer_pi;
3252 : : int ret;
3253 : :
3254 : 0 : if (port_id_is_invalid(pid, ENABLED_WARN))
3255 : 0 : return;
3256 : :
3257 : : printf("Stopping ports...\n");
3258 : :
3259 : 0 : RTE_ETH_FOREACH_DEV(pi) {
3260 : 0 : if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
3261 : 0 : continue;
3262 : :
3263 : 0 : if (port_is_forwarding(pi) != 0 && test_done == 0) {
3264 : 0 : fprintf(stderr,
3265 : : "Please remove port %d from forwarding configuration.\n",
3266 : : pi);
3267 : 0 : continue;
3268 : : }
3269 : :
3270 : 0 : if (port_is_bonding_member(pi)) {
3271 : 0 : fprintf(stderr,
3272 : : "Please remove port %d from bonding device.\n",
3273 : : pi);
3274 : 0 : continue;
3275 : : }
3276 : :
3277 : 0 : port = &ports[pi];
3278 : 0 : if (port->port_status == RTE_PORT_STARTED)
3279 : 0 : port->port_status = RTE_PORT_HANDLING;
3280 : : else
3281 : 0 : continue;
3282 : :
3283 : 0 : if (hairpin_mode & 0xf) {
3284 : : int j;
3285 : :
3286 : 0 : rte_eth_hairpin_unbind(pi, RTE_MAX_ETHPORTS);
3287 : : /* unbind all peer Tx from current Rx */
3288 : 0 : peer_pi = rte_eth_hairpin_get_peer_ports(pi, peer_pl,
3289 : : RTE_MAX_ETHPORTS, 0);
3290 : 0 : if (peer_pi < 0)
3291 : 0 : continue;
3292 : 0 : for (j = 0; j < peer_pi; j++) {
3293 : 0 : if (!port_is_started(peer_pl[j]))
3294 : 0 : continue;
3295 : 0 : rte_eth_hairpin_unbind(peer_pl[j], pi);
3296 : : }
3297 : : }
3298 : :
3299 : 0 : if (port->flow_list && !no_flow_flush)
3300 : 0 : port_flow_flush(pi);
3301 : :
3302 : 0 : ret = eth_dev_stop_mp(pi);
3303 : 0 : if (ret != 0) {
3304 : 0 : TESTPMD_LOG(ERR,
3305 : : "rte_eth_dev_stop failed for port %u\n", pi);
3306 : : /* Allow to retry stopping the port. */
3307 : 0 : port->port_status = RTE_PORT_STARTED;
3308 : 0 : continue;
3309 : : }
3310 : :
3311 : 0 : if (port->port_status == RTE_PORT_HANDLING)
3312 : 0 : port->port_status = RTE_PORT_STOPPED;
3313 : : else
3314 : 0 : fprintf(stderr, "Port %d can not be set into stopped\n",
3315 : : pi);
3316 : : need_check_link_status = 1;
3317 : : }
3318 : 0 : if (need_check_link_status && !no_link_check)
3319 : 0 : check_all_ports_link_status(RTE_PORT_ALL);
3320 : :
3321 : : printf("Done\n");
3322 : : }
3323 : :
3324 : : static void
3325 : 0 : remove_invalid_ports_in(portid_t *array, portid_t *total)
3326 : : {
3327 : : portid_t i;
3328 : : portid_t new_total = 0;
3329 : :
3330 : 0 : for (i = 0; i < *total; i++)
3331 : 0 : if (!port_id_is_invalid(array[i], DISABLED_WARN)) {
3332 : 0 : array[new_total] = array[i];
3333 : 0 : new_total++;
3334 : : }
3335 : 0 : *total = new_total;
3336 : 0 : }
3337 : :
3338 : : static void
3339 : 0 : remove_invalid_ports(void)
3340 : : {
3341 : 0 : remove_invalid_ports_in(ports_ids, &nb_ports);
3342 : 0 : remove_invalid_ports_in(fwd_ports_ids, &nb_fwd_ports);
3343 : 0 : nb_cfg_ports = nb_fwd_ports;
3344 : 0 : try_release_share_groups();
3345 : 0 : }
3346 : :
3347 : : static void
3348 : : port_free_job_list(portid_t pi)
3349 : : {
3350 : 0 : struct rte_port *port = &ports[pi];
3351 : 0 : free(port->job_list);
3352 : : }
3353 : :
3354 : : static void
3355 : 0 : flush_port_owned_resources(portid_t pi)
3356 : : {
3357 : 0 : mcast_addr_pool_destroy(pi);
3358 : 0 : port_flow_flush(pi);
3359 : 0 : port_flow_template_table_flush(pi);
3360 : 0 : port_flow_pattern_template_flush(pi);
3361 : 0 : port_flow_actions_template_flush(pi);
3362 : 0 : port_flex_item_flush(pi);
3363 : 0 : port_action_handle_flush(pi);
3364 : : port_free_job_list(pi);
3365 : 0 : }
3366 : :
3367 : : static void
3368 : 0 : clear_bonding_member_device(portid_t *member_pids, uint16_t num_members)
3369 : : {
3370 : : struct rte_port *port;
3371 : : portid_t member_pid;
3372 : : uint16_t i;
3373 : :
3374 : 0 : for (i = 0; i < num_members; i++) {
3375 : 0 : member_pid = member_pids[i];
3376 : 0 : if (port_is_started(member_pid) == 1) {
3377 : 0 : if (rte_eth_dev_stop(member_pid) != 0)
3378 : 0 : fprintf(stderr, "rte_eth_dev_stop failed for port %u\n",
3379 : : member_pid);
3380 : :
3381 : 0 : port = &ports[member_pid];
3382 : 0 : port->port_status = RTE_PORT_STOPPED;
3383 : : }
3384 : :
3385 : : clear_port_member_flag(member_pid);
3386 : :
3387 : : /* Close member device when testpmd quit or is killed. */
3388 : 0 : if (cl_quit == 1 || f_quit == 1)
3389 : 0 : rte_eth_dev_close(member_pid);
3390 : : }
3391 : 0 : }
3392 : :
3393 : : void
3394 : 0 : close_port(portid_t pid)
3395 : : {
3396 : : portid_t pi;
3397 : : struct rte_port *port;
3398 : : portid_t member_pids[RTE_MAX_ETHPORTS];
3399 : : int num_members = 0;
3400 : :
3401 : 0 : if (port_id_is_invalid(pid, ENABLED_WARN))
3402 : 0 : return;
3403 : :
3404 : : printf("Closing ports...\n");
3405 : :
3406 : 0 : RTE_ETH_FOREACH_DEV(pi) {
3407 : 0 : if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
3408 : 0 : continue;
3409 : :
3410 : 0 : if (port_is_forwarding(pi) != 0 && test_done == 0) {
3411 : 0 : fprintf(stderr,
3412 : : "Please remove port %d from forwarding configuration.\n",
3413 : : pi);
3414 : 0 : continue;
3415 : : }
3416 : :
3417 : 0 : if (port_is_bonding_member(pi)) {
3418 : 0 : fprintf(stderr,
3419 : : "Please remove port %d from bonding device.\n",
3420 : : pi);
3421 : 0 : continue;
3422 : : }
3423 : :
3424 : 0 : port = &ports[pi];
3425 : 0 : if (port->port_status == RTE_PORT_CLOSED) {
3426 : 0 : fprintf(stderr, "Port %d is already closed\n", pi);
3427 : 0 : continue;
3428 : : }
3429 : :
3430 : 0 : if (is_proc_primary()) {
3431 : 0 : flush_port_owned_resources(pi);
3432 : : #ifdef RTE_NET_BOND
3433 : 0 : if (port->bond_flag == 1)
3434 : 0 : num_members = rte_eth_bond_members_get(pi,
3435 : : member_pids, RTE_MAX_ETHPORTS);
3436 : : #endif
3437 : 0 : rte_eth_dev_close(pi);
3438 : : /*
3439 : : * If this port is bonding device, all members under the
3440 : : * device need to be removed or closed.
3441 : : */
3442 : 0 : if (port->bond_flag == 1 && num_members > 0)
3443 : 0 : clear_bonding_member_device(member_pids,
3444 : : num_members);
3445 : : }
3446 : :
3447 : 0 : free_xstats_display_info(pi);
3448 : : }
3449 : :
3450 : 0 : remove_invalid_ports();
3451 : : printf("Done\n");
3452 : : }
3453 : :
3454 : : void
3455 : 0 : reset_port(portid_t pid)
3456 : : {
3457 : : int diag;
3458 : : portid_t pi;
3459 : : struct rte_port *port;
3460 : :
3461 : 0 : if (port_id_is_invalid(pid, ENABLED_WARN))
3462 : : return;
3463 : :
3464 : 0 : if ((pid == (portid_t)RTE_PORT_ALL && !all_ports_stopped()) ||
3465 : : (pid != (portid_t)RTE_PORT_ALL && !port_is_stopped(pid))) {
3466 : 0 : fprintf(stderr,
3467 : : "Can not reset port(s), please stop port(s) first.\n");
3468 : 0 : return;
3469 : : }
3470 : :
3471 : : printf("Resetting ports...\n");
3472 : :
3473 : 0 : RTE_ETH_FOREACH_DEV(pi) {
3474 : 0 : if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
3475 : 0 : continue;
3476 : :
3477 : 0 : if (port_is_forwarding(pi) != 0 && test_done == 0) {
3478 : 0 : fprintf(stderr,
3479 : : "Please remove port %d from forwarding configuration.\n",
3480 : : pi);
3481 : 0 : continue;
3482 : : }
3483 : :
3484 : 0 : if (port_is_bonding_member(pi)) {
3485 : 0 : fprintf(stderr,
3486 : : "Please remove port %d from bonding device.\n",
3487 : : pi);
3488 : 0 : continue;
3489 : : }
3490 : :
3491 : 0 : if (is_proc_primary()) {
3492 : 0 : diag = rte_eth_dev_reset(pi);
3493 : 0 : if (diag == 0) {
3494 : 0 : port = &ports[pi];
3495 : 0 : port->need_reconfig = 1;
3496 : 0 : port->need_reconfig_queues = 1;
3497 : : } else {
3498 : 0 : fprintf(stderr, "Failed to reset port %d. diag=%d\n",
3499 : : pi, diag);
3500 : : }
3501 : : }
3502 : : }
3503 : :
3504 : : printf("Done\n");
3505 : : }
3506 : :
3507 : : static char *
3508 : 0 : convert_pci_address_format(const char *identifier, char *pci_buffer, size_t buf_size)
3509 : : {
3510 : : struct rte_devargs da;
3511 : : struct rte_pci_addr pci_addr;
3512 : : size_t pci_len;
3513 : : char *result = NULL;
3514 : :
3515 : 0 : if (rte_devargs_parse(&da, identifier) != 0)
3516 : : return NULL;
3517 : :
3518 : 0 : if (da.bus == NULL)
3519 : 0 : goto cleanup;
3520 : :
3521 : 0 : if (strcmp(rte_bus_name(da.bus), "pci") != 0)
3522 : 0 : goto cleanup;
3523 : :
3524 : 0 : if (rte_pci_addr_parse(da.name, &pci_addr) != 0)
3525 : 0 : goto cleanup;
3526 : :
3527 : 0 : rte_pci_device_name(&pci_addr, pci_buffer, buf_size);
3528 : 0 : pci_len = strlen(pci_buffer);
3529 : 0 : snprintf(pci_buffer + pci_len, buf_size - pci_len, ",%s", da.args);
3530 : : result = pci_buffer;
3531 : :
3532 : 0 : cleanup:
3533 : 0 : rte_devargs_reset(&da);
3534 : 0 : return result;
3535 : : }
3536 : :
3537 : : void
3538 : 0 : attach_port(char *identifier)
3539 : : {
3540 : : portid_t pi;
3541 : : struct rte_dev_iterator iterator;
3542 : : char *long_format, *long_identifier;
3543 : : size_t long_format_size;
3544 : :
3545 : : printf("Attaching a new port...\n");
3546 : :
3547 : 0 : if (identifier == NULL) {
3548 : 0 : fprintf(stderr, "Invalid parameters are specified\n");
3549 : 0 : return;
3550 : : }
3551 : 0 : long_format_size = strlen(identifier) + PCI_PRI_STR_SIZE;
3552 : 0 : long_format = alloca(long_format_size);
3553 : : if (long_format == NULL) {
3554 : : TESTPMD_LOG(ERR, "Failed to attach port %s - allocation failure\n", identifier);
3555 : : return;
3556 : : }
3557 : :
3558 : : /* For PCI device convert to canonical format */
3559 : 0 : long_identifier = convert_pci_address_format(identifier, long_format, long_format_size);
3560 : 0 : if (long_identifier != NULL)
3561 : : identifier = long_identifier;
3562 : :
3563 : 0 : if (rte_dev_probe(identifier) < 0) {
3564 : 0 : TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier);
3565 : 0 : return;
3566 : : }
3567 : :
3568 : : /* first attach mode: event */
3569 : 0 : if (setup_on_probe_event) {
3570 : : /* new ports are detected on RTE_ETH_EVENT_NEW event */
3571 : 0 : for (pi = 0; pi < RTE_MAX_ETHPORTS; pi++)
3572 : 0 : if (ports[pi].port_status == RTE_PORT_HANDLING &&
3573 : 0 : ports[pi].need_setup != 0)
3574 : 0 : setup_attached_port(pi);
3575 : : return;
3576 : : }
3577 : :
3578 : : /* second attach mode: iterator */
3579 : 0 : RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) {
3580 : : /* setup ports matching the devargs used for probing */
3581 : 0 : if (port_is_forwarding(pi))
3582 : 0 : continue; /* port was already attached before */
3583 : 0 : setup_attached_port(pi);
3584 : : }
3585 : : }
3586 : :
3587 : : static void
3588 : 0 : setup_attached_port(portid_t pi)
3589 : : {
3590 : : unsigned int socket_id;
3591 : : int ret;
3592 : :
3593 : 0 : socket_id = (unsigned)rte_eth_dev_socket_id(pi);
3594 : : /* if socket_id is invalid, set to the first available socket. */
3595 : 0 : if (check_socket_id(socket_id) < 0)
3596 : 0 : socket_id = socket_ids[0];
3597 : : reconfig(pi, socket_id);
3598 : 0 : ret = rte_eth_promiscuous_enable(pi);
3599 : 0 : if (ret != 0)
3600 : 0 : fprintf(stderr,
3601 : : "Error during enabling promiscuous mode for port %u: %s - ignore\n",
3602 : : pi, rte_strerror(-ret));
3603 : :
3604 : 0 : ports_ids[nb_ports++] = pi;
3605 : 0 : fwd_ports_ids[nb_fwd_ports++] = pi;
3606 : 0 : nb_cfg_ports = nb_fwd_ports;
3607 : 0 : ports[pi].need_setup = 0;
3608 : 0 : ports[pi].port_status = RTE_PORT_STOPPED;
3609 : :
3610 : 0 : printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
3611 : : printf("Done\n");
3612 : 0 : }
3613 : :
3614 : : static void
3615 : 0 : detach_device(struct rte_device *dev)
3616 : : {
3617 : : portid_t sibling;
3618 : :
3619 : 0 : if (dev == NULL) {
3620 : 0 : fprintf(stderr, "Device already removed\n");
3621 : 0 : return;
3622 : : }
3623 : :
3624 : : printf("Removing a device...\n");
3625 : :
3626 : 0 : RTE_ETH_FOREACH_DEV_OF(sibling, dev) {
3627 : 0 : if (ports[sibling].port_status != RTE_PORT_CLOSED) {
3628 : 0 : if (ports[sibling].port_status != RTE_PORT_STOPPED) {
3629 : 0 : fprintf(stderr, "Port %u not stopped\n",
3630 : : sibling);
3631 : 0 : return;
3632 : : }
3633 : 0 : flush_port_owned_resources(sibling);
3634 : : }
3635 : : }
3636 : :
3637 : 0 : if (rte_dev_remove(dev) < 0) {
3638 : 0 : TESTPMD_LOG(ERR, "Failed to detach device %s\n", rte_dev_name(dev));
3639 : 0 : return;
3640 : : }
3641 : 0 : remove_invalid_ports();
3642 : :
3643 : : printf("Device is detached\n");
3644 : 0 : printf("Now total ports is %d\n", nb_ports);
3645 : : printf("Done\n");
3646 : : return;
3647 : : }
3648 : :
3649 : : void
3650 : 0 : detach_port_device(portid_t port_id)
3651 : : {
3652 : : int ret;
3653 : : struct rte_eth_dev_info dev_info;
3654 : :
3655 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
3656 : 0 : return;
3657 : :
3658 : 0 : if (ports[port_id].port_status != RTE_PORT_CLOSED) {
3659 : 0 : if (ports[port_id].port_status != RTE_PORT_STOPPED) {
3660 : 0 : fprintf(stderr, "Port not stopped\n");
3661 : 0 : return;
3662 : : }
3663 : 0 : fprintf(stderr, "Port was not closed\n");
3664 : : }
3665 : :
3666 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
3667 : 0 : if (ret != 0) {
3668 : 0 : TESTPMD_LOG(ERR,
3669 : : "Failed to get device info for port %d, not detaching\n",
3670 : : port_id);
3671 : 0 : return;
3672 : : }
3673 : 0 : detach_device(dev_info.device);
3674 : : }
3675 : :
3676 : : void
3677 : 0 : detach_devargs(char *identifier)
3678 : : {
3679 : : struct rte_dev_iterator iterator;
3680 : : struct rte_devargs da;
3681 : : portid_t port_id;
3682 : :
3683 : : printf("Removing a device...\n");
3684 : :
3685 : : memset(&da, 0, sizeof(da));
3686 : 0 : if (rte_devargs_parsef(&da, "%s", identifier)) {
3687 : 0 : fprintf(stderr, "cannot parse identifier\n");
3688 : 0 : return;
3689 : : }
3690 : :
3691 : 0 : RTE_ETH_FOREACH_MATCHING_DEV(port_id, identifier, &iterator) {
3692 : 0 : if (ports[port_id].port_status != RTE_PORT_CLOSED) {
3693 : 0 : if (ports[port_id].port_status != RTE_PORT_STOPPED) {
3694 : 0 : fprintf(stderr, "Port %u not stopped\n",
3695 : : port_id);
3696 : 0 : rte_eth_iterator_cleanup(&iterator);
3697 : 0 : rte_devargs_reset(&da);
3698 : 0 : return;
3699 : : }
3700 : 0 : flush_port_owned_resources(port_id);
3701 : : }
3702 : : }
3703 : :
3704 : 0 : if (rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name) != 0) {
3705 : 0 : TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
3706 : : da.name, rte_bus_name(da.bus));
3707 : 0 : rte_devargs_reset(&da);
3708 : 0 : return;
3709 : : }
3710 : :
3711 : 0 : remove_invalid_ports();
3712 : :
3713 : : printf("Device %s is detached\n", identifier);
3714 : 0 : printf("Now total ports is %d\n", nb_ports);
3715 : : printf("Done\n");
3716 : 0 : rte_devargs_reset(&da);
3717 : : }
3718 : :
3719 : : #ifndef RTE_EXEC_ENV_WINDOWS
3720 : :
3721 : : enum testpmd_req_type {
3722 : : TESTPMD_REQ_TYPE_EXIT,
3723 : : };
3724 : :
3725 : : struct testpmd_mp_req {
3726 : : enum testpmd_req_type t;
3727 : : };
3728 : :
3729 : : struct testpmd_mp_resp {
3730 : : int result;
3731 : : };
3732 : :
3733 : : #define TESTPMD_MP "mp_testpmd"
3734 : :
3735 : : /* Send reply to this peer when testpmd exits */
3736 : : static RTE_ATOMIC(const char *) primary_name;
3737 : :
3738 : : static void
3739 : 0 : reply_to_primary(const char *peer, int result)
3740 : : {
3741 : 0 : struct rte_mp_msg reply = { };
3742 : : struct testpmd_mp_resp *resp = (struct testpmd_mp_resp *) &reply.param;
3743 : :
3744 : : strlcpy(reply.name, TESTPMD_MP, RTE_MP_MAX_NAME_LEN);
3745 : 0 : reply.len_param = sizeof(*resp);
3746 : 0 : resp->result = result;
3747 : :
3748 : : printf("Replying %d to primary\n", result);
3749 : 0 : fflush(stdout);
3750 : :
3751 : 0 : if (rte_mp_reply(&reply, peer) < 0)
3752 : 0 : printf("Failed to send response to primary:%s", strerror(rte_errno));
3753 : 0 : }
3754 : :
3755 : : /* Primary process is exiting, stop secondary process */
3756 : : static void
3757 : 0 : pmd_notify_secondary(void)
3758 : : {
3759 : : struct testpmd_mp_req request = {
3760 : : .t = TESTPMD_REQ_TYPE_EXIT,
3761 : : };
3762 : 0 : struct rte_mp_msg mp_req = {
3763 : : .name = TESTPMD_MP,
3764 : : .len_param = sizeof(request),
3765 : : };
3766 : : struct rte_mp_reply reply;
3767 : 0 : struct timespec ts = {.tv_sec = 5, .tv_nsec = 0};
3768 : :
3769 : : printf("\nPrimary: Sending 'stop_req' request to secondary...\n");
3770 : 0 : fflush(stdout);
3771 : :
3772 : : memcpy(mp_req.param, &request, sizeof(request));
3773 : 0 : rte_mp_request_sync(&mp_req, &reply, &ts);
3774 : 0 : }
3775 : :
3776 : : static int
3777 : 0 : handle_testpmd_request(const struct rte_mp_msg *request, const void *peer)
3778 : : {
3779 : : const struct testpmd_mp_req *req = (const struct testpmd_mp_req *)request->param;
3780 : :
3781 : 0 : if (req->t == TESTPMD_REQ_TYPE_EXIT) {
3782 : : printf("\nReceived notification of primary exiting\n");
3783 : 0 : fflush(stdout);
3784 : :
3785 : : /* Response is sent after forwarding loop exits */
3786 : 0 : rte_atomic_store_explicit(&primary_name, peer, rte_memory_order_relaxed);
3787 : :
3788 : 0 : kill(getpid(), SIGINT);
3789 : : } else {
3790 : 0 : reply_to_primary(peer, -EINVAL);
3791 : : }
3792 : 0 : return 0;
3793 : : }
3794 : : #endif
3795 : :
3796 : : void
3797 : 0 : pmd_test_exit(void)
3798 : : {
3799 : : portid_t pt_id;
3800 : : unsigned int i;
3801 : : int ret;
3802 : :
3803 : 0 : if (test_done == 0)
3804 : 0 : stop_packet_forwarding();
3805 : :
3806 : : #ifndef RTE_EXEC_ENV_WINDOWS
3807 : : /* Tell secondary to exit */
3808 : 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3809 : 0 : pmd_notify_secondary();
3810 : :
3811 : 0 : for (i = 0 ; i < RTE_DIM(mempools) ; i++) {
3812 : 0 : if (mempools[i]) {
3813 : 0 : if (mp_alloc_type == MP_ALLOC_ANON)
3814 : 0 : rte_mempool_mem_iter(mempools[i], dma_unmap_cb,
3815 : : NULL);
3816 : : }
3817 : : }
3818 : : #endif
3819 : 0 : if (ports != NULL) {
3820 : 0 : no_link_check = 1;
3821 : 0 : RTE_ETH_FOREACH_DEV(pt_id) {
3822 : 0 : printf("\nStopping port %d...\n", pt_id);
3823 : 0 : fflush(stdout);
3824 : 0 : stop_port(pt_id);
3825 : : }
3826 : 0 : RTE_ETH_FOREACH_DEV(pt_id) {
3827 : 0 : printf("\nShutting down port %d...\n", pt_id);
3828 : 0 : fflush(stdout);
3829 : 0 : close_port(pt_id);
3830 : : }
3831 : : }
3832 : :
3833 : 0 : if (hot_plug) {
3834 : 0 : ret = rte_dev_event_monitor_stop();
3835 : 0 : if (ret) {
3836 : 0 : TESTPMD_LOG(ERR, "fail to stop device event monitor.");
3837 : 0 : return;
3838 : : }
3839 : :
3840 : 0 : ret = rte_dev_event_callback_unregister(NULL,
3841 : : dev_event_callback, NULL);
3842 : 0 : if (ret < 0) {
3843 : 0 : TESTPMD_LOG(ERR, "fail to unregister device event callback.\n");
3844 : 0 : return;
3845 : : }
3846 : :
3847 : 0 : ret = rte_dev_hotplug_handle_disable();
3848 : 0 : if (ret) {
3849 : 0 : TESTPMD_LOG(ERR, "fail to disable hotplug handling.\n");
3850 : 0 : return;
3851 : : }
3852 : : }
3853 : 0 : for (i = 0 ; i < RTE_DIM(mempools) ; i++) {
3854 : 0 : if (mempools[i])
3855 : : mempool_free_mp(mempools[i]);
3856 : : }
3857 : 0 : free(xstats_display);
3858 : :
3859 : : printf("\nBye...\n");
3860 : : }
3861 : :
3862 : : typedef void (*cmd_func_t)(void);
3863 : : struct pmd_test_command {
3864 : : const char *cmd_name;
3865 : : cmd_func_t cmd_func;
3866 : : };
3867 : :
3868 : : /* Check the link status of all ports in up to 9s, and print them finally */
3869 : : static void
3870 : 0 : check_all_ports_link_status(uint32_t port_mask)
3871 : : {
3872 : : #define CHECK_INTERVAL 100 /* 100ms */
3873 : : #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
3874 : : portid_t portid;
3875 : : uint8_t count, all_ports_up, print_flag = 0;
3876 : : struct rte_eth_link link;
3877 : : int ret;
3878 : : char link_status[RTE_ETH_LINK_MAX_STR_LEN];
3879 : :
3880 : : printf("Checking link statuses...\n");
3881 : 0 : fflush(stdout);
3882 : 0 : for (count = 0; count <= MAX_CHECK_TIME; count++) {
3883 : : all_ports_up = 1;
3884 : 0 : RTE_ETH_FOREACH_DEV(portid) {
3885 : 0 : if ((port_mask & (1 << portid)) == 0)
3886 : 0 : continue;
3887 : : memset(&link, 0, sizeof(link));
3888 : 0 : ret = rte_eth_link_get_nowait(portid, &link);
3889 : 0 : if (ret < 0) {
3890 : : all_ports_up = 0;
3891 : 0 : if (print_flag == 1)
3892 : 0 : fprintf(stderr,
3893 : : "Port %u link get failed: %s\n",
3894 : : portid, rte_strerror(-ret));
3895 : 0 : continue;
3896 : : }
3897 : : /* print link status if flag set */
3898 : 0 : if (print_flag == 1) {
3899 : 0 : rte_eth_link_to_str(link_status,
3900 : : sizeof(link_status), &link);
3901 : : printf("Port %d %s\n", portid, link_status);
3902 : 0 : continue;
3903 : : }
3904 : : /* clear all_ports_up flag if any link down */
3905 : 0 : if (link.link_status == RTE_ETH_LINK_DOWN) {
3906 : : all_ports_up = 0;
3907 : : break;
3908 : : }
3909 : : }
3910 : : /* after finally printing all link status, get out */
3911 : 0 : if (print_flag == 1)
3912 : : break;
3913 : :
3914 : 0 : if (all_ports_up == 0) {
3915 : 0 : fflush(stdout);
3916 : : rte_delay_ms(CHECK_INTERVAL);
3917 : : }
3918 : :
3919 : : /* set the print_flag if all ports up or timeout */
3920 : 0 : if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
3921 : : print_flag = 1;
3922 : : }
3923 : :
3924 : 0 : if (lsc_interrupt)
3925 : : break;
3926 : : }
3927 : 0 : }
3928 : :
3929 : : static void
3930 : 0 : rmv_port_callback(void *arg)
3931 : : {
3932 : : int need_to_start = 0;
3933 : 0 : int org_no_link_check = no_link_check;
3934 : 0 : portid_t port_id = (intptr_t)arg;
3935 : : struct rte_eth_dev_info dev_info;
3936 : : int ret;
3937 : :
3938 : 0 : RTE_ETH_VALID_PORTID_OR_RET(port_id);
3939 : :
3940 : 0 : if (!test_done && port_is_forwarding(port_id)) {
3941 : : need_to_start = 1;
3942 : 0 : stop_packet_forwarding();
3943 : : }
3944 : 0 : no_link_check = 1;
3945 : 0 : stop_port(port_id);
3946 : 0 : no_link_check = org_no_link_check;
3947 : :
3948 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
3949 : 0 : if (ret != 0)
3950 : 0 : TESTPMD_LOG(ERR,
3951 : : "Failed to get device info for port %d, not detaching\n",
3952 : : port_id);
3953 : : else {
3954 : 0 : struct rte_device *device = dev_info.device;
3955 : 0 : close_port(port_id);
3956 : 0 : detach_device(device); /* might be already removed or have more ports */
3957 : : }
3958 : 0 : if (need_to_start)
3959 : 0 : start_packet_forwarding(0);
3960 : : }
3961 : :
3962 : : /* This function is used by the interrupt thread */
3963 : : static int
3964 : 0 : eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
3965 : : void *ret_param)
3966 : : {
3967 : : RTE_SET_USED(param);
3968 : : RTE_SET_USED(ret_param);
3969 : :
3970 : 0 : if (type >= RTE_ETH_EVENT_MAX) {
3971 : 0 : fprintf(stderr,
3972 : : "\nPort %" PRIu16 ": %s called upon invalid event %d\n",
3973 : : port_id, __func__, type);
3974 : 0 : fflush(stderr);
3975 : 0 : } else if (event_print_mask & (UINT32_C(1) << type)) {
3976 : 0 : printf("\nPort %" PRIu16 ": %s event\n", port_id,
3977 : 0 : eth_event_desc[type]);
3978 : 0 : fflush(stdout);
3979 : : }
3980 : :
3981 : 0 : switch (type) {
3982 : 0 : case RTE_ETH_EVENT_NEW:
3983 : 0 : ports[port_id].need_setup = 1;
3984 : 0 : ports[port_id].port_status = RTE_PORT_HANDLING;
3985 : 0 : break;
3986 : 0 : case RTE_ETH_EVENT_INTR_RMV:
3987 : 0 : if (port_id_is_invalid(port_id, DISABLED_WARN))
3988 : : break;
3989 : 0 : if (rte_eal_alarm_set(100000,
3990 : 0 : rmv_port_callback, (void *)(intptr_t)port_id))
3991 : 0 : fprintf(stderr,
3992 : : "Could not set up deferred device removal\n");
3993 : : break;
3994 : 0 : case RTE_ETH_EVENT_DESTROY:
3995 : 0 : ports[port_id].port_status = RTE_PORT_CLOSED;
3996 : 0 : printf("Port %u is closed\n", port_id);
3997 : : break;
3998 : 0 : case RTE_ETH_EVENT_RX_AVAIL_THRESH: {
3999 : : uint16_t rxq_id;
4000 : : int ret;
4001 : :
4002 : : /* avail_thresh query API rewinds rxq_id, no need to check max RxQ num */
4003 : 0 : for (rxq_id = 0; ; rxq_id++) {
4004 : 0 : ret = rte_eth_rx_avail_thresh_query(port_id, &rxq_id,
4005 : : NULL);
4006 : 0 : if (ret <= 0)
4007 : : break;
4008 : 0 : printf("Received avail_thresh event, port: %u, rxq_id: %u\n",
4009 : : port_id, rxq_id);
4010 : :
4011 : : #ifdef RTE_NET_MLX5
4012 : 0 : mlx5_test_avail_thresh_event_handler(port_id, rxq_id);
4013 : : #endif
4014 : : }
4015 : : break;
4016 : : }
4017 : : default:
4018 : : break;
4019 : : }
4020 : 0 : return 0;
4021 : : }
4022 : :
4023 : : static int
4024 : 0 : register_eth_event_callback(void)
4025 : : {
4026 : : int ret;
4027 : : enum rte_eth_event_type event;
4028 : :
4029 : 0 : for (event = RTE_ETH_EVENT_UNKNOWN;
4030 : 0 : event < RTE_ETH_EVENT_MAX; event++) {
4031 : 0 : ret = rte_eth_dev_callback_register(RTE_ETH_ALL,
4032 : : event,
4033 : : eth_event_callback,
4034 : : NULL);
4035 : 0 : if (ret != 0) {
4036 : 0 : TESTPMD_LOG(ERR, "Failed to register callback for "
4037 : : "%s event\n", eth_event_desc[event]);
4038 : 0 : return -1;
4039 : : }
4040 : : }
4041 : :
4042 : : return 0;
4043 : : }
4044 : :
4045 : : static int
4046 : 0 : unregister_eth_event_callback(void)
4047 : : {
4048 : : int ret;
4049 : : enum rte_eth_event_type event;
4050 : :
4051 : 0 : for (event = RTE_ETH_EVENT_UNKNOWN;
4052 : 0 : event < RTE_ETH_EVENT_MAX; event++) {
4053 : 0 : ret = rte_eth_dev_callback_unregister(RTE_ETH_ALL,
4054 : : event,
4055 : : eth_event_callback,
4056 : : NULL);
4057 : 0 : if (ret != 0) {
4058 : 0 : TESTPMD_LOG(ERR, "Failed to unregister callback for "
4059 : : "%s event\n", eth_event_desc[event]);
4060 : 0 : return -1;
4061 : : }
4062 : : }
4063 : :
4064 : : return 0;
4065 : : }
4066 : :
4067 : : /* This function is used by the interrupt thread */
4068 : : static void
4069 : 0 : dev_event_callback(const char *device_name, enum rte_dev_event_type type,
4070 : : __rte_unused void *arg)
4071 : : {
4072 : : uint16_t port_id;
4073 : : int ret;
4074 : :
4075 : 0 : switch (type) {
4076 : 0 : case RTE_DEV_EVENT_REMOVE:
4077 : 0 : TESTPMD_LOG(INFO, "The device: %s has been removed!\n", device_name);
4078 : 0 : ret = rte_eth_dev_get_port_by_name(device_name, &port_id);
4079 : 0 : if (ret) {
4080 : 0 : TESTPMD_LOG(ERR,
4081 : : "Can not get port for device %s!\n", device_name);
4082 : 0 : return;
4083 : : }
4084 : : /*
4085 : : * Because the user's callback is invoked in eal interrupt
4086 : : * callback, the interrupt callback need to be finished before
4087 : : * it can be unregistered when detaching device. So finish
4088 : : * callback soon and use a deferred removal to detach device
4089 : : * is need. It is a workaround, once the device detaching be
4090 : : * moved into the eal in the future, the deferred removal could
4091 : : * be deleted.
4092 : : */
4093 : 0 : if (rte_eal_alarm_set(100000,
4094 : 0 : rmv_port_callback, (void *)(intptr_t)port_id))
4095 : 0 : TESTPMD_LOG(ERR, "Could not set up deferred device removal\n");
4096 : : break;
4097 : :
4098 : 0 : case RTE_DEV_EVENT_ADD:
4099 : 0 : TESTPMD_LOG(INFO, "The device: %s has been added!\n", device_name);
4100 : : /* TODO: After finish kernel driver binding,
4101 : : * begin to attach port.
4102 : : */
4103 : 0 : break;
4104 : :
4105 : : default:
4106 : : if (type >= RTE_DEV_EVENT_MAX)
4107 : 0 : TESTPMD_LOG(ERR, "%s called upon invalid event %d\n",
4108 : : __func__, type);
4109 : : break;
4110 : : }
4111 : : }
4112 : :
4113 : : static void
4114 : 0 : rxtx_port_config(portid_t pid)
4115 : : {
4116 : : uint16_t qid;
4117 : : uint64_t offloads;
4118 : 0 : struct rte_port *port = &ports[pid];
4119 : :
4120 : 0 : for (qid = 0; qid < nb_rxq; qid++) {
4121 : 0 : offloads = port->rxq[qid].conf.offloads;
4122 : 0 : port->rxq[qid].conf = port->dev_info.default_rxconf;
4123 : :
4124 : 0 : if (rxq_share > 0 &&
4125 : 0 : (port->dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)) {
4126 : : /* Non-zero share group to enable RxQ share. */
4127 : : uint16_t share_group;
4128 : :
4129 : 0 : if (assign_share_group(&port->dev_info, &share_group) == 0) {
4130 : 0 : port->rxq[qid].conf.share_group = share_group;
4131 : 0 : port->rxq[qid].conf.share_qid = qid; /* Equal mapping. */
4132 : : } else {
4133 : 0 : TESTPMD_LOG(INFO, "port %u: failed assigning share group\n", pid);
4134 : : }
4135 : : }
4136 : :
4137 : 0 : if (offloads != 0)
4138 : 0 : port->rxq[qid].conf.offloads = offloads;
4139 : :
4140 : : /* Check if any Rx parameters have been passed */
4141 : 0 : if (rx_pthresh != RTE_PMD_PARAM_UNSET)
4142 : 0 : port->rxq[qid].conf.rx_thresh.pthresh = rx_pthresh;
4143 : :
4144 : 0 : if (rx_hthresh != RTE_PMD_PARAM_UNSET)
4145 : 0 : port->rxq[qid].conf.rx_thresh.hthresh = rx_hthresh;
4146 : :
4147 : 0 : if (rx_wthresh != RTE_PMD_PARAM_UNSET)
4148 : 0 : port->rxq[qid].conf.rx_thresh.wthresh = rx_wthresh;
4149 : :
4150 : 0 : if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
4151 : 0 : port->rxq[qid].conf.rx_free_thresh = rx_free_thresh;
4152 : :
4153 : 0 : if (rx_drop_en != RTE_PMD_PARAM_UNSET)
4154 : 0 : port->rxq[qid].conf.rx_drop_en = rx_drop_en;
4155 : :
4156 : 0 : port->nb_rx_desc[qid] = nb_rxd;
4157 : : }
4158 : :
4159 : 0 : for (qid = 0; qid < nb_txq; qid++) {
4160 : 0 : offloads = port->txq[qid].conf.offloads;
4161 : 0 : port->txq[qid].conf = port->dev_info.default_txconf;
4162 : 0 : if (offloads != 0)
4163 : 0 : port->txq[qid].conf.offloads = offloads;
4164 : :
4165 : : /* Check if any Tx parameters have been passed */
4166 : 0 : if (tx_pthresh != RTE_PMD_PARAM_UNSET)
4167 : 0 : port->txq[qid].conf.tx_thresh.pthresh = tx_pthresh;
4168 : :
4169 : 0 : if (tx_hthresh != RTE_PMD_PARAM_UNSET)
4170 : 0 : port->txq[qid].conf.tx_thresh.hthresh = tx_hthresh;
4171 : :
4172 : 0 : if (tx_wthresh != RTE_PMD_PARAM_UNSET)
4173 : 0 : port->txq[qid].conf.tx_thresh.wthresh = tx_wthresh;
4174 : :
4175 : 0 : if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
4176 : 0 : port->txq[qid].conf.tx_rs_thresh = tx_rs_thresh;
4177 : :
4178 : 0 : if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
4179 : 0 : port->txq[qid].conf.tx_free_thresh = tx_free_thresh;
4180 : :
4181 : 0 : port->nb_tx_desc[qid] = nb_txd;
4182 : : }
4183 : 0 : }
4184 : :
4185 : : /*
4186 : : * Helper function to set MTU from frame size
4187 : : *
4188 : : * port->dev_info should be set before calling this function.
4189 : : *
4190 : : * return 0 on success, negative on error
4191 : : */
4192 : : int
4193 : 0 : update_mtu_from_frame_size(portid_t portid, uint32_t max_rx_pktlen)
4194 : : {
4195 : 0 : struct rte_port *port = &ports[portid];
4196 : : uint32_t eth_overhead;
4197 : : uint16_t mtu, new_mtu;
4198 : :
4199 : : eth_overhead = get_eth_overhead(&port->dev_info);
4200 : :
4201 : 0 : if (rte_eth_dev_get_mtu(portid, &mtu) != 0) {
4202 : : printf("Failed to get MTU for port %u\n", portid);
4203 : 0 : return -1;
4204 : : }
4205 : :
4206 : 0 : new_mtu = max_rx_pktlen - eth_overhead;
4207 : :
4208 : 0 : if (mtu == new_mtu)
4209 : : return 0;
4210 : :
4211 : 0 : if (eth_dev_set_mtu_mp(portid, new_mtu) != 0) {
4212 : 0 : fprintf(stderr,
4213 : : "Failed to set MTU to %u for port %u\n",
4214 : : new_mtu, portid);
4215 : 0 : return -1;
4216 : : }
4217 : :
4218 : 0 : port->dev_conf.rxmode.mtu = new_mtu;
4219 : :
4220 : 0 : return 0;
4221 : : }
4222 : :
4223 : : void
4224 : 0 : init_port_config(void)
4225 : : {
4226 : : portid_t pid;
4227 : : struct rte_port *port;
4228 : : int ret, i;
4229 : :
4230 : 0 : RTE_ETH_FOREACH_DEV(pid) {
4231 : 0 : port = &ports[pid];
4232 : :
4233 : 0 : ret = eth_dev_info_get_print_err(pid, &port->dev_info);
4234 : 0 : if (ret != 0)
4235 : : return;
4236 : :
4237 : 0 : if (nb_rxq > 1 || force_rss) {
4238 : 0 : port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
4239 : 0 : port->dev_conf.rx_adv_conf.rss_conf.rss_hf =
4240 : 0 : rss_hf & port->dev_info.flow_type_rss_offloads;
4241 : : } else {
4242 : 0 : port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
4243 : 0 : port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
4244 : : }
4245 : :
4246 : 0 : if (port->dcb_flag == 0) {
4247 : 0 : if (port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0) {
4248 : 0 : port->dev_conf.rxmode.mq_mode =
4249 : 0 : (enum rte_eth_rx_mq_mode)
4250 : 0 : (rx_mq_mode & RTE_ETH_MQ_RX_RSS);
4251 : : } else {
4252 : 0 : port->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
4253 : 0 : port->dev_conf.rxmode.offloads &=
4254 : : ~RTE_ETH_RX_OFFLOAD_RSS_HASH;
4255 : :
4256 : 0 : for (i = 0;
4257 : 0 : i < port->dev_info.nb_rx_queues;
4258 : 0 : i++)
4259 : 0 : port->rxq[i].conf.offloads &=
4260 : : ~RTE_ETH_RX_OFFLOAD_RSS_HASH;
4261 : : }
4262 : : }
4263 : :
4264 : 0 : rxtx_port_config(pid);
4265 : :
4266 : 0 : ret = eth_macaddr_get_print_err(pid, &port->eth_addr);
4267 : 0 : if (ret != 0)
4268 : : return;
4269 : :
4270 : 0 : if (lsc_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_LSC))
4271 : 0 : port->dev_conf.intr_conf.lsc = 1;
4272 : 0 : if (rmv_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_RMV))
4273 : 0 : port->dev_conf.intr_conf.rmv = 1;
4274 : : }
4275 : : }
4276 : :
4277 : 0 : void set_port_member_flag(portid_t member_pid)
4278 : : {
4279 : : struct rte_port *port;
4280 : :
4281 : 0 : port = &ports[member_pid];
4282 : 0 : port->member_flag = 1;
4283 : 0 : }
4284 : :
4285 : 0 : void clear_port_member_flag(portid_t member_pid)
4286 : : {
4287 : : struct rte_port *port;
4288 : :
4289 : 0 : port = &ports[member_pid];
4290 : 0 : port->member_flag = 0;
4291 : 0 : }
4292 : :
4293 : 0 : uint8_t port_is_bonding_member(portid_t member_pid)
4294 : : {
4295 : : struct rte_port *port;
4296 : : struct rte_eth_dev_info dev_info;
4297 : : int ret;
4298 : :
4299 : 0 : port = &ports[member_pid];
4300 : 0 : ret = eth_dev_info_get_print_err(member_pid, &dev_info);
4301 : 0 : if (ret != 0) {
4302 : 0 : TESTPMD_LOG(ERR,
4303 : : "Failed to get device info for port id %d,"
4304 : : "cannot determine if the port is a bonding member",
4305 : : member_pid);
4306 : 0 : return 0;
4307 : : }
4308 : :
4309 : 0 : if ((*dev_info.dev_flags & RTE_ETH_DEV_BONDING_MEMBER) || (port->member_flag == 1))
4310 : 0 : return 1;
4311 : : return 0;
4312 : : }
4313 : :
4314 : : const uint16_t vlan_tags[] = {
4315 : : 0, 1, 2, 3, 4, 5, 6, 7,
4316 : : 8, 9, 10, 11, 12, 13, 14, 15,
4317 : : 16, 17, 18, 19, 20, 21, 22, 23,
4318 : : 24, 25, 26, 27, 28, 29, 30, 31
4319 : : };
4320 : :
4321 : : static void
4322 : 0 : get_eth_dcb_conf(struct rte_eth_conf *eth_conf, enum dcb_mode_enable dcb_mode,
4323 : : enum rte_eth_nb_tcs num_tcs, uint8_t pfc_en,
4324 : : uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES], uint8_t prio_tc_en)
4325 : : {
4326 : : uint8_t dcb_tc_val, i;
4327 : :
4328 : : /*
4329 : : * Builds up the correct configuration for dcb+vt based on the vlan tags array
4330 : : * given above, and the number of traffic classes available for use.
4331 : : */
4332 : 0 : if (dcb_mode == DCB_VT_ENABLED) {
4333 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
4334 : : ð_conf->rx_adv_conf.vmdq_dcb_conf;
4335 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
4336 : : ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
4337 : :
4338 : : /* VMDQ+DCB RX and TX configurations */
4339 : 0 : vmdq_rx_conf->enable_default_pool = 0;
4340 : 0 : vmdq_rx_conf->default_pool = 0;
4341 : 0 : vmdq_rx_conf->nb_queue_pools =
4342 : 0 : (num_tcs == RTE_ETH_4_TCS ? RTE_ETH_32_POOLS : RTE_ETH_16_POOLS);
4343 : 0 : vmdq_tx_conf->nb_queue_pools =
4344 : : (num_tcs == RTE_ETH_4_TCS ? RTE_ETH_32_POOLS : RTE_ETH_16_POOLS);
4345 : :
4346 : 0 : vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
4347 : 0 : for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
4348 : 0 : vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
4349 : 0 : vmdq_rx_conf->pool_map[i].pools =
4350 : 0 : RTE_BIT64(i % vmdq_rx_conf->nb_queue_pools);
4351 : : }
4352 : 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4353 : 0 : dcb_tc_val = prio_tc_en ? prio_tc[i] : i % num_tcs;
4354 : 0 : vmdq_rx_conf->dcb_tc[i] = dcb_tc_val;
4355 : 0 : vmdq_tx_conf->dcb_tc[i] = dcb_tc_val;
4356 : : }
4357 : :
4358 : : /* set DCB mode of RX and TX of multiple queues */
4359 : 0 : eth_conf->rxmode.mq_mode =
4360 : 0 : (enum rte_eth_rx_mq_mode)
4361 : 0 : (rx_mq_mode & RTE_ETH_MQ_RX_VMDQ_DCB);
4362 : 0 : eth_conf->txmode.mq_mode = RTE_ETH_MQ_TX_VMDQ_DCB;
4363 : : } else {
4364 : : struct rte_eth_dcb_rx_conf *rx_conf =
4365 : : ð_conf->rx_adv_conf.dcb_rx_conf;
4366 : : struct rte_eth_dcb_tx_conf *tx_conf =
4367 : : ð_conf->tx_adv_conf.dcb_tx_conf;
4368 : :
4369 : 0 : rx_conf->nb_tcs = num_tcs;
4370 : 0 : tx_conf->nb_tcs = num_tcs;
4371 : :
4372 : 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4373 : 0 : dcb_tc_val = prio_tc_en ? prio_tc[i] : i % num_tcs;
4374 : 0 : rx_conf->dcb_tc[i] = dcb_tc_val;
4375 : 0 : tx_conf->dcb_tc[i] = dcb_tc_val;
4376 : : }
4377 : :
4378 : 0 : eth_conf->rxmode.mq_mode =
4379 : 0 : (enum rte_eth_rx_mq_mode)
4380 : 0 : (rx_mq_mode & RTE_ETH_MQ_RX_DCB_RSS);
4381 : 0 : eth_conf->txmode.mq_mode = RTE_ETH_MQ_TX_DCB;
4382 : : }
4383 : :
4384 : 0 : if (pfc_en)
4385 : 0 : eth_conf->dcb_capability_en =
4386 : : RTE_ETH_DCB_PG_SUPPORT | RTE_ETH_DCB_PFC_SUPPORT;
4387 : : else
4388 : 0 : eth_conf->dcb_capability_en = RTE_ETH_DCB_PG_SUPPORT;
4389 : 0 : }
4390 : :
4391 : : static void
4392 : 0 : clear_eth_dcb_conf(portid_t pid, struct rte_eth_conf *eth_conf)
4393 : : {
4394 : : uint32_t i;
4395 : :
4396 : 0 : eth_conf->rxmode.mq_mode &= ~(RTE_ETH_MQ_RX_DCB | RTE_ETH_MQ_RX_VMDQ_DCB);
4397 : 0 : eth_conf->txmode.mq_mode = RTE_ETH_MQ_TX_NONE;
4398 : 0 : eth_conf->dcb_capability_en = 0;
4399 : 0 : if (dcb_config) {
4400 : : /* Unset VLAN filter configuration if already config DCB. */
4401 : 0 : eth_conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4402 : 0 : for (i = 0; i < RTE_DIM(vlan_tags); i++)
4403 : 0 : rx_vft_set(pid, vlan_tags[i], 0);
4404 : : }
4405 : 0 : }
4406 : :
4407 : : int
4408 : 0 : init_port_dcb_config(portid_t pid,
4409 : : enum dcb_mode_enable dcb_mode,
4410 : : enum rte_eth_nb_tcs num_tcs,
4411 : : uint8_t pfc_en,
4412 : : uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES],
4413 : : uint8_t prio_tc_en,
4414 : : uint8_t keep_qnum)
4415 : : {
4416 : : struct rte_eth_conf port_conf;
4417 : : struct rte_port *rte_port;
4418 : : int retval;
4419 : : uint16_t i;
4420 : :
4421 : 0 : if (num_procs > 1) {
4422 : : printf("The multi-process feature doesn't support dcb.\n");
4423 : 0 : return -ENOTSUP;
4424 : : }
4425 : 0 : rte_port = &ports[pid];
4426 : :
4427 : : /* retain the original device configuration. */
4428 : 0 : memcpy(&port_conf, &rte_port->dev_conf, sizeof(struct rte_eth_conf));
4429 : :
4430 : 0 : if (num_tcs > 1) {
4431 : : /* set configuration of DCB in vt mode and DCB in non-vt mode */
4432 : 0 : get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en, prio_tc, prio_tc_en);
4433 : 0 : port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4434 : : /* remove RSS HASH offload for DCB in vt mode */
4435 : 0 : if (port_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_DCB) {
4436 : 0 : port_conf.rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_RSS_HASH;
4437 : 0 : for (i = 0; i < nb_rxq; i++)
4438 : 0 : rte_port->rxq[i].conf.offloads &=
4439 : : ~RTE_ETH_RX_OFFLOAD_RSS_HASH;
4440 : : }
4441 : : } else {
4442 : 0 : clear_eth_dcb_conf(pid, &port_conf);
4443 : : }
4444 : :
4445 : : /* re-configure the device . */
4446 : 0 : retval = rte_eth_dev_configure(pid, nb_rxq, nb_rxq, &port_conf);
4447 : 0 : if (retval < 0)
4448 : : return retval;
4449 : :
4450 : 0 : retval = eth_dev_info_get_print_err(pid, &rte_port->dev_info);
4451 : 0 : if (retval != 0)
4452 : : return retval;
4453 : :
4454 : : /* If dev_info.vmdq_pool_base is greater than 0,
4455 : : * the queue id of vmdq pools is started after pf queues.
4456 : : */
4457 : 0 : if (num_tcs > 1 &&
4458 : 0 : dcb_mode == DCB_VT_ENABLED &&
4459 : 0 : rte_port->dev_info.vmdq_pool_base > 0) {
4460 : 0 : fprintf(stderr,
4461 : : "VMDQ_DCB multi-queue mode is nonsensical for port %d.\n",
4462 : : pid);
4463 : 0 : return -1;
4464 : : }
4465 : :
4466 : 0 : if (num_tcs > 1 && keep_qnum == 0) {
4467 : : /* Assume the ports in testpmd have the same dcb capability
4468 : : * and has the same number of rxq and txq in dcb mode
4469 : : */
4470 : 0 : if (dcb_mode == DCB_VT_ENABLED) {
4471 : 0 : if (rte_port->dev_info.max_vfs > 0) {
4472 : 0 : nb_rxq = rte_port->dev_info.nb_rx_queues;
4473 : 0 : nb_txq = rte_port->dev_info.nb_tx_queues;
4474 : : } else {
4475 : 0 : nb_rxq = rte_port->dev_info.max_rx_queues;
4476 : 0 : nb_txq = rte_port->dev_info.max_tx_queues;
4477 : : }
4478 : : } else {
4479 : : /*if vt is disabled, use all pf queues */
4480 : 0 : if (rte_port->dev_info.vmdq_pool_base == 0) {
4481 : 0 : nb_rxq = rte_port->dev_info.max_rx_queues;
4482 : 0 : nb_txq = rte_port->dev_info.max_tx_queues;
4483 : : } else {
4484 : 0 : nb_rxq = (queueid_t)num_tcs;
4485 : 0 : nb_txq = (queueid_t)num_tcs;
4486 : : }
4487 : : }
4488 : : }
4489 : 0 : rx_free_thresh = 64;
4490 : :
4491 : : memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
4492 : :
4493 : 0 : rxtx_port_config(pid);
4494 : 0 : if (num_tcs > 1) {
4495 : : /* VLAN filter */
4496 : 0 : rte_port->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4497 : 0 : for (i = 0; i < RTE_DIM(vlan_tags); i++)
4498 : 0 : rx_vft_set(pid, vlan_tags[i], 1);
4499 : : }
4500 : :
4501 : 0 : retval = eth_macaddr_get_print_err(pid, &rte_port->eth_addr);
4502 : 0 : if (retval != 0)
4503 : : return retval;
4504 : :
4505 : 0 : rte_port->dcb_flag = num_tcs > 1 ? 1 : 0;
4506 : :
4507 : : /* Enter DCB configuration status */
4508 : 0 : dcb_config = num_tcs > 1 ? 1 : 0;
4509 : :
4510 : 0 : return 0;
4511 : : }
4512 : :
4513 : : static void
4514 : 0 : init_port(void)
4515 : : {
4516 : : int i;
4517 : :
4518 : : /* Configuration of Ethernet ports. */
4519 : 0 : ports = rte_zmalloc("testpmd: ports",
4520 : : sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
4521 : : RTE_CACHE_LINE_SIZE);
4522 : 0 : if (ports == NULL) {
4523 : 0 : rte_exit(EXIT_FAILURE,
4524 : : "rte_zmalloc(%d struct rte_port) failed\n",
4525 : : RTE_MAX_ETHPORTS);
4526 : : }
4527 : 0 : for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
4528 : 0 : ports[i].fwd_mac_swap = 1;
4529 : 0 : ports[i].xstats_info.allocated = false;
4530 : 0 : LIST_INIT(&ports[i].flow_tunnel_list);
4531 : : }
4532 : : /* Initialize ports NUMA structures */
4533 : : memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
4534 : : memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
4535 : : memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
4536 : 0 : }
4537 : :
4538 : : static void
4539 : 0 : print_stats(void)
4540 : : {
4541 : : uint8_t i;
4542 : 0 : const char clr[] = { 27, '[', '2', 'J', '\0' };
4543 : 0 : const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
4544 : :
4545 : : /* Clear screen and move to top left */
4546 : : printf("%s%s", clr, top_left);
4547 : :
4548 : : printf("\nPort statistics ====================================");
4549 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
4550 : 0 : nic_stats_display(fwd_ports_ids[i]);
4551 : :
4552 : 0 : fflush(stdout);
4553 : 0 : }
4554 : :
4555 : : static void
4556 : 0 : signal_handler(int signum __rte_unused)
4557 : : {
4558 : 0 : f_quit = 1;
4559 : 0 : prompt_exit();
4560 : 0 : }
4561 : :
4562 : : #ifndef RTE_EXEC_ENV_WINDOWS
4563 : : /* Alarm signal handler, used to check that primary process */
4564 : : static void
4565 : 0 : monitor_primary(void *arg __rte_unused)
4566 : : {
4567 : 0 : if (rte_eal_primary_proc_alive(NULL)) {
4568 : 0 : rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
4569 : : } else {
4570 : : /*
4571 : : * If primary process exits, then all the device information
4572 : : * is no longer valid. Calling any cleanup code is going to
4573 : : * run into use after free.
4574 : : */
4575 : 0 : fprintf(stderr, "\nPrimary process is no longer active, exiting...\n");
4576 : 0 : exit(EXIT_FAILURE);
4577 : : }
4578 : 0 : }
4579 : :
4580 : : /* Setup handler to check when primary exits. */
4581 : : static int
4582 : : enable_primary_monitor(void)
4583 : : {
4584 : 0 : return rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
4585 : : }
4586 : :
4587 : : static void
4588 : : disable_primary_monitor(void)
4589 : : {
4590 : 0 : rte_eal_alarm_cancel(monitor_primary, NULL);
4591 : : }
4592 : : #endif
4593 : :
4594 : : int
4595 : 0 : main(int argc, char** argv)
4596 : : {
4597 : : int diag;
4598 : : portid_t port_id;
4599 : : uint16_t count;
4600 : : int ret;
4601 : :
4602 : : #ifdef RTE_EXEC_ENV_WINDOWS
4603 : : signal(SIGINT, signal_handler);
4604 : : signal(SIGTERM, signal_handler);
4605 : : #else
4606 : : /* Want read() not to be restarted on signal */
4607 : 0 : struct sigaction action = {
4608 : : .sa_handler = signal_handler,
4609 : : };
4610 : :
4611 : 0 : sigaction(SIGINT, &action, NULL);
4612 : 0 : sigaction(SIGTERM, &action, NULL);
4613 : : #endif
4614 : :
4615 : 0 : testpmd_logtype = rte_log_register("testpmd");
4616 : 0 : if (testpmd_logtype < 0)
4617 : 0 : rte_exit(EXIT_FAILURE, "Cannot register log type");
4618 : 0 : rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
4619 : :
4620 : 0 : diag = rte_eal_init(argc, argv);
4621 : 0 : if (diag < 0)
4622 : 0 : rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
4623 : : rte_strerror(rte_errno));
4624 : :
4625 : : #ifndef RTE_EXEC_ENV_WINDOWS
4626 : 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
4627 : 0 : if (enable_primary_monitor() < 0)
4628 : 0 : rte_exit(EXIT_FAILURE, "Cannot setup primary monitor");
4629 : 0 : if (rte_mp_action_register(TESTPMD_MP, handle_testpmd_request) < 0)
4630 : 0 : rte_exit(EXIT_FAILURE, "Failed to register message action\n");
4631 : : }
4632 : : #endif
4633 : :
4634 : : /* allocate port structures, and init them */
4635 : 0 : init_port();
4636 : :
4637 : 0 : ret = register_eth_event_callback();
4638 : 0 : if (ret != 0)
4639 : 0 : rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
4640 : :
4641 : : #ifdef RTE_LIB_PDUMP
4642 : : /* initialize packet capture framework */
4643 : 0 : rte_pdump_init();
4644 : : #endif
4645 : :
4646 : : count = 0;
4647 : 0 : RTE_ETH_FOREACH_DEV(port_id) {
4648 : 0 : ports_ids[count] = port_id;
4649 : 0 : count++;
4650 : : }
4651 : 0 : nb_ports = (portid_t) count;
4652 : 0 : if (nb_ports == 0)
4653 : 0 : TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
4654 : :
4655 : 0 : set_def_fwd_config();
4656 : 0 : if (nb_lcores == 0)
4657 : 0 : rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"
4658 : : "Check the core mask argument\n");
4659 : :
4660 : : /* Bitrate/latency stats disabled by default */
4661 : : #ifdef RTE_LIB_BITRATESTATS
4662 : 0 : bitrate_enabled = 0;
4663 : : #endif
4664 : : #ifdef RTE_LIB_LATENCYSTATS
4665 : 0 : latencystats_enabled = 0;
4666 : : #endif
4667 : :
4668 : : /* on FreeBSD, mlockall() is disabled by default */
4669 : : #ifdef RTE_EXEC_ENV_FREEBSD
4670 : : do_mlockall = 0;
4671 : : #else
4672 : 0 : do_mlockall = 1;
4673 : : #endif
4674 : :
4675 : 0 : argc -= diag;
4676 : 0 : argv += diag;
4677 : 0 : if (argc > 1)
4678 : 0 : launch_args_parse(argc, argv);
4679 : :
4680 : : #ifndef RTE_EXEC_ENV_WINDOWS
4681 : 0 : if (do_mlockall && mlockall(MCL_CURRENT | MCL_FUTURE)) {
4682 : 0 : TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
4683 : : strerror(errno));
4684 : : }
4685 : : #endif
4686 : :
4687 : 0 : if (tx_first && interactive)
4688 : 0 : rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
4689 : : "interactive mode.\n");
4690 : :
4691 : 0 : if (tx_first && lsc_interrupt) {
4692 : 0 : fprintf(stderr,
4693 : : "Warning: lsc_interrupt needs to be off when using tx_first. Disabling.\n");
4694 : 0 : lsc_interrupt = 0;
4695 : : }
4696 : :
4697 : 0 : if (!nb_rxq && !nb_txq)
4698 : 0 : rte_exit(EXIT_FAILURE, "Either rx or tx queues should be non-zero\n");
4699 : :
4700 : 0 : if (nb_rxq > 1 && nb_rxq > nb_txq)
4701 : 0 : fprintf(stderr,
4702 : : "Warning: nb_rxq=%d enables RSS configuration, but nb_txq=%d will prevent to fully test it.\n",
4703 : : nb_rxq, nb_txq);
4704 : :
4705 : 0 : init_config();
4706 : :
4707 : 0 : if (hot_plug) {
4708 : 0 : ret = rte_dev_hotplug_handle_enable();
4709 : 0 : if (ret) {
4710 : 0 : TESTPMD_LOG(ERR, "fail to enable hotplug handling.");
4711 : 0 : return -1;
4712 : : }
4713 : :
4714 : 0 : ret = rte_dev_event_monitor_start();
4715 : 0 : if (ret) {
4716 : 0 : TESTPMD_LOG(ERR, "fail to start device event monitoring.");
4717 : 0 : return -1;
4718 : : }
4719 : :
4720 : 0 : ret = rte_dev_event_callback_register(NULL, dev_event_callback, NULL);
4721 : 0 : if (ret) {
4722 : 0 : TESTPMD_LOG(ERR, "fail to register device event callback\n");
4723 : 0 : return -1;
4724 : : }
4725 : : }
4726 : :
4727 : 0 : if (!no_device_start && start_port(RTE_PORT_ALL) != 0) {
4728 : 0 : if (!interactive) {
4729 : 0 : rte_eal_cleanup();
4730 : 0 : rte_exit(EXIT_FAILURE, "Start ports failed\n");
4731 : : }
4732 : 0 : fprintf(stderr, "Start ports failed\n");
4733 : : }
4734 : :
4735 : : /* set all ports to promiscuous mode by default */
4736 : 0 : RTE_ETH_FOREACH_DEV(port_id) {
4737 : 0 : ret = rte_eth_promiscuous_enable(port_id);
4738 : 0 : if (ret != 0)
4739 : 0 : fprintf(stderr,
4740 : : "Error during enabling promiscuous mode for port %u: %s - ignore\n",
4741 : : port_id, rte_strerror(-ret));
4742 : : }
4743 : :
4744 : : #ifdef RTE_LIB_METRICS
4745 : : /* Init metrics library */
4746 : 0 : rte_metrics_init(SOCKET_ID_ANY);
4747 : : #endif
4748 : :
4749 : : #ifdef RTE_LIB_LATENCYSTATS
4750 : 0 : if (latencystats_enabled != 0) {
4751 : 0 : ret = rte_latencystats_init(1, NULL);
4752 : 0 : if (ret)
4753 : 0 : fprintf(stderr,
4754 : : "Warning: latencystats init() returned error %d\n",
4755 : : ret);
4756 : 0 : fprintf(stderr, "Latencystats running on lcore %d\n",
4757 : : latencystats_lcore_id);
4758 : : }
4759 : : #endif
4760 : :
4761 : : /* Setup bitrate stats */
4762 : : #ifdef RTE_LIB_BITRATESTATS
4763 : 0 : if (bitrate_enabled != 0) {
4764 : 0 : bitrate_data = rte_stats_bitrate_create();
4765 : 0 : if (bitrate_data == NULL)
4766 : 0 : rte_exit(EXIT_FAILURE,
4767 : : "Could not allocate bitrate data.\n");
4768 : 0 : rte_stats_bitrate_reg(bitrate_data);
4769 : : }
4770 : : #endif
4771 : :
4772 : 0 : if (record_core_cycles)
4773 : 0 : rte_lcore_register_usage_cb(lcore_usage_callback);
4774 : :
4775 : 0 : if (init_cmdline() != 0)
4776 : 0 : rte_exit(EXIT_FAILURE,
4777 : : "Could not initialise cmdline context.\n");
4778 : :
4779 : 0 : for (unsigned int i = 0; i < cmdline_file_count; i++) {
4780 : 0 : if (cmdline_read_from_file(cmdline_files[i].filename, cmdline_files[i].echo) != 0) {
4781 : 0 : fprintf(stderr, "Failed to process cmdline file: %s\n",
4782 : : cmdline_files[i].filename);
4783 : : break;
4784 : : }
4785 : : }
4786 : :
4787 : 0 : if (interactive == 1) {
4788 : 0 : if (auto_start) {
4789 : : printf("Start automatic packet forwarding\n");
4790 : 0 : start_packet_forwarding(0);
4791 : : }
4792 : 0 : prompt();
4793 : : } else {
4794 : : printf("No commandline core given, start packet forwarding\n");
4795 : 0 : start_packet_forwarding(tx_first);
4796 : 0 : if (stats_period != 0) {
4797 : : uint64_t prev_time = 0, cur_time, diff_time = 0;
4798 : : uint64_t timer_period;
4799 : :
4800 : : /* Convert to number of cycles */
4801 : 0 : timer_period = stats_period * rte_get_timer_hz();
4802 : :
4803 : 0 : while (f_quit == 0) {
4804 : : cur_time = rte_get_timer_cycles();
4805 : 0 : diff_time += cur_time - prev_time;
4806 : :
4807 : 0 : if (diff_time >= timer_period) {
4808 : 0 : print_stats();
4809 : : /* Reset the timer */
4810 : : diff_time = 0;
4811 : : }
4812 : : /* Sleep to avoid unnecessary checks */
4813 : : prev_time = cur_time;
4814 : 0 : rte_delay_us_sleep(US_PER_S);
4815 : : }
4816 : : } else {
4817 : : char c;
4818 : :
4819 : : printf("Press enter to exit\n");
4820 : 0 : while (f_quit == 0) {
4821 : : /* end-of-file or any character exits loop */
4822 : 0 : if (read(0, &c, 1) >= 0)
4823 : : break;
4824 : 0 : if (errno == EINTR)
4825 : 0 : continue;
4826 : 0 : rte_exit(EXIT_FAILURE, "Read failed: %s\n",
4827 : : strerror(errno));
4828 : : }
4829 : : }
4830 : : }
4831 : :
4832 : : #ifndef RTE_EXEC_ENV_WINDOWS
4833 : 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
4834 : : disable_primary_monitor();
4835 : 0 : rte_mp_action_unregister(TESTPMD_MP);
4836 : : }
4837 : : #endif
4838 : :
4839 : 0 : pmd_test_exit();
4840 : :
4841 : : #ifndef RTE_EXEC_ENV_WINDOWS
4842 : 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
4843 : 0 : const char *peer = rte_atomic_exchange_explicit(&primary_name, NULL,
4844 : : rte_memory_order_relaxed);
4845 : 0 : if (peer)
4846 : 0 : reply_to_primary(peer, 0);
4847 : : }
4848 : : #endif
4849 : :
4850 : : #ifdef RTE_LIB_PDUMP
4851 : : /* uninitialize packet capture framework */
4852 : 0 : rte_pdump_uninit();
4853 : : #endif
4854 : : #ifdef RTE_LIB_LATENCYSTATS
4855 : 0 : if (latencystats_enabled != 0)
4856 : 0 : rte_latencystats_uninit();
4857 : : #endif
4858 : :
4859 : 0 : ret = unregister_eth_event_callback();
4860 : 0 : if (ret != 0)
4861 : 0 : rte_exit(EXIT_FAILURE, "Cannot unregister for ethdev events");
4862 : :
4863 : :
4864 : 0 : ret = rte_eal_cleanup();
4865 : 0 : if (ret != 0)
4866 : 0 : rte_exit(EXIT_FAILURE,
4867 : : "EAL cleanup failed: %s\n", strerror(-ret));
4868 : :
4869 : : return EXIT_SUCCESS;
4870 : : }
|