4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include <sys/types.h>
47 #include <sys/queue.h>
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_launch.h>
62 #include <rte_tailq.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <cmdline_parse.h>
76 #include <cmdline_parse_etheraddr.h>
83 printf("usage: %s [--interactive|-i] [--help|-h] | ["
84 "--coremask=COREMASK --portmask=PORTMASK --numa "
85 "--eth-peers-configfile= | "
86 "--eth-peer=X,M:M:M:M:M:M | --nb-cores= | --nb-ports= | "
87 "--pkt-filter-mode= |"
88 "--rss-ip | --rss-udp | "
89 "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
90 "--txpt= | --txht= | --txwt= | --txfreet= | "
93 printf(" --interactive: run in interactive mode\n");
94 printf(" --help: display this message and quit\n");
95 printf(" --eth-peers-configfile=name of file with ethernet addresses "
97 printf(" --eth-peer=X,M:M:M:M:M:M set the mac address of the X peer "
98 "port (0 <= X < %d)\n", RTE_MAX_ETHPORTS);
99 printf(" --nb-cores=N set the number of forwarding cores"
100 " (1 <= N <= %d)\n", nb_lcores);
101 printf(" --nb-ports=N set the number of forwarding ports"
102 " (1 <= N <= %d)\n", nb_ports);
103 printf(" --coremask=COREMASK: hexadecimal bitmask of cores running "
104 "the packet forwarding test\n");
105 printf(" --portmask=PORTMASK: hexadecimal bitmask of ports used "
106 "by the packet forwarding test\n");
107 printf(" --numa: enable NUMA-aware allocation of RX/TX rings and of "
108 " RX memory buffers (mbufs)\n");
109 printf(" --mbuf-size=N set the data size of mbuf to N bytes\n");
110 printf(" --max-pkt-len=N set the maximum size of packet to N bytes\n");
111 printf(" --pkt-filter-mode=N: set Flow director mode "
112 "( N: none (default mode) or signature or perfect)\n");
113 printf(" --pkt-filter-report-hash=N: set Flow director report mode "
114 "( N: none or match (default) or always)\n");
115 printf(" --pkt-filter-size=N: set Flow director mode "
116 "( N: 64K (default mode) or 128K or 256K)\n");
117 printf(" --pkt-filter-flexbytes-offset=N: set flexbytes-offset."
118 " The offset is defined in word units counted from the"
119 " first byte of the destination Ethernet MAC address."
121 printf(" --pkt-filter-drop-queue=N: set drop-queue."
122 " In perfect mode, when you add a rule with queue -1"
123 " the packet will be enqueued into the rx drop-queue."
124 " If the drop-queue doesn't exist, the packet is dropped."
125 " By default drop-queue=127\n");
126 printf(" --crc-strip: enable CRC stripping by hardware\n");
127 printf(" --enable-rx-cksum: enable rx hardware checksum offload\n");
128 printf(" --disable-hw-vlan: disable hardware vlan\n");
129 printf(" --disable-rss: disable rss\n");
130 printf(" --port-topology=N: set port topology (N: paired (default) or "
132 printf(" --rss-ip: set RSS functions to IPv4/IPv6 only \n");
133 printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP\n");
134 printf(" --rxq=N set the number of RX queues per port to N\n");
135 printf(" --rxd=N set the number of descriptors in RX rings to N\n");
136 printf(" --txq=N set the number of TX queues per port to N\n");
137 printf(" --txd=N set the number of descriptors in TX rings to N\n");
138 printf(" --burst=N set the number of packets per burst to N\n");
139 printf(" --mbcache=N set the cache of mbuf memory pool to N\n");
140 printf(" --rxpt=N set prefetch threshold register of RX rings to N"
141 " (0 <= N <= 16)\n");
142 printf(" --rxht=N set the host threshold register of RX rings to N"
143 " (0 <= N <= 16)\n");
144 printf(" --rxfreet=N set the free threshold of RX descriptors to N"
145 " (0 <= N < value of rxd)\n");
146 printf(" --rxwt=N set the write-back threshold register of RX rings"
147 " to N (0 <= N <= 16)\n");
148 printf(" --txpt=N set the prefetch threshold register of TX rings"
149 " to N (0 <= N <= 16)\n");
150 printf(" --txht=N set the nhost threshold register of TX rings to N"
151 " (0 <= N <= 16)\n");
152 printf(" --txwt=N set the write-back threshold register of TX rings"
153 " to N (0 <= N <= 16)\n");
154 printf(" --txfreet=N set the transmit free threshold of TX rings to N"
155 " (0 <= N <= value of txd)\n");
156 printf(" --txrst=N set the transmit RS bit threshold of TX rings to N"
157 " (0 <= N <= value of txd)\n");
161 init_peer_eth_addrs(char *config_filename)
167 config_file = fopen(config_filename, "r");
168 if (config_file == NULL) {
169 perror("open log file failed\n");
173 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
175 if (fgets(buf, sizeof(buf), config_file) == NULL)
178 if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i]) < 0 ){
179 printf("bad format of mac address on line %d\n", i);
185 nb_peer_eth_addrs = (portid_t) i;
190 * Parse the coremask given as argument (hexadecimal string) and set
191 * the global configuration of forwarding cores.
194 parse_fwd_coremask(const char *coremask)
197 unsigned long long int cm;
199 /* parse hexadecimal string */
201 cm = strtoull(coremask, &end, 16);
202 if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0'))
203 rte_exit(EXIT_FAILURE, "Invalid fwd core mask\n");
205 set_fwd_lcores_mask((uint64_t) cm);
209 * Parse the coremask given as argument (hexadecimal string) and set
210 * the global configuration of forwarding cores.
213 parse_fwd_portmask(const char *portmask)
216 unsigned long long int pm;
218 /* parse hexadecimal string */
220 pm = strtoull(portmask, &end, 16);
221 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
222 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
224 set_fwd_ports_mask((uint64_t) pm);
228 launch_args_parse(int argc, char** argv)
233 static struct option lgopts[] = {
235 { "interactive", 0, 0, 0 },
236 { "eth-peers-configfile", 1, 0, 0 },
237 { "eth-peer", 1, 0, 0 },
238 { "ports", 1, 0, 0 },
239 { "nb-cores", 1, 0, 0 },
240 { "nb-ports", 1, 0, 0 },
241 { "coremask", 1, 0, 0 },
242 { "portmask", 1, 0, 0 },
244 { "mbuf-size", 1, 0, 0 },
245 { "max-pkt-len", 1, 0, 0 },
246 { "pkt-filter-mode", 1, 0, 0 },
247 { "pkt-filter-report-hash", 1, 0, 0 },
248 { "pkt-filter-size", 1, 0, 0 },
249 { "pkt-filter-flexbytes-offset",1, 0, 0 },
250 { "pkt-filter-drop-queue", 1, 0, 0 },
251 { "crc-strip", 0, 0, 0 },
252 { "disable-hw-vlan", 0, 0, 0 },
253 { "disable-rss", 0, 0, 0 },
254 { "port-topology", 1, 0, 0 },
255 { "rss-ip", 0, 0, 0 },
256 { "rss-udp", 0, 0, 0 },
261 { "burst", 1, 0, 0 },
262 { "mbcache", 1, 0, 0 },
266 { "txfreet", 1, 0, 0 },
267 { "txrst", 1, 0, 0 },
271 { "rxfreet", 1, 0, 0 },
277 while ((opt = getopt_long(argc, argvopt, "ih",
278 lgopts, &opt_idx)) != EOF) {
281 printf("Interactive-mode selected\n");
284 case 0: /*long options */
285 if (!strcmp(lgopts[opt_idx].name, "help")) {
287 rte_exit(EXIT_SUCCESS, "Displayed help\n");
289 if (!strcmp(lgopts[opt_idx].name, "interactive")) {
290 printf("Interactive-mode selected\n");
293 if (!strcmp(lgopts[opt_idx].name,
294 "eth-peers-configfile")) {
295 if (init_peer_eth_addrs(optarg) != 0)
296 rte_exit(EXIT_FAILURE,
297 "Cannot open logfile\n");
299 if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
301 uint8_t c, peer_addr[6];
304 n = strtoul(optarg, &port_end, 10);
305 if (errno != 0 || port_end == optarg || *port_end++ != ',')
306 rte_exit(EXIT_FAILURE,
307 "Invalid eth-peer: %s", optarg);
308 if (n >= RTE_MAX_ETHPORTS)
309 rte_exit(EXIT_FAILURE,
310 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
311 n, RTE_MAX_ETHPORTS);
313 if (cmdline_parse_etheraddr(NULL, port_end, &peer_addr) < 0 )
314 rte_exit(EXIT_FAILURE,
315 "Invalid ethernet address: %s\n",
317 for (c = 0; c < 6; c++)
318 peer_eth_addrs[n].addr_bytes[c] =
322 if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
324 if (n > 0 && n <= nb_ports)
325 nb_fwd_ports = (uint8_t) n;
327 rte_exit(EXIT_FAILURE,
328 "nb-ports should be > 0 and <= %d\n",
331 if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
333 if (n > 0 && n <= nb_lcores)
334 nb_fwd_lcores = (uint8_t) n;
336 rte_exit(EXIT_FAILURE,
337 "nb-cores should be > 0 and <= %d\n",
340 if (!strcmp(lgopts[opt_idx].name, "coremask"))
341 parse_fwd_coremask(optarg);
342 if (!strcmp(lgopts[opt_idx].name, "portmask"))
343 parse_fwd_portmask(optarg);
344 if (!strcmp(lgopts[opt_idx].name, "numa"))
346 if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
348 if (n > 0 && n <= 0xFFFF)
349 mbuf_data_size = (uint16_t) n;
351 rte_exit(EXIT_FAILURE,
352 "mbuf-size should be > 0 and < 65536\n");
354 if (!strcmp(lgopts[opt_idx].name, "max-pkt-len")) {
356 if (n >= ETHER_MIN_LEN) {
357 rx_mode.max_rx_pkt_len = (uint32_t) n;
358 if (n > ETHER_MAX_LEN)
359 rx_mode.jumbo_frame = 1;
361 rte_exit(EXIT_FAILURE,
362 "Invalid max-pkt-len=%d - should be > %d\n",
365 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-mode")) {
366 if (!strcmp(optarg, "signature"))
368 RTE_FDIR_MODE_SIGNATURE;
369 else if (!strcmp(optarg, "perfect"))
370 fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
371 else if (!strcmp(optarg, "none"))
372 fdir_conf.mode = RTE_FDIR_MODE_NONE;
374 rte_exit(EXIT_FAILURE,
375 "pkt-mode-invalid %s invalid - must be: "
376 "none, signature or perfect\n",
379 if (!strcmp(lgopts[opt_idx].name,
380 "pkt-filter-report-hash")) {
381 if (!strcmp(optarg, "none"))
383 RTE_FDIR_NO_REPORT_STATUS;
384 else if (!strcmp(optarg, "match"))
386 RTE_FDIR_REPORT_STATUS;
387 else if (!strcmp(optarg, "always"))
389 RTE_FDIR_REPORT_STATUS_ALWAYS;
391 rte_exit(EXIT_FAILURE,
392 "pkt-filter-report-hash %s invalid "
393 "- must be: none or match or always\n",
396 if (!strcmp(lgopts[opt_idx].name, "pkt-filter-size")) {
397 if (!strcmp(optarg, "64K"))
399 RTE_FDIR_PBALLOC_64K;
400 else if (!strcmp(optarg, "128K"))
402 RTE_FDIR_PBALLOC_128K;
403 else if (!strcmp(optarg, "256K"))
405 RTE_FDIR_PBALLOC_256K;
407 rte_exit(EXIT_FAILURE, "pkt-filter-size %s invalid -"
408 " must be: 64K or 128K or 256K\n",
411 if (!strcmp(lgopts[opt_idx].name,
412 "pkt-filter-flexbytes-offset")) {
414 if ( n >= 0 && n <= (int) 32)
415 fdir_conf.flexbytes_offset =
418 rte_exit(EXIT_FAILURE,
419 "flexbytes %d invalid - must"
420 "be >= 0 && <= 32\n", n);
422 if (!strcmp(lgopts[opt_idx].name,
423 "pkt-filter-drop-queue")) {
426 fdir_conf.drop_queue = (uint8_t) n;
428 rte_exit(EXIT_FAILURE,
429 "drop queue %d invalid - must"
432 if (!strcmp(lgopts[opt_idx].name, "crc-strip"))
433 rx_mode.hw_strip_crc = 1;
434 if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum"))
435 rx_mode.hw_ip_checksum = 1;
436 if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan"))
437 rx_mode.hw_vlan_filter = 0;
438 if (!strcmp(lgopts[opt_idx].name, "disable-rss"))
440 if (!strcmp(lgopts[opt_idx].name, "port-topology")) {
441 if (!strcmp(optarg, "paired"))
442 port_topology = PORT_TOPOLOGY_PAIRED;
443 else if (!strcmp(optarg, "chained"))
444 port_topology = PORT_TOPOLOGY_CHAINED;
446 rte_exit(EXIT_FAILURE, "port-topology %s invalid -"
447 " must be: paired or chained \n",
450 if (!strcmp(lgopts[opt_idx].name, "rss-ip"))
451 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
452 if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
453 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6 |
455 if (!strcmp(lgopts[opt_idx].name, "rxq")) {
457 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
458 nb_rxq = (queueid_t) n;
460 rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
461 " >= 1 && <= %d\n", n,
464 if (!strcmp(lgopts[opt_idx].name, "txq")) {
466 if (n >= 1 && n <= (int) MAX_QUEUE_ID)
467 nb_txq = (queueid_t) n;
469 rte_exit(EXIT_FAILURE, "txq %d invalid - must be"
470 " >= 1 && <= %d\n", n,
473 if (!strcmp(lgopts[opt_idx].name, "rxd")) {
476 nb_rxd = (uint16_t) n;
478 rte_exit(EXIT_FAILURE, "rxd must be > 0\n");
480 if (!strcmp(lgopts[opt_idx].name, "txd")) {
483 nb_txd = (uint16_t) n;
485 rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
487 if (!strcmp(lgopts[opt_idx].name, "burst")) {
489 if ((n >= 1) && (n <= MAX_PKT_BURST))
490 nb_pkt_per_burst = (uint16_t) n;
492 rte_exit(EXIT_FAILURE,
493 "burst must >= 1 and <= %d]",
496 if (!strcmp(lgopts[opt_idx].name, "mbcache")) {
499 (n <= RTE_MEMPOOL_CACHE_MAX_SIZE))
500 mb_mempool_cache = (uint16_t) n;
502 rte_exit(EXIT_FAILURE,
503 "mbcache must be >= 0 and <= %d\n",
504 RTE_MEMPOOL_CACHE_MAX_SIZE);
506 if (!strcmp(lgopts[opt_idx].name, "txpt")) {
509 tx_thresh.pthresh = (uint8_t)n;
511 rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
513 if (!strcmp(lgopts[opt_idx].name, "txht")) {
516 tx_thresh.hthresh = (uint8_t)n;
518 rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
520 if (!strcmp(lgopts[opt_idx].name, "txwt")) {
523 tx_thresh.wthresh = (uint8_t)n;
525 rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
527 if (!strcmp(lgopts[opt_idx].name, "txfreet")) {
530 tx_free_thresh = (uint16_t)n;
532 rte_exit(EXIT_FAILURE, "txfreet must be >= 0\n");
534 if (!strcmp(lgopts[opt_idx].name, "txrst")) {
537 tx_rs_thresh = (uint16_t)n;
539 rte_exit(EXIT_FAILURE, "txrst must be >= 0\n");
541 if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
544 rx_thresh.pthresh = (uint8_t)n;
546 rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
548 if (!strcmp(lgopts[opt_idx].name, "rxht")) {
551 rx_thresh.hthresh = (uint8_t)n;
553 rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
555 if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
558 rx_thresh.wthresh = (uint8_t)n;
560 rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
562 if (!strcmp(lgopts[opt_idx].name, "rxd")) {
565 if (rx_free_thresh >= n)
566 rte_exit(EXIT_FAILURE,
568 "rx_free_thresh(%d)\n",
569 (int)rx_free_thresh);
571 nb_rxd = (uint16_t) n;
573 rte_exit(EXIT_FAILURE,
574 "rxd(%d) invalid - must be > 0\n",
577 if (!strcmp(lgopts[opt_idx].name, "txd")) {
580 nb_txd = (uint16_t) n;
582 rte_exit(EXIT_FAILURE, "txd must be in > 0\n");
584 if (!strcmp(lgopts[opt_idx].name, "txpt")) {
587 tx_thresh.pthresh = (uint8_t)n;
589 rte_exit(EXIT_FAILURE, "txpt must be >= 0\n");
591 if (!strcmp(lgopts[opt_idx].name, "txht")) {
594 tx_thresh.hthresh = (uint8_t)n;
596 rte_exit(EXIT_FAILURE, "txht must be >= 0\n");
598 if (!strcmp(lgopts[opt_idx].name, "txwt")) {
601 tx_thresh.wthresh = (uint8_t)n;
603 rte_exit(EXIT_FAILURE, "txwt must be >= 0\n");
605 if (!strcmp(lgopts[opt_idx].name, "rxpt")) {
608 rx_thresh.pthresh = (uint8_t)n;
610 rte_exit(EXIT_FAILURE, "rxpt must be >= 0\n");
612 if (!strcmp(lgopts[opt_idx].name, "rxht")) {
615 rx_thresh.hthresh = (uint8_t)n;
617 rte_exit(EXIT_FAILURE, "rxht must be >= 0\n");
619 if (!strcmp(lgopts[opt_idx].name, "rxwt")) {
622 rx_thresh.wthresh = (uint8_t)n;
624 rte_exit(EXIT_FAILURE, "rxwt must be >= 0\n");
626 if (!strcmp(lgopts[opt_idx].name, "rxfreet")) {
629 rx_free_thresh = (uint16_t)n;
631 rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n");
636 rte_exit(EXIT_SUCCESS, "Displayed help\n");
640 rte_exit(EXIT_FAILURE,
641 "Command line is incomplete or incorrect\n");