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