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