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