app/testpmd: fix error message when setting Tx VLAN
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52
53 #include <sys/queue.h>
54
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78
79 #include <cmdline_rdline.h>
80 #include <cmdline_parse.h>
81 #include <cmdline_parse_num.h>
82 #include <cmdline_parse_string.h>
83 #include <cmdline_parse_ipaddr.h>
84 #include <cmdline_parse_etheraddr.h>
85 #include <cmdline_socket.h>
86 #include <cmdline.h>
87 #ifdef RTE_LIBRTE_PMD_BOND
88 #include <rte_eth_bond.h>
89 #endif
90
91 #include "testpmd.h"
92
93 static struct cmdline *testpmd_cl;
94
95 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
96
97 #ifdef RTE_NIC_BYPASS
98 uint8_t bypass_is_supported(portid_t port_id);
99 #endif
100
101 /* *** Help command with introduction. *** */
102 struct cmd_help_brief_result {
103         cmdline_fixed_string_t help;
104 };
105
106 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
107                                   struct cmdline *cl,
108                                   __attribute__((unused)) void *data)
109 {
110         cmdline_printf(
111                 cl,
112                 "\n"
113                 "Help is available for the following sections:\n\n"
114                 "    help control    : Start and stop forwarding.\n"
115                 "    help display    : Displaying port, stats and config "
116                 "information.\n"
117                 "    help config     : Configuration information.\n"
118                 "    help ports      : Configuring ports.\n"
119                 "    help registers  : Reading and setting port registers.\n"
120                 "    help filters    : Filters configuration help.\n"
121                 "    help all        : All of the above sections.\n\n"
122         );
123
124 }
125
126 cmdline_parse_token_string_t cmd_help_brief_help =
127         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
128
129 cmdline_parse_inst_t cmd_help_brief = {
130         .f = cmd_help_brief_parsed,
131         .data = NULL,
132         .help_str = "show help",
133         .tokens = {
134                 (void *)&cmd_help_brief_help,
135                 NULL,
136         },
137 };
138
139 /* *** Help command with help sections. *** */
140 struct cmd_help_long_result {
141         cmdline_fixed_string_t help;
142         cmdline_fixed_string_t section;
143 };
144
145 static void cmd_help_long_parsed(void *parsed_result,
146                                  struct cmdline *cl,
147                                  __attribute__((unused)) void *data)
148 {
149         int show_all = 0;
150         struct cmd_help_long_result *res = parsed_result;
151
152         if (!strcmp(res->section, "all"))
153                 show_all = 1;
154
155         if (show_all || !strcmp(res->section, "control")) {
156
157                 cmdline_printf(
158                         cl,
159                         "\n"
160                         "Control forwarding:\n"
161                         "-------------------\n\n"
162
163                         "start\n"
164                         "    Start packet forwarding with current configuration.\n\n"
165
166                         "start tx_first\n"
167                         "    Start packet forwarding with current config"
168                         " after sending one burst of packets.\n\n"
169
170                         "stop\n"
171                         "    Stop packet forwarding, and display accumulated"
172                         " statistics.\n\n"
173
174                         "quit\n"
175                         "    Quit to prompt.\n\n"
176                 );
177         }
178
179         if (show_all || !strcmp(res->section, "display")) {
180
181                 cmdline_printf(
182                         cl,
183                         "\n"
184                         "Display:\n"
185                         "--------\n\n"
186
187                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc) (port_id|all)\n"
188                         "    Display information for port_id, or all.\n\n"
189
190                         "show port X rss reta (size) (mask0,mask1,...)\n"
191                         "    Display the rss redirection table entry indicated"
192                         " by masks on port X. size is used to indicate the"
193                         " hardware supported reta size\n\n"
194
195                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
196                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
197                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
198                         "    Display the RSS hash functions and RSS hash key"
199                         " of port X\n\n"
200
201                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
202                         "    Clear information for port_id, or all.\n\n"
203
204                         "show (rxq|txq) info (port_id) (queue_id)\n"
205                         "    Display information for configured RX/TX queue.\n\n"
206
207                         "show config (rxtx|cores|fwd|txpkts)\n"
208                         "    Display the given configuration.\n\n"
209
210                         "read rxd (port_id) (queue_id) (rxd_id)\n"
211                         "    Display an RX descriptor of a port RX queue.\n\n"
212
213                         "read txd (port_id) (queue_id) (txd_id)\n"
214                         "    Display a TX descriptor of a port TX queue.\n\n"
215                 );
216         }
217
218         if (show_all || !strcmp(res->section, "config")) {
219                 cmdline_printf(
220                         cl,
221                         "\n"
222                         "Configuration:\n"
223                         "--------------\n"
224                         "Configuration changes only become active when"
225                         " forwarding is started/restarted.\n\n"
226
227                         "set default\n"
228                         "    Reset forwarding to the default configuration.\n\n"
229
230                         "set verbose (level)\n"
231                         "    Set the debug verbosity level X.\n\n"
232
233                         "set nbport (num)\n"
234                         "    Set number of ports.\n\n"
235
236                         "set nbcore (num)\n"
237                         "    Set number of cores.\n\n"
238
239                         "set coremask (mask)\n"
240                         "    Set the forwarding cores hexadecimal mask.\n\n"
241
242                         "set portmask (mask)\n"
243                         "    Set the forwarding ports hexadecimal mask.\n\n"
244
245                         "set burst (num)\n"
246                         "    Set number of packets per burst.\n\n"
247
248                         "set burst tx delay (microseconds) retry (num)\n"
249                         "    Set the transmit delay time and number of retries"
250                         " in mac_retry forwarding mode.\n\n"
251
252                         "set txpkts (x[,y]*)\n"
253                         "    Set the length of each segment of TXONLY"
254                         " and optionally CSUM packets.\n\n"
255
256                         "set txsplit (off|on|rand)\n"
257                         "    Set the split policy for the TX packets."
258                         " Right now only applicable for CSUM and TXONLY"
259                         " modes\n\n"
260
261                         "set corelist (x[,y]*)\n"
262                         "    Set the list of forwarding cores.\n\n"
263
264                         "set portlist (x[,y]*)\n"
265                         "    Set the list of forwarding ports.\n\n"
266
267                         "vlan set strip (on|off) (port_id)\n"
268                         "    Set the VLAN strip on a port.\n\n"
269
270                         "vlan set stripq (on|off) (port_id,queue_id)\n"
271                         "    Set the VLAN strip for a queue on a port.\n\n"
272
273                         "vlan set filter (on|off) (port_id)\n"
274                         "    Set the VLAN filter on a port.\n\n"
275
276                         "vlan set qinq (on|off) (port_id)\n"
277                         "    Set the VLAN QinQ (extended queue in queue)"
278                         " on a port.\n\n"
279
280                         "vlan set tpid (value) (port_id)\n"
281                         "    Set the outer VLAN TPID for Packet Filtering on"
282                         " a port\n\n"
283
284                         "rx_vlan add (vlan_id|all) (port_id)\n"
285                         "    Add a vlan_id, or all identifiers, to the set"
286                         " of VLAN identifiers filtered by port_id.\n\n"
287
288                         "rx_vlan rm (vlan_id|all) (port_id)\n"
289                         "    Remove a vlan_id, or all identifiers, from the set"
290                         " of VLAN identifiers filtered by port_id.\n\n"
291
292                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
293                         "    Add a vlan_id, to the set of VLAN identifiers"
294                         "filtered for VF(s) from port_id.\n\n"
295
296                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
297                         "    Remove a vlan_id, to the set of VLAN identifiers"
298                         "filtered for VF(s) from port_id.\n\n"
299
300                         "rx_vlan set tpid (value) (port_id)\n"
301                         "    Set the outer VLAN TPID for Packet Filtering on"
302                         " a port\n\n"
303
304                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
305                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
306                         "   add a tunnel filter of a port.\n\n"
307
308                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
309                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
310                         "   remove a tunnel filter of a port.\n\n"
311
312                         "rx_vxlan_port add (udp_port) (port_id)\n"
313                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
314
315                         "rx_vxlan_port rm (udp_port) (port_id)\n"
316                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
317
318                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
319                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
320                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
321
322                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
323                         "    Set port based TX VLAN insertion.\n\n"
324
325                         "tx_vlan reset (port_id)\n"
326                         "    Disable hardware insertion of a VLAN header in"
327                         " packets sent on a port.\n\n"
328
329                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
330                         "    Select hardware or software calculation of the"
331                         " checksum when transmitting a packet using the"
332                         " csum forward engine.\n"
333                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
334                         "    outer-ip concerns the outer IP layer in"
335                         " case the packet is recognized as a tunnel packet by"
336                         " the forward engine (vxlan, gre and ipip are supported)\n"
337                         "    Please check the NIC datasheet for HW limits.\n\n"
338
339                         "csum parse-tunnel (on|off) (tx_port_id)\n"
340                         "    If disabled, treat tunnel packets as non-tunneled"
341                         " packets (treat inner headers as payload). The port\n"
342                         "    argument is the port used for TX in csum forward"
343                         " engine.\n\n"
344
345                         "csum show (port_id)\n"
346                         "    Display tx checksum offload configuration\n\n"
347
348                         "tso set (segsize) (portid)\n"
349                         "    Enable TCP Segmentation Offload in csum forward"
350                         " engine.\n"
351                         "    Please check the NIC datasheet for HW limits.\n\n"
352
353                         "tso show (portid)"
354                         "    Display the status of TCP Segmentation Offload.\n\n"
355
356                         "set fwd (%s)\n"
357                         "    Set packet forwarding mode.\n\n"
358
359                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
360                         "    Add a MAC address on port_id.\n\n"
361
362                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
363                         "    Remove a MAC address from port_id.\n\n"
364
365                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
366                         "    Add a MAC address for a VF on the port.\n\n"
367
368                         "set port (port_id) uta (mac_address|all) (on|off)\n"
369                         "    Add/Remove a or all unicast hash filter(s)"
370                         "from port X.\n\n"
371
372                         "set promisc (port_id|all) (on|off)\n"
373                         "    Set the promiscuous mode on port_id, or all.\n\n"
374
375                         "set allmulti (port_id|all) (on|off)\n"
376                         "    Set the allmulti mode on port_id, or all.\n\n"
377
378                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
379                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
380                         " (on|off) autoneg (on|off) (port_id)\n"
381                         "set flow_ctrl rx (on|off) (portid)\n"
382                         "set flow_ctrl tx (on|off) (portid)\n"
383                         "set flow_ctrl high_water (high_water) (portid)\n"
384                         "set flow_ctrl low_water (low_water) (portid)\n"
385                         "set flow_ctrl pause_time (pause_time) (portid)\n"
386                         "set flow_ctrl send_xon (send_xon) (portid)\n"
387                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
388                         "set flow_ctrl autoneg (on|off) (port_id)\n"
389                         "    Set the link flow control parameter on a port.\n\n"
390
391                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
392                         " (low_water) (pause_time) (priority) (port_id)\n"
393                         "    Set the priority flow control parameter on a"
394                         " port.\n\n"
395
396                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
397                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
398                         " queue on port.\n"
399                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
400                         " on port 0 to mapping 5.\n\n"
401
402                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
403                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
404
405                         "set port (port_id) vf (vf_id) (mac_addr)"
406                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
407                         "   Add/Remove unicast or multicast MAC addr filter"
408                         " for a VF.\n\n"
409
410                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
411                         "|MPE) (on|off)\n"
412                         "    AUPE:accepts untagged VLAN;"
413                         "ROPE:accept unicast hash\n\n"
414                         "    BAM:accepts broadcast packets;"
415                         "MPE:accepts all multicast packets\n\n"
416                         "    Enable/Disable a VF receive mode of a port\n\n"
417
418                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
419                         "    Set rate limit for a queue of a port\n\n"
420
421                         "set port (port_id) vf (vf_id) rate (rate_num) "
422                         "queue_mask (queue_mask_value)\n"
423                         "    Set rate limit for queues in VF of a port\n\n"
424
425                         "set port (port_id) mirror-rule (rule_id)"
426                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
427                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
428                         "   Set pool or vlan type mirror rule on a port.\n"
429                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
430                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
431                         " to pool 0.\n\n"
432
433                         "set port (port_id) mirror-rule (rule_id)"
434                         " (uplink-mirror|downlink-mirror) dst-pool"
435                         " (pool_id) (on|off)\n"
436                         "   Set uplink or downlink type mirror rule on a port.\n"
437                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
438                         " 0 on' enable mirror income traffic to pool 0.\n\n"
439
440                         "reset port (port_id) mirror-rule (rule_id)\n"
441                         "   Reset a mirror rule.\n\n"
442
443                         "set flush_rx (on|off)\n"
444                         "   Flush (default) or don't flush RX streams before"
445                         " forwarding. Mainly used with PCAP drivers.\n\n"
446
447                         #ifdef RTE_NIC_BYPASS
448                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
449                         "   Set the bypass mode for the lowest port on bypass enabled"
450                         " NIC.\n\n"
451
452                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
453                         "mode (normal|bypass|isolate) (port_id)\n"
454                         "   Set the event required to initiate specified bypass mode for"
455                         " the lowest port on a bypass enabled NIC where:\n"
456                         "       timeout   = enable bypass after watchdog timeout.\n"
457                         "       os_on     = enable bypass when OS/board is powered on.\n"
458                         "       os_off    = enable bypass when OS/board is powered off.\n"
459                         "       power_on  = enable bypass when power supply is turned on.\n"
460                         "       power_off = enable bypass when power supply is turned off."
461                         "\n\n"
462
463                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
464                         "   Set the bypass watchdog timeout to 'n' seconds"
465                         " where 0 = instant.\n\n"
466
467                         "show bypass config (port_id)\n"
468                         "   Show the bypass configuration for a bypass enabled NIC"
469                         " using the lowest port on the NIC.\n\n"
470 #endif
471 #ifdef RTE_LIBRTE_PMD_BOND
472                         "create bonded device (mode) (socket)\n"
473                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
474
475                         "add bonding slave (slave_id) (port_id)\n"
476                         "       Add a slave device to a bonded device.\n\n"
477
478                         "remove bonding slave (slave_id) (port_id)\n"
479                         "       Remove a slave device from a bonded device.\n\n"
480
481                         "set bonding mode (value) (port_id)\n"
482                         "       Set the bonding mode on a bonded device.\n\n"
483
484                         "set bonding primary (slave_id) (port_id)\n"
485                         "       Set the primary slave for a bonded device.\n\n"
486
487                         "show bonding config (port_id)\n"
488                         "       Show the bonding config for port_id.\n\n"
489
490                         "set bonding mac_addr (port_id) (address)\n"
491                         "       Set the MAC address of a bonded device.\n\n"
492
493                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
494                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
495
496                         "set bonding mon_period (port_id) (value)\n"
497                         "       Set the bonding link status monitoring polling period in ms.\n\n"
498 #endif
499                         "set link-up port (port_id)\n"
500                         "       Set link up for a port.\n\n"
501
502                         "set link-down port (port_id)\n"
503                         "       Set link down for a port.\n\n"
504
505                         , list_pkt_forwarding_modes()
506                 );
507         }
508
509         if (show_all || !strcmp(res->section, "ports")) {
510
511                 cmdline_printf(
512                         cl,
513                         "\n"
514                         "Port Operations:\n"
515                         "----------------\n\n"
516
517                         "port start (port_id|all)\n"
518                         "    Start all ports or port_id.\n\n"
519
520                         "port stop (port_id|all)\n"
521                         "    Stop all ports or port_id.\n\n"
522
523                         "port close (port_id|all)\n"
524                         "    Close all ports or port_id.\n\n"
525
526                         "port attach (ident)\n"
527                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
528
529                         "port detach (port_id)\n"
530                         "    Detach physical or virtual dev by port_id\n\n"
531
532                         "port config (port_id|all)"
533                         " speed (10|100|1000|10000|40000|auto)"
534                         " duplex (half|full|auto)\n"
535                         "    Set speed and duplex for all ports or port_id\n\n"
536
537                         "port config all (rxq|txq|rxd|txd) (value)\n"
538                         "    Set number for rxq/txq/rxd/txd.\n\n"
539
540                         "port config all max-pkt-len (value)\n"
541                         "    Set the max packet length.\n\n"
542
543                         "port config all (crc-strip|rx-cksum|hw-vlan|hw-vlan-filter|"
544                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
545                         " (on|off)\n"
546                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
547                         " for ports.\n\n"
548
549                         "port config all rss (all|ip|tcp|udp|sctp|ether|none)\n"
550                         "    Set the RSS mode.\n\n"
551
552                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
553                         "    Set the RSS redirection table.\n\n"
554
555                         "port config (port_id) dcb vt (on|off) (traffic_class)"
556                         " pfc (on|off)\n"
557                         "    Set the DCB mode.\n\n"
558
559                         "port config all burst (value)\n"
560                         "    Set the number of packets per burst.\n\n"
561
562                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
563                         " (value)\n"
564                         "    Set the ring prefetch/host/writeback threshold"
565                         " for tx/rx queue.\n\n"
566
567                         "port config all (txfreet|txrst|rxfreet) (value)\n"
568                         "    Set free threshold for rx/tx, or set"
569                         " tx rs bit threshold.\n\n"
570                         "port config mtu X value\n"
571                         "    Set the MTU of port X to a given value\n\n"
572
573                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
574                         "    Start/stop a rx/tx queue of port X. Only take effect"
575                         " when port X is started\n"
576                 );
577         }
578
579         if (show_all || !strcmp(res->section, "registers")) {
580
581                 cmdline_printf(
582                         cl,
583                         "\n"
584                         "Registers:\n"
585                         "----------\n\n"
586
587                         "read reg (port_id) (address)\n"
588                         "    Display value of a port register.\n\n"
589
590                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
591                         "    Display a port register bit field.\n\n"
592
593                         "read regbit (port_id) (address) (bit_x)\n"
594                         "    Display a single port register bit.\n\n"
595
596                         "write reg (port_id) (address) (value)\n"
597                         "    Set value of a port register.\n\n"
598
599                         "write regfield (port_id) (address) (bit_x) (bit_y)"
600                         " (value)\n"
601                         "    Set bit field of a port register.\n\n"
602
603                         "write regbit (port_id) (address) (bit_x) (value)\n"
604                         "    Set single bit value of a port register.\n\n"
605                 );
606         }
607         if (show_all || !strcmp(res->section, "filters")) {
608
609                 cmdline_printf(
610                         cl,
611                         "\n"
612                         "filters:\n"
613                         "--------\n\n"
614
615                         "ethertype_filter (port_id) (add|del)"
616                         " (mac_addr|mac_ignr) (mac_address) ethertype"
617                         " (ether_type) (drop|fwd) queue (queue_id)\n"
618                         "    Add/Del an ethertype filter.\n\n"
619
620                         "2tuple_filter (port_id) (add|del)"
621                         " dst_port (dst_port_value) protocol (protocol_value)"
622                         " mask (mask_value) tcp_flags (tcp_flags_value)"
623                         " priority (prio_value) queue (queue_id)\n"
624                         "    Add/Del a 2tuple filter.\n\n"
625
626                         "5tuple_filter (port_id) (add|del)"
627                         " dst_ip (dst_address) src_ip (src_address)"
628                         " dst_port (dst_port_value) src_port (src_port_value)"
629                         " protocol (protocol_value)"
630                         " mask (mask_value) tcp_flags (tcp_flags_value)"
631                         " priority (prio_value) queue (queue_id)\n"
632                         "    Add/Del a 5tuple filter.\n\n"
633
634                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
635                         "    Add/Del syn filter.\n\n"
636
637                         "flex_filter (port_id) (add|del) len (len_value)"
638                         " bytes (bytes_value) mask (mask_value)"
639                         " priority (prio_value) queue (queue_id)\n"
640                         "    Add/Del a flex filter.\n\n"
641
642                         "flow_director_filter (port_id) mode IP (add|del|update)"
643                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
644                         " src (src_ip_address) dst (dst_ip_address)"
645                         " vlan (vlan_value) flexbytes (flexbytes_value)"
646                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
647                         " fd_id (fd_id_value)\n"
648                         "    Add/Del an IP type flow director filter.\n\n"
649
650                         "flow_director_filter (port_id) mode IP (add|del|update)"
651                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
652                         " src (src_ip_address) (src_port)"
653                         " dst (dst_ip_address) (dst_port)"
654                         " vlan (vlan_value) flexbytes (flexbytes_value)"
655                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
656                         " fd_id (fd_id_value)\n"
657                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
658
659                         "flow_director_filter (port_id) mode IP (add|del|update)"
660                         " flow (ipv4-sctp|ipv6-sctp)"
661                         " src (src_ip_address) (src_port)"
662                         " dst (dst_ip_address) (dst_port)"
663                         " tag (verification_tag) vlan (vlan_value)"
664                         " flexbytes (flexbytes_value) (drop|fwd)"
665                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
666                         "    Add/Del a SCTP type flow director filter.\n\n"
667
668                         "flow_director_filter (port_id) mode IP (add|del|update)"
669                         " flow l2_payload ether (ethertype)"
670                         " flexbytes (flexbytes_value) (drop|fwd)"
671                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
672                         "    Add/Del a l2 payload type flow director filter.\n\n"
673
674                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
675                         " mac (mac_address) vlan (vlan_value)"
676                         " flexbytes (flexbytes_value) (drop|fwd)"
677                         " queue (queue_id) fd_id (fd_id_value)\n"
678                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
679
680                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
681                         " mac (mac_address) vlan (vlan_value)"
682                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
683                         " flexbytes (flexbytes_value) (drop|fwd)"
684                         " queue (queue_id) fd_id (fd_id_value)\n"
685                         "    Add/Del a Tunnel flow director filter.\n\n"
686
687                         "flush_flow_director (port_id)\n"
688                         "    Flush all flow director entries of a device.\n\n"
689
690                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
691                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
692                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
693                         "    Set flow director IP mask.\n\n"
694
695                         "flow_director_mask (port_id) mode MAC-VLAN"
696                         " vlan (vlan_value) mac (mac_value)\n"
697                         "    Set flow director MAC-VLAN mask.\n\n"
698
699                         "flow_director_mask (port_id) mode Tunnel"
700                         " vlan (vlan_value) mac (mac_value)"
701                         " tunnel-type (tunnel_type_value)"
702                         " tunnel-id (tunnel_id_value)\n"
703                         "    Set flow director Tunnel mask.\n\n"
704
705                         "flow_director_flex_mask (port_id)"
706                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
707                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
708                         " (mask)\n"
709                         "    Configure mask of flex payload.\n\n"
710
711                         "flow_director_flex_payload (port_id)"
712                         " (raw|l2|l3|l4) (config)\n"
713                         "    Configure flex payload selection.\n\n"
714
715                         "get_sym_hash_ena_per_port (port_id)\n"
716                         "    get symmetric hash enable configuration per port.\n\n"
717
718                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
719                         "    set symmetric hash enable configuration per port"
720                         " to enable or disable.\n\n"
721
722                         "get_hash_global_config (port_id)\n"
723                         "    Get the global configurations of hash filters.\n\n"
724
725                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
726                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
727                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
728                         " (enable|disable)\n"
729                         "    Set the global configurations of hash filters.\n\n"
730
731                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
732                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
733                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
734                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
735                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
736                         "ipv6-next-header|udp-src-port|udp-dst-port|"
737                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
738                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
739                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
740                         "fld-8th|none) (select|add)\n"
741                         "    Set the input set for hash.\n\n"
742
743                         "set_fdir_input_set (port_id) (ipv4|ipv4-frag|"
744                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
745                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
746                         "l2_payload) (src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
747                         "udp-src-port|udp-dst-port|tcp-src-port|tcp-dst-port|"
748                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|fld-1st|"
749                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
750                         "fld-8th|none) (select|add)\n"
751                         "    Set the input set for FDir.\n\n"
752                 );
753         }
754 }
755
756 cmdline_parse_token_string_t cmd_help_long_help =
757         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
758
759 cmdline_parse_token_string_t cmd_help_long_section =
760         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
761                         "all#control#display#config#"
762                         "ports#registers#filters");
763
764 cmdline_parse_inst_t cmd_help_long = {
765         .f = cmd_help_long_parsed,
766         .data = NULL,
767         .help_str = "show help",
768         .tokens = {
769                 (void *)&cmd_help_long_help,
770                 (void *)&cmd_help_long_section,
771                 NULL,
772         },
773 };
774
775
776 /* *** start/stop/close all ports *** */
777 struct cmd_operate_port_result {
778         cmdline_fixed_string_t keyword;
779         cmdline_fixed_string_t name;
780         cmdline_fixed_string_t value;
781 };
782
783 static void cmd_operate_port_parsed(void *parsed_result,
784                                 __attribute__((unused)) struct cmdline *cl,
785                                 __attribute__((unused)) void *data)
786 {
787         struct cmd_operate_port_result *res = parsed_result;
788
789         if (!strcmp(res->name, "start"))
790                 start_port(RTE_PORT_ALL);
791         else if (!strcmp(res->name, "stop"))
792                 stop_port(RTE_PORT_ALL);
793         else if (!strcmp(res->name, "close"))
794                 close_port(RTE_PORT_ALL);
795         else
796                 printf("Unknown parameter\n");
797 }
798
799 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
800         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
801                                                                 "port");
802 cmdline_parse_token_string_t cmd_operate_port_all_port =
803         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
804                                                 "start#stop#close");
805 cmdline_parse_token_string_t cmd_operate_port_all_all =
806         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
807
808 cmdline_parse_inst_t cmd_operate_port = {
809         .f = cmd_operate_port_parsed,
810         .data = NULL,
811         .help_str = "port start|stop|close all: start/stop/close all ports",
812         .tokens = {
813                 (void *)&cmd_operate_port_all_cmd,
814                 (void *)&cmd_operate_port_all_port,
815                 (void *)&cmd_operate_port_all_all,
816                 NULL,
817         },
818 };
819
820 /* *** start/stop/close specific port *** */
821 struct cmd_operate_specific_port_result {
822         cmdline_fixed_string_t keyword;
823         cmdline_fixed_string_t name;
824         uint8_t value;
825 };
826
827 static void cmd_operate_specific_port_parsed(void *parsed_result,
828                         __attribute__((unused)) struct cmdline *cl,
829                                 __attribute__((unused)) void *data)
830 {
831         struct cmd_operate_specific_port_result *res = parsed_result;
832
833         if (!strcmp(res->name, "start"))
834                 start_port(res->value);
835         else if (!strcmp(res->name, "stop"))
836                 stop_port(res->value);
837         else if (!strcmp(res->name, "close"))
838                 close_port(res->value);
839         else
840                 printf("Unknown parameter\n");
841 }
842
843 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
844         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
845                                                         keyword, "port");
846 cmdline_parse_token_string_t cmd_operate_specific_port_port =
847         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
848                                                 name, "start#stop#close");
849 cmdline_parse_token_num_t cmd_operate_specific_port_id =
850         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
851                                                         value, UINT8);
852
853 cmdline_parse_inst_t cmd_operate_specific_port = {
854         .f = cmd_operate_specific_port_parsed,
855         .data = NULL,
856         .help_str = "port start|stop|close X: start/stop/close port X",
857         .tokens = {
858                 (void *)&cmd_operate_specific_port_cmd,
859                 (void *)&cmd_operate_specific_port_port,
860                 (void *)&cmd_operate_specific_port_id,
861                 NULL,
862         },
863 };
864
865 /* *** attach a specified port *** */
866 struct cmd_operate_attach_port_result {
867         cmdline_fixed_string_t port;
868         cmdline_fixed_string_t keyword;
869         cmdline_fixed_string_t identifier;
870 };
871
872 static void cmd_operate_attach_port_parsed(void *parsed_result,
873                                 __attribute__((unused)) struct cmdline *cl,
874                                 __attribute__((unused)) void *data)
875 {
876         struct cmd_operate_attach_port_result *res = parsed_result;
877
878         if (!strcmp(res->keyword, "attach"))
879                 attach_port(res->identifier);
880         else
881                 printf("Unknown parameter\n");
882 }
883
884 cmdline_parse_token_string_t cmd_operate_attach_port_port =
885         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
886                         port, "port");
887 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
888         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
889                         keyword, "attach");
890 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
891         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
892                         identifier, NULL);
893
894 cmdline_parse_inst_t cmd_operate_attach_port = {
895         .f = cmd_operate_attach_port_parsed,
896         .data = NULL,
897         .help_str = "port attach identifier, "
898                 "identifier: pci address or virtual dev name",
899         .tokens = {
900                 (void *)&cmd_operate_attach_port_port,
901                 (void *)&cmd_operate_attach_port_keyword,
902                 (void *)&cmd_operate_attach_port_identifier,
903                 NULL,
904         },
905 };
906
907 /* *** detach a specified port *** */
908 struct cmd_operate_detach_port_result {
909         cmdline_fixed_string_t port;
910         cmdline_fixed_string_t keyword;
911         uint8_t port_id;
912 };
913
914 static void cmd_operate_detach_port_parsed(void *parsed_result,
915                                 __attribute__((unused)) struct cmdline *cl,
916                                 __attribute__((unused)) void *data)
917 {
918         struct cmd_operate_detach_port_result *res = parsed_result;
919
920         if (!strcmp(res->keyword, "detach"))
921                 detach_port(res->port_id);
922         else
923                 printf("Unknown parameter\n");
924 }
925
926 cmdline_parse_token_string_t cmd_operate_detach_port_port =
927         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
928                         port, "port");
929 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
930         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
931                         keyword, "detach");
932 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
933         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
934                         port_id, UINT8);
935
936 cmdline_parse_inst_t cmd_operate_detach_port = {
937         .f = cmd_operate_detach_port_parsed,
938         .data = NULL,
939         .help_str = "port detach port_id",
940         .tokens = {
941                 (void *)&cmd_operate_detach_port_port,
942                 (void *)&cmd_operate_detach_port_keyword,
943                 (void *)&cmd_operate_detach_port_port_id,
944                 NULL,
945         },
946 };
947
948 /* *** configure speed for all ports *** */
949 struct cmd_config_speed_all {
950         cmdline_fixed_string_t port;
951         cmdline_fixed_string_t keyword;
952         cmdline_fixed_string_t all;
953         cmdline_fixed_string_t item1;
954         cmdline_fixed_string_t item2;
955         cmdline_fixed_string_t value1;
956         cmdline_fixed_string_t value2;
957 };
958
959 static void
960 cmd_config_speed_all_parsed(void *parsed_result,
961                         __attribute__((unused)) struct cmdline *cl,
962                         __attribute__((unused)) void *data)
963 {
964         struct cmd_config_speed_all *res = parsed_result;
965         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
966         uint16_t link_duplex = 0;
967         portid_t pid;
968
969         if (!all_ports_stopped()) {
970                 printf("Please stop all ports first\n");
971                 return;
972         }
973
974         if (!strcmp(res->value1, "10"))
975                 link_speed = ETH_LINK_SPEED_10;
976         else if (!strcmp(res->value1, "100"))
977                 link_speed = ETH_LINK_SPEED_100;
978         else if (!strcmp(res->value1, "1000"))
979                 link_speed = ETH_LINK_SPEED_1000;
980         else if (!strcmp(res->value1, "10000"))
981                 link_speed = ETH_LINK_SPEED_10G;
982         else if (!strcmp(res->value1, "40000"))
983                 link_speed = ETH_LINK_SPEED_40G;
984         else if (!strcmp(res->value1, "auto"))
985                 link_speed = ETH_LINK_SPEED_AUTONEG;
986         else {
987                 printf("Unknown parameter\n");
988                 return;
989         }
990
991         if (!strcmp(res->value2, "half"))
992                 link_duplex = ETH_LINK_HALF_DUPLEX;
993         else if (!strcmp(res->value2, "full"))
994                 link_duplex = ETH_LINK_FULL_DUPLEX;
995         else if (!strcmp(res->value2, "auto"))
996                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
997         else {
998                 printf("Unknown parameter\n");
999                 return;
1000         }
1001
1002         FOREACH_PORT(pid, ports) {
1003                 ports[pid].dev_conf.link_speed = link_speed;
1004                 ports[pid].dev_conf.link_duplex = link_duplex;
1005         }
1006
1007         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1008 }
1009
1010 cmdline_parse_token_string_t cmd_config_speed_all_port =
1011         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1012 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1013         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1014                                                         "config");
1015 cmdline_parse_token_string_t cmd_config_speed_all_all =
1016         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1017 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1018         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1019 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1020         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1021                                                 "10#100#1000#10000#40000#auto");
1022 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1023         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1024 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1025         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1026                                                 "half#full#auto");
1027
1028 cmdline_parse_inst_t cmd_config_speed_all = {
1029         .f = cmd_config_speed_all_parsed,
1030         .data = NULL,
1031         .help_str = "port config all speed 10|100|1000|10000|40000|auto duplex "
1032                                                         "half|full|auto",
1033         .tokens = {
1034                 (void *)&cmd_config_speed_all_port,
1035                 (void *)&cmd_config_speed_all_keyword,
1036                 (void *)&cmd_config_speed_all_all,
1037                 (void *)&cmd_config_speed_all_item1,
1038                 (void *)&cmd_config_speed_all_value1,
1039                 (void *)&cmd_config_speed_all_item2,
1040                 (void *)&cmd_config_speed_all_value2,
1041                 NULL,
1042         },
1043 };
1044
1045 /* *** configure speed for specific port *** */
1046 struct cmd_config_speed_specific {
1047         cmdline_fixed_string_t port;
1048         cmdline_fixed_string_t keyword;
1049         uint8_t id;
1050         cmdline_fixed_string_t item1;
1051         cmdline_fixed_string_t item2;
1052         cmdline_fixed_string_t value1;
1053         cmdline_fixed_string_t value2;
1054 };
1055
1056 static void
1057 cmd_config_speed_specific_parsed(void *parsed_result,
1058                                 __attribute__((unused)) struct cmdline *cl,
1059                                 __attribute__((unused)) void *data)
1060 {
1061         struct cmd_config_speed_specific *res = parsed_result;
1062         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
1063         uint16_t link_duplex = 0;
1064
1065         if (!all_ports_stopped()) {
1066                 printf("Please stop all ports first\n");
1067                 return;
1068         }
1069
1070         if (port_id_is_invalid(res->id, ENABLED_WARN))
1071                 return;
1072
1073         if (!strcmp(res->value1, "10"))
1074                 link_speed = ETH_LINK_SPEED_10;
1075         else if (!strcmp(res->value1, "100"))
1076                 link_speed = ETH_LINK_SPEED_100;
1077         else if (!strcmp(res->value1, "1000"))
1078                 link_speed = ETH_LINK_SPEED_1000;
1079         else if (!strcmp(res->value1, "10000"))
1080                 link_speed = ETH_LINK_SPEED_10000;
1081         else if (!strcmp(res->value1, "40000"))
1082                 link_speed = ETH_LINK_SPEED_40G;
1083         else if (!strcmp(res->value1, "auto"))
1084                 link_speed = ETH_LINK_SPEED_AUTONEG;
1085         else {
1086                 printf("Unknown parameter\n");
1087                 return;
1088         }
1089
1090         if (!strcmp(res->value2, "half"))
1091                 link_duplex = ETH_LINK_HALF_DUPLEX;
1092         else if (!strcmp(res->value2, "full"))
1093                 link_duplex = ETH_LINK_FULL_DUPLEX;
1094         else if (!strcmp(res->value2, "auto"))
1095                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1096         else {
1097                 printf("Unknown parameter\n");
1098                 return;
1099         }
1100
1101         ports[res->id].dev_conf.link_speed = link_speed;
1102         ports[res->id].dev_conf.link_duplex = link_duplex;
1103
1104         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1105 }
1106
1107
1108 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1109         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1110                                                                 "port");
1111 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1112         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1113                                                                 "config");
1114 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1115         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1116 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1117         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1118                                                                 "speed");
1119 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1120         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1121                                                 "10#100#1000#10000#40000#auto");
1122 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1123         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1124                                                                 "duplex");
1125 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1126         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1127                                                         "half#full#auto");
1128
1129 cmdline_parse_inst_t cmd_config_speed_specific = {
1130         .f = cmd_config_speed_specific_parsed,
1131         .data = NULL,
1132         .help_str = "port config X speed 10|100|1000|10000|40000|auto duplex "
1133                                                         "half|full|auto",
1134         .tokens = {
1135                 (void *)&cmd_config_speed_specific_port,
1136                 (void *)&cmd_config_speed_specific_keyword,
1137                 (void *)&cmd_config_speed_specific_id,
1138                 (void *)&cmd_config_speed_specific_item1,
1139                 (void *)&cmd_config_speed_specific_value1,
1140                 (void *)&cmd_config_speed_specific_item2,
1141                 (void *)&cmd_config_speed_specific_value2,
1142                 NULL,
1143         },
1144 };
1145
1146 /* *** configure txq/rxq, txd/rxd *** */
1147 struct cmd_config_rx_tx {
1148         cmdline_fixed_string_t port;
1149         cmdline_fixed_string_t keyword;
1150         cmdline_fixed_string_t all;
1151         cmdline_fixed_string_t name;
1152         uint16_t value;
1153 };
1154
1155 static void
1156 cmd_config_rx_tx_parsed(void *parsed_result,
1157                         __attribute__((unused)) struct cmdline *cl,
1158                         __attribute__((unused)) void *data)
1159 {
1160         struct cmd_config_rx_tx *res = parsed_result;
1161
1162         if (!all_ports_stopped()) {
1163                 printf("Please stop all ports first\n");
1164                 return;
1165         }
1166
1167         if (!strcmp(res->name, "rxq")) {
1168                 if (res->value <= 0) {
1169                         printf("rxq %d invalid - must be > 0\n", res->value);
1170                         return;
1171                 }
1172                 nb_rxq = res->value;
1173         }
1174         else if (!strcmp(res->name, "txq")) {
1175                 if (res->value <= 0) {
1176                         printf("txq %d invalid - must be > 0\n", res->value);
1177                         return;
1178                 }
1179                 nb_txq = res->value;
1180         }
1181         else if (!strcmp(res->name, "rxd")) {
1182                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1183                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1184                                         res->value, RTE_TEST_RX_DESC_MAX);
1185                         return;
1186                 }
1187                 nb_rxd = res->value;
1188         } else if (!strcmp(res->name, "txd")) {
1189                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1190                         printf("txd %d invalid - must be > 0 && <= %d\n",
1191                                         res->value, RTE_TEST_TX_DESC_MAX);
1192                         return;
1193                 }
1194                 nb_txd = res->value;
1195         } else {
1196                 printf("Unknown parameter\n");
1197                 return;
1198         }
1199
1200         init_port_config();
1201
1202         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1203 }
1204
1205 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1206         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1207 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1208         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1209 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1210         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1211 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1212         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1213                                                 "rxq#txq#rxd#txd");
1214 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1215         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1216
1217 cmdline_parse_inst_t cmd_config_rx_tx = {
1218         .f = cmd_config_rx_tx_parsed,
1219         .data = NULL,
1220         .help_str = "port config all rxq|txq|rxd|txd value",
1221         .tokens = {
1222                 (void *)&cmd_config_rx_tx_port,
1223                 (void *)&cmd_config_rx_tx_keyword,
1224                 (void *)&cmd_config_rx_tx_all,
1225                 (void *)&cmd_config_rx_tx_name,
1226                 (void *)&cmd_config_rx_tx_value,
1227                 NULL,
1228         },
1229 };
1230
1231 /* *** config max packet length *** */
1232 struct cmd_config_max_pkt_len_result {
1233         cmdline_fixed_string_t port;
1234         cmdline_fixed_string_t keyword;
1235         cmdline_fixed_string_t all;
1236         cmdline_fixed_string_t name;
1237         uint32_t value;
1238 };
1239
1240 static void
1241 cmd_config_max_pkt_len_parsed(void *parsed_result,
1242                                 __attribute__((unused)) struct cmdline *cl,
1243                                 __attribute__((unused)) void *data)
1244 {
1245         struct cmd_config_max_pkt_len_result *res = parsed_result;
1246
1247         if (!all_ports_stopped()) {
1248                 printf("Please stop all ports first\n");
1249                 return;
1250         }
1251
1252         if (!strcmp(res->name, "max-pkt-len")) {
1253                 if (res->value < ETHER_MIN_LEN) {
1254                         printf("max-pkt-len can not be less than %d\n",
1255                                                         ETHER_MIN_LEN);
1256                         return;
1257                 }
1258                 if (res->value == rx_mode.max_rx_pkt_len)
1259                         return;
1260
1261                 rx_mode.max_rx_pkt_len = res->value;
1262                 if (res->value > ETHER_MAX_LEN)
1263                         rx_mode.jumbo_frame = 1;
1264                 else
1265                         rx_mode.jumbo_frame = 0;
1266         } else {
1267                 printf("Unknown parameter\n");
1268                 return;
1269         }
1270
1271         init_port_config();
1272
1273         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1274 }
1275
1276 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1277         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1278                                                                 "port");
1279 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1280         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1281                                                                 "config");
1282 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1283         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1284                                                                 "all");
1285 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1286         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1287                                                                 "max-pkt-len");
1288 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1289         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1290                                                                 UINT32);
1291
1292 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1293         .f = cmd_config_max_pkt_len_parsed,
1294         .data = NULL,
1295         .help_str = "port config all max-pkt-len value",
1296         .tokens = {
1297                 (void *)&cmd_config_max_pkt_len_port,
1298                 (void *)&cmd_config_max_pkt_len_keyword,
1299                 (void *)&cmd_config_max_pkt_len_all,
1300                 (void *)&cmd_config_max_pkt_len_name,
1301                 (void *)&cmd_config_max_pkt_len_value,
1302                 NULL,
1303         },
1304 };
1305
1306 /* *** configure port MTU *** */
1307 struct cmd_config_mtu_result {
1308         cmdline_fixed_string_t port;
1309         cmdline_fixed_string_t keyword;
1310         cmdline_fixed_string_t mtu;
1311         uint8_t port_id;
1312         uint16_t value;
1313 };
1314
1315 static void
1316 cmd_config_mtu_parsed(void *parsed_result,
1317                       __attribute__((unused)) struct cmdline *cl,
1318                       __attribute__((unused)) void *data)
1319 {
1320         struct cmd_config_mtu_result *res = parsed_result;
1321
1322         if (res->value < ETHER_MIN_LEN) {
1323                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1324                 return;
1325         }
1326         port_mtu_set(res->port_id, res->value);
1327 }
1328
1329 cmdline_parse_token_string_t cmd_config_mtu_port =
1330         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1331                                  "port");
1332 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1333         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1334                                  "config");
1335 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1336         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1337                                  "mtu");
1338 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1339         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1340 cmdline_parse_token_num_t cmd_config_mtu_value =
1341         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1342
1343 cmdline_parse_inst_t cmd_config_mtu = {
1344         .f = cmd_config_mtu_parsed,
1345         .data = NULL,
1346         .help_str = "port config mtu value",
1347         .tokens = {
1348                 (void *)&cmd_config_mtu_port,
1349                 (void *)&cmd_config_mtu_keyword,
1350                 (void *)&cmd_config_mtu_mtu,
1351                 (void *)&cmd_config_mtu_port_id,
1352                 (void *)&cmd_config_mtu_value,
1353                 NULL,
1354         },
1355 };
1356
1357 /* *** configure rx mode *** */
1358 struct cmd_config_rx_mode_flag {
1359         cmdline_fixed_string_t port;
1360         cmdline_fixed_string_t keyword;
1361         cmdline_fixed_string_t all;
1362         cmdline_fixed_string_t name;
1363         cmdline_fixed_string_t value;
1364 };
1365
1366 static void
1367 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1368                                 __attribute__((unused)) struct cmdline *cl,
1369                                 __attribute__((unused)) void *data)
1370 {
1371         struct cmd_config_rx_mode_flag *res = parsed_result;
1372
1373         if (!all_ports_stopped()) {
1374                 printf("Please stop all ports first\n");
1375                 return;
1376         }
1377
1378         if (!strcmp(res->name, "crc-strip")) {
1379                 if (!strcmp(res->value, "on"))
1380                         rx_mode.hw_strip_crc = 1;
1381                 else if (!strcmp(res->value, "off"))
1382                         rx_mode.hw_strip_crc = 0;
1383                 else {
1384                         printf("Unknown parameter\n");
1385                         return;
1386                 }
1387         } else if (!strcmp(res->name, "rx-cksum")) {
1388                 if (!strcmp(res->value, "on"))
1389                         rx_mode.hw_ip_checksum = 1;
1390                 else if (!strcmp(res->value, "off"))
1391                         rx_mode.hw_ip_checksum = 0;
1392                 else {
1393                         printf("Unknown parameter\n");
1394                         return;
1395                 }
1396         } else if (!strcmp(res->name, "hw-vlan")) {
1397                 if (!strcmp(res->value, "on")) {
1398                         rx_mode.hw_vlan_filter = 1;
1399                         rx_mode.hw_vlan_strip  = 1;
1400                 }
1401                 else if (!strcmp(res->value, "off")) {
1402                         rx_mode.hw_vlan_filter = 0;
1403                         rx_mode.hw_vlan_strip  = 0;
1404                 }
1405                 else {
1406                         printf("Unknown parameter\n");
1407                         return;
1408                 }
1409         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1410                 if (!strcmp(res->value, "on"))
1411                         rx_mode.hw_vlan_filter = 1;
1412                 else if (!strcmp(res->value, "off"))
1413                         rx_mode.hw_vlan_filter = 0;
1414                 else {
1415                         printf("Unknown parameter\n");
1416                         return;
1417                 }
1418         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1419                 if (!strcmp(res->value, "on"))
1420                         rx_mode.hw_vlan_strip  = 1;
1421                 else if (!strcmp(res->value, "off"))
1422                         rx_mode.hw_vlan_strip  = 0;
1423                 else {
1424                         printf("Unknown parameter\n");
1425                         return;
1426                 }
1427         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1428                 if (!strcmp(res->value, "on"))
1429                         rx_mode.hw_vlan_extend = 1;
1430                 else if (!strcmp(res->value, "off"))
1431                         rx_mode.hw_vlan_extend = 0;
1432                 else {
1433                         printf("Unknown parameter\n");
1434                         return;
1435                 }
1436         } else if (!strcmp(res->name, "drop-en")) {
1437                 if (!strcmp(res->value, "on"))
1438                         rx_drop_en = 1;
1439                 else if (!strcmp(res->value, "off"))
1440                         rx_drop_en = 0;
1441                 else {
1442                         printf("Unknown parameter\n");
1443                         return;
1444                 }
1445         } else {
1446                 printf("Unknown parameter\n");
1447                 return;
1448         }
1449
1450         init_port_config();
1451
1452         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1453 }
1454
1455 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1456         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1457 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1459                                                                 "config");
1460 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1462 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1464                                         "crc-strip#rx-cksum#hw-vlan#"
1465                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1466 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1467         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1468                                                         "on#off");
1469
1470 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1471         .f = cmd_config_rx_mode_flag_parsed,
1472         .data = NULL,
1473         .help_str = "port config all crc-strip|rx-cksum|hw-vlan|"
1474                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1475         .tokens = {
1476                 (void *)&cmd_config_rx_mode_flag_port,
1477                 (void *)&cmd_config_rx_mode_flag_keyword,
1478                 (void *)&cmd_config_rx_mode_flag_all,
1479                 (void *)&cmd_config_rx_mode_flag_name,
1480                 (void *)&cmd_config_rx_mode_flag_value,
1481                 NULL,
1482         },
1483 };
1484
1485 /* *** configure rss *** */
1486 struct cmd_config_rss {
1487         cmdline_fixed_string_t port;
1488         cmdline_fixed_string_t keyword;
1489         cmdline_fixed_string_t all;
1490         cmdline_fixed_string_t name;
1491         cmdline_fixed_string_t value;
1492 };
1493
1494 static void
1495 cmd_config_rss_parsed(void *parsed_result,
1496                         __attribute__((unused)) struct cmdline *cl,
1497                         __attribute__((unused)) void *data)
1498 {
1499         struct cmd_config_rss *res = parsed_result;
1500         struct rte_eth_rss_conf rss_conf;
1501         uint8_t i;
1502
1503         if (!strcmp(res->value, "all"))
1504                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1505                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1506                                         ETH_RSS_L2_PAYLOAD;
1507         else if (!strcmp(res->value, "ip"))
1508                 rss_conf.rss_hf = ETH_RSS_IP;
1509         else if (!strcmp(res->value, "udp"))
1510                 rss_conf.rss_hf = ETH_RSS_UDP;
1511         else if (!strcmp(res->value, "tcp"))
1512                 rss_conf.rss_hf = ETH_RSS_TCP;
1513         else if (!strcmp(res->value, "sctp"))
1514                 rss_conf.rss_hf = ETH_RSS_SCTP;
1515         else if (!strcmp(res->value, "ether"))
1516                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1517         else if (!strcmp(res->value, "none"))
1518                 rss_conf.rss_hf = 0;
1519         else {
1520                 printf("Unknown parameter\n");
1521                 return;
1522         }
1523         rss_conf.rss_key = NULL;
1524         for (i = 0; i < rte_eth_dev_count(); i++)
1525                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1526 }
1527
1528 cmdline_parse_token_string_t cmd_config_rss_port =
1529         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1530 cmdline_parse_token_string_t cmd_config_rss_keyword =
1531         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1532 cmdline_parse_token_string_t cmd_config_rss_all =
1533         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1534 cmdline_parse_token_string_t cmd_config_rss_name =
1535         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1536 cmdline_parse_token_string_t cmd_config_rss_value =
1537         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1538                 "all#ip#tcp#udp#sctp#ether#none");
1539
1540 cmdline_parse_inst_t cmd_config_rss = {
1541         .f = cmd_config_rss_parsed,
1542         .data = NULL,
1543         .help_str = "port config all rss all|ip|tcp|udp|sctp|ether|none",
1544         .tokens = {
1545                 (void *)&cmd_config_rss_port,
1546                 (void *)&cmd_config_rss_keyword,
1547                 (void *)&cmd_config_rss_all,
1548                 (void *)&cmd_config_rss_name,
1549                 (void *)&cmd_config_rss_value,
1550                 NULL,
1551         },
1552 };
1553
1554 /* *** configure rss hash key *** */
1555 struct cmd_config_rss_hash_key {
1556         cmdline_fixed_string_t port;
1557         cmdline_fixed_string_t config;
1558         uint8_t port_id;
1559         cmdline_fixed_string_t rss_hash_key;
1560         cmdline_fixed_string_t rss_type;
1561         cmdline_fixed_string_t key;
1562 };
1563
1564 #define RSS_HASH_KEY_LENGTH 40
1565 static uint8_t
1566 hexa_digit_to_value(char hexa_digit)
1567 {
1568         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1569                 return (uint8_t) (hexa_digit - '0');
1570         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1571                 return (uint8_t) ((hexa_digit - 'a') + 10);
1572         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1573                 return (uint8_t) ((hexa_digit - 'A') + 10);
1574         /* Invalid hexa digit */
1575         return 0xFF;
1576 }
1577
1578 static uint8_t
1579 parse_and_check_key_hexa_digit(char *key, int idx)
1580 {
1581         uint8_t hexa_v;
1582
1583         hexa_v = hexa_digit_to_value(key[idx]);
1584         if (hexa_v == 0xFF)
1585                 printf("invalid key: character %c at position %d is not a "
1586                        "valid hexa digit\n", key[idx], idx);
1587         return hexa_v;
1588 }
1589
1590 static void
1591 cmd_config_rss_hash_key_parsed(void *parsed_result,
1592                                __attribute__((unused)) struct cmdline *cl,
1593                                __attribute__((unused)) void *data)
1594 {
1595         struct cmd_config_rss_hash_key *res = parsed_result;
1596         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1597         uint8_t xdgt0;
1598         uint8_t xdgt1;
1599         int i;
1600
1601         /* Check the length of the RSS hash key */
1602         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1603                 printf("key length: %d invalid - key must be a string of %d"
1604                        "hexa-decimal numbers\n", (int) strlen(res->key),
1605                        RSS_HASH_KEY_LENGTH * 2);
1606                 return;
1607         }
1608         /* Translate RSS hash key into binary representation */
1609         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1610                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1611                 if (xdgt0 == 0xFF)
1612                         return;
1613                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1614                 if (xdgt1 == 0xFF)
1615                         return;
1616                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1617         }
1618         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1619                                  RSS_HASH_KEY_LENGTH);
1620 }
1621
1622 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1623         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1624 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1625         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1626                                  "config");
1627 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1628         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1629 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1630         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1631                                  rss_hash_key, "rss-hash-key");
1632 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1633         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1634                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1635                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1636                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1637                                  "ipv6-tcp-ex#ipv6-udp-ex");
1638 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1639         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1640
1641 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1642         .f = cmd_config_rss_hash_key_parsed,
1643         .data = NULL,
1644         .help_str =
1645                 "port config X rss-hash-key ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
1646                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
1647                 "ipv6-sctp|ipv6-other|l2-payload|"
1648                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex 80 hexa digits\n",
1649         .tokens = {
1650                 (void *)&cmd_config_rss_hash_key_port,
1651                 (void *)&cmd_config_rss_hash_key_config,
1652                 (void *)&cmd_config_rss_hash_key_port_id,
1653                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1654                 (void *)&cmd_config_rss_hash_key_rss_type,
1655                 (void *)&cmd_config_rss_hash_key_value,
1656                 NULL,
1657         },
1658 };
1659
1660 /* *** configure port rxq/txq start/stop *** */
1661 struct cmd_config_rxtx_queue {
1662         cmdline_fixed_string_t port;
1663         uint8_t portid;
1664         cmdline_fixed_string_t rxtxq;
1665         uint16_t qid;
1666         cmdline_fixed_string_t opname;
1667 };
1668
1669 static void
1670 cmd_config_rxtx_queue_parsed(void *parsed_result,
1671                         __attribute__((unused)) struct cmdline *cl,
1672                         __attribute__((unused)) void *data)
1673 {
1674         struct cmd_config_rxtx_queue *res = parsed_result;
1675         uint8_t isrx;
1676         uint8_t isstart;
1677         int ret = 0;
1678
1679         if (test_done == 0) {
1680                 printf("Please stop forwarding first\n");
1681                 return;
1682         }
1683
1684         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1685                 return;
1686
1687         if (port_is_started(res->portid) != 1) {
1688                 printf("Please start port %u first\n", res->portid);
1689                 return;
1690         }
1691
1692         if (!strcmp(res->rxtxq, "rxq"))
1693                 isrx = 1;
1694         else if (!strcmp(res->rxtxq, "txq"))
1695                 isrx = 0;
1696         else {
1697                 printf("Unknown parameter\n");
1698                 return;
1699         }
1700
1701         if (isrx && rx_queue_id_is_invalid(res->qid))
1702                 return;
1703         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1704                 return;
1705
1706         if (!strcmp(res->opname, "start"))
1707                 isstart = 1;
1708         else if (!strcmp(res->opname, "stop"))
1709                 isstart = 0;
1710         else {
1711                 printf("Unknown parameter\n");
1712                 return;
1713         }
1714
1715         if (isstart && isrx)
1716                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1717         else if (!isstart && isrx)
1718                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1719         else if (isstart && !isrx)
1720                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1721         else
1722                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1723
1724         if (ret == -ENOTSUP)
1725                 printf("Function not supported in PMD driver\n");
1726 }
1727
1728 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1730 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1731         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1732 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1734 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1735         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1736 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1738                                                 "start#stop");
1739
1740 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1741         .f = cmd_config_rxtx_queue_parsed,
1742         .data = NULL,
1743         .help_str = "port X rxq|txq ID start|stop",
1744         .tokens = {
1745                 (void *)&cmd_config_speed_all_port,
1746                 (void *)&cmd_config_rxtx_queue_portid,
1747                 (void *)&cmd_config_rxtx_queue_rxtxq,
1748                 (void *)&cmd_config_rxtx_queue_qid,
1749                 (void *)&cmd_config_rxtx_queue_opname,
1750                 NULL,
1751         },
1752 };
1753
1754 /* *** Configure RSS RETA *** */
1755 struct cmd_config_rss_reta {
1756         cmdline_fixed_string_t port;
1757         cmdline_fixed_string_t keyword;
1758         uint8_t port_id;
1759         cmdline_fixed_string_t name;
1760         cmdline_fixed_string_t list_name;
1761         cmdline_fixed_string_t list_of_items;
1762 };
1763
1764 static int
1765 parse_reta_config(const char *str,
1766                   struct rte_eth_rss_reta_entry64 *reta_conf,
1767                   uint16_t nb_entries)
1768 {
1769         int i;
1770         unsigned size;
1771         uint16_t hash_index, idx, shift;
1772         uint16_t nb_queue;
1773         char s[256];
1774         const char *p, *p0 = str;
1775         char *end;
1776         enum fieldnames {
1777                 FLD_HASH_INDEX = 0,
1778                 FLD_QUEUE,
1779                 _NUM_FLD
1780         };
1781         unsigned long int_fld[_NUM_FLD];
1782         char *str_fld[_NUM_FLD];
1783
1784         while ((p = strchr(p0,'(')) != NULL) {
1785                 ++p;
1786                 if((p0 = strchr(p,')')) == NULL)
1787                         return -1;
1788
1789                 size = p0 - p;
1790                 if(size >= sizeof(s))
1791                         return -1;
1792
1793                 snprintf(s, sizeof(s), "%.*s", size, p);
1794                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1795                         return -1;
1796                 for (i = 0; i < _NUM_FLD; i++) {
1797                         errno = 0;
1798                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1799                         if (errno != 0 || end == str_fld[i] ||
1800                                         int_fld[i] > 65535)
1801                                 return -1;
1802                 }
1803
1804                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1805                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
1806
1807                 if (hash_index >= nb_entries) {
1808                         printf("Invalid RETA hash index=%d\n", hash_index);
1809                         return -1;
1810                 }
1811
1812                 idx = hash_index / RTE_RETA_GROUP_SIZE;
1813                 shift = hash_index % RTE_RETA_GROUP_SIZE;
1814                 reta_conf[idx].mask |= (1ULL << shift);
1815                 reta_conf[idx].reta[shift] = nb_queue;
1816         }
1817
1818         return 0;
1819 }
1820
1821 static void
1822 cmd_set_rss_reta_parsed(void *parsed_result,
1823                         __attribute__((unused)) struct cmdline *cl,
1824                         __attribute__((unused)) void *data)
1825 {
1826         int ret;
1827         struct rte_eth_dev_info dev_info;
1828         struct rte_eth_rss_reta_entry64 reta_conf[8];
1829         struct cmd_config_rss_reta *res = parsed_result;
1830
1831         memset(&dev_info, 0, sizeof(dev_info));
1832         rte_eth_dev_info_get(res->port_id, &dev_info);
1833         if (dev_info.reta_size == 0) {
1834                 printf("Redirection table size is 0 which is "
1835                                         "invalid for RSS\n");
1836                 return;
1837         } else
1838                 printf("The reta size of port %d is %u\n",
1839                         res->port_id, dev_info.reta_size);
1840         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
1841                 printf("Currently do not support more than %u entries of "
1842                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
1843                 return;
1844         }
1845
1846         memset(reta_conf, 0, sizeof(reta_conf));
1847         if (!strcmp(res->list_name, "reta")) {
1848                 if (parse_reta_config(res->list_of_items, reta_conf,
1849                                                 dev_info.reta_size)) {
1850                         printf("Invalid RSS Redirection Table "
1851                                         "config entered\n");
1852                         return;
1853                 }
1854                 ret = rte_eth_dev_rss_reta_update(res->port_id,
1855                                 reta_conf, dev_info.reta_size);
1856                 if (ret != 0)
1857                         printf("Bad redirection table parameter, "
1858                                         "return code = %d \n", ret);
1859         }
1860 }
1861
1862 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1864 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1865         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1866 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1867         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1868 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1869         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1870 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1871         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1872 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1873         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1874                                  NULL);
1875 cmdline_parse_inst_t cmd_config_rss_reta = {
1876         .f = cmd_set_rss_reta_parsed,
1877         .data = NULL,
1878         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1879         .tokens = {
1880                 (void *)&cmd_config_rss_reta_port,
1881                 (void *)&cmd_config_rss_reta_keyword,
1882                 (void *)&cmd_config_rss_reta_port_id,
1883                 (void *)&cmd_config_rss_reta_name,
1884                 (void *)&cmd_config_rss_reta_list_name,
1885                 (void *)&cmd_config_rss_reta_list_of_items,
1886                 NULL,
1887         },
1888 };
1889
1890 /* *** SHOW PORT RETA INFO *** */
1891 struct cmd_showport_reta {
1892         cmdline_fixed_string_t show;
1893         cmdline_fixed_string_t port;
1894         uint8_t port_id;
1895         cmdline_fixed_string_t rss;
1896         cmdline_fixed_string_t reta;
1897         uint16_t size;
1898         cmdline_fixed_string_t list_of_items;
1899 };
1900
1901 static int
1902 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
1903                            uint16_t nb_entries,
1904                            char *str)
1905 {
1906         uint32_t size;
1907         const char *p, *p0 = str;
1908         char s[256];
1909         char *end;
1910         char *str_fld[8];
1911         uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE;
1912         int ret;
1913
1914         p = strchr(p0, '(');
1915         if (p == NULL)
1916                 return -1;
1917         p++;
1918         p0 = strchr(p, ')');
1919         if (p0 == NULL)
1920                 return -1;
1921         size = p0 - p;
1922         if (size >= sizeof(s)) {
1923                 printf("The string size exceeds the internal buffer size\n");
1924                 return -1;
1925         }
1926         snprintf(s, sizeof(s), "%.*s", size, p);
1927         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
1928         if (ret <= 0 || ret != num) {
1929                 printf("The bits of masks do not match the number of "
1930                                         "reta entries: %u\n", num);
1931                 return -1;
1932         }
1933         for (i = 0; i < ret; i++)
1934                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
1935
1936         return 0;
1937 }
1938
1939 static void
1940 cmd_showport_reta_parsed(void *parsed_result,
1941                          __attribute__((unused)) struct cmdline *cl,
1942                          __attribute__((unused)) void *data)
1943 {
1944         struct cmd_showport_reta *res = parsed_result;
1945         struct rte_eth_rss_reta_entry64 reta_conf[8];
1946         struct rte_eth_dev_info dev_info;
1947
1948         memset(&dev_info, 0, sizeof(dev_info));
1949         rte_eth_dev_info_get(res->port_id, &dev_info);
1950         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
1951                                 res->size > ETH_RSS_RETA_SIZE_512) {
1952                 printf("Invalid redirection table size: %u\n", res->size);
1953                 return;
1954         }
1955
1956         memset(reta_conf, 0, sizeof(reta_conf));
1957         if (showport_parse_reta_config(reta_conf, res->size,
1958                                 res->list_of_items) < 0) {
1959                 printf("Invalid string: %s for reta masks\n",
1960                                         res->list_of_items);
1961                 return;
1962         }
1963         port_rss_reta_info(res->port_id, reta_conf, res->size);
1964 }
1965
1966 cmdline_parse_token_string_t cmd_showport_reta_show =
1967         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1968 cmdline_parse_token_string_t cmd_showport_reta_port =
1969         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1970 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1971         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1972 cmdline_parse_token_string_t cmd_showport_reta_rss =
1973         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1974 cmdline_parse_token_string_t cmd_showport_reta_reta =
1975         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1976 cmdline_parse_token_num_t cmd_showport_reta_size =
1977         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
1978 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
1979         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
1980                                         list_of_items, NULL);
1981
1982 cmdline_parse_inst_t cmd_showport_reta = {
1983         .f = cmd_showport_reta_parsed,
1984         .data = NULL,
1985         .help_str = "show port X rss reta (size) (mask0,mask1,...)",
1986         .tokens = {
1987                 (void *)&cmd_showport_reta_show,
1988                 (void *)&cmd_showport_reta_port,
1989                 (void *)&cmd_showport_reta_port_id,
1990                 (void *)&cmd_showport_reta_rss,
1991                 (void *)&cmd_showport_reta_reta,
1992                 (void *)&cmd_showport_reta_size,
1993                 (void *)&cmd_showport_reta_list_of_items,
1994                 NULL,
1995         },
1996 };
1997
1998 /* *** Show RSS hash configuration *** */
1999 struct cmd_showport_rss_hash {
2000         cmdline_fixed_string_t show;
2001         cmdline_fixed_string_t port;
2002         uint8_t port_id;
2003         cmdline_fixed_string_t rss_hash;
2004         cmdline_fixed_string_t rss_type;
2005         cmdline_fixed_string_t key; /* optional argument */
2006 };
2007
2008 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2009                                 __attribute__((unused)) struct cmdline *cl,
2010                                 void *show_rss_key)
2011 {
2012         struct cmd_showport_rss_hash *res = parsed_result;
2013
2014         port_rss_hash_conf_show(res->port_id, res->rss_type,
2015                                 show_rss_key != NULL);
2016 }
2017
2018 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2019         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2020 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2021         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2022 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2023         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2024 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2025         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2026                                  "rss-hash");
2027 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2028         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2029                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2030                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2031                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2032                                  "ipv6-tcp-ex#ipv6-udp-ex");
2033 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2034         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2035
2036 cmdline_parse_inst_t cmd_showport_rss_hash = {
2037         .f = cmd_showport_rss_hash_parsed,
2038         .data = NULL,
2039         .help_str =
2040                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2041                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2042                 "ipv6-sctp|ipv6-other|l2-payload|"
2043                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex (X = port number)\n",
2044         .tokens = {
2045                 (void *)&cmd_showport_rss_hash_show,
2046                 (void *)&cmd_showport_rss_hash_port,
2047                 (void *)&cmd_showport_rss_hash_port_id,
2048                 (void *)&cmd_showport_rss_hash_rss_hash,
2049                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2050                 NULL,
2051         },
2052 };
2053
2054 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2055         .f = cmd_showport_rss_hash_parsed,
2056         .data = (void *)1,
2057         .help_str =
2058                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2059                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2060                 "ipv6-sctp|ipv6-other|l2-payload|"
2061                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key (X = port number)\n",
2062         .tokens = {
2063                 (void *)&cmd_showport_rss_hash_show,
2064                 (void *)&cmd_showport_rss_hash_port,
2065                 (void *)&cmd_showport_rss_hash_port_id,
2066                 (void *)&cmd_showport_rss_hash_rss_hash,
2067                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2068                 (void *)&cmd_showport_rss_hash_rss_key,
2069                 NULL,
2070         },
2071 };
2072
2073 /* *** Configure DCB *** */
2074 struct cmd_config_dcb {
2075         cmdline_fixed_string_t port;
2076         cmdline_fixed_string_t config;
2077         uint8_t port_id;
2078         cmdline_fixed_string_t dcb;
2079         cmdline_fixed_string_t vt;
2080         cmdline_fixed_string_t vt_en;
2081         uint8_t num_tcs;
2082         cmdline_fixed_string_t pfc;
2083         cmdline_fixed_string_t pfc_en;
2084 };
2085
2086 static void
2087 cmd_config_dcb_parsed(void *parsed_result,
2088                         __attribute__((unused)) struct cmdline *cl,
2089                         __attribute__((unused)) void *data)
2090 {
2091         struct cmd_config_dcb *res = parsed_result;
2092         portid_t port_id = res->port_id;
2093         struct rte_port *port;
2094         uint8_t pfc_en;
2095         int ret;
2096
2097         port = &ports[port_id];
2098         /** Check if the port is not started **/
2099         if (port->port_status != RTE_PORT_STOPPED) {
2100                 printf("Please stop port %d first\n", port_id);
2101                 return;
2102         }
2103
2104         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2105                 printf("The invalid number of traffic class,"
2106                         " only 4 or 8 allowed.\n");
2107                 return;
2108         }
2109
2110         if (nb_fwd_lcores < res->num_tcs) {
2111                 printf("nb_cores shouldn't be less than number of TCs.\n");
2112                 return;
2113         }
2114         if (!strncmp(res->pfc_en, "on", 2))
2115                 pfc_en = 1;
2116         else
2117                 pfc_en = 0;
2118
2119         /* DCB in VT mode */
2120         if (!strncmp(res->vt_en, "on", 2))
2121                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2122                                 (enum rte_eth_nb_tcs)res->num_tcs,
2123                                 pfc_en);
2124         else
2125                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2126                                 (enum rte_eth_nb_tcs)res->num_tcs,
2127                                 pfc_en);
2128
2129
2130         if (ret != 0) {
2131                 printf("Cannot initialize network ports.\n");
2132                 return;
2133         }
2134
2135         cmd_reconfig_device_queue(port_id, 1, 1);
2136 }
2137
2138 cmdline_parse_token_string_t cmd_config_dcb_port =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2140 cmdline_parse_token_string_t cmd_config_dcb_config =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2142 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2143         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2144 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2146 cmdline_parse_token_string_t cmd_config_dcb_vt =
2147         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2148 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2150 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2151         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2152 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2154 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2156
2157 cmdline_parse_inst_t cmd_config_dcb = {
2158         .f = cmd_config_dcb_parsed,
2159         .data = NULL,
2160         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
2161         .tokens = {
2162                 (void *)&cmd_config_dcb_port,
2163                 (void *)&cmd_config_dcb_config,
2164                 (void *)&cmd_config_dcb_port_id,
2165                 (void *)&cmd_config_dcb_dcb,
2166                 (void *)&cmd_config_dcb_vt,
2167                 (void *)&cmd_config_dcb_vt_en,
2168                 (void *)&cmd_config_dcb_num_tcs,
2169                 (void *)&cmd_config_dcb_pfc,
2170                 (void *)&cmd_config_dcb_pfc_en,
2171                 NULL,
2172         },
2173 };
2174
2175 /* *** configure number of packets per burst *** */
2176 struct cmd_config_burst {
2177         cmdline_fixed_string_t port;
2178         cmdline_fixed_string_t keyword;
2179         cmdline_fixed_string_t all;
2180         cmdline_fixed_string_t name;
2181         uint16_t value;
2182 };
2183
2184 static void
2185 cmd_config_burst_parsed(void *parsed_result,
2186                         __attribute__((unused)) struct cmdline *cl,
2187                         __attribute__((unused)) void *data)
2188 {
2189         struct cmd_config_burst *res = parsed_result;
2190
2191         if (!all_ports_stopped()) {
2192                 printf("Please stop all ports first\n");
2193                 return;
2194         }
2195
2196         if (!strcmp(res->name, "burst")) {
2197                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2198                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2199                         return;
2200                 }
2201                 nb_pkt_per_burst = res->value;
2202         } else {
2203                 printf("Unknown parameter\n");
2204                 return;
2205         }
2206
2207         init_port_config();
2208
2209         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2210 }
2211
2212 cmdline_parse_token_string_t cmd_config_burst_port =
2213         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2214 cmdline_parse_token_string_t cmd_config_burst_keyword =
2215         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2216 cmdline_parse_token_string_t cmd_config_burst_all =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2218 cmdline_parse_token_string_t cmd_config_burst_name =
2219         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2220 cmdline_parse_token_num_t cmd_config_burst_value =
2221         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2222
2223 cmdline_parse_inst_t cmd_config_burst = {
2224         .f = cmd_config_burst_parsed,
2225         .data = NULL,
2226         .help_str = "port config all burst value",
2227         .tokens = {
2228                 (void *)&cmd_config_burst_port,
2229                 (void *)&cmd_config_burst_keyword,
2230                 (void *)&cmd_config_burst_all,
2231                 (void *)&cmd_config_burst_name,
2232                 (void *)&cmd_config_burst_value,
2233                 NULL,
2234         },
2235 };
2236
2237 /* *** configure rx/tx queues *** */
2238 struct cmd_config_thresh {
2239         cmdline_fixed_string_t port;
2240         cmdline_fixed_string_t keyword;
2241         cmdline_fixed_string_t all;
2242         cmdline_fixed_string_t name;
2243         uint8_t value;
2244 };
2245
2246 static void
2247 cmd_config_thresh_parsed(void *parsed_result,
2248                         __attribute__((unused)) struct cmdline *cl,
2249                         __attribute__((unused)) void *data)
2250 {
2251         struct cmd_config_thresh *res = parsed_result;
2252
2253         if (!all_ports_stopped()) {
2254                 printf("Please stop all ports first\n");
2255                 return;
2256         }
2257
2258         if (!strcmp(res->name, "txpt"))
2259                 tx_pthresh = res->value;
2260         else if(!strcmp(res->name, "txht"))
2261                 tx_hthresh = res->value;
2262         else if(!strcmp(res->name, "txwt"))
2263                 tx_wthresh = res->value;
2264         else if(!strcmp(res->name, "rxpt"))
2265                 rx_pthresh = res->value;
2266         else if(!strcmp(res->name, "rxht"))
2267                 rx_hthresh = res->value;
2268         else if(!strcmp(res->name, "rxwt"))
2269                 rx_wthresh = res->value;
2270         else {
2271                 printf("Unknown parameter\n");
2272                 return;
2273         }
2274
2275         init_port_config();
2276
2277         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2278 }
2279
2280 cmdline_parse_token_string_t cmd_config_thresh_port =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2282 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2284 cmdline_parse_token_string_t cmd_config_thresh_all =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2286 cmdline_parse_token_string_t cmd_config_thresh_name =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2288                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2289 cmdline_parse_token_num_t cmd_config_thresh_value =
2290         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2291
2292 cmdline_parse_inst_t cmd_config_thresh = {
2293         .f = cmd_config_thresh_parsed,
2294         .data = NULL,
2295         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
2296         .tokens = {
2297                 (void *)&cmd_config_thresh_port,
2298                 (void *)&cmd_config_thresh_keyword,
2299                 (void *)&cmd_config_thresh_all,
2300                 (void *)&cmd_config_thresh_name,
2301                 (void *)&cmd_config_thresh_value,
2302                 NULL,
2303         },
2304 };
2305
2306 /* *** configure free/rs threshold *** */
2307 struct cmd_config_threshold {
2308         cmdline_fixed_string_t port;
2309         cmdline_fixed_string_t keyword;
2310         cmdline_fixed_string_t all;
2311         cmdline_fixed_string_t name;
2312         uint16_t value;
2313 };
2314
2315 static void
2316 cmd_config_threshold_parsed(void *parsed_result,
2317                         __attribute__((unused)) struct cmdline *cl,
2318                         __attribute__((unused)) void *data)
2319 {
2320         struct cmd_config_threshold *res = parsed_result;
2321
2322         if (!all_ports_stopped()) {
2323                 printf("Please stop all ports first\n");
2324                 return;
2325         }
2326
2327         if (!strcmp(res->name, "txfreet"))
2328                 tx_free_thresh = res->value;
2329         else if (!strcmp(res->name, "txrst"))
2330                 tx_rs_thresh = res->value;
2331         else if (!strcmp(res->name, "rxfreet"))
2332                 rx_free_thresh = res->value;
2333         else {
2334                 printf("Unknown parameter\n");
2335                 return;
2336         }
2337
2338         init_port_config();
2339
2340         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2341 }
2342
2343 cmdline_parse_token_string_t cmd_config_threshold_port =
2344         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2345 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2346         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2347                                                                 "config");
2348 cmdline_parse_token_string_t cmd_config_threshold_all =
2349         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2350 cmdline_parse_token_string_t cmd_config_threshold_name =
2351         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2352                                                 "txfreet#txrst#rxfreet");
2353 cmdline_parse_token_num_t cmd_config_threshold_value =
2354         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2355
2356 cmdline_parse_inst_t cmd_config_threshold = {
2357         .f = cmd_config_threshold_parsed,
2358         .data = NULL,
2359         .help_str = "port config all txfreet|txrst|rxfreet value",
2360         .tokens = {
2361                 (void *)&cmd_config_threshold_port,
2362                 (void *)&cmd_config_threshold_keyword,
2363                 (void *)&cmd_config_threshold_all,
2364                 (void *)&cmd_config_threshold_name,
2365                 (void *)&cmd_config_threshold_value,
2366                 NULL,
2367         },
2368 };
2369
2370 /* *** stop *** */
2371 struct cmd_stop_result {
2372         cmdline_fixed_string_t stop;
2373 };
2374
2375 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2376                             __attribute__((unused)) struct cmdline *cl,
2377                             __attribute__((unused)) void *data)
2378 {
2379         stop_packet_forwarding();
2380 }
2381
2382 cmdline_parse_token_string_t cmd_stop_stop =
2383         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2384
2385 cmdline_parse_inst_t cmd_stop = {
2386         .f = cmd_stop_parsed,
2387         .data = NULL,
2388         .help_str = "stop - stop packet forwarding",
2389         .tokens = {
2390                 (void *)&cmd_stop_stop,
2391                 NULL,
2392         },
2393 };
2394
2395 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2396
2397 unsigned int
2398 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2399                 unsigned int *parsed_items, int check_unique_values)
2400 {
2401         unsigned int nb_item;
2402         unsigned int value;
2403         unsigned int i;
2404         unsigned int j;
2405         int value_ok;
2406         char c;
2407
2408         /*
2409          * First parse all items in the list and store their value.
2410          */
2411         value = 0;
2412         nb_item = 0;
2413         value_ok = 0;
2414         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2415                 c = str[i];
2416                 if ((c >= '0') && (c <= '9')) {
2417                         value = (unsigned int) (value * 10 + (c - '0'));
2418                         value_ok = 1;
2419                         continue;
2420                 }
2421                 if (c != ',') {
2422                         printf("character %c is not a decimal digit\n", c);
2423                         return 0;
2424                 }
2425                 if (! value_ok) {
2426                         printf("No valid value before comma\n");
2427                         return 0;
2428                 }
2429                 if (nb_item < max_items) {
2430                         parsed_items[nb_item] = value;
2431                         value_ok = 0;
2432                         value = 0;
2433                 }
2434                 nb_item++;
2435         }
2436         if (nb_item >= max_items) {
2437                 printf("Number of %s = %u > %u (maximum items)\n",
2438                        item_name, nb_item + 1, max_items);
2439                 return 0;
2440         }
2441         parsed_items[nb_item++] = value;
2442         if (! check_unique_values)
2443                 return nb_item;
2444
2445         /*
2446          * Then, check that all values in the list are differents.
2447          * No optimization here...
2448          */
2449         for (i = 0; i < nb_item; i++) {
2450                 for (j = i + 1; j < nb_item; j++) {
2451                         if (parsed_items[j] == parsed_items[i]) {
2452                                 printf("duplicated %s %u at index %u and %u\n",
2453                                        item_name, parsed_items[i], i, j);
2454                                 return 0;
2455                         }
2456                 }
2457         }
2458         return nb_item;
2459 }
2460
2461 struct cmd_set_list_result {
2462         cmdline_fixed_string_t cmd_keyword;
2463         cmdline_fixed_string_t list_name;
2464         cmdline_fixed_string_t list_of_items;
2465 };
2466
2467 static void cmd_set_list_parsed(void *parsed_result,
2468                                 __attribute__((unused)) struct cmdline *cl,
2469                                 __attribute__((unused)) void *data)
2470 {
2471         struct cmd_set_list_result *res;
2472         union {
2473                 unsigned int lcorelist[RTE_MAX_LCORE];
2474                 unsigned int portlist[RTE_MAX_ETHPORTS];
2475         } parsed_items;
2476         unsigned int nb_item;
2477
2478         if (test_done == 0) {
2479                 printf("Please stop forwarding first\n");
2480                 return;
2481         }
2482
2483         res = parsed_result;
2484         if (!strcmp(res->list_name, "corelist")) {
2485                 nb_item = parse_item_list(res->list_of_items, "core",
2486                                           RTE_MAX_LCORE,
2487                                           parsed_items.lcorelist, 1);
2488                 if (nb_item > 0)
2489                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2490                 return;
2491         }
2492         if (!strcmp(res->list_name, "portlist")) {
2493                 nb_item = parse_item_list(res->list_of_items, "port",
2494                                           RTE_MAX_ETHPORTS,
2495                                           parsed_items.portlist, 1);
2496                 if (nb_item > 0)
2497                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2498         }
2499 }
2500
2501 cmdline_parse_token_string_t cmd_set_list_keyword =
2502         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2503                                  "set");
2504 cmdline_parse_token_string_t cmd_set_list_name =
2505         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2506                                  "corelist#portlist");
2507 cmdline_parse_token_string_t cmd_set_list_of_items =
2508         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2509                                  NULL);
2510
2511 cmdline_parse_inst_t cmd_set_fwd_list = {
2512         .f = cmd_set_list_parsed,
2513         .data = NULL,
2514         .help_str = "set corelist|portlist x[,y]*",
2515         .tokens = {
2516                 (void *)&cmd_set_list_keyword,
2517                 (void *)&cmd_set_list_name,
2518                 (void *)&cmd_set_list_of_items,
2519                 NULL,
2520         },
2521 };
2522
2523 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2524
2525 struct cmd_setmask_result {
2526         cmdline_fixed_string_t set;
2527         cmdline_fixed_string_t mask;
2528         uint64_t hexavalue;
2529 };
2530
2531 static void cmd_set_mask_parsed(void *parsed_result,
2532                                 __attribute__((unused)) struct cmdline *cl,
2533                                 __attribute__((unused)) void *data)
2534 {
2535         struct cmd_setmask_result *res = parsed_result;
2536
2537         if (test_done == 0) {
2538                 printf("Please stop forwarding first\n");
2539                 return;
2540         }
2541         if (!strcmp(res->mask, "coremask"))
2542                 set_fwd_lcores_mask(res->hexavalue);
2543         else if (!strcmp(res->mask, "portmask"))
2544                 set_fwd_ports_mask(res->hexavalue);
2545 }
2546
2547 cmdline_parse_token_string_t cmd_setmask_set =
2548         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2549 cmdline_parse_token_string_t cmd_setmask_mask =
2550         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2551                                  "coremask#portmask");
2552 cmdline_parse_token_num_t cmd_setmask_value =
2553         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2554
2555 cmdline_parse_inst_t cmd_set_fwd_mask = {
2556         .f = cmd_set_mask_parsed,
2557         .data = NULL,
2558         .help_str = "set coremask|portmask hexadecimal value",
2559         .tokens = {
2560                 (void *)&cmd_setmask_set,
2561                 (void *)&cmd_setmask_mask,
2562                 (void *)&cmd_setmask_value,
2563                 NULL,
2564         },
2565 };
2566
2567 /*
2568  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2569  */
2570 struct cmd_set_result {
2571         cmdline_fixed_string_t set;
2572         cmdline_fixed_string_t what;
2573         uint16_t value;
2574 };
2575
2576 static void cmd_set_parsed(void *parsed_result,
2577                            __attribute__((unused)) struct cmdline *cl,
2578                            __attribute__((unused)) void *data)
2579 {
2580         struct cmd_set_result *res = parsed_result;
2581         if (!strcmp(res->what, "nbport"))
2582                 set_fwd_ports_number(res->value);
2583         else if (!strcmp(res->what, "nbcore"))
2584                 set_fwd_lcores_number(res->value);
2585         else if (!strcmp(res->what, "burst"))
2586                 set_nb_pkt_per_burst(res->value);
2587         else if (!strcmp(res->what, "verbose"))
2588                 set_verbose_level(res->value);
2589 }
2590
2591 cmdline_parse_token_string_t cmd_set_set =
2592         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2593 cmdline_parse_token_string_t cmd_set_what =
2594         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2595                                  "nbport#nbcore#burst#verbose");
2596 cmdline_parse_token_num_t cmd_set_value =
2597         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2598
2599 cmdline_parse_inst_t cmd_set_numbers = {
2600         .f = cmd_set_parsed,
2601         .data = NULL,
2602         .help_str = "set nbport|nbcore|burst|verbose value",
2603         .tokens = {
2604                 (void *)&cmd_set_set,
2605                 (void *)&cmd_set_what,
2606                 (void *)&cmd_set_value,
2607                 NULL,
2608         },
2609 };
2610
2611 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2612
2613 struct cmd_set_txpkts_result {
2614         cmdline_fixed_string_t cmd_keyword;
2615         cmdline_fixed_string_t txpkts;
2616         cmdline_fixed_string_t seg_lengths;
2617 };
2618
2619 static void
2620 cmd_set_txpkts_parsed(void *parsed_result,
2621                       __attribute__((unused)) struct cmdline *cl,
2622                       __attribute__((unused)) void *data)
2623 {
2624         struct cmd_set_txpkts_result *res;
2625         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2626         unsigned int nb_segs;
2627
2628         res = parsed_result;
2629         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2630                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2631         if (nb_segs > 0)
2632                 set_tx_pkt_segments(seg_lengths, nb_segs);
2633 }
2634
2635 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2636         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2637                                  cmd_keyword, "set");
2638 cmdline_parse_token_string_t cmd_set_txpkts_name =
2639         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2640                                  txpkts, "txpkts");
2641 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2642         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2643                                  seg_lengths, NULL);
2644
2645 cmdline_parse_inst_t cmd_set_txpkts = {
2646         .f = cmd_set_txpkts_parsed,
2647         .data = NULL,
2648         .help_str = "set txpkts x[,y]*",
2649         .tokens = {
2650                 (void *)&cmd_set_txpkts_keyword,
2651                 (void *)&cmd_set_txpkts_name,
2652                 (void *)&cmd_set_txpkts_lengths,
2653                 NULL,
2654         },
2655 };
2656
2657 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2658
2659 struct cmd_set_txsplit_result {
2660         cmdline_fixed_string_t cmd_keyword;
2661         cmdline_fixed_string_t txsplit;
2662         cmdline_fixed_string_t mode;
2663 };
2664
2665 static void
2666 cmd_set_txsplit_parsed(void *parsed_result,
2667                       __attribute__((unused)) struct cmdline *cl,
2668                       __attribute__((unused)) void *data)
2669 {
2670         struct cmd_set_txsplit_result *res;
2671
2672         res = parsed_result;
2673         set_tx_pkt_split(res->mode);
2674 }
2675
2676 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2677         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2678                                  cmd_keyword, "set");
2679 cmdline_parse_token_string_t cmd_set_txsplit_name =
2680         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2681                                  txsplit, "txsplit");
2682 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2683         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2684                                  mode, NULL);
2685
2686 cmdline_parse_inst_t cmd_set_txsplit = {
2687         .f = cmd_set_txsplit_parsed,
2688         .data = NULL,
2689         .help_str = "set txsplit on|off|rand",
2690         .tokens = {
2691                 (void *)&cmd_set_txsplit_keyword,
2692                 (void *)&cmd_set_txsplit_name,
2693                 (void *)&cmd_set_txsplit_mode,
2694                 NULL,
2695         },
2696 };
2697
2698 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2699 struct cmd_rx_vlan_filter_all_result {
2700         cmdline_fixed_string_t rx_vlan;
2701         cmdline_fixed_string_t what;
2702         cmdline_fixed_string_t all;
2703         uint8_t port_id;
2704 };
2705
2706 static void
2707 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2708                               __attribute__((unused)) struct cmdline *cl,
2709                               __attribute__((unused)) void *data)
2710 {
2711         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2712
2713         if (!strcmp(res->what, "add"))
2714                 rx_vlan_all_filter_set(res->port_id, 1);
2715         else
2716                 rx_vlan_all_filter_set(res->port_id, 0);
2717 }
2718
2719 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2720         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2721                                  rx_vlan, "rx_vlan");
2722 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2723         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2724                                  what, "add#rm");
2725 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2726         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2727                                  all, "all");
2728 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2729         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2730                               port_id, UINT8);
2731
2732 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2733         .f = cmd_rx_vlan_filter_all_parsed,
2734         .data = NULL,
2735         .help_str = "add/remove all identifiers to/from the set of VLAN "
2736         "Identifiers filtered by a port",
2737         .tokens = {
2738                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2739                 (void *)&cmd_rx_vlan_filter_all_what,
2740                 (void *)&cmd_rx_vlan_filter_all_all,
2741                 (void *)&cmd_rx_vlan_filter_all_portid,
2742                 NULL,
2743         },
2744 };
2745
2746 /* *** VLAN OFFLOAD SET ON A PORT *** */
2747 struct cmd_vlan_offload_result {
2748         cmdline_fixed_string_t vlan;
2749         cmdline_fixed_string_t set;
2750         cmdline_fixed_string_t what;
2751         cmdline_fixed_string_t on;
2752         cmdline_fixed_string_t port_id;
2753 };
2754
2755 static void
2756 cmd_vlan_offload_parsed(void *parsed_result,
2757                           __attribute__((unused)) struct cmdline *cl,
2758                           __attribute__((unused)) void *data)
2759 {
2760         int on;
2761         struct cmd_vlan_offload_result *res = parsed_result;
2762         char *str;
2763         int i, len = 0;
2764         portid_t port_id = 0;
2765         unsigned int tmp;
2766
2767         str = res->port_id;
2768         len = strnlen(str, STR_TOKEN_SIZE);
2769         i = 0;
2770         /* Get port_id first */
2771         while(i < len){
2772                 if(str[i] == ',')
2773                         break;
2774
2775                 i++;
2776         }
2777         str[i]='\0';
2778         tmp = strtoul(str, NULL, 0);
2779         /* If port_id greater that what portid_t can represent, return */
2780         if(tmp >= RTE_MAX_ETHPORTS)
2781                 return;
2782         port_id = (portid_t)tmp;
2783
2784         if (!strcmp(res->on, "on"))
2785                 on = 1;
2786         else
2787                 on = 0;
2788
2789         if (!strcmp(res->what, "strip"))
2790                 rx_vlan_strip_set(port_id,  on);
2791         else if(!strcmp(res->what, "stripq")){
2792                 uint16_t queue_id = 0;
2793
2794                 /* No queue_id, return */
2795                 if(i + 1 >= len) {
2796                         printf("must specify (port,queue_id)\n");
2797                         return;
2798                 }
2799                 tmp = strtoul(str + i + 1, NULL, 0);
2800                 /* If queue_id greater that what 16-bits can represent, return */
2801                 if(tmp > 0xffff)
2802                         return;
2803
2804                 queue_id = (uint16_t)tmp;
2805                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2806         }
2807         else if (!strcmp(res->what, "filter"))
2808                 rx_vlan_filter_set(port_id, on);
2809         else
2810                 vlan_extend_set(port_id, on);
2811
2812         return;
2813 }
2814
2815 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2816         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2817                                  vlan, "vlan");
2818 cmdline_parse_token_string_t cmd_vlan_offload_set =
2819         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2820                                  set, "set");
2821 cmdline_parse_token_string_t cmd_vlan_offload_what =
2822         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2823                                  what, "strip#filter#qinq#stripq");
2824 cmdline_parse_token_string_t cmd_vlan_offload_on =
2825         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2826                               on, "on#off");
2827 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2828         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2829                               port_id, NULL);
2830
2831 cmdline_parse_inst_t cmd_vlan_offload = {
2832         .f = cmd_vlan_offload_parsed,
2833         .data = NULL,
2834         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2835         " qinq(extended) for both rx/tx sides ",
2836         .tokens = {
2837                 (void *)&cmd_vlan_offload_vlan,
2838                 (void *)&cmd_vlan_offload_set,
2839                 (void *)&cmd_vlan_offload_what,
2840                 (void *)&cmd_vlan_offload_on,
2841                 (void *)&cmd_vlan_offload_portid,
2842                 NULL,
2843         },
2844 };
2845
2846 /* *** VLAN TPID SET ON A PORT *** */
2847 struct cmd_vlan_tpid_result {
2848         cmdline_fixed_string_t vlan;
2849         cmdline_fixed_string_t set;
2850         cmdline_fixed_string_t what;
2851         uint16_t tp_id;
2852         uint8_t port_id;
2853 };
2854
2855 static void
2856 cmd_vlan_tpid_parsed(void *parsed_result,
2857                           __attribute__((unused)) struct cmdline *cl,
2858                           __attribute__((unused)) void *data)
2859 {
2860         struct cmd_vlan_tpid_result *res = parsed_result;
2861         vlan_tpid_set(res->port_id, res->tp_id);
2862         return;
2863 }
2864
2865 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2866         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2867                                  vlan, "vlan");
2868 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2869         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2870                                  set, "set");
2871 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2872         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2873                                  what, "tpid");
2874 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2875         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2876                               tp_id, UINT16);
2877 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2878         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2879                               port_id, UINT8);
2880
2881 cmdline_parse_inst_t cmd_vlan_tpid = {
2882         .f = cmd_vlan_tpid_parsed,
2883         .data = NULL,
2884         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2885         .tokens = {
2886                 (void *)&cmd_vlan_tpid_vlan,
2887                 (void *)&cmd_vlan_tpid_set,
2888                 (void *)&cmd_vlan_tpid_what,
2889                 (void *)&cmd_vlan_tpid_tpid,
2890                 (void *)&cmd_vlan_tpid_portid,
2891                 NULL,
2892         },
2893 };
2894
2895 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2896 struct cmd_rx_vlan_filter_result {
2897         cmdline_fixed_string_t rx_vlan;
2898         cmdline_fixed_string_t what;
2899         uint16_t vlan_id;
2900         uint8_t port_id;
2901 };
2902
2903 static void
2904 cmd_rx_vlan_filter_parsed(void *parsed_result,
2905                           __attribute__((unused)) struct cmdline *cl,
2906                           __attribute__((unused)) void *data)
2907 {
2908         struct cmd_rx_vlan_filter_result *res = parsed_result;
2909
2910         if (!strcmp(res->what, "add"))
2911                 rx_vft_set(res->port_id, res->vlan_id, 1);
2912         else
2913                 rx_vft_set(res->port_id, res->vlan_id, 0);
2914 }
2915
2916 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2917         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2918                                  rx_vlan, "rx_vlan");
2919 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2920         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2921                                  what, "add#rm");
2922 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2923         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2924                               vlan_id, UINT16);
2925 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2926         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2927                               port_id, UINT8);
2928
2929 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2930         .f = cmd_rx_vlan_filter_parsed,
2931         .data = NULL,
2932         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2933         "Identifiers filtered by a port",
2934         .tokens = {
2935                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2936                 (void *)&cmd_rx_vlan_filter_what,
2937                 (void *)&cmd_rx_vlan_filter_vlanid,
2938                 (void *)&cmd_rx_vlan_filter_portid,
2939                 NULL,
2940         },
2941 };
2942
2943 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2944 struct cmd_tx_vlan_set_result {
2945         cmdline_fixed_string_t tx_vlan;
2946         cmdline_fixed_string_t set;
2947         uint8_t port_id;
2948         uint16_t vlan_id;
2949 };
2950
2951 static void
2952 cmd_tx_vlan_set_parsed(void *parsed_result,
2953                        __attribute__((unused)) struct cmdline *cl,
2954                        __attribute__((unused)) void *data)
2955 {
2956         struct cmd_tx_vlan_set_result *res = parsed_result;
2957
2958         tx_vlan_set(res->port_id, res->vlan_id);
2959 }
2960
2961 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2962         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2963                                  tx_vlan, "tx_vlan");
2964 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2965         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2966                                  set, "set");
2967 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2968         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2969                               port_id, UINT8);
2970 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2971         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2972                               vlan_id, UINT16);
2973
2974 cmdline_parse_inst_t cmd_tx_vlan_set = {
2975         .f = cmd_tx_vlan_set_parsed,
2976         .data = NULL,
2977         .help_str = "enable hardware insertion of a single VLAN header "
2978                 "with a given TAG Identifier in packets sent on a port",
2979         .tokens = {
2980                 (void *)&cmd_tx_vlan_set_tx_vlan,
2981                 (void *)&cmd_tx_vlan_set_set,
2982                 (void *)&cmd_tx_vlan_set_portid,
2983                 (void *)&cmd_tx_vlan_set_vlanid,
2984                 NULL,
2985         },
2986 };
2987
2988 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
2989 struct cmd_tx_vlan_set_qinq_result {
2990         cmdline_fixed_string_t tx_vlan;
2991         cmdline_fixed_string_t set;
2992         uint8_t port_id;
2993         uint16_t vlan_id;
2994         uint16_t vlan_id_outer;
2995 };
2996
2997 static void
2998 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
2999                             __attribute__((unused)) struct cmdline *cl,
3000                             __attribute__((unused)) void *data)
3001 {
3002         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3003
3004         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3005 }
3006
3007 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3008         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3009                 tx_vlan, "tx_vlan");
3010 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3011         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3012                 set, "set");
3013 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3014         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3015                 port_id, UINT8);
3016 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3017         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3018                 vlan_id, UINT16);
3019 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3020         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3021                 vlan_id_outer, UINT16);
3022
3023 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3024         .f = cmd_tx_vlan_set_qinq_parsed,
3025         .data = NULL,
3026         .help_str = "enable hardware insertion of double VLAN header "
3027                 "with given TAG Identifiers in packets sent on a port",
3028         .tokens = {
3029                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3030                 (void *)&cmd_tx_vlan_set_qinq_set,
3031                 (void *)&cmd_tx_vlan_set_qinq_portid,
3032                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3033                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3034                 NULL,
3035         },
3036 };
3037
3038 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3039 struct cmd_tx_vlan_set_pvid_result {
3040         cmdline_fixed_string_t tx_vlan;
3041         cmdline_fixed_string_t set;
3042         cmdline_fixed_string_t pvid;
3043         uint8_t port_id;
3044         uint16_t vlan_id;
3045         cmdline_fixed_string_t mode;
3046 };
3047
3048 static void
3049 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3050                             __attribute__((unused)) struct cmdline *cl,
3051                             __attribute__((unused)) void *data)
3052 {
3053         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3054
3055         if (strcmp(res->mode, "on") == 0)
3056                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3057         else
3058                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3059 }
3060
3061 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3062         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3063                                  tx_vlan, "tx_vlan");
3064 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3065         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3066                                  set, "set");
3067 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3068         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3069                                  pvid, "pvid");
3070 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3071         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3072                              port_id, UINT8);
3073 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3075                               vlan_id, UINT16);
3076 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3077         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3078                                  mode, "on#off");
3079
3080 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3081         .f = cmd_tx_vlan_set_pvid_parsed,
3082         .data = NULL,
3083         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
3084         .tokens = {
3085                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3086                 (void *)&cmd_tx_vlan_set_pvid_set,
3087                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3088                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3089                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3090                 (void *)&cmd_tx_vlan_set_pvid_mode,
3091                 NULL,
3092         },
3093 };
3094
3095 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3096 struct cmd_tx_vlan_reset_result {
3097         cmdline_fixed_string_t tx_vlan;
3098         cmdline_fixed_string_t reset;
3099         uint8_t port_id;
3100 };
3101
3102 static void
3103 cmd_tx_vlan_reset_parsed(void *parsed_result,
3104                          __attribute__((unused)) struct cmdline *cl,
3105                          __attribute__((unused)) void *data)
3106 {
3107         struct cmd_tx_vlan_reset_result *res = parsed_result;
3108
3109         tx_vlan_reset(res->port_id);
3110 }
3111
3112 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3113         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3114                                  tx_vlan, "tx_vlan");
3115 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3116         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3117                                  reset, "reset");
3118 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3119         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3120                               port_id, UINT8);
3121
3122 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3123         .f = cmd_tx_vlan_reset_parsed,
3124         .data = NULL,
3125         .help_str = "disable hardware insertion of a VLAN header in packets "
3126         "sent on a port",
3127         .tokens = {
3128                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3129                 (void *)&cmd_tx_vlan_reset_reset,
3130                 (void *)&cmd_tx_vlan_reset_portid,
3131                 NULL,
3132         },
3133 };
3134
3135
3136 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3137 struct cmd_csum_result {
3138         cmdline_fixed_string_t csum;
3139         cmdline_fixed_string_t mode;
3140         cmdline_fixed_string_t proto;
3141         cmdline_fixed_string_t hwsw;
3142         uint8_t port_id;
3143 };
3144
3145 static void
3146 csum_show(int port_id)
3147 {
3148         struct rte_eth_dev_info dev_info;
3149         uint16_t ol_flags;
3150
3151         ol_flags = ports[port_id].tx_ol_flags;
3152         printf("Parse tunnel is %s\n",
3153                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3154         printf("IP checksum offload is %s\n",
3155                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3156         printf("UDP checksum offload is %s\n",
3157                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3158         printf("TCP checksum offload is %s\n",
3159                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3160         printf("SCTP checksum offload is %s\n",
3161                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3162         printf("Outer-Ip checksum offload is %s\n",
3163                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3164
3165         /* display warnings if configuration is not supported by the NIC */
3166         rte_eth_dev_info_get(port_id, &dev_info);
3167         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3168                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3169                 printf("Warning: hardware IP checksum enabled but not "
3170                         "supported by port %d\n", port_id);
3171         }
3172         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3173                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3174                 printf("Warning: hardware UDP checksum enabled but not "
3175                         "supported by port %d\n", port_id);
3176         }
3177         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3178                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3179                 printf("Warning: hardware TCP checksum enabled but not "
3180                         "supported by port %d\n", port_id);
3181         }
3182         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3183                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3184                 printf("Warning: hardware SCTP checksum enabled but not "
3185                         "supported by port %d\n", port_id);
3186         }
3187         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3188                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3189                 printf("Warning: hardware outer IP checksum enabled but not "
3190                         "supported by port %d\n", port_id);
3191         }
3192 }
3193
3194 static void
3195 cmd_csum_parsed(void *parsed_result,
3196                        __attribute__((unused)) struct cmdline *cl,
3197                        __attribute__((unused)) void *data)
3198 {
3199         struct cmd_csum_result *res = parsed_result;
3200         int hw = 0;
3201         uint16_t mask = 0;
3202
3203         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3204                 printf("invalid port %d\n", res->port_id);
3205                 return;
3206         }
3207
3208         if (!strcmp(res->mode, "set")) {
3209
3210                 if (!strcmp(res->hwsw, "hw"))
3211                         hw = 1;
3212
3213                 if (!strcmp(res->proto, "ip")) {
3214                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3215                 } else if (!strcmp(res->proto, "udp")) {
3216                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3217                 } else if (!strcmp(res->proto, "tcp")) {
3218                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3219                 } else if (!strcmp(res->proto, "sctp")) {
3220                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3221                 } else if (!strcmp(res->proto, "outer-ip")) {
3222                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3223                 }
3224
3225                 if (hw)
3226                         ports[res->port_id].tx_ol_flags |= mask;
3227                 else
3228                         ports[res->port_id].tx_ol_flags &= (~mask);
3229         }
3230         csum_show(res->port_id);
3231 }
3232
3233 cmdline_parse_token_string_t cmd_csum_csum =
3234         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3235                                 csum, "csum");
3236 cmdline_parse_token_string_t cmd_csum_mode =
3237         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3238                                 mode, "set");
3239 cmdline_parse_token_string_t cmd_csum_proto =
3240         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3241                                 proto, "ip#tcp#udp#sctp#outer-ip");
3242 cmdline_parse_token_string_t cmd_csum_hwsw =
3243         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3244                                 hwsw, "hw#sw");
3245 cmdline_parse_token_num_t cmd_csum_portid =
3246         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3247                                 port_id, UINT8);
3248
3249 cmdline_parse_inst_t cmd_csum_set = {
3250         .f = cmd_csum_parsed,
3251         .data = NULL,
3252         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
3253                 "using csum forward engine: csum set ip|tcp|udp|sctp|outer-ip hw|sw <port>",
3254         .tokens = {
3255                 (void *)&cmd_csum_csum,
3256                 (void *)&cmd_csum_mode,
3257                 (void *)&cmd_csum_proto,
3258                 (void *)&cmd_csum_hwsw,
3259                 (void *)&cmd_csum_portid,
3260                 NULL,
3261         },
3262 };
3263
3264 cmdline_parse_token_string_t cmd_csum_mode_show =
3265         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3266                                 mode, "show");
3267
3268 cmdline_parse_inst_t cmd_csum_show = {
3269         .f = cmd_csum_parsed,
3270         .data = NULL,
3271         .help_str = "show checksum offload configuration: csum show <port>",
3272         .tokens = {
3273                 (void *)&cmd_csum_csum,
3274                 (void *)&cmd_csum_mode_show,
3275                 (void *)&cmd_csum_portid,
3276                 NULL,
3277         },
3278 };
3279
3280 /* Enable/disable tunnel parsing */
3281 struct cmd_csum_tunnel_result {
3282         cmdline_fixed_string_t csum;
3283         cmdline_fixed_string_t parse;
3284         cmdline_fixed_string_t onoff;
3285         uint8_t port_id;
3286 };
3287
3288 static void
3289 cmd_csum_tunnel_parsed(void *parsed_result,
3290                        __attribute__((unused)) struct cmdline *cl,
3291                        __attribute__((unused)) void *data)
3292 {
3293         struct cmd_csum_tunnel_result *res = parsed_result;
3294
3295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3296                 return;
3297
3298         if (!strcmp(res->onoff, "on"))
3299                 ports[res->port_id].tx_ol_flags |=
3300                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3301         else
3302                 ports[res->port_id].tx_ol_flags &=
3303                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3304
3305         csum_show(res->port_id);
3306 }
3307
3308 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3309         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3310                                 csum, "csum");
3311 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3312         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3313                                 parse, "parse_tunnel");
3314 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3315         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3316                                 onoff, "on#off");
3317 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3318         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3319                                 port_id, UINT8);
3320
3321 cmdline_parse_inst_t cmd_csum_tunnel = {
3322         .f = cmd_csum_tunnel_parsed,
3323         .data = NULL,
3324         .help_str = "enable/disable parsing of tunnels for csum engine: "
3325         "csum parse_tunnel on|off <tx-port>",
3326         .tokens = {
3327                 (void *)&cmd_csum_tunnel_csum,
3328                 (void *)&cmd_csum_tunnel_parse,
3329                 (void *)&cmd_csum_tunnel_onoff,
3330                 (void *)&cmd_csum_tunnel_portid,
3331                 NULL,
3332         },
3333 };
3334
3335 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3336 struct cmd_tso_set_result {
3337         cmdline_fixed_string_t tso;
3338         cmdline_fixed_string_t mode;
3339         uint16_t tso_segsz;
3340         uint8_t port_id;
3341 };
3342
3343 static void
3344 cmd_tso_set_parsed(void *parsed_result,
3345                        __attribute__((unused)) struct cmdline *cl,
3346                        __attribute__((unused)) void *data)
3347 {
3348         struct cmd_tso_set_result *res = parsed_result;
3349         struct rte_eth_dev_info dev_info;
3350
3351         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3352                 return;
3353
3354         if (!strcmp(res->mode, "set"))
3355                 ports[res->port_id].tso_segsz = res->tso_segsz;
3356
3357         if (ports[res->port_id].tso_segsz == 0)
3358                 printf("TSO is disabled\n");
3359         else
3360                 printf("TSO segment size is %d\n",
3361                         ports[res->port_id].tso_segsz);
3362
3363         /* display warnings if configuration is not supported by the NIC */
3364         rte_eth_dev_info_get(res->port_id, &dev_info);
3365         if ((ports[res->port_id].tso_segsz != 0) &&
3366                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3367                 printf("Warning: TSO enabled but not "
3368                         "supported by port %d\n", res->port_id);
3369         }
3370 }
3371
3372 cmdline_parse_token_string_t cmd_tso_set_tso =
3373         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3374                                 tso, "tso");
3375 cmdline_parse_token_string_t cmd_tso_set_mode =
3376         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3377                                 mode, "set");
3378 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3379         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3380                                 tso_segsz, UINT16);
3381 cmdline_parse_token_num_t cmd_tso_set_portid =
3382         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3383                                 port_id, UINT8);
3384
3385 cmdline_parse_inst_t cmd_tso_set = {
3386         .f = cmd_tso_set_parsed,
3387         .data = NULL,
3388         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3389         "tso set <tso_segsz> <port>",
3390         .tokens = {
3391                 (void *)&cmd_tso_set_tso,
3392                 (void *)&cmd_tso_set_mode,
3393                 (void *)&cmd_tso_set_tso_segsz,
3394                 (void *)&cmd_tso_set_portid,
3395                 NULL,
3396         },
3397 };
3398
3399 cmdline_parse_token_string_t cmd_tso_show_mode =
3400         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3401                                 mode, "show");
3402
3403
3404 cmdline_parse_inst_t cmd_tso_show = {
3405         .f = cmd_tso_set_parsed,
3406         .data = NULL,
3407         .help_str = "Show TSO segment size for csum engine: "
3408         "tso show <port>",
3409         .tokens = {
3410                 (void *)&cmd_tso_set_tso,
3411                 (void *)&cmd_tso_show_mode,
3412                 (void *)&cmd_tso_set_portid,
3413                 NULL,
3414         },
3415 };
3416
3417 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3418 struct cmd_set_flush_rx {
3419         cmdline_fixed_string_t set;
3420         cmdline_fixed_string_t flush_rx;
3421         cmdline_fixed_string_t mode;
3422 };
3423
3424 static void
3425 cmd_set_flush_rx_parsed(void *parsed_result,
3426                 __attribute__((unused)) struct cmdline *cl,
3427                 __attribute__((unused)) void *data)
3428 {
3429         struct cmd_set_flush_rx *res = parsed_result;
3430         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3431 }
3432
3433 cmdline_parse_token_string_t cmd_setflushrx_set =
3434         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3435                         set, "set");
3436 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3437         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3438                         flush_rx, "flush_rx");
3439 cmdline_parse_token_string_t cmd_setflushrx_mode =
3440         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3441                         mode, "on#off");
3442
3443
3444 cmdline_parse_inst_t cmd_set_flush_rx = {
3445         .f = cmd_set_flush_rx_parsed,
3446         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3447         .data = NULL,
3448         .tokens = {
3449                 (void *)&cmd_setflushrx_set,
3450                 (void *)&cmd_setflushrx_flush_rx,
3451                 (void *)&cmd_setflushrx_mode,
3452                 NULL,
3453         },
3454 };
3455
3456 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3457 struct cmd_set_link_check {
3458         cmdline_fixed_string_t set;
3459         cmdline_fixed_string_t link_check;
3460         cmdline_fixed_string_t mode;
3461 };
3462
3463 static void
3464 cmd_set_link_check_parsed(void *parsed_result,
3465                 __attribute__((unused)) struct cmdline *cl,
3466                 __attribute__((unused)) void *data)
3467 {
3468         struct cmd_set_link_check *res = parsed_result;
3469         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3470 }
3471
3472 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3473         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3474                         set, "set");
3475 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3476         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3477                         link_check, "link_check");
3478 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3479         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3480                         mode, "on#off");
3481
3482
3483 cmdline_parse_inst_t cmd_set_link_check = {
3484         .f = cmd_set_link_check_parsed,
3485         .help_str = "set link_check on|off: enable/disable link status check "
3486                     "when starting/stopping a port",
3487         .data = NULL,
3488         .tokens = {
3489                 (void *)&cmd_setlinkcheck_set,
3490                 (void *)&cmd_setlinkcheck_link_check,
3491                 (void *)&cmd_setlinkcheck_mode,
3492                 NULL,
3493         },
3494 };
3495
3496 #ifdef RTE_NIC_BYPASS
3497 /* *** SET NIC BYPASS MODE *** */
3498 struct cmd_set_bypass_mode_result {
3499         cmdline_fixed_string_t set;
3500         cmdline_fixed_string_t bypass;
3501         cmdline_fixed_string_t mode;
3502         cmdline_fixed_string_t value;
3503         uint8_t port_id;
3504 };
3505
3506 static void
3507 cmd_set_bypass_mode_parsed(void *parsed_result,
3508                 __attribute__((unused)) struct cmdline *cl,
3509                 __attribute__((unused)) void *data)
3510 {
3511         struct cmd_set_bypass_mode_result *res = parsed_result;
3512         portid_t port_id = res->port_id;
3513         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3514
3515         if (!bypass_is_supported(port_id))
3516                 return;
3517
3518         if (!strcmp(res->value, "bypass"))
3519                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3520         else if (!strcmp(res->value, "isolate"))
3521                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3522         else
3523                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3524
3525         /* Set the bypass mode for the relevant port. */
3526         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3527                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3528         }
3529 }
3530
3531 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3532         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3533                         set, "set");
3534 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3535         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3536                         bypass, "bypass");
3537 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3539                         mode, "mode");
3540 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3542                         value, "normal#bypass#isolate");
3543 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3544         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3545                                 port_id, UINT8);
3546
3547 cmdline_parse_inst_t cmd_set_bypass_mode = {
3548         .f = cmd_set_bypass_mode_parsed,
3549         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3550                     "Set the NIC bypass mode for port_id",
3551         .data = NULL,
3552         .tokens = {
3553                 (void *)&cmd_setbypass_mode_set,
3554                 (void *)&cmd_setbypass_mode_bypass,
3555                 (void *)&cmd_setbypass_mode_mode,
3556                 (void *)&cmd_setbypass_mode_value,
3557                 (void *)&cmd_setbypass_mode_port,
3558                 NULL,
3559         },
3560 };
3561
3562 /* *** SET NIC BYPASS EVENT *** */
3563 struct cmd_set_bypass_event_result {
3564         cmdline_fixed_string_t set;
3565         cmdline_fixed_string_t bypass;
3566         cmdline_fixed_string_t event;
3567         cmdline_fixed_string_t event_value;
3568         cmdline_fixed_string_t mode;
3569         cmdline_fixed_string_t mode_value;
3570         uint8_t port_id;
3571 };
3572
3573 static void
3574 cmd_set_bypass_event_parsed(void *parsed_result,
3575                 __attribute__((unused)) struct cmdline *cl,
3576                 __attribute__((unused)) void *data)
3577 {
3578         int32_t rc;
3579         struct cmd_set_bypass_event_result *res = parsed_result;
3580         portid_t port_id = res->port_id;
3581         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3582         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3583
3584         if (!bypass_is_supported(port_id))
3585                 return;
3586
3587         if (!strcmp(res->event_value, "timeout"))
3588                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3589         else if (!strcmp(res->event_value, "os_on"))
3590                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3591         else if (!strcmp(res->event_value, "os_off"))
3592                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3593         else if (!strcmp(res->event_value, "power_on"))
3594                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3595         else if (!strcmp(res->event_value, "power_off"))
3596                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3597         else
3598                 bypass_event = RTE_BYPASS_EVENT_NONE;
3599
3600         if (!strcmp(res->mode_value, "bypass"))
3601                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3602         else if (!strcmp(res->mode_value, "isolate"))
3603                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3604         else
3605                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3606
3607         /* Set the watchdog timeout. */
3608         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3609
3610                 rc = -EINVAL;
3611                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3612                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3613                                 bypass_timeout)) != 0) {
3614                         printf("Failed to set timeout value %u "
3615                                 "for port %d, errto code: %d.\n",
3616                                 bypass_timeout, port_id, rc);
3617                 }
3618         }
3619
3620         /* Set the bypass event to transition to bypass mode. */
3621         if (0 != rte_eth_dev_bypass_event_store(port_id,
3622                         bypass_event, bypass_mode)) {
3623                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3624         }
3625
3626 }
3627
3628 cmdline_parse_token_string_t cmd_setbypass_event_set =
3629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3630                         set, "set");
3631 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3633                         bypass, "bypass");
3634 cmdline_parse_token_string_t cmd_setbypass_event_event =
3635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3636                         event, "event");
3637 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3639                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3640 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3642                         mode, "mode");
3643 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3645                         mode_value, "normal#bypass#isolate");
3646 cmdline_parse_token_num_t cmd_setbypass_event_port =
3647         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3648                                 port_id, UINT8);
3649
3650 cmdline_parse_inst_t cmd_set_bypass_event = {
3651         .f = cmd_set_bypass_event_parsed,
3652         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3653                     "mode (normal|bypass|isolate) (port_id): "
3654                     "Set the NIC bypass event mode for port_id",
3655         .data = NULL,
3656         .tokens = {
3657                 (void *)&cmd_setbypass_event_set,
3658                 (void *)&cmd_setbypass_event_bypass,
3659                 (void *)&cmd_setbypass_event_event,
3660                 (void *)&cmd_setbypass_event_event_value,
3661                 (void *)&cmd_setbypass_event_mode,
3662                 (void *)&cmd_setbypass_event_mode_value,
3663                 (void *)&cmd_setbypass_event_port,
3664                 NULL,
3665         },
3666 };
3667
3668
3669 /* *** SET NIC BYPASS TIMEOUT *** */
3670 struct cmd_set_bypass_timeout_result {
3671         cmdline_fixed_string_t set;
3672         cmdline_fixed_string_t bypass;
3673         cmdline_fixed_string_t timeout;
3674         cmdline_fixed_string_t value;
3675 };
3676
3677 static void
3678 cmd_set_bypass_timeout_parsed(void *parsed_result,
3679                 __attribute__((unused)) struct cmdline *cl,
3680                 __attribute__((unused)) void *data)
3681 {
3682         struct cmd_set_bypass_timeout_result *res = parsed_result;
3683
3684         if (!strcmp(res->value, "1.5"))
3685                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3686         else if (!strcmp(res->value, "2"))
3687                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3688         else if (!strcmp(res->value, "3"))
3689                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3690         else if (!strcmp(res->value, "4"))
3691                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3692         else if (!strcmp(res->value, "8"))
3693                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3694         else if (!strcmp(res->value, "16"))
3695                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3696         else if (!strcmp(res->value, "32"))
3697                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3698         else
3699                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3700 }
3701
3702 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3703         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3704                         set, "set");
3705 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3707                         bypass, "bypass");
3708 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3709         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3710                         timeout, "timeout");
3711 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3713                         value, "0#1.5#2#3#4#8#16#32");
3714
3715 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3716         .f = cmd_set_bypass_timeout_parsed,
3717         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3718                     "Set the NIC bypass watchdog timeout",
3719         .data = NULL,
3720         .tokens = {
3721                 (void *)&cmd_setbypass_timeout_set,
3722                 (void *)&cmd_setbypass_timeout_bypass,
3723                 (void *)&cmd_setbypass_timeout_timeout,
3724                 (void *)&cmd_setbypass_timeout_value,
3725                 NULL,
3726         },
3727 };
3728
3729 /* *** SHOW NIC BYPASS MODE *** */
3730 struct cmd_show_bypass_config_result {
3731         cmdline_fixed_string_t show;
3732         cmdline_fixed_string_t bypass;
3733         cmdline_fixed_string_t config;
3734         uint8_t port_id;
3735 };
3736
3737 static void
3738 cmd_show_bypass_config_parsed(void *parsed_result,
3739                 __attribute__((unused)) struct cmdline *cl,
3740                 __attribute__((unused)) void *data)
3741 {
3742         struct cmd_show_bypass_config_result *res = parsed_result;
3743         uint32_t event_mode;
3744         uint32_t bypass_mode;
3745         portid_t port_id = res->port_id;
3746         uint32_t timeout = bypass_timeout;
3747         int i;
3748
3749         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3750                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3751         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3752                 {"UNKNOWN", "normal", "bypass", "isolate"};
3753         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3754                 "NONE",
3755                 "OS/board on",
3756                 "power supply on",
3757                 "OS/board off",
3758                 "power supply off",
3759                 "timeout"};
3760         int num_events = (sizeof events) / (sizeof events[0]);
3761
3762         if (!bypass_is_supported(port_id))
3763                 return;
3764
3765         /* Display the bypass mode.*/
3766         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3767                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3768                 return;
3769         }
3770         else {
3771                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3772                         bypass_mode = RTE_BYPASS_MODE_NONE;
3773
3774                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3775         }
3776
3777         /* Display the bypass timeout.*/
3778         if (!RTE_BYPASS_TMT_VALID(timeout))
3779                 timeout = RTE_BYPASS_TMT_OFF;
3780
3781         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3782
3783         /* Display the bypass events and associated modes. */
3784         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3785
3786                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3787                         printf("\tFailed to get bypass mode for event = %s\n",
3788                                 events[i]);
3789                 } else {
3790                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3791                                 event_mode = RTE_BYPASS_MODE_NONE;
3792
3793                         printf("\tbypass event: %-16s = %s\n", events[i],
3794                                 modes[event_mode]);
3795                 }
3796         }
3797 }
3798
3799 cmdline_parse_token_string_t cmd_showbypass_config_show =
3800         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3801                         show, "show");
3802 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3803         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3804                         bypass, "bypass");
3805 cmdline_parse_token_string_t cmd_showbypass_config_config =
3806         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3807                         config, "config");
3808 cmdline_parse_token_num_t cmd_showbypass_config_port =
3809         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3810                                 port_id, UINT8);
3811
3812 cmdline_parse_inst_t cmd_show_bypass_config = {
3813         .f = cmd_show_bypass_config_parsed,
3814         .help_str = "show bypass config (port_id): "
3815                     "Show the NIC bypass config for port_id",
3816         .data = NULL,
3817         .tokens = {
3818                 (void *)&cmd_showbypass_config_show,
3819                 (void *)&cmd_showbypass_config_bypass,
3820                 (void *)&cmd_showbypass_config_config,
3821                 (void *)&cmd_showbypass_config_port,
3822                 NULL,
3823         },
3824 };
3825 #endif
3826
3827 #ifdef RTE_LIBRTE_PMD_BOND
3828 /* *** SET BONDING MODE *** */
3829 struct cmd_set_bonding_mode_result {
3830         cmdline_fixed_string_t set;
3831         cmdline_fixed_string_t bonding;
3832         cmdline_fixed_string_t mode;
3833         uint8_t value;
3834         uint8_t port_id;
3835 };
3836
3837 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3838                 __attribute__((unused))  struct cmdline *cl,
3839                 __attribute__((unused)) void *data)
3840 {
3841         struct cmd_set_bonding_mode_result *res = parsed_result;
3842         portid_t port_id = res->port_id;
3843
3844         /* Set the bonding mode for the relevant port. */
3845         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3846                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3847 }
3848
3849 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3851                 set, "set");
3852 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3854                 bonding, "bonding");
3855 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3857                 mode, "mode");
3858 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3859 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3860                 value, UINT8);
3861 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3862 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3863                 port_id, UINT8);
3864
3865 cmdline_parse_inst_t cmd_set_bonding_mode = {
3866                 .f = cmd_set_bonding_mode_parsed,
3867                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3868                 .data = NULL,
3869                 .tokens = {
3870                                 (void *) &cmd_setbonding_mode_set,
3871                                 (void *) &cmd_setbonding_mode_bonding,
3872                                 (void *) &cmd_setbonding_mode_mode,
3873                                 (void *) &cmd_setbonding_mode_value,
3874                                 (void *) &cmd_setbonding_mode_port,
3875                                 NULL
3876                 }
3877 };
3878
3879 /* *** SET BALANCE XMIT POLICY *** */
3880 struct cmd_set_bonding_balance_xmit_policy_result {
3881         cmdline_fixed_string_t set;
3882         cmdline_fixed_string_t bonding;
3883         cmdline_fixed_string_t balance_xmit_policy;
3884         uint8_t port_id;
3885         cmdline_fixed_string_t policy;
3886 };
3887
3888 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3889                 __attribute__((unused))  struct cmdline *cl,
3890                 __attribute__((unused)) void *data)
3891 {
3892         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3893         portid_t port_id = res->port_id;
3894         uint8_t policy;
3895
3896         if (!strcmp(res->policy, "l2")) {
3897                 policy = BALANCE_XMIT_POLICY_LAYER2;
3898         } else if (!strcmp(res->policy, "l23")) {
3899                 policy = BALANCE_XMIT_POLICY_LAYER23;
3900         } else if (!strcmp(res->policy, "l34")) {
3901                 policy = BALANCE_XMIT_POLICY_LAYER34;
3902         } else {
3903                 printf("\t Invalid xmit policy selection");
3904                 return;
3905         }
3906
3907         /* Set the bonding mode for the relevant port. */
3908         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3909                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3910                                 port_id);
3911         }
3912 }
3913
3914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3916                 set, "set");
3917 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3919                 bonding, "bonding");
3920 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3922                 balance_xmit_policy, "balance_xmit_policy");
3923 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3924 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3925                 port_id, UINT8);
3926 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3928                 policy, "l2#l23#l34");
3929
3930 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3931                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3932                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3933                 .data = NULL,
3934                 .tokens = {
3935                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3936                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3937                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3938                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3939                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3940                                 NULL
3941                 }
3942 };
3943
3944 /* *** SHOW NIC BONDING CONFIGURATION *** */
3945 struct cmd_show_bonding_config_result {
3946         cmdline_fixed_string_t show;
3947         cmdline_fixed_string_t bonding;
3948         cmdline_fixed_string_t config;
3949         uint8_t port_id;
3950 };
3951
3952 static void cmd_show_bonding_config_parsed(void *parsed_result,
3953                 __attribute__((unused))  struct cmdline *cl,
3954                 __attribute__((unused)) void *data)
3955 {
3956         struct cmd_show_bonding_config_result *res = parsed_result;
3957         int bonding_mode;
3958         uint8_t slaves[RTE_MAX_ETHPORTS];
3959         int num_slaves, num_active_slaves;
3960         int primary_id;
3961         int i;
3962         portid_t port_id = res->port_id;
3963
3964         /* Display the bonding mode.*/
3965         bonding_mode = rte_eth_bond_mode_get(port_id);
3966         if (bonding_mode < 0) {
3967                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3968                 return;
3969         } else
3970                 printf("\tBonding mode: %d\n", bonding_mode);
3971
3972         if (bonding_mode == BONDING_MODE_BALANCE) {
3973                 int balance_xmit_policy;
3974
3975                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3976                 if (balance_xmit_policy < 0) {
3977                         printf("\tFailed to get balance xmit policy for port = %d\n",
3978                                         port_id);
3979                         return;
3980                 } else {
3981                         printf("\tBalance Xmit Policy: ");
3982
3983                         switch (balance_xmit_policy) {
3984                         case BALANCE_XMIT_POLICY_LAYER2:
3985                                 printf("BALANCE_XMIT_POLICY_LAYER2");
3986                                 break;
3987                         case BALANCE_XMIT_POLICY_LAYER23:
3988                                 printf("BALANCE_XMIT_POLICY_LAYER23");
3989                                 break;
3990                         case BALANCE_XMIT_POLICY_LAYER34:
3991                                 printf("BALANCE_XMIT_POLICY_LAYER34");
3992                                 break;
3993                         }
3994                         printf("\n");
3995                 }
3996         }
3997
3998         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
3999
4000         if (num_slaves < 0) {
4001                 printf("\tFailed to get slave list for port = %d\n", port_id);
4002                 return;
4003         }
4004         if (num_slaves > 0) {
4005                 printf("\tSlaves (%d): [", num_slaves);
4006                 for (i = 0; i < num_slaves - 1; i++)
4007                         printf("%d ", slaves[i]);
4008
4009                 printf("%d]\n", slaves[num_slaves - 1]);
4010         } else {
4011                 printf("\tSlaves: []\n");
4012
4013         }
4014
4015         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4016                         RTE_MAX_ETHPORTS);
4017
4018         if (num_active_slaves < 0) {
4019                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4020                 return;
4021         }
4022         if (num_active_slaves > 0) {
4023                 printf("\tActive Slaves (%d): [", num_active_slaves);
4024                 for (i = 0; i < num_active_slaves - 1; i++)
4025                         printf("%d ", slaves[i]);
4026
4027                 printf("%d]\n", slaves[num_active_slaves - 1]);
4028
4029         } else {
4030                 printf("\tActive Slaves: []\n");
4031
4032         }
4033
4034         primary_id = rte_eth_bond_primary_get(port_id);
4035         if (primary_id < 0) {
4036                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4037                 return;
4038         } else
4039                 printf("\tPrimary: [%d]\n", primary_id);
4040
4041 }
4042
4043 cmdline_parse_token_string_t cmd_showbonding_config_show =
4044 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4045                 show, "show");
4046 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4047 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4048                 bonding, "bonding");
4049 cmdline_parse_token_string_t cmd_showbonding_config_config =
4050 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4051                 config, "config");
4052 cmdline_parse_token_num_t cmd_showbonding_config_port =
4053 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4054                 port_id, UINT8);
4055
4056 cmdline_parse_inst_t cmd_show_bonding_config = {
4057                 .f = cmd_show_bonding_config_parsed,
4058                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
4059                 .data = NULL,
4060                 .tokens = {
4061                                 (void *)&cmd_showbonding_config_show,
4062                                 (void *)&cmd_showbonding_config_bonding,
4063                                 (void *)&cmd_showbonding_config_config,
4064                                 (void *)&cmd_showbonding_config_port,
4065                                 NULL
4066                 }
4067 };
4068
4069 /* *** SET BONDING PRIMARY *** */
4070 struct cmd_set_bonding_primary_result {
4071         cmdline_fixed_string_t set;
4072         cmdline_fixed_string_t bonding;
4073         cmdline_fixed_string_t primary;
4074         uint8_t slave_id;
4075         uint8_t port_id;
4076 };
4077
4078 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4079                 __attribute__((unused))  struct cmdline *cl,
4080                 __attribute__((unused)) void *data)
4081 {
4082         struct cmd_set_bonding_primary_result *res = parsed_result;
4083         portid_t master_port_id = res->port_id;
4084         portid_t slave_port_id = res->slave_id;
4085
4086         /* Set the primary slave for a bonded device. */
4087         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4088                 printf("\t Failed to set primary slave for port = %d.\n",
4089                                 master_port_id);
4090                 return;
4091         }
4092         init_port_config();
4093 }
4094
4095 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4096 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4097                 set, "set");
4098 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4099 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4100                 bonding, "bonding");
4101 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4102 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4103                 primary, "primary");
4104 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4105 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4106                 slave_id, UINT8);
4107 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4108 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4109                 port_id, UINT8);
4110
4111 cmdline_parse_inst_t cmd_set_bonding_primary = {
4112                 .f = cmd_set_bonding_primary_parsed,
4113                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
4114                 .data = NULL,
4115                 .tokens = {
4116                                 (void *)&cmd_setbonding_primary_set,
4117                                 (void *)&cmd_setbonding_primary_bonding,
4118                                 (void *)&cmd_setbonding_primary_primary,
4119                                 (void *)&cmd_setbonding_primary_slave,
4120                                 (void *)&cmd_setbonding_primary_port,
4121                                 NULL
4122                 }
4123 };
4124
4125 /* *** ADD SLAVE *** */
4126 struct cmd_add_bonding_slave_result {
4127         cmdline_fixed_string_t add;
4128         cmdline_fixed_string_t bonding;
4129         cmdline_fixed_string_t slave;
4130         uint8_t slave_id;
4131         uint8_t port_id;
4132 };
4133
4134 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4135                 __attribute__((unused))  struct cmdline *cl,
4136                 __attribute__((unused)) void *data)
4137 {
4138         struct cmd_add_bonding_slave_result *res = parsed_result;
4139         portid_t master_port_id = res->port_id;
4140         portid_t slave_port_id = res->slave_id;
4141
4142         /* Set the primary slave for a bonded device. */
4143         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4144                 printf("\t Failed to add slave %d to master port = %d.\n",
4145                                 slave_port_id, master_port_id);
4146                 return;
4147         }
4148         init_port_config();
4149         set_port_slave_flag(slave_port_id);
4150 }
4151
4152 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4153 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4154                 add, "add");
4155 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4156 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4157                 bonding, "bonding");
4158 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4159 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4160                 slave, "slave");
4161 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4162 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4163                 slave_id, UINT8);
4164 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4165 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4166                 port_id, UINT8);
4167
4168 cmdline_parse_inst_t cmd_add_bonding_slave = {
4169                 .f = cmd_add_bonding_slave_parsed,
4170                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4171                 .data = NULL,
4172                 .tokens = {
4173                                 (void *)&cmd_addbonding_slave_add,
4174                                 (void *)&cmd_addbonding_slave_bonding,
4175                                 (void *)&cmd_addbonding_slave_slave,
4176                                 (void *)&cmd_addbonding_slave_slaveid,
4177                                 (void *)&cmd_addbonding_slave_port,
4178                                 NULL
4179                 }
4180 };
4181
4182 /* *** REMOVE SLAVE *** */
4183 struct cmd_remove_bonding_slave_result {
4184         cmdline_fixed_string_t remove;
4185         cmdline_fixed_string_t bonding;
4186         cmdline_fixed_string_t slave;
4187         uint8_t slave_id;
4188         uint8_t port_id;
4189 };
4190
4191 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4192                 __attribute__((unused))  struct cmdline *cl,
4193                 __attribute__((unused)) void *data)
4194 {
4195         struct cmd_remove_bonding_slave_result *res = parsed_result;
4196         portid_t master_port_id = res->port_id;
4197         portid_t slave_port_id = res->slave_id;
4198
4199         /* Set the primary slave for a bonded device. */
4200         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4201                 printf("\t Failed to remove slave %d from master port = %d.\n",
4202                                 slave_port_id, master_port_id);
4203                 return;
4204         }
4205         init_port_config();
4206         clear_port_slave_flag(slave_port_id);
4207 }
4208
4209 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4210                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4211                                 remove, "remove");
4212 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4213                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4214                                 bonding, "bonding");
4215 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4216                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4217                                 slave, "slave");
4218 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4219                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4220                                 slave_id, UINT8);
4221 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4222                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4223                                 port_id, UINT8);
4224
4225 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4226                 .f = cmd_remove_bonding_slave_parsed,
4227                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4228                 .data = NULL,
4229                 .tokens = {
4230                                 (void *)&cmd_removebonding_slave_remove,
4231                                 (void *)&cmd_removebonding_slave_bonding,
4232                                 (void *)&cmd_removebonding_slave_slave,
4233                                 (void *)&cmd_removebonding_slave_slaveid,
4234                                 (void *)&cmd_removebonding_slave_port,
4235                                 NULL
4236                 }
4237 };
4238
4239 /* *** CREATE BONDED DEVICE *** */
4240 struct cmd_create_bonded_device_result {
4241         cmdline_fixed_string_t create;
4242         cmdline_fixed_string_t bonded;
4243         cmdline_fixed_string_t device;
4244         uint8_t mode;
4245         uint8_t socket;
4246 };
4247
4248 static int bond_dev_num = 0;
4249
4250 static void cmd_create_bonded_device_parsed(void *parsed_result,
4251                 __attribute__((unused))  struct cmdline *cl,
4252                 __attribute__((unused)) void *data)
4253 {
4254         struct cmd_create_bonded_device_result *res = parsed_result;
4255         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4256         int port_id;
4257
4258         if (test_done == 0) {
4259                 printf("Please stop forwarding first\n");
4260                 return;
4261         }
4262
4263         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
4264                         bond_dev_num++);
4265
4266         /* Create a new bonded device. */
4267         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4268         if (port_id < 0) {
4269                 printf("\t Failed to create bonded device.\n");
4270                 return;
4271         } else {
4272                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4273                                 port_id);
4274
4275                 /* Update number of ports */
4276                 nb_ports = rte_eth_dev_count();
4277                 reconfig(port_id, res->socket);
4278                 rte_eth_promiscuous_enable(port_id);
4279                 ports[port_id].enabled = 1;
4280         }
4281
4282 }
4283
4284 cmdline_parse_token_string_t cmd_createbonded_device_create =
4285                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4286                                 create, "create");
4287 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4288                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4289                                 bonded, "bonded");
4290 cmdline_parse_token_string_t cmd_createbonded_device_device =
4291                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4292                                 device, "device");
4293 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4294                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4295                                 mode, UINT8);
4296 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4297                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4298                                 socket, UINT8);
4299
4300 cmdline_parse_inst_t cmd_create_bonded_device = {
4301                 .f = cmd_create_bonded_device_parsed,
4302                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4303                 .data = NULL,
4304                 .tokens = {
4305                                 (void *)&cmd_createbonded_device_create,
4306                                 (void *)&cmd_createbonded_device_bonded,
4307                                 (void *)&cmd_createbonded_device_device,
4308                                 (void *)&cmd_createbonded_device_mode,
4309                                 (void *)&cmd_createbonded_device_socket,
4310                                 NULL
4311                 }
4312 };
4313
4314 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4315 struct cmd_set_bond_mac_addr_result {
4316         cmdline_fixed_string_t set;
4317         cmdline_fixed_string_t bonding;
4318         cmdline_fixed_string_t mac_addr;
4319         uint8_t port_num;
4320         struct ether_addr address;
4321 };
4322
4323 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4324                 __attribute__((unused))  struct cmdline *cl,
4325                 __attribute__((unused)) void *data)
4326 {
4327         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4328         int ret;
4329
4330         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4331                 return;
4332
4333         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4334
4335         /* check the return value and print it if is < 0 */
4336         if (ret < 0)
4337                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4338 }
4339
4340 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4341                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4342 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4343                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4344                                 "bonding");
4345 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4346                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4347                                 "mac_addr");
4348 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4349                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4350 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4351                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4352
4353 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4354                 .f = cmd_set_bond_mac_addr_parsed,
4355                 .data = (void *) 0,
4356                 .help_str = "set bonding mac_addr (port_id) (address): ",
4357                 .tokens = {
4358                                 (void *)&cmd_set_bond_mac_addr_set,
4359                                 (void *)&cmd_set_bond_mac_addr_bonding,
4360                                 (void *)&cmd_set_bond_mac_addr_mac,
4361                                 (void *)&cmd_set_bond_mac_addr_portnum,
4362                                 (void *)&cmd_set_bond_mac_addr_addr,
4363                                 NULL
4364                 }
4365 };
4366
4367
4368 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4369 struct cmd_set_bond_mon_period_result {
4370         cmdline_fixed_string_t set;
4371         cmdline_fixed_string_t bonding;
4372         cmdline_fixed_string_t mon_period;
4373         uint8_t port_num;
4374         uint32_t period_ms;
4375 };
4376
4377 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4378                 __attribute__((unused))  struct cmdline *cl,
4379                 __attribute__((unused)) void *data)
4380 {
4381         struct cmd_set_bond_mon_period_result *res = parsed_result;
4382         int ret;
4383
4384         if (res->port_num >= nb_ports) {
4385                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4386                 return;
4387         }
4388
4389         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4390
4391         /* check the return value and print it if is < 0 */
4392         if (ret < 0)
4393                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4394 }
4395
4396 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4397                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4398                                 set, "set");
4399 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4400                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4401                                 bonding, "bonding");
4402 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4403                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4404                                 mon_period,     "mon_period");
4405 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4406                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4407                                 port_num, UINT8);
4408 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4409                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4410                                 period_ms, UINT32);
4411
4412 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4413                 .f = cmd_set_bond_mon_period_parsed,
4414                 .data = (void *) 0,
4415                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4416                 .tokens = {
4417                                 (void *)&cmd_set_bond_mon_period_set,
4418                                 (void *)&cmd_set_bond_mon_period_bonding,
4419                                 (void *)&cmd_set_bond_mon_period_mon_period,
4420                                 (void *)&cmd_set_bond_mon_period_portnum,
4421                                 (void *)&cmd_set_bond_mon_period_period_ms,
4422                                 NULL
4423                 }
4424 };
4425
4426 #endif /* RTE_LIBRTE_PMD_BOND */
4427
4428 /* *** SET FORWARDING MODE *** */
4429 struct cmd_set_fwd_mode_result {
4430         cmdline_fixed_string_t set;
4431         cmdline_fixed_string_t fwd;
4432         cmdline_fixed_string_t mode;
4433 };
4434
4435 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4436                                     __attribute__((unused)) struct cmdline *cl,
4437                                     __attribute__((unused)) void *data)
4438 {
4439         struct cmd_set_fwd_mode_result *res = parsed_result;
4440
4441         set_pkt_forwarding_mode(res->mode);
4442 }
4443
4444 cmdline_parse_token_string_t cmd_setfwd_set =
4445         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4446 cmdline_parse_token_string_t cmd_setfwd_fwd =
4447         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4448 cmdline_parse_token_string_t cmd_setfwd_mode =
4449         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4450                 "" /* defined at init */);
4451
4452 cmdline_parse_inst_t cmd_set_fwd_mode = {
4453         .f = cmd_set_fwd_mode_parsed,
4454         .data = NULL,
4455         .help_str = NULL, /* defined at init */
4456         .tokens = {
4457                 (void *)&cmd_setfwd_set,
4458                 (void *)&cmd_setfwd_fwd,
4459                 (void *)&cmd_setfwd_mode,
4460                 NULL,
4461         },
4462 };
4463
4464 static void cmd_set_fwd_mode_init(void)
4465 {
4466         char *modes, *c;
4467         static char token[128];
4468         static char help[256];
4469         cmdline_parse_token_string_t *token_struct;
4470
4471         modes = list_pkt_forwarding_modes();
4472         snprintf(help, sizeof help, "set fwd %s - "
4473                 "set packet forwarding mode", modes);
4474         cmd_set_fwd_mode.help_str = help;
4475
4476         /* string token separator is # */
4477         for (c = token; *modes != '\0'; modes++)
4478                 if (*modes == '|')
4479                         *c++ = '#';
4480                 else
4481                         *c++ = *modes;
4482         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4483         token_struct->string_data.str = token;
4484 }
4485
4486 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4487 struct cmd_set_burst_tx_retry_result {
4488         cmdline_fixed_string_t set;
4489         cmdline_fixed_string_t burst;
4490         cmdline_fixed_string_t tx;
4491         cmdline_fixed_string_t delay;
4492         uint32_t time;
4493         cmdline_fixed_string_t retry;
4494         uint32_t retry_num;
4495 };
4496
4497 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4498                                         __attribute__((unused)) struct cmdline *cl,
4499                                         __attribute__((unused)) void *data)
4500 {
4501         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4502
4503         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4504                 && !strcmp(res->tx, "tx")) {
4505                 if (!strcmp(res->delay, "delay"))
4506                         burst_tx_delay_time = res->time;
4507                 if (!strcmp(res->retry, "retry"))
4508                         burst_tx_retry_num = res->retry_num;
4509         }
4510
4511 }
4512
4513 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4514         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4515 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4516         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4517                                  "burst");
4518 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4519         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4520 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4521         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4522 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4523         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4524 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4525         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4526 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4527         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4528
4529 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4530         .f = cmd_set_burst_tx_retry_parsed,
4531         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4532         .tokens = {
4533                 (void *)&cmd_set_burst_tx_retry_set,
4534                 (void *)&cmd_set_burst_tx_retry_burst,
4535                 (void *)&cmd_set_burst_tx_retry_tx,
4536                 (void *)&cmd_set_burst_tx_retry_delay,
4537                 (void *)&cmd_set_burst_tx_retry_time,
4538                 (void *)&cmd_set_burst_tx_retry_retry,
4539                 (void *)&cmd_set_burst_tx_retry_retry_num,
4540                 NULL,
4541         },
4542 };
4543
4544 /* *** SET PROMISC MODE *** */
4545 struct cmd_set_promisc_mode_result {
4546         cmdline_fixed_string_t set;
4547         cmdline_fixed_string_t promisc;
4548         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4549         uint8_t port_num;                /* valid if "allports" argument == 0 */
4550         cmdline_fixed_string_t mode;
4551 };
4552
4553 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4554                                         __attribute__((unused)) struct cmdline *cl,
4555                                         void *allports)
4556 {
4557         struct cmd_set_promisc_mode_result *res = parsed_result;
4558         int enable;
4559         portid_t i;
4560
4561         if (!strcmp(res->mode, "on"))
4562                 enable = 1;
4563         else
4564                 enable = 0;
4565
4566         /* all ports */
4567         if (allports) {
4568                 FOREACH_PORT(i, ports) {
4569                         if (enable)
4570                                 rte_eth_promiscuous_enable(i);
4571                         else
4572                                 rte_eth_promiscuous_disable(i);
4573                 }
4574         }
4575         else {
4576                 if (enable)
4577                         rte_eth_promiscuous_enable(res->port_num);
4578                 else
4579                         rte_eth_promiscuous_disable(res->port_num);
4580         }
4581 }
4582
4583 cmdline_parse_token_string_t cmd_setpromisc_set =
4584         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4585 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4586         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4587                                  "promisc");
4588 cmdline_parse_token_string_t cmd_setpromisc_portall =
4589         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4590                                  "all");
4591 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4592         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4593                               UINT8);
4594 cmdline_parse_token_string_t cmd_setpromisc_mode =
4595         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4596                                  "on#off");
4597
4598 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4599         .f = cmd_set_promisc_mode_parsed,
4600         .data = (void *)1,
4601         .help_str = "set promisc all on|off: set promisc mode for all ports",
4602         .tokens = {
4603                 (void *)&cmd_setpromisc_set,
4604                 (void *)&cmd_setpromisc_promisc,
4605                 (void *)&cmd_setpromisc_portall,
4606                 (void *)&cmd_setpromisc_mode,
4607                 NULL,
4608         },
4609 };
4610
4611 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4612         .f = cmd_set_promisc_mode_parsed,
4613         .data = (void *)0,
4614         .help_str = "set promisc X on|off: set promisc mode on port X",
4615         .tokens = {
4616                 (void *)&cmd_setpromisc_set,
4617                 (void *)&cmd_setpromisc_promisc,
4618                 (void *)&cmd_setpromisc_portnum,
4619                 (void *)&cmd_setpromisc_mode,
4620                 NULL,
4621         },
4622 };
4623
4624 /* *** SET ALLMULTI MODE *** */
4625 struct cmd_set_allmulti_mode_result {
4626         cmdline_fixed_string_t set;
4627         cmdline_fixed_string_t allmulti;
4628         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4629         uint8_t port_num;                /* valid if "allports" argument == 0 */
4630         cmdline_fixed_string_t mode;
4631 };
4632
4633 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4634                                         __attribute__((unused)) struct cmdline *cl,
4635                                         void *allports)
4636 {
4637         struct cmd_set_allmulti_mode_result *res = parsed_result;
4638         int enable;
4639         portid_t i;
4640
4641         if (!strcmp(res->mode, "on"))
4642                 enable = 1;
4643         else
4644                 enable = 0;
4645
4646         /* all ports */
4647         if (allports) {
4648                 FOREACH_PORT(i, ports) {
4649                         if (enable)
4650                                 rte_eth_allmulticast_enable(i);
4651                         else
4652                                 rte_eth_allmulticast_disable(i);
4653                 }
4654         }
4655         else {
4656                 if (enable)
4657                         rte_eth_allmulticast_enable(res->port_num);
4658                 else
4659                         rte_eth_allmulticast_disable(res->port_num);
4660         }
4661 }
4662
4663 cmdline_parse_token_string_t cmd_setallmulti_set =
4664         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4665 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4666         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4667                                  "allmulti");
4668 cmdline_parse_token_string_t cmd_setallmulti_portall =
4669         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4670                                  "all");
4671 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4672         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4673                               UINT8);
4674 cmdline_parse_token_string_t cmd_setallmulti_mode =
4675         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4676                                  "on#off");
4677
4678 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4679         .f = cmd_set_allmulti_mode_parsed,
4680         .data = (void *)1,
4681         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4682         .tokens = {
4683                 (void *)&cmd_setallmulti_set,
4684                 (void *)&cmd_setallmulti_allmulti,
4685                 (void *)&cmd_setallmulti_portall,
4686                 (void *)&cmd_setallmulti_mode,
4687                 NULL,
4688         },
4689 };
4690
4691 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4692         .f = cmd_set_allmulti_mode_parsed,
4693         .data = (void *)0,
4694         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4695         .tokens = {
4696                 (void *)&cmd_setallmulti_set,
4697                 (void *)&cmd_setallmulti_allmulti,
4698                 (void *)&cmd_setallmulti_portnum,
4699                 (void *)&cmd_setallmulti_mode,
4700                 NULL,
4701         },
4702 };
4703
4704 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4705 struct cmd_link_flow_ctrl_set_result {
4706         cmdline_fixed_string_t set;
4707         cmdline_fixed_string_t flow_ctrl;
4708         cmdline_fixed_string_t rx;
4709         cmdline_fixed_string_t rx_lfc_mode;
4710         cmdline_fixed_string_t tx;
4711         cmdline_fixed_string_t tx_lfc_mode;
4712         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4713         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4714         cmdline_fixed_string_t autoneg_str;
4715         cmdline_fixed_string_t autoneg;
4716         cmdline_fixed_string_t hw_str;
4717         uint32_t high_water;
4718         cmdline_fixed_string_t lw_str;
4719         uint32_t low_water;
4720         cmdline_fixed_string_t pt_str;
4721         uint16_t pause_time;
4722         cmdline_fixed_string_t xon_str;
4723         uint16_t send_xon;
4724         uint8_t  port_id;
4725 };
4726
4727 cmdline_parse_token_string_t cmd_lfc_set_set =
4728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4729                                 set, "set");
4730 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4731         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4732                                 flow_ctrl, "flow_ctrl");
4733 cmdline_parse_token_string_t cmd_lfc_set_rx =
4734         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4735                                 rx, "rx");
4736 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4737         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4738                                 rx_lfc_mode, "on#off");
4739 cmdline_parse_token_string_t cmd_lfc_set_tx =
4740         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4741                                 tx, "tx");
4742 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4743         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4744                                 tx_lfc_mode, "on#off");
4745 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4746         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4747                                 hw_str, "high_water");
4748 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4749         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4750                                 high_water, UINT32);
4751 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4752         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4753                                 lw_str, "low_water");
4754 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4755         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4756                                 low_water, UINT32);
4757 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4758         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4759                                 pt_str, "pause_time");
4760 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4761         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4762                                 pause_time, UINT16);
4763 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4764         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4765                                 xon_str, "send_xon");
4766 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4767         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4768                                 send_xon, UINT16);
4769 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4770         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4771                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4772 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4773         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4774                                 mac_ctrl_frame_fwd_mode, "on#off");
4775 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4776         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4777                                 autoneg_str, "autoneg");
4778 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4779         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4780                                 autoneg, "on#off");
4781 cmdline_parse_token_num_t cmd_lfc_set_portid =
4782         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4783                                 port_id, UINT8);
4784
4785 /* forward declaration */
4786 static void
4787 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4788                               void *data);
4789
4790 cmdline_parse_inst_t cmd_link_flow_control_set = {
4791         .f = cmd_link_flow_ctrl_set_parsed,
4792         .data = NULL,
4793         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4794 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4795 autoneg on|off port_id",
4796         .tokens = {
4797                 (void *)&cmd_lfc_set_set,
4798                 (void *)&cmd_lfc_set_flow_ctrl,
4799                 (void *)&cmd_lfc_set_rx,
4800                 (void *)&cmd_lfc_set_rx_mode,
4801                 (void *)&cmd_lfc_set_tx,
4802                 (void *)&cmd_lfc_set_tx_mode,
4803                 (void *)&cmd_lfc_set_high_water,
4804                 (void *)&cmd_lfc_set_low_water,
4805                 (void *)&cmd_lfc_set_pause_time,
4806                 (void *)&cmd_lfc_set_send_xon,
4807                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4808                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4809                 (void *)&cmd_lfc_set_autoneg_str,
4810                 (void *)&cmd_lfc_set_autoneg,
4811                 (void *)&cmd_lfc_set_portid,
4812                 NULL,
4813         },
4814 };
4815
4816 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4817         .f = cmd_link_flow_ctrl_set_parsed,
4818         .data = (void *)&cmd_link_flow_control_set_rx,
4819         .help_str = "Change rx flow control parameter: set flow_ctrl "
4820                     "rx on|off port_id",
4821         .tokens = {
4822                 (void *)&cmd_lfc_set_set,
4823                 (void *)&cmd_lfc_set_flow_ctrl,
4824                 (void *)&cmd_lfc_set_rx,
4825                 (void *)&cmd_lfc_set_rx_mode,
4826                 (void *)&cmd_lfc_set_portid,
4827                 NULL,
4828         },
4829 };
4830
4831 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4832         .f = cmd_link_flow_ctrl_set_parsed,
4833         .data = (void *)&cmd_link_flow_control_set_tx,
4834         .help_str = "Change tx flow control parameter: set flow_ctrl "
4835                     "tx on|off port_id",
4836         .tokens = {
4837                 (void *)&cmd_lfc_set_set,
4838                 (void *)&cmd_lfc_set_flow_ctrl,
4839                 (void *)&cmd_lfc_set_tx,
4840                 (void *)&cmd_lfc_set_tx_mode,
4841                 (void *)&cmd_lfc_set_portid,
4842                 NULL,
4843         },
4844 };
4845
4846 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
4847         .f = cmd_link_flow_ctrl_set_parsed,
4848         .data = (void *)&cmd_link_flow_control_set_hw,
4849         .help_str = "Change high water flow control parameter: set flow_ctrl "
4850                     "high_water value port_id",
4851         .tokens = {
4852                 (void *)&cmd_lfc_set_set,
4853                 (void *)&cmd_lfc_set_flow_ctrl,
4854                 (void *)&cmd_lfc_set_high_water_str,
4855                 (void *)&cmd_lfc_set_high_water,
4856                 (void *)&cmd_lfc_set_portid,
4857                 NULL,
4858         },
4859 };
4860
4861 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
4862         .f = cmd_link_flow_ctrl_set_parsed,
4863         .data = (void *)&cmd_link_flow_control_set_lw,
4864         .help_str = "Change low water flow control parameter: set flow_ctrl "
4865                     "low_water value port_id",
4866         .tokens = {
4867                 (void *)&cmd_lfc_set_set,
4868                 (void *)&cmd_lfc_set_flow_ctrl,
4869                 (void *)&cmd_lfc_set_low_water_str,
4870                 (void *)&cmd_lfc_set_low_water,
4871                 (void *)&cmd_lfc_set_portid,
4872                 NULL,
4873         },
4874 };
4875
4876 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
4877         .f = cmd_link_flow_ctrl_set_parsed,
4878         .data = (void *)&cmd_link_flow_control_set_pt,
4879         .help_str = "Change pause time flow control parameter: set flow_ctrl "
4880                     "pause_time value port_id",
4881         .tokens = {
4882                 (void *)&cmd_lfc_set_set,
4883                 (void *)&cmd_lfc_set_flow_ctrl,
4884                 (void *)&cmd_lfc_set_pause_time_str,
4885                 (void *)&cmd_lfc_set_pause_time,
4886                 (void *)&cmd_lfc_set_portid,
4887                 NULL,
4888         },
4889 };
4890
4891 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
4892         .f = cmd_link_flow_ctrl_set_parsed,
4893         .data = (void *)&cmd_link_flow_control_set_xon,
4894         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
4895                     "send_xon value port_id",
4896         .tokens = {
4897                 (void *)&cmd_lfc_set_set,
4898                 (void *)&cmd_lfc_set_flow_ctrl,
4899                 (void *)&cmd_lfc_set_send_xon_str,
4900                 (void *)&cmd_lfc_set_send_xon,
4901                 (void *)&cmd_lfc_set_portid,
4902                 NULL,
4903         },
4904 };
4905
4906 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
4907         .f = cmd_link_flow_ctrl_set_parsed,
4908         .data = (void *)&cmd_link_flow_control_set_macfwd,
4909         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
4910                     "mac_ctrl_frame_fwd on|off port_id",
4911         .tokens = {
4912                 (void *)&cmd_lfc_set_set,
4913                 (void *)&cmd_lfc_set_flow_ctrl,
4914                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4915                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4916                 (void *)&cmd_lfc_set_portid,
4917                 NULL,
4918         },
4919 };
4920
4921 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
4922         .f = cmd_link_flow_ctrl_set_parsed,
4923         .data = (void *)&cmd_link_flow_control_set_autoneg,
4924         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
4925                     "autoneg on|off port_id",
4926         .tokens = {
4927                 (void *)&cmd_lfc_set_set,
4928                 (void *)&cmd_lfc_set_flow_ctrl,
4929                 (void *)&cmd_lfc_set_autoneg_str,
4930                 (void *)&cmd_lfc_set_autoneg,
4931                 (void *)&cmd_lfc_set_portid,
4932                 NULL,
4933         },
4934 };
4935
4936 static void
4937 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
4938                               __attribute__((unused)) struct cmdline *cl,
4939                               void *data)
4940 {
4941         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
4942         cmdline_parse_inst_t *cmd = data;
4943         struct rte_eth_fc_conf fc_conf;
4944         int rx_fc_en = 0;
4945         int tx_fc_en = 0;
4946         int ret;
4947
4948         /*
4949          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
4950          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
4951          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
4952          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
4953          */
4954         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
4955                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
4956         };
4957
4958         /* Partial command line, retrieve current configuration */
4959         if (cmd) {
4960                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
4961                 if (ret != 0) {
4962                         printf("cannot get current flow ctrl parameters, return"
4963                                "code = %d\n", ret);
4964                         return;
4965                 }
4966
4967                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
4968                     (fc_conf.mode == RTE_FC_FULL))
4969                         rx_fc_en = 1;
4970                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
4971                     (fc_conf.mode == RTE_FC_FULL))
4972                         tx_fc_en = 1;
4973         }
4974
4975         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
4976                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
4977
4978         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
4979                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
4980
4981         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
4982
4983         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
4984                 fc_conf.high_water = res->high_water;
4985
4986         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
4987                 fc_conf.low_water = res->low_water;
4988
4989         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
4990                 fc_conf.pause_time = res->pause_time;
4991
4992         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
4993                 fc_conf.send_xon = res->send_xon;
4994
4995         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
4996                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
4997                         fc_conf.mac_ctrl_frame_fwd = 1;
4998                 else
4999                         fc_conf.mac_ctrl_frame_fwd = 0;
5000         }
5001
5002         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5003                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5004
5005         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5006         if (ret != 0)
5007                 printf("bad flow contrl parameter, return code = %d \n", ret);
5008 }
5009
5010 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5011 struct cmd_priority_flow_ctrl_set_result {
5012         cmdline_fixed_string_t set;
5013         cmdline_fixed_string_t pfc_ctrl;
5014         cmdline_fixed_string_t rx;
5015         cmdline_fixed_string_t rx_pfc_mode;
5016         cmdline_fixed_string_t tx;
5017         cmdline_fixed_string_t tx_pfc_mode;
5018         uint32_t high_water;
5019         uint32_t low_water;
5020         uint16_t pause_time;
5021         uint8_t  priority;
5022         uint8_t  port_id;
5023 };
5024
5025 static void
5026 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5027                        __attribute__((unused)) struct cmdline *cl,
5028                        __attribute__((unused)) void *data)
5029 {
5030         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5031         struct rte_eth_pfc_conf pfc_conf;
5032         int rx_fc_enable, tx_fc_enable;
5033         int ret;
5034
5035         /*
5036          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5037          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5038          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5039          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5040          */
5041         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5042                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5043         };
5044
5045         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5046         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5047         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5048         pfc_conf.fc.high_water = res->high_water;
5049         pfc_conf.fc.low_water  = res->low_water;
5050         pfc_conf.fc.pause_time = res->pause_time;
5051         pfc_conf.priority      = res->priority;
5052
5053         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5054         if (ret != 0)
5055                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5056 }
5057
5058 cmdline_parse_token_string_t cmd_pfc_set_set =
5059         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5060                                 set, "set");
5061 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5062         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5063                                 pfc_ctrl, "pfc_ctrl");
5064 cmdline_parse_token_string_t cmd_pfc_set_rx =
5065         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5066                                 rx, "rx");
5067 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5068         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5069                                 rx_pfc_mode, "on#off");
5070 cmdline_parse_token_string_t cmd_pfc_set_tx =
5071         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5072                                 tx, "tx");
5073 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5074         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5075                                 tx_pfc_mode, "on#off");
5076 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5077         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5078                                 high_water, UINT32);
5079 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5080         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5081                                 low_water, UINT32);
5082 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5083         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5084                                 pause_time, UINT16);
5085 cmdline_parse_token_num_t cmd_pfc_set_priority =
5086         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5087                                 priority, UINT8);
5088 cmdline_parse_token_num_t cmd_pfc_set_portid =
5089         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5090                                 port_id, UINT8);
5091
5092 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5093         .f = cmd_priority_flow_ctrl_set_parsed,
5094         .data = NULL,
5095         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5096                         tx on|off high_water low_water pause_time priority port_id",
5097         .tokens = {
5098                 (void *)&cmd_pfc_set_set,
5099                 (void *)&cmd_pfc_set_flow_ctrl,
5100                 (void *)&cmd_pfc_set_rx,
5101                 (void *)&cmd_pfc_set_rx_mode,
5102                 (void *)&cmd_pfc_set_tx,
5103                 (void *)&cmd_pfc_set_tx_mode,
5104                 (void *)&cmd_pfc_set_high_water,
5105                 (void *)&cmd_pfc_set_low_water,
5106                 (void *)&cmd_pfc_set_pause_time,
5107                 (void *)&cmd_pfc_set_priority,
5108                 (void *)&cmd_pfc_set_portid,
5109                 NULL,
5110         },
5111 };
5112
5113 /* *** RESET CONFIGURATION *** */
5114 struct cmd_reset_result {
5115         cmdline_fixed_string_t reset;
5116         cmdline_fixed_string_t def;
5117 };
5118
5119 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5120                              struct cmdline *cl,
5121                              __attribute__((unused)) void *data)
5122 {
5123         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5124         set_def_fwd_config();
5125 }
5126
5127 cmdline_parse_token_string_t cmd_reset_set =
5128         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5129 cmdline_parse_token_string_t cmd_reset_def =
5130         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5131                                  "default");
5132
5133 cmdline_parse_inst_t cmd_reset = {
5134         .f = cmd_reset_parsed,
5135         .data = NULL,
5136         .help_str = "set default: reset default forwarding configuration",
5137         .tokens = {
5138                 (void *)&cmd_reset_set,
5139                 (void *)&cmd_reset_def,
5140                 NULL,
5141         },
5142 };
5143
5144 /* *** START FORWARDING *** */
5145 struct cmd_start_result {
5146         cmdline_fixed_string_t start;
5147 };
5148
5149 cmdline_parse_token_string_t cmd_start_start =
5150         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5151
5152 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5153                              __attribute__((unused)) struct cmdline *cl,
5154                              __attribute__((unused)) void *data)
5155 {
5156         start_packet_forwarding(0);
5157 }
5158
5159 cmdline_parse_inst_t cmd_start = {
5160         .f = cmd_start_parsed,
5161         .data = NULL,
5162         .help_str = "start packet forwarding",
5163         .tokens = {
5164                 (void *)&cmd_start_start,
5165                 NULL,
5166         },
5167 };
5168
5169 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5170 struct cmd_start_tx_first_result {
5171         cmdline_fixed_string_t start;
5172         cmdline_fixed_string_t tx_first;
5173 };
5174
5175 static void
5176 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5177                           __attribute__((unused)) struct cmdline *cl,
5178                           __attribute__((unused)) void *data)
5179 {
5180         start_packet_forwarding(1);
5181 }
5182
5183 cmdline_parse_token_string_t cmd_start_tx_first_start =
5184         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5185                                  "start");
5186 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5187         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5188                                  tx_first, "tx_first");
5189
5190 cmdline_parse_inst_t cmd_start_tx_first = {
5191         .f = cmd_start_tx_first_parsed,
5192         .data = NULL,
5193         .help_str = "start packet forwarding, after sending 1 burst of packets",
5194         .tokens = {
5195                 (void *)&cmd_start_tx_first_start,
5196                 (void *)&cmd_start_tx_first_tx_first,
5197                 NULL,
5198         },
5199 };
5200
5201 /* *** SET LINK UP *** */
5202 struct cmd_set_link_up_result {
5203         cmdline_fixed_string_t set;
5204         cmdline_fixed_string_t link_up;
5205         cmdline_fixed_string_t port;
5206         uint8_t port_id;
5207 };
5208
5209 cmdline_parse_token_string_t cmd_set_link_up_set =
5210         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5211 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5212         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5213                                 "link-up");
5214 cmdline_parse_token_string_t cmd_set_link_up_port =
5215         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5216 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5217         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5218
5219 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5220                              __attribute__((unused)) struct cmdline *cl,
5221                              __attribute__((unused)) void *data)
5222 {
5223         struct cmd_set_link_up_result *res = parsed_result;
5224         dev_set_link_up(res->port_id);
5225 }
5226
5227 cmdline_parse_inst_t cmd_set_link_up = {
5228         .f = cmd_set_link_up_parsed,
5229         .data = NULL,
5230         .help_str = "set link-up port (port id)",
5231         .tokens = {
5232                 (void *)&cmd_set_link_up_set,
5233                 (void *)&cmd_set_link_up_link_up,
5234                 (void *)&cmd_set_link_up_port,
5235                 (void *)&cmd_set_link_up_port_id,
5236                 NULL,
5237         },
5238 };
5239
5240 /* *** SET LINK DOWN *** */
5241 struct cmd_set_link_down_result {
5242         cmdline_fixed_string_t set;
5243         cmdline_fixed_string_t link_down;
5244         cmdline_fixed_string_t port;
5245         uint8_t port_id;
5246 };
5247
5248 cmdline_parse_token_string_t cmd_set_link_down_set =
5249         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5250 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5251         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5252                                 "link-down");
5253 cmdline_parse_token_string_t cmd_set_link_down_port =
5254         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5255 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5256         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5257
5258 static void cmd_set_link_down_parsed(
5259                                 __attribute__((unused)) void *parsed_result,
5260                                 __attribute__((unused)) struct cmdline *cl,
5261                                 __attribute__((unused)) void *data)
5262 {
5263         struct cmd_set_link_down_result *res = parsed_result;
5264         dev_set_link_down(res->port_id);
5265 }
5266
5267 cmdline_parse_inst_t cmd_set_link_down = {
5268         .f = cmd_set_link_down_parsed,
5269         .data = NULL,
5270         .help_str = "set link-down port (port id)",
5271         .tokens = {
5272                 (void *)&cmd_set_link_down_set,
5273                 (void *)&cmd_set_link_down_link_down,
5274                 (void *)&cmd_set_link_down_port,
5275                 (void *)&cmd_set_link_down_port_id,
5276                 NULL,
5277         },
5278 };
5279
5280 /* *** SHOW CFG *** */
5281 struct cmd_showcfg_result {
5282         cmdline_fixed_string_t show;
5283         cmdline_fixed_string_t cfg;
5284         cmdline_fixed_string_t what;
5285 };
5286
5287 static void cmd_showcfg_parsed(void *parsed_result,
5288                                __attribute__((unused)) struct cmdline *cl,
5289                                __attribute__((unused)) void *data)
5290 {
5291         struct cmd_showcfg_result *res = parsed_result;
5292         if (!strcmp(res->what, "rxtx"))
5293                 rxtx_config_display();
5294         else if (!strcmp(res->what, "cores"))
5295                 fwd_lcores_config_display();
5296         else if (!strcmp(res->what, "fwd"))
5297                 fwd_config_display();
5298         else if (!strcmp(res->what, "txpkts"))
5299                 show_tx_pkt_segments();
5300 }
5301
5302 cmdline_parse_token_string_t cmd_showcfg_show =
5303         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5304 cmdline_parse_token_string_t cmd_showcfg_port =
5305         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5306 cmdline_parse_token_string_t cmd_showcfg_what =
5307         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5308                                  "rxtx#cores#fwd#txpkts");
5309
5310 cmdline_parse_inst_t cmd_showcfg = {
5311         .f = cmd_showcfg_parsed,
5312         .data = NULL,
5313         .help_str = "show config rxtx|cores|fwd|txpkts",
5314         .tokens = {
5315                 (void *)&cmd_showcfg_show,
5316                 (void *)&cmd_showcfg_port,
5317                 (void *)&cmd_showcfg_what,
5318                 NULL,
5319         },
5320 };
5321
5322 /* *** SHOW ALL PORT INFO *** */
5323 struct cmd_showportall_result {
5324         cmdline_fixed_string_t show;
5325         cmdline_fixed_string_t port;
5326         cmdline_fixed_string_t what;
5327         cmdline_fixed_string_t all;
5328 };
5329
5330 static void cmd_showportall_parsed(void *parsed_result,
5331                                 __attribute__((unused)) struct cmdline *cl,
5332                                 __attribute__((unused)) void *data)
5333 {
5334         portid_t i;
5335
5336         struct cmd_showportall_result *res = parsed_result;
5337         if (!strcmp(res->show, "clear")) {
5338                 if (!strcmp(res->what, "stats"))
5339                         FOREACH_PORT(i, ports)
5340                                 nic_stats_clear(i);
5341                 else if (!strcmp(res->what, "xstats"))
5342                         FOREACH_PORT(i, ports)
5343                                 nic_xstats_clear(i);
5344         } else if (!strcmp(res->what, "info"))
5345                 FOREACH_PORT(i, ports)
5346                         port_infos_display(i);
5347         else if (!strcmp(res->what, "stats"))
5348                 FOREACH_PORT(i, ports)
5349                         nic_stats_display(i);
5350         else if (!strcmp(res->what, "xstats"))
5351                 FOREACH_PORT(i, ports)
5352                         nic_xstats_display(i);
5353         else if (!strcmp(res->what, "fdir"))
5354                 FOREACH_PORT(i, ports)
5355                         fdir_get_infos(i);
5356         else if (!strcmp(res->what, "stat_qmap"))
5357                 FOREACH_PORT(i, ports)
5358                         nic_stats_mapping_display(i);
5359         else if (!strcmp(res->what, "dcb_tc"))
5360                 FOREACH_PORT(i, ports)
5361                         port_dcb_info_display(i);
5362 }
5363
5364 cmdline_parse_token_string_t cmd_showportall_show =
5365         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5366                                  "show#clear");
5367 cmdline_parse_token_string_t cmd_showportall_port =
5368         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5369 cmdline_parse_token_string_t cmd_showportall_what =
5370         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5371                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5372 cmdline_parse_token_string_t cmd_showportall_all =
5373         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5374 cmdline_parse_inst_t cmd_showportall = {
5375         .f = cmd_showportall_parsed,
5376         .data = NULL,
5377         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all",
5378         .tokens = {
5379                 (void *)&cmd_showportall_show,
5380                 (void *)&cmd_showportall_port,
5381                 (void *)&cmd_showportall_what,
5382                 (void *)&cmd_showportall_all,
5383                 NULL,
5384         },
5385 };
5386
5387 /* *** SHOW PORT INFO *** */
5388 struct cmd_showport_result {
5389         cmdline_fixed_string_t show;
5390         cmdline_fixed_string_t port;
5391         cmdline_fixed_string_t what;
5392         uint8_t portnum;
5393 };
5394
5395 static void cmd_showport_parsed(void *parsed_result,
5396                                 __attribute__((unused)) struct cmdline *cl,
5397                                 __attribute__((unused)) void *data)
5398 {
5399         struct cmd_showport_result *res = parsed_result;
5400         if (!strcmp(res->show, "clear")) {
5401                 if (!strcmp(res->what, "stats"))
5402                         nic_stats_clear(res->portnum);
5403                 else if (!strcmp(res->what, "xstats"))
5404                         nic_xstats_clear(res->portnum);
5405         } else if (!strcmp(res->what, "info"))
5406                 port_infos_display(res->portnum);
5407         else if (!strcmp(res->what, "stats"))
5408                 nic_stats_display(res->portnum);
5409         else if (!strcmp(res->what, "xstats"))
5410                 nic_xstats_display(res->portnum);
5411         else if (!strcmp(res->what, "fdir"))
5412                  fdir_get_infos(res->portnum);
5413         else if (!strcmp(res->what, "stat_qmap"))
5414                 nic_stats_mapping_display(res->portnum);
5415         else if (!strcmp(res->what, "dcb_tc"))
5416                 port_dcb_info_display(res->portnum);
5417 }
5418
5419 cmdline_parse_token_string_t cmd_showport_show =
5420         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5421                                  "show#clear");
5422 cmdline_parse_token_string_t cmd_showport_port =
5423         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5424 cmdline_parse_token_string_t cmd_showport_what =
5425         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5426                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5427 cmdline_parse_token_num_t cmd_showport_portnum =
5428         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5429
5430 cmdline_parse_inst_t cmd_showport = {
5431         .f = cmd_showport_parsed,
5432         .data = NULL,
5433         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc X (X = port number)",
5434         .tokens = {
5435                 (void *)&cmd_showport_show,
5436                 (void *)&cmd_showport_port,
5437                 (void *)&cmd_showport_what,
5438                 (void *)&cmd_showport_portnum,
5439                 NULL,
5440         },
5441 };
5442
5443 /* *** SHOW QUEUE INFO *** */
5444 struct cmd_showqueue_result {
5445         cmdline_fixed_string_t show;
5446         cmdline_fixed_string_t type;
5447         cmdline_fixed_string_t what;
5448         uint8_t portnum;
5449         uint16_t queuenum;
5450 };
5451
5452 static void
5453 cmd_showqueue_parsed(void *parsed_result,
5454         __attribute__((unused)) struct cmdline *cl,
5455         __attribute__((unused)) void *data)
5456 {
5457         struct cmd_showqueue_result *res = parsed_result;
5458
5459         if (!strcmp(res->type, "rxq"))
5460                 rx_queue_infos_display(res->portnum, res->queuenum);
5461         else if (!strcmp(res->type, "txq"))
5462                 tx_queue_infos_display(res->portnum, res->queuenum);
5463 }
5464
5465 cmdline_parse_token_string_t cmd_showqueue_show =
5466         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5467 cmdline_parse_token_string_t cmd_showqueue_type =
5468         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5469 cmdline_parse_token_string_t cmd_showqueue_what =
5470         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5471 cmdline_parse_token_num_t cmd_showqueue_portnum =
5472         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5473 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5474         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5475
5476 cmdline_parse_inst_t cmd_showqueue = {
5477         .f = cmd_showqueue_parsed,
5478         .data = NULL,
5479         .help_str = "show rxq|txq info <port number> <queue_number>",
5480         .tokens = {
5481                 (void *)&cmd_showqueue_show,
5482                 (void *)&cmd_showqueue_type,
5483                 (void *)&cmd_showqueue_what,
5484                 (void *)&cmd_showqueue_portnum,
5485                 (void *)&cmd_showqueue_queuenum,
5486                 NULL,
5487         },
5488 };
5489
5490 /* *** READ PORT REGISTER *** */
5491 struct cmd_read_reg_result {
5492         cmdline_fixed_string_t read;
5493         cmdline_fixed_string_t reg;
5494         uint8_t port_id;
5495         uint32_t reg_off;
5496 };
5497
5498 static void
5499 cmd_read_reg_parsed(void *parsed_result,
5500                     __attribute__((unused)) struct cmdline *cl,
5501                     __attribute__((unused)) void *data)
5502 {
5503         struct cmd_read_reg_result *res = parsed_result;
5504         port_reg_display(res->port_id, res->reg_off);
5505 }
5506
5507 cmdline_parse_token_string_t cmd_read_reg_read =
5508         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5509 cmdline_parse_token_string_t cmd_read_reg_reg =
5510         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5511 cmdline_parse_token_num_t cmd_read_reg_port_id =
5512         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5513 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5514         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5515
5516 cmdline_parse_inst_t cmd_read_reg = {
5517         .f = cmd_read_reg_parsed,
5518         .data = NULL,
5519         .help_str = "read reg port_id reg_off",
5520         .tokens = {
5521                 (void *)&cmd_read_reg_read,
5522                 (void *)&cmd_read_reg_reg,
5523                 (void *)&cmd_read_reg_port_id,
5524                 (void *)&cmd_read_reg_reg_off,
5525                 NULL,
5526         },
5527 };
5528
5529 /* *** READ PORT REGISTER BIT FIELD *** */
5530 struct cmd_read_reg_bit_field_result {
5531         cmdline_fixed_string_t read;
5532         cmdline_fixed_string_t regfield;
5533         uint8_t port_id;
5534         uint32_t reg_off;
5535         uint8_t bit1_pos;
5536         uint8_t bit2_pos;
5537 };
5538
5539 static void
5540 cmd_read_reg_bit_field_parsed(void *parsed_result,
5541                               __attribute__((unused)) struct cmdline *cl,
5542                               __attribute__((unused)) void *data)
5543 {
5544         struct cmd_read_reg_bit_field_result *res = parsed_result;
5545         port_reg_bit_field_display(res->port_id, res->reg_off,
5546                                    res->bit1_pos, res->bit2_pos);
5547 }
5548
5549 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5550         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5551                                  "read");
5552 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5553         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5554                                  regfield, "regfield");
5555 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5556         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5557                               UINT8);
5558 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5559         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5560                               UINT32);
5561 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5562         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5563                               UINT8);
5564 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5565         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5566                               UINT8);
5567
5568 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5569         .f = cmd_read_reg_bit_field_parsed,
5570         .data = NULL,
5571         .help_str = "read regfield port_id reg_off bit_x bit_y "
5572         "(read register bit field between bit_x and bit_y included)",
5573         .tokens = {
5574                 (void *)&cmd_read_reg_bit_field_read,
5575                 (void *)&cmd_read_reg_bit_field_regfield,
5576                 (void *)&cmd_read_reg_bit_field_port_id,
5577                 (void *)&cmd_read_reg_bit_field_reg_off,
5578                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5579                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5580                 NULL,
5581         },
5582 };
5583
5584 /* *** READ PORT REGISTER BIT *** */
5585 struct cmd_read_reg_bit_result {
5586         cmdline_fixed_string_t read;
5587         cmdline_fixed_string_t regbit;
5588         uint8_t port_id;
5589         uint32_t reg_off;
5590         uint8_t bit_pos;
5591 };
5592
5593 static void
5594 cmd_read_reg_bit_parsed(void *parsed_result,
5595                         __attribute__((unused)) struct cmdline *cl,
5596                         __attribute__((unused)) void *data)
5597 {
5598         struct cmd_read_reg_bit_result *res = parsed_result;
5599         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5600 }
5601
5602 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5603         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5604 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5605         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5606                                  regbit, "regbit");
5607 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5608         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5609 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5610         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5611 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5612         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5613
5614 cmdline_parse_inst_t cmd_read_reg_bit = {
5615         .f = cmd_read_reg_bit_parsed,
5616         .data = NULL,
5617         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5618         .tokens = {
5619                 (void *)&cmd_read_reg_bit_read,
5620                 (void *)&cmd_read_reg_bit_regbit,
5621                 (void *)&cmd_read_reg_bit_port_id,
5622                 (void *)&cmd_read_reg_bit_reg_off,
5623                 (void *)&cmd_read_reg_bit_bit_pos,
5624                 NULL,
5625         },
5626 };
5627
5628 /* *** WRITE PORT REGISTER *** */
5629 struct cmd_write_reg_result {
5630         cmdline_fixed_string_t write;
5631         cmdline_fixed_string_t reg;
5632         uint8_t port_id;
5633         uint32_t reg_off;
5634         uint32_t value;
5635 };
5636
5637 static void
5638 cmd_write_reg_parsed(void *parsed_result,
5639                      __attribute__((unused)) struct cmdline *cl,
5640                      __attribute__((unused)) void *data)
5641 {
5642         struct cmd_write_reg_result *res = parsed_result;
5643         port_reg_set(res->port_id, res->reg_off, res->value);
5644 }
5645
5646 cmdline_parse_token_string_t cmd_write_reg_write =
5647         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5648 cmdline_parse_token_string_t cmd_write_reg_reg =
5649         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5650 cmdline_parse_token_num_t cmd_write_reg_port_id =
5651         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5652 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5653         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5654 cmdline_parse_token_num_t cmd_write_reg_value =
5655         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5656
5657 cmdline_parse_inst_t cmd_write_reg = {
5658         .f = cmd_write_reg_parsed,
5659         .data = NULL,
5660         .help_str = "write reg port_id reg_off reg_value",
5661         .tokens = {
5662                 (void *)&cmd_write_reg_write,
5663                 (void *)&cmd_write_reg_reg,
5664                 (void *)&cmd_write_reg_port_id,
5665                 (void *)&cmd_write_reg_reg_off,
5666                 (void *)&cmd_write_reg_value,
5667                 NULL,
5668         },
5669 };
5670
5671 /* *** WRITE PORT REGISTER BIT FIELD *** */
5672 struct cmd_write_reg_bit_field_result {
5673         cmdline_fixed_string_t write;
5674         cmdline_fixed_string_t regfield;
5675         uint8_t port_id;
5676         uint32_t reg_off;
5677         uint8_t bit1_pos;
5678         uint8_t bit2_pos;
5679         uint32_t value;
5680 };
5681
5682 static void
5683 cmd_write_reg_bit_field_parsed(void *parsed_result,
5684                                __attribute__((unused)) struct cmdline *cl,
5685                                __attribute__((unused)) void *data)
5686 {
5687         struct cmd_write_reg_bit_field_result *res = parsed_result;
5688         port_reg_bit_field_set(res->port_id, res->reg_off,
5689                           res->bit1_pos, res->bit2_pos, res->value);
5690 }
5691
5692 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5693         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5694                                  "write");
5695 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5696         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5697                                  regfield, "regfield");
5698 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5699         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5700                               UINT8);
5701 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5702         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5703                               UINT32);
5704 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5705         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5706                               UINT8);
5707 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5708         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5709                               UINT8);
5710 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5711         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5712                               UINT32);
5713
5714 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5715         .f = cmd_write_reg_bit_field_parsed,
5716         .data = NULL,
5717         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5718         "(set register bit field between bit_x and bit_y included)",
5719         .tokens = {
5720                 (void *)&cmd_write_reg_bit_field_write,
5721                 (void *)&cmd_write_reg_bit_field_regfield,
5722                 (void *)&cmd_write_reg_bit_field_port_id,
5723                 (void *)&cmd_write_reg_bit_field_reg_off,
5724                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5725                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5726                 (void *)&cmd_write_reg_bit_field_value,
5727                 NULL,
5728         },
5729 };
5730
5731 /* *** WRITE PORT REGISTER BIT *** */
5732 struct cmd_write_reg_bit_result {
5733         cmdline_fixed_string_t write;
5734         cmdline_fixed_string_t regbit;
5735         uint8_t port_id;
5736         uint32_t reg_off;
5737         uint8_t bit_pos;
5738         uint8_t value;
5739 };
5740
5741 static void
5742 cmd_write_reg_bit_parsed(void *parsed_result,
5743                          __attribute__((unused)) struct cmdline *cl,
5744                          __attribute__((unused)) void *data)
5745 {
5746         struct cmd_write_reg_bit_result *res = parsed_result;
5747         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5748 }
5749
5750 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5751         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5752                                  "write");
5753 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5754         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5755                                  regbit, "regbit");
5756 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5757         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5758 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5759         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5760 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5761         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5762 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5763         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5764
5765 cmdline_parse_inst_t cmd_write_reg_bit = {
5766         .f = cmd_write_reg_bit_parsed,
5767         .data = NULL,
5768         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5769         .tokens = {
5770                 (void *)&cmd_write_reg_bit_write,
5771                 (void *)&cmd_write_reg_bit_regbit,
5772                 (void *)&cmd_write_reg_bit_port_id,
5773                 (void *)&cmd_write_reg_bit_reg_off,
5774                 (void *)&cmd_write_reg_bit_bit_pos,
5775                 (void *)&cmd_write_reg_bit_value,
5776                 NULL,
5777         },
5778 };
5779
5780 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5781 struct cmd_read_rxd_txd_result {
5782         cmdline_fixed_string_t read;
5783         cmdline_fixed_string_t rxd_txd;
5784         uint8_t port_id;
5785         uint16_t queue_id;
5786         uint16_t desc_id;
5787 };
5788
5789 static void
5790 cmd_read_rxd_txd_parsed(void *parsed_result,
5791                         __attribute__((unused)) struct cmdline *cl,
5792                         __attribute__((unused)) void *data)
5793 {
5794         struct cmd_read_rxd_txd_result *res = parsed_result;
5795
5796         if (!strcmp(res->rxd_txd, "rxd"))
5797                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5798         else if (!strcmp(res->rxd_txd, "txd"))
5799                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5800 }
5801
5802 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5803         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5804 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5805         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5806                                  "rxd#txd");
5807 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5808         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5809 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5810         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5811 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5812         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5813
5814 cmdline_parse_inst_t cmd_read_rxd_txd = {
5815         .f = cmd_read_rxd_txd_parsed,
5816         .data = NULL,
5817         .help_str = "read rxd|txd port_id queue_id rxd_id",
5818         .tokens = {
5819                 (void *)&cmd_read_rxd_txd_read,
5820                 (void *)&cmd_read_rxd_txd_rxd_txd,
5821                 (void *)&cmd_read_rxd_txd_port_id,
5822                 (void *)&cmd_read_rxd_txd_queue_id,
5823                 (void *)&cmd_read_rxd_txd_desc_id,
5824                 NULL,
5825         },
5826 };
5827
5828 /* *** QUIT *** */
5829 struct cmd_quit_result {
5830         cmdline_fixed_string_t quit;
5831 };
5832
5833 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5834                             struct cmdline *cl,
5835                             __attribute__((unused)) void *data)
5836 {
5837         pmd_test_exit();
5838         cmdline_quit(cl);
5839 }
5840
5841 cmdline_parse_token_string_t cmd_quit_quit =
5842         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5843
5844 cmdline_parse_inst_t cmd_quit = {
5845         .f = cmd_quit_parsed,
5846         .data = NULL,
5847         .help_str = "exit application",
5848         .tokens = {
5849                 (void *)&cmd_quit_quit,
5850                 NULL,
5851         },
5852 };
5853
5854 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5855 struct cmd_mac_addr_result {
5856         cmdline_fixed_string_t mac_addr_cmd;
5857         cmdline_fixed_string_t what;
5858         uint8_t port_num;
5859         struct ether_addr address;
5860 };
5861
5862 static void cmd_mac_addr_parsed(void *parsed_result,
5863                 __attribute__((unused)) struct cmdline *cl,
5864                 __attribute__((unused)) void *data)
5865 {
5866         struct cmd_mac_addr_result *res = parsed_result;
5867         int ret;
5868
5869         if (strcmp(res->what, "add") == 0)
5870                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5871         else
5872                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5873
5874         /* check the return value and print it if is < 0 */
5875         if(ret < 0)
5876                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5877
5878 }
5879
5880 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5881         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5882                                 "mac_addr");
5883 cmdline_parse_token_string_t cmd_mac_addr_what =
5884         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5885                                 "add#remove");
5886 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5887                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5888 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5889                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5890
5891 cmdline_parse_inst_t cmd_mac_addr = {
5892         .f = cmd_mac_addr_parsed,
5893         .data = (void *)0,
5894         .help_str = "mac_addr add|remove X <address>: "
5895                         "add/remove MAC address on port X",
5896         .tokens = {
5897                 (void *)&cmd_mac_addr_cmd,
5898                 (void *)&cmd_mac_addr_what,
5899                 (void *)&cmd_mac_addr_portnum,
5900                 (void *)&cmd_mac_addr_addr,
5901                 NULL,
5902         },
5903 };
5904
5905
5906 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5907 struct cmd_set_qmap_result {
5908         cmdline_fixed_string_t set;
5909         cmdline_fixed_string_t qmap;
5910         cmdline_fixed_string_t what;
5911         uint8_t port_id;
5912         uint16_t queue_id;
5913         uint8_t map_value;
5914 };
5915
5916 static void
5917 cmd_set_qmap_parsed(void *parsed_result,
5918                        __attribute__((unused)) struct cmdline *cl,
5919                        __attribute__((unused)) void *data)
5920 {
5921         struct cmd_set_qmap_result *res = parsed_result;
5922         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5923
5924         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5925 }
5926
5927 cmdline_parse_token_string_t cmd_setqmap_set =
5928         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5929                                  set, "set");
5930 cmdline_parse_token_string_t cmd_setqmap_qmap =
5931         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5932                                  qmap, "stat_qmap");
5933 cmdline_parse_token_string_t cmd_setqmap_what =
5934         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5935                                  what, "tx#rx");
5936 cmdline_parse_token_num_t cmd_setqmap_portid =
5937         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5938                               port_id, UINT8);
5939 cmdline_parse_token_num_t cmd_setqmap_queueid =
5940         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5941                               queue_id, UINT16);
5942 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5943         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5944                               map_value, UINT8);
5945
5946 cmdline_parse_inst_t cmd_set_qmap = {
5947         .f = cmd_set_qmap_parsed,
5948         .data = NULL,
5949         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
5950         .tokens = {
5951                 (void *)&cmd_setqmap_set,
5952                 (void *)&cmd_setqmap_qmap,
5953                 (void *)&cmd_setqmap_what,
5954                 (void *)&cmd_setqmap_portid,
5955                 (void *)&cmd_setqmap_queueid,
5956                 (void *)&cmd_setqmap_mapvalue,
5957                 NULL,
5958         },
5959 };
5960
5961 /* *** CONFIGURE UNICAST HASH TABLE *** */
5962 struct cmd_set_uc_hash_table {
5963         cmdline_fixed_string_t set;
5964         cmdline_fixed_string_t port;
5965         uint8_t port_id;
5966         cmdline_fixed_string_t what;
5967         struct ether_addr address;
5968         cmdline_fixed_string_t mode;
5969 };
5970
5971 static void
5972 cmd_set_uc_hash_parsed(void *parsed_result,
5973                        __attribute__((unused)) struct cmdline *cl,
5974                        __attribute__((unused)) void *data)
5975 {
5976         int ret=0;
5977         struct cmd_set_uc_hash_table *res = parsed_result;
5978
5979         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5980
5981         if (strcmp(res->what, "uta") == 0)
5982                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
5983                                                 &res->address,(uint8_t)is_on);
5984         if (ret < 0)
5985                 printf("bad unicast hash table parameter, return code = %d \n", ret);
5986
5987 }
5988
5989 cmdline_parse_token_string_t cmd_set_uc_hash_set =
5990         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5991                                  set, "set");
5992 cmdline_parse_token_string_t cmd_set_uc_hash_port =
5993         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5994                                  port, "port");
5995 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
5996         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
5997                               port_id, UINT8);
5998 cmdline_parse_token_string_t cmd_set_uc_hash_what =
5999         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6000                                  what, "uta");
6001 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6002         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6003                                 address);
6004 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6005         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6006                                  mode, "on#off");
6007
6008 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6009         .f = cmd_set_uc_hash_parsed,
6010         .data = NULL,
6011         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6012         .tokens = {
6013                 (void *)&cmd_set_uc_hash_set,
6014                 (void *)&cmd_set_uc_hash_port,
6015                 (void *)&cmd_set_uc_hash_portid,
6016                 (void *)&cmd_set_uc_hash_what,
6017                 (void *)&cmd_set_uc_hash_mac,
6018                 (void *)&cmd_set_uc_hash_mode,
6019                 NULL,
6020         },
6021 };
6022
6023 struct cmd_set_uc_all_hash_table {
6024         cmdline_fixed_string_t set;
6025         cmdline_fixed_string_t port;
6026         uint8_t port_id;
6027         cmdline_fixed_string_t what;
6028         cmdline_fixed_string_t value;
6029         cmdline_fixed_string_t mode;
6030 };
6031
6032 static void
6033 cmd_set_uc_all_hash_parsed(void *parsed_result,
6034                        __attribute__((unused)) struct cmdline *cl,
6035                        __attribute__((unused)) void *data)
6036 {
6037         int ret=0;
6038         struct cmd_set_uc_all_hash_table *res = parsed_result;
6039
6040         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6041
6042         if ((strcmp(res->what, "uta") == 0) &&
6043                 (strcmp(res->value, "all") == 0))
6044                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6045         if (ret < 0)
6046                 printf("bad unicast hash table parameter,"
6047                         "return code = %d \n", ret);
6048 }
6049
6050 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6051         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6052                                  set, "set");
6053 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6054         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6055                                  port, "port");
6056 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6057         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6058                               port_id, UINT8);
6059 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6060         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6061                                  what, "uta");
6062 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6063         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6064                                 value,"all");
6065 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6066         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6067                                  mode, "on#off");
6068
6069 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6070         .f = cmd_set_uc_all_hash_parsed,
6071         .data = NULL,
6072         .help_str = "set port X uta all on|off (X = port number)",
6073         .tokens = {
6074                 (void *)&cmd_set_uc_all_hash_set,
6075                 (void *)&cmd_set_uc_all_hash_port,
6076                 (void *)&cmd_set_uc_all_hash_portid,
6077                 (void *)&cmd_set_uc_all_hash_what,
6078                 (void *)&cmd_set_uc_all_hash_value,
6079                 (void *)&cmd_set_uc_all_hash_mode,
6080                 NULL,
6081         },
6082 };
6083
6084 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6085 struct cmd_set_vf_macvlan_filter {
6086         cmdline_fixed_string_t set;
6087         cmdline_fixed_string_t port;
6088         uint8_t port_id;
6089         cmdline_fixed_string_t vf;
6090         uint8_t vf_id;
6091         struct ether_addr address;
6092         cmdline_fixed_string_t filter_type;
6093         cmdline_fixed_string_t mode;
6094 };
6095
6096 static void
6097 cmd_set_vf_macvlan_parsed(void *parsed_result,
6098                        __attribute__((unused)) struct cmdline *cl,
6099                        __attribute__((unused)) void *data)
6100 {
6101         int is_on, ret = 0;
6102         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6103         struct rte_eth_mac_filter filter;
6104
6105         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6106
6107         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6108
6109         /* set VF MAC filter */
6110         filter.is_vf = 1;
6111
6112         /* set VF ID */
6113         filter.dst_id = res->vf_id;
6114
6115         if (!strcmp(res->filter_type, "exact-mac"))
6116                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6117         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6118                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6119         else if (!strcmp(res->filter_type, "hashmac"))
6120                 filter.filter_type = RTE_MAC_HASH_MATCH;
6121         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6122                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6123
6124         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6125
6126         if (is_on)
6127                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6128                                         RTE_ETH_FILTER_MACVLAN,
6129                                         RTE_ETH_FILTER_ADD,
6130                                          &filter);
6131         else
6132                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6133                                         RTE_ETH_FILTER_MACVLAN,
6134                                         RTE_ETH_FILTER_DELETE,
6135                                         &filter);
6136
6137         if (ret < 0)
6138                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6139
6140 }
6141
6142 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6143         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6144                                  set, "set");
6145 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6146         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6147                                  port, "port");
6148 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6149         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6150                               port_id, UINT8);
6151 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6152         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6153                                  vf, "vf");
6154 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6155         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6156                                 vf_id, UINT8);
6157 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6158         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6159                                 address);
6160 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6161         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6162                                 filter_type, "exact-mac#exact-mac-vlan"
6163                                 "#hashmac#hashmac-vlan");
6164 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6165         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6166                                  mode, "on#off");
6167
6168 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6169         .f = cmd_set_vf_macvlan_parsed,
6170         .data = NULL,
6171         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6172                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6173                         "on|off\n"
6174                         "exact match rule:exact match of MAC or MAC and VLAN; "
6175                         "hash match rule: hash match of MAC and exact match "
6176                         "of VLAN",
6177         .tokens = {
6178                 (void *)&cmd_set_vf_macvlan_set,
6179                 (void *)&cmd_set_vf_macvlan_port,
6180                 (void *)&cmd_set_vf_macvlan_portid,
6181                 (void *)&cmd_set_vf_macvlan_vf,
6182                 (void *)&cmd_set_vf_macvlan_vf_id,
6183                 (void *)&cmd_set_vf_macvlan_mac,
6184                 (void *)&cmd_set_vf_macvlan_filter_type,
6185                 (void *)&cmd_set_vf_macvlan_mode,
6186                 NULL,
6187         },
6188 };
6189
6190 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6191 struct cmd_set_vf_traffic {
6192         cmdline_fixed_string_t set;
6193         cmdline_fixed_string_t port;
6194         uint8_t port_id;
6195         cmdline_fixed_string_t vf;
6196         uint8_t vf_id;
6197         cmdline_fixed_string_t what;
6198         cmdline_fixed_string_t mode;
6199 };
6200
6201 static void
6202 cmd_set_vf_traffic_parsed(void *parsed_result,
6203                        __attribute__((unused)) struct cmdline *cl,
6204                        __attribute__((unused)) void *data)
6205 {
6206         struct cmd_set_vf_traffic *res = parsed_result;
6207         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6208         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6209
6210         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6211 }
6212
6213 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6214         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6215                                  set, "set");
6216 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6217         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6218                                  port, "port");
6219 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6220         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6221                               port_id, UINT8);
6222 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6223         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6224                                  vf, "vf");
6225 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6226         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6227                               vf_id, UINT8);
6228 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6229         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6230                                  what, "tx#rx");
6231 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6232         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6233                                  mode, "on#off");
6234
6235 cmdline_parse_inst_t cmd_set_vf_traffic = {
6236         .f = cmd_set_vf_traffic_parsed,
6237         .data = NULL,
6238         .help_str = "set port X vf Y rx|tx on|off"
6239                         "(X = port number,Y = vf id)",
6240         .tokens = {
6241                 (void *)&cmd_setvf_traffic_set,
6242                 (void *)&cmd_setvf_traffic_port,
6243                 (void *)&cmd_setvf_traffic_portid,
6244                 (void *)&cmd_setvf_traffic_vf,
6245                 (void *)&cmd_setvf_traffic_vfid,
6246                 (void *)&cmd_setvf_traffic_what,
6247                 (void *)&cmd_setvf_traffic_mode,
6248                 NULL,
6249         },
6250 };
6251
6252 /* *** CONFIGURE VF RECEIVE MODE *** */
6253 struct cmd_set_vf_rxmode {
6254         cmdline_fixed_string_t set;
6255         cmdline_fixed_string_t port;
6256         uint8_t port_id;
6257         cmdline_fixed_string_t vf;
6258         uint8_t vf_id;
6259         cmdline_fixed_string_t what;
6260         cmdline_fixed_string_t mode;
6261         cmdline_fixed_string_t on;
6262 };
6263
6264 static void
6265 cmd_set_vf_rxmode_parsed(void *parsed_result,
6266                        __attribute__((unused)) struct cmdline *cl,
6267                        __attribute__((unused)) void *data)
6268 {
6269         int ret;
6270         uint16_t rx_mode = 0;
6271         struct cmd_set_vf_rxmode *res = parsed_result;
6272
6273         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6274         if (!strcmp(res->what,"rxmode")) {
6275                 if (!strcmp(res->mode, "AUPE"))
6276                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6277                 else if (!strcmp(res->mode, "ROPE"))
6278                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6279                 else if (!strcmp(res->mode, "BAM"))
6280                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6281                 else if (!strncmp(res->mode, "MPE",3))
6282                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6283         }
6284
6285         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6286         if (ret < 0)
6287                 printf("bad VF receive mode parameter, return code = %d \n",
6288                 ret);
6289 }
6290
6291 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6292         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6293                                  set, "set");
6294 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6295         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6296                                  port, "port");
6297 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6298         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6299                               port_id, UINT8);
6300 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6301         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6302                                  vf, "vf");
6303 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6304         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6305                               vf_id, UINT8);
6306 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6307         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6308                                  what, "rxmode");
6309 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6310         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6311                                  mode, "AUPE#ROPE#BAM#MPE");
6312 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6313         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6314                                  on, "on#off");
6315
6316 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6317         .f = cmd_set_vf_rxmode_parsed,
6318         .data = NULL,
6319         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6320         .tokens = {
6321                 (void *)&cmd_set_vf_rxmode_set,
6322                 (void *)&cmd_set_vf_rxmode_port,
6323                 (void *)&cmd_set_vf_rxmode_portid,
6324                 (void *)&cmd_set_vf_rxmode_vf,
6325                 (void *)&cmd_set_vf_rxmode_vfid,
6326                 (void *)&cmd_set_vf_rxmode_what,
6327                 (void *)&cmd_set_vf_rxmode_mode,
6328                 (void *)&cmd_set_vf_rxmode_on,
6329                 NULL,
6330         },
6331 };
6332
6333 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6334 struct cmd_vf_mac_addr_result {
6335         cmdline_fixed_string_t mac_addr_cmd;
6336         cmdline_fixed_string_t what;
6337         cmdline_fixed_string_t port;
6338         uint8_t port_num;
6339         cmdline_fixed_string_t vf;
6340         uint8_t vf_num;
6341         struct ether_addr address;
6342 };
6343
6344 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6345                 __attribute__((unused)) struct cmdline *cl,
6346                 __attribute__((unused)) void *data)
6347 {
6348         struct cmd_vf_mac_addr_result *res = parsed_result;
6349         int ret = 0;
6350
6351         if (strcmp(res->what, "add") == 0)
6352                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6353                                         &res->address, res->vf_num);
6354         if(ret < 0)
6355                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6356
6357 }
6358
6359 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6360         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6361                                 mac_addr_cmd,"mac_addr");
6362 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6363         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6364                                 what,"add");
6365 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6366         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6367                                 port,"port");
6368 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6369         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6370                                 port_num, UINT8);
6371 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6372         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6373                                 vf,"vf");
6374 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6375         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6376                                 vf_num, UINT8);
6377 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6378         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6379                                 address);
6380
6381 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6382         .f = cmd_vf_mac_addr_parsed,
6383         .data = (void *)0,
6384         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6385         "Y = VF number)add MAC address filtering for a VF on port X",
6386         .tokens = {
6387                 (void *)&cmd_vf_mac_addr_cmd,
6388                 (void *)&cmd_vf_mac_addr_what,
6389                 (void *)&cmd_vf_mac_addr_port,
6390                 (void *)&cmd_vf_mac_addr_portnum,
6391                 (void *)&cmd_vf_mac_addr_vf,
6392                 (void *)&cmd_vf_mac_addr_vfnum,
6393                 (void *)&cmd_vf_mac_addr_addr,
6394                 NULL,
6395         },
6396 };
6397
6398 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6399 struct cmd_vf_rx_vlan_filter {
6400         cmdline_fixed_string_t rx_vlan;
6401         cmdline_fixed_string_t what;
6402         uint16_t vlan_id;
6403         cmdline_fixed_string_t port;
6404         uint8_t port_id;
6405         cmdline_fixed_string_t vf;
6406         uint64_t vf_mask;
6407 };
6408
6409 static void
6410 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6411                           __attribute__((unused)) struct cmdline *cl,
6412                           __attribute__((unused)) void *data)
6413 {
6414         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6415
6416         if (!strcmp(res->what, "add"))
6417                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6418         else
6419                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6420 }
6421
6422 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6423         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6424                                  rx_vlan, "rx_vlan");
6425 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6426         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6427                                  what, "add#rm");
6428 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6429         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6430                               vlan_id, UINT16);
6431 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6432         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6433                                  port, "port");
6434 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6435         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6436                               port_id, UINT8);
6437 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6438         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6439                                  vf, "vf");
6440 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6441         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6442                               vf_mask, UINT64);
6443
6444 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6445         .f = cmd_vf_rx_vlan_filter_parsed,
6446         .data = NULL,
6447         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6448                 "Y = port number,Z = hexadecimal VF mask)",
6449         .tokens = {
6450                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6451                 (void *)&cmd_vf_rx_vlan_filter_what,
6452                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6453                 (void *)&cmd_vf_rx_vlan_filter_port,
6454                 (void *)&cmd_vf_rx_vlan_filter_portid,
6455                 (void *)&cmd_vf_rx_vlan_filter_vf,
6456                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6457                 NULL,
6458         },
6459 };
6460
6461 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6462 struct cmd_queue_rate_limit_result {
6463         cmdline_fixed_string_t set;
6464         cmdline_fixed_string_t port;
6465         uint8_t port_num;
6466         cmdline_fixed_string_t queue;
6467         uint8_t queue_num;
6468         cmdline_fixed_string_t rate;
6469         uint16_t rate_num;
6470 };
6471
6472 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6473                 __attribute__((unused)) struct cmdline *cl,
6474                 __attribute__((unused)) void *data)
6475 {
6476         struct cmd_queue_rate_limit_result *res = parsed_result;
6477         int ret = 0;
6478
6479         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6480                 && (strcmp(res->queue, "queue") == 0)
6481                 && (strcmp(res->rate, "rate") == 0))
6482                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6483                                         res->rate_num);
6484         if (ret < 0)
6485                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6486
6487 }
6488
6489 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6490         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6491                                 set, "set");
6492 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6493         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6494                                 port, "port");
6495 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6496         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6497                                 port_num, UINT8);
6498 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6499         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6500                                 queue, "queue");
6501 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6502         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6503                                 queue_num, UINT8);
6504 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6505         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6506                                 rate, "rate");
6507 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6508         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6509                                 rate_num, UINT16);
6510
6511 cmdline_parse_inst_t cmd_queue_rate_limit = {
6512         .f = cmd_queue_rate_limit_parsed,
6513         .data = (void *)0,
6514         .help_str = "set port X queue Y rate Z:(X = port number,"
6515         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6516         .tokens = {
6517                 (void *)&cmd_queue_rate_limit_set,
6518                 (void *)&cmd_queue_rate_limit_port,
6519                 (void *)&cmd_queue_rate_limit_portnum,
6520                 (void *)&cmd_queue_rate_limit_queue,
6521                 (void *)&cmd_queue_rate_limit_queuenum,
6522                 (void *)&cmd_queue_rate_limit_rate,
6523                 (void *)&cmd_queue_rate_limit_ratenum,
6524                 NULL,
6525         },
6526 };
6527
6528 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6529 struct cmd_vf_rate_limit_result {
6530         cmdline_fixed_string_t set;
6531         cmdline_fixed_string_t port;
6532         uint8_t port_num;
6533         cmdline_fixed_string_t vf;
6534         uint8_t vf_num;
6535         cmdline_fixed_string_t rate;
6536         uint16_t rate_num;
6537         cmdline_fixed_string_t q_msk;
6538         uint64_t q_msk_val;
6539 };
6540
6541 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6542                 __attribute__((unused)) struct cmdline *cl,
6543                 __attribute__((unused)) void *data)
6544 {
6545         struct cmd_vf_rate_limit_result *res = parsed_result;
6546         int ret = 0;
6547
6548         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6549                 && (strcmp(res->vf, "vf") == 0)
6550                 && (strcmp(res->rate, "rate") == 0)
6551                 && (strcmp(res->q_msk, "queue_mask") == 0))
6552                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6553                                         res->rate_num, res->q_msk_val);
6554         if (ret < 0)
6555                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6556
6557 }
6558
6559 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6560         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6561                                 set, "set");
6562 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6563         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6564                                 port, "port");
6565 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6566         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6567                                 port_num, UINT8);
6568 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6569         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6570                                 vf, "vf");
6571 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6572         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6573                                 vf_num, UINT8);
6574 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6575         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6576                                 rate, "rate");
6577 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6578         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6579                                 rate_num, UINT16);
6580 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6581         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6582                                 q_msk, "queue_mask");
6583 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6584         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6585                                 q_msk_val, UINT64);
6586
6587 cmdline_parse_inst_t cmd_vf_rate_limit = {
6588         .f = cmd_vf_rate_limit_parsed,
6589         .data = (void *)0,
6590         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6591         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6592         "for queues of VF on port X",
6593         .tokens = {
6594                 (void *)&cmd_vf_rate_limit_set,
6595                 (void *)&cmd_vf_rate_limit_port,
6596                 (void *)&cmd_vf_rate_limit_portnum,
6597                 (void *)&cmd_vf_rate_limit_vf,
6598                 (void *)&cmd_vf_rate_limit_vfnum,
6599                 (void *)&cmd_vf_rate_limit_rate,
6600                 (void *)&cmd_vf_rate_limit_ratenum,
6601                 (void *)&cmd_vf_rate_limit_q_msk,
6602                 (void *)&cmd_vf_rate_limit_q_msk_val,
6603                 NULL,
6604         },
6605 };
6606
6607 /* *** ADD TUNNEL FILTER OF A PORT *** */
6608 struct cmd_tunnel_filter_result {
6609         cmdline_fixed_string_t cmd;
6610         cmdline_fixed_string_t what;
6611         uint8_t port_id;
6612         struct ether_addr outer_mac;
6613         struct ether_addr inner_mac;
6614         cmdline_ipaddr_t ip_value;
6615         uint16_t inner_vlan;
6616         cmdline_fixed_string_t tunnel_type;
6617         cmdline_fixed_string_t filter_type;
6618         uint32_t tenant_id;
6619         uint16_t queue_num;
6620 };
6621
6622 static void
6623 cmd_tunnel_filter_parsed(void *parsed_result,
6624                           __attribute__((unused)) struct cmdline *cl,
6625                           __attribute__((unused)) void *data)
6626 {
6627         struct cmd_tunnel_filter_result *res = parsed_result;
6628         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6629         int ret = 0;
6630
6631         tunnel_filter_conf.outer_mac = &res->outer_mac;
6632         tunnel_filter_conf.inner_mac = &res->inner_mac;
6633         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6634
6635         if (res->ip_value.family == AF_INET) {
6636                 tunnel_filter_conf.ip_addr.ipv4_addr =
6637                         res->ip_value.addr.ipv4.s_addr;
6638                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6639         } else {
6640                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6641                         &(res->ip_value.addr.ipv6),
6642                         sizeof(struct in6_addr));
6643                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6644         }
6645
6646         if (!strcmp(res->filter_type, "imac-ivlan"))
6647                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6648         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6649                 tunnel_filter_conf.filter_type =
6650                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6651         else if (!strcmp(res->filter_type, "imac-tenid"))
6652                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6653         else if (!strcmp(res->filter_type, "imac"))
6654                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6655         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6656                 tunnel_filter_conf.filter_type =
6657                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6658         else {
6659                 printf("The filter type is not supported");
6660                 return;
6661         }
6662
6663         if (!strcmp(res->tunnel_type, "vxlan"))
6664                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6665         else if (!strcmp(res->tunnel_type, "nvgre"))
6666                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
6667         else {
6668                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
6669                 return;
6670         }
6671
6672         tunnel_filter_conf.tenant_id = res->tenant_id;
6673         tunnel_filter_conf.queue_id = res->queue_num;
6674         if (!strcmp(res->what, "add"))
6675                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6676                                         RTE_ETH_FILTER_TUNNEL,
6677                                         RTE_ETH_FILTER_ADD,
6678                                         &tunnel_filter_conf);
6679         else
6680                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6681                                         RTE_ETH_FILTER_TUNNEL,
6682                                         RTE_ETH_FILTER_DELETE,
6683                                         &tunnel_filter_conf);
6684         if (ret < 0)
6685                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6686                                 strerror(-ret));
6687
6688 }
6689 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6690         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6691         cmd, "tunnel_filter");
6692 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6693         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6694         what, "add#rm");
6695 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6696         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6697         port_id, UINT8);
6698 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6699         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6700         outer_mac);
6701 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6702         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6703         inner_mac);
6704 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6705         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6706         inner_vlan, UINT16);
6707 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6708         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6709         ip_value);
6710 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6711         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6712         tunnel_type, "vxlan#nvgre");
6713
6714 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6715         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6716         filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6717                 "imac#omac-imac-tenid");
6718 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6719         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6720         tenant_id, UINT32);
6721 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6722         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6723         queue_num, UINT16);
6724
6725 cmdline_parse_inst_t cmd_tunnel_filter = {
6726         .f = cmd_tunnel_filter_parsed,
6727         .data = (void *)0,
6728         .help_str = "add/rm tunnel filter of a port: "
6729                         "tunnel_filter add port_id outer_mac inner_mac ip "
6730                         "inner_vlan tunnel_type(vxlan|nvgre) filter_type "
6731                         "(imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6732                         "imac|omac-imac-tenid) "
6733                         "tenant_id queue_num",
6734         .tokens = {
6735                 (void *)&cmd_tunnel_filter_cmd,
6736                 (void *)&cmd_tunnel_filter_what,
6737                 (void *)&cmd_tunnel_filter_port_id,
6738                 (void *)&cmd_tunnel_filter_outer_mac,
6739                 (void *)&cmd_tunnel_filter_inner_mac,
6740                 (void *)&cmd_tunnel_filter_ip_value,
6741                 (void *)&cmd_tunnel_filter_innner_vlan,
6742                 (void *)&cmd_tunnel_filter_tunnel_type,
6743                 (void *)&cmd_tunnel_filter_filter_type,
6744                 (void *)&cmd_tunnel_filter_tenant_id,
6745                 (void *)&cmd_tunnel_filter_queue_num,
6746                 NULL,
6747         },
6748 };
6749
6750 /* *** CONFIGURE TUNNEL UDP PORT *** */
6751 struct cmd_tunnel_udp_config {
6752         cmdline_fixed_string_t cmd;
6753         cmdline_fixed_string_t what;
6754         uint16_t udp_port;
6755         uint8_t port_id;
6756 };
6757
6758 static void
6759 cmd_tunnel_udp_config_parsed(void *parsed_result,
6760                           __attribute__((unused)) struct cmdline *cl,
6761                           __attribute__((unused)) void *data)
6762 {
6763         struct cmd_tunnel_udp_config *res = parsed_result;
6764         struct rte_eth_udp_tunnel tunnel_udp;
6765         int ret;
6766
6767         tunnel_udp.udp_port = res->udp_port;
6768
6769         if (!strcmp(res->cmd, "rx_vxlan_port"))
6770                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6771
6772         if (!strcmp(res->what, "add"))
6773                 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp);
6774         else
6775                 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp);
6776
6777         if (ret < 0)
6778                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6779 }
6780
6781 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6782         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6783                                 cmd, "rx_vxlan_port");
6784 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6785         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6786                                 what, "add#rm");
6787 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6788         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6789                                 udp_port, UINT16);
6790 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6791         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6792                                 port_id, UINT8);
6793
6794 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6795         .f = cmd_tunnel_udp_config_parsed,
6796         .data = (void *)0,
6797         .help_str = "add/rm an tunneling UDP port filter: "
6798                         "rx_vxlan_port add udp_port port_id",
6799         .tokens = {
6800                 (void *)&cmd_tunnel_udp_config_cmd,
6801                 (void *)&cmd_tunnel_udp_config_what,
6802                 (void *)&cmd_tunnel_udp_config_udp_port,
6803                 (void *)&cmd_tunnel_udp_config_port_id,
6804                 NULL,
6805         },
6806 };
6807
6808 /* *** GLOBAL CONFIG *** */
6809 struct cmd_global_config_result {
6810         cmdline_fixed_string_t cmd;
6811         uint8_t port_id;
6812         cmdline_fixed_string_t cfg_type;
6813         uint8_t len;
6814 };
6815
6816 static void
6817 cmd_global_config_parsed(void *parsed_result,
6818                          __attribute__((unused)) struct cmdline *cl,
6819                          __attribute__((unused)) void *data)
6820 {
6821         struct cmd_global_config_result *res = parsed_result;
6822         struct rte_eth_global_cfg conf;
6823         int ret;
6824
6825         memset(&conf, 0, sizeof(conf));
6826         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
6827         conf.cfg.gre_key_len = res->len;
6828         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
6829                                       RTE_ETH_FILTER_SET, &conf);
6830         if (ret != 0)
6831                 printf("Global config error\n");
6832 }
6833
6834 cmdline_parse_token_string_t cmd_global_config_cmd =
6835         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
6836                 "global_config");
6837 cmdline_parse_token_num_t cmd_global_config_port_id =
6838         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
6839 cmdline_parse_token_string_t cmd_global_config_type =
6840         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
6841                 cfg_type, "gre-key-len");
6842 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
6843         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
6844                 len, UINT8);
6845
6846 cmdline_parse_inst_t cmd_global_config = {
6847         .f = cmd_global_config_parsed,
6848         .data = (void *)NULL,
6849         .help_str = "global_config <port_id> gre-key-len <number>",
6850         .tokens = {
6851                 (void *)&cmd_global_config_cmd,
6852                 (void *)&cmd_global_config_port_id,
6853                 (void *)&cmd_global_config_type,
6854                 (void *)&cmd_global_config_gre_key_len,
6855                 NULL,
6856         },
6857 };
6858
6859 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6860 struct cmd_set_mirror_mask_result {
6861         cmdline_fixed_string_t set;
6862         cmdline_fixed_string_t port;
6863         uint8_t port_id;
6864         cmdline_fixed_string_t mirror;
6865         uint8_t rule_id;
6866         cmdline_fixed_string_t what;
6867         cmdline_fixed_string_t value;
6868         cmdline_fixed_string_t dstpool;
6869         uint8_t dstpool_id;
6870         cmdline_fixed_string_t on;
6871 };
6872
6873 cmdline_parse_token_string_t cmd_mirror_mask_set =
6874         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6875                                 set, "set");
6876 cmdline_parse_token_string_t cmd_mirror_mask_port =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6878                                 port, "port");
6879 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6880         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6881                                 port_id, UINT8);
6882 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6883         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6884                                 mirror, "mirror-rule");
6885 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6886         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6887                                 rule_id, UINT8);
6888 cmdline_parse_token_string_t cmd_mirror_mask_what =
6889         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6890                                 what, "pool-mirror-up#pool-mirror-down"
6891                                       "#vlan-mirror");
6892 cmdline_parse_token_string_t cmd_mirror_mask_value =
6893         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6894                                 value, NULL);
6895 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6896         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6897                                 dstpool, "dst-pool");
6898 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6899         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6900                                 dstpool_id, UINT8);
6901 cmdline_parse_token_string_t cmd_mirror_mask_on =
6902         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6903                                 on, "on#off");
6904
6905 static void
6906 cmd_set_mirror_mask_parsed(void *parsed_result,
6907                        __attribute__((unused)) struct cmdline *cl,
6908                        __attribute__((unused)) void *data)
6909 {
6910         int ret,nb_item,i;
6911         struct cmd_set_mirror_mask_result *res = parsed_result;
6912         struct rte_eth_mirror_conf mr_conf;
6913
6914         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6915
6916         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
6917
6918         mr_conf.dst_pool = res->dstpool_id;
6919
6920         if (!strcmp(res->what, "pool-mirror-up")) {
6921                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6922                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
6923         } else if (!strcmp(res->what, "pool-mirror-down")) {
6924                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6925                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
6926         } else if (!strcmp(res->what, "vlan-mirror")) {
6927                 mr_conf.rule_type = ETH_MIRROR_VLAN;
6928                 nb_item = parse_item_list(res->value, "vlan",
6929                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
6930                 if (nb_item <= 0)
6931                         return;
6932
6933                 for (i = 0; i < nb_item; i++) {
6934                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6935                                 printf("Invalid vlan_id: must be < 4096\n");
6936                                 return;
6937                         }
6938
6939                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6940                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6941                 }
6942         }
6943
6944         if (!strcmp(res->on, "on"))
6945                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6946                                                 res->rule_id, 1);
6947         else
6948                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6949                                                 res->rule_id, 0);
6950         if (ret < 0)
6951                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6952 }
6953
6954 cmdline_parse_inst_t cmd_set_mirror_mask = {
6955                 .f = cmd_set_mirror_mask_parsed,
6956                 .data = NULL,
6957                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
6958                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
6959                 .tokens = {
6960                         (void *)&cmd_mirror_mask_set,
6961                         (void *)&cmd_mirror_mask_port,
6962                         (void *)&cmd_mirror_mask_portid,
6963                         (void *)&cmd_mirror_mask_mirror,
6964                         (void *)&cmd_mirror_mask_ruleid,
6965                         (void *)&cmd_mirror_mask_what,
6966                         (void *)&cmd_mirror_mask_value,
6967                         (void *)&cmd_mirror_mask_dstpool,
6968                         (void *)&cmd_mirror_mask_poolid,
6969                         (void *)&cmd_mirror_mask_on,
6970                         NULL,
6971                 },
6972 };
6973
6974 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
6975 struct cmd_set_mirror_link_result {
6976         cmdline_fixed_string_t set;
6977         cmdline_fixed_string_t port;
6978         uint8_t port_id;
6979         cmdline_fixed_string_t mirror;
6980         uint8_t rule_id;
6981         cmdline_fixed_string_t what;
6982         cmdline_fixed_string_t dstpool;
6983         uint8_t dstpool_id;
6984         cmdline_fixed_string_t on;
6985 };
6986
6987 cmdline_parse_token_string_t cmd_mirror_link_set =
6988         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6989                                  set, "set");
6990 cmdline_parse_token_string_t cmd_mirror_link_port =
6991         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6992                                 port, "port");
6993 cmdline_parse_token_num_t cmd_mirror_link_portid =
6994         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6995                                 port_id, UINT8);
6996 cmdline_parse_token_string_t cmd_mirror_link_mirror =
6997         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6998                                 mirror, "mirror-rule");
6999 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7000         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7001                             rule_id, UINT8);
7002 cmdline_parse_token_string_t cmd_mirror_link_what =
7003         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7004                                 what, "uplink-mirror#downlink-mirror");
7005 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7006         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7007                                 dstpool, "dst-pool");
7008 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7009         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7010                                 dstpool_id, UINT8);
7011 cmdline_parse_token_string_t cmd_mirror_link_on =
7012         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7013                                 on, "on#off");
7014
7015 static void
7016 cmd_set_mirror_link_parsed(void *parsed_result,
7017                        __attribute__((unused)) struct cmdline *cl,
7018                        __attribute__((unused)) void *data)
7019 {
7020         int ret;
7021         struct cmd_set_mirror_link_result *res = parsed_result;
7022         struct rte_eth_mirror_conf mr_conf;
7023
7024         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7025         if (!strcmp(res->what, "uplink-mirror"))
7026                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7027         else
7028                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7029
7030         mr_conf.dst_pool = res->dstpool_id;
7031
7032         if (!strcmp(res->on, "on"))
7033                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7034                                                 res->rule_id, 1);
7035         else
7036                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7037                                                 res->rule_id, 0);
7038
7039         /* check the return value and print it if is < 0 */
7040         if (ret < 0)
7041                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7042
7043 }
7044
7045 cmdline_parse_inst_t cmd_set_mirror_link = {
7046                 .f = cmd_set_mirror_link_parsed,
7047                 .data = NULL,
7048                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7049                         "downlink-mirror dst-pool Z on|off",
7050                 .tokens = {
7051                         (void *)&cmd_mirror_link_set,
7052                         (void *)&cmd_mirror_link_port,
7053                         (void *)&cmd_mirror_link_portid,
7054                         (void *)&cmd_mirror_link_mirror,
7055                         (void *)&cmd_mirror_link_ruleid,
7056                         (void *)&cmd_mirror_link_what,
7057                         (void *)&cmd_mirror_link_dstpool,
7058                         (void *)&cmd_mirror_link_poolid,
7059                         (void *)&cmd_mirror_link_on,
7060                         NULL,
7061                 },
7062 };
7063
7064 /* *** RESET VM MIRROR RULE *** */
7065 struct cmd_rm_mirror_rule_result {
7066         cmdline_fixed_string_t reset;
7067         cmdline_fixed_string_t port;
7068         uint8_t port_id;
7069         cmdline_fixed_string_t mirror;
7070         uint8_t rule_id;
7071 };
7072
7073 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7074         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7075                                  reset, "reset");
7076 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7077         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7078                                 port, "port");
7079 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7080         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7081                                 port_id, UINT8);
7082 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7083         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7084                                 mirror, "mirror-rule");
7085 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7086         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7087                                 rule_id, UINT8);
7088
7089 static void
7090 cmd_reset_mirror_rule_parsed(void *parsed_result,
7091                        __attribute__((unused)) struct cmdline *cl,
7092                        __attribute__((unused)) void *data)
7093 {
7094         int ret;
7095         struct cmd_set_mirror_link_result *res = parsed_result;
7096         /* check rule_id */
7097         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7098         if(ret < 0)
7099                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7100 }
7101
7102 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7103                 .f = cmd_reset_mirror_rule_parsed,
7104                 .data = NULL,
7105                 .help_str = "reset port X mirror-rule Y",
7106                 .tokens = {
7107                         (void *)&cmd_rm_mirror_rule_reset,
7108                         (void *)&cmd_rm_mirror_rule_port,
7109                         (void *)&cmd_rm_mirror_rule_portid,
7110                         (void *)&cmd_rm_mirror_rule_mirror,
7111                         (void *)&cmd_rm_mirror_rule_ruleid,
7112                         NULL,
7113                 },
7114 };
7115
7116 /* ******************************************************************************** */
7117
7118 struct cmd_dump_result {
7119         cmdline_fixed_string_t dump;
7120 };
7121
7122 static void
7123 dump_struct_sizes(void)
7124 {
7125 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7126         DUMP_SIZE(struct rte_mbuf);
7127         DUMP_SIZE(struct rte_mempool);
7128         DUMP_SIZE(struct rte_ring);
7129 #undef DUMP_SIZE
7130 }
7131
7132 static void cmd_dump_parsed(void *parsed_result,
7133                             __attribute__((unused)) struct cmdline *cl,
7134                             __attribute__((unused)) void *data)
7135 {
7136         struct cmd_dump_result *res = parsed_result;
7137
7138         if (!strcmp(res->dump, "dump_physmem"))
7139                 rte_dump_physmem_layout(stdout);
7140         else if (!strcmp(res->dump, "dump_memzone"))
7141                 rte_memzone_dump(stdout);
7142         else if (!strcmp(res->dump, "dump_log_history"))
7143                 rte_log_dump_history(stdout);
7144         else if (!strcmp(res->dump, "dump_struct_sizes"))
7145                 dump_struct_sizes();
7146         else if (!strcmp(res->dump, "dump_ring"))
7147                 rte_ring_list_dump(stdout);
7148         else if (!strcmp(res->dump, "dump_mempool"))
7149                 rte_mempool_list_dump(stdout);
7150         else if (!strcmp(res->dump, "dump_devargs"))
7151                 rte_eal_devargs_dump(stdout);
7152 }
7153
7154 cmdline_parse_token_string_t cmd_dump_dump =
7155         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7156                 "dump_physmem#"
7157                 "dump_memzone#"
7158                 "dump_log_history#"
7159                 "dump_struct_sizes#"
7160                 "dump_ring#"
7161                 "dump_mempool#"
7162                 "dump_devargs");
7163
7164 cmdline_parse_inst_t cmd_dump = {
7165         .f = cmd_dump_parsed,  /* function to call */
7166         .data = NULL,      /* 2nd arg of func */
7167         .help_str = "dump status",
7168         .tokens = {        /* token list, NULL terminated */
7169                 (void *)&cmd_dump_dump,
7170                 NULL,
7171         },
7172 };
7173
7174 /* ******************************************************************************** */
7175
7176 struct cmd_dump_one_result {
7177         cmdline_fixed_string_t dump;
7178         cmdline_fixed_string_t name;
7179 };
7180
7181 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7182                                 __attribute__((unused)) void *data)
7183 {
7184         struct cmd_dump_one_result *res = parsed_result;
7185
7186         if (!strcmp(res->dump, "dump_ring")) {
7187                 struct rte_ring *r;
7188                 r = rte_ring_lookup(res->name);
7189                 if (r == NULL) {
7190                         cmdline_printf(cl, "Cannot find ring\n");
7191                         return;
7192                 }
7193                 rte_ring_dump(stdout, r);
7194         } else if (!strcmp(res->dump, "dump_mempool")) {
7195                 struct rte_mempool *mp;
7196                 mp = rte_mempool_lookup(res->name);
7197                 if (mp == NULL) {
7198                         cmdline_printf(cl, "Cannot find mempool\n");
7199                         return;
7200                 }
7201                 rte_mempool_dump(stdout, mp);
7202         }
7203 }
7204
7205 cmdline_parse_token_string_t cmd_dump_one_dump =
7206         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7207                                  "dump_ring#dump_mempool");
7208
7209 cmdline_parse_token_string_t cmd_dump_one_name =
7210         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7211
7212 cmdline_parse_inst_t cmd_dump_one = {
7213         .f = cmd_dump_one_parsed,  /* function to call */
7214         .data = NULL,      /* 2nd arg of func */
7215         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7216         .tokens = {        /* token list, NULL terminated */
7217                 (void *)&cmd_dump_one_dump,
7218                 (void *)&cmd_dump_one_name,
7219                 NULL,
7220         },
7221 };
7222
7223 /* *** Add/Del syn filter *** */
7224 struct cmd_syn_filter_result {
7225         cmdline_fixed_string_t filter;
7226         uint8_t port_id;
7227         cmdline_fixed_string_t ops;
7228         cmdline_fixed_string_t priority;
7229         cmdline_fixed_string_t high;
7230         cmdline_fixed_string_t queue;
7231         uint16_t queue_id;
7232 };
7233
7234 static void
7235 cmd_syn_filter_parsed(void *parsed_result,
7236                         __attribute__((unused)) struct cmdline *cl,
7237                         __attribute__((unused)) void *data)
7238 {
7239         struct cmd_syn_filter_result *res = parsed_result;
7240         struct rte_eth_syn_filter syn_filter;
7241         int ret = 0;
7242
7243         ret = rte_eth_dev_filter_supported(res->port_id,
7244                                         RTE_ETH_FILTER_SYN);
7245         if (ret < 0) {
7246                 printf("syn filter is not supported on port %u.\n",
7247                                 res->port_id);
7248                 return;
7249         }
7250
7251         memset(&syn_filter, 0, sizeof(syn_filter));
7252
7253         if (!strcmp(res->ops, "add")) {
7254                 if (!strcmp(res->high, "high"))
7255                         syn_filter.hig_pri = 1;
7256                 else
7257                         syn_filter.hig_pri = 0;
7258
7259                 syn_filter.queue = res->queue_id;
7260                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7261                                                 RTE_ETH_FILTER_SYN,
7262                                                 RTE_ETH_FILTER_ADD,
7263                                                 &syn_filter);
7264         } else
7265                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7266                                                 RTE_ETH_FILTER_SYN,
7267                                                 RTE_ETH_FILTER_DELETE,
7268                                                 &syn_filter);
7269
7270         if (ret < 0)
7271                 printf("syn filter programming error: (%s)\n",
7272                                 strerror(-ret));
7273 }
7274
7275 cmdline_parse_token_string_t cmd_syn_filter_filter =
7276         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7277         filter, "syn_filter");
7278 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7279         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7280         port_id, UINT8);
7281 cmdline_parse_token_string_t cmd_syn_filter_ops =
7282         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7283         ops, "add#del");
7284 cmdline_parse_token_string_t cmd_syn_filter_priority =
7285         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7286                                 priority, "priority");
7287 cmdline_parse_token_string_t cmd_syn_filter_high =
7288         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7289                                 high, "high#low");
7290 cmdline_parse_token_string_t cmd_syn_filter_queue =
7291         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7292                                 queue, "queue");
7293 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7294         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7295                                 queue_id, UINT16);
7296
7297 cmdline_parse_inst_t cmd_syn_filter = {
7298         .f = cmd_syn_filter_parsed,
7299         .data = NULL,
7300         .help_str = "add/delete syn filter",
7301         .tokens = {
7302                 (void *)&cmd_syn_filter_filter,
7303                 (void *)&cmd_syn_filter_port_id,
7304                 (void *)&cmd_syn_filter_ops,
7305                 (void *)&cmd_syn_filter_priority,
7306                 (void *)&cmd_syn_filter_high,
7307                 (void *)&cmd_syn_filter_queue,
7308                 (void *)&cmd_syn_filter_queue_id,
7309                 NULL,
7310         },
7311 };
7312
7313 /* *** ADD/REMOVE A 2tuple FILTER *** */
7314 struct cmd_2tuple_filter_result {
7315         cmdline_fixed_string_t filter;
7316         uint8_t  port_id;
7317         cmdline_fixed_string_t ops;
7318         cmdline_fixed_string_t dst_port;
7319         uint16_t dst_port_value;
7320         cmdline_fixed_string_t protocol;
7321         uint8_t protocol_value;
7322         cmdline_fixed_string_t mask;
7323         uint8_t  mask_value;
7324         cmdline_fixed_string_t tcp_flags;
7325         uint8_t tcp_flags_value;
7326         cmdline_fixed_string_t priority;
7327         uint8_t  priority_value;
7328         cmdline_fixed_string_t queue;
7329         uint16_t  queue_id;
7330 };
7331
7332 static void
7333 cmd_2tuple_filter_parsed(void *parsed_result,
7334                         __attribute__((unused)) struct cmdline *cl,
7335                         __attribute__((unused)) void *data)
7336 {
7337         struct rte_eth_ntuple_filter filter;
7338         struct cmd_2tuple_filter_result *res = parsed_result;
7339         int ret = 0;
7340
7341         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7342         if (ret < 0) {
7343                 printf("ntuple filter is not supported on port %u.\n",
7344                         res->port_id);
7345                 return;
7346         }
7347
7348         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7349
7350         filter.flags = RTE_2TUPLE_FLAGS;
7351         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7352         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7353         filter.proto = res->protocol_value;
7354         filter.priority = res->priority_value;
7355         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7356                 printf("nonzero tcp_flags is only meaningful"
7357                         " when protocol is TCP.\n");
7358                 return;
7359         }
7360         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7361                 printf("invalid TCP flags.\n");
7362                 return;
7363         }
7364
7365         if (res->tcp_flags_value != 0) {
7366                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7367                 filter.tcp_flags = res->tcp_flags_value;
7368         }
7369
7370         /* need convert to big endian. */
7371         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7372         filter.queue = res->queue_id;
7373
7374         if (!strcmp(res->ops, "add"))
7375                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7376                                 RTE_ETH_FILTER_NTUPLE,
7377                                 RTE_ETH_FILTER_ADD,
7378                                 &filter);
7379         else
7380                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7381                                 RTE_ETH_FILTER_NTUPLE,
7382                                 RTE_ETH_FILTER_DELETE,
7383                                 &filter);
7384         if (ret < 0)
7385                 printf("2tuple filter programming error: (%s)\n",
7386                         strerror(-ret));
7387
7388 }
7389
7390 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7391         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7392                                  filter, "2tuple_filter");
7393 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7394         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7395                                 port_id, UINT8);
7396 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7397         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7398                                  ops, "add#del");
7399 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7400         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7401                                 dst_port, "dst_port");
7402 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7403         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7404                                 dst_port_value, UINT16);
7405 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7406         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7407                                 protocol, "protocol");
7408 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7409         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7410                                 protocol_value, UINT8);
7411 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7412         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7413                                 mask, "mask");
7414 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7415         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7416                                 mask_value, INT8);
7417 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7418         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7419                                 tcp_flags, "tcp_flags");
7420 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7421         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7422                                 tcp_flags_value, UINT8);
7423 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7424         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7425                                 priority, "priority");
7426 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7427         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7428                                 priority_value, UINT8);
7429 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7430         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7431                                 queue, "queue");
7432 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7433         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7434                                 queue_id, UINT16);
7435
7436 cmdline_parse_inst_t cmd_2tuple_filter = {
7437         .f = cmd_2tuple_filter_parsed,
7438         .data = NULL,
7439         .help_str = "add a 2tuple filter",
7440         .tokens = {
7441                 (void *)&cmd_2tuple_filter_filter,
7442                 (void *)&cmd_2tuple_filter_port_id,
7443                 (void *)&cmd_2tuple_filter_ops,
7444                 (void *)&cmd_2tuple_filter_dst_port,
7445                 (void *)&cmd_2tuple_filter_dst_port_value,
7446                 (void *)&cmd_2tuple_filter_protocol,
7447                 (void *)&cmd_2tuple_filter_protocol_value,
7448                 (void *)&cmd_2tuple_filter_mask,
7449                 (void *)&cmd_2tuple_filter_mask_value,
7450                 (void *)&cmd_2tuple_filter_tcp_flags,
7451                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7452                 (void *)&cmd_2tuple_filter_priority,
7453                 (void *)&cmd_2tuple_filter_priority_value,
7454                 (void *)&cmd_2tuple_filter_queue,
7455                 (void *)&cmd_2tuple_filter_queue_id,
7456                 NULL,
7457         },
7458 };
7459
7460 /* *** ADD/REMOVE A 5tuple FILTER *** */
7461 struct cmd_5tuple_filter_result {
7462         cmdline_fixed_string_t filter;
7463         uint8_t  port_id;
7464         cmdline_fixed_string_t ops;
7465         cmdline_fixed_string_t dst_ip;
7466         cmdline_ipaddr_t dst_ip_value;
7467         cmdline_fixed_string_t src_ip;
7468         cmdline_ipaddr_t src_ip_value;
7469         cmdline_fixed_string_t dst_port;
7470         uint16_t dst_port_value;
7471         cmdline_fixed_string_t src_port;
7472         uint16_t src_port_value;
7473         cmdline_fixed_string_t protocol;
7474         uint8_t protocol_value;
7475         cmdline_fixed_string_t mask;
7476         uint8_t  mask_value;
7477         cmdline_fixed_string_t tcp_flags;
7478         uint8_t tcp_flags_value;
7479         cmdline_fixed_string_t priority;
7480         uint8_t  priority_value;
7481         cmdline_fixed_string_t queue;
7482         uint16_t  queue_id;
7483 };
7484
7485 static void
7486 cmd_5tuple_filter_parsed(void *parsed_result,
7487                         __attribute__((unused)) struct cmdline *cl,
7488                         __attribute__((unused)) void *data)
7489 {
7490         struct rte_eth_ntuple_filter filter;
7491         struct cmd_5tuple_filter_result *res = parsed_result;
7492         int ret = 0;
7493
7494         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7495         if (ret < 0) {
7496                 printf("ntuple filter is not supported on port %u.\n",
7497                         res->port_id);
7498                 return;
7499         }
7500
7501         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7502
7503         filter.flags = RTE_5TUPLE_FLAGS;
7504         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7505         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7506         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7507         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7508         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7509         filter.proto = res->protocol_value;
7510         filter.priority = res->priority_value;
7511         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7512                 printf("nonzero tcp_flags is only meaningful"
7513                         " when protocol is TCP.\n");
7514                 return;
7515         }
7516         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7517                 printf("invalid TCP flags.\n");
7518                 return;
7519         }
7520
7521         if (res->tcp_flags_value != 0) {
7522                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7523                 filter.tcp_flags = res->tcp_flags_value;
7524         }
7525
7526         if (res->dst_ip_value.family == AF_INET)
7527                 /* no need to convert, already big endian. */
7528                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7529         else {
7530                 if (filter.dst_ip_mask == 0) {
7531                         printf("can not support ipv6 involved compare.\n");
7532                         return;
7533                 }
7534                 filter.dst_ip = 0;
7535         }
7536
7537         if (res->src_ip_value.family == AF_INET)
7538                 /* no need to convert, already big endian. */
7539                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7540         else {
7541                 if (filter.src_ip_mask == 0) {
7542                         printf("can not support ipv6 involved compare.\n");
7543                         return;
7544                 }
7545                 filter.src_ip = 0;
7546         }
7547         /* need convert to big endian. */
7548         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7549         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7550         filter.queue = res->queue_id;
7551
7552         if (!strcmp(res->ops, "add"))
7553                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7554                                 RTE_ETH_FILTER_NTUPLE,
7555                                 RTE_ETH_FILTER_ADD,
7556                                 &filter);
7557         else
7558                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7559                                 RTE_ETH_FILTER_NTUPLE,
7560                                 RTE_ETH_FILTER_DELETE,
7561                                 &filter);
7562         if (ret < 0)
7563                 printf("5tuple filter programming error: (%s)\n",
7564                         strerror(-ret));
7565 }
7566
7567 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7568         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7569                                  filter, "5tuple_filter");
7570 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7571         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7572                                 port_id, UINT8);
7573 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7574         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7575                                  ops, "add#del");
7576 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7577         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7578                                 dst_ip, "dst_ip");
7579 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7580         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7581                                 dst_ip_value);
7582 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7583         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7584                                 src_ip, "src_ip");
7585 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7586         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7587                                 src_ip_value);
7588 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7589         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7590                                 dst_port, "dst_port");
7591 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7592         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7593                                 dst_port_value, UINT16);
7594 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7595         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7596                                 src_port, "src_port");
7597 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7598         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7599                                 src_port_value, UINT16);
7600 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7601         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7602                                 protocol, "protocol");
7603 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7604         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7605                                 protocol_value, UINT8);
7606 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7607         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7608                                 mask, "mask");
7609 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7610         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7611                                 mask_value, INT8);
7612 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7613         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7614                                 tcp_flags, "tcp_flags");
7615 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7616         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7617                                 tcp_flags_value, UINT8);
7618 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7619         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7620                                 priority, "priority");
7621 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7622         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7623                                 priority_value, UINT8);
7624 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7625         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7626                                 queue, "queue");
7627 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7628         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7629                                 queue_id, UINT16);
7630
7631 cmdline_parse_inst_t cmd_5tuple_filter = {
7632         .f = cmd_5tuple_filter_parsed,
7633         .data = NULL,
7634         .help_str = "add/del a 5tuple filter",
7635         .tokens = {
7636                 (void *)&cmd_5tuple_filter_filter,
7637                 (void *)&cmd_5tuple_filter_port_id,
7638                 (void *)&cmd_5tuple_filter_ops,
7639                 (void *)&cmd_5tuple_filter_dst_ip,
7640                 (void *)&cmd_5tuple_filter_dst_ip_value,
7641                 (void *)&cmd_5tuple_filter_src_ip,
7642                 (void *)&cmd_5tuple_filter_src_ip_value,
7643                 (void *)&cmd_5tuple_filter_dst_port,
7644                 (void *)&cmd_5tuple_filter_dst_port_value,
7645                 (void *)&cmd_5tuple_filter_src_port,
7646                 (void *)&cmd_5tuple_filter_src_port_value,
7647                 (void *)&cmd_5tuple_filter_protocol,
7648                 (void *)&cmd_5tuple_filter_protocol_value,
7649                 (void *)&cmd_5tuple_filter_mask,
7650                 (void *)&cmd_5tuple_filter_mask_value,
7651                 (void *)&cmd_5tuple_filter_tcp_flags,
7652                 (void *)&cmd_5tuple_filter_tcp_flags_value,
7653                 (void *)&cmd_5tuple_filter_priority,
7654                 (void *)&cmd_5tuple_filter_priority_value,
7655                 (void *)&cmd_5tuple_filter_queue,
7656                 (void *)&cmd_5tuple_filter_queue_id,
7657                 NULL,
7658         },
7659 };
7660
7661 /* *** ADD/REMOVE A flex FILTER *** */
7662 struct cmd_flex_filter_result {
7663         cmdline_fixed_string_t filter;
7664         cmdline_fixed_string_t ops;
7665         uint8_t port_id;
7666         cmdline_fixed_string_t len;
7667         uint8_t len_value;
7668         cmdline_fixed_string_t bytes;
7669         cmdline_fixed_string_t bytes_value;
7670         cmdline_fixed_string_t mask;
7671         cmdline_fixed_string_t mask_value;
7672         cmdline_fixed_string_t priority;
7673         uint8_t priority_value;
7674         cmdline_fixed_string_t queue;
7675         uint16_t queue_id;
7676 };
7677
7678 static int xdigit2val(unsigned char c)
7679 {
7680         int val;
7681         if (isdigit(c))
7682                 val = c - '0';
7683         else if (isupper(c))
7684                 val = c - 'A' + 10;
7685         else
7686                 val = c - 'a' + 10;
7687         return val;
7688 }
7689
7690 static void
7691 cmd_flex_filter_parsed(void *parsed_result,
7692                           __attribute__((unused)) struct cmdline *cl,
7693                           __attribute__((unused)) void *data)
7694 {
7695         int ret = 0;
7696         struct rte_eth_flex_filter filter;
7697         struct cmd_flex_filter_result *res = parsed_result;
7698         char *bytes_ptr, *mask_ptr;
7699         uint16_t len, i, j = 0;
7700         char c;
7701         int val;
7702         uint8_t byte = 0;
7703
7704         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
7705                 printf("the len exceed the max length 128\n");
7706                 return;
7707         }
7708         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
7709         filter.len = res->len_value;
7710         filter.priority = res->priority_value;
7711         filter.queue = res->queue_id;
7712         bytes_ptr = res->bytes_value;
7713         mask_ptr = res->mask_value;
7714
7715          /* translate bytes string to array. */
7716         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7717                 (bytes_ptr[1] == 'X')))
7718                 bytes_ptr += 2;
7719         len = strnlen(bytes_ptr, res->len_value * 2);
7720         if (len == 0 || (len % 8 != 0)) {
7721                 printf("please check len and bytes input\n");
7722                 return;
7723         }
7724         for (i = 0; i < len; i++) {
7725                 c = bytes_ptr[i];
7726                 if (isxdigit(c) == 0) {
7727                         /* invalid characters. */
7728                         printf("invalid input\n");
7729                         return;
7730                 }
7731                 val = xdigit2val(c);
7732                 if (i % 2) {
7733                         byte |= val;
7734                         filter.bytes[j] = byte;
7735                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
7736                         j++;
7737                         byte = 0;
7738                 } else
7739                         byte |= val << 4;
7740         }
7741         printf("\n");
7742          /* translate mask string to uint8_t array. */
7743         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7744                 (mask_ptr[1] == 'X')))
7745                 mask_ptr += 2;
7746         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
7747         if (len == 0) {
7748                 printf("invalid input\n");
7749                 return;
7750         }
7751         j = 0;
7752         byte = 0;
7753         for (i = 0; i < len; i++) {
7754                 c = mask_ptr[i];
7755                 if (isxdigit(c) == 0) {
7756                         /* invalid characters. */
7757                         printf("invalid input\n");
7758                         return;
7759                 }
7760                 val = xdigit2val(c);
7761                 if (i % 2) {
7762                         byte |= val;
7763                         filter.mask[j] = byte;
7764                         printf("mask[%d]:%02x ", j, filter.mask[j]);
7765                         j++;
7766                         byte = 0;
7767                 } else
7768                         byte |= val << 4;
7769         }
7770         printf("\n");
7771
7772         if (!strcmp(res->ops, "add"))
7773                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7774                                 RTE_ETH_FILTER_FLEXIBLE,
7775                                 RTE_ETH_FILTER_ADD,
7776                                 &filter);
7777         else
7778                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7779                                 RTE_ETH_FILTER_FLEXIBLE,
7780                                 RTE_ETH_FILTER_DELETE,
7781                                 &filter);
7782
7783         if (ret < 0)
7784                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7785 }
7786
7787 cmdline_parse_token_string_t cmd_flex_filter_filter =
7788         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7789                                 filter, "flex_filter");
7790 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7791         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7792                                 port_id, UINT8);
7793 cmdline_parse_token_string_t cmd_flex_filter_ops =
7794         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7795                                 ops, "add#del");
7796 cmdline_parse_token_string_t cmd_flex_filter_len =
7797         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7798                                 len, "len");
7799 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7800         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7801                                 len_value, UINT8);
7802 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7803         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7804                                 bytes, "bytes");
7805 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7806         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7807                                 bytes_value, NULL);
7808 cmdline_parse_token_string_t cmd_flex_filter_mask =
7809         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7810                                 mask, "mask");
7811 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7812         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7813                                 mask_value, NULL);
7814 cmdline_parse_token_string_t cmd_flex_filter_priority =
7815         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7816                                 priority, "priority");
7817 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7818         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7819                                 priority_value, UINT8);
7820 cmdline_parse_token_string_t cmd_flex_filter_queue =
7821         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7822                                 queue, "queue");
7823 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7824         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7825                                 queue_id, UINT16);
7826 cmdline_parse_inst_t cmd_flex_filter = {
7827         .f = cmd_flex_filter_parsed,
7828         .data = NULL,
7829         .help_str = "add/del a flex filter",
7830         .tokens = {
7831                 (void *)&cmd_flex_filter_filter,
7832                 (void *)&cmd_flex_filter_port_id,
7833                 (void *)&cmd_flex_filter_ops,
7834                 (void *)&cmd_flex_filter_len,
7835                 (void *)&cmd_flex_filter_len_value,
7836                 (void *)&cmd_flex_filter_bytes,
7837                 (void *)&cmd_flex_filter_bytes_value,
7838                 (void *)&cmd_flex_filter_mask,
7839                 (void *)&cmd_flex_filter_mask_value,
7840                 (void *)&cmd_flex_filter_priority,
7841                 (void *)&cmd_flex_filter_priority_value,
7842                 (void *)&cmd_flex_filter_queue,
7843                 (void *)&cmd_flex_filter_queue_id,
7844                 NULL,
7845         },
7846 };
7847
7848 /* *** Filters Control *** */
7849
7850 /* *** deal with ethertype filter *** */
7851 struct cmd_ethertype_filter_result {
7852         cmdline_fixed_string_t filter;
7853         uint8_t port_id;
7854         cmdline_fixed_string_t ops;
7855         cmdline_fixed_string_t mac;
7856         struct ether_addr mac_addr;
7857         cmdline_fixed_string_t ethertype;
7858         uint16_t ethertype_value;
7859         cmdline_fixed_string_t drop;
7860         cmdline_fixed_string_t queue;
7861         uint16_t  queue_id;
7862 };
7863
7864 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7865         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7866                                  filter, "ethertype_filter");
7867 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7868         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7869                               port_id, UINT8);
7870 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
7871         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7872                                  ops, "add#del");
7873 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
7874         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7875                                  mac, "mac_addr#mac_ignr");
7876 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
7877         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
7878                                      mac_addr);
7879 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
7880         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7881                                  ethertype, "ethertype");
7882 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
7883         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7884                               ethertype_value, UINT16);
7885 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
7886         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7887                                  drop, "drop#fwd");
7888 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
7889         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7890                                  queue, "queue");
7891 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
7892         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7893                               queue_id, UINT16);
7894
7895 static void
7896 cmd_ethertype_filter_parsed(void *parsed_result,
7897                           __attribute__((unused)) struct cmdline *cl,
7898                           __attribute__((unused)) void *data)
7899 {
7900         struct cmd_ethertype_filter_result *res = parsed_result;
7901         struct rte_eth_ethertype_filter filter;
7902         int ret = 0;
7903
7904         ret = rte_eth_dev_filter_supported(res->port_id,
7905                         RTE_ETH_FILTER_ETHERTYPE);
7906         if (ret < 0) {
7907                 printf("ethertype filter is not supported on port %u.\n",
7908                         res->port_id);
7909                 return;
7910         }
7911
7912         memset(&filter, 0, sizeof(filter));
7913         if (!strcmp(res->mac, "mac_addr")) {
7914                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
7915                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
7916                         sizeof(struct ether_addr));
7917         }
7918         if (!strcmp(res->drop, "drop"))
7919                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
7920         filter.ether_type = res->ethertype_value;
7921         filter.queue = res->queue_id;
7922
7923         if (!strcmp(res->ops, "add"))
7924                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7925                                 RTE_ETH_FILTER_ETHERTYPE,
7926                                 RTE_ETH_FILTER_ADD,
7927                                 &filter);
7928         else
7929                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7930                                 RTE_ETH_FILTER_ETHERTYPE,
7931                                 RTE_ETH_FILTER_DELETE,
7932                                 &filter);
7933         if (ret < 0)
7934                 printf("ethertype filter programming error: (%s)\n",
7935                         strerror(-ret));
7936 }
7937
7938 cmdline_parse_inst_t cmd_ethertype_filter = {
7939         .f = cmd_ethertype_filter_parsed,
7940         .data = NULL,
7941         .help_str = "add or delete an ethertype filter entry",
7942         .tokens = {
7943                 (void *)&cmd_ethertype_filter_filter,
7944                 (void *)&cmd_ethertype_filter_port_id,
7945                 (void *)&cmd_ethertype_filter_ops,
7946                 (void *)&cmd_ethertype_filter_mac,
7947                 (void *)&cmd_ethertype_filter_mac_addr,
7948                 (void *)&cmd_ethertype_filter_ethertype,
7949                 (void *)&cmd_ethertype_filter_ethertype_value,
7950                 (void *)&cmd_ethertype_filter_drop,
7951                 (void *)&cmd_ethertype_filter_queue,
7952                 (void *)&cmd_ethertype_filter_queue_id,
7953                 NULL,
7954         },
7955 };
7956
7957 /* *** deal with flow director filter *** */
7958 struct cmd_flow_director_result {
7959         cmdline_fixed_string_t flow_director_filter;
7960         uint8_t port_id;
7961         cmdline_fixed_string_t mode;
7962         cmdline_fixed_string_t mode_value;
7963         cmdline_fixed_string_t ops;
7964         cmdline_fixed_string_t flow;
7965         cmdline_fixed_string_t flow_type;
7966         cmdline_fixed_string_t ether;
7967         uint16_t ether_type;
7968         cmdline_fixed_string_t src;
7969         cmdline_ipaddr_t ip_src;
7970         uint16_t port_src;
7971         cmdline_fixed_string_t dst;
7972         cmdline_ipaddr_t ip_dst;
7973         uint16_t port_dst;
7974         cmdline_fixed_string_t verify_tag;
7975         uint32_t verify_tag_value;
7976         cmdline_fixed_string_t vlan;
7977         uint16_t vlan_value;
7978         cmdline_fixed_string_t flexbytes;
7979         cmdline_fixed_string_t flexbytes_value;
7980         cmdline_fixed_string_t pf_vf;
7981         cmdline_fixed_string_t drop;
7982         cmdline_fixed_string_t queue;
7983         uint16_t  queue_id;
7984         cmdline_fixed_string_t fd_id;
7985         uint32_t  fd_id_value;
7986         cmdline_fixed_string_t mac;
7987         struct ether_addr mac_addr;
7988         cmdline_fixed_string_t tunnel;
7989         cmdline_fixed_string_t tunnel_type;
7990         cmdline_fixed_string_t tunnel_id;
7991         uint32_t tunnel_id_value;
7992 };
7993
7994 static inline int
7995 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
7996 {
7997         char s[256];
7998         const char *p, *p0 = q_arg;
7999         char *end;
8000         unsigned long int_fld;
8001         char *str_fld[max_num];
8002         int i;
8003         unsigned size;
8004         int ret = -1;
8005
8006         p = strchr(p0, '(');
8007         if (p == NULL)
8008                 return -1;
8009         ++p;
8010         p0 = strchr(p, ')');
8011         if (p0 == NULL)
8012                 return -1;
8013
8014         size = p0 - p;
8015         if (size >= sizeof(s))
8016                 return -1;
8017
8018         snprintf(s, sizeof(s), "%.*s", size, p);
8019         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8020         if (ret < 0 || ret > max_num)
8021                 return -1;
8022         for (i = 0; i < ret; i++) {
8023                 errno = 0;
8024                 int_fld = strtoul(str_fld[i], &end, 0);
8025                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8026                         return -1;
8027                 flexbytes[i] = (uint8_t)int_fld;
8028         }
8029         return ret;
8030 }
8031
8032 static uint16_t
8033 str2flowtype(char *string)
8034 {
8035         uint8_t i = 0;
8036         static const struct {
8037                 char str[32];
8038                 uint16_t type;
8039         } flowtype_str[] = {
8040                 {"raw", RTE_ETH_FLOW_RAW},
8041                 {"ipv4", RTE_ETH_FLOW_IPV4},
8042                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8043                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8044                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8045                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8046                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8047                 {"ipv6", RTE_ETH_FLOW_IPV6},
8048                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8049                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8050                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8051                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8052                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8053                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8054         };
8055
8056         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8057                 if (!strcmp(flowtype_str[i].str, string))
8058                         return flowtype_str[i].type;
8059         }
8060         return RTE_ETH_FLOW_UNKNOWN;
8061 }
8062
8063 static enum rte_eth_fdir_tunnel_type
8064 str2fdir_tunneltype(char *string)
8065 {
8066         uint8_t i = 0;
8067
8068         static const struct {
8069                 char str[32];
8070                 enum rte_eth_fdir_tunnel_type type;
8071         } tunneltype_str[] = {
8072                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8073                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8074         };
8075
8076         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8077                 if (!strcmp(tunneltype_str[i].str, string))
8078                         return tunneltype_str[i].type;
8079         }
8080         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8081 }
8082
8083 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8084 do { \
8085         if ((ip_addr).family == AF_INET) \
8086                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8087         else { \
8088                 printf("invalid parameter.\n"); \
8089                 return; \
8090         } \
8091 } while (0)
8092
8093 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8094 do { \
8095         if ((ip_addr).family == AF_INET6) \
8096                 (void)rte_memcpy(&(ip), \
8097                                  &((ip_addr).addr.ipv6), \
8098                                  sizeof(struct in6_addr)); \
8099         else { \
8100                 printf("invalid parameter.\n"); \
8101                 return; \
8102         } \
8103 } while (0)
8104
8105 static void
8106 cmd_flow_director_filter_parsed(void *parsed_result,
8107                           __attribute__((unused)) struct cmdline *cl,
8108                           __attribute__((unused)) void *data)
8109 {
8110         struct cmd_flow_director_result *res = parsed_result;
8111         struct rte_eth_fdir_filter entry;
8112         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8113         char *end;
8114         unsigned long vf_id;
8115         int ret = 0;
8116
8117         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8118         if (ret < 0) {
8119                 printf("flow director is not supported on port %u.\n",
8120                         res->port_id);
8121                 return;
8122         }
8123         memset(flexbytes, 0, sizeof(flexbytes));
8124         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8125
8126         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8127                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8128                         printf("Please set mode to MAC-VLAN.\n");
8129                         return;
8130                 }
8131         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8132                 if (strcmp(res->mode_value, "Tunnel")) {
8133                         printf("Please set mode to Tunnel.\n");
8134                         return;
8135                 }
8136         } else {
8137                 if (strcmp(res->mode_value, "IP")) {
8138                         printf("Please set mode to IP.\n");
8139                         return;
8140                 }
8141                 entry.input.flow_type = str2flowtype(res->flow_type);
8142         }
8143
8144         ret = parse_flexbytes(res->flexbytes_value,
8145                                         flexbytes,
8146                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8147         if (ret < 0) {
8148                 printf("error: Cannot parse flexbytes input.\n");
8149                 return;
8150         }
8151
8152         switch (entry.input.flow_type) {
8153         case RTE_ETH_FLOW_FRAG_IPV4:
8154         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8155         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8156         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8157                 IPV4_ADDR_TO_UINT(res->ip_dst,
8158                         entry.input.flow.ip4_flow.dst_ip);
8159                 IPV4_ADDR_TO_UINT(res->ip_src,
8160                         entry.input.flow.ip4_flow.src_ip);
8161                 /* need convert to big endian. */
8162                 entry.input.flow.udp4_flow.dst_port =
8163                                 rte_cpu_to_be_16(res->port_dst);
8164                 entry.input.flow.udp4_flow.src_port =
8165                                 rte_cpu_to_be_16(res->port_src);
8166                 break;
8167         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8168                 IPV4_ADDR_TO_UINT(res->ip_dst,
8169                         entry.input.flow.sctp4_flow.ip.dst_ip);
8170                 IPV4_ADDR_TO_UINT(res->ip_src,
8171                         entry.input.flow.sctp4_flow.ip.src_ip);
8172                 /* need convert to big endian. */
8173                 entry.input.flow.sctp4_flow.dst_port =
8174                                 rte_cpu_to_be_16(res->port_dst);
8175                 entry.input.flow.sctp4_flow.src_port =
8176                                 rte_cpu_to_be_16(res->port_src);
8177                 entry.input.flow.sctp4_flow.verify_tag =
8178                                 rte_cpu_to_be_32(res->verify_tag_value);
8179                 break;
8180         case RTE_ETH_FLOW_FRAG_IPV6:
8181         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8182         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8183         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8184                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8185                         entry.input.flow.ipv6_flow.dst_ip);
8186                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8187                         entry.input.flow.ipv6_flow.src_ip);
8188                 /* need convert to big endian. */
8189                 entry.input.flow.udp6_flow.dst_port =
8190                                 rte_cpu_to_be_16(res->port_dst);
8191                 entry.input.flow.udp6_flow.src_port =
8192                                 rte_cpu_to_be_16(res->port_src);
8193                 break;
8194         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8195                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8196                         entry.input.flow.sctp6_flow.ip.dst_ip);
8197                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8198                         entry.input.flow.sctp6_flow.ip.src_ip);
8199                 /* need convert to big endian. */
8200                 entry.input.flow.sctp6_flow.dst_port =
8201                                 rte_cpu_to_be_16(res->port_dst);
8202                 entry.input.flow.sctp6_flow.src_port =
8203                                 rte_cpu_to_be_16(res->port_src);
8204                 entry.input.flow.sctp6_flow.verify_tag =
8205                                 rte_cpu_to_be_32(res->verify_tag_value);
8206                 break;
8207         case RTE_ETH_FLOW_L2_PAYLOAD:
8208                 entry.input.flow.l2_flow.ether_type =
8209                         rte_cpu_to_be_16(res->ether_type);
8210                 break;
8211         default:
8212                 break;
8213         }
8214
8215         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8216                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8217                                  &res->mac_addr,
8218                                  sizeof(struct ether_addr));
8219
8220         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8221                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8222                                  &res->mac_addr,
8223                                  sizeof(struct ether_addr));
8224                 entry.input.flow.tunnel_flow.tunnel_type =
8225                         str2fdir_tunneltype(res->tunnel_type);
8226                 entry.input.flow.tunnel_flow.tunnel_id =
8227                         rte_cpu_to_be_32(res->tunnel_id_value);
8228         }
8229
8230         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8231                    flexbytes,
8232                    RTE_ETH_FDIR_MAX_FLEXLEN);
8233
8234         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8235
8236         entry.action.flex_off = 0;  /*use 0 by default */
8237         if (!strcmp(res->drop, "drop"))
8238                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8239         else
8240                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8241
8242         if (!strcmp(res->pf_vf, "pf"))
8243                 entry.input.flow_ext.is_vf = 0;
8244         else if (!strncmp(res->pf_vf, "vf", 2)) {
8245                 struct rte_eth_dev_info dev_info;
8246
8247                 memset(&dev_info, 0, sizeof(dev_info));
8248                 rte_eth_dev_info_get(res->port_id, &dev_info);
8249                 errno = 0;
8250                 vf_id = strtoul(res->pf_vf + 2, &end, 10);
8251                 if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
8252                         printf("invalid parameter %s.\n", res->pf_vf);
8253                         return;
8254                 }
8255                 entry.input.flow_ext.is_vf = 1;
8256                 entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8257         } else {
8258                 printf("invalid parameter %s.\n", res->pf_vf);
8259                 return;
8260         }
8261
8262         /* set to report FD ID by default */
8263         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8264         entry.action.rx_queue = res->queue_id;
8265         entry.soft_id = res->fd_id_value;
8266         if (!strcmp(res->ops, "add"))
8267                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8268                                              RTE_ETH_FILTER_ADD, &entry);
8269         else if (!strcmp(res->ops, "del"))
8270                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8271                                              RTE_ETH_FILTER_DELETE, &entry);
8272         else
8273                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8274                                              RTE_ETH_FILTER_UPDATE, &entry);
8275         if (ret < 0)
8276                 printf("flow director programming error: (%s)\n",
8277                         strerror(-ret));
8278 }
8279
8280 cmdline_parse_token_string_t cmd_flow_director_filter =
8281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8282                                  flow_director_filter, "flow_director_filter");
8283 cmdline_parse_token_num_t cmd_flow_director_port_id =
8284         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8285                               port_id, UINT8);
8286 cmdline_parse_token_string_t cmd_flow_director_ops =
8287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8288                                  ops, "add#del#update");
8289 cmdline_parse_token_string_t cmd_flow_director_flow =
8290         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8291                                  flow, "flow");
8292 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8294                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8295                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8296 cmdline_parse_token_string_t cmd_flow_director_ether =
8297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8298                                  ether, "ether");
8299 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8300         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8301                               ether_type, UINT16);
8302 cmdline_parse_token_string_t cmd_flow_director_src =
8303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8304                                  src, "src");
8305 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8306         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8307                                  ip_src);
8308 cmdline_parse_token_num_t cmd_flow_director_port_src =
8309         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8310                               port_src, UINT16);
8311 cmdline_parse_token_string_t cmd_flow_director_dst =
8312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8313                                  dst, "dst");
8314 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8315         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8316                                  ip_dst);
8317 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8318         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8319                               port_dst, UINT16);
8320 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8321         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8322                                   verify_tag, "verify_tag");
8323 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8324         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8325                               verify_tag_value, UINT32);
8326 cmdline_parse_token_string_t cmd_flow_director_vlan =
8327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8328                                  vlan, "vlan");
8329 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8330         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8331                               vlan_value, UINT16);
8332 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8334                                  flexbytes, "flexbytes");
8335 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8337                               flexbytes_value, NULL);
8338 cmdline_parse_token_string_t cmd_flow_director_drop =
8339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8340                                  drop, "drop#fwd");
8341 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8343                               pf_vf, NULL);
8344 cmdline_parse_token_string_t cmd_flow_director_queue =
8345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8346                                  queue, "queue");
8347 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8348         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8349                               queue_id, UINT16);
8350 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8352                                  fd_id, "fd_id");
8353 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8354         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8355                               fd_id_value, UINT32);
8356
8357 cmdline_parse_token_string_t cmd_flow_director_mode =
8358         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8359                                  mode, "mode");
8360 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8361         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8362                                  mode_value, "IP");
8363 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8365                                  mode_value, "MAC-VLAN");
8366 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8367         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8368                                  mode_value, "Tunnel");
8369 cmdline_parse_token_string_t cmd_flow_director_mac =
8370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8371                                  mac, "mac");
8372 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8373         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8374                                     mac_addr);
8375 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8377                                  tunnel, "tunnel");
8378 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8380                                  tunnel_type, "NVGRE#VxLAN");
8381 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8383                                  tunnel_id, "tunnel-id");
8384 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8385         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8386                               tunnel_id_value, UINT32);
8387
8388 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8389         .f = cmd_flow_director_filter_parsed,
8390         .data = NULL,
8391         .help_str = "add or delete an ip flow director entry on NIC",
8392         .tokens = {
8393                 (void *)&cmd_flow_director_filter,
8394                 (void *)&cmd_flow_director_port_id,
8395                 (void *)&cmd_flow_director_mode,
8396                 (void *)&cmd_flow_director_mode_ip,
8397                 (void *)&cmd_flow_director_ops,
8398                 (void *)&cmd_flow_director_flow,
8399                 (void *)&cmd_flow_director_flow_type,
8400                 (void *)&cmd_flow_director_src,
8401                 (void *)&cmd_flow_director_ip_src,
8402                 (void *)&cmd_flow_director_dst,
8403                 (void *)&cmd_flow_director_ip_dst,
8404                 (void *)&cmd_flow_director_vlan,
8405                 (void *)&cmd_flow_director_vlan_value,
8406                 (void *)&cmd_flow_director_flexbytes,
8407                 (void *)&cmd_flow_director_flexbytes_value,
8408                 (void *)&cmd_flow_director_drop,
8409                 (void *)&cmd_flow_director_pf_vf,
8410                 (void *)&cmd_flow_director_queue,
8411                 (void *)&cmd_flow_director_queue_id,
8412                 (void *)&cmd_flow_director_fd_id,
8413                 (void *)&cmd_flow_director_fd_id_value,
8414                 NULL,
8415         },
8416 };
8417
8418 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8419         .f = cmd_flow_director_filter_parsed,
8420         .data = NULL,
8421         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8422         .tokens = {
8423                 (void *)&cmd_flow_director_filter,
8424                 (void *)&cmd_flow_director_port_id,
8425                 (void *)&cmd_flow_director_mode,
8426                 (void *)&cmd_flow_director_mode_ip,
8427                 (void *)&cmd_flow_director_ops,
8428                 (void *)&cmd_flow_director_flow,
8429                 (void *)&cmd_flow_director_flow_type,
8430                 (void *)&cmd_flow_director_src,
8431                 (void *)&cmd_flow_director_ip_src,
8432                 (void *)&cmd_flow_director_port_src,
8433                 (void *)&cmd_flow_director_dst,
8434                 (void *)&cmd_flow_director_ip_dst,
8435                 (void *)&cmd_flow_director_port_dst,
8436                 (void *)&cmd_flow_director_vlan,
8437                 (void *)&cmd_flow_director_vlan_value,
8438                 (void *)&cmd_flow_director_flexbytes,
8439                 (void *)&cmd_flow_director_flexbytes_value,
8440                 (void *)&cmd_flow_director_drop,
8441                 (void *)&cmd_flow_director_pf_vf,
8442                 (void *)&cmd_flow_director_queue,
8443                 (void *)&cmd_flow_director_queue_id,
8444                 (void *)&cmd_flow_director_fd_id,
8445                 (void *)&cmd_flow_director_fd_id_value,
8446                 NULL,
8447         },
8448 };
8449
8450 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8451         .f = cmd_flow_director_filter_parsed,
8452         .data = NULL,
8453         .help_str = "add or delete a sctp flow director entry on NIC",
8454         .tokens = {
8455                 (void *)&cmd_flow_director_filter,
8456                 (void *)&cmd_flow_director_port_id,
8457                 (void *)&cmd_flow_director_mode,
8458                 (void *)&cmd_flow_director_mode_ip,
8459                 (void *)&cmd_flow_director_ops,
8460                 (void *)&cmd_flow_director_flow,
8461                 (void *)&cmd_flow_director_flow_type,
8462                 (void *)&cmd_flow_director_src,
8463                 (void *)&cmd_flow_director_ip_src,
8464                 (void *)&cmd_flow_director_port_dst,
8465                 (void *)&cmd_flow_director_dst,
8466                 (void *)&cmd_flow_director_ip_dst,
8467                 (void *)&cmd_flow_director_port_dst,
8468                 (void *)&cmd_flow_director_verify_tag,
8469                 (void *)&cmd_flow_director_verify_tag_value,
8470                 (void *)&cmd_flow_director_vlan,
8471                 (void *)&cmd_flow_director_vlan_value,
8472                 (void *)&cmd_flow_director_flexbytes,
8473                 (void *)&cmd_flow_director_flexbytes_value,
8474                 (void *)&cmd_flow_director_drop,
8475                 (void *)&cmd_flow_director_pf_vf,
8476                 (void *)&cmd_flow_director_queue,
8477                 (void *)&cmd_flow_director_queue_id,
8478                 (void *)&cmd_flow_director_fd_id,
8479                 (void *)&cmd_flow_director_fd_id_value,
8480                 NULL,
8481         },
8482 };
8483
8484 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
8485         .f = cmd_flow_director_filter_parsed,
8486         .data = NULL,
8487         .help_str = "add or delete a L2 flow director entry on NIC",
8488         .tokens = {
8489                 (void *)&cmd_flow_director_filter,
8490                 (void *)&cmd_flow_director_port_id,
8491                 (void *)&cmd_flow_director_mode,
8492                 (void *)&cmd_flow_director_mode_ip,
8493                 (void *)&cmd_flow_director_ops,
8494                 (void *)&cmd_flow_director_flow,
8495                 (void *)&cmd_flow_director_flow_type,
8496                 (void *)&cmd_flow_director_ether,
8497                 (void *)&cmd_flow_director_ether_type,
8498                 (void *)&cmd_flow_director_flexbytes,
8499                 (void *)&cmd_flow_director_flexbytes_value,
8500                 (void *)&cmd_flow_director_drop,
8501                 (void *)&cmd_flow_director_pf_vf,
8502                 (void *)&cmd_flow_director_queue,
8503                 (void *)&cmd_flow_director_queue_id,
8504                 (void *)&cmd_flow_director_fd_id,
8505                 (void *)&cmd_flow_director_fd_id_value,
8506                 NULL,
8507         },
8508 };
8509
8510 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
8511         .f = cmd_flow_director_filter_parsed,
8512         .data = NULL,
8513         .help_str = "add or delete a MAC VLAN flow director entry on NIC",
8514         .tokens = {
8515                 (void *)&cmd_flow_director_filter,
8516                 (void *)&cmd_flow_director_port_id,
8517                 (void *)&cmd_flow_director_mode,
8518                 (void *)&cmd_flow_director_mode_mac_vlan,
8519                 (void *)&cmd_flow_director_ops,
8520                 (void *)&cmd_flow_director_mac,
8521                 (void *)&cmd_flow_director_mac_addr,
8522                 (void *)&cmd_flow_director_vlan,
8523                 (void *)&cmd_flow_director_vlan_value,
8524                 (void *)&cmd_flow_director_flexbytes,
8525                 (void *)&cmd_flow_director_flexbytes_value,
8526                 (void *)&cmd_flow_director_drop,
8527                 (void *)&cmd_flow_director_queue,
8528                 (void *)&cmd_flow_director_queue_id,
8529                 (void *)&cmd_flow_director_fd_id,
8530                 (void *)&cmd_flow_director_fd_id_value,
8531                 NULL,
8532         },
8533 };
8534
8535 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
8536         .f = cmd_flow_director_filter_parsed,
8537         .data = NULL,
8538         .help_str = "add or delete a tunnel flow director entry on NIC",
8539         .tokens = {
8540                 (void *)&cmd_flow_director_filter,
8541                 (void *)&cmd_flow_director_port_id,
8542                 (void *)&cmd_flow_director_mode,
8543                 (void *)&cmd_flow_director_mode_tunnel,
8544                 (void *)&cmd_flow_director_ops,
8545                 (void *)&cmd_flow_director_mac,
8546                 (void *)&cmd_flow_director_mac_addr,
8547                 (void *)&cmd_flow_director_vlan,
8548                 (void *)&cmd_flow_director_vlan_value,
8549                 (void *)&cmd_flow_director_tunnel,
8550                 (void *)&cmd_flow_director_tunnel_type,
8551                 (void *)&cmd_flow_director_tunnel_id,
8552                 (void *)&cmd_flow_director_tunnel_id_value,
8553                 (void *)&cmd_flow_director_flexbytes,
8554                 (void *)&cmd_flow_director_flexbytes_value,
8555                 (void *)&cmd_flow_director_drop,
8556                 (void *)&cmd_flow_director_queue,
8557                 (void *)&cmd_flow_director_queue_id,
8558                 (void *)&cmd_flow_director_fd_id,
8559                 (void *)&cmd_flow_director_fd_id_value,
8560                 NULL,
8561         },
8562 };
8563
8564 struct cmd_flush_flow_director_result {
8565         cmdline_fixed_string_t flush_flow_director;
8566         uint8_t port_id;
8567 };
8568
8569 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8570         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8571                                  flush_flow_director, "flush_flow_director");
8572 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8573         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8574                               port_id, UINT8);
8575
8576 static void
8577 cmd_flush_flow_director_parsed(void *parsed_result,
8578                           __attribute__((unused)) struct cmdline *cl,
8579                           __attribute__((unused)) void *data)
8580 {
8581         struct cmd_flow_director_result *res = parsed_result;
8582         int ret = 0;
8583
8584         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8585         if (ret < 0) {
8586                 printf("flow director is not supported on port %u.\n",
8587                         res->port_id);
8588                 return;
8589         }
8590
8591         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8592                         RTE_ETH_FILTER_FLUSH, NULL);
8593         if (ret < 0)
8594                 printf("flow director table flushing error: (%s)\n",
8595                         strerror(-ret));
8596 }
8597
8598 cmdline_parse_inst_t cmd_flush_flow_director = {
8599         .f = cmd_flush_flow_director_parsed,
8600         .data = NULL,
8601         .help_str = "flush all flow director entries of a device on NIC",
8602         .tokens = {
8603                 (void *)&cmd_flush_flow_director_flush,
8604                 (void *)&cmd_flush_flow_director_port_id,
8605                 NULL,
8606         },
8607 };
8608
8609 /* *** deal with flow director mask *** */
8610 struct cmd_flow_director_mask_result {
8611         cmdline_fixed_string_t flow_director_mask;
8612         uint8_t port_id;
8613         cmdline_fixed_string_t mode;
8614         cmdline_fixed_string_t mode_value;
8615         cmdline_fixed_string_t vlan;
8616         uint16_t vlan_mask;
8617         cmdline_fixed_string_t src_mask;
8618         cmdline_ipaddr_t ipv4_src;
8619         cmdline_ipaddr_t ipv6_src;
8620         uint16_t port_src;
8621         cmdline_fixed_string_t dst_mask;
8622         cmdline_ipaddr_t ipv4_dst;
8623         cmdline_ipaddr_t ipv6_dst;
8624         uint16_t port_dst;
8625         cmdline_fixed_string_t mac;
8626         uint8_t mac_addr_byte_mask;
8627         cmdline_fixed_string_t tunnel_id;
8628         uint32_t tunnel_id_mask;
8629         cmdline_fixed_string_t tunnel_type;
8630         uint8_t tunnel_type_mask;
8631 };
8632
8633 static void
8634 cmd_flow_director_mask_parsed(void *parsed_result,
8635                           __attribute__((unused)) struct cmdline *cl,
8636                           __attribute__((unused)) void *data)
8637 {
8638         struct cmd_flow_director_mask_result *res = parsed_result;
8639         struct rte_eth_fdir_masks *mask;
8640         struct rte_port *port;
8641
8642         if (res->port_id > nb_ports) {
8643                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8644                 return;
8645         }
8646
8647         port = &ports[res->port_id];
8648         /** Check if the port is not started **/
8649         if (port->port_status != RTE_PORT_STOPPED) {
8650                 printf("Please stop port %d first\n", res->port_id);
8651                 return;
8652         }
8653
8654         mask = &port->dev_conf.fdir_conf.mask;
8655
8656         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8657                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8658                         printf("Please set mode to MAC-VLAN.\n");
8659                         return;
8660                 }
8661
8662                 mask->vlan_tci_mask = res->vlan_mask;
8663                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8664         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8665                 if (strcmp(res->mode_value, "Tunnel")) {
8666                         printf("Please set mode to Tunnel.\n");
8667                         return;
8668                 }
8669
8670                 mask->vlan_tci_mask = res->vlan_mask;
8671                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8672                 mask->tunnel_id_mask = res->tunnel_id_mask;
8673                 mask->tunnel_type_mask = res->tunnel_type_mask;
8674         } else {
8675                 if (strcmp(res->mode_value, "IP")) {
8676                         printf("Please set mode to IP.\n");
8677                         return;
8678                 }
8679
8680                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
8681                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
8682                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
8683                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
8684                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
8685                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
8686                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
8687         }
8688
8689         cmd_reconfig_device_queue(res->port_id, 1, 1);
8690 }
8691
8692 cmdline_parse_token_string_t cmd_flow_director_mask =
8693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8694                                  flow_director_mask, "flow_director_mask");
8695 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
8696         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8697                               port_id, UINT8);
8698 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
8699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8700                                  vlan, "vlan");
8701 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
8702         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8703                               vlan_mask, UINT16);
8704 cmdline_parse_token_string_t cmd_flow_director_mask_src =
8705         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8706                                  src_mask, "src_mask");
8707 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
8708         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8709                                  ipv4_src);
8710 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
8711         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8712                                  ipv6_src);
8713 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
8714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8715                               port_src, UINT16);
8716 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
8717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8718                                  dst_mask, "dst_mask");
8719 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
8720         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8721                                  ipv4_dst);
8722 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
8723         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8724                                  ipv6_dst);
8725 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
8726         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8727                               port_dst, UINT16);
8728
8729 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
8730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8731                                  mode, "mode");
8732 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
8733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8734                                  mode_value, "IP");
8735 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
8736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8737                                  mode_value, "MAC-VLAN");
8738 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
8739         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8740                                  mode_value, "Tunnel");
8741 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
8742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8743                                  mac, "mac");
8744 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
8745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8746                               mac_addr_byte_mask, UINT8);
8747 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
8748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8749                                  tunnel_type, "tunnel-type");
8750 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
8751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8752                               tunnel_type_mask, UINT8);
8753 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
8754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8755                                  tunnel_id, "tunnel-id");
8756 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
8757         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8758                               tunnel_id_mask, UINT32);
8759
8760 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
8761         .f = cmd_flow_director_mask_parsed,
8762         .data = NULL,
8763         .help_str = "set IP mode flow director's mask on NIC",
8764         .tokens = {
8765                 (void *)&cmd_flow_director_mask,
8766                 (void *)&cmd_flow_director_mask_port_id,
8767                 (void *)&cmd_flow_director_mask_mode,
8768                 (void *)&cmd_flow_director_mask_mode_ip,
8769                 (void *)&cmd_flow_director_mask_vlan,
8770                 (void *)&cmd_flow_director_mask_vlan_value,
8771                 (void *)&cmd_flow_director_mask_src,
8772                 (void *)&cmd_flow_director_mask_ipv4_src,
8773                 (void *)&cmd_flow_director_mask_ipv6_src,
8774                 (void *)&cmd_flow_director_mask_port_src,
8775                 (void *)&cmd_flow_director_mask_dst,
8776                 (void *)&cmd_flow_director_mask_ipv4_dst,
8777                 (void *)&cmd_flow_director_mask_ipv6_dst,
8778                 (void *)&cmd_flow_director_mask_port_dst,
8779                 NULL,
8780         },
8781 };
8782
8783 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
8784         .f = cmd_flow_director_mask_parsed,
8785         .data = NULL,
8786         .help_str = "set MAC VLAN mode flow director's mask on NIC",
8787         .tokens = {
8788                 (void *)&cmd_flow_director_mask,
8789                 (void *)&cmd_flow_director_mask_port_id,
8790                 (void *)&cmd_flow_director_mask_mode,
8791                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
8792                 (void *)&cmd_flow_director_mask_vlan,
8793                 (void *)&cmd_flow_director_mask_vlan_value,
8794                 (void *)&cmd_flow_director_mask_mac,
8795                 (void *)&cmd_flow_director_mask_mac_value,
8796                 NULL,
8797         },
8798 };
8799
8800 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
8801         .f = cmd_flow_director_mask_parsed,
8802         .data = NULL,
8803         .help_str = "set tunnel mode flow director's mask on NIC",
8804         .tokens = {
8805                 (void *)&cmd_flow_director_mask,
8806                 (void *)&cmd_flow_director_mask_port_id,
8807                 (void *)&cmd_flow_director_mask_mode,
8808                 (void *)&cmd_flow_director_mask_mode_tunnel,
8809                 (void *)&cmd_flow_director_mask_vlan,
8810                 (void *)&cmd_flow_director_mask_vlan_value,
8811                 (void *)&cmd_flow_director_mask_mac,
8812                 (void *)&cmd_flow_director_mask_mac_value,
8813                 (void *)&cmd_flow_director_mask_tunnel_type,
8814                 (void *)&cmd_flow_director_mask_tunnel_type_value,
8815                 (void *)&cmd_flow_director_mask_tunnel_id,
8816                 (void *)&cmd_flow_director_mask_tunnel_id_value,
8817                 NULL,
8818         },
8819 };
8820
8821 /* *** deal with flow director mask on flexible payload *** */
8822 struct cmd_flow_director_flex_mask_result {
8823         cmdline_fixed_string_t flow_director_flexmask;
8824         uint8_t port_id;
8825         cmdline_fixed_string_t flow;
8826         cmdline_fixed_string_t flow_type;
8827         cmdline_fixed_string_t mask;
8828 };
8829
8830 static void
8831 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8832                           __attribute__((unused)) struct cmdline *cl,
8833                           __attribute__((unused)) void *data)
8834 {
8835         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8836         struct rte_eth_fdir_info fdir_info;
8837         struct rte_eth_fdir_flex_mask flex_mask;
8838         struct rte_port *port;
8839         uint32_t flow_type_mask;
8840         uint16_t i;
8841         int ret;
8842
8843         if (res->port_id > nb_ports) {
8844                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8845                 return;
8846         }
8847
8848         port = &ports[res->port_id];
8849         /** Check if the port is not started **/
8850         if (port->port_status != RTE_PORT_STOPPED) {
8851                 printf("Please stop port %d first\n", res->port_id);
8852                 return;
8853         }
8854
8855         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8856         ret = parse_flexbytes(res->mask,
8857                         flex_mask.mask,
8858                         RTE_ETH_FDIR_MAX_FLEXLEN);
8859         if (ret < 0) {
8860                 printf("error: Cannot parse mask input.\n");
8861                 return;
8862         }
8863
8864         memset(&fdir_info, 0, sizeof(fdir_info));
8865         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8866                                 RTE_ETH_FILTER_INFO, &fdir_info);
8867         if (ret < 0) {
8868                 printf("Cannot get FDir filter info\n");
8869                 return;
8870         }
8871
8872         if (!strcmp(res->flow_type, "none")) {
8873                 /* means don't specify the flow type */
8874                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
8875                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
8876                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
8877                                0, sizeof(struct rte_eth_fdir_flex_mask));
8878                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
8879                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
8880                                  &flex_mask,
8881                                  sizeof(struct rte_eth_fdir_flex_mask));
8882                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8883                 return;
8884         }
8885         flow_type_mask = fdir_info.flow_types_mask[0];
8886         if (!strcmp(res->flow_type, "all")) {
8887                 if (!flow_type_mask) {
8888                         printf("No flow type supported\n");
8889                         return;
8890                 }
8891                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
8892                         if (flow_type_mask & (1 << i)) {
8893                                 flex_mask.flow_type = i;
8894                                 fdir_set_flex_mask(res->port_id, &flex_mask);
8895                         }
8896                 }
8897                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8898                 return;
8899         }
8900         flex_mask.flow_type = str2flowtype(res->flow_type);
8901         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
8902                 printf("Flow type %s not supported on port %d\n",
8903                                 res->flow_type, res->port_id);
8904                 return;
8905         }
8906         fdir_set_flex_mask(res->port_id, &flex_mask);
8907         cmd_reconfig_device_queue(res->port_id, 1, 1);
8908 }
8909
8910 cmdline_parse_token_string_t cmd_flow_director_flexmask =
8911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8912                                  flow_director_flexmask,
8913                                  "flow_director_flex_mask");
8914 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
8915         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8916                               port_id, UINT8);
8917 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
8918         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8919                                  flow, "flow");
8920 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
8921         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8922                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8923                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
8924 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
8925         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8926                                  mask, NULL);
8927
8928 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
8929         .f = cmd_flow_director_flex_mask_parsed,
8930         .data = NULL,
8931         .help_str = "set flow director's flex mask on NIC",
8932         .tokens = {
8933                 (void *)&cmd_flow_director_flexmask,
8934                 (void *)&cmd_flow_director_flexmask_port_id,
8935                 (void *)&cmd_flow_director_flexmask_flow,
8936                 (void *)&cmd_flow_director_flexmask_flow_type,
8937                 (void *)&cmd_flow_director_flexmask_mask,
8938                 NULL,
8939         },
8940 };
8941
8942 /* *** deal with flow director flexible payload configuration *** */
8943 struct cmd_flow_director_flexpayload_result {
8944         cmdline_fixed_string_t flow_director_flexpayload;
8945         uint8_t port_id;
8946         cmdline_fixed_string_t payload_layer;
8947         cmdline_fixed_string_t payload_cfg;
8948 };
8949
8950 static inline int
8951 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
8952 {
8953         char s[256];
8954         const char *p, *p0 = q_arg;
8955         char *end;
8956         unsigned long int_fld;
8957         char *str_fld[max_num];
8958         int i;
8959         unsigned size;
8960         int ret = -1;
8961
8962         p = strchr(p0, '(');
8963         if (p == NULL)
8964                 return -1;
8965         ++p;
8966         p0 = strchr(p, ')');
8967         if (p0 == NULL)
8968                 return -1;
8969
8970         size = p0 - p;
8971         if (size >= sizeof(s))
8972                 return -1;
8973
8974         snprintf(s, sizeof(s), "%.*s", size, p);
8975         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8976         if (ret < 0 || ret > max_num)
8977                 return -1;
8978         for (i = 0; i < ret; i++) {
8979                 errno = 0;
8980                 int_fld = strtoul(str_fld[i], &end, 0);
8981                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
8982                         return -1;
8983                 offsets[i] = (uint16_t)int_fld;
8984         }
8985         return ret;
8986 }
8987
8988 static void
8989 cmd_flow_director_flxpld_parsed(void *parsed_result,
8990                           __attribute__((unused)) struct cmdline *cl,
8991                           __attribute__((unused)) void *data)
8992 {
8993         struct cmd_flow_director_flexpayload_result *res = parsed_result;
8994         struct rte_eth_flex_payload_cfg flex_cfg;
8995         struct rte_port *port;
8996         int ret = 0;
8997
8998         if (res->port_id > nb_ports) {
8999                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9000                 return;
9001         }
9002
9003         port = &ports[res->port_id];
9004         /** Check if the port is not started **/
9005         if (port->port_status != RTE_PORT_STOPPED) {
9006                 printf("Please stop port %d first\n", res->port_id);
9007                 return;
9008         }
9009
9010         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9011
9012         if (!strcmp(res->payload_layer, "raw"))
9013                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9014         else if (!strcmp(res->payload_layer, "l2"))
9015                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9016         else if (!strcmp(res->payload_layer, "l3"))
9017                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9018         else if (!strcmp(res->payload_layer, "l4"))
9019                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9020
9021         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9022                             RTE_ETH_FDIR_MAX_FLEXLEN);
9023         if (ret < 0) {
9024                 printf("error: Cannot parse flex payload input.\n");
9025                 return;
9026         }
9027
9028         fdir_set_flex_payload(res->port_id, &flex_cfg);
9029         cmd_reconfig_device_queue(res->port_id, 1, 1);
9030 }
9031
9032 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9033         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9034                                  flow_director_flexpayload,
9035                                  "flow_director_flex_payload");
9036 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9037         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9038                               port_id, UINT8);
9039 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9040         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9041                                  payload_layer, "raw#l2#l3#l4");
9042 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9043         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9044                                  payload_cfg, NULL);
9045
9046 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9047         .f = cmd_flow_director_flxpld_parsed,
9048         .data = NULL,
9049         .help_str = "set flow director's flex payload on NIC",
9050         .tokens = {
9051                 (void *)&cmd_flow_director_flexpayload,
9052                 (void *)&cmd_flow_director_flexpayload_port_id,
9053                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9054                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9055                 NULL,
9056         },
9057 };
9058
9059 /* *** Classification Filters Control *** */
9060 /* *** Get symmetric hash enable per port *** */
9061 struct cmd_get_sym_hash_ena_per_port_result {
9062         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9063         uint8_t port_id;
9064 };
9065
9066 static void
9067 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9068                                  __rte_unused struct cmdline *cl,
9069                                  __rte_unused void *data)
9070 {
9071         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9072         struct rte_eth_hash_filter_info info;
9073         int ret;
9074
9075         if (rte_eth_dev_filter_supported(res->port_id,
9076                                 RTE_ETH_FILTER_HASH) < 0) {
9077                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9078                                                         res->port_id);
9079                 return;
9080         }
9081
9082         memset(&info, 0, sizeof(info));
9083         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9084         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9085                                                 RTE_ETH_FILTER_GET, &info);
9086
9087         if (ret < 0) {
9088                 printf("Cannot get symmetric hash enable per port "
9089                                         "on port %u\n", res->port_id);
9090                 return;
9091         }
9092
9093         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9094                                 "enabled" : "disabled", res->port_id);
9095 }
9096
9097 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9098         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9099                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9100 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9101         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9102                 port_id, UINT8);
9103
9104 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9105         .f = cmd_get_sym_hash_per_port_parsed,
9106         .data = NULL,
9107         .help_str = "get_sym_hash_ena_per_port port_id",
9108         .tokens = {
9109                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9110                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9111                 NULL,
9112         },
9113 };
9114
9115 /* *** Set symmetric hash enable per port *** */
9116 struct cmd_set_sym_hash_ena_per_port_result {
9117         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9118         cmdline_fixed_string_t enable;
9119         uint8_t port_id;
9120 };
9121
9122 static void
9123 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9124                                  __rte_unused struct cmdline *cl,
9125                                  __rte_unused void *data)
9126 {
9127         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9128         struct rte_eth_hash_filter_info info;
9129         int ret;
9130
9131         if (rte_eth_dev_filter_supported(res->port_id,
9132                                 RTE_ETH_FILTER_HASH) < 0) {
9133                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9134                                                         res->port_id);
9135                 return;
9136         }
9137
9138         memset(&info, 0, sizeof(info));
9139         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9140         if (!strcmp(res->enable, "enable"))
9141                 info.info.enable = 1;
9142         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9143                                         RTE_ETH_FILTER_SET, &info);
9144         if (ret < 0) {
9145                 printf("Cannot set symmetric hash enable per port on "
9146                                         "port %u\n", res->port_id);
9147                 return;
9148         }
9149         printf("Symmetric hash has been set to %s on port %u\n",
9150                                         res->enable, res->port_id);
9151 }
9152
9153 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9154         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9155                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9156 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9157         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9158                 port_id, UINT8);
9159 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9160         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9161                 enable, "enable#disable");
9162
9163 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9164         .f = cmd_set_sym_hash_per_port_parsed,
9165         .data = NULL,
9166         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
9167         .tokens = {
9168                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9169                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9170                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9171                 NULL,
9172         },
9173 };
9174
9175 /* Get global config of hash function */
9176 struct cmd_get_hash_global_config_result {
9177         cmdline_fixed_string_t get_hash_global_config;
9178         uint8_t port_id;
9179 };
9180
9181 static char *
9182 flowtype_to_str(uint16_t ftype)
9183 {
9184         uint16_t i;
9185         static struct {
9186                 char str[16];
9187                 uint16_t ftype;
9188         } ftype_table[] = {
9189                 {"ipv4", RTE_ETH_FLOW_IPV4},
9190                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9191                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9192                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9193                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9194                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9195                 {"ipv6", RTE_ETH_FLOW_IPV6},
9196                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9197                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9198                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9199                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9200                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9201                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9202         };
9203
9204         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9205                 if (ftype_table[i].ftype == ftype)
9206                         return ftype_table[i].str;
9207         }
9208
9209         return NULL;
9210 }
9211
9212 static void
9213 cmd_get_hash_global_config_parsed(void *parsed_result,
9214                                   __rte_unused struct cmdline *cl,
9215                                   __rte_unused void *data)
9216 {
9217         struct cmd_get_hash_global_config_result *res = parsed_result;
9218         struct rte_eth_hash_filter_info info;
9219         uint32_t idx, offset;
9220         uint16_t i;
9221         char *str;
9222         int ret;
9223
9224         if (rte_eth_dev_filter_supported(res->port_id,
9225                         RTE_ETH_FILTER_HASH) < 0) {
9226                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9227                                                         res->port_id);
9228                 return;
9229         }
9230
9231         memset(&info, 0, sizeof(info));
9232         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9233         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9234                                         RTE_ETH_FILTER_GET, &info);
9235         if (ret < 0) {
9236                 printf("Cannot get hash global configurations by port %d\n",
9237                                                         res->port_id);
9238                 return;
9239         }
9240
9241         switch (info.info.global_conf.hash_func) {
9242         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9243                 printf("Hash function is Toeplitz\n");
9244                 break;
9245         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9246                 printf("Hash function is Simple XOR\n");
9247                 break;
9248         default:
9249                 printf("Unknown hash function\n");
9250                 break;
9251         }
9252
9253         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9254                 idx = i / UINT32_BIT;
9255                 offset = i % UINT32_BIT;
9256                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9257                                                 (1UL << offset)))
9258                         continue;
9259                 str = flowtype_to_str(i);
9260                 if (!str)
9261                         continue;
9262                 printf("Symmetric hash is %s globally for flow type %s "
9263                                                         "by port %d\n",
9264                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9265                         (1UL << offset)) ? "enabled" : "disabled"), str,
9266                                                         res->port_id);
9267         }
9268 }
9269
9270 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9271         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9272                 get_hash_global_config, "get_hash_global_config");
9273 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9274         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9275                 port_id, UINT8);
9276
9277 cmdline_parse_inst_t cmd_get_hash_global_config = {
9278         .f = cmd_get_hash_global_config_parsed,
9279         .data = NULL,
9280         .help_str = "get_hash_global_config port_id",
9281         .tokens = {
9282                 (void *)&cmd_get_hash_global_config_all,
9283                 (void *)&cmd_get_hash_global_config_port_id,
9284                 NULL,
9285         },
9286 };
9287
9288 /* Set global config of hash function */
9289 struct cmd_set_hash_global_config_result {
9290         cmdline_fixed_string_t set_hash_global_config;
9291         uint8_t port_id;
9292         cmdline_fixed_string_t hash_func;
9293         cmdline_fixed_string_t flow_type;
9294         cmdline_fixed_string_t enable;
9295 };
9296
9297 static void
9298 cmd_set_hash_global_config_parsed(void *parsed_result,
9299                                   __rte_unused struct cmdline *cl,
9300                                   __rte_unused void *data)
9301 {
9302         struct cmd_set_hash_global_config_result *res = parsed_result;
9303         struct rte_eth_hash_filter_info info;
9304         uint32_t ftype, idx, offset;
9305         int ret;
9306
9307         if (rte_eth_dev_filter_supported(res->port_id,
9308                                 RTE_ETH_FILTER_HASH) < 0) {
9309                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9310                                                         res->port_id);
9311                 return;
9312         }
9313         memset(&info, 0, sizeof(info));
9314         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9315         if (!strcmp(res->hash_func, "toeplitz"))
9316                 info.info.global_conf.hash_func =
9317                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9318         else if (!strcmp(res->hash_func, "simple_xor"))
9319                 info.info.global_conf.hash_func =
9320                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9321         else if (!strcmp(res->hash_func, "default"))
9322                 info.info.global_conf.hash_func =
9323                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9324
9325         ftype = str2flowtype(res->flow_type);
9326         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9327         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9328         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9329         if (!strcmp(res->enable, "enable"))
9330                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9331                                                 (1UL << offset);
9332         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9333                                         RTE_ETH_FILTER_SET, &info);
9334         if (ret < 0)
9335                 printf("Cannot set global hash configurations by port %d\n",
9336                                                         res->port_id);
9337         else
9338                 printf("Global hash configurations have been set "
9339                         "succcessfully by port %d\n", res->port_id);
9340 }
9341
9342 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9343         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9344                 set_hash_global_config, "set_hash_global_config");
9345 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9346         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9347                 port_id, UINT8);
9348 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9349         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9350                 hash_func, "toeplitz#simple_xor#default");
9351 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9352         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9353                 flow_type,
9354                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9355                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9356 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9357         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9358                 enable, "enable#disable");
9359
9360 cmdline_parse_inst_t cmd_set_hash_global_config = {
9361         .f = cmd_set_hash_global_config_parsed,
9362         .data = NULL,
9363         .help_str = "set_hash_global_config port_id "
9364                 "toeplitz|simple_xor|default "
9365                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
9366                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9367                 "enable|disable",
9368         .tokens = {
9369                 (void *)&cmd_set_hash_global_config_all,
9370                 (void *)&cmd_set_hash_global_config_port_id,
9371                 (void *)&cmd_set_hash_global_config_hash_func,
9372                 (void *)&cmd_set_hash_global_config_flow_type,
9373                 (void *)&cmd_set_hash_global_config_enable,
9374                 NULL,
9375         },
9376 };
9377
9378 /* Set hash input set */
9379 struct cmd_set_hash_input_set_result {
9380         cmdline_fixed_string_t set_hash_input_set;
9381         uint8_t port_id;
9382         cmdline_fixed_string_t flow_type;
9383         cmdline_fixed_string_t inset_field;
9384         cmdline_fixed_string_t select;
9385 };
9386
9387 static enum rte_eth_input_set_field
9388 str2inset(char *string)
9389 {
9390         uint16_t i;
9391
9392         static const struct {
9393                 char str[32];
9394                 enum rte_eth_input_set_field inset;
9395         } inset_table[] = {
9396                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9397                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9398                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9399                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9400                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9401                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9402                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9403                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9404                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9405                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9406                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9407                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9408                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9409                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9410                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9411                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9412                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9413                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9414                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9415                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9416                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9417                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9418                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9419                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9420                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9421                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9422                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9423                 {"none", RTE_ETH_INPUT_SET_NONE},
9424         };
9425
9426         for (i = 0; i < RTE_DIM(inset_table); i++) {
9427                 if (!strcmp(string, inset_table[i].str))
9428                         return inset_table[i].inset;
9429         }
9430
9431         return RTE_ETH_INPUT_SET_UNKNOWN;
9432 }
9433
9434 static void
9435 cmd_set_hash_input_set_parsed(void *parsed_result,
9436                               __rte_unused struct cmdline *cl,
9437                               __rte_unused void *data)
9438 {
9439         struct cmd_set_hash_input_set_result *res = parsed_result;
9440         struct rte_eth_hash_filter_info info;
9441
9442         memset(&info, 0, sizeof(info));
9443         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
9444         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9445         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9446         info.info.input_set_conf.inset_size = 1;
9447         if (!strcmp(res->select, "select"))
9448                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9449         else if (!strcmp(res->select, "add"))
9450                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9451         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9452                                 RTE_ETH_FILTER_SET, &info);
9453 }
9454
9455 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
9456         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9457                 set_hash_input_set, "set_hash_input_set");
9458 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
9459         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
9460                 port_id, UINT8);
9461 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
9462         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9463                 flow_type,
9464                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9465                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9466 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
9467         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9468                 inset_field,
9469                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9470                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
9471                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
9472                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
9473                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
9474                 "fld-8th#none");
9475 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
9476         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9477                 select, "select#add");
9478
9479 cmdline_parse_inst_t cmd_set_hash_input_set = {
9480         .f = cmd_set_hash_input_set_parsed,
9481         .data = NULL,
9482         .help_str = "set_hash_input_set <port_id> "
9483         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9484         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9485         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
9486         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
9487         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
9488         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9489         "fld-7th|fld-8th|none select|add",
9490         .tokens = {
9491                 (void *)&cmd_set_hash_input_set_cmd,
9492                 (void *)&cmd_set_hash_input_set_port_id,
9493                 (void *)&cmd_set_hash_input_set_flow_type,
9494                 (void *)&cmd_set_hash_input_set_field,
9495                 (void *)&cmd_set_hash_input_set_select,
9496                 NULL,
9497         },
9498 };
9499
9500 /* Set flow director input set */
9501 struct cmd_set_fdir_input_set_result {
9502         cmdline_fixed_string_t set_fdir_input_set;
9503         uint8_t port_id;
9504         cmdline_fixed_string_t flow_type;
9505         cmdline_fixed_string_t inset_field;
9506         cmdline_fixed_string_t select;
9507 };
9508
9509 static void
9510 cmd_set_fdir_input_set_parsed(void *parsed_result,
9511         __rte_unused struct cmdline *cl,
9512         __rte_unused void *data)
9513 {
9514         struct cmd_set_fdir_input_set_result *res = parsed_result;
9515         struct rte_eth_fdir_filter_info info;
9516
9517         memset(&info, 0, sizeof(info));
9518         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
9519         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9520         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9521         info.info.input_set_conf.inset_size = 1;
9522         if (!strcmp(res->select, "select"))
9523                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9524         else if (!strcmp(res->select, "add"))
9525                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9526         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9527                 RTE_ETH_FILTER_SET, &info);
9528 }
9529
9530 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
9531         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9532         set_fdir_input_set, "set_fdir_input_set");
9533 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
9534         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
9535         port_id, UINT8);
9536 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
9537         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9538         flow_type,
9539         "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9540         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9541 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
9542         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9543         inset_field,
9544         "src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#udp-src-port#udp-dst-port#"
9545         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
9546         "sctp-veri-tag#fld-1st#fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#"
9547         "fld-7th#fld-8th#none");
9548 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
9549         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9550         select, "select#add");
9551
9552 cmdline_parse_inst_t cmd_set_fdir_input_set = {
9553         .f = cmd_set_fdir_input_set_parsed,
9554         .data = NULL,
9555         .help_str = "set_fdir_input_set <port_id> "
9556         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9557         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9558         "src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|udp-src-port|udp-dst-port|"
9559         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|"
9560         "fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9561         "fld-7th|fld-8th|none select|add",
9562         .tokens = {
9563                 (void *)&cmd_set_fdir_input_set_cmd,
9564                 (void *)&cmd_set_fdir_input_set_port_id,
9565                 (void *)&cmd_set_fdir_input_set_flow_type,
9566                 (void *)&cmd_set_fdir_input_set_field,
9567                 (void *)&cmd_set_fdir_input_set_select,
9568                 NULL,
9569         },
9570 };
9571
9572 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
9573 struct cmd_mcast_addr_result {
9574         cmdline_fixed_string_t mcast_addr_cmd;
9575         cmdline_fixed_string_t what;
9576         uint8_t port_num;
9577         struct ether_addr mc_addr;
9578 };
9579
9580 static void cmd_mcast_addr_parsed(void *parsed_result,
9581                 __attribute__((unused)) struct cmdline *cl,
9582                 __attribute__((unused)) void *data)
9583 {
9584         struct cmd_mcast_addr_result *res = parsed_result;
9585
9586         if (!is_multicast_ether_addr(&res->mc_addr)) {
9587                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
9588                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
9589                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
9590                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
9591                 return;
9592         }
9593         if (strcmp(res->what, "add") == 0)
9594                 mcast_addr_add(res->port_num, &res->mc_addr);
9595         else
9596                 mcast_addr_remove(res->port_num, &res->mc_addr);
9597 }
9598
9599 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
9600         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
9601                                  mcast_addr_cmd, "mcast_addr");
9602 cmdline_parse_token_string_t cmd_mcast_addr_what =
9603         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
9604                                  "add#remove");
9605 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
9606         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
9607 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
9608         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
9609
9610 cmdline_parse_inst_t cmd_mcast_addr = {
9611         .f = cmd_mcast_addr_parsed,
9612         .data = (void *)0,
9613         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
9614         .tokens = {
9615                 (void *)&cmd_mcast_addr_cmd,
9616                 (void *)&cmd_mcast_addr_what,
9617                 (void *)&cmd_mcast_addr_portnum,
9618                 (void *)&cmd_mcast_addr_addr,
9619                 NULL,
9620         },
9621 };
9622
9623 /* ******************************************************************************** */
9624
9625 /* list of instructions */
9626 cmdline_parse_ctx_t main_ctx[] = {
9627         (cmdline_parse_inst_t *)&cmd_help_brief,
9628         (cmdline_parse_inst_t *)&cmd_help_long,
9629         (cmdline_parse_inst_t *)&cmd_quit,
9630         (cmdline_parse_inst_t *)&cmd_showport,
9631         (cmdline_parse_inst_t *)&cmd_showqueue,
9632         (cmdline_parse_inst_t *)&cmd_showportall,
9633         (cmdline_parse_inst_t *)&cmd_showcfg,
9634         (cmdline_parse_inst_t *)&cmd_start,
9635         (cmdline_parse_inst_t *)&cmd_start_tx_first,
9636         (cmdline_parse_inst_t *)&cmd_set_link_up,
9637         (cmdline_parse_inst_t *)&cmd_set_link_down,
9638         (cmdline_parse_inst_t *)&cmd_reset,
9639         (cmdline_parse_inst_t *)&cmd_set_numbers,
9640         (cmdline_parse_inst_t *)&cmd_set_txpkts,
9641         (cmdline_parse_inst_t *)&cmd_set_txsplit,
9642         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
9643         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
9644         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
9645         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
9646         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
9647         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
9648         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
9649         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
9650         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
9651         (cmdline_parse_inst_t *)&cmd_set_link_check,
9652 #ifdef RTE_NIC_BYPASS
9653         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
9654         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
9655         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
9656         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
9657 #endif
9658 #ifdef RTE_LIBRTE_PMD_BOND
9659         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
9660         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
9661         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
9662         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
9663         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
9664         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
9665         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
9666         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
9667         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
9668 #endif
9669         (cmdline_parse_inst_t *)&cmd_vlan_offload,
9670         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
9671         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
9672         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
9673         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
9674         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
9675         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
9676         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
9677         (cmdline_parse_inst_t *)&cmd_csum_set,
9678         (cmdline_parse_inst_t *)&cmd_csum_show,
9679         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
9680         (cmdline_parse_inst_t *)&cmd_tso_set,
9681         (cmdline_parse_inst_t *)&cmd_tso_show,
9682         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
9683         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
9684         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
9685         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
9686         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
9687         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
9688         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
9689         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
9690         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
9691         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
9692         (cmdline_parse_inst_t *)&cmd_config_dcb,
9693         (cmdline_parse_inst_t *)&cmd_read_reg,
9694         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
9695         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
9696         (cmdline_parse_inst_t *)&cmd_write_reg,
9697         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
9698         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
9699         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
9700         (cmdline_parse_inst_t *)&cmd_stop,
9701         (cmdline_parse_inst_t *)&cmd_mac_addr,
9702         (cmdline_parse_inst_t *)&cmd_set_qmap,
9703         (cmdline_parse_inst_t *)&cmd_operate_port,
9704         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
9705         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
9706         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
9707         (cmdline_parse_inst_t *)&cmd_config_speed_all,
9708         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
9709         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
9710         (cmdline_parse_inst_t *)&cmd_config_mtu,
9711         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
9712         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
9713         (cmdline_parse_inst_t *)&cmd_config_rss,
9714         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
9715         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
9716         (cmdline_parse_inst_t *)&cmd_showport_reta,
9717         (cmdline_parse_inst_t *)&cmd_config_burst,
9718         (cmdline_parse_inst_t *)&cmd_config_thresh,
9719         (cmdline_parse_inst_t *)&cmd_config_threshold,
9720         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
9721         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
9722         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
9723         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
9724         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
9725         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
9726         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
9727         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
9728         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
9729         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
9730         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
9731         (cmdline_parse_inst_t *)&cmd_global_config,
9732         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
9733         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
9734         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
9735         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
9736         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
9737         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
9738         (cmdline_parse_inst_t *)&cmd_dump,
9739         (cmdline_parse_inst_t *)&cmd_dump_one,
9740         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
9741         (cmdline_parse_inst_t *)&cmd_syn_filter,
9742         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
9743         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
9744         (cmdline_parse_inst_t *)&cmd_flex_filter,
9745         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
9746         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
9747         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
9748         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
9749         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
9750         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
9751         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
9752         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
9753         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
9754         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
9755         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
9756         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
9757         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
9758         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
9759         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
9760         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
9761         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
9762         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
9763         (cmdline_parse_inst_t *)&cmd_mcast_addr,
9764         NULL,
9765 };
9766
9767 /* prompt function, called from main on MASTER lcore */
9768 void
9769 prompt(void)
9770 {
9771         /* initialize non-constant commands */
9772         cmd_set_fwd_mode_init();
9773
9774         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
9775         if (testpmd_cl == NULL)
9776                 return;
9777         cmdline_interact(testpmd_cl);
9778         cmdline_stdin_exit(testpmd_cl);
9779 }
9780
9781 void
9782 prompt_exit(void)
9783 {
9784         if (testpmd_cl != NULL)
9785                 cmdline_quit(testpmd_cl);
9786 }
9787
9788 static void
9789 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
9790 {
9791         if (id == (portid_t)RTE_PORT_ALL) {
9792                 portid_t pid;
9793
9794                 FOREACH_PORT(pid, ports) {
9795                         /* check if need_reconfig has been set to 1 */
9796                         if (ports[pid].need_reconfig == 0)
9797                                 ports[pid].need_reconfig = dev;
9798                         /* check if need_reconfig_queues has been set to 1 */
9799                         if (ports[pid].need_reconfig_queues == 0)
9800                                 ports[pid].need_reconfig_queues = queue;
9801                 }
9802         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
9803                 /* check if need_reconfig has been set to 1 */
9804                 if (ports[id].need_reconfig == 0)
9805                         ports[id].need_reconfig = dev;
9806                 /* check if need_reconfig_queues has been set to 1 */
9807                 if (ports[id].need_reconfig_queues == 0)
9808                         ports[id].need_reconfig_queues = queue;
9809         }
9810 }
9811
9812 #ifdef RTE_NIC_BYPASS
9813 #include <rte_pci_dev_ids.h>
9814 uint8_t
9815 bypass_is_supported(portid_t port_id)
9816 {
9817         struct rte_port   *port;
9818         struct rte_pci_id *pci_id;
9819
9820         if (port_id_is_invalid(port_id, ENABLED_WARN))
9821                 return 0;
9822
9823         /* Get the device id. */
9824         port    = &ports[port_id];
9825         pci_id = &port->dev_info.pci_dev->id;
9826
9827         /* Check if NIC supports bypass. */
9828         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
9829                 return 1;
9830         }
9831         else {
9832                 printf("\tBypass not supported for port_id = %d.\n", port_id);
9833                 return 0;
9834         }
9835 }
9836 #endif