Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation.
3 : : * Copyright 2013-2014 6WIND S.A.
4 : : */
5 : :
6 : : #include <ctype.h>
7 : : #include <stdarg.h>
8 : : #include <errno.h>
9 : : #include <stdbool.h>
10 : : #include <stdio.h>
11 : : #include <stdlib.h>
12 : : #include <string.h>
13 : : #include <stdint.h>
14 : : #include <inttypes.h>
15 : :
16 : : #include <sys/queue.h>
17 : : #include <sys/types.h>
18 : : #include <sys/stat.h>
19 : : #include <fcntl.h>
20 : : #include <unistd.h>
21 : :
22 : : #include <rte_common.h>
23 : : #include <rte_byteorder.h>
24 : : #include <rte_debug.h>
25 : : #include <rte_log.h>
26 : : #include <rte_memory.h>
27 : : #include <rte_memcpy.h>
28 : : #include <rte_memzone.h>
29 : : #include <rte_launch.h>
30 : : #include <rte_bus.h>
31 : : #include <rte_eal.h>
32 : : #include <rte_per_lcore.h>
33 : : #include <rte_lcore.h>
34 : : #include <rte_branch_prediction.h>
35 : : #include <rte_mempool.h>
36 : : #include <rte_mbuf.h>
37 : : #include <rte_interrupts.h>
38 : : #include <rte_ether.h>
39 : : #include <rte_ethdev.h>
40 : : #include <rte_string_fns.h>
41 : : #include <rte_cycles.h>
42 : : #include <rte_flow.h>
43 : : #include <rte_mtr.h>
44 : : #include <rte_errno.h>
45 : : #ifdef RTE_NET_IXGBE
46 : : #include <rte_pmd_ixgbe.h>
47 : : #endif
48 : : #ifdef RTE_NET_I40E
49 : : #include <rte_pmd_i40e.h>
50 : : #endif
51 : : #ifdef RTE_NET_BNXT
52 : : #include <rte_pmd_bnxt.h>
53 : : #endif
54 : : #ifdef RTE_LIB_GRO
55 : : #include <rte_gro.h>
56 : : #endif
57 : : #include <rte_hexdump.h>
58 : :
59 : : #include "testpmd.h"
60 : : #include "cmdline_mtr.h"
61 : :
62 : : #define ETHDEV_FWVERS_LEN 32
63 : :
64 : : #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
65 : : #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
66 : : #else
67 : : #define CLOCK_TYPE_ID CLOCK_MONOTONIC
68 : : #endif
69 : :
70 : : #define NS_PER_SEC 1E9
71 : :
72 : : static const struct {
73 : : enum tx_pkt_split split;
74 : : const char *name;
75 : : } tx_split_name[] = {
76 : : {
77 : : .split = TX_PKT_SPLIT_OFF,
78 : : .name = "off",
79 : : },
80 : : {
81 : : .split = TX_PKT_SPLIT_ON,
82 : : .name = "on",
83 : : },
84 : : {
85 : : .split = TX_PKT_SPLIT_RND,
86 : : .name = "rand",
87 : : },
88 : : };
89 : :
90 : : const struct rss_type_info rss_type_table[] = {
91 : : /* Group types */
92 : : { "all", RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP |
93 : : RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP | RTE_ETH_RSS_L2_PAYLOAD |
94 : : RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP | RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP |
95 : : RTE_ETH_RSS_GTPU | RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_MPLS | RTE_ETH_RSS_L2TPV2 |
96 : : RTE_ETH_RSS_IB_BTH },
97 : : { "none", 0 },
98 : : { "ip", RTE_ETH_RSS_IP },
99 : : { "udp", RTE_ETH_RSS_UDP },
100 : : { "tcp", RTE_ETH_RSS_TCP },
101 : : { "sctp", RTE_ETH_RSS_SCTP },
102 : : { "tunnel", RTE_ETH_RSS_TUNNEL },
103 : : { "vlan", RTE_ETH_RSS_VLAN },
104 : :
105 : : /* Individual type */
106 : : { "ipv4", RTE_ETH_RSS_IPV4 },
107 : : { "ipv4-frag", RTE_ETH_RSS_FRAG_IPV4 },
108 : : { "ipv4-tcp", RTE_ETH_RSS_NONFRAG_IPV4_TCP },
109 : : { "ipv4-udp", RTE_ETH_RSS_NONFRAG_IPV4_UDP },
110 : : { "ipv4-sctp", RTE_ETH_RSS_NONFRAG_IPV4_SCTP },
111 : : { "ipv4-other", RTE_ETH_RSS_NONFRAG_IPV4_OTHER },
112 : : { "ipv6", RTE_ETH_RSS_IPV6 },
113 : : { "ipv6-frag", RTE_ETH_RSS_FRAG_IPV6 },
114 : : { "ipv6-tcp", RTE_ETH_RSS_NONFRAG_IPV6_TCP },
115 : : { "ipv6-udp", RTE_ETH_RSS_NONFRAG_IPV6_UDP },
116 : : { "ipv6-sctp", RTE_ETH_RSS_NONFRAG_IPV6_SCTP },
117 : : { "ipv6-other", RTE_ETH_RSS_NONFRAG_IPV6_OTHER },
118 : : { "l2-payload", RTE_ETH_RSS_L2_PAYLOAD },
119 : : { "ipv6-ex", RTE_ETH_RSS_IPV6_EX },
120 : : { "ipv6-tcp-ex", RTE_ETH_RSS_IPV6_TCP_EX },
121 : : { "ipv6-udp-ex", RTE_ETH_RSS_IPV6_UDP_EX },
122 : : { "port", RTE_ETH_RSS_PORT },
123 : : { "vxlan", RTE_ETH_RSS_VXLAN },
124 : : { "geneve", RTE_ETH_RSS_GENEVE },
125 : : { "nvgre", RTE_ETH_RSS_NVGRE },
126 : : { "gtpu", RTE_ETH_RSS_GTPU },
127 : : { "eth", RTE_ETH_RSS_ETH },
128 : : { "s-vlan", RTE_ETH_RSS_S_VLAN },
129 : : { "c-vlan", RTE_ETH_RSS_C_VLAN },
130 : : { "esp", RTE_ETH_RSS_ESP },
131 : : { "ah", RTE_ETH_RSS_AH },
132 : : { "l2tpv3", RTE_ETH_RSS_L2TPV3 },
133 : : { "pfcp", RTE_ETH_RSS_PFCP },
134 : : { "pppoe", RTE_ETH_RSS_PPPOE },
135 : : { "ecpri", RTE_ETH_RSS_ECPRI },
136 : : { "mpls", RTE_ETH_RSS_MPLS },
137 : : { "ipv4-chksum", RTE_ETH_RSS_IPV4_CHKSUM },
138 : : { "l4-chksum", RTE_ETH_RSS_L4_CHKSUM },
139 : : { "l2tpv2", RTE_ETH_RSS_L2TPV2 },
140 : : { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
141 : : { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
142 : : { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
143 : : { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
144 : : { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
145 : : { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
146 : : { "l2-dst-only", RTE_ETH_RSS_L2_DST_ONLY },
147 : : { "l2-src-only", RTE_ETH_RSS_L2_SRC_ONLY },
148 : : { "l4-dst-only", RTE_ETH_RSS_L4_DST_ONLY },
149 : : { "l4-src-only", RTE_ETH_RSS_L4_SRC_ONLY },
150 : : { "l3-dst-only", RTE_ETH_RSS_L3_DST_ONLY },
151 : : { "l3-src-only", RTE_ETH_RSS_L3_SRC_ONLY },
152 : : { "ipv6-flow-label", RTE_ETH_RSS_IPV6_FLOW_LABEL },
153 : : { "ib-bth", RTE_ETH_RSS_IB_BTH },
154 : : { NULL, 0},
155 : : };
156 : :
157 : : static const struct {
158 : : enum rte_eth_fec_mode mode;
159 : : const char *name;
160 : : } fec_mode_name[] = {
161 : : {
162 : : .mode = RTE_ETH_FEC_NOFEC,
163 : : .name = "off",
164 : : },
165 : : {
166 : : .mode = RTE_ETH_FEC_AUTO,
167 : : .name = "auto",
168 : : },
169 : : {
170 : : .mode = RTE_ETH_FEC_BASER,
171 : : .name = "baser",
172 : : },
173 : : {
174 : : .mode = RTE_ETH_FEC_RS,
175 : : .name = "rs",
176 : : },
177 : : {
178 : : .mode = RTE_ETH_FEC_LLRS,
179 : : .name = "llrs",
180 : : },
181 : : };
182 : :
183 : : static const struct {
184 : : char str[32];
185 : : uint16_t ftype;
186 : : } flowtype_str_table[] = {
187 : : {"raw", RTE_ETH_FLOW_RAW},
188 : : {"ipv4", RTE_ETH_FLOW_IPV4},
189 : : {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
190 : : {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
191 : : {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
192 : : {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
193 : : {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
194 : : {"ipv6", RTE_ETH_FLOW_IPV6},
195 : : {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
196 : : {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
197 : : {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
198 : : {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
199 : : {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
200 : : {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
201 : : {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
202 : : {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
203 : : {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
204 : : {"port", RTE_ETH_FLOW_PORT},
205 : : {"vxlan", RTE_ETH_FLOW_VXLAN},
206 : : {"geneve", RTE_ETH_FLOW_GENEVE},
207 : : {"nvgre", RTE_ETH_FLOW_NVGRE},
208 : : {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
209 : : {"gtpu", RTE_ETH_FLOW_GTPU},
210 : : };
211 : :
212 : : static void
213 : 0 : print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
214 : : {
215 : : char buf[RTE_ETHER_ADDR_FMT_SIZE];
216 : 0 : rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
217 : : printf("%s%s", name, buf);
218 : 0 : }
219 : :
220 : : static void
221 : 0 : nic_xstats_display_periodic(portid_t port_id)
222 : : {
223 : : struct xstat_display_info *xstats_info;
224 : : uint64_t *prev_values, *curr_values;
225 : : uint64_t diff_value, value_rate;
226 : : struct timespec cur_time;
227 : : uint64_t *ids_supp;
228 : : size_t ids_supp_sz;
229 : : uint64_t diff_ns;
230 : : unsigned int i;
231 : : int rc;
232 : :
233 : 0 : xstats_info = &ports[port_id].xstats_info;
234 : :
235 : 0 : ids_supp_sz = xstats_info->ids_supp_sz;
236 : 0 : if (ids_supp_sz == 0)
237 : 0 : return;
238 : :
239 : : printf("\n");
240 : :
241 : 0 : ids_supp = xstats_info->ids_supp;
242 : 0 : prev_values = xstats_info->prev_values;
243 : 0 : curr_values = xstats_info->curr_values;
244 : :
245 : 0 : rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
246 : : ids_supp_sz);
247 : 0 : if (rc != (int)ids_supp_sz) {
248 : 0 : fprintf(stderr,
249 : : "Failed to get values of %zu xstats for port %u - return code %d\n",
250 : : ids_supp_sz, port_id, rc);
251 : 0 : return;
252 : : }
253 : :
254 : : diff_ns = 0;
255 : 0 : if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
256 : : uint64_t ns;
257 : :
258 : 0 : ns = cur_time.tv_sec * NS_PER_SEC;
259 : 0 : ns += cur_time.tv_nsec;
260 : :
261 : 0 : if (xstats_info->prev_ns != 0)
262 : 0 : diff_ns = ns - xstats_info->prev_ns;
263 : 0 : xstats_info->prev_ns = ns;
264 : : }
265 : :
266 : : printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
267 : 0 : for (i = 0; i < ids_supp_sz; i++) {
268 : 0 : diff_value = (curr_values[i] > prev_values[i]) ?
269 : 0 : (curr_values[i] - prev_values[i]) : 0;
270 : 0 : prev_values[i] = curr_values[i];
271 : 0 : value_rate = diff_ns > 0 ?
272 : 0 : (double)diff_value / diff_ns * NS_PER_SEC : 0;
273 : :
274 : : printf(" %-25s%12"PRIu64" %15"PRIu64"\n",
275 : 0 : xstats_display[i].name, curr_values[i], value_rate);
276 : : }
277 : : }
278 : :
279 : : void
280 : 0 : nic_stats_display(portid_t port_id)
281 : : {
282 : : static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
283 : : static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
284 : : static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
285 : : static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
286 : : static uint64_t prev_ns[RTE_MAX_ETHPORTS];
287 : : struct timespec cur_time;
288 : : uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
289 : : diff_ns;
290 : : uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
291 : : struct rte_eth_stats stats;
292 : : static const char *nic_stats_border = "########################";
293 : : int ret;
294 : :
295 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
296 : 0 : print_valid_ports();
297 : 0 : return;
298 : : }
299 : 0 : ret = rte_eth_stats_get(port_id, &stats);
300 : 0 : if (ret != 0) {
301 : 0 : fprintf(stderr,
302 : : "%s: Error: failed to get stats (port %u): %d",
303 : : __func__, port_id, ret);
304 : 0 : return;
305 : : }
306 : 0 : printf("\n %s NIC statistics for port %-2d %s\n",
307 : : nic_stats_border, port_id, nic_stats_border);
308 : :
309 : 0 : printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
310 : : "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
311 : 0 : printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
312 : 0 : printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
313 : 0 : printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
314 : : "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
315 : :
316 : : diff_ns = 0;
317 : 0 : if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
318 : : uint64_t ns;
319 : :
320 : 0 : ns = cur_time.tv_sec * NS_PER_SEC;
321 : 0 : ns += cur_time.tv_nsec;
322 : :
323 : 0 : if (prev_ns[port_id] != 0)
324 : 0 : diff_ns = ns - prev_ns[port_id];
325 : 0 : prev_ns[port_id] = ns;
326 : : }
327 : :
328 : 0 : diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
329 : 0 : (stats.ipackets - prev_pkts_rx[port_id]) : 0;
330 : 0 : diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
331 : 0 : (stats.opackets - prev_pkts_tx[port_id]) : 0;
332 : 0 : prev_pkts_rx[port_id] = stats.ipackets;
333 : 0 : prev_pkts_tx[port_id] = stats.opackets;
334 : 0 : mpps_rx = diff_ns > 0 ?
335 : 0 : (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
336 : 0 : mpps_tx = diff_ns > 0 ?
337 : 0 : (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
338 : :
339 : 0 : diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
340 : 0 : (stats.ibytes - prev_bytes_rx[port_id]) : 0;
341 : 0 : diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
342 : 0 : (stats.obytes - prev_bytes_tx[port_id]) : 0;
343 : 0 : prev_bytes_rx[port_id] = stats.ibytes;
344 : 0 : prev_bytes_tx[port_id] = stats.obytes;
345 : 0 : mbps_rx = diff_ns > 0 ?
346 : 0 : (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
347 : 0 : mbps_tx = diff_ns > 0 ?
348 : 0 : (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
349 : :
350 : : printf("\n Throughput (since last show)\n");
351 : 0 : printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
352 : : PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
353 : : mpps_tx, mbps_tx * 8);
354 : :
355 : 0 : if (xstats_display_num > 0)
356 : 0 : nic_xstats_display_periodic(port_id);
357 : :
358 : 0 : printf(" %s############################%s\n",
359 : : nic_stats_border, nic_stats_border);
360 : : }
361 : :
362 : : void
363 : 0 : nic_stats_clear(portid_t port_id)
364 : : {
365 : : int ret;
366 : :
367 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
368 : 0 : print_valid_ports();
369 : 0 : return;
370 : : }
371 : :
372 : 0 : ret = rte_eth_stats_reset(port_id);
373 : 0 : if (ret != 0) {
374 : 0 : fprintf(stderr,
375 : : "%s: Error: failed to reset stats (port %u): %s",
376 : : __func__, port_id, strerror(-ret));
377 : 0 : return;
378 : : }
379 : :
380 : 0 : ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
381 : 0 : if (ret != 0) {
382 : : if (ret < 0)
383 : : ret = -ret;
384 : 0 : fprintf(stderr,
385 : : "%s: Error: failed to get stats (port %u): %s",
386 : : __func__, port_id, strerror(ret));
387 : 0 : return;
388 : : }
389 : : printf("\n NIC statistics for port %d cleared\n", port_id);
390 : : }
391 : :
392 : : void
393 : 0 : nic_xstats_display(portid_t port_id)
394 : : {
395 : : struct rte_eth_xstat *xstats;
396 : : int cnt_xstats, idx_xstat;
397 : : struct rte_eth_xstat_name *xstats_names;
398 : : int state;
399 : :
400 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
401 : 0 : print_valid_ports();
402 : 0 : return;
403 : : }
404 : : printf("###### NIC extended statistics for port %-2d\n", port_id);
405 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
406 : 0 : fprintf(stderr, "Error: Invalid port number %i\n", port_id);
407 : 0 : return;
408 : : }
409 : :
410 : : /* Get count */
411 : 0 : cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
412 : 0 : if (cnt_xstats < 0) {
413 : 0 : fprintf(stderr, "Error: Cannot get count of xstats\n");
414 : 0 : return;
415 : : }
416 : :
417 : : /* Get id-name lookup table */
418 : 0 : xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
419 : 0 : if (xstats_names == NULL) {
420 : 0 : fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
421 : 0 : return;
422 : : }
423 : 0 : if (cnt_xstats != rte_eth_xstats_get_names(
424 : : port_id, xstats_names, cnt_xstats)) {
425 : 0 : fprintf(stderr, "Error: Cannot get xstats lookup\n");
426 : 0 : free(xstats_names);
427 : 0 : return;
428 : : }
429 : :
430 : : /* Get stats themselves */
431 : 0 : xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
432 : 0 : if (xstats == NULL) {
433 : 0 : fprintf(stderr, "Cannot allocate memory for xstats\n");
434 : 0 : free(xstats_names);
435 : 0 : return;
436 : : }
437 : 0 : if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
438 : 0 : fprintf(stderr, "Error: Unable to get xstats\n");
439 : 0 : free(xstats_names);
440 : 0 : free(xstats);
441 : 0 : return;
442 : : }
443 : :
444 : : /* Display xstats */
445 : 0 : for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
446 : 0 : if (xstats_hide_zero && !xstats[idx_xstat].value)
447 : 0 : continue;
448 : 0 : if (xstats_hide_disabled) {
449 : 0 : state = rte_eth_xstats_query_state(port_id, idx_xstat);
450 : 0 : if (state == 0)
451 : 0 : continue;
452 : : }
453 : 0 : if (xstats_show_state) {
454 : 0 : char opt[3] = {'D', 'E', '-'};
455 : 0 : state = rte_eth_xstats_query_state(port_id, idx_xstat);
456 : 0 : printf("state: %c ", state < 0 ? opt[2] : opt[state]);
457 : : }
458 : :
459 : 0 : printf("%s: %"PRIu64"\n",
460 : 0 : xstats_names[idx_xstat].name,
461 : 0 : xstats[idx_xstat].value);
462 : : }
463 : 0 : free(xstats_names);
464 : 0 : free(xstats);
465 : : }
466 : :
467 : : void
468 : 0 : nic_xstats_clear(portid_t port_id)
469 : : {
470 : : int ret;
471 : :
472 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
473 : 0 : print_valid_ports();
474 : 0 : return;
475 : : }
476 : :
477 : 0 : ret = rte_eth_xstats_reset(port_id);
478 : 0 : if (ret != 0) {
479 : 0 : fprintf(stderr,
480 : : "%s: Error: failed to reset xstats (port %u): %s\n",
481 : : __func__, port_id, strerror(-ret));
482 : 0 : return;
483 : : }
484 : :
485 : 0 : ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
486 : 0 : if (ret != 0) {
487 : : if (ret < 0)
488 : : ret = -ret;
489 : 0 : fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
490 : : __func__, port_id, strerror(ret));
491 : 0 : return;
492 : : }
493 : : }
494 : :
495 : : static const char *
496 : : get_queue_state_name(uint8_t queue_state)
497 : : {
498 : 0 : if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
499 : : return "stopped";
500 : 0 : else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
501 : : return "started";
502 : 0 : else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
503 : : return "hairpin";
504 : : else
505 : 0 : return "unknown";
506 : : }
507 : :
508 : : void
509 : 0 : rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
510 : : {
511 : : struct rte_eth_burst_mode mode;
512 : : struct rte_eth_rxq_info qinfo;
513 : : int32_t rc;
514 : : static const char *info_border = "*********************";
515 : :
516 : 0 : rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
517 : 0 : if (rc != 0) {
518 : 0 : fprintf(stderr,
519 : : "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
520 : : port_id, queue_id, strerror(-rc), rc);
521 : 0 : return;
522 : : }
523 : :
524 : 0 : printf("\n%s Infos for port %-2u, RX queue %-2u %s",
525 : : info_border, port_id, queue_id, info_border);
526 : :
527 : 0 : printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
528 : 0 : printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
529 : 0 : printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
530 : 0 : printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
531 : 0 : printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
532 : 0 : printf("\nRX drop packets: %s",
533 : 0 : (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
534 : 0 : printf("\nRX deferred start: %s",
535 : 0 : (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
536 : 0 : printf("\nRX scattered packets: %s",
537 : 0 : (qinfo.scattered_rx != 0) ? "on" : "off");
538 : 0 : printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
539 : 0 : if (qinfo.rx_buf_size != 0)
540 : 0 : printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
541 : 0 : printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
542 : :
543 : 0 : if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
544 : 0 : printf("\nBurst mode: %s%s",
545 : : mode.info,
546 : 0 : mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
547 : : " (per queue)" : "");
548 : :
549 : : printf("\n");
550 : : }
551 : :
552 : : void
553 : 0 : tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
554 : : {
555 : : struct rte_eth_burst_mode mode;
556 : : struct rte_eth_txq_info qinfo;
557 : : int32_t rc;
558 : : static const char *info_border = "*********************";
559 : :
560 : 0 : rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
561 : 0 : if (rc != 0) {
562 : 0 : fprintf(stderr,
563 : : "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
564 : : port_id, queue_id, strerror(-rc), rc);
565 : 0 : return;
566 : : }
567 : :
568 : 0 : printf("\n%s Infos for port %-2u, TX queue %-2u %s",
569 : : info_border, port_id, queue_id, info_border);
570 : :
571 : 0 : printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
572 : 0 : printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
573 : 0 : printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
574 : 0 : printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
575 : 0 : printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
576 : 0 : printf("\nTX deferred start: %s",
577 : 0 : (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
578 : 0 : printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
579 : 0 : printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
580 : :
581 : 0 : if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
582 : 0 : printf("\nBurst mode: %s%s",
583 : : mode.info,
584 : 0 : mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
585 : : " (per queue)" : "");
586 : :
587 : : printf("\n");
588 : : }
589 : :
590 : 0 : static int bus_match_all(const struct rte_bus *bus, const void *data)
591 : : {
592 : : RTE_SET_USED(bus);
593 : : RTE_SET_USED(data);
594 : 0 : return 0;
595 : : }
596 : :
597 : : static void
598 : 0 : device_infos_display_speeds(uint32_t speed_capa)
599 : : {
600 : : printf("\n\tDevice speed capability:");
601 : 0 : if (speed_capa == RTE_ETH_LINK_SPEED_AUTONEG)
602 : : printf(" Autonegotiate (all speeds)");
603 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_FIXED)
604 : : printf(" Disable autonegotiate (fixed speed) ");
605 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_10M_HD)
606 : : printf(" 10 Mbps half-duplex ");
607 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_10M)
608 : : printf(" 10 Mbps full-duplex ");
609 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_100M_HD)
610 : : printf(" 100 Mbps half-duplex ");
611 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_100M)
612 : : printf(" 100 Mbps full-duplex ");
613 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_1G)
614 : : printf(" 1 Gbps ");
615 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_2_5G)
616 : : printf(" 2.5 Gbps ");
617 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_5G)
618 : : printf(" 5 Gbps ");
619 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_10G)
620 : : printf(" 10 Gbps ");
621 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_20G)
622 : : printf(" 20 Gbps ");
623 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_25G)
624 : : printf(" 25 Gbps ");
625 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_40G)
626 : : printf(" 40 Gbps ");
627 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_50G)
628 : : printf(" 50 Gbps ");
629 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_56G)
630 : : printf(" 56 Gbps ");
631 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_100G)
632 : : printf(" 100 Gbps ");
633 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_200G)
634 : : printf(" 200 Gbps ");
635 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_400G)
636 : : printf(" 400 Gbps ");
637 : 0 : if (speed_capa & RTE_ETH_LINK_SPEED_800G)
638 : : printf(" 800 Gbps ");
639 : 0 : }
640 : :
641 : : void
642 : 0 : device_infos_display(const char *identifier)
643 : : {
644 : : static const char *info_border = "*********************";
645 : : struct rte_bus *start = NULL, *next;
646 : : struct rte_dev_iterator dev_iter;
647 : : char name[RTE_ETH_NAME_MAX_LEN];
648 : : struct rte_ether_addr mac_addr;
649 : : struct rte_device *dev;
650 : : struct rte_devargs da;
651 : : portid_t port_id;
652 : : struct rte_eth_dev_info dev_info;
653 : : char devstr[128];
654 : :
655 : : memset(&da, 0, sizeof(da));
656 : 0 : if (!identifier)
657 : 0 : goto skip_parse;
658 : :
659 : 0 : if (rte_devargs_parsef(&da, "%s", identifier)) {
660 : 0 : fprintf(stderr, "cannot parse identifier\n");
661 : 0 : return;
662 : : }
663 : :
664 : 0 : skip_parse:
665 : 0 : while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
666 : :
667 : : start = next;
668 : 0 : if (identifier && da.bus != next)
669 : 0 : continue;
670 : :
671 : 0 : snprintf(devstr, sizeof(devstr), "bus=%s", rte_bus_name(next));
672 : 0 : RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
673 : :
674 : 0 : if (rte_dev_driver(dev) == NULL)
675 : 0 : continue;
676 : : /* Check for matching device if identifier is present */
677 : 0 : if (identifier &&
678 : 0 : strncmp(da.name, rte_dev_name(dev), strlen(rte_dev_name(dev))))
679 : 0 : continue;
680 : 0 : printf("\n%s Infos for device %s %s\n",
681 : : info_border, rte_dev_name(dev), info_border);
682 : 0 : printf("Bus name: %s", rte_bus_name(rte_dev_bus(dev)));
683 : 0 : printf("\nBus information: %s",
684 : 0 : rte_dev_bus_info(dev) ? rte_dev_bus_info(dev) : "");
685 : 0 : printf("\nDriver name: %s", rte_driver_name(rte_dev_driver(dev)));
686 : 0 : printf("\nDevargs: %s",
687 : 0 : rte_dev_devargs(dev) ? rte_dev_devargs(dev)->args : "");
688 : 0 : printf("\nConnect to socket: %d", rte_dev_numa_node(dev));
689 : : printf("\n");
690 : :
691 : : /* List ports with matching device name */
692 : 0 : RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
693 : 0 : printf("\n\tPort id: %-2d", port_id);
694 : 0 : if (eth_macaddr_get_print_err(port_id,
695 : : &mac_addr) == 0)
696 : 0 : print_ethaddr("\n\tMAC address: ",
697 : : &mac_addr);
698 : 0 : rte_eth_dev_get_name_by_port(port_id, name);
699 : : printf("\n\tDevice name: %s", name);
700 : 0 : if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
701 : 0 : device_infos_display_speeds(dev_info.speed_capa);
702 : : printf("\n");
703 : : }
704 : : }
705 : : };
706 : 0 : rte_devargs_reset(&da);
707 : : }
708 : :
709 : : static void
710 : 0 : print_dev_capabilities(uint64_t capabilities)
711 : : {
712 : : uint64_t single_capa;
713 : : int begin;
714 : : int end;
715 : : int bit;
716 : :
717 : 0 : if (capabilities == 0)
718 : : return;
719 : :
720 : : begin = rte_ctz64(capabilities);
721 : 0 : end = sizeof(capabilities) * CHAR_BIT - rte_clz64(capabilities);
722 : :
723 : 0 : single_capa = 1ULL << begin;
724 : 0 : for (bit = begin; bit < end; bit++) {
725 : 0 : if (capabilities & single_capa)
726 : 0 : printf(" %s",
727 : : rte_eth_dev_capability_name(single_capa));
728 : 0 : single_capa <<= 1;
729 : : }
730 : : }
731 : :
732 : : uint64_t
733 : 0 : str_to_rsstypes(const char *str)
734 : : {
735 : : uint16_t i;
736 : :
737 : 0 : for (i = 0; rss_type_table[i].str != NULL; i++) {
738 : 0 : if (strcmp(rss_type_table[i].str, str) == 0)
739 : 0 : return rss_type_table[i].rss_type;
740 : : }
741 : :
742 : : return 0;
743 : : }
744 : :
745 : : const char *
746 : 0 : rsstypes_to_str(uint64_t rss_type)
747 : : {
748 : : uint16_t i;
749 : :
750 : 0 : for (i = 0; rss_type_table[i].str != NULL; i++) {
751 : 0 : if (rss_type_table[i].rss_type == rss_type)
752 : 0 : return rss_type_table[i].str;
753 : : }
754 : :
755 : : return NULL;
756 : : }
757 : :
758 : : static void
759 : 0 : rss_offload_types_display(uint64_t offload_types, uint16_t char_num_per_line)
760 : : {
761 : : uint16_t user_defined_str_len;
762 : : uint16_t total_len = 0;
763 : : uint16_t str_len = 0;
764 : : uint64_t rss_offload;
765 : : uint16_t i;
766 : :
767 : 0 : for (i = 0; i < sizeof(offload_types) * CHAR_BIT; i++) {
768 : 0 : rss_offload = RTE_BIT64(i);
769 : 0 : if ((offload_types & rss_offload) != 0) {
770 : : const char *p = rsstypes_to_str(rss_offload);
771 : :
772 : 0 : user_defined_str_len =
773 : 0 : strlen("user-defined-") + (i / 10 + 1);
774 : 0 : str_len = p ? strlen(p) : user_defined_str_len;
775 : 0 : str_len += 2; /* add two spaces */
776 : 0 : if (total_len + str_len >= char_num_per_line) {
777 : : total_len = 0;
778 : : printf("\n");
779 : : }
780 : :
781 : 0 : if (p)
782 : : printf(" %s", p);
783 : : else
784 : : printf(" user-defined-%u", i);
785 : 0 : total_len += str_len;
786 : : }
787 : : }
788 : : printf("\n");
789 : 0 : }
790 : :
791 : : void
792 : 0 : port_infos_display(portid_t port_id)
793 : : {
794 : : struct rte_port *port;
795 : : struct rte_ether_addr mac_addr;
796 : : struct rte_eth_link link;
797 : : struct rte_eth_dev_info dev_info;
798 : : int vlan_offload;
799 : : struct rte_mempool * mp;
800 : : static const char *info_border = "*********************";
801 : : uint16_t mtu;
802 : : char name[RTE_ETH_NAME_MAX_LEN];
803 : : int ret;
804 : : char fw_version[ETHDEV_FWVERS_LEN];
805 : : uint32_t lanes;
806 : :
807 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
808 : 0 : print_valid_ports();
809 : 0 : return;
810 : : }
811 : 0 : port = &ports[port_id];
812 : 0 : ret = eth_link_get_nowait_print_err(port_id, &link);
813 : 0 : if (ret < 0)
814 : : return;
815 : :
816 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
817 : 0 : if (ret != 0)
818 : : return;
819 : :
820 : 0 : printf("\n%s Infos for port %-2d %s\n",
821 : : info_border, port_id, info_border);
822 : 0 : if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
823 : 0 : print_ethaddr("MAC address: ", &mac_addr);
824 : 0 : rte_eth_dev_get_name_by_port(port_id, name);
825 : : printf("\nDevice name: %s", name);
826 : 0 : printf("\nDriver name: %s", dev_info.driver_name);
827 : :
828 : 0 : if (rte_eth_dev_fw_version_get(port_id, fw_version,
829 : : ETHDEV_FWVERS_LEN) == 0)
830 : : printf("\nFirmware-version: %s", fw_version);
831 : : else
832 : : printf("\nFirmware-version: %s", "not available");
833 : :
834 : 0 : if (rte_dev_devargs(dev_info.device) && rte_dev_devargs(dev_info.device)->args)
835 : 0 : printf("\nDevargs: %s", rte_dev_devargs(dev_info.device)->args);
836 : 0 : printf("\nConnect to socket: %u", port->socket_id);
837 : :
838 : 0 : if (port_numa[port_id] != NUMA_NO_CONFIG) {
839 : 0 : mp = mbuf_pool_find(port_numa[port_id], 0);
840 : 0 : if (mp)
841 : 0 : printf("\nmemory allocation on the socket: %d",
842 : 0 : port_numa[port_id]);
843 : : } else
844 : 0 : printf("\nmemory allocation on the socket: %u",port->socket_id);
845 : :
846 : 0 : printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
847 : 0 : printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
848 : 0 : if (rte_eth_speed_lanes_get(port_id, &lanes) == 0)
849 : 0 : printf("Active Lanes: %d\n", lanes);
850 : 0 : printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
851 : : ("full-duplex") : ("half-duplex"));
852 : 0 : printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
853 : : ("On") : ("Off"));
854 : :
855 : 0 : if (!rte_eth_dev_get_mtu(port_id, &mtu))
856 : 0 : printf("MTU: %u\n", mtu);
857 : 0 : printf("Minimum MTU: %u\n", dev_info.min_mtu);
858 : 0 : printf("Maximum MTU: %u\n", dev_info.max_mtu);
859 : :
860 : 0 : printf("Promiscuous mode: %s\n",
861 : 0 : rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
862 : 0 : printf("Allmulticast mode: %s\n",
863 : 0 : rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
864 : : printf("Maximum number of MAC addresses: %u\n",
865 : 0 : (unsigned int)(port->dev_info.max_mac_addrs));
866 : : printf("Maximum number of MAC addresses of hash filtering: %u\n",
867 : 0 : (unsigned int)(port->dev_info.max_hash_mac_addrs));
868 : :
869 : 0 : vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
870 : 0 : if (vlan_offload >= 0){
871 : : printf("VLAN offload: \n");
872 : 0 : if (vlan_offload & RTE_ETH_VLAN_STRIP_OFFLOAD)
873 : : printf(" strip on, ");
874 : : else
875 : : printf(" strip off, ");
876 : :
877 : 0 : if (vlan_offload & RTE_ETH_VLAN_FILTER_OFFLOAD)
878 : : printf("filter on, ");
879 : : else
880 : : printf("filter off, ");
881 : :
882 : 0 : if (vlan_offload & RTE_ETH_VLAN_EXTEND_OFFLOAD)
883 : : printf("extend on, ");
884 : : else
885 : : printf("extend off, ");
886 : :
887 : 0 : if (vlan_offload & RTE_ETH_QINQ_STRIP_OFFLOAD)
888 : : printf("qinq strip on\n");
889 : : else
890 : : printf("qinq strip off\n");
891 : : }
892 : :
893 : 0 : if (dev_info.hash_key_size > 0)
894 : 0 : printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
895 : 0 : if (dev_info.reta_size > 0)
896 : 0 : printf("Redirection table size: %u\n", dev_info.reta_size);
897 : 0 : if (!dev_info.flow_type_rss_offloads)
898 : : printf("No RSS offload flow type is supported.\n");
899 : : else {
900 : : printf("Supported RSS offload flow types:\n");
901 : 0 : rss_offload_types_display(dev_info.flow_type_rss_offloads,
902 : : TESTPMD_RSS_TYPES_CHAR_NUM_PER_LINE);
903 : : }
904 : :
905 : 0 : printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
906 : 0 : if (dev_info.max_rx_bufsize != UINT32_MAX)
907 : : printf("Maximum size of RX buffer: %u\n", dev_info.max_rx_bufsize);
908 : 0 : printf("Maximum configurable length of RX packet: %u\n",
909 : : dev_info.max_rx_pktlen);
910 : 0 : printf("Maximum configurable size of LRO aggregated packet: %u\n",
911 : : dev_info.max_lro_pkt_size);
912 : 0 : if (dev_info.max_vfs)
913 : 0 : printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
914 : 0 : if (dev_info.max_vmdq_pools)
915 : 0 : printf("Maximum number of VMDq pools: %u\n",
916 : : dev_info.max_vmdq_pools);
917 : :
918 : 0 : printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
919 : 0 : printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
920 : 0 : printf("Max possible number of RXDs per queue: %hu\n",
921 : 0 : dev_info.rx_desc_lim.nb_max);
922 : 0 : printf("Min possible number of RXDs per queue: %hu\n",
923 : 0 : dev_info.rx_desc_lim.nb_min);
924 : 0 : printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
925 : :
926 : 0 : printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
927 : 0 : printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
928 : 0 : printf("Max possible number of TXDs per queue: %hu\n",
929 : 0 : dev_info.tx_desc_lim.nb_max);
930 : 0 : printf("Min possible number of TXDs per queue: %hu\n",
931 : 0 : dev_info.tx_desc_lim.nb_min);
932 : 0 : printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
933 : 0 : printf("Max segment number per packet: %hu\n",
934 : 0 : dev_info.tx_desc_lim.nb_seg_max);
935 : 0 : printf("Max segment number per MTU/TSO: %hu\n",
936 : 0 : dev_info.tx_desc_lim.nb_mtu_seg_max);
937 : :
938 : 0 : printf("Device capabilities: 0x%"PRIx64"(", dev_info.dev_capa);
939 : 0 : print_dev_capabilities(dev_info.dev_capa);
940 : : printf(" )\n");
941 : : /* Show switch info only if valid switch domain and port id is set */
942 : 0 : if (dev_info.switch_info.domain_id !=
943 : : RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
944 : 0 : if (dev_info.switch_info.name)
945 : : printf("Switch name: %s\n", dev_info.switch_info.name);
946 : :
947 : 0 : printf("Switch domain Id: %u\n",
948 : 0 : dev_info.switch_info.domain_id);
949 : 0 : printf("Switch Port Id: %u\n",
950 : 0 : dev_info.switch_info.port_id);
951 : 0 : if ((dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) != 0)
952 : 0 : printf("Switch Rx domain: %u\n",
953 : 0 : dev_info.switch_info.rx_domain);
954 : : }
955 : : printf("Device error handling mode: ");
956 : 0 : switch (dev_info.err_handle_mode) {
957 : : case RTE_ETH_ERROR_HANDLE_MODE_NONE:
958 : : printf("none\n");
959 : : break;
960 : : case RTE_ETH_ERROR_HANDLE_MODE_PASSIVE:
961 : : printf("passive\n");
962 : : break;
963 : : case RTE_ETH_ERROR_HANDLE_MODE_PROACTIVE:
964 : : printf("proactive\n");
965 : : break;
966 : : default:
967 : : printf("unknown\n");
968 : : break;
969 : : }
970 : : printf("Device private info:\n");
971 : 0 : ret = rte_eth_dev_priv_dump(port_id, stdout);
972 : 0 : if (ret == -ENOTSUP)
973 : : printf(" none\n");
974 : 0 : else if (ret < 0)
975 : 0 : fprintf(stderr, " Failed to dump private info with error (%d): %s\n",
976 : : ret, strerror(-ret));
977 : : }
978 : :
979 : : void
980 : 0 : port_summary_header_display(void)
981 : : {
982 : : uint16_t port_number;
983 : :
984 : 0 : port_number = rte_eth_dev_count_avail();
985 : 0 : printf("Number of available ports: %i\n", port_number);
986 : : printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
987 : : "Driver", "Status", "Link");
988 : 0 : }
989 : :
990 : : void
991 : 0 : port_summary_display(portid_t port_id)
992 : : {
993 : : struct rte_ether_addr mac_addr;
994 : : struct rte_eth_link link;
995 : : struct rte_eth_dev_info dev_info;
996 : : char name[RTE_ETH_NAME_MAX_LEN];
997 : : int ret;
998 : :
999 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
1000 : 0 : print_valid_ports();
1001 : 0 : return;
1002 : : }
1003 : :
1004 : 0 : ret = eth_link_get_nowait_print_err(port_id, &link);
1005 : 0 : if (ret < 0)
1006 : : return;
1007 : :
1008 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
1009 : 0 : if (ret != 0)
1010 : : return;
1011 : :
1012 : 0 : rte_eth_dev_get_name_by_port(port_id, name);
1013 : 0 : ret = eth_macaddr_get_print_err(port_id, &mac_addr);
1014 : 0 : if (ret != 0)
1015 : : return;
1016 : :
1017 : 0 : printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
1018 : 0 : port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
1019 : 0 : dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
1020 : : rte_eth_link_speed_to_str(link.link_speed));
1021 : : }
1022 : :
1023 : : void
1024 : 0 : port_eeprom_display(portid_t port_id)
1025 : : {
1026 : : struct rte_dev_eeprom_info einfo;
1027 : : int ret;
1028 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
1029 : 0 : print_valid_ports();
1030 : 0 : return;
1031 : : }
1032 : :
1033 : 0 : int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
1034 : 0 : if (len_eeprom < 0) {
1035 : 0 : switch (len_eeprom) {
1036 : 0 : case -ENODEV:
1037 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
1038 : : break;
1039 : 0 : case -ENOTSUP:
1040 : 0 : fprintf(stderr, "operation not supported by device\n");
1041 : : break;
1042 : 0 : case -EIO:
1043 : 0 : fprintf(stderr, "device is removed\n");
1044 : : break;
1045 : 0 : default:
1046 : 0 : fprintf(stderr, "Unable to get EEPROM: %d\n",
1047 : : len_eeprom);
1048 : : break;
1049 : : }
1050 : 0 : return;
1051 : : }
1052 : :
1053 : 0 : einfo.offset = 0;
1054 : 0 : einfo.length = len_eeprom;
1055 : 0 : einfo.data = calloc(1, len_eeprom);
1056 : 0 : if (!einfo.data) {
1057 : 0 : fprintf(stderr,
1058 : : "Allocation of port %u eeprom data failed\n",
1059 : : port_id);
1060 : 0 : return;
1061 : : }
1062 : :
1063 : 0 : ret = rte_eth_dev_get_eeprom(port_id, &einfo);
1064 : 0 : if (ret != 0) {
1065 : 0 : switch (ret) {
1066 : 0 : case -ENODEV:
1067 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
1068 : : break;
1069 : 0 : case -ENOTSUP:
1070 : 0 : fprintf(stderr, "operation not supported by device\n");
1071 : : break;
1072 : 0 : case -EIO:
1073 : 0 : fprintf(stderr, "device is removed\n");
1074 : : break;
1075 : 0 : default:
1076 : 0 : fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
1077 : : break;
1078 : : }
1079 : 0 : free(einfo.data);
1080 : 0 : return;
1081 : : }
1082 : 0 : rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1083 : : printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
1084 : 0 : free(einfo.data);
1085 : : }
1086 : :
1087 : : void
1088 : 0 : port_eeprom_set(portid_t port_id,
1089 : : uint32_t magic,
1090 : : uint32_t offset,
1091 : : uint32_t length,
1092 : : uint8_t *value)
1093 : : {
1094 : : struct rte_dev_eeprom_info einfo;
1095 : : int len_eeprom;
1096 : : int ret;
1097 : :
1098 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
1099 : 0 : print_valid_ports();
1100 : 0 : return;
1101 : : }
1102 : :
1103 : 0 : len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
1104 : 0 : if (len_eeprom < 0) {
1105 : 0 : fprintf(stderr, "Unable to get EEPROM length: %s\n",
1106 : : rte_strerror(-len_eeprom));
1107 : 0 : return;
1108 : : }
1109 : :
1110 : 0 : einfo.data = value;
1111 : 0 : einfo.magic = magic;
1112 : 0 : einfo.length = length;
1113 : 0 : einfo.offset = offset;
1114 : :
1115 : 0 : if (einfo.offset + einfo.length > (uint32_t)(len_eeprom)) {
1116 : 0 : fprintf(stderr, "offset and length exceed capabilities of EEPROM length: %d\n",
1117 : : len_eeprom);
1118 : 0 : return;
1119 : : }
1120 : :
1121 : 0 : ret = rte_eth_dev_set_eeprom(port_id, &einfo);
1122 : 0 : if (ret != 0)
1123 : 0 : fprintf(stderr, "Unable to set EEPROM: %s\n", rte_strerror(-ret));
1124 : : }
1125 : :
1126 : : void
1127 : 0 : port_module_eeprom_display(portid_t port_id)
1128 : : {
1129 : : struct rte_eth_dev_module_info minfo;
1130 : : struct rte_dev_eeprom_info einfo;
1131 : : int ret;
1132 : :
1133 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
1134 : 0 : print_valid_ports();
1135 : 0 : return;
1136 : : }
1137 : :
1138 : :
1139 : 0 : ret = rte_eth_dev_get_module_info(port_id, &minfo);
1140 : 0 : if (ret != 0) {
1141 : 0 : switch (ret) {
1142 : 0 : case -ENODEV:
1143 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
1144 : : break;
1145 : 0 : case -ENOTSUP:
1146 : 0 : fprintf(stderr, "operation not supported by device\n");
1147 : : break;
1148 : 0 : case -EIO:
1149 : 0 : fprintf(stderr, "device is removed\n");
1150 : : break;
1151 : 0 : default:
1152 : 0 : fprintf(stderr, "Unable to get module EEPROM: %d\n",
1153 : : ret);
1154 : : break;
1155 : : }
1156 : 0 : return;
1157 : : }
1158 : :
1159 : 0 : einfo.offset = 0;
1160 : 0 : einfo.length = minfo.eeprom_len;
1161 : 0 : einfo.data = calloc(1, minfo.eeprom_len);
1162 : 0 : if (!einfo.data) {
1163 : 0 : fprintf(stderr,
1164 : : "Allocation of port %u eeprom data failed\n",
1165 : : port_id);
1166 : 0 : return;
1167 : : }
1168 : :
1169 : 0 : ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
1170 : 0 : if (ret != 0) {
1171 : 0 : switch (ret) {
1172 : 0 : case -ENODEV:
1173 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
1174 : : break;
1175 : 0 : case -ENOTSUP:
1176 : 0 : fprintf(stderr, "operation not supported by device\n");
1177 : : break;
1178 : 0 : case -EIO:
1179 : 0 : fprintf(stderr, "device is removed\n");
1180 : : break;
1181 : 0 : default:
1182 : 0 : fprintf(stderr, "Unable to get module EEPROM: %d\n",
1183 : : ret);
1184 : : break;
1185 : : }
1186 : 0 : free(einfo.data);
1187 : 0 : return;
1188 : : }
1189 : :
1190 : 0 : rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1191 : 0 : printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
1192 : 0 : free(einfo.data);
1193 : : }
1194 : :
1195 : : int
1196 : 0 : port_id_is_invalid(portid_t port_id, enum print_warning warning)
1197 : : {
1198 : : uint16_t pid;
1199 : :
1200 : 0 : if (port_id == (portid_t)RTE_PORT_ALL)
1201 : : return 0;
1202 : :
1203 : 0 : RTE_ETH_FOREACH_DEV(pid)
1204 : 0 : if (port_id == pid)
1205 : : return 0;
1206 : :
1207 : 0 : if (warning == ENABLED_WARN)
1208 : 0 : fprintf(stderr, "Invalid port %d\n", port_id);
1209 : :
1210 : : return 1;
1211 : : }
1212 : :
1213 : 0 : void print_valid_ports(void)
1214 : : {
1215 : : portid_t pid;
1216 : :
1217 : : printf("The valid ports array is [");
1218 : 0 : RTE_ETH_FOREACH_DEV(pid) {
1219 : 0 : printf(" %d", pid);
1220 : : }
1221 : : printf(" ]\n");
1222 : 0 : }
1223 : :
1224 : : static int
1225 : : vlan_id_is_invalid(uint16_t vlan_id)
1226 : : {
1227 : 0 : if (vlan_id < 4096)
1228 : : return 0;
1229 : 0 : fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1230 : : return 1;
1231 : : }
1232 : :
1233 : : static uint32_t
1234 : : eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
1235 : : {
1236 : : uint32_t overhead_len;
1237 : :
1238 : 0 : if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
1239 : 0 : overhead_len = max_rx_pktlen - max_mtu;
1240 : : else
1241 : : overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1242 : :
1243 : : return overhead_len;
1244 : : }
1245 : :
1246 : : static int
1247 : 0 : eth_dev_validate_mtu(uint16_t port_id, uint16_t mtu)
1248 : : {
1249 : : struct rte_eth_dev_info dev_info;
1250 : : uint32_t overhead_len;
1251 : : uint32_t frame_size;
1252 : : int ret;
1253 : :
1254 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
1255 : 0 : if (ret != 0)
1256 : : return ret;
1257 : :
1258 : 0 : if (mtu < dev_info.min_mtu) {
1259 : 0 : fprintf(stderr,
1260 : : "MTU (%u) < device min MTU (%u) for port_id %u\n",
1261 : : mtu, dev_info.min_mtu, port_id);
1262 : 0 : return -EINVAL;
1263 : : }
1264 : 0 : if (mtu > dev_info.max_mtu) {
1265 : 0 : fprintf(stderr,
1266 : : "MTU (%u) > device max MTU (%u) for port_id %u\n",
1267 : : mtu, dev_info.max_mtu, port_id);
1268 : 0 : return -EINVAL;
1269 : : }
1270 : :
1271 : 0 : overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
1272 : : dev_info.max_mtu);
1273 : 0 : frame_size = mtu + overhead_len;
1274 : 0 : if (frame_size > dev_info.max_rx_pktlen) {
1275 : 0 : fprintf(stderr,
1276 : : "Frame size (%u) > device max frame size (%u) for port_id %u\n",
1277 : : frame_size, dev_info.max_rx_pktlen, port_id);
1278 : 0 : return -EINVAL;
1279 : : }
1280 : :
1281 : : return 0;
1282 : : }
1283 : :
1284 : : void
1285 : 0 : port_mtu_set(portid_t port_id, uint16_t mtu)
1286 : : {
1287 : 0 : struct rte_port *port = &ports[port_id];
1288 : : int diag;
1289 : :
1290 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
1291 : : return;
1292 : :
1293 : 0 : diag = eth_dev_validate_mtu(port_id, mtu);
1294 : 0 : if (diag != 0)
1295 : : return;
1296 : :
1297 : 0 : if (port->need_reconfig == 0) {
1298 : 0 : diag = rte_eth_dev_set_mtu(port_id, mtu);
1299 : 0 : if (diag != 0) {
1300 : 0 : fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1301 : 0 : return;
1302 : : }
1303 : : }
1304 : :
1305 : 0 : port->dev_conf.rxmode.mtu = mtu;
1306 : : }
1307 : :
1308 : : /* Generic flow management functions. */
1309 : :
1310 : : static struct port_flow_tunnel *
1311 : : port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1312 : : {
1313 : : struct port_flow_tunnel *flow_tunnel;
1314 : :
1315 : 0 : LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1316 : 0 : if (flow_tunnel->id == port_tunnel_id)
1317 : 0 : goto out;
1318 : : }
1319 : : flow_tunnel = NULL;
1320 : :
1321 : 0 : out:
1322 : : return flow_tunnel;
1323 : : }
1324 : :
1325 : : const char *
1326 : 0 : port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1327 : : {
1328 : : const char *type;
1329 : 0 : switch (tunnel->type) {
1330 : : default:
1331 : : type = "unknown";
1332 : : break;
1333 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
1334 : : type = "vxlan";
1335 : 0 : break;
1336 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
1337 : : type = "gre";
1338 : 0 : break;
1339 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
1340 : : type = "nvgre";
1341 : 0 : break;
1342 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
1343 : : type = "geneve";
1344 : 0 : break;
1345 : : }
1346 : :
1347 : 0 : return type;
1348 : : }
1349 : :
1350 : : struct port_flow_tunnel *
1351 : 0 : port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1352 : : {
1353 : 0 : struct rte_port *port = &ports[port_id];
1354 : : struct port_flow_tunnel *flow_tunnel;
1355 : :
1356 : 0 : LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1357 : 0 : if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1358 : 0 : goto out;
1359 : : }
1360 : : flow_tunnel = NULL;
1361 : :
1362 : 0 : out:
1363 : 0 : return flow_tunnel;
1364 : : }
1365 : :
1366 : 0 : void port_flow_tunnel_list(portid_t port_id)
1367 : : {
1368 : 0 : struct rte_port *port = &ports[port_id];
1369 : : struct port_flow_tunnel *flt;
1370 : :
1371 : 0 : LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1372 : 0 : printf("port %u tunnel #%u type=%s",
1373 : : port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1374 : 0 : if (flt->tunnel.tun_id)
1375 : : printf(" id=%" PRIu64, flt->tunnel.tun_id);
1376 : : printf("\n");
1377 : : }
1378 : 0 : }
1379 : :
1380 : 0 : void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1381 : : {
1382 : 0 : struct rte_port *port = &ports[port_id];
1383 : : struct port_flow_tunnel *flt;
1384 : :
1385 : 0 : LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1386 : 0 : if (flt->id == tunnel_id)
1387 : : break;
1388 : : }
1389 : 0 : if (flt) {
1390 : 0 : LIST_REMOVE(flt, chain);
1391 : 0 : free(flt);
1392 : 0 : printf("port %u: flow tunnel #%u destroyed\n",
1393 : : port_id, tunnel_id);
1394 : : }
1395 : 0 : }
1396 : :
1397 : 0 : void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1398 : : {
1399 : 0 : struct rte_port *port = &ports[port_id];
1400 : : enum rte_flow_item_type type;
1401 : : struct port_flow_tunnel *flt;
1402 : :
1403 : 0 : if (!strcmp(ops->type, "vxlan"))
1404 : : type = RTE_FLOW_ITEM_TYPE_VXLAN;
1405 : 0 : else if (!strcmp(ops->type, "gre"))
1406 : : type = RTE_FLOW_ITEM_TYPE_GRE;
1407 : 0 : else if (!strcmp(ops->type, "nvgre"))
1408 : : type = RTE_FLOW_ITEM_TYPE_NVGRE;
1409 : 0 : else if (!strcmp(ops->type, "geneve"))
1410 : : type = RTE_FLOW_ITEM_TYPE_GENEVE;
1411 : : else {
1412 : 0 : fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1413 : : ops->type);
1414 : 0 : return;
1415 : : }
1416 : 0 : LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1417 : 0 : if (flt->tunnel.type == type)
1418 : : break;
1419 : : }
1420 : 0 : if (!flt) {
1421 : 0 : flt = calloc(1, sizeof(*flt));
1422 : 0 : if (!flt) {
1423 : 0 : fprintf(stderr, "failed to allocate port flt object\n");
1424 : 0 : return;
1425 : : }
1426 : 0 : flt->tunnel.type = type;
1427 : 0 : flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1428 : 0 : LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1429 : 0 : LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1430 : : }
1431 : 0 : printf("port %d: flow tunnel #%u type %s\n",
1432 : : port_id, flt->id, ops->type);
1433 : : }
1434 : :
1435 : : /** Generate a port_flow entry from attributes/pattern/actions. */
1436 : : static struct port_flow *
1437 : 0 : port_flow_new(const struct rte_flow_attr *attr,
1438 : : const struct rte_flow_item *pattern,
1439 : : const struct rte_flow_action *actions,
1440 : : struct rte_flow_error *error)
1441 : : {
1442 : 0 : const struct rte_flow_conv_rule rule = {
1443 : : .attr_ro = attr,
1444 : : .pattern_ro = pattern,
1445 : : .actions_ro = actions,
1446 : : };
1447 : : struct port_flow *pf;
1448 : : int ret;
1449 : :
1450 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1451 : 0 : if (ret < 0)
1452 : : return NULL;
1453 : 0 : pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1454 : 0 : if (!pf) {
1455 : 0 : rte_flow_error_set
1456 : 0 : (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1457 : : "calloc() failed");
1458 : 0 : return NULL;
1459 : : }
1460 : 0 : if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1461 : : error) >= 0)
1462 : : return pf;
1463 : 0 : free(pf);
1464 : 0 : return NULL;
1465 : : }
1466 : :
1467 : : static struct port_flow *
1468 : : port_flow_locate(struct port_flow *flows_list, uint32_t flow_id)
1469 : : {
1470 : : struct port_flow *pf = flows_list;
1471 : :
1472 : 0 : while (pf) {
1473 : 0 : if (pf->id == flow_id)
1474 : : break;
1475 : 0 : pf = pf->next;
1476 : : }
1477 : : return pf;
1478 : : }
1479 : :
1480 : : /** Print a message out of a flow error. */
1481 : : static int
1482 : 0 : port_flow_complain(struct rte_flow_error *error)
1483 : : {
1484 : : static const char *const errstrlist[] = {
1485 : : [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1486 : : [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1487 : : [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1488 : : [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1489 : : [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1490 : : [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1491 : : [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1492 : : [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1493 : : [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1494 : : [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1495 : : [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1496 : : [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1497 : : [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1498 : : [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1499 : : [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1500 : : [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1501 : : [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1502 : : };
1503 : : const char *errstr;
1504 : : char buf[32];
1505 : 0 : int err = rte_errno;
1506 : :
1507 : 0 : if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1508 : 0 : !errstrlist[error->type])
1509 : : errstr = "unknown type";
1510 : : else
1511 : : errstr = errstrlist[error->type];
1512 : 0 : fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1513 : 0 : __func__, error->type, errstr,
1514 : 0 : error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1515 : : error->cause), buf) : "",
1516 : 0 : error->message ? error->message : "(no stated reason)",
1517 : : rte_strerror(err));
1518 : :
1519 : 0 : switch (error->type) {
1520 : 0 : case RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER:
1521 : 0 : fprintf(stderr, "The status suggests the use of \"transfer\" "
1522 : : "as the possible cause of the failure. Make "
1523 : : "sure that the flow in question and its "
1524 : : "indirect components (if any) are managed "
1525 : : "via \"transfer\" proxy port. Use command "
1526 : : "\"show port (port_id) flow transfer proxy\" "
1527 : : "to figure out the proxy port ID\n");
1528 : : break;
1529 : : default:
1530 : : break;
1531 : : }
1532 : :
1533 : 0 : return -err;
1534 : : }
1535 : :
1536 : : static void
1537 : 0 : rss_types_display(uint64_t rss_types, uint16_t char_num_per_line)
1538 : : {
1539 : : uint16_t total_len = 0;
1540 : : uint16_t str_len;
1541 : : uint16_t i;
1542 : :
1543 : 0 : if (rss_types == 0)
1544 : : return;
1545 : :
1546 : 0 : for (i = 0; rss_type_table[i].str; i++) {
1547 : 0 : if (rss_type_table[i].rss_type == 0)
1548 : 0 : continue;
1549 : :
1550 : 0 : if ((rss_types & rss_type_table[i].rss_type) ==
1551 : : rss_type_table[i].rss_type) {
1552 : : /* Contain two spaces */
1553 : 0 : str_len = strlen(rss_type_table[i].str) + 2;
1554 : 0 : if (total_len + str_len > char_num_per_line) {
1555 : : printf("\n");
1556 : : total_len = 0;
1557 : : }
1558 : : printf(" %s", rss_type_table[i].str);
1559 : 0 : total_len += str_len;
1560 : : }
1561 : : }
1562 : : printf("\n");
1563 : : }
1564 : :
1565 : : static void
1566 : 0 : rss_config_display(struct rte_flow_action_rss *rss_conf)
1567 : : {
1568 : : uint8_t i;
1569 : :
1570 : 0 : if (rss_conf == NULL) {
1571 : 0 : fprintf(stderr, "Invalid rule\n");
1572 : 0 : return;
1573 : : }
1574 : :
1575 : : printf("RSS:\n"
1576 : : " queues:");
1577 : 0 : if (rss_conf->queue_num == 0)
1578 : : printf(" none");
1579 : 0 : for (i = 0; i < rss_conf->queue_num; i++)
1580 : 0 : printf(" %d", rss_conf->queue[i]);
1581 : : printf("\n");
1582 : :
1583 : 0 : printf(" function: %s\n", rte_eth_dev_rss_algo_name(rss_conf->func));
1584 : :
1585 : : printf(" RSS key:\n");
1586 : 0 : if (rss_conf->key_len == 0) {
1587 : : printf(" none");
1588 : : } else {
1589 : : printf(" key_len: %u\n", rss_conf->key_len);
1590 : : printf(" key: ");
1591 : 0 : if (rss_conf->key == NULL) {
1592 : : printf("none");
1593 : : } else {
1594 : 0 : for (i = 0; i < rss_conf->key_len; i++)
1595 : 0 : printf("%02X", rss_conf->key[i]);
1596 : : }
1597 : : }
1598 : : printf("\n");
1599 : :
1600 : : printf(" types:\n");
1601 : 0 : if (rss_conf->types == 0) {
1602 : : printf(" none\n");
1603 : 0 : return;
1604 : : }
1605 : 0 : rss_types_display(rss_conf->types, TESTPMD_RSS_TYPES_CHAR_NUM_PER_LINE);
1606 : : }
1607 : :
1608 : : static struct port_indirect_action *
1609 : 0 : action_get_by_id(portid_t port_id, uint32_t id)
1610 : : {
1611 : : struct rte_port *port;
1612 : : struct port_indirect_action **ppia;
1613 : : struct port_indirect_action *pia = NULL;
1614 : :
1615 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1616 : : port_id == (portid_t)RTE_PORT_ALL)
1617 : : return NULL;
1618 : 0 : port = &ports[port_id];
1619 : 0 : ppia = &port->actions_list;
1620 : 0 : while (*ppia) {
1621 : 0 : if ((*ppia)->id == id) {
1622 : : pia = *ppia;
1623 : : break;
1624 : : }
1625 : 0 : ppia = &(*ppia)->next;
1626 : : }
1627 : 0 : if (!pia)
1628 : 0 : fprintf(stderr,
1629 : : "Failed to find indirect action #%u on port %u\n",
1630 : : id, port_id);
1631 : : return pia;
1632 : : }
1633 : :
1634 : : static int
1635 : 0 : action_alloc(portid_t port_id, uint32_t id,
1636 : : struct port_indirect_action **action)
1637 : : {
1638 : : struct rte_port *port;
1639 : : struct port_indirect_action **ppia;
1640 : : struct port_indirect_action *pia = NULL;
1641 : :
1642 : 0 : *action = NULL;
1643 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1644 : : port_id == (portid_t)RTE_PORT_ALL)
1645 : : return -EINVAL;
1646 : 0 : port = &ports[port_id];
1647 : 0 : if (id == UINT32_MAX) {
1648 : : /* taking first available ID */
1649 : 0 : if (port->actions_list) {
1650 : 0 : if (port->actions_list->id == UINT32_MAX - 1) {
1651 : 0 : fprintf(stderr,
1652 : : "Highest indirect action ID is already assigned, delete it first\n");
1653 : 0 : return -ENOMEM;
1654 : : }
1655 : 0 : id = port->actions_list->id + 1;
1656 : : } else {
1657 : : id = 0;
1658 : : }
1659 : : }
1660 : 0 : pia = calloc(1, sizeof(*pia));
1661 : 0 : if (!pia) {
1662 : 0 : fprintf(stderr,
1663 : : "Allocation of port %u indirect action failed\n",
1664 : : port_id);
1665 : 0 : return -ENOMEM;
1666 : : }
1667 : 0 : ppia = &port->actions_list;
1668 : 0 : while (*ppia && (*ppia)->id > id)
1669 : 0 : ppia = &(*ppia)->next;
1670 : 0 : if (*ppia && (*ppia)->id == id) {
1671 : 0 : fprintf(stderr,
1672 : : "Indirect action #%u is already assigned, delete it first\n",
1673 : : id);
1674 : 0 : free(pia);
1675 : 0 : return -EINVAL;
1676 : : }
1677 : 0 : pia->next = *ppia;
1678 : 0 : pia->id = id;
1679 : 0 : *ppia = pia;
1680 : 0 : *action = pia;
1681 : 0 : return 0;
1682 : : }
1683 : :
1684 : : static int
1685 : 0 : template_alloc(uint32_t id, struct port_template **template,
1686 : : struct port_template **list)
1687 : : {
1688 : 0 : struct port_template *lst = *list;
1689 : : struct port_template **ppt;
1690 : : struct port_template *pt = NULL;
1691 : :
1692 : 0 : *template = NULL;
1693 : 0 : if (id == UINT32_MAX) {
1694 : : /* taking first available ID */
1695 : 0 : if (lst) {
1696 : 0 : if (lst->id == UINT32_MAX - 1) {
1697 : : printf("Highest template ID is already"
1698 : : " assigned, delete it first\n");
1699 : 0 : return -ENOMEM;
1700 : : }
1701 : 0 : id = lst->id + 1;
1702 : : } else {
1703 : : id = 0;
1704 : : }
1705 : : }
1706 : 0 : pt = calloc(1, sizeof(*pt));
1707 : 0 : if (!pt) {
1708 : : printf("Allocation of port template failed\n");
1709 : 0 : return -ENOMEM;
1710 : : }
1711 : : ppt = list;
1712 : 0 : while (*ppt && (*ppt)->id > id)
1713 : 0 : ppt = &(*ppt)->next;
1714 : 0 : if (*ppt && (*ppt)->id == id) {
1715 : : printf("Template #%u is already assigned,"
1716 : : " delete it first\n", id);
1717 : 0 : free(pt);
1718 : 0 : return -EINVAL;
1719 : : }
1720 : 0 : pt->next = *ppt;
1721 : 0 : pt->id = id;
1722 : 0 : *ppt = pt;
1723 : 0 : *template = pt;
1724 : 0 : return 0;
1725 : : }
1726 : :
1727 : : static int
1728 : 0 : table_alloc(uint32_t id, struct port_table **table,
1729 : : struct port_table **list)
1730 : : {
1731 : 0 : struct port_table *lst = *list;
1732 : : struct port_table **ppt;
1733 : : struct port_table *pt = NULL;
1734 : :
1735 : 0 : *table = NULL;
1736 : 0 : if (id == UINT32_MAX) {
1737 : : /* taking first available ID */
1738 : 0 : if (lst) {
1739 : 0 : if (lst->id == UINT32_MAX - 1) {
1740 : : printf("Highest table ID is already"
1741 : : " assigned, delete it first\n");
1742 : 0 : return -ENOMEM;
1743 : : }
1744 : 0 : id = lst->id + 1;
1745 : : } else {
1746 : : id = 0;
1747 : : }
1748 : : }
1749 : 0 : pt = calloc(1, sizeof(*pt));
1750 : 0 : if (!pt) {
1751 : : printf("Allocation of table failed\n");
1752 : 0 : return -ENOMEM;
1753 : : }
1754 : : ppt = list;
1755 : 0 : while (*ppt && (*ppt)->id > id)
1756 : 0 : ppt = &(*ppt)->next;
1757 : 0 : if (*ppt && (*ppt)->id == id) {
1758 : : printf("Table #%u is already assigned,"
1759 : : " delete it first\n", id);
1760 : 0 : free(pt);
1761 : 0 : return -EINVAL;
1762 : : }
1763 : 0 : pt->next = *ppt;
1764 : 0 : pt->id = id;
1765 : 0 : *ppt = pt;
1766 : 0 : *table = pt;
1767 : 0 : return 0;
1768 : : }
1769 : :
1770 : : static struct port_table *
1771 : : port_table_locate(struct port_table *tables_list, uint32_t table_id)
1772 : : {
1773 : : struct port_table *pt = tables_list;
1774 : :
1775 : 0 : while (pt) {
1776 : 0 : if (pt->id == table_id)
1777 : : break;
1778 : 0 : pt = pt->next;
1779 : : }
1780 : : return pt;
1781 : : }
1782 : :
1783 : : /** Get info about flow management resources. */
1784 : : int
1785 : 0 : port_flow_get_info(portid_t port_id)
1786 : : {
1787 : : struct rte_flow_port_info port_info;
1788 : : struct rte_flow_queue_info queue_info;
1789 : : struct rte_flow_error error;
1790 : :
1791 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1792 : : port_id == (portid_t)RTE_PORT_ALL)
1793 : : return -EINVAL;
1794 : : /* Poisoning to make sure PMDs update it in case of error. */
1795 : : memset(&error, 0x99, sizeof(error));
1796 : : memset(&port_info, 0, sizeof(port_info));
1797 : : memset(&queue_info, 0, sizeof(queue_info));
1798 : 0 : if (rte_flow_info_get(port_id, &port_info, &queue_info, &error))
1799 : 0 : return port_flow_complain(&error);
1800 : 0 : printf("Flow engine resources on port %u:\n"
1801 : : "Number of queues: %d\n"
1802 : : "Size of queues: %d\n"
1803 : : "Number of counters: %d\n"
1804 : : "Number of aging objects: %d\n"
1805 : : "Number of meter actions: %d\n",
1806 : : port_id, port_info.max_nb_queues,
1807 : : queue_info.max_size,
1808 : : port_info.max_nb_counters,
1809 : : port_info.max_nb_aging_objects,
1810 : : port_info.max_nb_meters);
1811 : 0 : return 0;
1812 : : }
1813 : :
1814 : : /** Configure flow management resources. */
1815 : : int
1816 : 0 : port_flow_configure(portid_t port_id,
1817 : : const struct rte_flow_port_attr *port_attr,
1818 : : uint16_t nb_queue,
1819 : : const struct rte_flow_queue_attr *queue_attr)
1820 : : {
1821 : : struct rte_port *port;
1822 : : struct rte_flow_error error;
1823 : : const struct rte_flow_queue_attr **attr_list =
1824 : 0 : alloca(sizeof(struct rte_flow_queue_attr *) * nb_queue);
1825 : : int std_queue;
1826 : :
1827 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1828 : : port_id == (portid_t)RTE_PORT_ALL)
1829 : : return -EINVAL;
1830 : 0 : port = &ports[port_id];
1831 : 0 : port->queue_nb = nb_queue;
1832 : 0 : port->queue_sz = queue_attr->size;
1833 : 0 : for (std_queue = 0; std_queue < nb_queue; std_queue++)
1834 : 0 : attr_list[std_queue] = queue_attr;
1835 : : /* Poisoning to make sure PMDs update it in case of error. */
1836 : : memset(&error, 0x66, sizeof(error));
1837 : 0 : if (rte_flow_configure(port_id, port_attr, nb_queue, attr_list, &error))
1838 : 0 : return port_flow_complain(&error);
1839 : : printf("Configure flows on port %u: "
1840 : : "number of queues %d with %d elements\n",
1841 : 0 : port_id, nb_queue, queue_attr->size);
1842 : 0 : return 0;
1843 : : }
1844 : :
1845 : : static int
1846 : 0 : action_handle_create(portid_t port_id,
1847 : : struct port_indirect_action *pia,
1848 : : const struct rte_flow_indir_action_conf *conf,
1849 : : const struct rte_flow_action *action,
1850 : : struct rte_flow_error *error)
1851 : : {
1852 : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1853 : 0 : struct rte_flow_action_age *age =
1854 : : (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1855 : :
1856 : 0 : pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1857 : 0 : age->context = &pia->age_type;
1858 : 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1859 : 0 : struct rte_flow_action_conntrack *ct =
1860 : : (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1861 : :
1862 : : memcpy(ct, &conntrack_context, sizeof(*ct));
1863 : : }
1864 : 0 : pia->type = action->type;
1865 : 0 : pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1866 : : error);
1867 : 0 : return pia->handle ? 0 : -1;
1868 : : }
1869 : :
1870 : : static int
1871 : : action_list_handle_create(portid_t port_id,
1872 : : struct port_indirect_action *pia,
1873 : : const struct rte_flow_indir_action_conf *conf,
1874 : : const struct rte_flow_action *actions,
1875 : : struct rte_flow_error *error)
1876 : : {
1877 : 0 : pia->type = RTE_FLOW_ACTION_TYPE_INDIRECT_LIST;
1878 : 0 : pia->list_handle =
1879 : 0 : rte_flow_action_list_handle_create(port_id, conf,
1880 : : actions, error);
1881 : 0 : return pia->list_handle ? 0 : -1;
1882 : : }
1883 : : /** Create indirect action */
1884 : : int
1885 : 0 : port_action_handle_create(portid_t port_id, uint32_t id, bool indirect_list,
1886 : : const struct rte_flow_indir_action_conf *conf,
1887 : : const struct rte_flow_action *action)
1888 : : {
1889 : : struct port_indirect_action *pia;
1890 : : int ret;
1891 : : struct rte_flow_error error;
1892 : :
1893 : 0 : ret = action_alloc(port_id, id, &pia);
1894 : 0 : if (ret)
1895 : : return ret;
1896 : : /* Poisoning to make sure PMDs update it in case of error. */
1897 : : memset(&error, 0x22, sizeof(error));
1898 : : ret = indirect_list ?
1899 : 0 : action_list_handle_create(port_id, pia, conf, action, &error) :
1900 : 0 : action_handle_create(port_id, pia, conf, action, &error);
1901 : 0 : if (ret) {
1902 : 0 : uint32_t destroy_id = pia->id;
1903 : 0 : port_action_handle_destroy(port_id, 1, &destroy_id);
1904 : 0 : return port_flow_complain(&error);
1905 : : }
1906 : 0 : printf("Indirect action #%u created\n", pia->id);
1907 : 0 : return 0;
1908 : : }
1909 : :
1910 : : /** Destroy indirect action */
1911 : : int
1912 : 0 : port_action_handle_destroy(portid_t port_id,
1913 : : uint32_t n,
1914 : : const uint32_t *actions)
1915 : : {
1916 : : struct rte_port *port;
1917 : : struct port_indirect_action **tmp;
1918 : : int ret = 0;
1919 : :
1920 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1921 : : port_id == (portid_t)RTE_PORT_ALL)
1922 : : return -EINVAL;
1923 : 0 : port = &ports[port_id];
1924 : 0 : tmp = &port->actions_list;
1925 : 0 : while (*tmp) {
1926 : : uint32_t i;
1927 : :
1928 : 0 : for (i = 0; i != n; ++i) {
1929 : : struct rte_flow_error error;
1930 : 0 : struct port_indirect_action *pia = *tmp;
1931 : :
1932 : 0 : if (actions[i] != pia->id)
1933 : 0 : continue;
1934 : : /*
1935 : : * Poisoning to make sure PMDs update it in case
1936 : : * of error.
1937 : : */
1938 : : memset(&error, 0x33, sizeof(error));
1939 : :
1940 : 0 : if (pia->handle) {
1941 : 0 : ret = pia->type ==
1942 : : RTE_FLOW_ACTION_TYPE_INDIRECT_LIST ?
1943 : 0 : rte_flow_action_list_handle_destroy
1944 : 0 : (port_id, pia->list_handle, &error) :
1945 : 0 : rte_flow_action_handle_destroy
1946 : : (port_id, pia->handle, &error);
1947 : 0 : if (ret) {
1948 : 0 : ret = port_flow_complain(&error);
1949 : 0 : continue;
1950 : : }
1951 : : }
1952 : 0 : *tmp = pia->next;
1953 : 0 : printf("Indirect action #%u destroyed\n", pia->id);
1954 : 0 : free(pia);
1955 : 0 : break;
1956 : : }
1957 : 0 : if (i == n)
1958 : 0 : tmp = &(*tmp)->next;
1959 : : }
1960 : : return ret;
1961 : : }
1962 : :
1963 : : int
1964 : 0 : port_action_handle_flush(portid_t port_id)
1965 : : {
1966 : : struct rte_port *port;
1967 : : struct port_indirect_action **tmp;
1968 : : int ret = 0;
1969 : :
1970 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1971 : : port_id == (portid_t)RTE_PORT_ALL)
1972 : : return -EINVAL;
1973 : 0 : port = &ports[port_id];
1974 : : tmp = &port->actions_list;
1975 : 0 : while (*tmp != NULL) {
1976 : : struct rte_flow_error error;
1977 : : struct port_indirect_action *pia = *tmp;
1978 : :
1979 : : /* Poisoning to make sure PMDs update it in case of error. */
1980 : : memset(&error, 0x44, sizeof(error));
1981 : 0 : if (pia->handle != NULL) {
1982 : 0 : ret = pia->type == RTE_FLOW_ACTION_TYPE_INDIRECT_LIST ?
1983 : 0 : rte_flow_action_list_handle_destroy
1984 : 0 : (port_id, pia->list_handle, &error) :
1985 : 0 : rte_flow_action_handle_destroy
1986 : : (port_id, pia->handle, &error);
1987 : 0 : if (ret) {
1988 : 0 : printf("Indirect action #%u not destroyed\n",
1989 : : pia->id);
1990 : 0 : ret = port_flow_complain(&error);
1991 : : }
1992 : : }
1993 : 0 : *tmp = pia->next;
1994 : 0 : free(pia);
1995 : : }
1996 : : return ret;
1997 : : }
1998 : :
1999 : : /** Get indirect action by port + id */
2000 : : struct rte_flow_action_handle *
2001 : 0 : port_action_handle_get_by_id(portid_t port_id, uint32_t id)
2002 : : {
2003 : :
2004 : 0 : struct port_indirect_action *pia = action_get_by_id(port_id, id);
2005 : :
2006 : 0 : return (pia) ? pia->handle : NULL;
2007 : : }
2008 : :
2009 : : /** Update indirect action */
2010 : : int
2011 : 0 : port_action_handle_update(portid_t port_id, uint32_t id,
2012 : : const struct rte_flow_action *action)
2013 : : {
2014 : : struct rte_flow_error error;
2015 : : struct rte_flow_action_handle *action_handle;
2016 : : struct port_indirect_action *pia;
2017 : : struct rte_flow_update_meter_mark mtr_update;
2018 : : const void *update;
2019 : :
2020 : 0 : action_handle = port_action_handle_get_by_id(port_id, id);
2021 : 0 : if (!action_handle)
2022 : : return -EINVAL;
2023 : 0 : pia = action_get_by_id(port_id, id);
2024 : 0 : if (!pia)
2025 : : return -EINVAL;
2026 : 0 : switch (pia->type) {
2027 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
2028 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2029 : 0 : update = action->conf;
2030 : 0 : break;
2031 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
2032 : 0 : memcpy(&mtr_update.meter_mark, action->conf,
2033 : : sizeof(struct rte_flow_action_meter_mark));
2034 : 0 : if (mtr_update.meter_mark.profile)
2035 : 0 : mtr_update.profile_valid = 1;
2036 : 0 : if (mtr_update.meter_mark.policy)
2037 : 0 : mtr_update.policy_valid = 1;
2038 : 0 : mtr_update.color_mode_valid = 1;
2039 : 0 : mtr_update.state_valid = 1;
2040 : : update = &mtr_update;
2041 : 0 : break;
2042 : : default:
2043 : : update = action;
2044 : : break;
2045 : : }
2046 : 0 : if (rte_flow_action_handle_update(port_id, action_handle, update,
2047 : : &error)) {
2048 : 0 : return port_flow_complain(&error);
2049 : : }
2050 : : printf("Indirect action #%u updated\n", id);
2051 : 0 : return 0;
2052 : : }
2053 : :
2054 : : static void
2055 : 0 : port_action_handle_query_dump(portid_t port_id,
2056 : : const struct port_indirect_action *pia,
2057 : : union port_action_query *query)
2058 : : {
2059 : 0 : if (!pia || !query)
2060 : : return;
2061 : 0 : switch (pia->type) {
2062 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
2063 : 0 : printf("Indirect AGE action:\n"
2064 : : " aged: %u\n"
2065 : : " sec_since_last_hit_valid: %u\n"
2066 : : " sec_since_last_hit: %" PRIu32 "\n",
2067 : 0 : query->age.aged,
2068 : 0 : query->age.sec_since_last_hit_valid,
2069 : 0 : query->age.sec_since_last_hit);
2070 : : break;
2071 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
2072 : 0 : printf("Indirect COUNT action:\n"
2073 : : " hits_set: %u\n"
2074 : : " bytes_set: %u\n"
2075 : : " hits: %" PRIu64 "\n"
2076 : : " bytes: %" PRIu64 "\n",
2077 : 0 : query->count.hits_set,
2078 : 0 : query->count.bytes_set,
2079 : : query->count.hits,
2080 : : query->count.bytes);
2081 : : break;
2082 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2083 : 0 : printf("Conntrack Context:\n"
2084 : : " Peer: %u, Flow dir: %s, Enable: %u\n"
2085 : : " Live: %u, SACK: %u, CACK: %u\n"
2086 : : " Packet dir: %s, Liberal: %u, State: %u\n"
2087 : : " Factor: %u, Retrans: %u, TCP flags: %u\n"
2088 : : " Last Seq: %u, Last ACK: %u\n"
2089 : : " Last Win: %u, Last End: %u\n",
2090 : 0 : query->ct.peer_port,
2091 : 0 : query->ct.is_original_dir ? "Original" : "Reply",
2092 : 0 : query->ct.enable, query->ct.live_connection,
2093 : 0 : query->ct.selective_ack, query->ct.challenge_ack_passed,
2094 : 0 : query->ct.last_direction ? "Original" : "Reply",
2095 : 0 : query->ct.liberal_mode, query->ct.state,
2096 : 0 : query->ct.max_ack_window, query->ct.retransmission_limit,
2097 : 0 : query->ct.last_index, query->ct.last_seq,
2098 : 0 : query->ct.last_ack, query->ct.last_window,
2099 : : query->ct.last_end);
2100 : 0 : printf(" Original Dir:\n"
2101 : : " scale: %u, fin: %u, ack seen: %u\n"
2102 : : " unacked data: %u\n Sent end: %u,"
2103 : : " Reply end: %u, Max win: %u, Max ACK: %u\n",
2104 : 0 : query->ct.original_dir.scale,
2105 : 0 : query->ct.original_dir.close_initiated,
2106 : 0 : query->ct.original_dir.last_ack_seen,
2107 : 0 : query->ct.original_dir.data_unacked,
2108 : : query->ct.original_dir.sent_end,
2109 : : query->ct.original_dir.reply_end,
2110 : : query->ct.original_dir.max_win,
2111 : : query->ct.original_dir.max_ack);
2112 : 0 : printf(" Reply Dir:\n"
2113 : : " scale: %u, fin: %u, ack seen: %u\n"
2114 : : " unacked data: %u\n Sent end: %u,"
2115 : : " Reply end: %u, Max win: %u, Max ACK: %u\n",
2116 : 0 : query->ct.reply_dir.scale,
2117 : 0 : query->ct.reply_dir.close_initiated,
2118 : 0 : query->ct.reply_dir.last_ack_seen,
2119 : 0 : query->ct.reply_dir.data_unacked,
2120 : : query->ct.reply_dir.sent_end,
2121 : : query->ct.reply_dir.reply_end,
2122 : : query->ct.reply_dir.max_win,
2123 : : query->ct.reply_dir.max_ack);
2124 : : break;
2125 : 0 : case RTE_FLOW_ACTION_TYPE_QUOTA:
2126 : 0 : printf("Indirect QUOTA action %u\n"
2127 : : " unused quota: %" PRId64 "\n",
2128 : 0 : pia->id, query->quota.quota);
2129 : : break;
2130 : 0 : default:
2131 : 0 : printf("port-%u: indirect action %u (type: %d) doesn't support query\n",
2132 : 0 : pia->type, pia->id, port_id);
2133 : : break;
2134 : : }
2135 : :
2136 : : }
2137 : :
2138 : : void
2139 : 0 : port_action_handle_query_update(portid_t port_id, uint32_t id,
2140 : : enum rte_flow_query_update_mode qu_mode,
2141 : : const struct rte_flow_action *action)
2142 : : {
2143 : : int ret;
2144 : : struct rte_flow_error error;
2145 : : struct port_indirect_action *pia;
2146 : : union port_action_query query;
2147 : :
2148 : 0 : pia = action_get_by_id(port_id, id);
2149 : 0 : if (!pia || !pia->handle)
2150 : 0 : return;
2151 : 0 : ret = rte_flow_action_handle_query_update(port_id, pia->handle, action,
2152 : : &query, qu_mode, &error);
2153 : 0 : if (ret)
2154 : 0 : port_flow_complain(&error);
2155 : : else
2156 : 0 : port_action_handle_query_dump(port_id, pia, &query);
2157 : :
2158 : : }
2159 : :
2160 : : int
2161 : 0 : port_action_handle_query(portid_t port_id, uint32_t id)
2162 : : {
2163 : : struct rte_flow_error error;
2164 : : struct port_indirect_action *pia;
2165 : : union port_action_query query;
2166 : :
2167 : 0 : pia = action_get_by_id(port_id, id);
2168 : 0 : if (!pia)
2169 : : return -EINVAL;
2170 : 0 : switch (pia->type) {
2171 : : case RTE_FLOW_ACTION_TYPE_AGE:
2172 : : case RTE_FLOW_ACTION_TYPE_COUNT:
2173 : : case RTE_FLOW_ACTION_TYPE_QUOTA:
2174 : : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2175 : : break;
2176 : 0 : default:
2177 : 0 : fprintf(stderr,
2178 : : "Indirect action %u (type: %d) on port %u doesn't support query\n",
2179 : : id, pia->type, port_id);
2180 : 0 : return -ENOTSUP;
2181 : : }
2182 : : /* Poisoning to make sure PMDs update it in case of error. */
2183 : : memset(&error, 0x55, sizeof(error));
2184 : : memset(&query, 0, sizeof(query));
2185 : 0 : if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
2186 : 0 : return port_flow_complain(&error);
2187 : 0 : port_action_handle_query_dump(port_id, pia, &query);
2188 : 0 : return 0;
2189 : : }
2190 : :
2191 : : static struct port_flow_tunnel *
2192 : 0 : port_flow_tunnel_offload_cmd_prep(portid_t port_id,
2193 : : const struct rte_flow_item *pattern,
2194 : : const struct rte_flow_action *actions,
2195 : : const struct tunnel_ops *tunnel_ops)
2196 : : {
2197 : : int ret;
2198 : : struct rte_port *port;
2199 : : struct port_flow_tunnel *pft;
2200 : : struct rte_flow_error error;
2201 : :
2202 : 0 : port = &ports[port_id];
2203 : 0 : pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
2204 : 0 : if (!pft) {
2205 : 0 : fprintf(stderr, "failed to locate port flow tunnel #%u\n",
2206 : : tunnel_ops->id);
2207 : 0 : return NULL;
2208 : : }
2209 : 0 : if (tunnel_ops->actions) {
2210 : : uint32_t num_actions;
2211 : : const struct rte_flow_action *aptr;
2212 : :
2213 : 0 : ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
2214 : : &pft->pmd_actions,
2215 : : &pft->num_pmd_actions,
2216 : : &error);
2217 : 0 : if (ret) {
2218 : 0 : port_flow_complain(&error);
2219 : 0 : return NULL;
2220 : : }
2221 : : for (aptr = actions, num_actions = 1;
2222 : 0 : aptr->type != RTE_FLOW_ACTION_TYPE_END;
2223 : 0 : aptr++, num_actions++);
2224 : 0 : pft->actions = malloc(
2225 : 0 : (num_actions + pft->num_pmd_actions) *
2226 : : sizeof(actions[0]));
2227 : 0 : if (!pft->actions) {
2228 : 0 : rte_flow_tunnel_action_decap_release(
2229 : : port_id, pft->actions,
2230 : : pft->num_pmd_actions, &error);
2231 : 0 : return NULL;
2232 : : }
2233 : 0 : rte_memcpy(pft->actions, pft->pmd_actions,
2234 : 0 : pft->num_pmd_actions * sizeof(actions[0]));
2235 : 0 : rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
2236 : : num_actions * sizeof(actions[0]));
2237 : : }
2238 : 0 : if (tunnel_ops->items) {
2239 : : uint32_t num_items;
2240 : : const struct rte_flow_item *iptr;
2241 : :
2242 : 0 : ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
2243 : : &pft->pmd_items,
2244 : : &pft->num_pmd_items,
2245 : : &error);
2246 : 0 : if (ret) {
2247 : 0 : port_flow_complain(&error);
2248 : 0 : return NULL;
2249 : : }
2250 : : for (iptr = pattern, num_items = 1;
2251 : 0 : iptr->type != RTE_FLOW_ITEM_TYPE_END;
2252 : 0 : iptr++, num_items++);
2253 : 0 : pft->items = malloc((num_items + pft->num_pmd_items) *
2254 : : sizeof(pattern[0]));
2255 : 0 : if (!pft->items) {
2256 : 0 : rte_flow_tunnel_item_release(
2257 : : port_id, pft->pmd_items,
2258 : : pft->num_pmd_items, &error);
2259 : 0 : return NULL;
2260 : : }
2261 : 0 : rte_memcpy(pft->items, pft->pmd_items,
2262 : 0 : pft->num_pmd_items * sizeof(pattern[0]));
2263 : 0 : rte_memcpy(pft->items + pft->num_pmd_items, pattern,
2264 : : num_items * sizeof(pattern[0]));
2265 : : }
2266 : :
2267 : : return pft;
2268 : : }
2269 : :
2270 : : static void
2271 : 0 : port_flow_tunnel_offload_cmd_release(portid_t port_id,
2272 : : const struct tunnel_ops *tunnel_ops,
2273 : : struct port_flow_tunnel *pft)
2274 : : {
2275 : : struct rte_flow_error error;
2276 : :
2277 : 0 : if (tunnel_ops->actions) {
2278 : 0 : free(pft->actions);
2279 : 0 : rte_flow_tunnel_action_decap_release(
2280 : : port_id, pft->pmd_actions,
2281 : : pft->num_pmd_actions, &error);
2282 : 0 : pft->actions = NULL;
2283 : 0 : pft->pmd_actions = NULL;
2284 : : }
2285 : 0 : if (tunnel_ops->items) {
2286 : 0 : free(pft->items);
2287 : 0 : rte_flow_tunnel_item_release(port_id, pft->pmd_items,
2288 : : pft->num_pmd_items,
2289 : : &error);
2290 : 0 : pft->items = NULL;
2291 : 0 : pft->pmd_items = NULL;
2292 : : }
2293 : 0 : }
2294 : :
2295 : : /** Add port meter policy */
2296 : : int
2297 : 0 : port_meter_policy_add(portid_t port_id, uint32_t policy_id,
2298 : : const struct rte_flow_action *actions)
2299 : : {
2300 : : struct rte_mtr_error error;
2301 : : const struct rte_flow_action *act = actions;
2302 : : const struct rte_flow_action *start;
2303 : : struct rte_mtr_meter_policy_params policy;
2304 : : uint32_t i = 0, act_n;
2305 : : int ret;
2306 : :
2307 : 0 : for (i = 0; i < RTE_COLORS; i++) {
2308 : : for (act_n = 0, start = act;
2309 : 0 : act->type != RTE_FLOW_ACTION_TYPE_END; act++)
2310 : 0 : act_n++;
2311 : 0 : if (act_n > 0)
2312 : 0 : policy.actions[i] = start;
2313 : : else
2314 : 0 : policy.actions[i] = NULL;
2315 : 0 : act++;
2316 : : }
2317 : 0 : ret = rte_mtr_meter_policy_add(port_id,
2318 : : policy_id,
2319 : : &policy, &error);
2320 : 0 : if (ret)
2321 : 0 : print_mtr_err_msg(&error);
2322 : 0 : return ret;
2323 : : }
2324 : :
2325 : : struct rte_flow_meter_profile *
2326 : 0 : port_meter_profile_get_by_id(portid_t port_id, uint32_t id)
2327 : : {
2328 : : struct rte_mtr_error error;
2329 : : struct rte_flow_meter_profile *profile;
2330 : :
2331 : 0 : profile = rte_mtr_meter_profile_get(port_id, id, &error);
2332 : 0 : if (!profile)
2333 : 0 : print_mtr_err_msg(&error);
2334 : 0 : return profile;
2335 : : }
2336 : : struct rte_flow_meter_policy *
2337 : 0 : port_meter_policy_get_by_id(portid_t port_id, uint32_t id)
2338 : : {
2339 : : struct rte_mtr_error error;
2340 : : struct rte_flow_meter_policy *policy;
2341 : :
2342 : 0 : policy = rte_mtr_meter_policy_get(port_id, id, &error);
2343 : 0 : if (!policy)
2344 : 0 : print_mtr_err_msg(&error);
2345 : 0 : return policy;
2346 : : }
2347 : :
2348 : : /** Validate flow rule. */
2349 : : int
2350 : 0 : port_flow_validate(portid_t port_id,
2351 : : const struct rte_flow_attr *attr,
2352 : : const struct rte_flow_item *pattern,
2353 : : const struct rte_flow_action *actions,
2354 : : const struct tunnel_ops *tunnel_ops)
2355 : : {
2356 : : struct rte_flow_error error;
2357 : : struct port_flow_tunnel *pft = NULL;
2358 : : int ret;
2359 : :
2360 : : /* Poisoning to make sure PMDs update it in case of error. */
2361 : : memset(&error, 0x11, sizeof(error));
2362 : 0 : if (tunnel_ops->enabled) {
2363 : 0 : pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2364 : : actions, tunnel_ops);
2365 : 0 : if (!pft)
2366 : : return -ENOENT;
2367 : 0 : if (pft->items)
2368 : : pattern = pft->items;
2369 : 0 : if (pft->actions)
2370 : : actions = pft->actions;
2371 : : }
2372 : 0 : ret = rte_flow_validate(port_id, attr, pattern, actions, &error);
2373 : 0 : if (tunnel_ops->enabled)
2374 : 0 : port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2375 : 0 : if (ret)
2376 : 0 : return port_flow_complain(&error);
2377 : : printf("Flow rule validated\n");
2378 : 0 : return 0;
2379 : : }
2380 : :
2381 : : /** Return age action structure if exists, otherwise NULL. */
2382 : : static struct rte_flow_action_age *
2383 : : age_action_get(const struct rte_flow_action *actions)
2384 : : {
2385 : 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2386 : 0 : switch (actions->type) {
2387 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
2388 : 0 : return (struct rte_flow_action_age *)
2389 : : (uintptr_t)actions->conf;
2390 : : default:
2391 : : break;
2392 : : }
2393 : : }
2394 : : return NULL;
2395 : : }
2396 : :
2397 : : /** Create pattern template */
2398 : : int
2399 : 0 : port_flow_pattern_template_create(portid_t port_id, uint32_t id,
2400 : : const struct rte_flow_pattern_template_attr *attr,
2401 : : const struct rte_flow_item *pattern)
2402 : : {
2403 : : struct rte_port *port;
2404 : : struct port_template *pit;
2405 : : int ret;
2406 : : struct rte_flow_error error;
2407 : :
2408 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2409 : : port_id == (portid_t)RTE_PORT_ALL)
2410 : : return -EINVAL;
2411 : 0 : port = &ports[port_id];
2412 : 0 : ret = template_alloc(id, &pit, &port->pattern_templ_list);
2413 : 0 : if (ret)
2414 : : return ret;
2415 : : /* Poisoning to make sure PMDs update it in case of error. */
2416 : : memset(&error, 0x22, sizeof(error));
2417 : 0 : pit->template.pattern_template = rte_flow_pattern_template_create(port_id,
2418 : : attr, pattern, &error);
2419 : 0 : if (!pit->template.pattern_template) {
2420 : 0 : uint32_t destroy_id = pit->id;
2421 : 0 : port_flow_pattern_template_destroy(port_id, 1, &destroy_id);
2422 : 0 : return port_flow_complain(&error);
2423 : : }
2424 : 0 : printf("Pattern template #%u created\n", pit->id);
2425 : 0 : return 0;
2426 : : }
2427 : :
2428 : : /** Destroy pattern template */
2429 : : int
2430 : 0 : port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
2431 : : const uint32_t *template)
2432 : : {
2433 : : struct rte_port *port;
2434 : : struct port_template **tmp;
2435 : : int ret = 0;
2436 : :
2437 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2438 : : port_id == (portid_t)RTE_PORT_ALL)
2439 : : return -EINVAL;
2440 : 0 : port = &ports[port_id];
2441 : 0 : tmp = &port->pattern_templ_list;
2442 : 0 : while (*tmp) {
2443 : : uint32_t i;
2444 : :
2445 : 0 : for (i = 0; i != n; ++i) {
2446 : : struct rte_flow_error error;
2447 : 0 : struct port_template *pit = *tmp;
2448 : :
2449 : 0 : if (template[i] != pit->id)
2450 : 0 : continue;
2451 : : /*
2452 : : * Poisoning to make sure PMDs update it in case
2453 : : * of error.
2454 : : */
2455 : : memset(&error, 0x33, sizeof(error));
2456 : :
2457 : 0 : if (pit->template.pattern_template &&
2458 : 0 : rte_flow_pattern_template_destroy(port_id,
2459 : : pit->template.pattern_template,
2460 : : &error)) {
2461 : 0 : ret = port_flow_complain(&error);
2462 : 0 : continue;
2463 : : }
2464 : 0 : *tmp = pit->next;
2465 : 0 : printf("Pattern template #%u destroyed\n", pit->id);
2466 : 0 : free(pit);
2467 : 0 : break;
2468 : : }
2469 : 0 : if (i == n)
2470 : 0 : tmp = &(*tmp)->next;
2471 : : }
2472 : : return ret;
2473 : : }
2474 : :
2475 : : /** Flush pattern template */
2476 : : int
2477 : 0 : port_flow_pattern_template_flush(portid_t port_id)
2478 : : {
2479 : : struct rte_port *port;
2480 : : struct port_template **tmp;
2481 : : int ret = 0;
2482 : :
2483 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2484 : : port_id == (portid_t)RTE_PORT_ALL)
2485 : : return -EINVAL;
2486 : 0 : port = &ports[port_id];
2487 : 0 : tmp = &port->pattern_templ_list;
2488 : 0 : while (*tmp) {
2489 : : struct rte_flow_error error;
2490 : : struct port_template *pit = *tmp;
2491 : :
2492 : : /*
2493 : : * Poisoning to make sure PMDs update it in case
2494 : : * of error.
2495 : : */
2496 : : memset(&error, 0x33, sizeof(error));
2497 : 0 : if (pit->template.pattern_template &&
2498 : 0 : rte_flow_pattern_template_destroy(port_id,
2499 : : pit->template.pattern_template, &error)) {
2500 : 0 : printf("Pattern template #%u not destroyed\n", pit->id);
2501 : 0 : ret = port_flow_complain(&error);
2502 : 0 : tmp = &pit->next;
2503 : : } else {
2504 : 0 : *tmp = pit->next;
2505 : 0 : free(pit);
2506 : : }
2507 : : }
2508 : : return ret;
2509 : : }
2510 : :
2511 : : /** Create actions template */
2512 : : int
2513 : 0 : port_flow_actions_template_create(portid_t port_id, uint32_t id,
2514 : : const struct rte_flow_actions_template_attr *attr,
2515 : : const struct rte_flow_action *actions,
2516 : : const struct rte_flow_action *masks)
2517 : : {
2518 : : struct rte_port *port;
2519 : : struct port_template *pat;
2520 : : int ret;
2521 : : struct rte_flow_error error;
2522 : :
2523 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2524 : : port_id == (portid_t)RTE_PORT_ALL)
2525 : : return -EINVAL;
2526 : 0 : port = &ports[port_id];
2527 : 0 : ret = template_alloc(id, &pat, &port->actions_templ_list);
2528 : 0 : if (ret)
2529 : : return ret;
2530 : : /* Poisoning to make sure PMDs update it in case of error. */
2531 : : memset(&error, 0x22, sizeof(error));
2532 : 0 : pat->template.actions_template = rte_flow_actions_template_create(port_id,
2533 : : attr, actions, masks, &error);
2534 : 0 : if (!pat->template.actions_template) {
2535 : 0 : uint32_t destroy_id = pat->id;
2536 : 0 : port_flow_actions_template_destroy(port_id, 1, &destroy_id);
2537 : 0 : return port_flow_complain(&error);
2538 : : }
2539 : 0 : printf("Actions template #%u created\n", pat->id);
2540 : 0 : return 0;
2541 : : }
2542 : :
2543 : : /** Destroy actions template */
2544 : : int
2545 : 0 : port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
2546 : : const uint32_t *template)
2547 : : {
2548 : : struct rte_port *port;
2549 : : struct port_template **tmp;
2550 : : int ret = 0;
2551 : :
2552 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2553 : : port_id == (portid_t)RTE_PORT_ALL)
2554 : : return -EINVAL;
2555 : 0 : port = &ports[port_id];
2556 : 0 : tmp = &port->actions_templ_list;
2557 : 0 : while (*tmp) {
2558 : : uint32_t i;
2559 : :
2560 : 0 : for (i = 0; i != n; ++i) {
2561 : : struct rte_flow_error error;
2562 : 0 : struct port_template *pat = *tmp;
2563 : :
2564 : 0 : if (template[i] != pat->id)
2565 : 0 : continue;
2566 : : /*
2567 : : * Poisoning to make sure PMDs update it in case
2568 : : * of error.
2569 : : */
2570 : : memset(&error, 0x33, sizeof(error));
2571 : :
2572 : 0 : if (pat->template.actions_template &&
2573 : 0 : rte_flow_actions_template_destroy(port_id,
2574 : : pat->template.actions_template, &error)) {
2575 : 0 : ret = port_flow_complain(&error);
2576 : 0 : continue;
2577 : : }
2578 : 0 : *tmp = pat->next;
2579 : 0 : printf("Actions template #%u destroyed\n", pat->id);
2580 : 0 : free(pat);
2581 : 0 : break;
2582 : : }
2583 : 0 : if (i == n)
2584 : 0 : tmp = &(*tmp)->next;
2585 : : }
2586 : : return ret;
2587 : : }
2588 : :
2589 : : /** Flush actions template */
2590 : : int
2591 : 0 : port_flow_actions_template_flush(portid_t port_id)
2592 : : {
2593 : : struct rte_port *port;
2594 : : struct port_template **tmp;
2595 : : int ret = 0;
2596 : :
2597 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2598 : : port_id == (portid_t)RTE_PORT_ALL)
2599 : : return -EINVAL;
2600 : 0 : port = &ports[port_id];
2601 : 0 : tmp = &port->actions_templ_list;
2602 : 0 : while (*tmp) {
2603 : : struct rte_flow_error error;
2604 : : struct port_template *pat = *tmp;
2605 : :
2606 : : /*
2607 : : * Poisoning to make sure PMDs update it in case
2608 : : * of error.
2609 : : */
2610 : : memset(&error, 0x33, sizeof(error));
2611 : :
2612 : 0 : if (pat->template.actions_template &&
2613 : 0 : rte_flow_actions_template_destroy(port_id,
2614 : : pat->template.actions_template, &error)) {
2615 : 0 : ret = port_flow_complain(&error);
2616 : 0 : printf("Actions template #%u not destroyed\n", pat->id);
2617 : 0 : tmp = &pat->next;
2618 : : } else {
2619 : 0 : *tmp = pat->next;
2620 : 0 : free(pat);
2621 : : }
2622 : : }
2623 : : return ret;
2624 : : }
2625 : :
2626 : : /** Create table */
2627 : : int
2628 : 0 : port_flow_template_table_create(portid_t port_id, uint32_t id,
2629 : : const struct rte_flow_template_table_attr *table_attr,
2630 : : uint32_t nb_pattern_templates, uint32_t *pattern_templates,
2631 : : uint32_t nb_actions_templates, uint32_t *actions_templates)
2632 : : {
2633 : : struct rte_port *port;
2634 : : struct port_table *pt;
2635 : : struct port_template *temp = NULL;
2636 : : int ret;
2637 : : uint32_t i;
2638 : : struct rte_flow_error error;
2639 : : struct rte_flow_pattern_template **flow_pattern_templates =
2640 : 0 : alloca(sizeof(struct rte_flow_pattern_template *) * nb_pattern_templates);
2641 : : struct rte_flow_actions_template **flow_actions_templates =
2642 : 0 : alloca(sizeof(struct rte_flow_actions_template *) * nb_actions_templates);
2643 : :
2644 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2645 : : port_id == (portid_t)RTE_PORT_ALL)
2646 : : return -EINVAL;
2647 : 0 : port = &ports[port_id];
2648 : 0 : for (i = 0; i < nb_pattern_templates; ++i) {
2649 : : bool found = false;
2650 : 0 : temp = port->pattern_templ_list;
2651 : 0 : while (temp) {
2652 : 0 : if (pattern_templates[i] == temp->id) {
2653 : 0 : flow_pattern_templates[i] =
2654 : 0 : temp->template.pattern_template;
2655 : : found = true;
2656 : : break;
2657 : : }
2658 : 0 : temp = temp->next;
2659 : : }
2660 : : if (!found) {
2661 : 0 : printf("Pattern template #%u is invalid\n",
2662 : 0 : pattern_templates[i]);
2663 : 0 : return -EINVAL;
2664 : : }
2665 : : }
2666 : 0 : for (i = 0; i < nb_actions_templates; ++i) {
2667 : : bool found = false;
2668 : 0 : temp = port->actions_templ_list;
2669 : 0 : while (temp) {
2670 : 0 : if (actions_templates[i] == temp->id) {
2671 : 0 : flow_actions_templates[i] =
2672 : 0 : temp->template.actions_template;
2673 : : found = true;
2674 : : break;
2675 : : }
2676 : 0 : temp = temp->next;
2677 : : }
2678 : : if (!found) {
2679 : 0 : printf("Actions template #%u is invalid\n",
2680 : 0 : actions_templates[i]);
2681 : 0 : return -EINVAL;
2682 : : }
2683 : : }
2684 : 0 : ret = table_alloc(id, &pt, &port->table_list);
2685 : 0 : if (ret)
2686 : : return ret;
2687 : : /* Poisoning to make sure PMDs update it in case of error. */
2688 : : memset(&error, 0x22, sizeof(error));
2689 : 0 : pt->table = rte_flow_template_table_create(port_id, table_attr,
2690 : : flow_pattern_templates, nb_pattern_templates,
2691 : : flow_actions_templates, nb_actions_templates,
2692 : : &error);
2693 : :
2694 : 0 : if (!pt->table) {
2695 : 0 : uint32_t destroy_id = pt->id;
2696 : 0 : port_flow_template_table_destroy(port_id, 1, &destroy_id);
2697 : 0 : return port_flow_complain(&error);
2698 : : }
2699 : 0 : pt->nb_pattern_templates = nb_pattern_templates;
2700 : 0 : pt->nb_actions_templates = nb_actions_templates;
2701 : 0 : rte_memcpy(&pt->attr, table_attr,
2702 : : sizeof(struct rte_flow_template_table_attr));
2703 : 0 : printf("Template table #%u created\n", pt->id);
2704 : 0 : return 0;
2705 : : }
2706 : :
2707 : : /** Destroy table */
2708 : : int
2709 : 0 : port_flow_template_table_destroy(portid_t port_id,
2710 : : uint32_t n, const uint32_t *table)
2711 : : {
2712 : : struct rte_port *port;
2713 : : struct port_table **tmp;
2714 : : int ret = 0;
2715 : :
2716 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2717 : : port_id == (portid_t)RTE_PORT_ALL)
2718 : : return -EINVAL;
2719 : 0 : port = &ports[port_id];
2720 : 0 : tmp = &port->table_list;
2721 : 0 : while (*tmp) {
2722 : : uint32_t i;
2723 : :
2724 : 0 : for (i = 0; i != n; ++i) {
2725 : : struct rte_flow_error error;
2726 : 0 : struct port_table *pt = *tmp;
2727 : :
2728 : 0 : if (table[i] != pt->id)
2729 : 0 : continue;
2730 : : /*
2731 : : * Poisoning to make sure PMDs update it in case
2732 : : * of error.
2733 : : */
2734 : : memset(&error, 0x33, sizeof(error));
2735 : :
2736 : 0 : if (pt->table &&
2737 : 0 : rte_flow_template_table_destroy(port_id,
2738 : : pt->table,
2739 : : &error)) {
2740 : 0 : ret = port_flow_complain(&error);
2741 : 0 : continue;
2742 : : }
2743 : 0 : *tmp = pt->next;
2744 : 0 : printf("Template table #%u destroyed\n", pt->id);
2745 : 0 : free(pt);
2746 : 0 : break;
2747 : : }
2748 : 0 : if (i == n)
2749 : 0 : tmp = &(*tmp)->next;
2750 : : }
2751 : : return ret;
2752 : : }
2753 : :
2754 : : int
2755 : 0 : port_flow_template_table_resize_complete(portid_t port_id, uint32_t table_id)
2756 : : {
2757 : : struct rte_port *port;
2758 : : struct port_table *pt;
2759 : 0 : struct rte_flow_error error = { 0, };
2760 : : int ret;
2761 : :
2762 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
2763 : : return -EINVAL;
2764 : 0 : port = &ports[port_id];
2765 : 0 : pt = port_table_locate(port->table_list, table_id);
2766 : 0 : if (!pt)
2767 : : return -EINVAL;
2768 : 0 : ret = rte_flow_template_table_resize_complete(port_id,
2769 : : pt->table, &error);
2770 : 0 : return !ret ? 0 : port_flow_complain(&error);
2771 : : }
2772 : :
2773 : : int
2774 : 0 : port_flow_template_table_resize(portid_t port_id,
2775 : : uint32_t table_id, uint32_t flows_num)
2776 : : {
2777 : : struct rte_port *port;
2778 : : struct port_table *pt;
2779 : 0 : struct rte_flow_error error = { 0, };
2780 : : int ret;
2781 : :
2782 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
2783 : : return -EINVAL;
2784 : 0 : port = &ports[port_id];
2785 : 0 : pt = port_table_locate(port->table_list, table_id);
2786 : 0 : if (!pt)
2787 : : return -EINVAL;
2788 : 0 : ret = rte_flow_template_table_resize(port_id, pt->table, flows_num, &error);
2789 : 0 : if (ret)
2790 : 0 : return port_flow_complain(&error);
2791 : : return 0;
2792 : : }
2793 : :
2794 : : /** Flush table */
2795 : : int
2796 : 0 : port_flow_template_table_flush(portid_t port_id)
2797 : : {
2798 : : struct rte_port *port;
2799 : : struct port_table **tmp;
2800 : : int ret = 0;
2801 : :
2802 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2803 : : port_id == (portid_t)RTE_PORT_ALL)
2804 : : return -EINVAL;
2805 : 0 : port = &ports[port_id];
2806 : 0 : tmp = &port->table_list;
2807 : 0 : while (*tmp) {
2808 : : struct rte_flow_error error;
2809 : : struct port_table *pt = *tmp;
2810 : :
2811 : : /*
2812 : : * Poisoning to make sure PMDs update it in case
2813 : : * of error.
2814 : : */
2815 : : memset(&error, 0x33, sizeof(error));
2816 : :
2817 : 0 : if (pt->table &&
2818 : 0 : rte_flow_template_table_destroy(port_id,
2819 : : pt->table,
2820 : : &error)) {
2821 : 0 : ret = port_flow_complain(&error);
2822 : 0 : printf("Template table #%u not destroyed\n", pt->id);
2823 : 0 : tmp = &pt->next;
2824 : : } else {
2825 : 0 : *tmp = pt->next;
2826 : 0 : free(pt);
2827 : : }
2828 : : }
2829 : : return ret;
2830 : : }
2831 : :
2832 : : /** Enqueue create flow rule operation. */
2833 : : int
2834 : 0 : port_queue_flow_create(portid_t port_id, queueid_t queue_id,
2835 : : bool postpone, uint32_t table_id, uint32_t rule_idx,
2836 : : uint32_t pattern_idx, uint32_t actions_idx,
2837 : : const struct rte_flow_item *pattern,
2838 : : const struct rte_flow_action *actions)
2839 : : {
2840 : 0 : struct rte_flow_op_attr op_attr = { .postpone = postpone };
2841 : : struct rte_flow *flow;
2842 : : struct rte_port *port;
2843 : : struct port_flow *pf;
2844 : : struct port_table *pt;
2845 : : uint32_t id = 0;
2846 : : bool found;
2847 : 0 : struct rte_flow_error error = { RTE_FLOW_ERROR_TYPE_NONE, NULL, NULL };
2848 : : struct rte_flow_action_age *age = age_action_get(actions);
2849 : : struct queue_job *job;
2850 : :
2851 : 0 : port = &ports[port_id];
2852 : 0 : if (port->flow_list) {
2853 : 0 : if (port->flow_list->id == UINT32_MAX) {
2854 : : printf("Highest rule ID is already assigned,"
2855 : : " delete it first");
2856 : 0 : return -ENOMEM;
2857 : : }
2858 : 0 : id = port->flow_list->id + 1;
2859 : : }
2860 : :
2861 : 0 : if (queue_id >= port->queue_nb) {
2862 : 0 : printf("Queue #%u is invalid\n", queue_id);
2863 : 0 : return -EINVAL;
2864 : : }
2865 : :
2866 : : found = false;
2867 : 0 : pt = port->table_list;
2868 : 0 : while (pt) {
2869 : 0 : if (table_id == pt->id) {
2870 : : found = true;
2871 : : break;
2872 : : }
2873 : 0 : pt = pt->next;
2874 : : }
2875 : 0 : if (!found) {
2876 : : printf("Table #%u is invalid\n", table_id);
2877 : 0 : return -EINVAL;
2878 : : }
2879 : :
2880 : 0 : if (pattern_idx >= pt->nb_pattern_templates) {
2881 : : printf("Pattern template index #%u is invalid,"
2882 : : " %u templates present in the table\n",
2883 : : pattern_idx, pt->nb_pattern_templates);
2884 : 0 : return -EINVAL;
2885 : : }
2886 : 0 : if (actions_idx >= pt->nb_actions_templates) {
2887 : : printf("Actions template index #%u is invalid,"
2888 : : " %u templates present in the table\n",
2889 : : actions_idx, pt->nb_actions_templates);
2890 : 0 : return -EINVAL;
2891 : : }
2892 : :
2893 : 0 : job = calloc(1, sizeof(*job));
2894 : 0 : if (!job) {
2895 : : printf("Queue flow create job allocate failed\n");
2896 : 0 : return -ENOMEM;
2897 : : }
2898 : : job->type = QUEUE_JOB_TYPE_FLOW_CREATE;
2899 : :
2900 : 0 : pf = port_flow_new(&pt->attr.flow_attr, pattern, actions, &error);
2901 : 0 : if (!pf) {
2902 : 0 : free(job);
2903 : 0 : return port_flow_complain(&error);
2904 : : }
2905 : 0 : if (age) {
2906 : 0 : pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2907 : 0 : age->context = &pf->age_type;
2908 : : }
2909 : : /* Poisoning to make sure PMDs update it in case of error. */
2910 : : memset(&error, 0x11, sizeof(error));
2911 : 0 : if (pt->attr.insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN)
2912 : 0 : flow = rte_flow_async_create(port_id, queue_id, &op_attr, pt->table,
2913 : : pattern, pattern_idx, actions, actions_idx, job, &error);
2914 : 0 : else if (pt->attr.insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX)
2915 : 0 : flow = rte_flow_async_create_by_index(port_id, queue_id, &op_attr, pt->table,
2916 : : rule_idx, actions, actions_idx, job, &error);
2917 : 0 : else if (pt->attr.insertion_type == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN)
2918 : 0 : flow = rte_flow_async_create_by_index_with_pattern(port_id, queue_id, &op_attr,
2919 : : pt->table, rule_idx, pattern, pattern_idx, actions, actions_idx, job,
2920 : : &error);
2921 : : else {
2922 : 0 : free(pf);
2923 : 0 : free(job);
2924 : 0 : printf("Insertion type %d is invalid\n", pt->attr.insertion_type);
2925 : 0 : return -EINVAL;
2926 : : }
2927 : 0 : if (!flow) {
2928 : 0 : free(pf);
2929 : 0 : free(job);
2930 : 0 : return port_flow_complain(&error);
2931 : : }
2932 : :
2933 : 0 : pf->next = port->flow_list;
2934 : 0 : pf->id = id;
2935 : 0 : pf->table = pt;
2936 : 0 : pf->flow = flow;
2937 : 0 : job->pf = pf;
2938 : 0 : port->flow_list = pf;
2939 : : printf("Flow rule #%"PRIu64" creation enqueued\n", pf->id);
2940 : 0 : return 0;
2941 : : }
2942 : :
2943 : : int
2944 : 0 : port_queue_flow_update_resized(portid_t port_id, queueid_t queue_id,
2945 : : bool postpone, uint32_t flow_id)
2946 : : {
2947 : 0 : const struct rte_flow_op_attr op_attr = { .postpone = postpone };
2948 : 0 : struct rte_flow_error error = { 0, };
2949 : : struct port_flow *pf;
2950 : : struct rte_port *port;
2951 : : struct queue_job *job;
2952 : : int ret;
2953 : :
2954 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2955 : : port_id == (portid_t)RTE_PORT_ALL)
2956 : : return -EINVAL;
2957 : 0 : port = &ports[port_id];
2958 : 0 : if (queue_id >= port->queue_nb) {
2959 : 0 : printf("Queue #%u is invalid\n", queue_id);
2960 : 0 : return -EINVAL;
2961 : : }
2962 : 0 : pf = port_flow_locate(port->flow_list, flow_id);
2963 : 0 : if (!pf)
2964 : : return -EINVAL;
2965 : 0 : job = calloc(1, sizeof(*job));
2966 : 0 : if (!job)
2967 : : return -ENOMEM;
2968 : 0 : job->type = QUEUE_JOB_TYPE_FLOW_TRANSFER;
2969 : 0 : job->pf = pf;
2970 : 0 : ret = rte_flow_async_update_resized(port_id, queue_id, &op_attr,
2971 : : pf->flow, job, &error);
2972 : 0 : if (ret) {
2973 : 0 : free(job);
2974 : 0 : return port_flow_complain(&error);
2975 : : }
2976 : : return 0;
2977 : : }
2978 : :
2979 : : /** Enqueue number of destroy flow rules operations. */
2980 : : int
2981 : 0 : port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
2982 : : bool postpone, uint32_t n, const uint64_t *rule)
2983 : : {
2984 : 0 : struct rte_flow_op_attr op_attr = { .postpone = postpone };
2985 : : struct rte_port *port;
2986 : : struct port_flow **tmp;
2987 : : int ret = 0;
2988 : : struct queue_job *job;
2989 : :
2990 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2991 : : port_id == (portid_t)RTE_PORT_ALL)
2992 : : return -EINVAL;
2993 : 0 : port = &ports[port_id];
2994 : :
2995 : 0 : if (queue_id >= port->queue_nb) {
2996 : 0 : printf("Queue #%u is invalid\n", queue_id);
2997 : 0 : return -EINVAL;
2998 : : }
2999 : :
3000 : 0 : tmp = &port->flow_list;
3001 : 0 : while (*tmp) {
3002 : : uint32_t i;
3003 : :
3004 : 0 : for (i = 0; i != n; ++i) {
3005 : : struct rte_flow_error error;
3006 : 0 : struct port_flow *pf = *tmp;
3007 : :
3008 : 0 : if (rule[i] != pf->id)
3009 : 0 : continue;
3010 : : /*
3011 : : * Poisoning to make sure PMD
3012 : : * update it in case of error.
3013 : : */
3014 : : memset(&error, 0x33, sizeof(error));
3015 : 0 : job = calloc(1, sizeof(*job));
3016 : 0 : if (!job) {
3017 : : printf("Queue flow destroy job allocate failed\n");
3018 : 0 : return -ENOMEM;
3019 : : }
3020 : 0 : job->type = QUEUE_JOB_TYPE_FLOW_DESTROY;
3021 : 0 : job->pf = pf;
3022 : :
3023 : 0 : if (rte_flow_async_destroy(port_id, queue_id, &op_attr,
3024 : : pf->flow, job, &error)) {
3025 : 0 : free(job);
3026 : 0 : ret = port_flow_complain(&error);
3027 : 0 : continue;
3028 : : }
3029 : 0 : printf("Flow rule #%"PRIu64" destruction enqueued\n",
3030 : : pf->id);
3031 : 0 : *tmp = pf->next;
3032 : 0 : break;
3033 : : }
3034 : 0 : if (i == n)
3035 : 0 : tmp = &(*tmp)->next;
3036 : : }
3037 : : return ret;
3038 : : }
3039 : :
3040 : : static void
3041 : : queue_action_handle_create(portid_t port_id, uint32_t queue_id,
3042 : : struct port_indirect_action *pia,
3043 : : struct queue_job *job,
3044 : : const struct rte_flow_op_attr *attr,
3045 : : const struct rte_flow_indir_action_conf *conf,
3046 : : const struct rte_flow_action *action,
3047 : : struct rte_flow_error *error)
3048 : : {
3049 : 0 : if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
3050 : 0 : struct rte_flow_action_age *age =
3051 : : (struct rte_flow_action_age *)(uintptr_t)(action->conf);
3052 : :
3053 : 0 : pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
3054 : 0 : age->context = &pia->age_type;
3055 : : }
3056 : : /* Poisoning to make sure PMDs update it in case of error. */
3057 : 0 : pia->handle = rte_flow_async_action_handle_create(port_id, queue_id,
3058 : : attr, conf, action,
3059 : : job, error);
3060 : 0 : pia->type = action->type;
3061 : 0 : }
3062 : :
3063 : : static void
3064 : : queue_action_list_handle_create(portid_t port_id, uint32_t queue_id,
3065 : : struct port_indirect_action *pia,
3066 : : struct queue_job *job,
3067 : : const struct rte_flow_op_attr *attr,
3068 : : const struct rte_flow_indir_action_conf *conf,
3069 : : const struct rte_flow_action *action,
3070 : : struct rte_flow_error *error)
3071 : : {
3072 : : /* Poisoning to make sure PMDs update it in case of error. */
3073 : 0 : pia->type = RTE_FLOW_ACTION_TYPE_INDIRECT_LIST;
3074 : 0 : pia->list_handle = rte_flow_async_action_list_handle_create
3075 : : (port_id, queue_id, attr, conf, action,
3076 : : job, error);
3077 : 0 : }
3078 : :
3079 : : /** Enqueue update flow rule operation. */
3080 : : int
3081 : 0 : port_queue_flow_update(portid_t port_id, queueid_t queue_id,
3082 : : bool postpone, uint32_t rule_idx, uint32_t actions_idx,
3083 : : const struct rte_flow_action *actions)
3084 : : {
3085 : 0 : struct rte_flow_op_attr op_attr = { .postpone = postpone };
3086 : : struct rte_port *port;
3087 : : struct port_flow *pf, *uf;
3088 : : struct port_flow **tmp;
3089 : : struct port_table *pt;
3090 : : bool found;
3091 : 0 : struct rte_flow_error error = { RTE_FLOW_ERROR_TYPE_NONE, NULL, NULL };
3092 : : struct rte_flow_action_age *age = age_action_get(actions);
3093 : : struct queue_job *job;
3094 : :
3095 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3096 : : port_id == (portid_t)RTE_PORT_ALL)
3097 : : return -EINVAL;
3098 : 0 : port = &ports[port_id];
3099 : :
3100 : 0 : if (queue_id >= port->queue_nb) {
3101 : 0 : printf("Queue #%u is invalid\n", queue_id);
3102 : 0 : return -EINVAL;
3103 : : }
3104 : :
3105 : : found = false;
3106 : 0 : tmp = &port->flow_list;
3107 : 0 : while (*tmp) {
3108 : : pf = *tmp;
3109 : 0 : if (rule_idx == pf->id) {
3110 : : found = true;
3111 : : break;
3112 : : }
3113 : 0 : tmp = &(*tmp)->next;
3114 : : }
3115 : 0 : if (!found) {
3116 : : printf("Flow rule #%u is invalid\n", rule_idx);
3117 : 0 : return -EINVAL;
3118 : : }
3119 : :
3120 : 0 : pt = pf->table;
3121 : 0 : if (actions_idx >= pt->nb_actions_templates) {
3122 : : printf("Actions template index #%u is invalid,"
3123 : : " %u templates present in the table\n",
3124 : : actions_idx, pt->nb_actions_templates);
3125 : 0 : return -EINVAL;
3126 : : }
3127 : :
3128 : 0 : job = calloc(1, sizeof(*job));
3129 : 0 : if (!job) {
3130 : : printf("Queue flow create job allocate failed\n");
3131 : 0 : return -ENOMEM;
3132 : : }
3133 : 0 : job->type = QUEUE_JOB_TYPE_FLOW_UPDATE;
3134 : :
3135 : 0 : uf = port_flow_new(&pt->attr.flow_attr, pf->rule.pattern_ro, actions, &error);
3136 : 0 : if (!uf) {
3137 : 0 : free(job);
3138 : 0 : return port_flow_complain(&error);
3139 : : }
3140 : :
3141 : 0 : if (age) {
3142 : 0 : uf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
3143 : 0 : age->context = &uf->age_type;
3144 : : }
3145 : :
3146 : : /*
3147 : : * Poisoning to make sure PMD update it in case of error.
3148 : : */
3149 : : memset(&error, 0x44, sizeof(error));
3150 : 0 : if (rte_flow_async_actions_update(port_id, queue_id, &op_attr, pf->flow,
3151 : : actions, actions_idx, job, &error)) {
3152 : 0 : free(uf);
3153 : 0 : free(job);
3154 : 0 : return port_flow_complain(&error);
3155 : : }
3156 : 0 : uf->next = pf->next;
3157 : 0 : uf->id = pf->id;
3158 : 0 : uf->table = pt;
3159 : 0 : uf->flow = pf->flow;
3160 : 0 : *tmp = uf;
3161 : 0 : job->pf = pf;
3162 : :
3163 : 0 : printf("Flow rule #%"PRIu64" update enqueued\n", pf->id);
3164 : 0 : return 0;
3165 : : }
3166 : :
3167 : : /** Enqueue indirect action create operation. */
3168 : : int
3169 : 0 : port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
3170 : : bool postpone, uint32_t id,
3171 : : bool indirect_list,
3172 : : const struct rte_flow_indir_action_conf *conf,
3173 : : const struct rte_flow_action *action)
3174 : : {
3175 : 0 : const struct rte_flow_op_attr attr = { .postpone = postpone};
3176 : : struct rte_port *port;
3177 : : struct port_indirect_action *pia;
3178 : : int ret;
3179 : : struct rte_flow_error error;
3180 : : struct queue_job *job;
3181 : :
3182 : 0 : ret = action_alloc(port_id, id, &pia);
3183 : 0 : if (ret)
3184 : : return ret;
3185 : :
3186 : 0 : port = &ports[port_id];
3187 : 0 : if (queue_id >= port->queue_nb) {
3188 : : printf("Queue #%u is invalid\n", queue_id);
3189 : 0 : return -EINVAL;
3190 : : }
3191 : 0 : job = calloc(1, sizeof(*job));
3192 : 0 : if (!job) {
3193 : : printf("Queue action create job allocate failed\n");
3194 : 0 : return -ENOMEM;
3195 : : }
3196 : 0 : job->type = QUEUE_JOB_TYPE_ACTION_CREATE;
3197 : 0 : job->pia = pia;
3198 : :
3199 : : /* Poisoning to make sure PMDs update it in case of error. */
3200 : : memset(&error, 0x88, sizeof(error));
3201 : :
3202 : 0 : if (indirect_list)
3203 : : queue_action_list_handle_create(port_id, queue_id, pia, job,
3204 : : &attr, conf, action, &error);
3205 : : else
3206 : : queue_action_handle_create(port_id, queue_id, pia, job, &attr,
3207 : : conf, action, &error);
3208 : :
3209 : 0 : if (!pia->handle) {
3210 : 0 : uint32_t destroy_id = pia->id;
3211 : 0 : port_queue_action_handle_destroy(port_id, queue_id,
3212 : : postpone, 1, &destroy_id);
3213 : 0 : free(job);
3214 : 0 : return port_flow_complain(&error);
3215 : : }
3216 : 0 : printf("Indirect action #%u creation queued\n", pia->id);
3217 : 0 : return 0;
3218 : : }
3219 : :
3220 : : /** Enqueue indirect action destroy operation. */
3221 : : int
3222 : 0 : port_queue_action_handle_destroy(portid_t port_id,
3223 : : uint32_t queue_id, bool postpone,
3224 : : uint32_t n, const uint32_t *actions)
3225 : : {
3226 : 0 : const struct rte_flow_op_attr attr = { .postpone = postpone};
3227 : : struct rte_port *port;
3228 : : struct port_indirect_action **tmp;
3229 : : int ret = 0;
3230 : : struct queue_job *job;
3231 : :
3232 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3233 : : port_id == (portid_t)RTE_PORT_ALL)
3234 : : return -EINVAL;
3235 : 0 : port = &ports[port_id];
3236 : :
3237 : 0 : if (queue_id >= port->queue_nb) {
3238 : : printf("Queue #%u is invalid\n", queue_id);
3239 : 0 : return -EINVAL;
3240 : : }
3241 : :
3242 : 0 : tmp = &port->actions_list;
3243 : 0 : while (*tmp) {
3244 : : uint32_t i;
3245 : :
3246 : 0 : for (i = 0; i != n; ++i) {
3247 : : struct rte_flow_error error;
3248 : 0 : struct port_indirect_action *pia = *tmp;
3249 : :
3250 : 0 : if (actions[i] != pia->id)
3251 : 0 : continue;
3252 : : /*
3253 : : * Poisoning to make sure PMDs update it in case
3254 : : * of error.
3255 : : */
3256 : : memset(&error, 0x99, sizeof(error));
3257 : 0 : job = calloc(1, sizeof(*job));
3258 : 0 : if (!job) {
3259 : : printf("Queue action destroy job allocate failed\n");
3260 : 0 : return -ENOMEM;
3261 : : }
3262 : 0 : job->type = QUEUE_JOB_TYPE_ACTION_DESTROY;
3263 : 0 : job->pia = pia;
3264 : 0 : ret = pia->type == RTE_FLOW_ACTION_TYPE_INDIRECT_LIST ?
3265 : 0 : rte_flow_async_action_list_handle_destroy
3266 : : (port_id, queue_id,
3267 : : &attr, pia->list_handle,
3268 : 0 : job, &error) :
3269 : 0 : rte_flow_async_action_handle_destroy
3270 : : (port_id, queue_id, &attr, pia->handle,
3271 : : job, &error);
3272 : 0 : if (ret) {
3273 : 0 : free(job);
3274 : 0 : ret = port_flow_complain(&error);
3275 : 0 : continue;
3276 : : }
3277 : 0 : *tmp = pia->next;
3278 : 0 : printf("Indirect action #%u destruction queued\n",
3279 : : pia->id);
3280 : 0 : break;
3281 : : }
3282 : 0 : if (i == n)
3283 : 0 : tmp = &(*tmp)->next;
3284 : : }
3285 : : return ret;
3286 : : }
3287 : :
3288 : : /** Enqueue indirect action update operation. */
3289 : : int
3290 : 0 : port_queue_action_handle_update(portid_t port_id,
3291 : : uint32_t queue_id, bool postpone, uint32_t id,
3292 : : const struct rte_flow_action *action)
3293 : : {
3294 : 0 : const struct rte_flow_op_attr attr = { .postpone = postpone};
3295 : : struct rte_port *port;
3296 : : struct rte_flow_error error;
3297 : : struct rte_flow_action_handle *action_handle;
3298 : : struct queue_job *job;
3299 : : struct port_indirect_action *pia;
3300 : : struct rte_flow_update_meter_mark mtr_update;
3301 : : const void *update;
3302 : :
3303 : 0 : action_handle = port_action_handle_get_by_id(port_id, id);
3304 : 0 : if (!action_handle)
3305 : : return -EINVAL;
3306 : :
3307 : 0 : port = &ports[port_id];
3308 : 0 : if (queue_id >= port->queue_nb) {
3309 : : printf("Queue #%u is invalid\n", queue_id);
3310 : 0 : return -EINVAL;
3311 : : }
3312 : :
3313 : 0 : job = calloc(1, sizeof(*job));
3314 : 0 : if (!job) {
3315 : : printf("Queue action update job allocate failed\n");
3316 : 0 : return -ENOMEM;
3317 : : }
3318 : 0 : job->type = QUEUE_JOB_TYPE_ACTION_UPDATE;
3319 : :
3320 : 0 : pia = action_get_by_id(port_id, id);
3321 : 0 : if (!pia) {
3322 : 0 : free(job);
3323 : 0 : return -EINVAL;
3324 : : }
3325 : :
3326 : 0 : switch (pia->type) {
3327 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
3328 : 0 : update = action->conf;
3329 : 0 : break;
3330 : 0 : case RTE_FLOW_ACTION_TYPE_METER_MARK:
3331 : 0 : rte_memcpy(&mtr_update.meter_mark, action->conf,
3332 : : sizeof(struct rte_flow_action_meter_mark));
3333 : 0 : if (mtr_update.meter_mark.profile)
3334 : 0 : mtr_update.profile_valid = 1;
3335 : 0 : if (mtr_update.meter_mark.policy)
3336 : 0 : mtr_update.policy_valid = 1;
3337 : 0 : mtr_update.color_mode_valid = 1;
3338 : 0 : mtr_update.state_valid = 1;
3339 : : update = &mtr_update;
3340 : 0 : break;
3341 : : default:
3342 : : update = action;
3343 : : break;
3344 : : }
3345 : :
3346 : 0 : if (rte_flow_async_action_handle_update(port_id, queue_id, &attr,
3347 : : action_handle, update, job, &error)) {
3348 : 0 : free(job);
3349 : 0 : return port_flow_complain(&error);
3350 : : }
3351 : : printf("Indirect action #%u update queued\n", id);
3352 : 0 : return 0;
3353 : : }
3354 : :
3355 : : void
3356 : 0 : port_queue_action_handle_query_update(portid_t port_id,
3357 : : uint32_t queue_id, bool postpone,
3358 : : uint32_t id,
3359 : : enum rte_flow_query_update_mode qu_mode,
3360 : : const struct rte_flow_action *action)
3361 : : {
3362 : : int ret;
3363 : : struct rte_flow_error error;
3364 : 0 : struct port_indirect_action *pia = action_get_by_id(port_id, id);
3365 : 0 : const struct rte_flow_op_attr attr = { .postpone = postpone};
3366 : : struct queue_job *job;
3367 : :
3368 : 0 : if (!pia || !pia->handle)
3369 : 0 : return;
3370 : 0 : job = calloc(1, sizeof(*job));
3371 : 0 : if (!job)
3372 : : return;
3373 : 0 : job->type = QUEUE_JOB_TYPE_ACTION_QUERY;
3374 : 0 : job->pia = pia;
3375 : :
3376 : 0 : ret = rte_flow_async_action_handle_query_update(port_id, queue_id,
3377 : : &attr, pia->handle,
3378 : : action,
3379 : 0 : &job->query,
3380 : : qu_mode, job,
3381 : : &error);
3382 : 0 : if (ret) {
3383 : 0 : port_flow_complain(&error);
3384 : 0 : free(job);
3385 : : } else {
3386 : : printf("port-%u: indirect action #%u update-and-query queued\n",
3387 : : port_id, id);
3388 : : }
3389 : : }
3390 : :
3391 : : /** Enqueue indirect action query operation. */
3392 : : int
3393 : 0 : port_queue_action_handle_query(portid_t port_id,
3394 : : uint32_t queue_id, bool postpone, uint32_t id)
3395 : : {
3396 : 0 : const struct rte_flow_op_attr attr = { .postpone = postpone};
3397 : : struct rte_port *port;
3398 : : struct rte_flow_error error;
3399 : : struct rte_flow_action_handle *action_handle;
3400 : : struct port_indirect_action *pia;
3401 : : struct queue_job *job;
3402 : :
3403 : 0 : pia = action_get_by_id(port_id, id);
3404 : 0 : action_handle = pia ? pia->handle : NULL;
3405 : 0 : if (!action_handle)
3406 : : return -EINVAL;
3407 : :
3408 : 0 : port = &ports[port_id];
3409 : 0 : if (queue_id >= port->queue_nb) {
3410 : : printf("Queue #%u is invalid\n", queue_id);
3411 : 0 : return -EINVAL;
3412 : : }
3413 : :
3414 : 0 : job = calloc(1, sizeof(*job));
3415 : 0 : if (!job) {
3416 : : printf("Queue action update job allocate failed\n");
3417 : 0 : return -ENOMEM;
3418 : : }
3419 : 0 : job->type = QUEUE_JOB_TYPE_ACTION_QUERY;
3420 : 0 : job->pia = pia;
3421 : :
3422 : 0 : if (rte_flow_async_action_handle_query(port_id, queue_id, &attr,
3423 : 0 : action_handle, &job->query, job, &error)) {
3424 : 0 : free(job);
3425 : 0 : return port_flow_complain(&error);
3426 : : }
3427 : : printf("Indirect action #%u update queued\n", id);
3428 : 0 : return 0;
3429 : : }
3430 : :
3431 : : /** Push all the queue operations in the queue to the NIC. */
3432 : : int
3433 : 0 : port_queue_flow_push(portid_t port_id, queueid_t queue_id)
3434 : : {
3435 : : struct rte_port *port;
3436 : : struct rte_flow_error error;
3437 : : int ret = 0;
3438 : :
3439 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3440 : : port_id == (portid_t)RTE_PORT_ALL)
3441 : : return -EINVAL;
3442 : 0 : port = &ports[port_id];
3443 : :
3444 : 0 : if (queue_id >= port->queue_nb) {
3445 : 0 : printf("Queue #%u is invalid\n", queue_id);
3446 : 0 : return -EINVAL;
3447 : : }
3448 : :
3449 : : memset(&error, 0x55, sizeof(error));
3450 : 0 : ret = rte_flow_push(port_id, queue_id, &error);
3451 : 0 : if (ret < 0) {
3452 : : printf("Failed to push operations in the queue\n");
3453 : 0 : return -EINVAL;
3454 : : }
3455 : 0 : printf("Queue #%u operations pushed\n", queue_id);
3456 : 0 : return ret;
3457 : : }
3458 : :
3459 : : /** Calculate the hash result for a given pattern in a given table. */
3460 : : int
3461 : 0 : port_flow_hash_calc(portid_t port_id, uint32_t table_id,
3462 : : uint8_t pattern_template_index, const struct rte_flow_item pattern[])
3463 : : {
3464 : : uint32_t hash;
3465 : : bool found;
3466 : : struct port_table *pt;
3467 : : struct rte_port *port;
3468 : : struct rte_flow_error error;
3469 : : int ret = 0;
3470 : :
3471 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3472 : : port_id == (portid_t)RTE_PORT_ALL)
3473 : : return -EINVAL;
3474 : 0 : port = &ports[port_id];
3475 : :
3476 : : found = false;
3477 : 0 : pt = port->table_list;
3478 : 0 : while (pt) {
3479 : 0 : if (table_id == pt->id) {
3480 : : found = true;
3481 : : break;
3482 : : }
3483 : 0 : pt = pt->next;
3484 : : }
3485 : 0 : if (!found) {
3486 : : printf("Table #%u is invalid\n", table_id);
3487 : 0 : return -EINVAL;
3488 : : }
3489 : :
3490 : : memset(&error, 0x55, sizeof(error));
3491 : 0 : ret = rte_flow_calc_table_hash(port_id, pt->table, pattern,
3492 : : pattern_template_index, &hash, &error);
3493 : 0 : if (ret < 0) {
3494 : : printf("Failed to calculate hash ");
3495 : 0 : switch (abs(ret)) {
3496 : : case ENODEV:
3497 : : printf("no such device\n");
3498 : : break;
3499 : : case ENOTSUP:
3500 : : printf("device doesn't support this operation\n");
3501 : : break;
3502 : : default:
3503 : : printf("\n");
3504 : : break;
3505 : : }
3506 : 0 : return ret;
3507 : : }
3508 : 0 : printf("Hash results 0x%x\n", hash);
3509 : 0 : return 0;
3510 : : }
3511 : :
3512 : : /** Calculate the encap hash result for a given pattern. */
3513 : : int
3514 : 0 : port_flow_hash_calc_encap(portid_t port_id,
3515 : : enum rte_flow_encap_hash_field encap_hash_field,
3516 : : const struct rte_flow_item pattern[])
3517 : : {
3518 : : struct rte_flow_error error;
3519 : : int ret = 0;
3520 : 0 : uint16_t hash = 0;
3521 : 0 : uint8_t len = encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ? 2 : 1;
3522 : :
3523 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3524 : : port_id == (portid_t)RTE_PORT_ALL) {
3525 : : printf("Failed to calculate encap hash - not a valid port");
3526 : 0 : return -EINVAL;
3527 : : }
3528 : :
3529 : 0 : ret = rte_flow_calc_encap_hash(port_id, pattern, encap_hash_field, len,
3530 : : (uint8_t *)&hash, &error);
3531 : 0 : if (ret < 0) {
3532 : : printf("Failed to calculate encap hash");
3533 : 0 : return ret;
3534 : : }
3535 : 0 : if (encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT)
3536 : 0 : printf("encap hash result %#x\n", hash);
3537 : : else
3538 : 0 : printf("encap hash result %#x\n", *(uint8_t *)&hash);
3539 : : return 0;
3540 : : }
3541 : :
3542 : : /** Pull queue operation results from the queue. */
3543 : : static int
3544 : 0 : port_queue_aged_flow_destroy(portid_t port_id, queueid_t queue_id,
3545 : : const uint64_t *rule, int nb_flows)
3546 : : {
3547 : 0 : struct rte_port *port = &ports[port_id];
3548 : : struct rte_flow_op_result *res;
3549 : : struct rte_flow_error error;
3550 : 0 : uint32_t n = nb_flows;
3551 : : int ret = 0;
3552 : : int i;
3553 : :
3554 : 0 : res = calloc(port->queue_sz, sizeof(struct rte_flow_op_result));
3555 : 0 : if (!res) {
3556 : : printf("Failed to allocate memory for pulled results\n");
3557 : 0 : return -ENOMEM;
3558 : : }
3559 : :
3560 : : memset(&error, 0x66, sizeof(error));
3561 : 0 : while (nb_flows > 0) {
3562 : : int success = 0;
3563 : :
3564 : 0 : if (n > port->queue_sz)
3565 : : n = port->queue_sz;
3566 : 0 : ret = port_queue_flow_destroy(port_id, queue_id, true, n, rule);
3567 : 0 : if (ret < 0) {
3568 : 0 : free(res);
3569 : 0 : return ret;
3570 : : }
3571 : 0 : ret = rte_flow_push(port_id, queue_id, &error);
3572 : 0 : if (ret < 0) {
3573 : 0 : printf("Failed to push operations in the queue: %s\n",
3574 : : strerror(-ret));
3575 : 0 : free(res);
3576 : 0 : return ret;
3577 : : }
3578 : 0 : while (success < nb_flows) {
3579 : 0 : ret = rte_flow_pull(port_id, queue_id, res,
3580 : 0 : port->queue_sz, &error);
3581 : 0 : if (ret < 0) {
3582 : 0 : printf("Failed to pull a operation results: %s\n",
3583 : : strerror(-ret));
3584 : 0 : free(res);
3585 : 0 : return ret;
3586 : : }
3587 : :
3588 : 0 : for (i = 0; i < ret; i++) {
3589 : 0 : if (res[i].status == RTE_FLOW_OP_SUCCESS)
3590 : 0 : success++;
3591 : : }
3592 : : }
3593 : 0 : rule += n;
3594 : 0 : nb_flows -= n;
3595 : : n = nb_flows;
3596 : : }
3597 : :
3598 : 0 : free(res);
3599 : 0 : return ret;
3600 : : }
3601 : :
3602 : : /** List simply and destroy all aged flows per queue. */
3603 : : void
3604 : 0 : port_queue_flow_aged(portid_t port_id, uint32_t queue_id, uint8_t destroy)
3605 : : {
3606 : : void **contexts;
3607 : : int nb_context, total = 0, idx;
3608 : : uint64_t *rules = NULL;
3609 : : struct rte_port *port;
3610 : : struct rte_flow_error error;
3611 : : enum age_action_context_type *type;
3612 : : union {
3613 : : struct port_flow *pf;
3614 : : struct port_indirect_action *pia;
3615 : : } ctx;
3616 : :
3617 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3618 : : port_id == (portid_t)RTE_PORT_ALL)
3619 : 0 : return;
3620 : 0 : port = &ports[port_id];
3621 : 0 : if (queue_id >= port->queue_nb) {
3622 : : printf("Error: queue #%u is invalid\n", queue_id);
3623 : 0 : return;
3624 : : }
3625 : 0 : total = rte_flow_get_q_aged_flows(port_id, queue_id, NULL, 0, &error);
3626 : 0 : if (total < 0) {
3627 : 0 : port_flow_complain(&error);
3628 : 0 : return;
3629 : : }
3630 : : printf("Port %u queue %u total aged flows: %d\n",
3631 : : port_id, queue_id, total);
3632 : 0 : if (total == 0)
3633 : : return;
3634 : 0 : contexts = calloc(total, sizeof(void *));
3635 : 0 : if (contexts == NULL) {
3636 : : printf("Cannot allocate contexts for aged flow\n");
3637 : 0 : return;
3638 : : }
3639 : : printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
3640 : 0 : nb_context = rte_flow_get_q_aged_flows(port_id, queue_id, contexts,
3641 : : total, &error);
3642 : 0 : if (nb_context > total) {
3643 : : printf("Port %u queue %u get aged flows count(%d) > total(%d)\n",
3644 : : port_id, queue_id, nb_context, total);
3645 : 0 : free(contexts);
3646 : 0 : return;
3647 : : }
3648 : 0 : if (destroy) {
3649 : 0 : rules = malloc(sizeof(uint32_t) * nb_context);
3650 : 0 : if (rules == NULL)
3651 : : printf("Cannot allocate memory for destroy aged flow\n");
3652 : : }
3653 : : total = 0;
3654 : 0 : for (idx = 0; idx < nb_context; idx++) {
3655 : 0 : if (!contexts[idx]) {
3656 : : printf("Error: get Null context in port %u queue %u\n",
3657 : : port_id, queue_id);
3658 : 0 : continue;
3659 : : }
3660 : : type = (enum age_action_context_type *)contexts[idx];
3661 : 0 : switch (*type) {
3662 : 0 : case ACTION_AGE_CONTEXT_TYPE_FLOW:
3663 : 0 : ctx.pf = container_of(type, struct port_flow, age_type);
3664 : 0 : printf("%-20s\t%" PRIu64 "\t%" PRIu32 "\t%" PRIu32
3665 : : "\t%c%c%c\t\n",
3666 : : "Flow",
3667 : : ctx.pf->id,
3668 : : ctx.pf->rule.attr->group,
3669 : : ctx.pf->rule.attr->priority,
3670 : 0 : ctx.pf->rule.attr->ingress ? 'i' : '-',
3671 : 0 : ctx.pf->rule.attr->egress ? 'e' : '-',
3672 : 0 : ctx.pf->rule.attr->transfer ? 't' : '-');
3673 : 0 : if (rules != NULL) {
3674 : 0 : rules[total] = ctx.pf->id;
3675 : 0 : total++;
3676 : : }
3677 : : break;
3678 : 0 : case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
3679 : 0 : ctx.pia = container_of(type,
3680 : : struct port_indirect_action,
3681 : : age_type);
3682 : 0 : printf("%-20s\t%" PRIu32 "\n", "Indirect action",
3683 : : ctx.pia->id);
3684 : : break;
3685 : 0 : default:
3686 : : printf("Error: invalid context type %u\n", port_id);
3687 : : break;
3688 : : }
3689 : : }
3690 : 0 : if (rules != NULL) {
3691 : 0 : port_queue_aged_flow_destroy(port_id, queue_id, rules, total);
3692 : 0 : free(rules);
3693 : : }
3694 : : printf("\n%d flows destroyed\n", total);
3695 : 0 : free(contexts);
3696 : : }
3697 : :
3698 : : /** Pull queue operation results from the queue. */
3699 : : int
3700 : 0 : port_queue_flow_pull(portid_t port_id, queueid_t queue_id)
3701 : : {
3702 : : struct rte_port *port;
3703 : : struct rte_flow_op_result *res;
3704 : : struct rte_flow_error error;
3705 : : int ret = 0;
3706 : : int success = 0;
3707 : : int i;
3708 : : struct queue_job *job;
3709 : :
3710 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3711 : : port_id == (portid_t)RTE_PORT_ALL)
3712 : : return -EINVAL;
3713 : 0 : port = &ports[port_id];
3714 : :
3715 : 0 : if (queue_id >= port->queue_nb) {
3716 : 0 : printf("Queue #%u is invalid\n", queue_id);
3717 : 0 : return -EINVAL;
3718 : : }
3719 : :
3720 : 0 : res = calloc(port->queue_sz, sizeof(struct rte_flow_op_result));
3721 : 0 : if (!res) {
3722 : : printf("Failed to allocate memory for pulled results\n");
3723 : 0 : return -ENOMEM;
3724 : : }
3725 : :
3726 : : memset(&error, 0x66, sizeof(error));
3727 : 0 : ret = rte_flow_pull(port_id, queue_id, res,
3728 : : port->queue_sz, &error);
3729 : 0 : if (ret < 0) {
3730 : : printf("Failed to pull a operation results\n");
3731 : 0 : free(res);
3732 : 0 : return -EINVAL;
3733 : : }
3734 : :
3735 : 0 : for (i = 0; i < ret; i++) {
3736 : 0 : if (res[i].status == RTE_FLOW_OP_SUCCESS)
3737 : 0 : success++;
3738 : 0 : job = (struct queue_job *)res[i].user_data;
3739 : 0 : if (job->type == QUEUE_JOB_TYPE_FLOW_DESTROY ||
3740 : : job->type == QUEUE_JOB_TYPE_FLOW_UPDATE)
3741 : 0 : free(job->pf);
3742 : 0 : else if (job->type == QUEUE_JOB_TYPE_ACTION_DESTROY)
3743 : 0 : free(job->pia);
3744 : 0 : else if (job->type == QUEUE_JOB_TYPE_ACTION_QUERY)
3745 : 0 : port_action_handle_query_dump(port_id, job->pia,
3746 : : &job->query);
3747 : 0 : free(job);
3748 : : }
3749 : 0 : printf("Queue #%u pulled %u operations (%u failed, %u succeeded)\n",
3750 : : queue_id, ret, ret - success, success);
3751 : 0 : free(res);
3752 : 0 : return ret;
3753 : : }
3754 : :
3755 : : /* Set group miss actions */
3756 : : int
3757 : 0 : port_queue_group_set_miss_actions(portid_t port_id, const struct rte_flow_attr *attr,
3758 : : const struct rte_flow_action *actions)
3759 : : {
3760 : 0 : struct rte_flow_group_attr gattr = {
3761 : 0 : .ingress = attr->ingress,
3762 : 0 : .egress = attr->egress,
3763 : 0 : .transfer = attr->transfer,
3764 : : };
3765 : : struct rte_flow_error error;
3766 : : int ret = 0;
3767 : :
3768 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3769 : : port_id == (portid_t)RTE_PORT_ALL)
3770 : : return -EINVAL;
3771 : :
3772 : : memset(&error, 0x66, sizeof(error));
3773 : 0 : ret = rte_flow_group_set_miss_actions(port_id, attr->group, &gattr, actions, &error);
3774 : :
3775 : 0 : if (ret < 0)
3776 : 0 : return port_flow_complain(&error);
3777 : :
3778 : 0 : printf("Group #%u set miss actions succeeded\n", attr->group);
3779 : 0 : return ret;
3780 : : }
3781 : :
3782 : : /** Create flow rule. */
3783 : : int
3784 : 0 : port_flow_create(portid_t port_id,
3785 : : const struct rte_flow_attr *attr,
3786 : : const struct rte_flow_item *pattern,
3787 : : const struct rte_flow_action *actions,
3788 : : const struct tunnel_ops *tunnel_ops,
3789 : : uintptr_t user_id)
3790 : : {
3791 : : struct rte_flow *flow;
3792 : : struct rte_port *port;
3793 : : struct port_flow *pf;
3794 : : uint32_t id = 0;
3795 : : struct rte_flow_error error;
3796 : : struct port_flow_tunnel *pft = NULL;
3797 : : struct rte_flow_action_age *age = age_action_get(actions);
3798 : :
3799 : 0 : port = &ports[port_id];
3800 : 0 : if (port->flow_list) {
3801 : 0 : if (port->flow_list->id == UINT32_MAX) {
3802 : 0 : fprintf(stderr,
3803 : : "Highest rule ID is already assigned, delete it first");
3804 : 0 : return -ENOMEM;
3805 : : }
3806 : 0 : id = port->flow_list->id + 1;
3807 : : }
3808 : 0 : if (tunnel_ops->enabled) {
3809 : 0 : pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
3810 : : actions, tunnel_ops);
3811 : 0 : if (!pft)
3812 : : return -ENOENT;
3813 : 0 : if (pft->items)
3814 : : pattern = pft->items;
3815 : 0 : if (pft->actions)
3816 : : actions = pft->actions;
3817 : : }
3818 : 0 : pf = port_flow_new(attr, pattern, actions, &error);
3819 : 0 : if (!pf)
3820 : 0 : return port_flow_complain(&error);
3821 : 0 : if (age) {
3822 : 0 : pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
3823 : 0 : age->context = &pf->age_type;
3824 : : }
3825 : : /* Poisoning to make sure PMDs update it in case of error. */
3826 : : memset(&error, 0x22, sizeof(error));
3827 : 0 : flow = rte_flow_create(port_id, attr, pattern, actions, &error);
3828 : 0 : if (!flow) {
3829 : 0 : if (tunnel_ops->enabled)
3830 : 0 : port_flow_tunnel_offload_cmd_release(port_id,
3831 : : tunnel_ops, pft);
3832 : 0 : free(pf);
3833 : 0 : return port_flow_complain(&error);
3834 : : }
3835 : 0 : pf->next = port->flow_list;
3836 : 0 : pf->id = id;
3837 : 0 : pf->user_id = user_id;
3838 : 0 : pf->flow = flow;
3839 : 0 : port->flow_list = pf;
3840 : 0 : if (tunnel_ops->enabled)
3841 : 0 : port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
3842 : 0 : if (user_id)
3843 : 0 : printf("Flow rule #%"PRIu64" created, user-id 0x%"PRIx64"\n",
3844 : : pf->id, pf->user_id);
3845 : : else
3846 : 0 : printf("Flow rule #%"PRIu64" created\n", pf->id);
3847 : : return 0;
3848 : : }
3849 : :
3850 : : /** Destroy a number of flow rules. */
3851 : : int
3852 : 0 : port_flow_destroy(portid_t port_id, uint32_t n, const uint64_t *rule,
3853 : : bool is_user_id)
3854 : : {
3855 : : struct rte_port *port;
3856 : : struct port_flow **tmp;
3857 : : int ret = 0;
3858 : :
3859 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3860 : : port_id == (portid_t)RTE_PORT_ALL)
3861 : : return -EINVAL;
3862 : 0 : port = &ports[port_id];
3863 : 0 : tmp = &port->flow_list;
3864 : 0 : while (*tmp) {
3865 : : uint32_t i;
3866 : :
3867 : 0 : for (i = 0; i != n; ++i) {
3868 : : struct rte_flow_error error;
3869 : 0 : struct port_flow *pf = *tmp;
3870 : :
3871 : 0 : if (rule[i] != (is_user_id ? pf->user_id : pf->id))
3872 : 0 : continue;
3873 : : /*
3874 : : * Poisoning to make sure PMDs update it in case
3875 : : * of error.
3876 : : */
3877 : : memset(&error, 0x33, sizeof(error));
3878 : 0 : if (rte_flow_destroy(port_id, pf->flow, &error)) {
3879 : 0 : ret = port_flow_complain(&error);
3880 : 0 : continue;
3881 : : }
3882 : 0 : if (is_user_id)
3883 : 0 : printf("Flow rule #%"PRIu64" destroyed, "
3884 : : "user-id 0x%"PRIx64"\n",
3885 : : pf->id, pf->user_id);
3886 : : else
3887 : 0 : printf("Flow rule #%"PRIu64" destroyed\n",
3888 : : pf->id);
3889 : 0 : *tmp = pf->next;
3890 : 0 : free(pf);
3891 : 0 : break;
3892 : : }
3893 : 0 : if (i == n)
3894 : 0 : tmp = &(*tmp)->next;
3895 : : }
3896 : : return ret;
3897 : : }
3898 : :
3899 : : /** Update a flow rule with new actions. */
3900 : : int
3901 : 0 : port_flow_update(portid_t port_id, uint32_t rule_id,
3902 : : const struct rte_flow_action *actions, bool is_user_id)
3903 : : {
3904 : : struct rte_port *port;
3905 : : struct port_flow **flow_list, *uf;
3906 : : struct rte_flow_action_age *age = age_action_get(actions);
3907 : :
3908 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3909 : : port_id == (portid_t)RTE_PORT_ALL)
3910 : : return -EINVAL;
3911 : 0 : port = &ports[port_id];
3912 : 0 : flow_list = &port->flow_list;
3913 : 0 : while (*flow_list) {
3914 : : struct port_flow *flow = *flow_list;
3915 : : struct rte_flow_error error;
3916 : :
3917 : 0 : if (rule_id != (is_user_id ? flow->user_id : flow->id)) {
3918 : 0 : flow_list = &flow->next;
3919 : 0 : continue;
3920 : : }
3921 : :
3922 : : /* Update flow action(s) with new action(s) */
3923 : 0 : uf = port_flow_new(flow->rule.attr_ro, flow->rule.pattern_ro, actions, &error);
3924 : 0 : if (!uf)
3925 : 0 : return port_flow_complain(&error);
3926 : 0 : if (age) {
3927 : 0 : flow->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
3928 : 0 : age->context = &flow->age_type;
3929 : : }
3930 : :
3931 : : /*
3932 : : * Poisoning to make sure PMDs update it in case
3933 : : * of error.
3934 : : */
3935 : : memset(&error, 0x33, sizeof(error));
3936 : 0 : if (rte_flow_actions_update(port_id, flow->flow, actions,
3937 : : &error))
3938 : 0 : return port_flow_complain(&error);
3939 : 0 : if (is_user_id)
3940 : 0 : printf("Flow rule #%"PRIu64" updated with new actions,"
3941 : : " user-id 0x%"PRIx64"\n",
3942 : : flow->id, flow->user_id);
3943 : : else
3944 : 0 : printf("Flow rule #%"PRIu64
3945 : : " updated with new actions\n",
3946 : : flow->id);
3947 : :
3948 : 0 : uf->next = flow->next;
3949 : 0 : uf->id = flow->id;
3950 : 0 : uf->user_id = flow->user_id;
3951 : 0 : uf->flow = flow->flow;
3952 : 0 : *flow_list = uf;
3953 : :
3954 : 0 : free(flow);
3955 : 0 : return 0;
3956 : : }
3957 : : printf("Failed to find flow %"PRIu32"\n", rule_id);
3958 : 0 : return -EINVAL;
3959 : : }
3960 : :
3961 : : /** Remove all flow rules. */
3962 : : int
3963 : 0 : port_flow_flush(portid_t port_id)
3964 : : {
3965 : : struct rte_flow_error error;
3966 : : struct rte_port *port;
3967 : : int ret = 0;
3968 : :
3969 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3970 : : port_id == (portid_t)RTE_PORT_ALL)
3971 : : return -EINVAL;
3972 : :
3973 : 0 : port = &ports[port_id];
3974 : :
3975 : 0 : if (port->flow_list == NULL)
3976 : : return ret;
3977 : :
3978 : : /* Poisoning to make sure PMDs update it in case of error. */
3979 : : memset(&error, 0x44, sizeof(error));
3980 : 0 : if (rte_flow_flush(port_id, &error)) {
3981 : 0 : port_flow_complain(&error);
3982 : : }
3983 : :
3984 : 0 : while (port->flow_list) {
3985 : 0 : struct port_flow *pf = port->flow_list->next;
3986 : :
3987 : 0 : free(port->flow_list);
3988 : 0 : port->flow_list = pf;
3989 : : }
3990 : : return ret;
3991 : : }
3992 : :
3993 : : /** Dump flow rules. */
3994 : : int
3995 : 0 : port_flow_dump(portid_t port_id, bool dump_all, uint64_t rule_id,
3996 : : const char *file_name, bool is_user_id)
3997 : : {
3998 : : int ret = 0;
3999 : 0 : FILE *file = stdout;
4000 : : struct rte_flow_error error;
4001 : : struct rte_port *port;
4002 : : struct port_flow *pflow;
4003 : : struct rte_flow *tmpFlow = NULL;
4004 : : bool found = false;
4005 : :
4006 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
4007 : : port_id == (portid_t)RTE_PORT_ALL)
4008 : : return -EINVAL;
4009 : :
4010 : 0 : if (!dump_all) {
4011 : 0 : port = &ports[port_id];
4012 : 0 : pflow = port->flow_list;
4013 : 0 : while (pflow) {
4014 : 0 : if (rule_id !=
4015 : 0 : (is_user_id ? pflow->user_id : pflow->id)) {
4016 : 0 : pflow = pflow->next;
4017 : : } else {
4018 : 0 : tmpFlow = pflow->flow;
4019 : 0 : if (tmpFlow)
4020 : : found = true;
4021 : : break;
4022 : : }
4023 : : }
4024 : 0 : if (found == false) {
4025 : 0 : fprintf(stderr, "Failed to dump to flow %"PRIu64"\n",
4026 : : rule_id);
4027 : 0 : return -EINVAL;
4028 : : }
4029 : : }
4030 : :
4031 : 0 : if (file_name && strlen(file_name)) {
4032 : 0 : file = fopen(file_name, "w");
4033 : 0 : if (!file) {
4034 : 0 : fprintf(stderr, "Failed to create file %s: %s\n",
4035 : 0 : file_name, strerror(errno));
4036 : 0 : return -errno;
4037 : : }
4038 : : }
4039 : :
4040 : 0 : if (!dump_all)
4041 : 0 : ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
4042 : : else
4043 : 0 : ret = rte_flow_dev_dump(port_id, NULL, file, &error);
4044 : 0 : if (ret) {
4045 : 0 : port_flow_complain(&error);
4046 : 0 : fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
4047 : : } else
4048 : : printf("Flow dump finished\n");
4049 : 0 : if (file_name && strlen(file_name))
4050 : 0 : fclose(file);
4051 : : return ret;
4052 : : }
4053 : :
4054 : : /** Query a flow rule. */
4055 : : int
4056 : 0 : port_flow_query(portid_t port_id, uint64_t rule,
4057 : : const struct rte_flow_action *action, bool is_user_id)
4058 : : {
4059 : : struct rte_flow_error error;
4060 : : struct rte_port *port;
4061 : : struct port_flow *pf;
4062 : : const char *name;
4063 : : union {
4064 : : struct rte_flow_query_count count;
4065 : : struct rte_flow_action_rss rss_conf;
4066 : : struct rte_flow_query_age age;
4067 : : } query;
4068 : : int ret;
4069 : :
4070 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
4071 : : port_id == (portid_t)RTE_PORT_ALL)
4072 : : return -EINVAL;
4073 : 0 : port = &ports[port_id];
4074 : 0 : for (pf = port->flow_list; pf; pf = pf->next)
4075 : 0 : if ((is_user_id ? pf->user_id : pf->id) == rule)
4076 : : break;
4077 : 0 : if (!pf) {
4078 : 0 : fprintf(stderr, "Flow rule #%"PRIu64" not found\n", rule);
4079 : 0 : return -ENOENT;
4080 : : }
4081 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
4082 : : &name, sizeof(name),
4083 : 0 : (void *)(uintptr_t)action->type, &error);
4084 : 0 : if (ret < 0)
4085 : 0 : return port_flow_complain(&error);
4086 : 0 : switch (action->type) {
4087 : : case RTE_FLOW_ACTION_TYPE_COUNT:
4088 : : case RTE_FLOW_ACTION_TYPE_RSS:
4089 : : case RTE_FLOW_ACTION_TYPE_AGE:
4090 : : break;
4091 : 0 : default:
4092 : 0 : fprintf(stderr, "Cannot query action type %d (%s)\n",
4093 : : action->type, name);
4094 : 0 : return -ENOTSUP;
4095 : : }
4096 : : /* Poisoning to make sure PMDs update it in case of error. */
4097 : : memset(&error, 0x55, sizeof(error));
4098 : : memset(&query, 0, sizeof(query));
4099 : 0 : if (rte_flow_query(port_id, pf->flow, action, &query, &error))
4100 : 0 : return port_flow_complain(&error);
4101 : 0 : switch (action->type) {
4102 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
4103 : 0 : printf("%s:\n"
4104 : : " hits_set: %u\n"
4105 : : " bytes_set: %u\n"
4106 : : " hits: %" PRIu64 "\n"
4107 : : " bytes: %" PRIu64 "\n",
4108 : : name,
4109 : 0 : query.count.hits_set,
4110 : 0 : query.count.bytes_set,
4111 : : query.count.hits,
4112 : : query.count.bytes);
4113 : : break;
4114 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4115 : 0 : rss_config_display(&query.rss_conf);
4116 : 0 : break;
4117 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
4118 : 0 : printf("%s:\n"
4119 : : " aged: %u\n"
4120 : : " sec_since_last_hit_valid: %u\n"
4121 : : " sec_since_last_hit: %" PRIu32 "\n",
4122 : : name,
4123 : 0 : query.age.aged,
4124 : 0 : query.age.sec_since_last_hit_valid,
4125 : 0 : query.age.sec_since_last_hit);
4126 : : break;
4127 : 0 : default:
4128 : 0 : fprintf(stderr,
4129 : : "Cannot display result for action type %d (%s)\n",
4130 : : action->type, name);
4131 : : break;
4132 : : }
4133 : : return 0;
4134 : : }
4135 : :
4136 : : /** List simply and destroy all aged flows. */
4137 : : void
4138 : 0 : port_flow_aged(portid_t port_id, uint8_t destroy)
4139 : : {
4140 : : void **contexts;
4141 : : int nb_context, total = 0, idx;
4142 : : struct rte_flow_error error;
4143 : : enum age_action_context_type *type;
4144 : : union {
4145 : : struct port_flow *pf;
4146 : : struct port_indirect_action *pia;
4147 : : } ctx;
4148 : :
4149 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
4150 : : port_id == (portid_t)RTE_PORT_ALL)
4151 : 0 : return;
4152 : 0 : total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
4153 : : printf("Port %u total aged flows: %d\n", port_id, total);
4154 : 0 : if (total < 0) {
4155 : 0 : port_flow_complain(&error);
4156 : 0 : return;
4157 : : }
4158 : 0 : if (total == 0)
4159 : : return;
4160 : 0 : contexts = malloc(sizeof(void *) * total);
4161 : 0 : if (contexts == NULL) {
4162 : 0 : fprintf(stderr, "Cannot allocate contexts for aged flow\n");
4163 : 0 : return;
4164 : : }
4165 : : printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
4166 : 0 : nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
4167 : 0 : if (nb_context != total) {
4168 : 0 : fprintf(stderr,
4169 : : "Port:%d get aged flows count(%d) != total(%d)\n",
4170 : : port_id, nb_context, total);
4171 : 0 : free(contexts);
4172 : 0 : return;
4173 : : }
4174 : : total = 0;
4175 : 0 : for (idx = 0; idx < nb_context; idx++) {
4176 : 0 : if (!contexts[idx]) {
4177 : 0 : fprintf(stderr, "Error: get Null context in port %u\n",
4178 : : port_id);
4179 : 0 : continue;
4180 : : }
4181 : : type = (enum age_action_context_type *)contexts[idx];
4182 : 0 : switch (*type) {
4183 : 0 : case ACTION_AGE_CONTEXT_TYPE_FLOW: {
4184 : : uint64_t flow_id;
4185 : 0 : ctx.pf = container_of(type, struct port_flow, age_type);
4186 : 0 : flow_id = ctx.pf->id;
4187 : 0 : printf("%-20s\t%" PRIu64 "\t%" PRIu32 "\t%" PRIu32
4188 : : "\t%c%c%c\t\n",
4189 : : "Flow",
4190 : : ctx.pf->id,
4191 : : ctx.pf->rule.attr->group,
4192 : : ctx.pf->rule.attr->priority,
4193 : 0 : ctx.pf->rule.attr->ingress ? 'i' : '-',
4194 : 0 : ctx.pf->rule.attr->egress ? 'e' : '-',
4195 : 0 : ctx.pf->rule.attr->transfer ? 't' : '-');
4196 : 0 : if (destroy && !port_flow_destroy(port_id, 1,
4197 : : &flow_id, false))
4198 : 0 : total++;
4199 : : break;
4200 : : }
4201 : 0 : case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
4202 : 0 : ctx.pia = container_of(type,
4203 : : struct port_indirect_action, age_type);
4204 : 0 : printf("%-20s\t%" PRIu32 "\n", "Indirect action",
4205 : : ctx.pia->id);
4206 : : break;
4207 : 0 : default:
4208 : 0 : fprintf(stderr, "Error: invalid context type %u\n",
4209 : : port_id);
4210 : : break;
4211 : : }
4212 : : }
4213 : : printf("\n%d flows destroyed\n", total);
4214 : 0 : free(contexts);
4215 : : }
4216 : :
4217 : : /** List flow rules. */
4218 : : void
4219 : 0 : port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
4220 : : {
4221 : : struct rte_port *port;
4222 : : struct port_flow *pf;
4223 : 0 : struct port_flow *list = NULL;
4224 : : uint32_t i;
4225 : :
4226 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
4227 : : port_id == (portid_t)RTE_PORT_ALL)
4228 : 0 : return;
4229 : 0 : port = &ports[port_id];
4230 : 0 : if (!port->flow_list)
4231 : : return;
4232 : : /* Sort flows by group, priority and ID. */
4233 : 0 : for (pf = port->flow_list; pf != NULL; pf = pf->next) {
4234 : : struct port_flow **tmp;
4235 : 0 : const struct rte_flow_attr *curr = pf->rule.attr;
4236 : :
4237 : 0 : if (n) {
4238 : : /* Filter out unwanted groups. */
4239 : 0 : for (i = 0; i != n; ++i)
4240 : 0 : if (curr->group == group[i])
4241 : : break;
4242 : 0 : if (i == n)
4243 : 0 : continue;
4244 : : }
4245 : 0 : for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
4246 : 0 : const struct rte_flow_attr *comp = (*tmp)->rule.attr;
4247 : :
4248 : 0 : if (curr->group > comp->group ||
4249 : 0 : (curr->group == comp->group &&
4250 : 0 : curr->priority > comp->priority) ||
4251 : 0 : (curr->group == comp->group &&
4252 : 0 : curr->priority == comp->priority &&
4253 : 0 : pf->id > (*tmp)->id))
4254 : : continue;
4255 : : break;
4256 : : }
4257 : 0 : pf->tmp = *tmp;
4258 : 0 : *tmp = pf;
4259 : : }
4260 : : printf("ID\tGroup\tPrio\tAttr\tRule\n");
4261 : 0 : for (pf = list; pf != NULL; pf = pf->tmp) {
4262 : 0 : const struct rte_flow_item *item = pf->rule.pattern;
4263 : 0 : const struct rte_flow_action *action = pf->rule.actions;
4264 : : const char *name;
4265 : :
4266 : 0 : printf("%" PRIu64 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
4267 : : pf->id,
4268 : : pf->rule.attr->group,
4269 : : pf->rule.attr->priority,
4270 : 0 : pf->rule.attr->ingress ? 'i' : '-',
4271 : 0 : pf->rule.attr->egress ? 'e' : '-',
4272 : 0 : pf->rule.attr->transfer ? 't' : '-');
4273 : 0 : while (item->type != RTE_FLOW_ITEM_TYPE_END) {
4274 : 0 : if ((uint32_t)item->type > INT_MAX)
4275 : 0 : name = "PMD_INTERNAL";
4276 : 0 : else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
4277 : : &name, sizeof(name),
4278 : 0 : (void *)(uintptr_t)item->type,
4279 : : NULL) <= 0)
4280 : 0 : name = "[UNKNOWN]";
4281 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
4282 : 0 : printf("%s ", name);
4283 : 0 : ++item;
4284 : : }
4285 : : printf("=>");
4286 : 0 : while (action->type != RTE_FLOW_ACTION_TYPE_END) {
4287 : 0 : if ((uint32_t)action->type > INT_MAX)
4288 : 0 : name = "PMD_INTERNAL";
4289 : 0 : else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
4290 : : &name, sizeof(name),
4291 : 0 : (void *)(uintptr_t)action->type,
4292 : : NULL) <= 0)
4293 : 0 : name = "[UNKNOWN]";
4294 : 0 : if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
4295 : 0 : printf(" %s", name);
4296 : 0 : ++action;
4297 : : }
4298 : : printf("\n");
4299 : : }
4300 : : }
4301 : :
4302 : : /** Restrict ingress traffic to the defined flow rules. */
4303 : : int
4304 : 0 : port_flow_isolate(portid_t port_id, int set)
4305 : : {
4306 : : struct rte_flow_error error;
4307 : :
4308 : : /* Poisoning to make sure PMDs update it in case of error. */
4309 : : memset(&error, 0x66, sizeof(error));
4310 : 0 : if (rte_flow_isolate(port_id, set, &error))
4311 : 0 : return port_flow_complain(&error);
4312 : 0 : printf("Ingress traffic on port %u is %s to the defined flow rules\n",
4313 : : port_id,
4314 : : set ? "now restricted" : "not restricted anymore");
4315 : 0 : return 0;
4316 : : }
4317 : :
4318 : : /*
4319 : : * RX/TX ring descriptors display functions.
4320 : : */
4321 : : int
4322 : 0 : rx_queue_id_is_invalid(queueid_t rxq_id)
4323 : : {
4324 : 0 : if (rxq_id < nb_rxq)
4325 : : return 0;
4326 : 0 : fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
4327 : : rxq_id, nb_rxq);
4328 : 0 : return 1;
4329 : : }
4330 : :
4331 : : int
4332 : 0 : tx_queue_id_is_invalid(queueid_t txq_id)
4333 : : {
4334 : 0 : if (txq_id < nb_txq)
4335 : : return 0;
4336 : 0 : fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
4337 : : txq_id, nb_txq);
4338 : 0 : return 1;
4339 : : }
4340 : :
4341 : : static int
4342 : 0 : get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
4343 : : {
4344 : 0 : struct rte_port *port = &ports[port_id];
4345 : : struct rte_eth_rxq_info rx_qinfo;
4346 : : int ret;
4347 : :
4348 : 0 : ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
4349 : 0 : if (ret == 0) {
4350 : 0 : *ring_size = rx_qinfo.nb_desc;
4351 : 0 : return ret;
4352 : : }
4353 : :
4354 : 0 : if (ret != -ENOTSUP)
4355 : : return ret;
4356 : : /*
4357 : : * If the rte_eth_rx_queue_info_get is not support for this PMD,
4358 : : * ring_size stored in testpmd will be used for validity verification.
4359 : : * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
4360 : : * being 0, it will use a default value provided by PMDs to setup this
4361 : : * rxq. If the default value is 0, it will use the
4362 : : * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
4363 : : */
4364 : 0 : if (port->nb_rx_desc[rxq_id])
4365 : 0 : *ring_size = port->nb_rx_desc[rxq_id];
4366 : 0 : else if (port->dev_info.default_rxportconf.ring_size)
4367 : 0 : *ring_size = port->dev_info.default_rxportconf.ring_size;
4368 : : else
4369 : 0 : *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
4370 : : return 0;
4371 : : }
4372 : :
4373 : : static int
4374 : 0 : get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
4375 : : {
4376 : 0 : struct rte_port *port = &ports[port_id];
4377 : : struct rte_eth_txq_info tx_qinfo;
4378 : : int ret;
4379 : :
4380 : 0 : ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
4381 : 0 : if (ret == 0) {
4382 : 0 : *ring_size = tx_qinfo.nb_desc;
4383 : 0 : return ret;
4384 : : }
4385 : :
4386 : 0 : if (ret != -ENOTSUP)
4387 : : return ret;
4388 : : /*
4389 : : * If the rte_eth_tx_queue_info_get is not support for this PMD,
4390 : : * ring_size stored in testpmd will be used for validity verification.
4391 : : * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
4392 : : * being 0, it will use a default value provided by PMDs to setup this
4393 : : * txq. If the default value is 0, it will use the
4394 : : * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
4395 : : */
4396 : 0 : if (port->nb_tx_desc[txq_id])
4397 : 0 : *ring_size = port->nb_tx_desc[txq_id];
4398 : 0 : else if (port->dev_info.default_txportconf.ring_size)
4399 : 0 : *ring_size = port->dev_info.default_txportconf.ring_size;
4400 : : else
4401 : 0 : *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
4402 : : return 0;
4403 : : }
4404 : :
4405 : : static int
4406 : 0 : rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
4407 : : {
4408 : : uint16_t ring_size;
4409 : : int ret;
4410 : :
4411 : 0 : ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
4412 : 0 : if (ret)
4413 : : return 1;
4414 : :
4415 : 0 : if (rxdesc_id < ring_size)
4416 : : return 0;
4417 : :
4418 : 0 : fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
4419 : : rxdesc_id, ring_size);
4420 : 0 : return 1;
4421 : : }
4422 : :
4423 : : static int
4424 : 0 : tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
4425 : : {
4426 : : uint16_t ring_size;
4427 : : int ret;
4428 : :
4429 : 0 : ret = get_tx_ring_size(port_id, txq_id, &ring_size);
4430 : 0 : if (ret)
4431 : : return 1;
4432 : :
4433 : 0 : if (txdesc_id < ring_size)
4434 : : return 0;
4435 : :
4436 : 0 : fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
4437 : : txdesc_id, ring_size);
4438 : 0 : return 1;
4439 : : }
4440 : :
4441 : : static const struct rte_memzone *
4442 : 0 : ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
4443 : : {
4444 : : char mz_name[RTE_MEMZONE_NAMESIZE];
4445 : : const struct rte_memzone *mz;
4446 : :
4447 : 0 : snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
4448 : : port_id, q_id, ring_name);
4449 : 0 : mz = rte_memzone_lookup(mz_name);
4450 : 0 : if (mz == NULL)
4451 : 0 : fprintf(stderr,
4452 : : "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
4453 : : ring_name, port_id, q_id, mz_name);
4454 : 0 : return mz;
4455 : : }
4456 : :
4457 : : union igb_ring_dword {
4458 : : uint64_t dword;
4459 : : struct {
4460 : : #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
4461 : : uint32_t lo;
4462 : : uint32_t hi;
4463 : : #else
4464 : : uint32_t hi;
4465 : : uint32_t lo;
4466 : : #endif
4467 : : } words;
4468 : : };
4469 : :
4470 : : struct igb_ring_desc_32_bytes {
4471 : : union igb_ring_dword lo_dword;
4472 : : union igb_ring_dword hi_dword;
4473 : : union igb_ring_dword resv1;
4474 : : union igb_ring_dword resv2;
4475 : : };
4476 : :
4477 : : struct igb_ring_desc_16_bytes {
4478 : : union igb_ring_dword lo_dword;
4479 : : union igb_ring_dword hi_dword;
4480 : : };
4481 : :
4482 : : static void
4483 : : ring_rxd_display_dword(union igb_ring_dword dword)
4484 : : {
4485 : : printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
4486 : : (unsigned)dword.words.hi);
4487 : : }
4488 : :
4489 : : static void
4490 : 0 : ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
4491 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
4492 : : portid_t port_id,
4493 : : #else
4494 : : __rte_unused portid_t port_id,
4495 : : #endif
4496 : : uint16_t desc_id)
4497 : : {
4498 : 0 : struct igb_ring_desc_16_bytes *ring =
4499 : : (struct igb_ring_desc_16_bytes *)ring_mz->addr;
4500 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
4501 : : int ret;
4502 : : struct rte_eth_dev_info dev_info;
4503 : :
4504 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
4505 : 0 : if (ret != 0)
4506 : 0 : return;
4507 : :
4508 : 0 : if (strstr(dev_info.driver_name, "i40e") != NULL) {
4509 : : /* 32 bytes RX descriptor, i40e only */
4510 : 0 : struct igb_ring_desc_32_bytes *ring =
4511 : : (struct igb_ring_desc_32_bytes *)ring_mz->addr;
4512 : : ring[desc_id].lo_dword.dword =
4513 : 0 : rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
4514 : : ring_rxd_display_dword(ring[desc_id].lo_dword);
4515 : : ring[desc_id].hi_dword.dword =
4516 : : rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
4517 : : ring_rxd_display_dword(ring[desc_id].hi_dword);
4518 : : ring[desc_id].resv1.dword =
4519 : : rte_le_to_cpu_64(ring[desc_id].resv1.dword);
4520 : : ring_rxd_display_dword(ring[desc_id].resv1);
4521 : : ring[desc_id].resv2.dword =
4522 : : rte_le_to_cpu_64(ring[desc_id].resv2.dword);
4523 : : ring_rxd_display_dword(ring[desc_id].resv2);
4524 : :
4525 : 0 : return;
4526 : : }
4527 : : #endif
4528 : : /* 16 bytes RX descriptor */
4529 : : ring[desc_id].lo_dword.dword =
4530 : 0 : rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
4531 : : ring_rxd_display_dword(ring[desc_id].lo_dword);
4532 : : ring[desc_id].hi_dword.dword =
4533 : : rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
4534 : : ring_rxd_display_dword(ring[desc_id].hi_dword);
4535 : : }
4536 : :
4537 : : static void
4538 : 0 : ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
4539 : : {
4540 : : struct igb_ring_desc_16_bytes *ring;
4541 : : struct igb_ring_desc_16_bytes txd;
4542 : :
4543 : 0 : ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
4544 : 0 : txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
4545 : 0 : txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
4546 : : printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
4547 : : (unsigned)txd.lo_dword.words.lo,
4548 : : (unsigned)txd.lo_dword.words.hi,
4549 : : (unsigned)txd.hi_dword.words.lo,
4550 : : (unsigned)txd.hi_dword.words.hi);
4551 : 0 : }
4552 : :
4553 : : void
4554 : 0 : rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
4555 : : {
4556 : : const struct rte_memzone *rx_mz;
4557 : :
4558 : 0 : if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
4559 : : return;
4560 : 0 : rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
4561 : 0 : if (rx_mz == NULL)
4562 : : return;
4563 : 0 : ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
4564 : : }
4565 : :
4566 : : void
4567 : 0 : tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
4568 : : {
4569 : : const struct rte_memzone *tx_mz;
4570 : :
4571 : 0 : if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
4572 : : return;
4573 : 0 : tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
4574 : 0 : if (tx_mz == NULL)
4575 : : return;
4576 : 0 : ring_tx_descriptor_display(tx_mz, txd_id);
4577 : : }
4578 : :
4579 : : void
4580 : 0 : fwd_lcores_config_display(void)
4581 : : {
4582 : : lcoreid_t lc_id;
4583 : :
4584 : : printf("List of forwarding lcores:");
4585 : 0 : for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
4586 : 0 : printf(" %2u", fwd_lcores_cpuids[lc_id]);
4587 : : printf("\n");
4588 : 0 : }
4589 : : void
4590 : 0 : rxtx_config_display(void)
4591 : : {
4592 : : portid_t pid;
4593 : : queueid_t qid;
4594 : :
4595 : 0 : printf(" %s%s%s packet forwarding%s packets/burst=%d\n",
4596 : : cur_fwd_eng->fwd_mode_name,
4597 : : cur_fwd_eng->status ? "-" : "",
4598 : 0 : cur_fwd_eng->status ? cur_fwd_eng->status : "",
4599 : 0 : retry_enabled == 0 ? "" : " with retry",
4600 : : nb_pkt_per_burst);
4601 : :
4602 : 0 : if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
4603 : 0 : printf(" packet len=%u - nb packet segments=%d\n",
4604 : : (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
4605 : :
4606 : 0 : printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
4607 : : nb_fwd_lcores, nb_fwd_ports);
4608 : :
4609 : 0 : RTE_ETH_FOREACH_DEV(pid) {
4610 : 0 : struct rte_eth_rxconf *rx_conf = &ports[pid].rxq[0].conf;
4611 : 0 : struct rte_eth_txconf *tx_conf = &ports[pid].txq[0].conf;
4612 : 0 : uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
4613 : 0 : uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
4614 : : struct rte_eth_rxq_info rx_qinfo;
4615 : : struct rte_eth_txq_info tx_qinfo;
4616 : : uint16_t rx_free_thresh_tmp;
4617 : : uint16_t tx_free_thresh_tmp;
4618 : : uint16_t tx_rs_thresh_tmp;
4619 : : uint16_t nb_rx_desc_tmp;
4620 : : uint16_t nb_tx_desc_tmp;
4621 : : uint64_t offloads_tmp;
4622 : : uint8_t pthresh_tmp;
4623 : : uint8_t hthresh_tmp;
4624 : : uint8_t wthresh_tmp;
4625 : : int32_t rc;
4626 : :
4627 : : /* per port config */
4628 : 0 : printf(" port %d: RX queue number: %d Tx queue number: %d\n",
4629 : : (unsigned int)pid, nb_rxq, nb_txq);
4630 : :
4631 : 0 : printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
4632 : : ports[pid].dev_conf.rxmode.offloads,
4633 : 0 : ports[pid].dev_conf.txmode.offloads);
4634 : :
4635 : : /* per rx queue config only for first queue to be less verbose */
4636 : 0 : for (qid = 0; qid < 1; qid++) {
4637 : 0 : rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
4638 : 0 : if (rc) {
4639 : 0 : nb_rx_desc_tmp = nb_rx_desc[qid];
4640 : 0 : rx_free_thresh_tmp =
4641 : 0 : rx_conf[qid].rx_free_thresh;
4642 : 0 : pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
4643 : 0 : hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
4644 : 0 : wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
4645 : 0 : offloads_tmp = rx_conf[qid].offloads;
4646 : : } else {
4647 : 0 : nb_rx_desc_tmp = rx_qinfo.nb_desc;
4648 : 0 : rx_free_thresh_tmp =
4649 : : rx_qinfo.conf.rx_free_thresh;
4650 : 0 : pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
4651 : 0 : hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
4652 : 0 : wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
4653 : 0 : offloads_tmp = rx_qinfo.conf.offloads;
4654 : : }
4655 : :
4656 : : printf(" RX queue: %d\n", qid);
4657 : 0 : printf(" RX desc=%d - RX free threshold=%d\n",
4658 : : nb_rx_desc_tmp, rx_free_thresh_tmp);
4659 : 0 : printf(" RX threshold registers: pthresh=%d hthresh=%d "
4660 : : " wthresh=%d\n",
4661 : : pthresh_tmp, hthresh_tmp, wthresh_tmp);
4662 : : printf(" RX Offloads=0x%"PRIx64, offloads_tmp);
4663 : 0 : if (rx_conf->share_group > 0)
4664 : 0 : printf(" share_group=%u share_qid=%u",
4665 : : rx_conf->share_group,
4666 : 0 : rx_conf->share_qid);
4667 : : printf("\n");
4668 : : }
4669 : :
4670 : : /* per tx queue config only for first queue to be less verbose */
4671 : 0 : for (qid = 0; qid < 1; qid++) {
4672 : 0 : rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
4673 : 0 : if (rc) {
4674 : 0 : nb_tx_desc_tmp = nb_tx_desc[qid];
4675 : 0 : tx_free_thresh_tmp =
4676 : 0 : tx_conf[qid].tx_free_thresh;
4677 : 0 : pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
4678 : 0 : hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
4679 : 0 : wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
4680 : 0 : offloads_tmp = tx_conf[qid].offloads;
4681 : 0 : tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
4682 : : } else {
4683 : 0 : nb_tx_desc_tmp = tx_qinfo.nb_desc;
4684 : 0 : tx_free_thresh_tmp =
4685 : : tx_qinfo.conf.tx_free_thresh;
4686 : 0 : pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
4687 : 0 : hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
4688 : 0 : wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
4689 : 0 : offloads_tmp = tx_qinfo.conf.offloads;
4690 : 0 : tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
4691 : : }
4692 : :
4693 : : printf(" TX queue: %d\n", qid);
4694 : 0 : printf(" TX desc=%d - TX free threshold=%d\n",
4695 : : nb_tx_desc_tmp, tx_free_thresh_tmp);
4696 : 0 : printf(" TX threshold registers: pthresh=%d hthresh=%d "
4697 : : " wthresh=%d\n",
4698 : : pthresh_tmp, hthresh_tmp, wthresh_tmp);
4699 : 0 : printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
4700 : : offloads_tmp, tx_rs_thresh_tmp);
4701 : : }
4702 : : }
4703 : 0 : }
4704 : :
4705 : : void
4706 : 0 : port_rss_reta_info(portid_t port_id,
4707 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4708 : : uint16_t nb_entries)
4709 : : {
4710 : : uint16_t i, idx, shift;
4711 : : int ret;
4712 : :
4713 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
4714 : : return;
4715 : :
4716 : 0 : ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
4717 : 0 : if (ret != 0) {
4718 : 0 : fprintf(stderr,
4719 : : "Failed to get RSS RETA info, return code = %d\n",
4720 : : ret);
4721 : 0 : return;
4722 : : }
4723 : :
4724 : 0 : for (i = 0; i < nb_entries; i++) {
4725 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4726 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4727 : 0 : if (!(reta_conf[idx].mask & (1ULL << shift)))
4728 : 0 : continue;
4729 : 0 : printf("RSS RETA configuration: hash index=%u, queue=%u\n",
4730 : 0 : i, reta_conf[idx].reta[shift]);
4731 : : }
4732 : : }
4733 : :
4734 : : /*
4735 : : * Displays the RSS hash functions of a port, and, optionally, the RSS hash
4736 : : * key of the port.
4737 : : */
4738 : : void
4739 : 0 : port_rss_hash_conf_show(portid_t port_id, int show_rss_key, int show_rss_algo)
4740 : : {
4741 : 0 : struct rte_eth_rss_conf rss_conf = {0};
4742 : : uint8_t rss_key[RSS_HASH_KEY_LENGTH];
4743 : : uint64_t rss_hf;
4744 : : uint8_t i;
4745 : : int diag;
4746 : : struct rte_eth_dev_info dev_info;
4747 : : uint8_t hash_key_size;
4748 : : int ret;
4749 : :
4750 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
4751 : 0 : return;
4752 : :
4753 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
4754 : 0 : if (ret != 0)
4755 : : return;
4756 : :
4757 : 0 : if (dev_info.hash_key_size > 0 &&
4758 : : dev_info.hash_key_size <= sizeof(rss_key))
4759 : : hash_key_size = dev_info.hash_key_size;
4760 : : else {
4761 : 0 : fprintf(stderr,
4762 : : "dev_info did not provide a valid hash key size\n");
4763 : 0 : return;
4764 : : }
4765 : :
4766 : : /* Get RSS hash key if asked to display it */
4767 : 0 : rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
4768 : 0 : rss_conf.rss_key_len = hash_key_size;
4769 : 0 : diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
4770 : 0 : if (diag != 0) {
4771 : 0 : switch (diag) {
4772 : 0 : case -ENODEV:
4773 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
4774 : : break;
4775 : 0 : case -ENOTSUP:
4776 : 0 : fprintf(stderr, "operation not supported by device\n");
4777 : : break;
4778 : 0 : default:
4779 : 0 : fprintf(stderr, "operation failed - diag=%d\n", diag);
4780 : : break;
4781 : : }
4782 : 0 : return;
4783 : : }
4784 : 0 : rss_hf = rss_conf.rss_hf;
4785 : 0 : if (rss_hf == 0) {
4786 : : printf("RSS disabled\n");
4787 : 0 : return;
4788 : : }
4789 : :
4790 : 0 : if (show_rss_algo) {
4791 : 0 : printf("RSS algorithm:\n %s\n",
4792 : : rte_eth_dev_rss_algo_name(rss_conf.algorithm));
4793 : 0 : return;
4794 : : }
4795 : :
4796 : : printf("RSS functions:\n");
4797 : 0 : rss_types_display(rss_hf, TESTPMD_RSS_TYPES_CHAR_NUM_PER_LINE);
4798 : :
4799 : 0 : if (!show_rss_key)
4800 : : return;
4801 : : printf("RSS key:\n");
4802 : 0 : for (i = 0; i < hash_key_size; i++)
4803 : 0 : printf("%02X", rss_key[i]);
4804 : : printf("\n");
4805 : : }
4806 : :
4807 : : void
4808 : 0 : port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
4809 : : uint8_t hash_key_len)
4810 : : {
4811 : : struct rte_eth_rss_conf rss_conf;
4812 : : int diag;
4813 : :
4814 : 0 : rss_conf.rss_key = NULL;
4815 : 0 : rss_conf.rss_key_len = 0;
4816 : 0 : rss_conf.rss_hf = 0;
4817 : 0 : diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
4818 : 0 : if (diag == 0) {
4819 : 0 : rss_conf.rss_key = hash_key;
4820 : 0 : rss_conf.rss_key_len = hash_key_len;
4821 : 0 : rss_conf.rss_hf = str_to_rsstypes(rss_type);
4822 : 0 : diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
4823 : : }
4824 : 0 : if (diag == 0)
4825 : 0 : return;
4826 : :
4827 : 0 : switch (diag) {
4828 : 0 : case -ENODEV:
4829 : 0 : fprintf(stderr, "port index %d invalid\n", port_id);
4830 : : break;
4831 : 0 : case -ENOTSUP:
4832 : 0 : fprintf(stderr, "operation not supported by device\n");
4833 : : break;
4834 : 0 : default:
4835 : 0 : fprintf(stderr, "operation failed - diag=%d\n", diag);
4836 : : break;
4837 : : }
4838 : : }
4839 : :
4840 : : /*
4841 : : * Check whether a shared rxq scheduled on other lcores.
4842 : : */
4843 : : static bool
4844 : 0 : fwd_stream_on_other_lcores(uint16_t domain_id, lcoreid_t src_lc,
4845 : : portid_t src_port, queueid_t src_rxq,
4846 : : uint32_t share_group, queueid_t share_rxq)
4847 : : {
4848 : : streamid_t sm_id;
4849 : : streamid_t nb_fs_per_lcore;
4850 : : lcoreid_t nb_fc;
4851 : : lcoreid_t lc_id;
4852 : : struct fwd_stream *fs;
4853 : : struct rte_port *port;
4854 : : struct rte_eth_dev_info *dev_info;
4855 : : struct rte_eth_rxconf *rxq_conf;
4856 : :
4857 : 0 : nb_fc = cur_fwd_config.nb_fwd_lcores;
4858 : : /* Check remaining cores. */
4859 : 0 : for (lc_id = src_lc + 1; lc_id < nb_fc; lc_id++) {
4860 : 0 : sm_id = fwd_lcores[lc_id]->stream_idx;
4861 : 0 : nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
4862 : 0 : for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
4863 : 0 : sm_id++) {
4864 : 0 : fs = fwd_streams[sm_id];
4865 : 0 : port = &ports[fs->rx_port];
4866 : : dev_info = &port->dev_info;
4867 : 0 : rxq_conf = &port->rxq[fs->rx_queue].conf;
4868 : 0 : if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
4869 : 0 : == 0 || rxq_conf->share_group == 0)
4870 : : /* Not shared rxq. */
4871 : 0 : continue;
4872 : 0 : if (domain_id != port->dev_info.switch_info.domain_id)
4873 : 0 : continue;
4874 : 0 : if (rxq_conf->share_group != share_group)
4875 : 0 : continue;
4876 : 0 : if (rxq_conf->share_qid != share_rxq)
4877 : 0 : continue;
4878 : 0 : printf("Shared Rx queue group %u queue %hu can't be scheduled on different cores:\n",
4879 : : share_group, share_rxq);
4880 : 0 : printf(" lcore %u Port %hu queue %hu\n",
4881 : : src_lc, src_port, src_rxq);
4882 : 0 : printf(" lcore %u Port %hu queue %hu\n",
4883 : 0 : lc_id, fs->rx_port, fs->rx_queue);
4884 : 0 : printf("Please use --nb-cores=%hu to limit number of forwarding cores\n",
4885 : : nb_rxq);
4886 : 0 : return true;
4887 : : }
4888 : : }
4889 : : return false;
4890 : : }
4891 : :
4892 : : /*
4893 : : * Check shared rxq configuration.
4894 : : *
4895 : : * Shared group must not being scheduled on different core.
4896 : : */
4897 : : bool
4898 : 0 : pkt_fwd_shared_rxq_check(void)
4899 : : {
4900 : : streamid_t sm_id;
4901 : : streamid_t nb_fs_per_lcore;
4902 : : lcoreid_t nb_fc;
4903 : : lcoreid_t lc_id;
4904 : : struct fwd_stream *fs;
4905 : : uint16_t domain_id;
4906 : : struct rte_port *port;
4907 : : struct rte_eth_dev_info *dev_info;
4908 : : struct rte_eth_rxconf *rxq_conf;
4909 : :
4910 : 0 : if (rxq_share == 0)
4911 : : return true;
4912 : 0 : nb_fc = cur_fwd_config.nb_fwd_lcores;
4913 : : /*
4914 : : * Check streams on each core, make sure the same switch domain +
4915 : : * group + queue doesn't get scheduled on other cores.
4916 : : */
4917 : 0 : for (lc_id = 0; lc_id < nb_fc; lc_id++) {
4918 : 0 : sm_id = fwd_lcores[lc_id]->stream_idx;
4919 : 0 : nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
4920 : 0 : for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
4921 : 0 : sm_id++) {
4922 : 0 : fs = fwd_streams[sm_id];
4923 : : /* Update lcore info stream being scheduled. */
4924 : 0 : fs->lcore = fwd_lcores[lc_id];
4925 : 0 : port = &ports[fs->rx_port];
4926 : : dev_info = &port->dev_info;
4927 : 0 : rxq_conf = &port->rxq[fs->rx_queue].conf;
4928 : 0 : if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
4929 : 0 : == 0 || rxq_conf->share_group == 0)
4930 : : /* Not shared rxq. */
4931 : 0 : continue;
4932 : : /* Check shared rxq not scheduled on remaining cores. */
4933 : 0 : domain_id = port->dev_info.switch_info.domain_id;
4934 : 0 : if (fwd_stream_on_other_lcores(domain_id, lc_id,
4935 : : fs->rx_port,
4936 : : fs->rx_queue,
4937 : : rxq_conf->share_group,
4938 : 0 : rxq_conf->share_qid))
4939 : : return false;
4940 : : }
4941 : : }
4942 : : return true;
4943 : : }
4944 : :
4945 : : /*
4946 : : * Setup forwarding configuration for each logical core.
4947 : : */
4948 : : static void
4949 : 0 : setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
4950 : : {
4951 : : streamid_t nb_fs_per_lcore;
4952 : : streamid_t nb_fs;
4953 : : streamid_t sm_id;
4954 : : lcoreid_t nb_extra;
4955 : : lcoreid_t nb_fc;
4956 : : lcoreid_t nb_lc;
4957 : : lcoreid_t lc_id;
4958 : :
4959 : 0 : nb_fs = cfg->nb_fwd_streams;
4960 : 0 : nb_fc = cfg->nb_fwd_lcores;
4961 : 0 : if (nb_fs <= nb_fc) {
4962 : : nb_fs_per_lcore = 1;
4963 : : nb_extra = 0;
4964 : : } else {
4965 : 0 : nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
4966 : 0 : nb_extra = (lcoreid_t) (nb_fs % nb_fc);
4967 : : }
4968 : :
4969 : 0 : nb_lc = (lcoreid_t) (nb_fc - nb_extra);
4970 : : sm_id = 0;
4971 : 0 : for (lc_id = 0; lc_id < nb_lc; lc_id++) {
4972 : 0 : fwd_lcores[lc_id]->stream_idx = sm_id;
4973 : 0 : fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
4974 : 0 : sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
4975 : : }
4976 : :
4977 : : /*
4978 : : * Assign extra remaining streams, if any.
4979 : : */
4980 : 0 : nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
4981 : 0 : for (lc_id = 0; lc_id < nb_extra; lc_id++) {
4982 : 0 : fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
4983 : 0 : fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
4984 : 0 : sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
4985 : : }
4986 : 0 : }
4987 : :
4988 : : static portid_t
4989 : 0 : fwd_topology_tx_port_get(portid_t rxp)
4990 : : {
4991 : : static int warning_once = 1;
4992 : :
4993 : : RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
4994 : :
4995 : 0 : switch (port_topology) {
4996 : 0 : default:
4997 : : case PORT_TOPOLOGY_PAIRED:
4998 : 0 : if ((rxp & 0x1) == 0) {
4999 : 0 : if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
5000 : 0 : return rxp + 1;
5001 : 0 : if (warning_once) {
5002 : 0 : fprintf(stderr,
5003 : : "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
5004 : 0 : warning_once = 0;
5005 : : }
5006 : 0 : return rxp;
5007 : : }
5008 : 0 : return rxp - 1;
5009 : 0 : case PORT_TOPOLOGY_CHAINED:
5010 : 0 : return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
5011 : : case PORT_TOPOLOGY_LOOP:
5012 : : return rxp;
5013 : : }
5014 : : }
5015 : :
5016 : : static void
5017 : 0 : simple_fwd_config_setup(void)
5018 : : {
5019 : : portid_t i;
5020 : :
5021 : 0 : cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
5022 : 0 : cur_fwd_config.nb_fwd_streams =
5023 : : (streamid_t) cur_fwd_config.nb_fwd_ports;
5024 : :
5025 : : /* reinitialize forwarding streams */
5026 : 0 : init_fwd_streams();
5027 : :
5028 : : /*
5029 : : * In the simple forwarding test, the number of forwarding cores
5030 : : * must be lower or equal to the number of forwarding ports.
5031 : : */
5032 : 0 : cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
5033 : 0 : if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
5034 : 0 : cur_fwd_config.nb_fwd_lcores =
5035 : : (lcoreid_t) cur_fwd_config.nb_fwd_ports;
5036 : 0 : setup_fwd_config_of_each_lcore(&cur_fwd_config);
5037 : :
5038 : 0 : for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
5039 : 0 : fwd_streams[i]->rx_port = fwd_ports_ids[i];
5040 : 0 : fwd_streams[i]->rx_queue = 0;
5041 : 0 : fwd_streams[i]->tx_port =
5042 : 0 : fwd_ports_ids[fwd_topology_tx_port_get(i)];
5043 : 0 : fwd_streams[i]->tx_queue = 0;
5044 : 0 : fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
5045 : 0 : fwd_streams[i]->retry_enabled = retry_enabled;
5046 : : }
5047 : 0 : }
5048 : :
5049 : : /**
5050 : : * For the RSS forwarding test all streams distributed over lcores. Each stream
5051 : : * being composed of a RX queue to poll on a RX port for input messages,
5052 : : * associated with a TX queue of a TX port where to send forwarded packets.
5053 : : */
5054 : : static void
5055 : 0 : rss_fwd_config_setup(void)
5056 : : {
5057 : : portid_t rxp;
5058 : : portid_t txp;
5059 : : queueid_t rxq;
5060 : : queueid_t nb_q;
5061 : : streamid_t sm_id;
5062 : : int start;
5063 : :
5064 : 0 : nb_q = nb_rxq;
5065 : 0 : if (nb_q > nb_txq)
5066 : : nb_q = nb_txq;
5067 : 0 : cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
5068 : 0 : cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
5069 : 0 : cur_fwd_config.nb_fwd_streams =
5070 : 0 : (streamid_t) (nb_q / num_procs * cur_fwd_config.nb_fwd_ports);
5071 : :
5072 : 0 : if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
5073 : 0 : cur_fwd_config.nb_fwd_lcores =
5074 : : (lcoreid_t)cur_fwd_config.nb_fwd_streams;
5075 : :
5076 : : /* reinitialize forwarding streams */
5077 : 0 : init_fwd_streams();
5078 : :
5079 : 0 : setup_fwd_config_of_each_lcore(&cur_fwd_config);
5080 : :
5081 : 0 : if (proc_id > 0 && nb_q % num_procs != 0)
5082 : : printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
5083 : :
5084 : : /**
5085 : : * In multi-process, All queues are allocated to different
5086 : : * processes based on num_procs and proc_id. For example:
5087 : : * if supports 4 queues(nb_q), 2 processes(num_procs),
5088 : : * the 0~1 queue for primary process.
5089 : : * the 2~3 queue for secondary process.
5090 : : */
5091 : 0 : start = proc_id * nb_q / num_procs;
5092 : : rxp = 0;
5093 : 0 : rxq = start;
5094 : 0 : for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
5095 : : struct fwd_stream *fs;
5096 : :
5097 : 0 : fs = fwd_streams[sm_id];
5098 : 0 : txp = fwd_topology_tx_port_get(rxp);
5099 : 0 : fs->rx_port = fwd_ports_ids[rxp];
5100 : 0 : fs->rx_queue = rxq;
5101 : 0 : fs->tx_port = fwd_ports_ids[txp];
5102 : 0 : fs->tx_queue = rxq;
5103 : 0 : fs->peer_addr = fs->tx_port;
5104 : 0 : fs->retry_enabled = retry_enabled;
5105 : 0 : rxp++;
5106 : 0 : if (rxp < nb_fwd_ports)
5107 : 0 : continue;
5108 : : rxp = 0;
5109 : 0 : rxq++;
5110 : : }
5111 : 0 : }
5112 : :
5113 : : static uint16_t
5114 : 0 : get_fwd_port_total_tc_num(void)
5115 : : {
5116 : : struct rte_eth_dcb_info dcb_info;
5117 : : uint16_t total_tc_num = 0;
5118 : : unsigned int i;
5119 : :
5120 : 0 : for (i = 0; i < nb_fwd_ports; i++) {
5121 : 0 : (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
5122 : 0 : total_tc_num += dcb_info.nb_tcs;
5123 : : }
5124 : :
5125 : 0 : return total_tc_num;
5126 : : }
5127 : :
5128 : : /**
5129 : : * For the DCB forwarding test, each core is assigned on each traffic class.
5130 : : *
5131 : : * Each core is assigned a multi-stream, each stream being composed of
5132 : : * a RX queue to poll on a RX port for input messages, associated with
5133 : : * a TX queue of a TX port where to send forwarded packets. All RX and
5134 : : * TX queues are mapping to the same traffic class.
5135 : : * If VMDQ and DCB co-exist, each traffic class on different POOLs share
5136 : : * the same core
5137 : : */
5138 : : static void
5139 : 0 : dcb_fwd_config_setup(void)
5140 : : {
5141 : : struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
5142 : : portid_t txp, rxp = 0;
5143 : : queueid_t txq, rxq = 0;
5144 : : lcoreid_t lc_id;
5145 : : uint16_t nb_rx_queue, nb_tx_queue;
5146 : : uint16_t i, j, k, sm_id = 0;
5147 : : uint16_t total_tc_num;
5148 : : struct rte_port *port;
5149 : : uint8_t tc = 0;
5150 : : portid_t pid;
5151 : : int ret;
5152 : :
5153 : : /*
5154 : : * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
5155 : : * or RTE_PORT_STOPPED.
5156 : : *
5157 : : * Re-configure ports to get updated mapping between tc and queue in
5158 : : * case the queue number of the port is changed. Skip for started ports
5159 : : * since modifying queue number and calling dev_configure need to stop
5160 : : * ports first.
5161 : : */
5162 : 0 : for (pid = 0; pid < nb_fwd_ports; pid++) {
5163 : 0 : if (port_is_started(pid) == 1)
5164 : 0 : continue;
5165 : :
5166 : 0 : port = &ports[pid];
5167 : 0 : ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
5168 : 0 : &port->dev_conf);
5169 : 0 : if (ret < 0) {
5170 : 0 : fprintf(stderr,
5171 : : "Failed to re-configure port %d, ret = %d.\n",
5172 : : pid, ret);
5173 : 0 : return;
5174 : : }
5175 : : }
5176 : :
5177 : 0 : cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
5178 : 0 : cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
5179 : 0 : cur_fwd_config.nb_fwd_streams =
5180 : 0 : (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
5181 : 0 : total_tc_num = get_fwd_port_total_tc_num();
5182 : 0 : if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
5183 : 0 : cur_fwd_config.nb_fwd_lcores = total_tc_num;
5184 : :
5185 : : /* reinitialize forwarding streams */
5186 : 0 : init_fwd_streams();
5187 : : sm_id = 0;
5188 : : txp = 1;
5189 : : /* get the dcb info on the first RX and TX ports */
5190 : 0 : (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
5191 : 0 : (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
5192 : :
5193 : 0 : for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
5194 : 0 : fwd_lcores[lc_id]->stream_nb = 0;
5195 : 0 : fwd_lcores[lc_id]->stream_idx = sm_id;
5196 : 0 : for (i = 0; i < RTE_ETH_MAX_VMDQ_POOL; i++) {
5197 : : /* if the nb_queue is zero, means this tc is
5198 : : * not enabled on the POOL
5199 : : */
5200 : 0 : if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
5201 : : break;
5202 : 0 : k = fwd_lcores[lc_id]->stream_nb +
5203 : : fwd_lcores[lc_id]->stream_idx;
5204 : 0 : rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
5205 : 0 : txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
5206 : 0 : nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
5207 : 0 : nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
5208 : 0 : for (j = 0; j < nb_rx_queue; j++) {
5209 : : struct fwd_stream *fs;
5210 : :
5211 : 0 : fs = fwd_streams[k + j];
5212 : 0 : fs->rx_port = fwd_ports_ids[rxp];
5213 : 0 : fs->rx_queue = rxq + j;
5214 : 0 : fs->tx_port = fwd_ports_ids[txp];
5215 : 0 : fs->tx_queue = txq + j % nb_tx_queue;
5216 : 0 : fs->peer_addr = fs->tx_port;
5217 : 0 : fs->retry_enabled = retry_enabled;
5218 : : }
5219 : 0 : fwd_lcores[lc_id]->stream_nb +=
5220 : : rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
5221 : : }
5222 : 0 : sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
5223 : :
5224 : 0 : tc++;
5225 : 0 : if (tc < rxp_dcb_info.nb_tcs)
5226 : 0 : continue;
5227 : : /* Restart from TC 0 on next RX port */
5228 : : tc = 0;
5229 : 0 : if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
5230 : 0 : rxp = (portid_t)
5231 : 0 : (rxp + ((nb_ports >> 1) / nb_fwd_ports));
5232 : : else
5233 : 0 : rxp++;
5234 : 0 : if (rxp >= nb_fwd_ports)
5235 : : return;
5236 : : /* get the dcb information on next RX and TX ports */
5237 : 0 : if ((rxp & 0x1) == 0)
5238 : 0 : txp = (portid_t) (rxp + 1);
5239 : : else
5240 : 0 : txp = (portid_t) (rxp - 1);
5241 : 0 : rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
5242 : 0 : rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
5243 : : }
5244 : : }
5245 : :
5246 : : static void
5247 : 0 : icmp_echo_config_setup(void)
5248 : : {
5249 : : portid_t rxp;
5250 : : queueid_t rxq;
5251 : : lcoreid_t lc_id;
5252 : : uint16_t sm_id;
5253 : :
5254 : 0 : if ((lcoreid_t)(nb_txq * nb_fwd_ports) < nb_fwd_lcores)
5255 : 0 : cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
5256 : : (nb_txq * nb_fwd_ports);
5257 : : else
5258 : 0 : cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
5259 : 0 : cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
5260 : 0 : cur_fwd_config.nb_fwd_streams =
5261 : 0 : (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
5262 : 0 : if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
5263 : 0 : cur_fwd_config.nb_fwd_lcores =
5264 : : (lcoreid_t)cur_fwd_config.nb_fwd_streams;
5265 : 0 : if (verbose_level > 0) {
5266 : 0 : printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
5267 : : __FUNCTION__,
5268 : : cur_fwd_config.nb_fwd_lcores,
5269 : : cur_fwd_config.nb_fwd_ports,
5270 : : cur_fwd_config.nb_fwd_streams);
5271 : : }
5272 : :
5273 : : /* reinitialize forwarding streams */
5274 : 0 : init_fwd_streams();
5275 : 0 : setup_fwd_config_of_each_lcore(&cur_fwd_config);
5276 : : rxp = 0; rxq = 0;
5277 : 0 : for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
5278 : 0 : if (verbose_level > 0)
5279 : : printf(" core=%d: \n", lc_id);
5280 : 0 : for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
5281 : : struct fwd_stream *fs;
5282 : 0 : fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
5283 : 0 : fs->rx_port = fwd_ports_ids[rxp];
5284 : 0 : fs->rx_queue = rxq;
5285 : 0 : fs->tx_port = fs->rx_port;
5286 : 0 : fs->tx_queue = rxq;
5287 : 0 : fs->peer_addr = fs->tx_port;
5288 : 0 : fs->retry_enabled = retry_enabled;
5289 : 0 : if (verbose_level > 0)
5290 : 0 : printf(" stream=%d port=%d rxq=%d txq=%d\n",
5291 : : sm_id, fs->rx_port, fs->rx_queue,
5292 : : fs->tx_queue);
5293 : 0 : rxq = (queueid_t) (rxq + 1);
5294 : 0 : if (rxq == nb_rxq) {
5295 : : rxq = 0;
5296 : 0 : rxp = (portid_t) (rxp + 1);
5297 : : }
5298 : : }
5299 : : }
5300 : 0 : }
5301 : :
5302 : : void
5303 : 0 : fwd_config_setup(void)
5304 : : {
5305 : : struct rte_port *port;
5306 : : portid_t pt_id;
5307 : : unsigned int i;
5308 : :
5309 : 0 : cur_fwd_config.fwd_eng = cur_fwd_eng;
5310 : 0 : if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
5311 : 0 : icmp_echo_config_setup();
5312 : 0 : return;
5313 : : }
5314 : :
5315 : 0 : if ((nb_rxq > 1) && (nb_txq > 1)){
5316 : 0 : if (dcb_config) {
5317 : 0 : for (i = 0; i < nb_fwd_ports; i++) {
5318 : 0 : pt_id = fwd_ports_ids[i];
5319 : 0 : port = &ports[pt_id];
5320 : 0 : if (!port->dcb_flag) {
5321 : 0 : fprintf(stderr,
5322 : : "In DCB mode, all forwarding ports must be configured in this mode.\n");
5323 : 0 : return;
5324 : : }
5325 : : }
5326 : 0 : if (nb_fwd_lcores == 1) {
5327 : 0 : fprintf(stderr,
5328 : : "In DCB mode,the nb forwarding cores should be larger than 1.\n");
5329 : 0 : return;
5330 : : }
5331 : :
5332 : 0 : dcb_fwd_config_setup();
5333 : : } else
5334 : 0 : rss_fwd_config_setup();
5335 : : }
5336 : : else
5337 : 0 : simple_fwd_config_setup();
5338 : : }
5339 : :
5340 : : static const char *
5341 : : mp_alloc_to_str(uint8_t mode)
5342 : : {
5343 : 0 : switch (mode) {
5344 : : case MP_ALLOC_NATIVE:
5345 : : return "native";
5346 : 0 : case MP_ALLOC_ANON:
5347 : 0 : return "anon";
5348 : 0 : case MP_ALLOC_XMEM:
5349 : 0 : return "xmem";
5350 : 0 : case MP_ALLOC_XMEM_HUGE:
5351 : 0 : return "xmemhuge";
5352 : 0 : case MP_ALLOC_XBUF:
5353 : 0 : return "xbuf";
5354 : 0 : default:
5355 : 0 : return "invalid";
5356 : : }
5357 : : }
5358 : :
5359 : : void
5360 : 0 : pkt_fwd_config_display(struct fwd_config *cfg)
5361 : : {
5362 : : struct fwd_stream *fs;
5363 : : lcoreid_t lc_id;
5364 : : streamid_t sm_id;
5365 : :
5366 : 0 : printf("%s%s%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
5367 : : "NUMA support %s, MP allocation mode: %s\n",
5368 : : cfg->fwd_eng->fwd_mode_name,
5369 : : cfg->fwd_eng->status ? "-" : "",
5370 : 0 : cfg->fwd_eng->status ? cfg->fwd_eng->status : "",
5371 : 0 : retry_enabled == 0 ? "" : " with retry",
5372 : 0 : cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
5373 : 0 : numa_support == 1 ? "enabled" : "disabled",
5374 : : mp_alloc_to_str(mp_alloc_type));
5375 : :
5376 : 0 : if (retry_enabled)
5377 : 0 : printf("TX retry num: %u, delay between TX retries: %uus\n",
5378 : : burst_tx_retry_num, burst_tx_delay_time);
5379 : 0 : for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
5380 : 0 : printf("Logical Core %u (socket %u) forwards packets on "
5381 : : "%d streams:",
5382 : : fwd_lcores_cpuids[lc_id],
5383 : : rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
5384 : 0 : fwd_lcores[lc_id]->stream_nb);
5385 : 0 : for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
5386 : 0 : fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
5387 : 0 : printf("\n RX P=%d/Q=%d (socket %u) -> TX "
5388 : : "P=%d/Q=%d (socket %u) ",
5389 : 0 : fs->rx_port, fs->rx_queue,
5390 : 0 : ports[fs->rx_port].socket_id,
5391 : 0 : fs->tx_port, fs->tx_queue,
5392 : 0 : ports[fs->tx_port].socket_id);
5393 : 0 : print_ethaddr("peer=",
5394 : 0 : &peer_eth_addrs[fs->peer_addr]);
5395 : : }
5396 : : printf("\n");
5397 : : }
5398 : : printf("\n");
5399 : 0 : }
5400 : :
5401 : : void
5402 : 0 : set_fwd_eth_peer(portid_t port_id, char *peer_addr)
5403 : : {
5404 : : struct rte_ether_addr new_peer_addr;
5405 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
5406 : 0 : fprintf(stderr, "Error: Invalid port number %i\n", port_id);
5407 : 0 : return;
5408 : : }
5409 : 0 : if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
5410 : 0 : fprintf(stderr, "Error: Invalid ethernet address: %s\n",
5411 : : peer_addr);
5412 : 0 : return;
5413 : : }
5414 : 0 : peer_eth_addrs[port_id] = new_peer_addr;
5415 : : }
5416 : :
5417 : : void
5418 : 0 : set_dev_led(portid_t port_id, bool active)
5419 : : {
5420 : : int ret;
5421 : :
5422 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
5423 : 0 : fprintf(stderr, "Error: Invalid port number %u\n", port_id);
5424 : 0 : return;
5425 : : }
5426 : :
5427 : 0 : if (active)
5428 : 0 : ret = rte_eth_led_on(port_id);
5429 : : else
5430 : 0 : ret = rte_eth_led_off(port_id);
5431 : :
5432 : 0 : if (ret < 0)
5433 : 0 : fprintf(stderr, "Error: Unable to change LED state for port %u: %s\n",
5434 : : port_id, rte_strerror(-ret));
5435 : : }
5436 : :
5437 : : int
5438 : 0 : set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
5439 : : {
5440 : : unsigned int i;
5441 : : unsigned int lcore_cpuid;
5442 : : int record_now;
5443 : :
5444 : : record_now = 0;
5445 : 0 : again:
5446 : 0 : for (i = 0; i < nb_lc; i++) {
5447 : 0 : lcore_cpuid = lcorelist[i];
5448 : 0 : if (! rte_lcore_is_enabled(lcore_cpuid)) {
5449 : 0 : fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
5450 : 0 : return -1;
5451 : : }
5452 : 0 : if (lcore_cpuid == rte_get_main_lcore()) {
5453 : 0 : fprintf(stderr,
5454 : : "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
5455 : : lcore_cpuid);
5456 : 0 : return -1;
5457 : : }
5458 : 0 : if (record_now)
5459 : 0 : fwd_lcores_cpuids[i] = lcore_cpuid;
5460 : : }
5461 : 0 : if (record_now == 0) {
5462 : : record_now = 1;
5463 : 0 : goto again;
5464 : : }
5465 : 0 : nb_cfg_lcores = (lcoreid_t) nb_lc;
5466 : 0 : if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
5467 : : printf("previous number of forwarding cores %u - changed to "
5468 : : "number of configured cores %u\n",
5469 : : (unsigned int) nb_fwd_lcores, nb_lc);
5470 : 0 : nb_fwd_lcores = (lcoreid_t) nb_lc;
5471 : : }
5472 : :
5473 : : return 0;
5474 : : }
5475 : :
5476 : : int
5477 : 0 : set_fwd_lcores_mask(uint64_t lcoremask)
5478 : : {
5479 : : unsigned int lcorelist[64];
5480 : : unsigned int nb_lc;
5481 : : unsigned int i;
5482 : :
5483 : 0 : if (lcoremask == 0) {
5484 : 0 : fprintf(stderr, "Invalid NULL mask of cores\n");
5485 : 0 : return -1;
5486 : : }
5487 : : nb_lc = 0;
5488 : 0 : for (i = 0; i < 64; i++) {
5489 : 0 : if (! ((uint64_t)(1ULL << i) & lcoremask))
5490 : 0 : continue;
5491 : 0 : lcorelist[nb_lc++] = i;
5492 : : }
5493 : 0 : return set_fwd_lcores_list(lcorelist, nb_lc);
5494 : : }
5495 : :
5496 : : void
5497 : 0 : set_fwd_lcores_number(uint16_t nb_lc)
5498 : : {
5499 : 0 : if (test_done == 0) {
5500 : 0 : fprintf(stderr, "Please stop forwarding first\n");
5501 : 0 : return;
5502 : : }
5503 : 0 : if (nb_lc > nb_cfg_lcores) {
5504 : 0 : fprintf(stderr,
5505 : : "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
5506 : : (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
5507 : 0 : return;
5508 : : }
5509 : 0 : nb_fwd_lcores = (lcoreid_t) nb_lc;
5510 : : printf("Number of forwarding cores set to %u\n",
5511 : : (unsigned int) nb_fwd_lcores);
5512 : : }
5513 : :
5514 : : void
5515 : 0 : set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
5516 : : {
5517 : : unsigned int i;
5518 : : portid_t port_id;
5519 : : int record_now;
5520 : :
5521 : : record_now = 0;
5522 : 0 : again:
5523 : 0 : for (i = 0; i < nb_pt; i++) {
5524 : 0 : port_id = (portid_t) portlist[i];
5525 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
5526 : : return;
5527 : 0 : if (record_now)
5528 : 0 : fwd_ports_ids[i] = port_id;
5529 : : }
5530 : 0 : if (record_now == 0) {
5531 : : record_now = 1;
5532 : 0 : goto again;
5533 : : }
5534 : 0 : nb_cfg_ports = (portid_t) nb_pt;
5535 : 0 : if (nb_fwd_ports != (portid_t) nb_pt) {
5536 : 0 : printf("previous number of forwarding ports %u - changed to "
5537 : : "number of configured ports %u\n",
5538 : : (unsigned int) nb_fwd_ports, nb_pt);
5539 : 0 : nb_fwd_ports = (portid_t) nb_pt;
5540 : : }
5541 : : }
5542 : :
5543 : : /**
5544 : : * Parse the user input and obtain the list of forwarding ports
5545 : : *
5546 : : * @param[in] list
5547 : : * String containing the user input. User can specify
5548 : : * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
5549 : : * For example, if the user wants to use all the available
5550 : : * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
5551 : : * If the user wants to use only the ports 1,2 then the input
5552 : : * is 1,2.
5553 : : * valid characters are '-' and ','
5554 : : * @param[out] values
5555 : : * This array will be filled with a list of port IDs
5556 : : * based on the user input
5557 : : * Note that duplicate entries are discarded and only the first
5558 : : * count entries in this array are port IDs and all the rest
5559 : : * will contain default values
5560 : : * @param[in] maxsize
5561 : : * This parameter denotes 2 things
5562 : : * 1) Number of elements in the values array
5563 : : * 2) Maximum value of each element in the values array
5564 : : * @return
5565 : : * On success, returns total count of parsed port IDs
5566 : : * On failure, returns 0
5567 : : */
5568 : : static unsigned int
5569 : 0 : parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
5570 : : {
5571 : : unsigned int count = 0;
5572 : 0 : char *end = NULL;
5573 : : int min, max;
5574 : : int value, i;
5575 : 0 : unsigned int *marked = alloca(sizeof(unsigned int) * maxsize);
5576 : :
5577 : 0 : if (list == NULL || values == NULL)
5578 : : return 0;
5579 : :
5580 : 0 : for (i = 0; i < (int)maxsize; i++)
5581 : 0 : marked[i] = 0;
5582 : :
5583 : : min = INT_MAX;
5584 : :
5585 : : do {
5586 : : /*Remove the blank spaces if any*/
5587 : 0 : while (isblank(*list))
5588 : 0 : list++;
5589 : 0 : if (*list == '\0')
5590 : : break;
5591 : 0 : errno = 0;
5592 : 0 : value = strtol(list, &end, 10);
5593 : 0 : if (errno || end == NULL)
5594 : : return 0;
5595 : 0 : if (value < 0 || value >= (int)maxsize)
5596 : : return 0;
5597 : 0 : while (isblank(*end))
5598 : 0 : end++;
5599 : 0 : if (*end == '-' && min == INT_MAX) {
5600 : : min = value;
5601 : 0 : } else if ((*end == ',') || (*end == '\0')) {
5602 : : max = value;
5603 : 0 : if (min == INT_MAX)
5604 : : min = value;
5605 : 0 : for (i = min; i <= max; i++) {
5606 : 0 : if (count < maxsize) {
5607 : 0 : if (marked[i])
5608 : 0 : continue;
5609 : 0 : values[count] = i;
5610 : 0 : marked[i] = 1;
5611 : 0 : count++;
5612 : : }
5613 : : }
5614 : : min = INT_MAX;
5615 : : } else
5616 : : return 0;
5617 : 0 : list = end + 1;
5618 : 0 : } while (*end != '\0');
5619 : :
5620 : : return count;
5621 : : }
5622 : :
5623 : : void
5624 : 0 : parse_fwd_portlist(const char *portlist)
5625 : : {
5626 : : unsigned int portcount;
5627 : : unsigned int portindex[RTE_MAX_ETHPORTS];
5628 : : unsigned int i, valid_port_count = 0;
5629 : :
5630 : 0 : portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
5631 : 0 : if (!portcount)
5632 : 0 : rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
5633 : :
5634 : : /*
5635 : : * Here we verify the validity of the ports
5636 : : * and thereby calculate the total number of
5637 : : * valid ports
5638 : : */
5639 : 0 : for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
5640 : 0 : if (rte_eth_dev_is_valid_port(portindex[i])) {
5641 : 0 : portindex[valid_port_count] = portindex[i];
5642 : 0 : valid_port_count++;
5643 : : }
5644 : : }
5645 : :
5646 : 0 : set_fwd_ports_list(portindex, valid_port_count);
5647 : 0 : }
5648 : :
5649 : : void
5650 : 0 : set_fwd_ports_mask(uint64_t portmask)
5651 : : {
5652 : : unsigned int portlist[64];
5653 : : unsigned int nb_pt;
5654 : : unsigned int i;
5655 : :
5656 : 0 : if (portmask == 0) {
5657 : 0 : fprintf(stderr, "Invalid NULL mask of ports\n");
5658 : 0 : return;
5659 : : }
5660 : : nb_pt = 0;
5661 : 0 : RTE_ETH_FOREACH_DEV(i) {
5662 : 0 : if (! ((uint64_t)(1ULL << i) & portmask))
5663 : 0 : continue;
5664 : 0 : portlist[nb_pt++] = i;
5665 : : }
5666 : 0 : set_fwd_ports_list(portlist, nb_pt);
5667 : : }
5668 : :
5669 : : void
5670 : 0 : set_fwd_ports_number(uint16_t nb_pt)
5671 : : {
5672 : 0 : if (nb_pt > nb_cfg_ports) {
5673 : 0 : fprintf(stderr,
5674 : : "nb fwd ports %u > %u (number of configured ports) - ignored\n",
5675 : : (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
5676 : 0 : return;
5677 : : }
5678 : 0 : nb_fwd_ports = (portid_t) nb_pt;
5679 : 0 : printf("Number of forwarding ports set to %u\n",
5680 : : (unsigned int) nb_fwd_ports);
5681 : : }
5682 : :
5683 : : int
5684 : 0 : port_is_forwarding(portid_t port_id)
5685 : : {
5686 : : unsigned int i;
5687 : :
5688 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
5689 : : return -1;
5690 : :
5691 : 0 : for (i = 0; i < nb_fwd_ports; i++) {
5692 : 0 : if (fwd_ports_ids[i] == port_id)
5693 : : return 1;
5694 : : }
5695 : :
5696 : : return 0;
5697 : : }
5698 : :
5699 : : void
5700 : 0 : set_nb_pkt_per_burst(uint16_t nb)
5701 : : {
5702 : 0 : if (nb > MAX_PKT_BURST) {
5703 : 0 : fprintf(stderr,
5704 : : "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
5705 : : (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
5706 : 0 : return;
5707 : : }
5708 : 0 : nb_pkt_per_burst = nb;
5709 : 0 : printf("Number of packets per burst set to %u\n",
5710 : : (unsigned int) nb_pkt_per_burst);
5711 : : }
5712 : :
5713 : : static const char *
5714 : : tx_split_get_name(enum tx_pkt_split split)
5715 : : {
5716 : : uint32_t i;
5717 : :
5718 : 0 : for (i = 0; i != RTE_DIM(tx_split_name); i++) {
5719 : 0 : if (tx_split_name[i].split == split)
5720 : 0 : return tx_split_name[i].name;
5721 : : }
5722 : : return NULL;
5723 : : }
5724 : :
5725 : : void
5726 : 0 : set_tx_pkt_split(const char *name)
5727 : : {
5728 : : uint32_t i;
5729 : :
5730 : 0 : for (i = 0; i != RTE_DIM(tx_split_name); i++) {
5731 : 0 : if (strcmp(tx_split_name[i].name, name) == 0) {
5732 : 0 : tx_pkt_split = tx_split_name[i].split;
5733 : 0 : return;
5734 : : }
5735 : : }
5736 : 0 : fprintf(stderr, "unknown value: \"%s\"\n", name);
5737 : : }
5738 : :
5739 : : int
5740 : 0 : parse_fec_mode(const char *name, uint32_t *fec_capa)
5741 : : {
5742 : : uint8_t i;
5743 : :
5744 : 0 : for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
5745 : 0 : if (strcmp(fec_mode_name[i].name, name) == 0) {
5746 : 0 : *fec_capa =
5747 : 0 : RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
5748 : 0 : return 0;
5749 : : }
5750 : : }
5751 : : return -1;
5752 : : }
5753 : :
5754 : : void
5755 : 0 : show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
5756 : : {
5757 : : unsigned int i, j;
5758 : :
5759 : : printf("FEC capabilities:\n");
5760 : :
5761 : 0 : for (i = 0; i < num; i++) {
5762 : 0 : printf("%s : ",
5763 : 0 : rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
5764 : :
5765 : 0 : for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
5766 : 0 : if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
5767 : 0 : speed_fec_capa[i].capa)
5768 : 0 : printf("%s ", fec_mode_name[j].name);
5769 : : }
5770 : : printf("\n");
5771 : : }
5772 : 0 : }
5773 : :
5774 : : void
5775 : 0 : show_rx_pkt_offsets(void)
5776 : : {
5777 : : uint32_t i, n;
5778 : :
5779 : 0 : n = rx_pkt_nb_offs;
5780 : : printf("Number of offsets: %u\n", n);
5781 : 0 : if (n) {
5782 : : printf("Segment offsets: ");
5783 : 0 : for (i = 0; i != n - 1; i++)
5784 : 0 : printf("%hu,", rx_pkt_seg_offsets[i]);
5785 : 0 : printf("%hu\n", rx_pkt_seg_lengths[i]);
5786 : : }
5787 : 0 : }
5788 : :
5789 : : void
5790 : 0 : set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
5791 : : {
5792 : : unsigned int i;
5793 : :
5794 : 0 : if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
5795 : : printf("nb segments per RX packets=%u >= "
5796 : : "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
5797 : 0 : return;
5798 : : }
5799 : :
5800 : : /*
5801 : : * No extra check here, the segment length will be checked by PMD
5802 : : * in the extended queue setup.
5803 : : */
5804 : 0 : for (i = 0; i < nb_offs; i++) {
5805 : 0 : if (seg_offsets[i] >= UINT16_MAX) {
5806 : : printf("offset[%u]=%u > UINT16_MAX - give up\n",
5807 : : i, seg_offsets[i]);
5808 : 0 : return;
5809 : : }
5810 : : }
5811 : :
5812 : 0 : for (i = 0; i < nb_offs; i++)
5813 : 0 : rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
5814 : :
5815 : 0 : rx_pkt_nb_offs = (uint8_t) nb_offs;
5816 : : }
5817 : :
5818 : : void
5819 : 0 : show_rx_pkt_segments(void)
5820 : : {
5821 : : uint32_t i, n;
5822 : :
5823 : 0 : n = rx_pkt_nb_segs;
5824 : : printf("Number of segments: %u\n", n);
5825 : 0 : if (n) {
5826 : : printf("Segment sizes: ");
5827 : 0 : for (i = 0; i != n - 1; i++)
5828 : 0 : printf("%hu,", rx_pkt_seg_lengths[i]);
5829 : 0 : printf("%hu\n", rx_pkt_seg_lengths[i]);
5830 : : }
5831 : 0 : }
5832 : :
5833 : 0 : static const char *get_ptype_str(uint32_t ptype)
5834 : : {
5835 : : const char *str;
5836 : :
5837 : 0 : switch (ptype) {
5838 : : case RTE_PTYPE_L2_ETHER:
5839 : : str = "eth";
5840 : : break;
5841 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
5842 : : str = "ipv4";
5843 : 0 : break;
5844 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
5845 : : str = "ipv6";
5846 : 0 : break;
5847 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP:
5848 : : str = "ipv4-tcp";
5849 : 0 : break;
5850 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP:
5851 : : str = "ipv4-udp";
5852 : 0 : break;
5853 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP:
5854 : : str = "ipv4-sctp";
5855 : 0 : break;
5856 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP:
5857 : : str = "ipv6-tcp";
5858 : 0 : break;
5859 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP:
5860 : : str = "ipv6-udp";
5861 : 0 : break;
5862 : 0 : case RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP:
5863 : : str = "ipv6-sctp";
5864 : 0 : break;
5865 : 0 : case RTE_PTYPE_TUNNEL_GRENAT:
5866 : : str = "grenat";
5867 : 0 : break;
5868 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER:
5869 : : str = "inner-eth";
5870 : 0 : break;
5871 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER
5872 : : | RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
5873 : : str = "inner-ipv4";
5874 : 0 : break;
5875 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER
5876 : : | RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
5877 : : str = "inner-ipv6";
5878 : 0 : break;
5879 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5880 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP:
5881 : : str = "inner-ipv4-tcp";
5882 : 0 : break;
5883 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5884 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP:
5885 : : str = "inner-ipv4-udp";
5886 : 0 : break;
5887 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5888 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP:
5889 : : str = "inner-ipv4-sctp";
5890 : 0 : break;
5891 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5892 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP:
5893 : : str = "inner-ipv6-tcp";
5894 : 0 : break;
5895 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5896 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP:
5897 : : str = "inner-ipv6-udp";
5898 : 0 : break;
5899 : 0 : case RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
5900 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP:
5901 : : str = "inner-ipv6-sctp";
5902 : 0 : break;
5903 : 0 : default:
5904 : : str = "unsupported";
5905 : : }
5906 : :
5907 : 0 : return str;
5908 : : }
5909 : :
5910 : : void
5911 : 0 : show_rx_pkt_hdrs(void)
5912 : : {
5913 : : uint32_t i, n;
5914 : :
5915 : 0 : n = rx_pkt_nb_segs;
5916 : : printf("Number of segments: %u\n", n);
5917 : 0 : if (n) {
5918 : : printf("Packet segs: ");
5919 : 0 : for (i = 0; i < n - 1; i++)
5920 : 0 : printf("%s, ", get_ptype_str(rx_pkt_hdr_protos[i]));
5921 : : printf("payload\n");
5922 : : }
5923 : 0 : }
5924 : :
5925 : : void
5926 : 0 : set_rx_pkt_hdrs(unsigned int *seg_hdrs, unsigned int nb_segs)
5927 : : {
5928 : : unsigned int i;
5929 : :
5930 : 0 : if (nb_segs + 1 > MAX_SEGS_BUFFER_SPLIT) {
5931 : : printf("nb segments per RX packets=%u > "
5932 : : "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs + 1);
5933 : 0 : return;
5934 : : }
5935 : :
5936 : : memset(rx_pkt_hdr_protos, 0, sizeof(rx_pkt_hdr_protos));
5937 : :
5938 : 0 : for (i = 0; i < nb_segs; i++)
5939 : 0 : rx_pkt_hdr_protos[i] = (uint32_t)seg_hdrs[i];
5940 : : /*
5941 : : * We calculate the number of hdrs, but payload is not included,
5942 : : * so rx_pkt_nb_segs would increase 1.
5943 : : */
5944 : 0 : rx_pkt_nb_segs = nb_segs + 1;
5945 : : }
5946 : :
5947 : : void
5948 : 0 : set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
5949 : : {
5950 : : unsigned int i;
5951 : :
5952 : 0 : if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
5953 : : printf("nb segments per RX packets=%u >= "
5954 : : "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
5955 : 0 : return;
5956 : : }
5957 : :
5958 : : /*
5959 : : * No extra check here, the segment length will be checked by PMD
5960 : : * in the extended queue setup.
5961 : : */
5962 : 0 : for (i = 0; i < nb_segs; i++) {
5963 : 0 : if (seg_lengths[i] >= UINT16_MAX) {
5964 : : printf("length[%u]=%u > UINT16_MAX - give up\n",
5965 : : i, seg_lengths[i]);
5966 : 0 : return;
5967 : : }
5968 : : }
5969 : :
5970 : 0 : for (i = 0; i < nb_segs; i++)
5971 : 0 : rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
5972 : :
5973 : 0 : rx_pkt_nb_segs = (uint8_t) nb_segs;
5974 : : }
5975 : :
5976 : : void
5977 : 0 : show_tx_pkt_segments(void)
5978 : : {
5979 : : uint32_t i, n;
5980 : : const char *split;
5981 : :
5982 : 0 : n = tx_pkt_nb_segs;
5983 : 0 : split = tx_split_get_name(tx_pkt_split);
5984 : :
5985 : : printf("Number of segments: %u\n", n);
5986 : : printf("Segment sizes: ");
5987 : 0 : for (i = 0; i != n - 1; i++)
5988 : 0 : printf("%hu,", tx_pkt_seg_lengths[i]);
5989 : 0 : printf("%hu\n", tx_pkt_seg_lengths[i]);
5990 : : printf("Split packet: %s\n", split);
5991 : 0 : }
5992 : :
5993 : : static bool
5994 : 0 : nb_segs_is_invalid(unsigned int nb_segs)
5995 : : {
5996 : : uint16_t ring_size;
5997 : : uint16_t queue_id;
5998 : : uint16_t port_id;
5999 : : int ret;
6000 : :
6001 : 0 : RTE_ETH_FOREACH_DEV(port_id) {
6002 : 0 : for (queue_id = 0; queue_id < nb_txq; queue_id++) {
6003 : 0 : ret = get_tx_ring_size(port_id, queue_id, &ring_size);
6004 : 0 : if (ret) {
6005 : : /* Port may not be initialized yet, can't say
6006 : : * the port is invalid in this stage.
6007 : : */
6008 : 0 : continue;
6009 : : }
6010 : 0 : if (ring_size < nb_segs) {
6011 : 0 : printf("nb segments per TX packets=%u >= TX "
6012 : : "queue(%u) ring_size=%u - txpkts ignored\n",
6013 : : nb_segs, queue_id, ring_size);
6014 : 0 : return true;
6015 : : }
6016 : : }
6017 : : }
6018 : :
6019 : : return false;
6020 : : }
6021 : :
6022 : : void
6023 : 0 : set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
6024 : : {
6025 : : uint16_t tx_pkt_len;
6026 : : unsigned int i;
6027 : :
6028 : : /*
6029 : : * For single segment settings failed check is ignored.
6030 : : * It is a very basic capability to send the single segment
6031 : : * packets, suppose it is always supported.
6032 : : */
6033 : 0 : if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
6034 : 0 : fprintf(stderr,
6035 : : "Tx segment size(%u) is not supported - txpkts ignored\n",
6036 : : nb_segs);
6037 : 0 : return;
6038 : : }
6039 : :
6040 : 0 : if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
6041 : 0 : fprintf(stderr,
6042 : : "Tx segment size(%u) is bigger than max number of segment(%u)\n",
6043 : : nb_segs, RTE_MAX_SEGS_PER_PKT);
6044 : 0 : return;
6045 : : }
6046 : :
6047 : : /*
6048 : : * Check that each segment length is greater or equal than
6049 : : * the mbuf data size.
6050 : : * Check also that the total packet length is greater or equal than the
6051 : : * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
6052 : : * 20 + 8).
6053 : : */
6054 : : tx_pkt_len = 0;
6055 : 0 : for (i = 0; i < nb_segs; i++) {
6056 : 0 : if (seg_lengths[i] > mbuf_data_size[0]) {
6057 : 0 : fprintf(stderr,
6058 : : "length[%u]=%u > mbuf_data_size=%u - give up\n",
6059 : : i, seg_lengths[i], mbuf_data_size[0]);
6060 : 0 : return;
6061 : : }
6062 : 0 : tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
6063 : : }
6064 : 0 : if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
6065 : 0 : fprintf(stderr, "total packet length=%u < %d - give up\n",
6066 : : (unsigned) tx_pkt_len,
6067 : : (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
6068 : 0 : return;
6069 : : }
6070 : :
6071 : 0 : for (i = 0; i < nb_segs; i++)
6072 : 0 : tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
6073 : :
6074 : 0 : tx_pkt_length = tx_pkt_len;
6075 : 0 : tx_pkt_nb_segs = (uint8_t) nb_segs;
6076 : : }
6077 : :
6078 : : void
6079 : 0 : show_tx_pkt_times(void)
6080 : : {
6081 : 0 : printf("Interburst gap: %u\n", tx_pkt_times_inter);
6082 : 0 : printf("Intraburst gap: %u\n", tx_pkt_times_intra);
6083 : 0 : }
6084 : :
6085 : : void
6086 : 0 : set_tx_pkt_times(unsigned int *tx_times)
6087 : : {
6088 : 0 : tx_pkt_times_inter = tx_times[0];
6089 : 0 : tx_pkt_times_intra = tx_times[1];
6090 : 0 : }
6091 : :
6092 : : #ifdef RTE_LIB_GRO
6093 : : void
6094 : 0 : setup_gro(const char *onoff, portid_t port_id)
6095 : : {
6096 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
6097 : 0 : fprintf(stderr, "invalid port id %u\n", port_id);
6098 : 0 : return;
6099 : : }
6100 : 0 : if (test_done == 0) {
6101 : 0 : fprintf(stderr,
6102 : : "Before enable/disable GRO, please stop forwarding first\n");
6103 : 0 : return;
6104 : : }
6105 : 0 : if (strcmp(onoff, "on") == 0) {
6106 : 0 : if (gro_ports[port_id].enable != 0) {
6107 : 0 : fprintf(stderr,
6108 : : "Port %u has enabled GRO. Please disable GRO first\n",
6109 : : port_id);
6110 : 0 : return;
6111 : : }
6112 : 0 : if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
6113 : 0 : gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
6114 : 0 : gro_ports[port_id].param.max_flow_num =
6115 : : GRO_DEFAULT_FLOW_NUM;
6116 : 0 : gro_ports[port_id].param.max_item_per_flow =
6117 : : GRO_DEFAULT_ITEM_NUM_PER_FLOW;
6118 : : }
6119 : 0 : gro_ports[port_id].enable = 1;
6120 : : } else {
6121 : 0 : if (gro_ports[port_id].enable == 0) {
6122 : 0 : fprintf(stderr, "Port %u has disabled GRO\n", port_id);
6123 : 0 : return;
6124 : : }
6125 : 0 : gro_ports[port_id].enable = 0;
6126 : : }
6127 : : }
6128 : :
6129 : : void
6130 : 0 : setup_gro_flush_cycles(uint8_t cycles)
6131 : : {
6132 : 0 : if (test_done == 0) {
6133 : 0 : fprintf(stderr,
6134 : : "Before change flush interval for GRO, please stop forwarding first.\n");
6135 : 0 : return;
6136 : : }
6137 : :
6138 : 0 : if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
6139 : : GRO_DEFAULT_FLUSH_CYCLES) {
6140 : 0 : fprintf(stderr,
6141 : : "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
6142 : : GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
6143 : : cycles = GRO_DEFAULT_FLUSH_CYCLES;
6144 : : }
6145 : :
6146 : 0 : gro_flush_cycles = cycles;
6147 : : }
6148 : :
6149 : : void
6150 : 0 : show_gro(portid_t port_id)
6151 : : {
6152 : : struct rte_gro_param *param;
6153 : : uint32_t max_pkts_num;
6154 : :
6155 : 0 : param = &gro_ports[port_id].param;
6156 : :
6157 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
6158 : 0 : fprintf(stderr, "Invalid port id %u.\n", port_id);
6159 : 0 : return;
6160 : : }
6161 : 0 : if (gro_ports[port_id].enable) {
6162 : : printf("GRO type: TCP/IPv4\n");
6163 : 0 : if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
6164 : 0 : max_pkts_num = param->max_flow_num *
6165 : 0 : param->max_item_per_flow;
6166 : : } else
6167 : : max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
6168 : : printf("Max number of packets to perform GRO: %u\n",
6169 : : max_pkts_num);
6170 : 0 : printf("Flushing cycles: %u\n", gro_flush_cycles);
6171 : : } else
6172 : : printf("Port %u doesn't enable GRO.\n", port_id);
6173 : : }
6174 : : #endif /* RTE_LIB_GRO */
6175 : :
6176 : : #ifdef RTE_LIB_GSO
6177 : : void
6178 : 0 : setup_gso(const char *mode, portid_t port_id)
6179 : : {
6180 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
6181 : 0 : fprintf(stderr, "invalid port id %u\n", port_id);
6182 : 0 : return;
6183 : : }
6184 : 0 : if (strcmp(mode, "on") == 0) {
6185 : 0 : if (test_done == 0) {
6186 : 0 : fprintf(stderr,
6187 : : "before enabling GSO, please stop forwarding first\n");
6188 : 0 : return;
6189 : : }
6190 : 0 : gso_ports[port_id].enable = 1;
6191 : 0 : } else if (strcmp(mode, "off") == 0) {
6192 : 0 : if (test_done == 0) {
6193 : 0 : fprintf(stderr,
6194 : : "before disabling GSO, please stop forwarding first\n");
6195 : 0 : return;
6196 : : }
6197 : 0 : gso_ports[port_id].enable = 0;
6198 : : }
6199 : : }
6200 : : #endif /* RTE_LIB_GSO */
6201 : :
6202 : : char*
6203 : 0 : list_pkt_forwarding_modes(void)
6204 : : {
6205 : : static char fwd_modes[128] = "";
6206 : : const char *separator = "|";
6207 : : struct fwd_engine *fwd_eng;
6208 : : unsigned i = 0;
6209 : :
6210 : 0 : if (strlen (fwd_modes) == 0) {
6211 : 0 : while ((fwd_eng = fwd_engines[i++]) != NULL) {
6212 : 0 : strncat(fwd_modes, fwd_eng->fwd_mode_name,
6213 : 0 : sizeof(fwd_modes) - strlen(fwd_modes) - 1);
6214 : 0 : strncat(fwd_modes, separator,
6215 : 0 : sizeof(fwd_modes) - strlen(fwd_modes) - 1);
6216 : : }
6217 : 0 : fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
6218 : : }
6219 : :
6220 : 0 : return fwd_modes;
6221 : : }
6222 : :
6223 : : char*
6224 : 0 : list_pkt_forwarding_retry_modes(void)
6225 : : {
6226 : : static char fwd_modes[128] = "";
6227 : : const char *separator = "|";
6228 : : struct fwd_engine *fwd_eng;
6229 : : unsigned i = 0;
6230 : :
6231 : 0 : if (strlen(fwd_modes) == 0) {
6232 : 0 : while ((fwd_eng = fwd_engines[i++]) != NULL) {
6233 : 0 : if (fwd_eng == &rx_only_engine)
6234 : 0 : continue;
6235 : 0 : strncat(fwd_modes, fwd_eng->fwd_mode_name,
6236 : : sizeof(fwd_modes) -
6237 : 0 : strlen(fwd_modes) - 1);
6238 : 0 : strncat(fwd_modes, separator,
6239 : : sizeof(fwd_modes) -
6240 : 0 : strlen(fwd_modes) - 1);
6241 : : }
6242 : 0 : fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
6243 : : }
6244 : :
6245 : 0 : return fwd_modes;
6246 : : }
6247 : :
6248 : : void
6249 : 0 : set_pkt_forwarding_mode(const char *fwd_mode_name)
6250 : : {
6251 : : struct fwd_engine *fwd_eng;
6252 : : unsigned i;
6253 : :
6254 : : i = 0;
6255 : 0 : while ((fwd_eng = fwd_engines[i]) != NULL) {
6256 : 0 : if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
6257 : 0 : printf("Set %s packet forwarding mode%s\n",
6258 : : fwd_mode_name,
6259 : 0 : retry_enabled == 0 ? "" : " with retry");
6260 : 0 : cur_fwd_eng = fwd_eng;
6261 : 0 : return;
6262 : : }
6263 : 0 : i++;
6264 : : }
6265 : 0 : fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
6266 : : }
6267 : :
6268 : : void
6269 : 0 : add_rx_dump_callbacks(portid_t portid)
6270 : : {
6271 : : struct rte_eth_dev_info dev_info;
6272 : : uint16_t queue;
6273 : : int ret;
6274 : :
6275 : 0 : if (port_id_is_invalid(portid, ENABLED_WARN))
6276 : 0 : return;
6277 : :
6278 : 0 : ret = eth_dev_info_get_print_err(portid, &dev_info);
6279 : 0 : if (ret != 0)
6280 : : return;
6281 : :
6282 : 0 : for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
6283 : 0 : if (!ports[portid].rx_dump_cb[queue])
6284 : 0 : ports[portid].rx_dump_cb[queue] =
6285 : 0 : rte_eth_add_rx_callback(portid, queue,
6286 : : dump_rx_pkts, NULL);
6287 : : }
6288 : :
6289 : : void
6290 : 0 : add_tx_dump_callbacks(portid_t portid)
6291 : : {
6292 : : struct rte_eth_dev_info dev_info;
6293 : : uint16_t queue;
6294 : : int ret;
6295 : :
6296 : 0 : if (port_id_is_invalid(portid, ENABLED_WARN))
6297 : 0 : return;
6298 : :
6299 : 0 : ret = eth_dev_info_get_print_err(portid, &dev_info);
6300 : 0 : if (ret != 0)
6301 : : return;
6302 : :
6303 : 0 : for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
6304 : 0 : if (!ports[portid].tx_dump_cb[queue])
6305 : 0 : ports[portid].tx_dump_cb[queue] =
6306 : 0 : rte_eth_add_tx_callback(portid, queue,
6307 : : dump_tx_pkts, NULL);
6308 : : }
6309 : :
6310 : : void
6311 : 0 : remove_rx_dump_callbacks(portid_t portid)
6312 : : {
6313 : : struct rte_eth_dev_info dev_info;
6314 : : uint16_t queue;
6315 : : int ret;
6316 : :
6317 : 0 : if (port_id_is_invalid(portid, ENABLED_WARN))
6318 : 0 : return;
6319 : :
6320 : 0 : ret = eth_dev_info_get_print_err(portid, &dev_info);
6321 : 0 : if (ret != 0)
6322 : : return;
6323 : :
6324 : 0 : for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
6325 : 0 : if (ports[portid].rx_dump_cb[queue]) {
6326 : 0 : rte_eth_remove_rx_callback(portid, queue,
6327 : : ports[portid].rx_dump_cb[queue]);
6328 : 0 : ports[portid].rx_dump_cb[queue] = NULL;
6329 : : }
6330 : : }
6331 : :
6332 : : void
6333 : 0 : remove_tx_dump_callbacks(portid_t portid)
6334 : : {
6335 : : struct rte_eth_dev_info dev_info;
6336 : : uint16_t queue;
6337 : : int ret;
6338 : :
6339 : 0 : if (port_id_is_invalid(portid, ENABLED_WARN))
6340 : 0 : return;
6341 : :
6342 : 0 : ret = eth_dev_info_get_print_err(portid, &dev_info);
6343 : 0 : if (ret != 0)
6344 : : return;
6345 : :
6346 : 0 : for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
6347 : 0 : if (ports[portid].tx_dump_cb[queue]) {
6348 : 0 : rte_eth_remove_tx_callback(portid, queue,
6349 : : ports[portid].tx_dump_cb[queue]);
6350 : 0 : ports[portid].tx_dump_cb[queue] = NULL;
6351 : : }
6352 : : }
6353 : :
6354 : : void
6355 : 0 : configure_rxtx_dump_callbacks(uint16_t verbose)
6356 : : {
6357 : : portid_t portid;
6358 : :
6359 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6360 : : TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
6361 : : return;
6362 : : #endif
6363 : :
6364 : 0 : RTE_ETH_FOREACH_DEV(portid)
6365 : : {
6366 : 0 : if (verbose == 1 || verbose > 2)
6367 : 0 : add_rx_dump_callbacks(portid);
6368 : : else
6369 : 0 : remove_rx_dump_callbacks(portid);
6370 : 0 : if (verbose >= 2)
6371 : 0 : add_tx_dump_callbacks(portid);
6372 : : else
6373 : 0 : remove_tx_dump_callbacks(portid);
6374 : : }
6375 : 0 : }
6376 : :
6377 : : void
6378 : 0 : set_verbose_level(uint16_t vb_level)
6379 : : {
6380 : 0 : printf("Change verbose level from %u to %u\n",
6381 : : (unsigned int) verbose_level, (unsigned int) vb_level);
6382 : 0 : verbose_level = vb_level;
6383 : 0 : configure_rxtx_dump_callbacks(verbose_level);
6384 : 0 : }
6385 : :
6386 : : void
6387 : 0 : vlan_extend_set(portid_t port_id, int on)
6388 : : {
6389 : : int diag;
6390 : : int vlan_offload;
6391 : 0 : uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
6392 : :
6393 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6394 : : return;
6395 : :
6396 : 0 : vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
6397 : :
6398 : 0 : if (on) {
6399 : 0 : vlan_offload |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
6400 : 0 : port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
6401 : : } else {
6402 : 0 : vlan_offload &= ~RTE_ETH_VLAN_EXTEND_OFFLOAD;
6403 : 0 : port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
6404 : : }
6405 : :
6406 : 0 : diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
6407 : 0 : if (diag < 0) {
6408 : 0 : fprintf(stderr,
6409 : : "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
6410 : : port_id, on, diag);
6411 : 0 : return;
6412 : : }
6413 : 0 : ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
6414 : : }
6415 : :
6416 : : void
6417 : 0 : rx_vlan_strip_set(portid_t port_id, int on)
6418 : : {
6419 : : int diag;
6420 : : int vlan_offload;
6421 : 0 : uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
6422 : :
6423 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6424 : : return;
6425 : :
6426 : 0 : vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
6427 : :
6428 : 0 : if (on) {
6429 : 0 : vlan_offload |= RTE_ETH_VLAN_STRIP_OFFLOAD;
6430 : 0 : port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
6431 : : } else {
6432 : 0 : vlan_offload &= ~RTE_ETH_VLAN_STRIP_OFFLOAD;
6433 : 0 : port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
6434 : : }
6435 : :
6436 : 0 : diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
6437 : 0 : if (diag < 0) {
6438 : 0 : fprintf(stderr,
6439 : : "%s(port_pi=%d, on=%d) failed diag=%d\n",
6440 : : __func__, port_id, on, diag);
6441 : 0 : return;
6442 : : }
6443 : 0 : ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
6444 : : }
6445 : :
6446 : : void
6447 : 0 : rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
6448 : : {
6449 : : int diag;
6450 : :
6451 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6452 : : return;
6453 : :
6454 : 0 : diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
6455 : 0 : if (diag < 0)
6456 : 0 : fprintf(stderr,
6457 : : "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
6458 : : __func__, port_id, queue_id, on, diag);
6459 : : }
6460 : :
6461 : : void
6462 : 0 : nic_xstats_set_counter(portid_t port_id, char *counter_name, int on)
6463 : : {
6464 : : struct rte_eth_xstat_name *xstats_names;
6465 : : int cnt_xstats;
6466 : : int ret;
6467 : : uint64_t id;
6468 : :
6469 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN)) {
6470 : 0 : print_valid_ports();
6471 : 0 : return;
6472 : : }
6473 : 0 : if (!rte_eth_dev_is_valid_port(port_id)) {
6474 : 0 : fprintf(stderr, "Error: Invalid port number %i\n", port_id);
6475 : 0 : return;
6476 : : }
6477 : :
6478 : 0 : if (counter_name == NULL) {
6479 : 0 : fprintf(stderr, "Error: Invalid counter name\n");
6480 : 0 : return;
6481 : : }
6482 : :
6483 : : /* Get count */
6484 : 0 : cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
6485 : 0 : if (cnt_xstats < 0) {
6486 : 0 : fprintf(stderr, "Error: Cannot get count of xstats\n");
6487 : 0 : return;
6488 : : }
6489 : :
6490 : : /* Get id-name lookup table */
6491 : 0 : xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
6492 : 0 : if (xstats_names == NULL) {
6493 : 0 : fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
6494 : 0 : return;
6495 : : }
6496 : 0 : if (cnt_xstats != rte_eth_xstats_get_names(
6497 : : port_id, xstats_names, cnt_xstats)) {
6498 : 0 : fprintf(stderr, "Error: Cannot get xstats lookup\n");
6499 : 0 : free(xstats_names);
6500 : 0 : return;
6501 : : }
6502 : :
6503 : 0 : if (rte_eth_xstats_get_id_by_name(port_id, counter_name, &id) < 0) {
6504 : 0 : fprintf(stderr, "Cannot find xstats with a given name\n");
6505 : 0 : free(xstats_names);
6506 : 0 : return;
6507 : : }
6508 : :
6509 : : /* set counter */
6510 : 0 : ret = rte_eth_xstats_set_counter(port_id, id, on);
6511 : 0 : if (ret < 0) {
6512 : 0 : switch (ret) {
6513 : 0 : case -EINVAL:
6514 : 0 : fprintf(stderr, "failed to find %s\n", counter_name);
6515 : : break;
6516 : 0 : case -ENOTSUP:
6517 : 0 : fprintf(stderr, "operation not supported by device\n");
6518 : : break;
6519 : 0 : case -ENOSPC:
6520 : 0 : fprintf(stderr, "there were not enough available counters\n");
6521 : : break;
6522 : 0 : case -EPERM:
6523 : 0 : fprintf(stderr, "operation not premitted\n");
6524 : : break;
6525 : 0 : default:
6526 : 0 : fprintf(stderr, "operation failed - diag=%d\n", ret);
6527 : : break;
6528 : : }
6529 : : }
6530 : 0 : free(xstats_names);
6531 : : }
6532 : :
6533 : : void
6534 : 0 : rx_vlan_filter_set(portid_t port_id, int on)
6535 : : {
6536 : : int diag;
6537 : : int vlan_offload;
6538 : 0 : uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
6539 : :
6540 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6541 : : return;
6542 : :
6543 : 0 : vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
6544 : :
6545 : 0 : if (on) {
6546 : 0 : vlan_offload |= RTE_ETH_VLAN_FILTER_OFFLOAD;
6547 : 0 : port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
6548 : : } else {
6549 : 0 : vlan_offload &= ~RTE_ETH_VLAN_FILTER_OFFLOAD;
6550 : 0 : port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
6551 : : }
6552 : :
6553 : 0 : diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
6554 : 0 : if (diag < 0) {
6555 : 0 : fprintf(stderr,
6556 : : "%s(port_pi=%d, on=%d) failed diag=%d\n",
6557 : : __func__, port_id, on, diag);
6558 : 0 : return;
6559 : : }
6560 : 0 : ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
6561 : : }
6562 : :
6563 : : void
6564 : 0 : rx_vlan_qinq_strip_set(portid_t port_id, int on)
6565 : : {
6566 : : int diag;
6567 : : int vlan_offload;
6568 : 0 : uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
6569 : :
6570 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6571 : : return;
6572 : :
6573 : 0 : vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
6574 : :
6575 : 0 : if (on) {
6576 : 0 : vlan_offload |= RTE_ETH_QINQ_STRIP_OFFLOAD;
6577 : 0 : port_rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
6578 : : } else {
6579 : 0 : vlan_offload &= ~RTE_ETH_QINQ_STRIP_OFFLOAD;
6580 : 0 : port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
6581 : : }
6582 : :
6583 : 0 : diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
6584 : 0 : if (diag < 0) {
6585 : 0 : fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
6586 : : __func__, port_id, on, diag);
6587 : 0 : return;
6588 : : }
6589 : 0 : ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
6590 : : }
6591 : :
6592 : : int
6593 : 0 : rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
6594 : : {
6595 : : int diag;
6596 : :
6597 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6598 : : return 1;
6599 : 0 : if (vlan_id_is_invalid(vlan_id))
6600 : 0 : return 1;
6601 : 0 : diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
6602 : 0 : if (diag == 0)
6603 : : return 0;
6604 : 0 : fprintf(stderr,
6605 : : "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
6606 : : port_id, vlan_id, on, diag);
6607 : 0 : return -1;
6608 : : }
6609 : :
6610 : : void
6611 : 0 : rx_vlan_all_filter_set(portid_t port_id, int on)
6612 : : {
6613 : : uint16_t vlan_id;
6614 : :
6615 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6616 : : return;
6617 : 0 : for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
6618 : 0 : if (rx_vft_set(port_id, vlan_id, on))
6619 : : break;
6620 : : }
6621 : : }
6622 : :
6623 : : void
6624 : 0 : vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
6625 : : {
6626 : : int diag;
6627 : :
6628 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6629 : : return;
6630 : :
6631 : 0 : diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
6632 : 0 : if (diag == 0)
6633 : : return;
6634 : :
6635 : 0 : fprintf(stderr,
6636 : : "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
6637 : : port_id, vlan_type, tp_id, diag);
6638 : : }
6639 : :
6640 : : void
6641 : 0 : tx_vlan_set(portid_t port_id, uint16_t vlan_id)
6642 : : {
6643 : : struct rte_eth_dev_info dev_info;
6644 : : int ret;
6645 : :
6646 : 0 : if (vlan_id_is_invalid(vlan_id))
6647 : 0 : return;
6648 : :
6649 : 0 : if (ports[port_id].dev_conf.txmode.offloads &
6650 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT) {
6651 : 0 : fprintf(stderr, "Error, as QinQ has been enabled.\n");
6652 : 0 : return;
6653 : : }
6654 : :
6655 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
6656 : 0 : if (ret != 0)
6657 : : return;
6658 : :
6659 : 0 : if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) == 0) {
6660 : 0 : fprintf(stderr,
6661 : : "Error: vlan insert is not supported by port %d\n",
6662 : : port_id);
6663 : 0 : return;
6664 : : }
6665 : :
6666 : : tx_vlan_reset(port_id);
6667 : 0 : ports[port_id].dev_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
6668 : 0 : ports[port_id].tx_vlan_id = vlan_id;
6669 : : }
6670 : :
6671 : : void
6672 : 0 : tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
6673 : : {
6674 : : struct rte_eth_dev_info dev_info;
6675 : : int ret;
6676 : :
6677 : 0 : if (vlan_id_is_invalid(vlan_id))
6678 : 0 : return;
6679 : 0 : if (vlan_id_is_invalid(vlan_id_outer))
6680 : 0 : return;
6681 : :
6682 : 0 : ret = eth_dev_info_get_print_err(port_id, &dev_info);
6683 : 0 : if (ret != 0)
6684 : : return;
6685 : :
6686 : 0 : if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) == 0) {
6687 : 0 : fprintf(stderr,
6688 : : "Error: qinq insert not supported by port %d\n",
6689 : : port_id);
6690 : 0 : return;
6691 : : }
6692 : :
6693 : : tx_vlan_reset(port_id);
6694 : 0 : ports[port_id].dev_conf.txmode.offloads |= (RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
6695 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
6696 : 0 : ports[port_id].tx_vlan_id = vlan_id;
6697 : 0 : ports[port_id].tx_vlan_id_outer = vlan_id_outer;
6698 : : }
6699 : :
6700 : : void
6701 : 0 : tx_vlan_reset(portid_t port_id)
6702 : : {
6703 : 0 : ports[port_id].dev_conf.txmode.offloads &=
6704 : : ~(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
6705 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
6706 : 0 : ports[port_id].tx_vlan_id = 0;
6707 : 0 : ports[port_id].tx_vlan_id_outer = 0;
6708 : 0 : }
6709 : :
6710 : : void
6711 : 0 : tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
6712 : : {
6713 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6714 : : return;
6715 : :
6716 : 0 : rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
6717 : : }
6718 : :
6719 : : void
6720 : 0 : set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
6721 : : {
6722 : : int ret;
6723 : :
6724 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6725 : : return;
6726 : :
6727 : 0 : if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
6728 : : return;
6729 : :
6730 : 0 : if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
6731 : 0 : fprintf(stderr, "map_value not in required range 0..%d\n",
6732 : : RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
6733 : 0 : return;
6734 : : }
6735 : :
6736 : 0 : if (!is_rx) { /* tx */
6737 : 0 : ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
6738 : : map_value);
6739 : 0 : if (ret) {
6740 : 0 : fprintf(stderr,
6741 : : "failed to set tx queue stats mapping.\n");
6742 : 0 : return;
6743 : : }
6744 : : } else { /* rx */
6745 : 0 : ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
6746 : : map_value);
6747 : 0 : if (ret) {
6748 : 0 : fprintf(stderr,
6749 : : "failed to set rx queue stats mapping.\n");
6750 : 0 : return;
6751 : : }
6752 : : }
6753 : : }
6754 : :
6755 : : void
6756 : 0 : set_xstats_hide_zero(uint8_t on_off)
6757 : : {
6758 : 0 : xstats_hide_zero = on_off;
6759 : 0 : }
6760 : :
6761 : : void
6762 : 0 : set_xstats_show_state(uint8_t on_off)
6763 : : {
6764 : 0 : xstats_show_state = on_off;
6765 : 0 : }
6766 : :
6767 : : void
6768 : 0 : set_xstats_hide_disabled(uint8_t on_off)
6769 : : {
6770 : 0 : xstats_hide_disabled = on_off;
6771 : 0 : }
6772 : :
6773 : : void
6774 : 0 : set_record_core_cycles(uint8_t on_off)
6775 : : {
6776 : 0 : record_core_cycles = on_off;
6777 : 0 : }
6778 : :
6779 : : void
6780 : 0 : set_record_burst_stats(uint8_t on_off)
6781 : : {
6782 : 0 : record_burst_stats = on_off;
6783 : 0 : }
6784 : :
6785 : : uint16_t
6786 : 0 : str_to_flowtype(const char *string)
6787 : : {
6788 : : uint8_t i;
6789 : :
6790 : 0 : for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
6791 : 0 : if (!strcmp(flowtype_str_table[i].str, string))
6792 : 0 : return flowtype_str_table[i].ftype;
6793 : : }
6794 : :
6795 : 0 : if (isdigit(string[0])) {
6796 : : int val = atoi(string);
6797 : 0 : if (val > 0 && val < 64)
6798 : 0 : return (uint16_t)val;
6799 : : }
6800 : :
6801 : : return RTE_ETH_FLOW_UNKNOWN;
6802 : : }
6803 : :
6804 : : const char*
6805 : 0 : flowtype_to_str(uint16_t flow_type)
6806 : : {
6807 : : uint8_t i;
6808 : :
6809 : 0 : for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
6810 : 0 : if (flowtype_str_table[i].ftype == flow_type)
6811 : 0 : return flowtype_str_table[i].str;
6812 : : }
6813 : :
6814 : : return NULL;
6815 : : }
6816 : :
6817 : : #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
6818 : :
6819 : : static inline void
6820 : 0 : print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
6821 : : {
6822 : : struct rte_eth_flex_payload_cfg *cfg;
6823 : : uint32_t i, j;
6824 : :
6825 : 0 : for (i = 0; i < flex_conf->nb_payloads; i++) {
6826 : : cfg = &flex_conf->flex_set[i];
6827 : 0 : if (cfg->type == RTE_ETH_RAW_PAYLOAD)
6828 : : printf("\n RAW: ");
6829 : 0 : else if (cfg->type == RTE_ETH_L2_PAYLOAD)
6830 : : printf("\n L2_PAYLOAD: ");
6831 : 0 : else if (cfg->type == RTE_ETH_L3_PAYLOAD)
6832 : : printf("\n L3_PAYLOAD: ");
6833 : 0 : else if (cfg->type == RTE_ETH_L4_PAYLOAD)
6834 : : printf("\n L4_PAYLOAD: ");
6835 : : else
6836 : : printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
6837 : 0 : for (j = 0; j < num; j++)
6838 : 0 : printf(" %-5u", cfg->src_offset[j]);
6839 : : }
6840 : : printf("\n");
6841 : 0 : }
6842 : :
6843 : : static inline void
6844 : 0 : print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
6845 : : {
6846 : : struct rte_eth_fdir_flex_mask *mask;
6847 : : uint32_t i, j;
6848 : : const char *p;
6849 : :
6850 : 0 : for (i = 0; i < flex_conf->nb_flexmasks; i++) {
6851 : : mask = &flex_conf->flex_mask[i];
6852 : 0 : p = flowtype_to_str(mask->flow_type);
6853 : 0 : printf("\n %s:\t", p ? p : "unknown");
6854 : 0 : for (j = 0; j < num; j++)
6855 : 0 : printf(" %02x", mask->mask[j]);
6856 : : }
6857 : : printf("\n");
6858 : 0 : }
6859 : :
6860 : : static inline void
6861 : 0 : print_fdir_flow_type(uint32_t flow_types_mask)
6862 : : {
6863 : : int i;
6864 : : const char *p;
6865 : :
6866 : 0 : for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
6867 : 0 : if (!(flow_types_mask & (1 << i)))
6868 : 0 : continue;
6869 : 0 : p = flowtype_to_str(i);
6870 : 0 : if (p)
6871 : : printf(" %s", p);
6872 : : else
6873 : : printf(" unknown");
6874 : : }
6875 : : printf("\n");
6876 : 0 : }
6877 : :
6878 : : static int
6879 : 0 : get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
6880 : : struct rte_eth_fdir_stats *fdir_stat)
6881 : : {
6882 : : int ret = -ENOTSUP;
6883 : :
6884 : : #ifdef RTE_NET_I40E
6885 : : if (ret == -ENOTSUP) {
6886 : 0 : ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
6887 : 0 : if (!ret)
6888 : 0 : ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
6889 : : }
6890 : : #endif
6891 : : #ifdef RTE_NET_IXGBE
6892 : 0 : if (ret == -ENOTSUP) {
6893 : 0 : ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
6894 : 0 : if (!ret)
6895 : 0 : ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
6896 : : }
6897 : : #endif
6898 : 0 : switch (ret) {
6899 : : case 0:
6900 : : break;
6901 : 0 : case -ENOTSUP:
6902 : 0 : fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
6903 : : port_id);
6904 : : break;
6905 : 0 : default:
6906 : 0 : fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
6907 : : break;
6908 : : }
6909 : 0 : return ret;
6910 : : }
6911 : :
6912 : : void
6913 : 0 : fdir_get_infos(portid_t port_id)
6914 : : {
6915 : : struct rte_eth_fdir_stats fdir_stat;
6916 : : struct rte_eth_fdir_info fdir_info;
6917 : :
6918 : : static const char *fdir_stats_border = "########################";
6919 : :
6920 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
6921 : 0 : return;
6922 : :
6923 : : memset(&fdir_info, 0, sizeof(fdir_info));
6924 : : memset(&fdir_stat, 0, sizeof(fdir_stat));
6925 : 0 : if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
6926 : : return;
6927 : :
6928 : 0 : printf("\n %s FDIR infos for port %-2d %s\n",
6929 : : fdir_stats_border, port_id, fdir_stats_border);
6930 : : printf(" MODE: ");
6931 : 0 : if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
6932 : : printf(" PERFECT\n");
6933 : 0 : else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
6934 : : printf(" PERFECT-MAC-VLAN\n");
6935 : 0 : else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
6936 : : printf(" PERFECT-TUNNEL\n");
6937 : 0 : else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
6938 : : printf(" SIGNATURE\n");
6939 : : else
6940 : : printf(" DISABLE\n");
6941 : 0 : if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
6942 : 0 : && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
6943 : : printf(" SUPPORTED FLOW TYPE: ");
6944 : 0 : print_fdir_flow_type(fdir_info.flow_types_mask[0]);
6945 : : }
6946 : : printf(" FLEX PAYLOAD INFO:\n");
6947 : 0 : printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
6948 : : " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
6949 : : " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
6950 : 0 : fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
6951 : : fdir_info.flex_payload_unit,
6952 : : fdir_info.max_flex_payload_segment_num,
6953 : : fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
6954 : 0 : if (fdir_info.flex_conf.nb_payloads > 0) {
6955 : : printf(" FLEX PAYLOAD SRC OFFSET:");
6956 : 0 : print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
6957 : : }
6958 : 0 : if (fdir_info.flex_conf.nb_flexmasks > 0) {
6959 : : printf(" FLEX MASK CFG:");
6960 : 0 : print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
6961 : : }
6962 : 0 : printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
6963 : : fdir_stat.guarant_cnt, fdir_stat.best_cnt);
6964 : 0 : printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
6965 : : fdir_info.guarant_spc, fdir_info.best_spc);
6966 : 0 : printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
6967 : : " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
6968 : : " add: %-10"PRIu64" remove: %"PRIu64"\n"
6969 : : " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
6970 : : fdir_stat.collision, fdir_stat.free,
6971 : : fdir_stat.maxhash, fdir_stat.maxlen,
6972 : : fdir_stat.add, fdir_stat.remove,
6973 : : fdir_stat.f_add, fdir_stat.f_remove);
6974 : 0 : printf(" %s############################%s\n",
6975 : : fdir_stats_border, fdir_stats_border);
6976 : : }
6977 : :
6978 : : #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
6979 : :
6980 : : void
6981 : 0 : set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
6982 : : {
6983 : : #ifdef RTE_NET_IXGBE
6984 : : int diag;
6985 : :
6986 : 0 : if (is_rx)
6987 : 0 : diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
6988 : : else
6989 : 0 : diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
6990 : :
6991 : 0 : if (diag == 0)
6992 : : return;
6993 : 0 : fprintf(stderr,
6994 : : "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
6995 : : is_rx ? "rx" : "tx", port_id, diag);
6996 : : return;
6997 : : #endif
6998 : : fprintf(stderr, "VF %s setting not supported for port %d\n",
6999 : : is_rx ? "Rx" : "Tx", port_id);
7000 : : RTE_SET_USED(vf);
7001 : : RTE_SET_USED(on);
7002 : : }
7003 : :
7004 : : int
7005 : 0 : set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint32_t rate)
7006 : : {
7007 : : int diag;
7008 : : struct rte_eth_link link;
7009 : : int ret;
7010 : :
7011 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7012 : : return 1;
7013 : 0 : ret = eth_link_get_nowait_print_err(port_id, &link);
7014 : 0 : if (ret < 0)
7015 : : return 1;
7016 : 0 : if (link.link_speed != RTE_ETH_SPEED_NUM_UNKNOWN &&
7017 : : rate > link.link_speed) {
7018 : 0 : fprintf(stderr,
7019 : : "Invalid rate value:%u bigger than link speed: %u\n",
7020 : : rate, link.link_speed);
7021 : 0 : return 1;
7022 : : }
7023 : 0 : diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
7024 : 0 : if (diag == 0)
7025 : : return diag;
7026 : 0 : fprintf(stderr,
7027 : : "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
7028 : : port_id, diag);
7029 : 0 : return diag;
7030 : : }
7031 : :
7032 : : int
7033 : 0 : set_vf_rate_limit(portid_t port_id, uint16_t vf, uint32_t rate, uint64_t q_msk)
7034 : : {
7035 : : int diag = -ENOTSUP;
7036 : :
7037 : : RTE_SET_USED(vf);
7038 : : RTE_SET_USED(rate);
7039 : : RTE_SET_USED(q_msk);
7040 : :
7041 : : #ifdef RTE_NET_IXGBE
7042 : : if (diag == -ENOTSUP)
7043 : 0 : diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
7044 : : q_msk);
7045 : : #endif
7046 : : #ifdef RTE_NET_BNXT
7047 : 0 : if (diag == -ENOTSUP)
7048 : 0 : diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
7049 : : #endif
7050 : 0 : if (diag == 0)
7051 : : return diag;
7052 : :
7053 : 0 : fprintf(stderr,
7054 : : "%s for port_id=%d failed diag=%d\n",
7055 : : __func__, port_id, diag);
7056 : 0 : return diag;
7057 : : }
7058 : :
7059 : : int
7060 : 0 : set_rxq_avail_thresh(portid_t port_id, uint16_t queue_id, uint8_t avail_thresh)
7061 : : {
7062 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7063 : : return -EINVAL;
7064 : :
7065 : 0 : return rte_eth_rx_avail_thresh_set(port_id, queue_id, avail_thresh);
7066 : : }
7067 : :
7068 : : /*
7069 : : * Functions to manage the set of filtered Multicast MAC addresses.
7070 : : *
7071 : : * A pool of filtered multicast MAC addresses is associated with each port.
7072 : : * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
7073 : : * The address of the pool and the number of valid multicast MAC addresses
7074 : : * recorded in the pool are stored in the fields "mc_addr_pool" and
7075 : : * "mc_addr_nb" of the "rte_port" data structure.
7076 : : *
7077 : : * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
7078 : : * to be supplied a contiguous array of multicast MAC addresses.
7079 : : * To comply with this constraint, the set of multicast addresses recorded
7080 : : * into the pool are systematically compacted at the beginning of the pool.
7081 : : * Hence, when a multicast address is removed from the pool, all following
7082 : : * addresses, if any, are copied back to keep the set contiguous.
7083 : : */
7084 : : #define MCAST_POOL_INC 32
7085 : :
7086 : : static int
7087 : 0 : mcast_addr_pool_extend(struct rte_port *port)
7088 : : {
7089 : : struct rte_ether_addr *mc_pool;
7090 : : size_t mc_pool_size;
7091 : :
7092 : : /*
7093 : : * If a free entry is available at the end of the pool, just
7094 : : * increment the number of recorded multicast addresses.
7095 : : */
7096 : 0 : if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
7097 : 0 : port->mc_addr_nb++;
7098 : 0 : return 0;
7099 : : }
7100 : :
7101 : : /*
7102 : : * [re]allocate a pool with MCAST_POOL_INC more entries.
7103 : : * The previous test guarantees that port->mc_addr_nb is a multiple
7104 : : * of MCAST_POOL_INC.
7105 : : */
7106 : 0 : mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
7107 : : MCAST_POOL_INC);
7108 : 0 : mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
7109 : : mc_pool_size);
7110 : 0 : if (mc_pool == NULL) {
7111 : 0 : fprintf(stderr,
7112 : : "allocation of pool of %u multicast addresses failed\n",
7113 : 0 : port->mc_addr_nb + MCAST_POOL_INC);
7114 : 0 : return -ENOMEM;
7115 : : }
7116 : :
7117 : 0 : port->mc_addr_pool = mc_pool;
7118 : 0 : port->mc_addr_nb++;
7119 : 0 : return 0;
7120 : :
7121 : : }
7122 : :
7123 : : static void
7124 : 0 : mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
7125 : : {
7126 : 0 : if (mcast_addr_pool_extend(port) != 0)
7127 : : return;
7128 : 0 : rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
7129 : : }
7130 : :
7131 : : static void
7132 : 0 : mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
7133 : : {
7134 : 0 : port->mc_addr_nb--;
7135 : 0 : if (addr_idx == port->mc_addr_nb) {
7136 : : /* No need to recompact the set of multicast addresses. */
7137 : 0 : if (port->mc_addr_nb == 0) {
7138 : : /* free the pool of multicast addresses. */
7139 : 0 : free(port->mc_addr_pool);
7140 : 0 : port->mc_addr_pool = NULL;
7141 : : }
7142 : 0 : return;
7143 : : }
7144 : 0 : memmove(&port->mc_addr_pool[addr_idx],
7145 : 0 : &port->mc_addr_pool[addr_idx + 1],
7146 : 0 : sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
7147 : : }
7148 : :
7149 : : int
7150 : 0 : mcast_addr_pool_destroy(portid_t port_id)
7151 : : {
7152 : : struct rte_port *port;
7153 : :
7154 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN) ||
7155 : : port_id == (portid_t)RTE_PORT_ALL)
7156 : : return -EINVAL;
7157 : 0 : port = &ports[port_id];
7158 : :
7159 : 0 : if (port->mc_addr_nb != 0) {
7160 : : /* free the pool of multicast addresses. */
7161 : 0 : free(port->mc_addr_pool);
7162 : 0 : port->mc_addr_pool = NULL;
7163 : 0 : port->mc_addr_nb = 0;
7164 : : }
7165 : : return 0;
7166 : : }
7167 : :
7168 : : static int
7169 : 0 : eth_port_multicast_addr_list_set(portid_t port_id)
7170 : : {
7171 : : struct rte_port *port;
7172 : : int diag;
7173 : :
7174 : 0 : port = &ports[port_id];
7175 : 0 : diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
7176 : : port->mc_addr_nb);
7177 : 0 : if (diag < 0)
7178 : 0 : fprintf(stderr,
7179 : : "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
7180 : : port_id, port->mc_addr_nb, diag);
7181 : :
7182 : 0 : return diag;
7183 : : }
7184 : :
7185 : : void
7186 : 0 : mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
7187 : : {
7188 : : struct rte_port *port;
7189 : : uint32_t i;
7190 : :
7191 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7192 : : return;
7193 : :
7194 : 0 : port = &ports[port_id];
7195 : :
7196 : : /*
7197 : : * Check that the added multicast MAC address is not already recorded
7198 : : * in the pool of multicast addresses.
7199 : : */
7200 : 0 : for (i = 0; i < port->mc_addr_nb; i++) {
7201 : 0 : if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
7202 : 0 : fprintf(stderr,
7203 : : "multicast address already filtered by port\n");
7204 : 0 : return;
7205 : : }
7206 : : }
7207 : :
7208 : 0 : mcast_addr_pool_append(port, mc_addr);
7209 : 0 : if (eth_port_multicast_addr_list_set(port_id) < 0)
7210 : : /* Rollback on failure, remove the address from the pool */
7211 : 0 : mcast_addr_pool_remove(port, i);
7212 : : }
7213 : :
7214 : : void
7215 : 0 : mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
7216 : : {
7217 : : struct rte_port *port;
7218 : : uint32_t i;
7219 : :
7220 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7221 : : return;
7222 : :
7223 : 0 : port = &ports[port_id];
7224 : :
7225 : : /*
7226 : : * Search the pool of multicast MAC addresses for the removed address.
7227 : : */
7228 : 0 : for (i = 0; i < port->mc_addr_nb; i++) {
7229 : 0 : if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
7230 : : break;
7231 : : }
7232 : 0 : if (i == port->mc_addr_nb) {
7233 : 0 : fprintf(stderr, "multicast address not filtered by port %d\n",
7234 : : port_id);
7235 : 0 : return;
7236 : : }
7237 : :
7238 : 0 : mcast_addr_pool_remove(port, i);
7239 : 0 : if (eth_port_multicast_addr_list_set(port_id) < 0)
7240 : : /* Rollback on failure, add the address back into the pool */
7241 : 0 : mcast_addr_pool_append(port, mc_addr);
7242 : : }
7243 : :
7244 : : void
7245 : 0 : mcast_addr_flush(portid_t port_id)
7246 : : {
7247 : : int ret;
7248 : :
7249 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7250 : : return;
7251 : :
7252 : 0 : ret = rte_eth_dev_set_mc_addr_list(port_id, NULL, 0);
7253 : 0 : if (ret != 0) {
7254 : 0 : fprintf(stderr,
7255 : : "Failed to flush all multicast MAC addresses on port_id %u\n",
7256 : : port_id);
7257 : 0 : return;
7258 : : }
7259 : 0 : mcast_addr_pool_destroy(port_id);
7260 : : }
7261 : :
7262 : : void
7263 : 0 : port_dcb_info_display(portid_t port_id)
7264 : : {
7265 : : struct rte_eth_dcb_info dcb_info;
7266 : : uint16_t i;
7267 : : int ret;
7268 : : static const char *border = "================";
7269 : :
7270 : 0 : if (port_id_is_invalid(port_id, ENABLED_WARN))
7271 : 0 : return;
7272 : :
7273 : 0 : ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
7274 : 0 : if (ret) {
7275 : 0 : fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
7276 : : port_id);
7277 : 0 : return;
7278 : : }
7279 : 0 : printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
7280 : 0 : printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
7281 : : printf("\n TC : ");
7282 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7283 : 0 : printf("\t%4d", i);
7284 : : printf("\n Prio2TC : ");
7285 : 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
7286 : 0 : printf("\t%4d", dcb_info.prio_tc[i]);
7287 : : printf("\n BW percent :");
7288 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7289 : 0 : printf("\t%4d%%", dcb_info.tc_bws[i]);
7290 : : printf("\n RXQ base : ");
7291 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7292 : 0 : printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
7293 : : printf("\n RXQ number :");
7294 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7295 : 0 : printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
7296 : : printf("\n TXQ base : ");
7297 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7298 : 0 : printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
7299 : : printf("\n TXQ number :");
7300 : 0 : for (i = 0; i < dcb_info.nb_tcs; i++)
7301 : 0 : printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
7302 : : printf("\n");
7303 : : }
7304 : :
7305 : : uint8_t *
7306 : 0 : open_file(const char *file_path, uint32_t *size)
7307 : : {
7308 : : int fd = open(file_path, O_RDONLY);
7309 : : off_t pkg_size;
7310 : : uint8_t *buf = NULL;
7311 : : int ret = 0;
7312 : : struct stat st_buf;
7313 : :
7314 : 0 : if (size)
7315 : 0 : *size = 0;
7316 : :
7317 : 0 : if (fd == -1) {
7318 : 0 : fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
7319 : 0 : return buf;
7320 : : }
7321 : :
7322 : 0 : if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
7323 : 0 : close(fd);
7324 : 0 : fprintf(stderr, "%s: File operations failed\n", __func__);
7325 : 0 : return buf;
7326 : : }
7327 : :
7328 : 0 : pkg_size = st_buf.st_size;
7329 : 0 : if (pkg_size < 0) {
7330 : 0 : close(fd);
7331 : 0 : fprintf(stderr, "%s: File operations failed\n", __func__);
7332 : 0 : return buf;
7333 : : }
7334 : :
7335 : 0 : buf = (uint8_t *)malloc(pkg_size);
7336 : 0 : if (!buf) {
7337 : 0 : close(fd);
7338 : 0 : fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
7339 : 0 : return buf;
7340 : : }
7341 : :
7342 : 0 : ret = read(fd, buf, pkg_size);
7343 : 0 : if (ret < 0) {
7344 : 0 : close(fd);
7345 : 0 : fprintf(stderr, "%s: File read operation failed\n", __func__);
7346 : : close_file(buf);
7347 : 0 : return NULL;
7348 : : }
7349 : :
7350 : 0 : if (size)
7351 : 0 : *size = pkg_size;
7352 : :
7353 : 0 : close(fd);
7354 : :
7355 : 0 : return buf;
7356 : : }
7357 : :
7358 : : int
7359 : 0 : save_file(const char *file_path, uint8_t *buf, uint32_t size)
7360 : : {
7361 : 0 : FILE *fh = fopen(file_path, "wb");
7362 : :
7363 : 0 : if (fh == NULL) {
7364 : 0 : fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
7365 : 0 : return -1;
7366 : : }
7367 : :
7368 : 0 : if (fwrite(buf, 1, size, fh) != size) {
7369 : 0 : fclose(fh);
7370 : 0 : fprintf(stderr, "%s: File write operation failed\n", __func__);
7371 : 0 : return -1;
7372 : : }
7373 : :
7374 : 0 : fclose(fh);
7375 : :
7376 : 0 : return 0;
7377 : : }
7378 : :
7379 : : int
7380 : 0 : close_file(uint8_t *buf)
7381 : : {
7382 : 0 : if (buf) {
7383 : 0 : free((void *)buf);
7384 : 0 : return 0;
7385 : : }
7386 : :
7387 : : return -1;
7388 : : }
7389 : :
7390 : : void
7391 : 0 : show_macs(portid_t port_id)
7392 : : {
7393 : : char buf[RTE_ETHER_ADDR_FMT_SIZE];
7394 : : struct rte_eth_dev_info dev_info;
7395 : : int32_t i, rc, num_macs = 0;
7396 : :
7397 : 0 : if (eth_dev_info_get_print_err(port_id, &dev_info))
7398 : 0 : return;
7399 : :
7400 : : struct rte_ether_addr *addr =
7401 : 0 : alloca(sizeof(struct rte_ether_addr) * dev_info.max_mac_addrs);
7402 : 0 : rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
7403 : 0 : if (rc < 0)
7404 : : return;
7405 : :
7406 : 0 : for (i = 0; i < rc; i++) {
7407 : :
7408 : : /* skip zero address */
7409 : 0 : if (rte_is_zero_ether_addr(&addr[i]))
7410 : 0 : continue;
7411 : :
7412 : 0 : num_macs++;
7413 : : }
7414 : :
7415 : : printf("Number of MAC address added: %d\n", num_macs);
7416 : :
7417 : 0 : for (i = 0; i < rc; i++) {
7418 : :
7419 : : /* skip zero address */
7420 : 0 : if (rte_is_zero_ether_addr(&addr[i]))
7421 : 0 : continue;
7422 : :
7423 : 0 : rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &addr[i]);
7424 : : printf(" %s\n", buf);
7425 : : }
7426 : : }
7427 : :
7428 : : void
7429 : 0 : show_mcast_macs(portid_t port_id)
7430 : : {
7431 : : char buf[RTE_ETHER_ADDR_FMT_SIZE];
7432 : : struct rte_ether_addr *addr;
7433 : : struct rte_port *port;
7434 : : uint32_t i;
7435 : :
7436 : 0 : port = &ports[port_id];
7437 : :
7438 : 0 : printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
7439 : :
7440 : 0 : for (i = 0; i < port->mc_addr_nb; i++) {
7441 : 0 : addr = &port->mc_addr_pool[i];
7442 : :
7443 : 0 : rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
7444 : : printf(" %s\n", buf);
7445 : : }
7446 : 0 : }
|