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