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