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