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