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