remove extra parentheses in return statement
[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         uint8_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 = (uint8_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         int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id);
2958
2959         if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2960                 printf("Error, as QinQ has been enabled.\n");
2961                 return;
2962         }
2963
2964         tx_vlan_set(res->port_id, res->vlan_id);
2965 }
2966
2967 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2968         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2969                                  tx_vlan, "tx_vlan");
2970 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2971         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2972                                  set, "set");
2973 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2974         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2975                               vlan_id, UINT16);
2976 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2977         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2978                               port_id, UINT8);
2979
2980 cmdline_parse_inst_t cmd_tx_vlan_set = {
2981         .f = cmd_tx_vlan_set_parsed,
2982         .data = NULL,
2983         .help_str = "enable hardware insertion of a single VLAN header "
2984                 "with a given TAG Identifier in packets sent on a port",
2985         .tokens = {
2986                 (void *)&cmd_tx_vlan_set_tx_vlan,
2987                 (void *)&cmd_tx_vlan_set_set,
2988                 (void *)&cmd_tx_vlan_set_portid,
2989                 (void *)&cmd_tx_vlan_set_vlanid,
2990                 NULL,
2991         },
2992 };
2993
2994 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
2995 struct cmd_tx_vlan_set_qinq_result {
2996         cmdline_fixed_string_t tx_vlan;
2997         cmdline_fixed_string_t set;
2998         uint8_t port_id;
2999         uint16_t vlan_id;
3000         uint16_t vlan_id_outer;
3001 };
3002
3003 static void
3004 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3005                             __attribute__((unused)) struct cmdline *cl,
3006                             __attribute__((unused)) void *data)
3007 {
3008         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3009         int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id);
3010
3011         if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
3012                 printf("Error, as QinQ hasn't been enabled.\n");
3013                 return;
3014         }
3015
3016         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3017 }
3018
3019 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3020         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3021                 tx_vlan, "tx_vlan");
3022 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3023         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3024                 set, "set");
3025 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3026         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3027                 port_id, UINT8);
3028 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3029         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3030                 vlan_id, UINT16);
3031 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3032         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3033                 vlan_id_outer, UINT16);
3034
3035 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3036         .f = cmd_tx_vlan_set_qinq_parsed,
3037         .data = NULL,
3038         .help_str = "enable hardware insertion of double VLAN header "
3039                 "with given TAG Identifiers in packets sent on a port",
3040         .tokens = {
3041                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3042                 (void *)&cmd_tx_vlan_set_qinq_set,
3043                 (void *)&cmd_tx_vlan_set_qinq_portid,
3044                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3045                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3046                 NULL,
3047         },
3048 };
3049
3050 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3051 struct cmd_tx_vlan_set_pvid_result {
3052         cmdline_fixed_string_t tx_vlan;
3053         cmdline_fixed_string_t set;
3054         cmdline_fixed_string_t pvid;
3055         uint8_t port_id;
3056         uint16_t vlan_id;
3057         cmdline_fixed_string_t mode;
3058 };
3059
3060 static void
3061 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3062                             __attribute__((unused)) struct cmdline *cl,
3063                             __attribute__((unused)) void *data)
3064 {
3065         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3066
3067         if (strcmp(res->mode, "on") == 0)
3068                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3069         else
3070                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3071 }
3072
3073 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3074         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3075                                  tx_vlan, "tx_vlan");
3076 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3077         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3078                                  set, "set");
3079 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3080         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3081                                  pvid, "pvid");
3082 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3083         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3084                              port_id, UINT8);
3085 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3086         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3087                               vlan_id, UINT16);
3088 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3089         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3090                                  mode, "on#off");
3091
3092 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3093         .f = cmd_tx_vlan_set_pvid_parsed,
3094         .data = NULL,
3095         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
3096         .tokens = {
3097                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3098                 (void *)&cmd_tx_vlan_set_pvid_set,
3099                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3100                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3101                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3102                 (void *)&cmd_tx_vlan_set_pvid_mode,
3103                 NULL,
3104         },
3105 };
3106
3107 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3108 struct cmd_tx_vlan_reset_result {
3109         cmdline_fixed_string_t tx_vlan;
3110         cmdline_fixed_string_t reset;
3111         uint8_t port_id;
3112 };
3113
3114 static void
3115 cmd_tx_vlan_reset_parsed(void *parsed_result,
3116                          __attribute__((unused)) struct cmdline *cl,
3117                          __attribute__((unused)) void *data)
3118 {
3119         struct cmd_tx_vlan_reset_result *res = parsed_result;
3120
3121         tx_vlan_reset(res->port_id);
3122 }
3123
3124 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3125         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3126                                  tx_vlan, "tx_vlan");
3127 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3128         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3129                                  reset, "reset");
3130 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3131         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3132                               port_id, UINT8);
3133
3134 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3135         .f = cmd_tx_vlan_reset_parsed,
3136         .data = NULL,
3137         .help_str = "disable hardware insertion of a VLAN header in packets "
3138         "sent on a port",
3139         .tokens = {
3140                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3141                 (void *)&cmd_tx_vlan_reset_reset,
3142                 (void *)&cmd_tx_vlan_reset_portid,
3143                 NULL,
3144         },
3145 };
3146
3147
3148 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3149 struct cmd_csum_result {
3150         cmdline_fixed_string_t csum;
3151         cmdline_fixed_string_t mode;
3152         cmdline_fixed_string_t proto;
3153         cmdline_fixed_string_t hwsw;
3154         uint8_t port_id;
3155 };
3156
3157 static void
3158 csum_show(int port_id)
3159 {
3160         struct rte_eth_dev_info dev_info;
3161         uint16_t ol_flags;
3162
3163         ol_flags = ports[port_id].tx_ol_flags;
3164         printf("Parse tunnel is %s\n",
3165                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3166         printf("IP checksum offload is %s\n",
3167                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3168         printf("UDP checksum offload is %s\n",
3169                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3170         printf("TCP checksum offload is %s\n",
3171                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3172         printf("SCTP checksum offload is %s\n",
3173                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3174         printf("Outer-Ip checksum offload is %s\n",
3175                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3176
3177         /* display warnings if configuration is not supported by the NIC */
3178         rte_eth_dev_info_get(port_id, &dev_info);
3179         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3180                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3181                 printf("Warning: hardware IP checksum enabled but not "
3182                         "supported by port %d\n", port_id);
3183         }
3184         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3185                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3186                 printf("Warning: hardware UDP checksum enabled but not "
3187                         "supported by port %d\n", port_id);
3188         }
3189         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3190                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3191                 printf("Warning: hardware TCP checksum enabled but not "
3192                         "supported by port %d\n", port_id);
3193         }
3194         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3195                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3196                 printf("Warning: hardware SCTP checksum enabled but not "
3197                         "supported by port %d\n", port_id);
3198         }
3199         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3200                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3201                 printf("Warning: hardware outer IP checksum enabled but not "
3202                         "supported by port %d\n", port_id);
3203         }
3204 }
3205
3206 static void
3207 cmd_csum_parsed(void *parsed_result,
3208                        __attribute__((unused)) struct cmdline *cl,
3209                        __attribute__((unused)) void *data)
3210 {
3211         struct cmd_csum_result *res = parsed_result;
3212         int hw = 0;
3213         uint16_t mask = 0;
3214
3215         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3216                 printf("invalid port %d\n", res->port_id);
3217                 return;
3218         }
3219
3220         if (!strcmp(res->mode, "set")) {
3221
3222                 if (!strcmp(res->hwsw, "hw"))
3223                         hw = 1;
3224
3225                 if (!strcmp(res->proto, "ip")) {
3226                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3227                 } else if (!strcmp(res->proto, "udp")) {
3228                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3229                 } else if (!strcmp(res->proto, "tcp")) {
3230                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3231                 } else if (!strcmp(res->proto, "sctp")) {
3232                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3233                 } else if (!strcmp(res->proto, "outer-ip")) {
3234                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3235                 }
3236
3237                 if (hw)
3238                         ports[res->port_id].tx_ol_flags |= mask;
3239                 else
3240                         ports[res->port_id].tx_ol_flags &= (~mask);
3241         }
3242         csum_show(res->port_id);
3243 }
3244
3245 cmdline_parse_token_string_t cmd_csum_csum =
3246         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3247                                 csum, "csum");
3248 cmdline_parse_token_string_t cmd_csum_mode =
3249         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3250                                 mode, "set");
3251 cmdline_parse_token_string_t cmd_csum_proto =
3252         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3253                                 proto, "ip#tcp#udp#sctp#outer-ip");
3254 cmdline_parse_token_string_t cmd_csum_hwsw =
3255         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3256                                 hwsw, "hw#sw");
3257 cmdline_parse_token_num_t cmd_csum_portid =
3258         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3259                                 port_id, UINT8);
3260
3261 cmdline_parse_inst_t cmd_csum_set = {
3262         .f = cmd_csum_parsed,
3263         .data = NULL,
3264         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
3265                 "using csum forward engine: csum set ip|tcp|udp|sctp|outer-ip hw|sw <port>",
3266         .tokens = {
3267                 (void *)&cmd_csum_csum,
3268                 (void *)&cmd_csum_mode,
3269                 (void *)&cmd_csum_proto,
3270                 (void *)&cmd_csum_hwsw,
3271                 (void *)&cmd_csum_portid,
3272                 NULL,
3273         },
3274 };
3275
3276 cmdline_parse_token_string_t cmd_csum_mode_show =
3277         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3278                                 mode, "show");
3279
3280 cmdline_parse_inst_t cmd_csum_show = {
3281         .f = cmd_csum_parsed,
3282         .data = NULL,
3283         .help_str = "show checksum offload configuration: csum show <port>",
3284         .tokens = {
3285                 (void *)&cmd_csum_csum,
3286                 (void *)&cmd_csum_mode_show,
3287                 (void *)&cmd_csum_portid,
3288                 NULL,
3289         },
3290 };
3291
3292 /* Enable/disable tunnel parsing */
3293 struct cmd_csum_tunnel_result {
3294         cmdline_fixed_string_t csum;
3295         cmdline_fixed_string_t parse;
3296         cmdline_fixed_string_t onoff;
3297         uint8_t port_id;
3298 };
3299
3300 static void
3301 cmd_csum_tunnel_parsed(void *parsed_result,
3302                        __attribute__((unused)) struct cmdline *cl,
3303                        __attribute__((unused)) void *data)
3304 {
3305         struct cmd_csum_tunnel_result *res = parsed_result;
3306
3307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3308                 return;
3309
3310         if (!strcmp(res->onoff, "on"))
3311                 ports[res->port_id].tx_ol_flags |=
3312                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3313         else
3314                 ports[res->port_id].tx_ol_flags &=
3315                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3316
3317         csum_show(res->port_id);
3318 }
3319
3320 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3321         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3322                                 csum, "csum");
3323 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3324         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3325                                 parse, "parse_tunnel");
3326 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3327         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3328                                 onoff, "on#off");
3329 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3330         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3331                                 port_id, UINT8);
3332
3333 cmdline_parse_inst_t cmd_csum_tunnel = {
3334         .f = cmd_csum_tunnel_parsed,
3335         .data = NULL,
3336         .help_str = "enable/disable parsing of tunnels for csum engine: "
3337         "csum parse_tunnel on|off <tx-port>",
3338         .tokens = {
3339                 (void *)&cmd_csum_tunnel_csum,
3340                 (void *)&cmd_csum_tunnel_parse,
3341                 (void *)&cmd_csum_tunnel_onoff,
3342                 (void *)&cmd_csum_tunnel_portid,
3343                 NULL,
3344         },
3345 };
3346
3347 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3348 struct cmd_tso_set_result {
3349         cmdline_fixed_string_t tso;
3350         cmdline_fixed_string_t mode;
3351         uint16_t tso_segsz;
3352         uint8_t port_id;
3353 };
3354
3355 static void
3356 cmd_tso_set_parsed(void *parsed_result,
3357                        __attribute__((unused)) struct cmdline *cl,
3358                        __attribute__((unused)) void *data)
3359 {
3360         struct cmd_tso_set_result *res = parsed_result;
3361         struct rte_eth_dev_info dev_info;
3362
3363         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3364                 return;
3365
3366         if (!strcmp(res->mode, "set"))
3367                 ports[res->port_id].tso_segsz = res->tso_segsz;
3368
3369         if (ports[res->port_id].tso_segsz == 0)
3370                 printf("TSO is disabled\n");
3371         else
3372                 printf("TSO segment size is %d\n",
3373                         ports[res->port_id].tso_segsz);
3374
3375         /* display warnings if configuration is not supported by the NIC */
3376         rte_eth_dev_info_get(res->port_id, &dev_info);
3377         if ((ports[res->port_id].tso_segsz != 0) &&
3378                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3379                 printf("Warning: TSO enabled but not "
3380                         "supported by port %d\n", res->port_id);
3381         }
3382 }
3383
3384 cmdline_parse_token_string_t cmd_tso_set_tso =
3385         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3386                                 tso, "tso");
3387 cmdline_parse_token_string_t cmd_tso_set_mode =
3388         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3389                                 mode, "set");
3390 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3391         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3392                                 tso_segsz, UINT16);
3393 cmdline_parse_token_num_t cmd_tso_set_portid =
3394         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3395                                 port_id, UINT8);
3396
3397 cmdline_parse_inst_t cmd_tso_set = {
3398         .f = cmd_tso_set_parsed,
3399         .data = NULL,
3400         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3401         "tso set <tso_segsz> <port>",
3402         .tokens = {
3403                 (void *)&cmd_tso_set_tso,
3404                 (void *)&cmd_tso_set_mode,
3405                 (void *)&cmd_tso_set_tso_segsz,
3406                 (void *)&cmd_tso_set_portid,
3407                 NULL,
3408         },
3409 };
3410
3411 cmdline_parse_token_string_t cmd_tso_show_mode =
3412         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3413                                 mode, "show");
3414
3415
3416 cmdline_parse_inst_t cmd_tso_show = {
3417         .f = cmd_tso_set_parsed,
3418         .data = NULL,
3419         .help_str = "Show TSO segment size for csum engine: "
3420         "tso show <port>",
3421         .tokens = {
3422                 (void *)&cmd_tso_set_tso,
3423                 (void *)&cmd_tso_show_mode,
3424                 (void *)&cmd_tso_set_portid,
3425                 NULL,
3426         },
3427 };
3428
3429 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3430 struct cmd_set_flush_rx {
3431         cmdline_fixed_string_t set;
3432         cmdline_fixed_string_t flush_rx;
3433         cmdline_fixed_string_t mode;
3434 };
3435
3436 static void
3437 cmd_set_flush_rx_parsed(void *parsed_result,
3438                 __attribute__((unused)) struct cmdline *cl,
3439                 __attribute__((unused)) void *data)
3440 {
3441         struct cmd_set_flush_rx *res = parsed_result;
3442         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3443 }
3444
3445 cmdline_parse_token_string_t cmd_setflushrx_set =
3446         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3447                         set, "set");
3448 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3449         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3450                         flush_rx, "flush_rx");
3451 cmdline_parse_token_string_t cmd_setflushrx_mode =
3452         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3453                         mode, "on#off");
3454
3455
3456 cmdline_parse_inst_t cmd_set_flush_rx = {
3457         .f = cmd_set_flush_rx_parsed,
3458         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3459         .data = NULL,
3460         .tokens = {
3461                 (void *)&cmd_setflushrx_set,
3462                 (void *)&cmd_setflushrx_flush_rx,
3463                 (void *)&cmd_setflushrx_mode,
3464                 NULL,
3465         },
3466 };
3467
3468 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3469 struct cmd_set_link_check {
3470         cmdline_fixed_string_t set;
3471         cmdline_fixed_string_t link_check;
3472         cmdline_fixed_string_t mode;
3473 };
3474
3475 static void
3476 cmd_set_link_check_parsed(void *parsed_result,
3477                 __attribute__((unused)) struct cmdline *cl,
3478                 __attribute__((unused)) void *data)
3479 {
3480         struct cmd_set_link_check *res = parsed_result;
3481         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3482 }
3483
3484 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3485         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3486                         set, "set");
3487 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3488         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3489                         link_check, "link_check");
3490 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3491         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3492                         mode, "on#off");
3493
3494
3495 cmdline_parse_inst_t cmd_set_link_check = {
3496         .f = cmd_set_link_check_parsed,
3497         .help_str = "set link_check on|off: enable/disable link status check "
3498                     "when starting/stopping a port",
3499         .data = NULL,
3500         .tokens = {
3501                 (void *)&cmd_setlinkcheck_set,
3502                 (void *)&cmd_setlinkcheck_link_check,
3503                 (void *)&cmd_setlinkcheck_mode,
3504                 NULL,
3505         },
3506 };
3507
3508 #ifdef RTE_NIC_BYPASS
3509 /* *** SET NIC BYPASS MODE *** */
3510 struct cmd_set_bypass_mode_result {
3511         cmdline_fixed_string_t set;
3512         cmdline_fixed_string_t bypass;
3513         cmdline_fixed_string_t mode;
3514         cmdline_fixed_string_t value;
3515         uint8_t port_id;
3516 };
3517
3518 static void
3519 cmd_set_bypass_mode_parsed(void *parsed_result,
3520                 __attribute__((unused)) struct cmdline *cl,
3521                 __attribute__((unused)) void *data)
3522 {
3523         struct cmd_set_bypass_mode_result *res = parsed_result;
3524         portid_t port_id = res->port_id;
3525         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3526
3527         if (!bypass_is_supported(port_id))
3528                 return;
3529
3530         if (!strcmp(res->value, "bypass"))
3531                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3532         else if (!strcmp(res->value, "isolate"))
3533                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3534         else
3535                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3536
3537         /* Set the bypass mode for the relevant port. */
3538         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3539                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3540         }
3541 }
3542
3543 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3545                         set, "set");
3546 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3548                         bypass, "bypass");
3549 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3551                         mode, "mode");
3552 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3554                         value, "normal#bypass#isolate");
3555 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3556         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3557                                 port_id, UINT8);
3558
3559 cmdline_parse_inst_t cmd_set_bypass_mode = {
3560         .f = cmd_set_bypass_mode_parsed,
3561         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3562                     "Set the NIC bypass mode for port_id",
3563         .data = NULL,
3564         .tokens = {
3565                 (void *)&cmd_setbypass_mode_set,
3566                 (void *)&cmd_setbypass_mode_bypass,
3567                 (void *)&cmd_setbypass_mode_mode,
3568                 (void *)&cmd_setbypass_mode_value,
3569                 (void *)&cmd_setbypass_mode_port,
3570                 NULL,
3571         },
3572 };
3573
3574 /* *** SET NIC BYPASS EVENT *** */
3575 struct cmd_set_bypass_event_result {
3576         cmdline_fixed_string_t set;
3577         cmdline_fixed_string_t bypass;
3578         cmdline_fixed_string_t event;
3579         cmdline_fixed_string_t event_value;
3580         cmdline_fixed_string_t mode;
3581         cmdline_fixed_string_t mode_value;
3582         uint8_t port_id;
3583 };
3584
3585 static void
3586 cmd_set_bypass_event_parsed(void *parsed_result,
3587                 __attribute__((unused)) struct cmdline *cl,
3588                 __attribute__((unused)) void *data)
3589 {
3590         int32_t rc;
3591         struct cmd_set_bypass_event_result *res = parsed_result;
3592         portid_t port_id = res->port_id;
3593         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3594         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3595
3596         if (!bypass_is_supported(port_id))
3597                 return;
3598
3599         if (!strcmp(res->event_value, "timeout"))
3600                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3601         else if (!strcmp(res->event_value, "os_on"))
3602                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3603         else if (!strcmp(res->event_value, "os_off"))
3604                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3605         else if (!strcmp(res->event_value, "power_on"))
3606                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3607         else if (!strcmp(res->event_value, "power_off"))
3608                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3609         else
3610                 bypass_event = RTE_BYPASS_EVENT_NONE;
3611
3612         if (!strcmp(res->mode_value, "bypass"))
3613                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3614         else if (!strcmp(res->mode_value, "isolate"))
3615                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3616         else
3617                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3618
3619         /* Set the watchdog timeout. */
3620         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3621
3622                 rc = -EINVAL;
3623                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3624                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3625                                 bypass_timeout)) != 0) {
3626                         printf("Failed to set timeout value %u "
3627                                 "for port %d, errto code: %d.\n",
3628                                 bypass_timeout, port_id, rc);
3629                 }
3630         }
3631
3632         /* Set the bypass event to transition to bypass mode. */
3633         if (0 != rte_eth_dev_bypass_event_store(port_id,
3634                         bypass_event, bypass_mode)) {
3635                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3636         }
3637
3638 }
3639
3640 cmdline_parse_token_string_t cmd_setbypass_event_set =
3641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3642                         set, "set");
3643 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3645                         bypass, "bypass");
3646 cmdline_parse_token_string_t cmd_setbypass_event_event =
3647         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3648                         event, "event");
3649 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3650         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3651                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3652 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3653         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3654                         mode, "mode");
3655 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3656         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3657                         mode_value, "normal#bypass#isolate");
3658 cmdline_parse_token_num_t cmd_setbypass_event_port =
3659         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3660                                 port_id, UINT8);
3661
3662 cmdline_parse_inst_t cmd_set_bypass_event = {
3663         .f = cmd_set_bypass_event_parsed,
3664         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3665                     "mode (normal|bypass|isolate) (port_id): "
3666                     "Set the NIC bypass event mode for port_id",
3667         .data = NULL,
3668         .tokens = {
3669                 (void *)&cmd_setbypass_event_set,
3670                 (void *)&cmd_setbypass_event_bypass,
3671                 (void *)&cmd_setbypass_event_event,
3672                 (void *)&cmd_setbypass_event_event_value,
3673                 (void *)&cmd_setbypass_event_mode,
3674                 (void *)&cmd_setbypass_event_mode_value,
3675                 (void *)&cmd_setbypass_event_port,
3676                 NULL,
3677         },
3678 };
3679
3680
3681 /* *** SET NIC BYPASS TIMEOUT *** */
3682 struct cmd_set_bypass_timeout_result {
3683         cmdline_fixed_string_t set;
3684         cmdline_fixed_string_t bypass;
3685         cmdline_fixed_string_t timeout;
3686         cmdline_fixed_string_t value;
3687 };
3688
3689 static void
3690 cmd_set_bypass_timeout_parsed(void *parsed_result,
3691                 __attribute__((unused)) struct cmdline *cl,
3692                 __attribute__((unused)) void *data)
3693 {
3694         struct cmd_set_bypass_timeout_result *res = parsed_result;
3695
3696         if (!strcmp(res->value, "1.5"))
3697                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3698         else if (!strcmp(res->value, "2"))
3699                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3700         else if (!strcmp(res->value, "3"))
3701                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3702         else if (!strcmp(res->value, "4"))
3703                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3704         else if (!strcmp(res->value, "8"))
3705                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3706         else if (!strcmp(res->value, "16"))
3707                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3708         else if (!strcmp(res->value, "32"))
3709                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3710         else
3711                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3712 }
3713
3714 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3715         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3716                         set, "set");
3717 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3718         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3719                         bypass, "bypass");
3720 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3721         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3722                         timeout, "timeout");
3723 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3724         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3725                         value, "0#1.5#2#3#4#8#16#32");
3726
3727 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3728         .f = cmd_set_bypass_timeout_parsed,
3729         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3730                     "Set the NIC bypass watchdog timeout",
3731         .data = NULL,
3732         .tokens = {
3733                 (void *)&cmd_setbypass_timeout_set,
3734                 (void *)&cmd_setbypass_timeout_bypass,
3735                 (void *)&cmd_setbypass_timeout_timeout,
3736                 (void *)&cmd_setbypass_timeout_value,
3737                 NULL,
3738         },
3739 };
3740
3741 /* *** SHOW NIC BYPASS MODE *** */
3742 struct cmd_show_bypass_config_result {
3743         cmdline_fixed_string_t show;
3744         cmdline_fixed_string_t bypass;
3745         cmdline_fixed_string_t config;
3746         uint8_t port_id;
3747 };
3748
3749 static void
3750 cmd_show_bypass_config_parsed(void *parsed_result,
3751                 __attribute__((unused)) struct cmdline *cl,
3752                 __attribute__((unused)) void *data)
3753 {
3754         struct cmd_show_bypass_config_result *res = parsed_result;
3755         uint32_t event_mode;
3756         uint32_t bypass_mode;
3757         portid_t port_id = res->port_id;
3758         uint32_t timeout = bypass_timeout;
3759         int i;
3760
3761         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3762                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3763         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3764                 {"UNKNOWN", "normal", "bypass", "isolate"};
3765         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3766                 "NONE",
3767                 "OS/board on",
3768                 "power supply on",
3769                 "OS/board off",
3770                 "power supply off",
3771                 "timeout"};
3772         int num_events = (sizeof events) / (sizeof events[0]);
3773
3774         if (!bypass_is_supported(port_id))
3775                 return;
3776
3777         /* Display the bypass mode.*/
3778         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3779                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3780                 return;
3781         }
3782         else {
3783                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3784                         bypass_mode = RTE_BYPASS_MODE_NONE;
3785
3786                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3787         }
3788
3789         /* Display the bypass timeout.*/
3790         if (!RTE_BYPASS_TMT_VALID(timeout))
3791                 timeout = RTE_BYPASS_TMT_OFF;
3792
3793         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3794
3795         /* Display the bypass events and associated modes. */
3796         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3797
3798                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3799                         printf("\tFailed to get bypass mode for event = %s\n",
3800                                 events[i]);
3801                 } else {
3802                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3803                                 event_mode = RTE_BYPASS_MODE_NONE;
3804
3805                         printf("\tbypass event: %-16s = %s\n", events[i],
3806                                 modes[event_mode]);
3807                 }
3808         }
3809 }
3810
3811 cmdline_parse_token_string_t cmd_showbypass_config_show =
3812         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3813                         show, "show");
3814 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3815         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3816                         bypass, "bypass");
3817 cmdline_parse_token_string_t cmd_showbypass_config_config =
3818         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3819                         config, "config");
3820 cmdline_parse_token_num_t cmd_showbypass_config_port =
3821         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3822                                 port_id, UINT8);
3823
3824 cmdline_parse_inst_t cmd_show_bypass_config = {
3825         .f = cmd_show_bypass_config_parsed,
3826         .help_str = "show bypass config (port_id): "
3827                     "Show the NIC bypass config for port_id",
3828         .data = NULL,
3829         .tokens = {
3830                 (void *)&cmd_showbypass_config_show,
3831                 (void *)&cmd_showbypass_config_bypass,
3832                 (void *)&cmd_showbypass_config_config,
3833                 (void *)&cmd_showbypass_config_port,
3834                 NULL,
3835         },
3836 };
3837 #endif
3838
3839 #ifdef RTE_LIBRTE_PMD_BOND
3840 /* *** SET BONDING MODE *** */
3841 struct cmd_set_bonding_mode_result {
3842         cmdline_fixed_string_t set;
3843         cmdline_fixed_string_t bonding;
3844         cmdline_fixed_string_t mode;
3845         uint8_t value;
3846         uint8_t port_id;
3847 };
3848
3849 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3850                 __attribute__((unused))  struct cmdline *cl,
3851                 __attribute__((unused)) void *data)
3852 {
3853         struct cmd_set_bonding_mode_result *res = parsed_result;
3854         portid_t port_id = res->port_id;
3855
3856         /* Set the bonding mode for the relevant port. */
3857         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3858                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3859 }
3860
3861 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3862 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3863                 set, "set");
3864 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3865 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3866                 bonding, "bonding");
3867 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3868 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3869                 mode, "mode");
3870 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3871 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3872                 value, UINT8);
3873 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3874 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3875                 port_id, UINT8);
3876
3877 cmdline_parse_inst_t cmd_set_bonding_mode = {
3878                 .f = cmd_set_bonding_mode_parsed,
3879                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3880                 .data = NULL,
3881                 .tokens = {
3882                                 (void *) &cmd_setbonding_mode_set,
3883                                 (void *) &cmd_setbonding_mode_bonding,
3884                                 (void *) &cmd_setbonding_mode_mode,
3885                                 (void *) &cmd_setbonding_mode_value,
3886                                 (void *) &cmd_setbonding_mode_port,
3887                                 NULL
3888                 }
3889 };
3890
3891 /* *** SET BALANCE XMIT POLICY *** */
3892 struct cmd_set_bonding_balance_xmit_policy_result {
3893         cmdline_fixed_string_t set;
3894         cmdline_fixed_string_t bonding;
3895         cmdline_fixed_string_t balance_xmit_policy;
3896         uint8_t port_id;
3897         cmdline_fixed_string_t policy;
3898 };
3899
3900 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3901                 __attribute__((unused))  struct cmdline *cl,
3902                 __attribute__((unused)) void *data)
3903 {
3904         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3905         portid_t port_id = res->port_id;
3906         uint8_t policy;
3907
3908         if (!strcmp(res->policy, "l2")) {
3909                 policy = BALANCE_XMIT_POLICY_LAYER2;
3910         } else if (!strcmp(res->policy, "l23")) {
3911                 policy = BALANCE_XMIT_POLICY_LAYER23;
3912         } else if (!strcmp(res->policy, "l34")) {
3913                 policy = BALANCE_XMIT_POLICY_LAYER34;
3914         } else {
3915                 printf("\t Invalid xmit policy selection");
3916                 return;
3917         }
3918
3919         /* Set the bonding mode for the relevant port. */
3920         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3921                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3922                                 port_id);
3923         }
3924 }
3925
3926 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3928                 set, "set");
3929 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3931                 bonding, "bonding");
3932 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3933 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3934                 balance_xmit_policy, "balance_xmit_policy");
3935 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3936 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3937                 port_id, UINT8);
3938 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3939 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3940                 policy, "l2#l23#l34");
3941
3942 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3943                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3944                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3945                 .data = NULL,
3946                 .tokens = {
3947                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3948                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3949                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3950                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3951                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3952                                 NULL
3953                 }
3954 };
3955
3956 /* *** SHOW NIC BONDING CONFIGURATION *** */
3957 struct cmd_show_bonding_config_result {
3958         cmdline_fixed_string_t show;
3959         cmdline_fixed_string_t bonding;
3960         cmdline_fixed_string_t config;
3961         uint8_t port_id;
3962 };
3963
3964 static void cmd_show_bonding_config_parsed(void *parsed_result,
3965                 __attribute__((unused))  struct cmdline *cl,
3966                 __attribute__((unused)) void *data)
3967 {
3968         struct cmd_show_bonding_config_result *res = parsed_result;
3969         int bonding_mode;
3970         uint8_t slaves[RTE_MAX_ETHPORTS];
3971         int num_slaves, num_active_slaves;
3972         int primary_id;
3973         int i;
3974         portid_t port_id = res->port_id;
3975
3976         /* Display the bonding mode.*/
3977         bonding_mode = rte_eth_bond_mode_get(port_id);
3978         if (bonding_mode < 0) {
3979                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3980                 return;
3981         } else
3982                 printf("\tBonding mode: %d\n", bonding_mode);
3983
3984         if (bonding_mode == BONDING_MODE_BALANCE) {
3985                 int balance_xmit_policy;
3986
3987                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3988                 if (balance_xmit_policy < 0) {
3989                         printf("\tFailed to get balance xmit policy for port = %d\n",
3990                                         port_id);
3991                         return;
3992                 } else {
3993                         printf("\tBalance Xmit Policy: ");
3994
3995                         switch (balance_xmit_policy) {
3996                         case BALANCE_XMIT_POLICY_LAYER2:
3997                                 printf("BALANCE_XMIT_POLICY_LAYER2");
3998                                 break;
3999                         case BALANCE_XMIT_POLICY_LAYER23:
4000                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4001                                 break;
4002                         case BALANCE_XMIT_POLICY_LAYER34:
4003                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4004                                 break;
4005                         }
4006                         printf("\n");
4007                 }
4008         }
4009
4010         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4011
4012         if (num_slaves < 0) {
4013                 printf("\tFailed to get slave list for port = %d\n", port_id);
4014                 return;
4015         }
4016         if (num_slaves > 0) {
4017                 printf("\tSlaves (%d): [", num_slaves);
4018                 for (i = 0; i < num_slaves - 1; i++)
4019                         printf("%d ", slaves[i]);
4020
4021                 printf("%d]\n", slaves[num_slaves - 1]);
4022         } else {
4023                 printf("\tSlaves: []\n");
4024
4025         }
4026
4027         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4028                         RTE_MAX_ETHPORTS);
4029
4030         if (num_active_slaves < 0) {
4031                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4032                 return;
4033         }
4034         if (num_active_slaves > 0) {
4035                 printf("\tActive Slaves (%d): [", num_active_slaves);
4036                 for (i = 0; i < num_active_slaves - 1; i++)
4037                         printf("%d ", slaves[i]);
4038
4039                 printf("%d]\n", slaves[num_active_slaves - 1]);
4040
4041         } else {
4042                 printf("\tActive Slaves: []\n");
4043
4044         }
4045
4046         primary_id = rte_eth_bond_primary_get(port_id);
4047         if (primary_id < 0) {
4048                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4049                 return;
4050         } else
4051                 printf("\tPrimary: [%d]\n", primary_id);
4052
4053 }
4054
4055 cmdline_parse_token_string_t cmd_showbonding_config_show =
4056 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4057                 show, "show");
4058 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4059 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4060                 bonding, "bonding");
4061 cmdline_parse_token_string_t cmd_showbonding_config_config =
4062 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4063                 config, "config");
4064 cmdline_parse_token_num_t cmd_showbonding_config_port =
4065 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4066                 port_id, UINT8);
4067
4068 cmdline_parse_inst_t cmd_show_bonding_config = {
4069                 .f = cmd_show_bonding_config_parsed,
4070                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
4071                 .data = NULL,
4072                 .tokens = {
4073                                 (void *)&cmd_showbonding_config_show,
4074                                 (void *)&cmd_showbonding_config_bonding,
4075                                 (void *)&cmd_showbonding_config_config,
4076                                 (void *)&cmd_showbonding_config_port,
4077                                 NULL
4078                 }
4079 };
4080
4081 /* *** SET BONDING PRIMARY *** */
4082 struct cmd_set_bonding_primary_result {
4083         cmdline_fixed_string_t set;
4084         cmdline_fixed_string_t bonding;
4085         cmdline_fixed_string_t primary;
4086         uint8_t slave_id;
4087         uint8_t port_id;
4088 };
4089
4090 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4091                 __attribute__((unused))  struct cmdline *cl,
4092                 __attribute__((unused)) void *data)
4093 {
4094         struct cmd_set_bonding_primary_result *res = parsed_result;
4095         portid_t master_port_id = res->port_id;
4096         portid_t slave_port_id = res->slave_id;
4097
4098         /* Set the primary slave for a bonded device. */
4099         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4100                 printf("\t Failed to set primary slave for port = %d.\n",
4101                                 master_port_id);
4102                 return;
4103         }
4104         init_port_config();
4105 }
4106
4107 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4108 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4109                 set, "set");
4110 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4112                 bonding, "bonding");
4113 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4114 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4115                 primary, "primary");
4116 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4117 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4118                 slave_id, UINT8);
4119 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4120 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4121                 port_id, UINT8);
4122
4123 cmdline_parse_inst_t cmd_set_bonding_primary = {
4124                 .f = cmd_set_bonding_primary_parsed,
4125                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
4126                 .data = NULL,
4127                 .tokens = {
4128                                 (void *)&cmd_setbonding_primary_set,
4129                                 (void *)&cmd_setbonding_primary_bonding,
4130                                 (void *)&cmd_setbonding_primary_primary,
4131                                 (void *)&cmd_setbonding_primary_slave,
4132                                 (void *)&cmd_setbonding_primary_port,
4133                                 NULL
4134                 }
4135 };
4136
4137 /* *** ADD SLAVE *** */
4138 struct cmd_add_bonding_slave_result {
4139         cmdline_fixed_string_t add;
4140         cmdline_fixed_string_t bonding;
4141         cmdline_fixed_string_t slave;
4142         uint8_t slave_id;
4143         uint8_t port_id;
4144 };
4145
4146 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4147                 __attribute__((unused))  struct cmdline *cl,
4148                 __attribute__((unused)) void *data)
4149 {
4150         struct cmd_add_bonding_slave_result *res = parsed_result;
4151         portid_t master_port_id = res->port_id;
4152         portid_t slave_port_id = res->slave_id;
4153
4154         /* Set the primary slave for a bonded device. */
4155         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4156                 printf("\t Failed to add slave %d to master port = %d.\n",
4157                                 slave_port_id, master_port_id);
4158                 return;
4159         }
4160         init_port_config();
4161         set_port_slave_flag(slave_port_id);
4162 }
4163
4164 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4165 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4166                 add, "add");
4167 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4168 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4169                 bonding, "bonding");
4170 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4171 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4172                 slave, "slave");
4173 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4174 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4175                 slave_id, UINT8);
4176 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4177 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4178                 port_id, UINT8);
4179
4180 cmdline_parse_inst_t cmd_add_bonding_slave = {
4181                 .f = cmd_add_bonding_slave_parsed,
4182                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4183                 .data = NULL,
4184                 .tokens = {
4185                                 (void *)&cmd_addbonding_slave_add,
4186                                 (void *)&cmd_addbonding_slave_bonding,
4187                                 (void *)&cmd_addbonding_slave_slave,
4188                                 (void *)&cmd_addbonding_slave_slaveid,
4189                                 (void *)&cmd_addbonding_slave_port,
4190                                 NULL
4191                 }
4192 };
4193
4194 /* *** REMOVE SLAVE *** */
4195 struct cmd_remove_bonding_slave_result {
4196         cmdline_fixed_string_t remove;
4197         cmdline_fixed_string_t bonding;
4198         cmdline_fixed_string_t slave;
4199         uint8_t slave_id;
4200         uint8_t port_id;
4201 };
4202
4203 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4204                 __attribute__((unused))  struct cmdline *cl,
4205                 __attribute__((unused)) void *data)
4206 {
4207         struct cmd_remove_bonding_slave_result *res = parsed_result;
4208         portid_t master_port_id = res->port_id;
4209         portid_t slave_port_id = res->slave_id;
4210
4211         /* Set the primary slave for a bonded device. */
4212         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4213                 printf("\t Failed to remove slave %d from master port = %d.\n",
4214                                 slave_port_id, master_port_id);
4215                 return;
4216         }
4217         init_port_config();
4218         clear_port_slave_flag(slave_port_id);
4219 }
4220
4221 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4222                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4223                                 remove, "remove");
4224 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4225                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4226                                 bonding, "bonding");
4227 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4228                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4229                                 slave, "slave");
4230 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4231                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4232                                 slave_id, UINT8);
4233 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4234                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4235                                 port_id, UINT8);
4236
4237 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4238                 .f = cmd_remove_bonding_slave_parsed,
4239                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4240                 .data = NULL,
4241                 .tokens = {
4242                                 (void *)&cmd_removebonding_slave_remove,
4243                                 (void *)&cmd_removebonding_slave_bonding,
4244                                 (void *)&cmd_removebonding_slave_slave,
4245                                 (void *)&cmd_removebonding_slave_slaveid,
4246                                 (void *)&cmd_removebonding_slave_port,
4247                                 NULL
4248                 }
4249 };
4250
4251 /* *** CREATE BONDED DEVICE *** */
4252 struct cmd_create_bonded_device_result {
4253         cmdline_fixed_string_t create;
4254         cmdline_fixed_string_t bonded;
4255         cmdline_fixed_string_t device;
4256         uint8_t mode;
4257         uint8_t socket;
4258 };
4259
4260 static int bond_dev_num = 0;
4261
4262 static void cmd_create_bonded_device_parsed(void *parsed_result,
4263                 __attribute__((unused))  struct cmdline *cl,
4264                 __attribute__((unused)) void *data)
4265 {
4266         struct cmd_create_bonded_device_result *res = parsed_result;
4267         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4268         int port_id;
4269
4270         if (test_done == 0) {
4271                 printf("Please stop forwarding first\n");
4272                 return;
4273         }
4274
4275         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
4276                         bond_dev_num++);
4277
4278         /* Create a new bonded device. */
4279         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4280         if (port_id < 0) {
4281                 printf("\t Failed to create bonded device.\n");
4282                 return;
4283         } else {
4284                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4285                                 port_id);
4286
4287                 /* Update number of ports */
4288                 nb_ports = rte_eth_dev_count();
4289                 reconfig(port_id, res->socket);
4290                 rte_eth_promiscuous_enable(port_id);
4291                 ports[port_id].enabled = 1;
4292         }
4293
4294 }
4295
4296 cmdline_parse_token_string_t cmd_createbonded_device_create =
4297                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4298                                 create, "create");
4299 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4300                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4301                                 bonded, "bonded");
4302 cmdline_parse_token_string_t cmd_createbonded_device_device =
4303                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4304                                 device, "device");
4305 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4306                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4307                                 mode, UINT8);
4308 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4309                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4310                                 socket, UINT8);
4311
4312 cmdline_parse_inst_t cmd_create_bonded_device = {
4313                 .f = cmd_create_bonded_device_parsed,
4314                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4315                 .data = NULL,
4316                 .tokens = {
4317                                 (void *)&cmd_createbonded_device_create,
4318                                 (void *)&cmd_createbonded_device_bonded,
4319                                 (void *)&cmd_createbonded_device_device,
4320                                 (void *)&cmd_createbonded_device_mode,
4321                                 (void *)&cmd_createbonded_device_socket,
4322                                 NULL
4323                 }
4324 };
4325
4326 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4327 struct cmd_set_bond_mac_addr_result {
4328         cmdline_fixed_string_t set;
4329         cmdline_fixed_string_t bonding;
4330         cmdline_fixed_string_t mac_addr;
4331         uint8_t port_num;
4332         struct ether_addr address;
4333 };
4334
4335 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4336                 __attribute__((unused))  struct cmdline *cl,
4337                 __attribute__((unused)) void *data)
4338 {
4339         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4340         int ret;
4341
4342         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4343                 return;
4344
4345         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4346
4347         /* check the return value and print it if is < 0 */
4348         if (ret < 0)
4349                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4350 }
4351
4352 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4353                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4354 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4355                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4356                                 "bonding");
4357 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4358                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4359                                 "mac_addr");
4360 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4361                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4362 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4363                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4364
4365 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4366                 .f = cmd_set_bond_mac_addr_parsed,
4367                 .data = (void *) 0,
4368                 .help_str = "set bonding mac_addr (port_id) (address): ",
4369                 .tokens = {
4370                                 (void *)&cmd_set_bond_mac_addr_set,
4371                                 (void *)&cmd_set_bond_mac_addr_bonding,
4372                                 (void *)&cmd_set_bond_mac_addr_mac,
4373                                 (void *)&cmd_set_bond_mac_addr_portnum,
4374                                 (void *)&cmd_set_bond_mac_addr_addr,
4375                                 NULL
4376                 }
4377 };
4378
4379
4380 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4381 struct cmd_set_bond_mon_period_result {
4382         cmdline_fixed_string_t set;
4383         cmdline_fixed_string_t bonding;
4384         cmdline_fixed_string_t mon_period;
4385         uint8_t port_num;
4386         uint32_t period_ms;
4387 };
4388
4389 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4390                 __attribute__((unused))  struct cmdline *cl,
4391                 __attribute__((unused)) void *data)
4392 {
4393         struct cmd_set_bond_mon_period_result *res = parsed_result;
4394         int ret;
4395
4396         if (res->port_num >= nb_ports) {
4397                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4398                 return;
4399         }
4400
4401         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4402
4403         /* check the return value and print it if is < 0 */
4404         if (ret < 0)
4405                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4406 }
4407
4408 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4409                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4410                                 set, "set");
4411 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4412                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4413                                 bonding, "bonding");
4414 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4415                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4416                                 mon_period,     "mon_period");
4417 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4418                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4419                                 port_num, UINT8);
4420 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4421                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4422                                 period_ms, UINT32);
4423
4424 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4425                 .f = cmd_set_bond_mon_period_parsed,
4426                 .data = (void *) 0,
4427                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4428                 .tokens = {
4429                                 (void *)&cmd_set_bond_mon_period_set,
4430                                 (void *)&cmd_set_bond_mon_period_bonding,
4431                                 (void *)&cmd_set_bond_mon_period_mon_period,
4432                                 (void *)&cmd_set_bond_mon_period_portnum,
4433                                 (void *)&cmd_set_bond_mon_period_period_ms,
4434                                 NULL
4435                 }
4436 };
4437
4438 #endif /* RTE_LIBRTE_PMD_BOND */
4439
4440 /* *** SET FORWARDING MODE *** */
4441 struct cmd_set_fwd_mode_result {
4442         cmdline_fixed_string_t set;
4443         cmdline_fixed_string_t fwd;
4444         cmdline_fixed_string_t mode;
4445 };
4446
4447 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4448                                     __attribute__((unused)) struct cmdline *cl,
4449                                     __attribute__((unused)) void *data)
4450 {
4451         struct cmd_set_fwd_mode_result *res = parsed_result;
4452
4453         set_pkt_forwarding_mode(res->mode);
4454 }
4455
4456 cmdline_parse_token_string_t cmd_setfwd_set =
4457         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4458 cmdline_parse_token_string_t cmd_setfwd_fwd =
4459         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4460 cmdline_parse_token_string_t cmd_setfwd_mode =
4461         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4462                 "" /* defined at init */);
4463
4464 cmdline_parse_inst_t cmd_set_fwd_mode = {
4465         .f = cmd_set_fwd_mode_parsed,
4466         .data = NULL,
4467         .help_str = NULL, /* defined at init */
4468         .tokens = {
4469                 (void *)&cmd_setfwd_set,
4470                 (void *)&cmd_setfwd_fwd,
4471                 (void *)&cmd_setfwd_mode,
4472                 NULL,
4473         },
4474 };
4475
4476 static void cmd_set_fwd_mode_init(void)
4477 {
4478         char *modes, *c;
4479         static char token[128];
4480         static char help[256];
4481         cmdline_parse_token_string_t *token_struct;
4482
4483         modes = list_pkt_forwarding_modes();
4484         snprintf(help, sizeof help, "set fwd %s - "
4485                 "set packet forwarding mode", modes);
4486         cmd_set_fwd_mode.help_str = help;
4487
4488         /* string token separator is # */
4489         for (c = token; *modes != '\0'; modes++)
4490                 if (*modes == '|')
4491                         *c++ = '#';
4492                 else
4493                         *c++ = *modes;
4494         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4495         token_struct->string_data.str = token;
4496 }
4497
4498 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4499 struct cmd_set_burst_tx_retry_result {
4500         cmdline_fixed_string_t set;
4501         cmdline_fixed_string_t burst;
4502         cmdline_fixed_string_t tx;
4503         cmdline_fixed_string_t delay;
4504         uint32_t time;
4505         cmdline_fixed_string_t retry;
4506         uint32_t retry_num;
4507 };
4508
4509 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4510                                         __attribute__((unused)) struct cmdline *cl,
4511                                         __attribute__((unused)) void *data)
4512 {
4513         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4514
4515         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4516                 && !strcmp(res->tx, "tx")) {
4517                 if (!strcmp(res->delay, "delay"))
4518                         burst_tx_delay_time = res->time;
4519                 if (!strcmp(res->retry, "retry"))
4520                         burst_tx_retry_num = res->retry_num;
4521         }
4522
4523 }
4524
4525 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4526         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4527 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4528         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4529                                  "burst");
4530 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4531         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4532 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4533         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4534 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4535         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4536 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4537         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4538 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4539         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4540
4541 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4542         .f = cmd_set_burst_tx_retry_parsed,
4543         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4544         .tokens = {
4545                 (void *)&cmd_set_burst_tx_retry_set,
4546                 (void *)&cmd_set_burst_tx_retry_burst,
4547                 (void *)&cmd_set_burst_tx_retry_tx,
4548                 (void *)&cmd_set_burst_tx_retry_delay,
4549                 (void *)&cmd_set_burst_tx_retry_time,
4550                 (void *)&cmd_set_burst_tx_retry_retry,
4551                 (void *)&cmd_set_burst_tx_retry_retry_num,
4552                 NULL,
4553         },
4554 };
4555
4556 /* *** SET PROMISC MODE *** */
4557 struct cmd_set_promisc_mode_result {
4558         cmdline_fixed_string_t set;
4559         cmdline_fixed_string_t promisc;
4560         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4561         uint8_t port_num;                /* valid if "allports" argument == 0 */
4562         cmdline_fixed_string_t mode;
4563 };
4564
4565 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4566                                         __attribute__((unused)) struct cmdline *cl,
4567                                         void *allports)
4568 {
4569         struct cmd_set_promisc_mode_result *res = parsed_result;
4570         int enable;
4571         portid_t i;
4572
4573         if (!strcmp(res->mode, "on"))
4574                 enable = 1;
4575         else
4576                 enable = 0;
4577
4578         /* all ports */
4579         if (allports) {
4580                 FOREACH_PORT(i, ports) {
4581                         if (enable)
4582                                 rte_eth_promiscuous_enable(i);
4583                         else
4584                                 rte_eth_promiscuous_disable(i);
4585                 }
4586         }
4587         else {
4588                 if (enable)
4589                         rte_eth_promiscuous_enable(res->port_num);
4590                 else
4591                         rte_eth_promiscuous_disable(res->port_num);
4592         }
4593 }
4594
4595 cmdline_parse_token_string_t cmd_setpromisc_set =
4596         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4597 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4598         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4599                                  "promisc");
4600 cmdline_parse_token_string_t cmd_setpromisc_portall =
4601         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4602                                  "all");
4603 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4604         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4605                               UINT8);
4606 cmdline_parse_token_string_t cmd_setpromisc_mode =
4607         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4608                                  "on#off");
4609
4610 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4611         .f = cmd_set_promisc_mode_parsed,
4612         .data = (void *)1,
4613         .help_str = "set promisc all on|off: set promisc mode for all ports",
4614         .tokens = {
4615                 (void *)&cmd_setpromisc_set,
4616                 (void *)&cmd_setpromisc_promisc,
4617                 (void *)&cmd_setpromisc_portall,
4618                 (void *)&cmd_setpromisc_mode,
4619                 NULL,
4620         },
4621 };
4622
4623 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4624         .f = cmd_set_promisc_mode_parsed,
4625         .data = (void *)0,
4626         .help_str = "set promisc X on|off: set promisc mode on port X",
4627         .tokens = {
4628                 (void *)&cmd_setpromisc_set,
4629                 (void *)&cmd_setpromisc_promisc,
4630                 (void *)&cmd_setpromisc_portnum,
4631                 (void *)&cmd_setpromisc_mode,
4632                 NULL,
4633         },
4634 };
4635
4636 /* *** SET ALLMULTI MODE *** */
4637 struct cmd_set_allmulti_mode_result {
4638         cmdline_fixed_string_t set;
4639         cmdline_fixed_string_t allmulti;
4640         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4641         uint8_t port_num;                /* valid if "allports" argument == 0 */
4642         cmdline_fixed_string_t mode;
4643 };
4644
4645 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4646                                         __attribute__((unused)) struct cmdline *cl,
4647                                         void *allports)
4648 {
4649         struct cmd_set_allmulti_mode_result *res = parsed_result;
4650         int enable;
4651         portid_t i;
4652
4653         if (!strcmp(res->mode, "on"))
4654                 enable = 1;
4655         else
4656                 enable = 0;
4657
4658         /* all ports */
4659         if (allports) {
4660                 FOREACH_PORT(i, ports) {
4661                         if (enable)
4662                                 rte_eth_allmulticast_enable(i);
4663                         else
4664                                 rte_eth_allmulticast_disable(i);
4665                 }
4666         }
4667         else {
4668                 if (enable)
4669                         rte_eth_allmulticast_enable(res->port_num);
4670                 else
4671                         rte_eth_allmulticast_disable(res->port_num);
4672         }
4673 }
4674
4675 cmdline_parse_token_string_t cmd_setallmulti_set =
4676         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4677 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4678         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4679                                  "allmulti");
4680 cmdline_parse_token_string_t cmd_setallmulti_portall =
4681         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4682                                  "all");
4683 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4684         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4685                               UINT8);
4686 cmdline_parse_token_string_t cmd_setallmulti_mode =
4687         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4688                                  "on#off");
4689
4690 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4691         .f = cmd_set_allmulti_mode_parsed,
4692         .data = (void *)1,
4693         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4694         .tokens = {
4695                 (void *)&cmd_setallmulti_set,
4696                 (void *)&cmd_setallmulti_allmulti,
4697                 (void *)&cmd_setallmulti_portall,
4698                 (void *)&cmd_setallmulti_mode,
4699                 NULL,
4700         },
4701 };
4702
4703 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4704         .f = cmd_set_allmulti_mode_parsed,
4705         .data = (void *)0,
4706         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4707         .tokens = {
4708                 (void *)&cmd_setallmulti_set,
4709                 (void *)&cmd_setallmulti_allmulti,
4710                 (void *)&cmd_setallmulti_portnum,
4711                 (void *)&cmd_setallmulti_mode,
4712                 NULL,
4713         },
4714 };
4715
4716 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4717 struct cmd_link_flow_ctrl_set_result {
4718         cmdline_fixed_string_t set;
4719         cmdline_fixed_string_t flow_ctrl;
4720         cmdline_fixed_string_t rx;
4721         cmdline_fixed_string_t rx_lfc_mode;
4722         cmdline_fixed_string_t tx;
4723         cmdline_fixed_string_t tx_lfc_mode;
4724         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4725         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4726         cmdline_fixed_string_t autoneg_str;
4727         cmdline_fixed_string_t autoneg;
4728         cmdline_fixed_string_t hw_str;
4729         uint32_t high_water;
4730         cmdline_fixed_string_t lw_str;
4731         uint32_t low_water;
4732         cmdline_fixed_string_t pt_str;
4733         uint16_t pause_time;
4734         cmdline_fixed_string_t xon_str;
4735         uint16_t send_xon;
4736         uint8_t  port_id;
4737 };
4738
4739 cmdline_parse_token_string_t cmd_lfc_set_set =
4740         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4741                                 set, "set");
4742 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4743         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4744                                 flow_ctrl, "flow_ctrl");
4745 cmdline_parse_token_string_t cmd_lfc_set_rx =
4746         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4747                                 rx, "rx");
4748 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4749         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4750                                 rx_lfc_mode, "on#off");
4751 cmdline_parse_token_string_t cmd_lfc_set_tx =
4752         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4753                                 tx, "tx");
4754 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4755         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4756                                 tx_lfc_mode, "on#off");
4757 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4758         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4759                                 hw_str, "high_water");
4760 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4761         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4762                                 high_water, UINT32);
4763 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4764         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4765                                 lw_str, "low_water");
4766 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4767         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4768                                 low_water, UINT32);
4769 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4770         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4771                                 pt_str, "pause_time");
4772 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4773         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4774                                 pause_time, UINT16);
4775 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4776         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4777                                 xon_str, "send_xon");
4778 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4779         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4780                                 send_xon, UINT16);
4781 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4782         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4783                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4784 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4785         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4786                                 mac_ctrl_frame_fwd_mode, "on#off");
4787 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4788         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4789                                 autoneg_str, "autoneg");
4790 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4791         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4792                                 autoneg, "on#off");
4793 cmdline_parse_token_num_t cmd_lfc_set_portid =
4794         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4795                                 port_id, UINT8);
4796
4797 /* forward declaration */
4798 static void
4799 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4800                               void *data);
4801
4802 cmdline_parse_inst_t cmd_link_flow_control_set = {
4803         .f = cmd_link_flow_ctrl_set_parsed,
4804         .data = NULL,
4805         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4806 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4807 autoneg on|off port_id",
4808         .tokens = {
4809                 (void *)&cmd_lfc_set_set,
4810                 (void *)&cmd_lfc_set_flow_ctrl,
4811                 (void *)&cmd_lfc_set_rx,
4812                 (void *)&cmd_lfc_set_rx_mode,
4813                 (void *)&cmd_lfc_set_tx,
4814                 (void *)&cmd_lfc_set_tx_mode,
4815                 (void *)&cmd_lfc_set_high_water,
4816                 (void *)&cmd_lfc_set_low_water,
4817                 (void *)&cmd_lfc_set_pause_time,
4818                 (void *)&cmd_lfc_set_send_xon,
4819                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4820                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4821                 (void *)&cmd_lfc_set_autoneg_str,
4822                 (void *)&cmd_lfc_set_autoneg,
4823                 (void *)&cmd_lfc_set_portid,
4824                 NULL,
4825         },
4826 };
4827
4828 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4829         .f = cmd_link_flow_ctrl_set_parsed,
4830         .data = (void *)&cmd_link_flow_control_set_rx,
4831         .help_str = "Change rx flow control parameter: set flow_ctrl "
4832                     "rx on|off port_id",
4833         .tokens = {
4834                 (void *)&cmd_lfc_set_set,
4835                 (void *)&cmd_lfc_set_flow_ctrl,
4836                 (void *)&cmd_lfc_set_rx,
4837                 (void *)&cmd_lfc_set_rx_mode,
4838                 (void *)&cmd_lfc_set_portid,
4839                 NULL,
4840         },
4841 };
4842
4843 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4844         .f = cmd_link_flow_ctrl_set_parsed,
4845         .data = (void *)&cmd_link_flow_control_set_tx,
4846         .help_str = "Change tx flow control parameter: set flow_ctrl "
4847                     "tx on|off port_id",
4848         .tokens = {
4849                 (void *)&cmd_lfc_set_set,
4850                 (void *)&cmd_lfc_set_flow_ctrl,
4851                 (void *)&cmd_lfc_set_tx,
4852                 (void *)&cmd_lfc_set_tx_mode,
4853                 (void *)&cmd_lfc_set_portid,
4854                 NULL,
4855         },
4856 };
4857
4858 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
4859         .f = cmd_link_flow_ctrl_set_parsed,
4860         .data = (void *)&cmd_link_flow_control_set_hw,
4861         .help_str = "Change high water flow control parameter: set flow_ctrl "
4862                     "high_water value port_id",
4863         .tokens = {
4864                 (void *)&cmd_lfc_set_set,
4865                 (void *)&cmd_lfc_set_flow_ctrl,
4866                 (void *)&cmd_lfc_set_high_water_str,
4867                 (void *)&cmd_lfc_set_high_water,
4868                 (void *)&cmd_lfc_set_portid,
4869                 NULL,
4870         },
4871 };
4872
4873 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
4874         .f = cmd_link_flow_ctrl_set_parsed,
4875         .data = (void *)&cmd_link_flow_control_set_lw,
4876         .help_str = "Change low water flow control parameter: set flow_ctrl "
4877                     "low_water value port_id",
4878         .tokens = {
4879                 (void *)&cmd_lfc_set_set,
4880                 (void *)&cmd_lfc_set_flow_ctrl,
4881                 (void *)&cmd_lfc_set_low_water_str,
4882                 (void *)&cmd_lfc_set_low_water,
4883                 (void *)&cmd_lfc_set_portid,
4884                 NULL,
4885         },
4886 };
4887
4888 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
4889         .f = cmd_link_flow_ctrl_set_parsed,
4890         .data = (void *)&cmd_link_flow_control_set_pt,
4891         .help_str = "Change pause time flow control parameter: set flow_ctrl "
4892                     "pause_time value port_id",
4893         .tokens = {
4894                 (void *)&cmd_lfc_set_set,
4895                 (void *)&cmd_lfc_set_flow_ctrl,
4896                 (void *)&cmd_lfc_set_pause_time_str,
4897                 (void *)&cmd_lfc_set_pause_time,
4898                 (void *)&cmd_lfc_set_portid,
4899                 NULL,
4900         },
4901 };
4902
4903 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
4904         .f = cmd_link_flow_ctrl_set_parsed,
4905         .data = (void *)&cmd_link_flow_control_set_xon,
4906         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
4907                     "send_xon value port_id",
4908         .tokens = {
4909                 (void *)&cmd_lfc_set_set,
4910                 (void *)&cmd_lfc_set_flow_ctrl,
4911                 (void *)&cmd_lfc_set_send_xon_str,
4912                 (void *)&cmd_lfc_set_send_xon,
4913                 (void *)&cmd_lfc_set_portid,
4914                 NULL,
4915         },
4916 };
4917
4918 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
4919         .f = cmd_link_flow_ctrl_set_parsed,
4920         .data = (void *)&cmd_link_flow_control_set_macfwd,
4921         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
4922                     "mac_ctrl_frame_fwd on|off port_id",
4923         .tokens = {
4924                 (void *)&cmd_lfc_set_set,
4925                 (void *)&cmd_lfc_set_flow_ctrl,
4926                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4927                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4928                 (void *)&cmd_lfc_set_portid,
4929                 NULL,
4930         },
4931 };
4932
4933 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
4934         .f = cmd_link_flow_ctrl_set_parsed,
4935         .data = (void *)&cmd_link_flow_control_set_autoneg,
4936         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
4937                     "autoneg on|off port_id",
4938         .tokens = {
4939                 (void *)&cmd_lfc_set_set,
4940                 (void *)&cmd_lfc_set_flow_ctrl,
4941                 (void *)&cmd_lfc_set_autoneg_str,
4942                 (void *)&cmd_lfc_set_autoneg,
4943                 (void *)&cmd_lfc_set_portid,
4944                 NULL,
4945         },
4946 };
4947
4948 static void
4949 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
4950                               __attribute__((unused)) struct cmdline *cl,
4951                               void *data)
4952 {
4953         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
4954         cmdline_parse_inst_t *cmd = data;
4955         struct rte_eth_fc_conf fc_conf;
4956         int rx_fc_en = 0;
4957         int tx_fc_en = 0;
4958         int ret;
4959
4960         /*
4961          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
4962          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
4963          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
4964          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
4965          */
4966         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
4967                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
4968         };
4969
4970         /* Partial command line, retrieve current configuration */
4971         if (cmd) {
4972                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
4973                 if (ret != 0) {
4974                         printf("cannot get current flow ctrl parameters, return"
4975                                "code = %d\n", ret);
4976                         return;
4977                 }
4978
4979                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
4980                     (fc_conf.mode == RTE_FC_FULL))
4981                         rx_fc_en = 1;
4982                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
4983                     (fc_conf.mode == RTE_FC_FULL))
4984                         tx_fc_en = 1;
4985         }
4986
4987         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
4988                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
4989
4990         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
4991                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
4992
4993         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
4994
4995         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
4996                 fc_conf.high_water = res->high_water;
4997
4998         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
4999                 fc_conf.low_water = res->low_water;
5000
5001         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5002                 fc_conf.pause_time = res->pause_time;
5003
5004         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5005                 fc_conf.send_xon = res->send_xon;
5006
5007         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5008                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5009                         fc_conf.mac_ctrl_frame_fwd = 1;
5010                 else
5011                         fc_conf.mac_ctrl_frame_fwd = 0;
5012         }
5013
5014         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5015                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5016
5017         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5018         if (ret != 0)
5019                 printf("bad flow contrl parameter, return code = %d \n", ret);
5020 }
5021
5022 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5023 struct cmd_priority_flow_ctrl_set_result {
5024         cmdline_fixed_string_t set;
5025         cmdline_fixed_string_t pfc_ctrl;
5026         cmdline_fixed_string_t rx;
5027         cmdline_fixed_string_t rx_pfc_mode;
5028         cmdline_fixed_string_t tx;
5029         cmdline_fixed_string_t tx_pfc_mode;
5030         uint32_t high_water;
5031         uint32_t low_water;
5032         uint16_t pause_time;
5033         uint8_t  priority;
5034         uint8_t  port_id;
5035 };
5036
5037 static void
5038 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5039                        __attribute__((unused)) struct cmdline *cl,
5040                        __attribute__((unused)) void *data)
5041 {
5042         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5043         struct rte_eth_pfc_conf pfc_conf;
5044         int rx_fc_enable, tx_fc_enable;
5045         int ret;
5046
5047         /*
5048          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5049          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5050          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5051          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5052          */
5053         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5054                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5055         };
5056
5057         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5058         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5059         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5060         pfc_conf.fc.high_water = res->high_water;
5061         pfc_conf.fc.low_water  = res->low_water;
5062         pfc_conf.fc.pause_time = res->pause_time;
5063         pfc_conf.priority      = res->priority;
5064
5065         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5066         if (ret != 0)
5067                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5068 }
5069
5070 cmdline_parse_token_string_t cmd_pfc_set_set =
5071         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5072                                 set, "set");
5073 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5074         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5075                                 pfc_ctrl, "pfc_ctrl");
5076 cmdline_parse_token_string_t cmd_pfc_set_rx =
5077         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5078                                 rx, "rx");
5079 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5080         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5081                                 rx_pfc_mode, "on#off");
5082 cmdline_parse_token_string_t cmd_pfc_set_tx =
5083         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5084                                 tx, "tx");
5085 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5086         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5087                                 tx_pfc_mode, "on#off");
5088 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5089         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5090                                 high_water, UINT32);
5091 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5092         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5093                                 low_water, UINT32);
5094 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5095         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5096                                 pause_time, UINT16);
5097 cmdline_parse_token_num_t cmd_pfc_set_priority =
5098         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5099                                 priority, UINT8);
5100 cmdline_parse_token_num_t cmd_pfc_set_portid =
5101         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5102                                 port_id, UINT8);
5103
5104 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5105         .f = cmd_priority_flow_ctrl_set_parsed,
5106         .data = NULL,
5107         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5108                         tx on|off high_water low_water pause_time priority port_id",
5109         .tokens = {
5110                 (void *)&cmd_pfc_set_set,
5111                 (void *)&cmd_pfc_set_flow_ctrl,
5112                 (void *)&cmd_pfc_set_rx,
5113                 (void *)&cmd_pfc_set_rx_mode,
5114                 (void *)&cmd_pfc_set_tx,
5115                 (void *)&cmd_pfc_set_tx_mode,
5116                 (void *)&cmd_pfc_set_high_water,
5117                 (void *)&cmd_pfc_set_low_water,
5118                 (void *)&cmd_pfc_set_pause_time,
5119                 (void *)&cmd_pfc_set_priority,
5120                 (void *)&cmd_pfc_set_portid,
5121                 NULL,
5122         },
5123 };
5124
5125 /* *** RESET CONFIGURATION *** */
5126 struct cmd_reset_result {
5127         cmdline_fixed_string_t reset;
5128         cmdline_fixed_string_t def;
5129 };
5130
5131 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5132                              struct cmdline *cl,
5133                              __attribute__((unused)) void *data)
5134 {
5135         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5136         set_def_fwd_config();
5137 }
5138
5139 cmdline_parse_token_string_t cmd_reset_set =
5140         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5141 cmdline_parse_token_string_t cmd_reset_def =
5142         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5143                                  "default");
5144
5145 cmdline_parse_inst_t cmd_reset = {
5146         .f = cmd_reset_parsed,
5147         .data = NULL,
5148         .help_str = "set default: reset default forwarding configuration",
5149         .tokens = {
5150                 (void *)&cmd_reset_set,
5151                 (void *)&cmd_reset_def,
5152                 NULL,
5153         },
5154 };
5155
5156 /* *** START FORWARDING *** */
5157 struct cmd_start_result {
5158         cmdline_fixed_string_t start;
5159 };
5160
5161 cmdline_parse_token_string_t cmd_start_start =
5162         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5163
5164 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5165                              __attribute__((unused)) struct cmdline *cl,
5166                              __attribute__((unused)) void *data)
5167 {
5168         start_packet_forwarding(0);
5169 }
5170
5171 cmdline_parse_inst_t cmd_start = {
5172         .f = cmd_start_parsed,
5173         .data = NULL,
5174         .help_str = "start packet forwarding",
5175         .tokens = {
5176                 (void *)&cmd_start_start,
5177                 NULL,
5178         },
5179 };
5180
5181 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5182 struct cmd_start_tx_first_result {
5183         cmdline_fixed_string_t start;
5184         cmdline_fixed_string_t tx_first;
5185 };
5186
5187 static void
5188 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5189                           __attribute__((unused)) struct cmdline *cl,
5190                           __attribute__((unused)) void *data)
5191 {
5192         start_packet_forwarding(1);
5193 }
5194
5195 cmdline_parse_token_string_t cmd_start_tx_first_start =
5196         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5197                                  "start");
5198 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5199         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5200                                  tx_first, "tx_first");
5201
5202 cmdline_parse_inst_t cmd_start_tx_first = {
5203         .f = cmd_start_tx_first_parsed,
5204         .data = NULL,
5205         .help_str = "start packet forwarding, after sending 1 burst of packets",
5206         .tokens = {
5207                 (void *)&cmd_start_tx_first_start,
5208                 (void *)&cmd_start_tx_first_tx_first,
5209                 NULL,
5210         },
5211 };
5212
5213 /* *** SET LINK UP *** */
5214 struct cmd_set_link_up_result {
5215         cmdline_fixed_string_t set;
5216         cmdline_fixed_string_t link_up;
5217         cmdline_fixed_string_t port;
5218         uint8_t port_id;
5219 };
5220
5221 cmdline_parse_token_string_t cmd_set_link_up_set =
5222         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5223 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5224         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5225                                 "link-up");
5226 cmdline_parse_token_string_t cmd_set_link_up_port =
5227         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5228 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5229         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5230
5231 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5232                              __attribute__((unused)) struct cmdline *cl,
5233                              __attribute__((unused)) void *data)
5234 {
5235         struct cmd_set_link_up_result *res = parsed_result;
5236         dev_set_link_up(res->port_id);
5237 }
5238
5239 cmdline_parse_inst_t cmd_set_link_up = {
5240         .f = cmd_set_link_up_parsed,
5241         .data = NULL,
5242         .help_str = "set link-up port (port id)",
5243         .tokens = {
5244                 (void *)&cmd_set_link_up_set,
5245                 (void *)&cmd_set_link_up_link_up,
5246                 (void *)&cmd_set_link_up_port,
5247                 (void *)&cmd_set_link_up_port_id,
5248                 NULL,
5249         },
5250 };
5251
5252 /* *** SET LINK DOWN *** */
5253 struct cmd_set_link_down_result {
5254         cmdline_fixed_string_t set;
5255         cmdline_fixed_string_t link_down;
5256         cmdline_fixed_string_t port;
5257         uint8_t port_id;
5258 };
5259
5260 cmdline_parse_token_string_t cmd_set_link_down_set =
5261         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5262 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5263         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5264                                 "link-down");
5265 cmdline_parse_token_string_t cmd_set_link_down_port =
5266         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5267 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5268         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5269
5270 static void cmd_set_link_down_parsed(
5271                                 __attribute__((unused)) void *parsed_result,
5272                                 __attribute__((unused)) struct cmdline *cl,
5273                                 __attribute__((unused)) void *data)
5274 {
5275         struct cmd_set_link_down_result *res = parsed_result;
5276         dev_set_link_down(res->port_id);
5277 }
5278
5279 cmdline_parse_inst_t cmd_set_link_down = {
5280         .f = cmd_set_link_down_parsed,
5281         .data = NULL,
5282         .help_str = "set link-down port (port id)",
5283         .tokens = {
5284                 (void *)&cmd_set_link_down_set,
5285                 (void *)&cmd_set_link_down_link_down,
5286                 (void *)&cmd_set_link_down_port,
5287                 (void *)&cmd_set_link_down_port_id,
5288                 NULL,
5289         },
5290 };
5291
5292 /* *** SHOW CFG *** */
5293 struct cmd_showcfg_result {
5294         cmdline_fixed_string_t show;
5295         cmdline_fixed_string_t cfg;
5296         cmdline_fixed_string_t what;
5297 };
5298
5299 static void cmd_showcfg_parsed(void *parsed_result,
5300                                __attribute__((unused)) struct cmdline *cl,
5301                                __attribute__((unused)) void *data)
5302 {
5303         struct cmd_showcfg_result *res = parsed_result;
5304         if (!strcmp(res->what, "rxtx"))
5305                 rxtx_config_display();
5306         else if (!strcmp(res->what, "cores"))
5307                 fwd_lcores_config_display();
5308         else if (!strcmp(res->what, "fwd"))
5309                 fwd_config_display();
5310         else if (!strcmp(res->what, "txpkts"))
5311                 show_tx_pkt_segments();
5312 }
5313
5314 cmdline_parse_token_string_t cmd_showcfg_show =
5315         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5316 cmdline_parse_token_string_t cmd_showcfg_port =
5317         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5318 cmdline_parse_token_string_t cmd_showcfg_what =
5319         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5320                                  "rxtx#cores#fwd#txpkts");
5321
5322 cmdline_parse_inst_t cmd_showcfg = {
5323         .f = cmd_showcfg_parsed,
5324         .data = NULL,
5325         .help_str = "show config rxtx|cores|fwd|txpkts",
5326         .tokens = {
5327                 (void *)&cmd_showcfg_show,
5328                 (void *)&cmd_showcfg_port,
5329                 (void *)&cmd_showcfg_what,
5330                 NULL,
5331         },
5332 };
5333
5334 /* *** SHOW ALL PORT INFO *** */
5335 struct cmd_showportall_result {
5336         cmdline_fixed_string_t show;
5337         cmdline_fixed_string_t port;
5338         cmdline_fixed_string_t what;
5339         cmdline_fixed_string_t all;
5340 };
5341
5342 static void cmd_showportall_parsed(void *parsed_result,
5343                                 __attribute__((unused)) struct cmdline *cl,
5344                                 __attribute__((unused)) void *data)
5345 {
5346         portid_t i;
5347
5348         struct cmd_showportall_result *res = parsed_result;
5349         if (!strcmp(res->show, "clear")) {
5350                 if (!strcmp(res->what, "stats"))
5351                         FOREACH_PORT(i, ports)
5352                                 nic_stats_clear(i);
5353                 else if (!strcmp(res->what, "xstats"))
5354                         FOREACH_PORT(i, ports)
5355                                 nic_xstats_clear(i);
5356         } else if (!strcmp(res->what, "info"))
5357                 FOREACH_PORT(i, ports)
5358                         port_infos_display(i);
5359         else if (!strcmp(res->what, "stats"))
5360                 FOREACH_PORT(i, ports)
5361                         nic_stats_display(i);
5362         else if (!strcmp(res->what, "xstats"))
5363                 FOREACH_PORT(i, ports)
5364                         nic_xstats_display(i);
5365         else if (!strcmp(res->what, "fdir"))
5366                 FOREACH_PORT(i, ports)
5367                         fdir_get_infos(i);
5368         else if (!strcmp(res->what, "stat_qmap"))
5369                 FOREACH_PORT(i, ports)
5370                         nic_stats_mapping_display(i);
5371         else if (!strcmp(res->what, "dcb_tc"))
5372                 FOREACH_PORT(i, ports)
5373                         port_dcb_info_display(i);
5374 }
5375
5376 cmdline_parse_token_string_t cmd_showportall_show =
5377         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5378                                  "show#clear");
5379 cmdline_parse_token_string_t cmd_showportall_port =
5380         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5381 cmdline_parse_token_string_t cmd_showportall_what =
5382         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5383                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5384 cmdline_parse_token_string_t cmd_showportall_all =
5385         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5386 cmdline_parse_inst_t cmd_showportall = {
5387         .f = cmd_showportall_parsed,
5388         .data = NULL,
5389         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all",
5390         .tokens = {
5391                 (void *)&cmd_showportall_show,
5392                 (void *)&cmd_showportall_port,
5393                 (void *)&cmd_showportall_what,
5394                 (void *)&cmd_showportall_all,
5395                 NULL,
5396         },
5397 };
5398
5399 /* *** SHOW PORT INFO *** */
5400 struct cmd_showport_result {
5401         cmdline_fixed_string_t show;
5402         cmdline_fixed_string_t port;
5403         cmdline_fixed_string_t what;
5404         uint8_t portnum;
5405 };
5406
5407 static void cmd_showport_parsed(void *parsed_result,
5408                                 __attribute__((unused)) struct cmdline *cl,
5409                                 __attribute__((unused)) void *data)
5410 {
5411         struct cmd_showport_result *res = parsed_result;
5412         if (!strcmp(res->show, "clear")) {
5413                 if (!strcmp(res->what, "stats"))
5414                         nic_stats_clear(res->portnum);
5415                 else if (!strcmp(res->what, "xstats"))
5416                         nic_xstats_clear(res->portnum);
5417         } else if (!strcmp(res->what, "info"))
5418                 port_infos_display(res->portnum);
5419         else if (!strcmp(res->what, "stats"))
5420                 nic_stats_display(res->portnum);
5421         else if (!strcmp(res->what, "xstats"))
5422                 nic_xstats_display(res->portnum);
5423         else if (!strcmp(res->what, "fdir"))
5424                  fdir_get_infos(res->portnum);
5425         else if (!strcmp(res->what, "stat_qmap"))
5426                 nic_stats_mapping_display(res->portnum);
5427         else if (!strcmp(res->what, "dcb_tc"))
5428                 port_dcb_info_display(res->portnum);
5429 }
5430
5431 cmdline_parse_token_string_t cmd_showport_show =
5432         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5433                                  "show#clear");
5434 cmdline_parse_token_string_t cmd_showport_port =
5435         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5436 cmdline_parse_token_string_t cmd_showport_what =
5437         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5438                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5439 cmdline_parse_token_num_t cmd_showport_portnum =
5440         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5441
5442 cmdline_parse_inst_t cmd_showport = {
5443         .f = cmd_showport_parsed,
5444         .data = NULL,
5445         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc X (X = port number)",
5446         .tokens = {
5447                 (void *)&cmd_showport_show,
5448                 (void *)&cmd_showport_port,
5449                 (void *)&cmd_showport_what,
5450                 (void *)&cmd_showport_portnum,
5451                 NULL,
5452         },
5453 };
5454
5455 /* *** SHOW QUEUE INFO *** */
5456 struct cmd_showqueue_result {
5457         cmdline_fixed_string_t show;
5458         cmdline_fixed_string_t type;
5459         cmdline_fixed_string_t what;
5460         uint8_t portnum;
5461         uint16_t queuenum;
5462 };
5463
5464 static void
5465 cmd_showqueue_parsed(void *parsed_result,
5466         __attribute__((unused)) struct cmdline *cl,
5467         __attribute__((unused)) void *data)
5468 {
5469         struct cmd_showqueue_result *res = parsed_result;
5470
5471         if (!strcmp(res->type, "rxq"))
5472                 rx_queue_infos_display(res->portnum, res->queuenum);
5473         else if (!strcmp(res->type, "txq"))
5474                 tx_queue_infos_display(res->portnum, res->queuenum);
5475 }
5476
5477 cmdline_parse_token_string_t cmd_showqueue_show =
5478         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5479 cmdline_parse_token_string_t cmd_showqueue_type =
5480         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5481 cmdline_parse_token_string_t cmd_showqueue_what =
5482         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5483 cmdline_parse_token_num_t cmd_showqueue_portnum =
5484         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5485 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5486         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5487
5488 cmdline_parse_inst_t cmd_showqueue = {
5489         .f = cmd_showqueue_parsed,
5490         .data = NULL,
5491         .help_str = "show rxq|txq info <port number> <queue_number>",
5492         .tokens = {
5493                 (void *)&cmd_showqueue_show,
5494                 (void *)&cmd_showqueue_type,
5495                 (void *)&cmd_showqueue_what,
5496                 (void *)&cmd_showqueue_portnum,
5497                 (void *)&cmd_showqueue_queuenum,
5498                 NULL,
5499         },
5500 };
5501
5502 /* *** READ PORT REGISTER *** */
5503 struct cmd_read_reg_result {
5504         cmdline_fixed_string_t read;
5505         cmdline_fixed_string_t reg;
5506         uint8_t port_id;
5507         uint32_t reg_off;
5508 };
5509
5510 static void
5511 cmd_read_reg_parsed(void *parsed_result,
5512                     __attribute__((unused)) struct cmdline *cl,
5513                     __attribute__((unused)) void *data)
5514 {
5515         struct cmd_read_reg_result *res = parsed_result;
5516         port_reg_display(res->port_id, res->reg_off);
5517 }
5518
5519 cmdline_parse_token_string_t cmd_read_reg_read =
5520         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5521 cmdline_parse_token_string_t cmd_read_reg_reg =
5522         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5523 cmdline_parse_token_num_t cmd_read_reg_port_id =
5524         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5525 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5526         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5527
5528 cmdline_parse_inst_t cmd_read_reg = {
5529         .f = cmd_read_reg_parsed,
5530         .data = NULL,
5531         .help_str = "read reg port_id reg_off",
5532         .tokens = {
5533                 (void *)&cmd_read_reg_read,
5534                 (void *)&cmd_read_reg_reg,
5535                 (void *)&cmd_read_reg_port_id,
5536                 (void *)&cmd_read_reg_reg_off,
5537                 NULL,
5538         },
5539 };
5540
5541 /* *** READ PORT REGISTER BIT FIELD *** */
5542 struct cmd_read_reg_bit_field_result {
5543         cmdline_fixed_string_t read;
5544         cmdline_fixed_string_t regfield;
5545         uint8_t port_id;
5546         uint32_t reg_off;
5547         uint8_t bit1_pos;
5548         uint8_t bit2_pos;
5549 };
5550
5551 static void
5552 cmd_read_reg_bit_field_parsed(void *parsed_result,
5553                               __attribute__((unused)) struct cmdline *cl,
5554                               __attribute__((unused)) void *data)
5555 {
5556         struct cmd_read_reg_bit_field_result *res = parsed_result;
5557         port_reg_bit_field_display(res->port_id, res->reg_off,
5558                                    res->bit1_pos, res->bit2_pos);
5559 }
5560
5561 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5562         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5563                                  "read");
5564 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5565         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5566                                  regfield, "regfield");
5567 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5568         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5569                               UINT8);
5570 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5571         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5572                               UINT32);
5573 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5574         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5575                               UINT8);
5576 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5577         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5578                               UINT8);
5579
5580 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5581         .f = cmd_read_reg_bit_field_parsed,
5582         .data = NULL,
5583         .help_str = "read regfield port_id reg_off bit_x bit_y "
5584         "(read register bit field between bit_x and bit_y included)",
5585         .tokens = {
5586                 (void *)&cmd_read_reg_bit_field_read,
5587                 (void *)&cmd_read_reg_bit_field_regfield,
5588                 (void *)&cmd_read_reg_bit_field_port_id,
5589                 (void *)&cmd_read_reg_bit_field_reg_off,
5590                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5591                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5592                 NULL,
5593         },
5594 };
5595
5596 /* *** READ PORT REGISTER BIT *** */
5597 struct cmd_read_reg_bit_result {
5598         cmdline_fixed_string_t read;
5599         cmdline_fixed_string_t regbit;
5600         uint8_t port_id;
5601         uint32_t reg_off;
5602         uint8_t bit_pos;
5603 };
5604
5605 static void
5606 cmd_read_reg_bit_parsed(void *parsed_result,
5607                         __attribute__((unused)) struct cmdline *cl,
5608                         __attribute__((unused)) void *data)
5609 {
5610         struct cmd_read_reg_bit_result *res = parsed_result;
5611         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5612 }
5613
5614 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5615         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5616 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5617         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5618                                  regbit, "regbit");
5619 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5620         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5621 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5622         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5623 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5624         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5625
5626 cmdline_parse_inst_t cmd_read_reg_bit = {
5627         .f = cmd_read_reg_bit_parsed,
5628         .data = NULL,
5629         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5630         .tokens = {
5631                 (void *)&cmd_read_reg_bit_read,
5632                 (void *)&cmd_read_reg_bit_regbit,
5633                 (void *)&cmd_read_reg_bit_port_id,
5634                 (void *)&cmd_read_reg_bit_reg_off,
5635                 (void *)&cmd_read_reg_bit_bit_pos,
5636                 NULL,
5637         },
5638 };
5639
5640 /* *** WRITE PORT REGISTER *** */
5641 struct cmd_write_reg_result {
5642         cmdline_fixed_string_t write;
5643         cmdline_fixed_string_t reg;
5644         uint8_t port_id;
5645         uint32_t reg_off;
5646         uint32_t value;
5647 };
5648
5649 static void
5650 cmd_write_reg_parsed(void *parsed_result,
5651                      __attribute__((unused)) struct cmdline *cl,
5652                      __attribute__((unused)) void *data)
5653 {
5654         struct cmd_write_reg_result *res = parsed_result;
5655         port_reg_set(res->port_id, res->reg_off, res->value);
5656 }
5657
5658 cmdline_parse_token_string_t cmd_write_reg_write =
5659         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5660 cmdline_parse_token_string_t cmd_write_reg_reg =
5661         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5662 cmdline_parse_token_num_t cmd_write_reg_port_id =
5663         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5664 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5665         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5666 cmdline_parse_token_num_t cmd_write_reg_value =
5667         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5668
5669 cmdline_parse_inst_t cmd_write_reg = {
5670         .f = cmd_write_reg_parsed,
5671         .data = NULL,
5672         .help_str = "write reg port_id reg_off reg_value",
5673         .tokens = {
5674                 (void *)&cmd_write_reg_write,
5675                 (void *)&cmd_write_reg_reg,
5676                 (void *)&cmd_write_reg_port_id,
5677                 (void *)&cmd_write_reg_reg_off,
5678                 (void *)&cmd_write_reg_value,
5679                 NULL,
5680         },
5681 };
5682
5683 /* *** WRITE PORT REGISTER BIT FIELD *** */
5684 struct cmd_write_reg_bit_field_result {
5685         cmdline_fixed_string_t write;
5686         cmdline_fixed_string_t regfield;
5687         uint8_t port_id;
5688         uint32_t reg_off;
5689         uint8_t bit1_pos;
5690         uint8_t bit2_pos;
5691         uint32_t value;
5692 };
5693
5694 static void
5695 cmd_write_reg_bit_field_parsed(void *parsed_result,
5696                                __attribute__((unused)) struct cmdline *cl,
5697                                __attribute__((unused)) void *data)
5698 {
5699         struct cmd_write_reg_bit_field_result *res = parsed_result;
5700         port_reg_bit_field_set(res->port_id, res->reg_off,
5701                           res->bit1_pos, res->bit2_pos, res->value);
5702 }
5703
5704 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5705         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5706                                  "write");
5707 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5708         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5709                                  regfield, "regfield");
5710 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5711         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5712                               UINT8);
5713 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5714         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5715                               UINT32);
5716 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5717         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5718                               UINT8);
5719 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5720         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5721                               UINT8);
5722 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5723         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5724                               UINT32);
5725
5726 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5727         .f = cmd_write_reg_bit_field_parsed,
5728         .data = NULL,
5729         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5730         "(set register bit field between bit_x and bit_y included)",
5731         .tokens = {
5732                 (void *)&cmd_write_reg_bit_field_write,
5733                 (void *)&cmd_write_reg_bit_field_regfield,
5734                 (void *)&cmd_write_reg_bit_field_port_id,
5735                 (void *)&cmd_write_reg_bit_field_reg_off,
5736                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5737                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5738                 (void *)&cmd_write_reg_bit_field_value,
5739                 NULL,
5740         },
5741 };
5742
5743 /* *** WRITE PORT REGISTER BIT *** */
5744 struct cmd_write_reg_bit_result {
5745         cmdline_fixed_string_t write;
5746         cmdline_fixed_string_t regbit;
5747         uint8_t port_id;
5748         uint32_t reg_off;
5749         uint8_t bit_pos;
5750         uint8_t value;
5751 };
5752
5753 static void
5754 cmd_write_reg_bit_parsed(void *parsed_result,
5755                          __attribute__((unused)) struct cmdline *cl,
5756                          __attribute__((unused)) void *data)
5757 {
5758         struct cmd_write_reg_bit_result *res = parsed_result;
5759         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5760 }
5761
5762 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5763         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5764                                  "write");
5765 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5766         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5767                                  regbit, "regbit");
5768 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5769         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5770 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5771         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5772 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5773         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5774 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5775         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5776
5777 cmdline_parse_inst_t cmd_write_reg_bit = {
5778         .f = cmd_write_reg_bit_parsed,
5779         .data = NULL,
5780         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5781         .tokens = {
5782                 (void *)&cmd_write_reg_bit_write,
5783                 (void *)&cmd_write_reg_bit_regbit,
5784                 (void *)&cmd_write_reg_bit_port_id,
5785                 (void *)&cmd_write_reg_bit_reg_off,
5786                 (void *)&cmd_write_reg_bit_bit_pos,
5787                 (void *)&cmd_write_reg_bit_value,
5788                 NULL,
5789         },
5790 };
5791
5792 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5793 struct cmd_read_rxd_txd_result {
5794         cmdline_fixed_string_t read;
5795         cmdline_fixed_string_t rxd_txd;
5796         uint8_t port_id;
5797         uint16_t queue_id;
5798         uint16_t desc_id;
5799 };
5800
5801 static void
5802 cmd_read_rxd_txd_parsed(void *parsed_result,
5803                         __attribute__((unused)) struct cmdline *cl,
5804                         __attribute__((unused)) void *data)
5805 {
5806         struct cmd_read_rxd_txd_result *res = parsed_result;
5807
5808         if (!strcmp(res->rxd_txd, "rxd"))
5809                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5810         else if (!strcmp(res->rxd_txd, "txd"))
5811                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5812 }
5813
5814 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5815         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5816 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5817         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5818                                  "rxd#txd");
5819 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5820         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5821 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5822         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5823 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5824         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5825
5826 cmdline_parse_inst_t cmd_read_rxd_txd = {
5827         .f = cmd_read_rxd_txd_parsed,
5828         .data = NULL,
5829         .help_str = "read rxd|txd port_id queue_id rxd_id",
5830         .tokens = {
5831                 (void *)&cmd_read_rxd_txd_read,
5832                 (void *)&cmd_read_rxd_txd_rxd_txd,
5833                 (void *)&cmd_read_rxd_txd_port_id,
5834                 (void *)&cmd_read_rxd_txd_queue_id,
5835                 (void *)&cmd_read_rxd_txd_desc_id,
5836                 NULL,
5837         },
5838 };
5839
5840 /* *** QUIT *** */
5841 struct cmd_quit_result {
5842         cmdline_fixed_string_t quit;
5843 };
5844
5845 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5846                             struct cmdline *cl,
5847                             __attribute__((unused)) void *data)
5848 {
5849         pmd_test_exit();
5850         cmdline_quit(cl);
5851 }
5852
5853 cmdline_parse_token_string_t cmd_quit_quit =
5854         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5855
5856 cmdline_parse_inst_t cmd_quit = {
5857         .f = cmd_quit_parsed,
5858         .data = NULL,
5859         .help_str = "exit application",
5860         .tokens = {
5861                 (void *)&cmd_quit_quit,
5862                 NULL,
5863         },
5864 };
5865
5866 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5867 struct cmd_mac_addr_result {
5868         cmdline_fixed_string_t mac_addr_cmd;
5869         cmdline_fixed_string_t what;
5870         uint8_t port_num;
5871         struct ether_addr address;
5872 };
5873
5874 static void cmd_mac_addr_parsed(void *parsed_result,
5875                 __attribute__((unused)) struct cmdline *cl,
5876                 __attribute__((unused)) void *data)
5877 {
5878         struct cmd_mac_addr_result *res = parsed_result;
5879         int ret;
5880
5881         if (strcmp(res->what, "add") == 0)
5882                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5883         else
5884                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5885
5886         /* check the return value and print it if is < 0 */
5887         if(ret < 0)
5888                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5889
5890 }
5891
5892 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5893         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5894                                 "mac_addr");
5895 cmdline_parse_token_string_t cmd_mac_addr_what =
5896         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5897                                 "add#remove");
5898 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5899                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5900 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5901                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5902
5903 cmdline_parse_inst_t cmd_mac_addr = {
5904         .f = cmd_mac_addr_parsed,
5905         .data = (void *)0,
5906         .help_str = "mac_addr add|remove X <address>: "
5907                         "add/remove MAC address on port X",
5908         .tokens = {
5909                 (void *)&cmd_mac_addr_cmd,
5910                 (void *)&cmd_mac_addr_what,
5911                 (void *)&cmd_mac_addr_portnum,
5912                 (void *)&cmd_mac_addr_addr,
5913                 NULL,
5914         },
5915 };
5916
5917
5918 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5919 struct cmd_set_qmap_result {
5920         cmdline_fixed_string_t set;
5921         cmdline_fixed_string_t qmap;
5922         cmdline_fixed_string_t what;
5923         uint8_t port_id;
5924         uint16_t queue_id;
5925         uint8_t map_value;
5926 };
5927
5928 static void
5929 cmd_set_qmap_parsed(void *parsed_result,
5930                        __attribute__((unused)) struct cmdline *cl,
5931                        __attribute__((unused)) void *data)
5932 {
5933         struct cmd_set_qmap_result *res = parsed_result;
5934         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5935
5936         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5937 }
5938
5939 cmdline_parse_token_string_t cmd_setqmap_set =
5940         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5941                                  set, "set");
5942 cmdline_parse_token_string_t cmd_setqmap_qmap =
5943         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5944                                  qmap, "stat_qmap");
5945 cmdline_parse_token_string_t cmd_setqmap_what =
5946         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5947                                  what, "tx#rx");
5948 cmdline_parse_token_num_t cmd_setqmap_portid =
5949         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5950                               port_id, UINT8);
5951 cmdline_parse_token_num_t cmd_setqmap_queueid =
5952         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5953                               queue_id, UINT16);
5954 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5955         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5956                               map_value, UINT8);
5957
5958 cmdline_parse_inst_t cmd_set_qmap = {
5959         .f = cmd_set_qmap_parsed,
5960         .data = NULL,
5961         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
5962         .tokens = {
5963                 (void *)&cmd_setqmap_set,
5964                 (void *)&cmd_setqmap_qmap,
5965                 (void *)&cmd_setqmap_what,
5966                 (void *)&cmd_setqmap_portid,
5967                 (void *)&cmd_setqmap_queueid,
5968                 (void *)&cmd_setqmap_mapvalue,
5969                 NULL,
5970         },
5971 };
5972
5973 /* *** CONFIGURE UNICAST HASH TABLE *** */
5974 struct cmd_set_uc_hash_table {
5975         cmdline_fixed_string_t set;
5976         cmdline_fixed_string_t port;
5977         uint8_t port_id;
5978         cmdline_fixed_string_t what;
5979         struct ether_addr address;
5980         cmdline_fixed_string_t mode;
5981 };
5982
5983 static void
5984 cmd_set_uc_hash_parsed(void *parsed_result,
5985                        __attribute__((unused)) struct cmdline *cl,
5986                        __attribute__((unused)) void *data)
5987 {
5988         int ret=0;
5989         struct cmd_set_uc_hash_table *res = parsed_result;
5990
5991         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5992
5993         if (strcmp(res->what, "uta") == 0)
5994                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
5995                                                 &res->address,(uint8_t)is_on);
5996         if (ret < 0)
5997                 printf("bad unicast hash table parameter, return code = %d \n", ret);
5998
5999 }
6000
6001 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6002         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6003                                  set, "set");
6004 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6005         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6006                                  port, "port");
6007 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6008         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6009                               port_id, UINT8);
6010 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6011         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6012                                  what, "uta");
6013 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6014         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6015                                 address);
6016 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6017         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6018                                  mode, "on#off");
6019
6020 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6021         .f = cmd_set_uc_hash_parsed,
6022         .data = NULL,
6023         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6024         .tokens = {
6025                 (void *)&cmd_set_uc_hash_set,
6026                 (void *)&cmd_set_uc_hash_port,
6027                 (void *)&cmd_set_uc_hash_portid,
6028                 (void *)&cmd_set_uc_hash_what,
6029                 (void *)&cmd_set_uc_hash_mac,
6030                 (void *)&cmd_set_uc_hash_mode,
6031                 NULL,
6032         },
6033 };
6034
6035 struct cmd_set_uc_all_hash_table {
6036         cmdline_fixed_string_t set;
6037         cmdline_fixed_string_t port;
6038         uint8_t port_id;
6039         cmdline_fixed_string_t what;
6040         cmdline_fixed_string_t value;
6041         cmdline_fixed_string_t mode;
6042 };
6043
6044 static void
6045 cmd_set_uc_all_hash_parsed(void *parsed_result,
6046                        __attribute__((unused)) struct cmdline *cl,
6047                        __attribute__((unused)) void *data)
6048 {
6049         int ret=0;
6050         struct cmd_set_uc_all_hash_table *res = parsed_result;
6051
6052         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6053
6054         if ((strcmp(res->what, "uta") == 0) &&
6055                 (strcmp(res->value, "all") == 0))
6056                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6057         if (ret < 0)
6058                 printf("bad unicast hash table parameter,"
6059                         "return code = %d \n", ret);
6060 }
6061
6062 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6063         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6064                                  set, "set");
6065 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6066         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6067                                  port, "port");
6068 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6069         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6070                               port_id, UINT8);
6071 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6072         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6073                                  what, "uta");
6074 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6075         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6076                                 value,"all");
6077 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6078         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6079                                  mode, "on#off");
6080
6081 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6082         .f = cmd_set_uc_all_hash_parsed,
6083         .data = NULL,
6084         .help_str = "set port X uta all on|off (X = port number)",
6085         .tokens = {
6086                 (void *)&cmd_set_uc_all_hash_set,
6087                 (void *)&cmd_set_uc_all_hash_port,
6088                 (void *)&cmd_set_uc_all_hash_portid,
6089                 (void *)&cmd_set_uc_all_hash_what,
6090                 (void *)&cmd_set_uc_all_hash_value,
6091                 (void *)&cmd_set_uc_all_hash_mode,
6092                 NULL,
6093         },
6094 };
6095
6096 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6097 struct cmd_set_vf_macvlan_filter {
6098         cmdline_fixed_string_t set;
6099         cmdline_fixed_string_t port;
6100         uint8_t port_id;
6101         cmdline_fixed_string_t vf;
6102         uint8_t vf_id;
6103         struct ether_addr address;
6104         cmdline_fixed_string_t filter_type;
6105         cmdline_fixed_string_t mode;
6106 };
6107
6108 static void
6109 cmd_set_vf_macvlan_parsed(void *parsed_result,
6110                        __attribute__((unused)) struct cmdline *cl,
6111                        __attribute__((unused)) void *data)
6112 {
6113         int is_on, ret = 0;
6114         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6115         struct rte_eth_mac_filter filter;
6116
6117         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6118
6119         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6120
6121         /* set VF MAC filter */
6122         filter.is_vf = 1;
6123
6124         /* set VF ID */
6125         filter.dst_id = res->vf_id;
6126
6127         if (!strcmp(res->filter_type, "exact-mac"))
6128                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6129         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6130                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6131         else if (!strcmp(res->filter_type, "hashmac"))
6132                 filter.filter_type = RTE_MAC_HASH_MATCH;
6133         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6134                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6135
6136         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6137
6138         if (is_on)
6139                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6140                                         RTE_ETH_FILTER_MACVLAN,
6141                                         RTE_ETH_FILTER_ADD,
6142                                          &filter);
6143         else
6144                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6145                                         RTE_ETH_FILTER_MACVLAN,
6146                                         RTE_ETH_FILTER_DELETE,
6147                                         &filter);
6148
6149         if (ret < 0)
6150                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6151
6152 }
6153
6154 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6155         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6156                                  set, "set");
6157 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6158         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6159                                  port, "port");
6160 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6161         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6162                               port_id, UINT8);
6163 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6164         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6165                                  vf, "vf");
6166 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6167         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6168                                 vf_id, UINT8);
6169 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6170         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6171                                 address);
6172 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6173         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6174                                 filter_type, "exact-mac#exact-mac-vlan"
6175                                 "#hashmac#hashmac-vlan");
6176 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6177         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6178                                  mode, "on#off");
6179
6180 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6181         .f = cmd_set_vf_macvlan_parsed,
6182         .data = NULL,
6183         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6184                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6185                         "on|off\n"
6186                         "exact match rule:exact match of MAC or MAC and VLAN; "
6187                         "hash match rule: hash match of MAC and exact match "
6188                         "of VLAN",
6189         .tokens = {
6190                 (void *)&cmd_set_vf_macvlan_set,
6191                 (void *)&cmd_set_vf_macvlan_port,
6192                 (void *)&cmd_set_vf_macvlan_portid,
6193                 (void *)&cmd_set_vf_macvlan_vf,
6194                 (void *)&cmd_set_vf_macvlan_vf_id,
6195                 (void *)&cmd_set_vf_macvlan_mac,
6196                 (void *)&cmd_set_vf_macvlan_filter_type,
6197                 (void *)&cmd_set_vf_macvlan_mode,
6198                 NULL,
6199         },
6200 };
6201
6202 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6203 struct cmd_set_vf_traffic {
6204         cmdline_fixed_string_t set;
6205         cmdline_fixed_string_t port;
6206         uint8_t port_id;
6207         cmdline_fixed_string_t vf;
6208         uint8_t vf_id;
6209         cmdline_fixed_string_t what;
6210         cmdline_fixed_string_t mode;
6211 };
6212
6213 static void
6214 cmd_set_vf_traffic_parsed(void *parsed_result,
6215                        __attribute__((unused)) struct cmdline *cl,
6216                        __attribute__((unused)) void *data)
6217 {
6218         struct cmd_set_vf_traffic *res = parsed_result;
6219         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6220         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6221
6222         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6223 }
6224
6225 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6226         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6227                                  set, "set");
6228 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6229         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6230                                  port, "port");
6231 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6232         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6233                               port_id, UINT8);
6234 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6235         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6236                                  vf, "vf");
6237 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6238         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6239                               vf_id, UINT8);
6240 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6241         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6242                                  what, "tx#rx");
6243 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6244         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6245                                  mode, "on#off");
6246
6247 cmdline_parse_inst_t cmd_set_vf_traffic = {
6248         .f = cmd_set_vf_traffic_parsed,
6249         .data = NULL,
6250         .help_str = "set port X vf Y rx|tx on|off"
6251                         "(X = port number,Y = vf id)",
6252         .tokens = {
6253                 (void *)&cmd_setvf_traffic_set,
6254                 (void *)&cmd_setvf_traffic_port,
6255                 (void *)&cmd_setvf_traffic_portid,
6256                 (void *)&cmd_setvf_traffic_vf,
6257                 (void *)&cmd_setvf_traffic_vfid,
6258                 (void *)&cmd_setvf_traffic_what,
6259                 (void *)&cmd_setvf_traffic_mode,
6260                 NULL,
6261         },
6262 };
6263
6264 /* *** CONFIGURE VF RECEIVE MODE *** */
6265 struct cmd_set_vf_rxmode {
6266         cmdline_fixed_string_t set;
6267         cmdline_fixed_string_t port;
6268         uint8_t port_id;
6269         cmdline_fixed_string_t vf;
6270         uint8_t vf_id;
6271         cmdline_fixed_string_t what;
6272         cmdline_fixed_string_t mode;
6273         cmdline_fixed_string_t on;
6274 };
6275
6276 static void
6277 cmd_set_vf_rxmode_parsed(void *parsed_result,
6278                        __attribute__((unused)) struct cmdline *cl,
6279                        __attribute__((unused)) void *data)
6280 {
6281         int ret;
6282         uint16_t rx_mode = 0;
6283         struct cmd_set_vf_rxmode *res = parsed_result;
6284
6285         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6286         if (!strcmp(res->what,"rxmode")) {
6287                 if (!strcmp(res->mode, "AUPE"))
6288                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6289                 else if (!strcmp(res->mode, "ROPE"))
6290                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6291                 else if (!strcmp(res->mode, "BAM"))
6292                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6293                 else if (!strncmp(res->mode, "MPE",3))
6294                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6295         }
6296
6297         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6298         if (ret < 0)
6299                 printf("bad VF receive mode parameter, return code = %d \n",
6300                 ret);
6301 }
6302
6303 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6304         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6305                                  set, "set");
6306 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6307         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6308                                  port, "port");
6309 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6310         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6311                               port_id, UINT8);
6312 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6313         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6314                                  vf, "vf");
6315 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6316         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6317                               vf_id, UINT8);
6318 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6319         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6320                                  what, "rxmode");
6321 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6322         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6323                                  mode, "AUPE#ROPE#BAM#MPE");
6324 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6325         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6326                                  on, "on#off");
6327
6328 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6329         .f = cmd_set_vf_rxmode_parsed,
6330         .data = NULL,
6331         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6332         .tokens = {
6333                 (void *)&cmd_set_vf_rxmode_set,
6334                 (void *)&cmd_set_vf_rxmode_port,
6335                 (void *)&cmd_set_vf_rxmode_portid,
6336                 (void *)&cmd_set_vf_rxmode_vf,
6337                 (void *)&cmd_set_vf_rxmode_vfid,
6338                 (void *)&cmd_set_vf_rxmode_what,
6339                 (void *)&cmd_set_vf_rxmode_mode,
6340                 (void *)&cmd_set_vf_rxmode_on,
6341                 NULL,
6342         },
6343 };
6344
6345 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6346 struct cmd_vf_mac_addr_result {
6347         cmdline_fixed_string_t mac_addr_cmd;
6348         cmdline_fixed_string_t what;
6349         cmdline_fixed_string_t port;
6350         uint8_t port_num;
6351         cmdline_fixed_string_t vf;
6352         uint8_t vf_num;
6353         struct ether_addr address;
6354 };
6355
6356 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6357                 __attribute__((unused)) struct cmdline *cl,
6358                 __attribute__((unused)) void *data)
6359 {
6360         struct cmd_vf_mac_addr_result *res = parsed_result;
6361         int ret = 0;
6362
6363         if (strcmp(res->what, "add") == 0)
6364                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6365                                         &res->address, res->vf_num);
6366         if(ret < 0)
6367                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6368
6369 }
6370
6371 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6372         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6373                                 mac_addr_cmd,"mac_addr");
6374 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6375         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6376                                 what,"add");
6377 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6378         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6379                                 port,"port");
6380 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6381         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6382                                 port_num, UINT8);
6383 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6384         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6385                                 vf,"vf");
6386 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6387         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6388                                 vf_num, UINT8);
6389 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6390         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6391                                 address);
6392
6393 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6394         .f = cmd_vf_mac_addr_parsed,
6395         .data = (void *)0,
6396         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6397         "Y = VF number)add MAC address filtering for a VF on port X",
6398         .tokens = {
6399                 (void *)&cmd_vf_mac_addr_cmd,
6400                 (void *)&cmd_vf_mac_addr_what,
6401                 (void *)&cmd_vf_mac_addr_port,
6402                 (void *)&cmd_vf_mac_addr_portnum,
6403                 (void *)&cmd_vf_mac_addr_vf,
6404                 (void *)&cmd_vf_mac_addr_vfnum,
6405                 (void *)&cmd_vf_mac_addr_addr,
6406                 NULL,
6407         },
6408 };
6409
6410 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6411 struct cmd_vf_rx_vlan_filter {
6412         cmdline_fixed_string_t rx_vlan;
6413         cmdline_fixed_string_t what;
6414         uint16_t vlan_id;
6415         cmdline_fixed_string_t port;
6416         uint8_t port_id;
6417         cmdline_fixed_string_t vf;
6418         uint64_t vf_mask;
6419 };
6420
6421 static void
6422 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6423                           __attribute__((unused)) struct cmdline *cl,
6424                           __attribute__((unused)) void *data)
6425 {
6426         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6427
6428         if (!strcmp(res->what, "add"))
6429                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6430         else
6431                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6432 }
6433
6434 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6435         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6436                                  rx_vlan, "rx_vlan");
6437 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6438         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6439                                  what, "add#rm");
6440 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6441         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6442                               vlan_id, UINT16);
6443 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6444         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6445                                  port, "port");
6446 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6447         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6448                               port_id, UINT8);
6449 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6450         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6451                                  vf, "vf");
6452 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6453         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6454                               vf_mask, UINT64);
6455
6456 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6457         .f = cmd_vf_rx_vlan_filter_parsed,
6458         .data = NULL,
6459         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6460                 "Y = port number,Z = hexadecimal VF mask)",
6461         .tokens = {
6462                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6463                 (void *)&cmd_vf_rx_vlan_filter_what,
6464                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6465                 (void *)&cmd_vf_rx_vlan_filter_port,
6466                 (void *)&cmd_vf_rx_vlan_filter_portid,
6467                 (void *)&cmd_vf_rx_vlan_filter_vf,
6468                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6469                 NULL,
6470         },
6471 };
6472
6473 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6474 struct cmd_queue_rate_limit_result {
6475         cmdline_fixed_string_t set;
6476         cmdline_fixed_string_t port;
6477         uint8_t port_num;
6478         cmdline_fixed_string_t queue;
6479         uint8_t queue_num;
6480         cmdline_fixed_string_t rate;
6481         uint16_t rate_num;
6482 };
6483
6484 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6485                 __attribute__((unused)) struct cmdline *cl,
6486                 __attribute__((unused)) void *data)
6487 {
6488         struct cmd_queue_rate_limit_result *res = parsed_result;
6489         int ret = 0;
6490
6491         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6492                 && (strcmp(res->queue, "queue") == 0)
6493                 && (strcmp(res->rate, "rate") == 0))
6494                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6495                                         res->rate_num);
6496         if (ret < 0)
6497                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6498
6499 }
6500
6501 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6502         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6503                                 set, "set");
6504 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6505         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6506                                 port, "port");
6507 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6508         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6509                                 port_num, UINT8);
6510 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6511         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6512                                 queue, "queue");
6513 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6514         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6515                                 queue_num, UINT8);
6516 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6517         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6518                                 rate, "rate");
6519 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6520         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6521                                 rate_num, UINT16);
6522
6523 cmdline_parse_inst_t cmd_queue_rate_limit = {
6524         .f = cmd_queue_rate_limit_parsed,
6525         .data = (void *)0,
6526         .help_str = "set port X queue Y rate Z:(X = port number,"
6527         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6528         .tokens = {
6529                 (void *)&cmd_queue_rate_limit_set,
6530                 (void *)&cmd_queue_rate_limit_port,
6531                 (void *)&cmd_queue_rate_limit_portnum,
6532                 (void *)&cmd_queue_rate_limit_queue,
6533                 (void *)&cmd_queue_rate_limit_queuenum,
6534                 (void *)&cmd_queue_rate_limit_rate,
6535                 (void *)&cmd_queue_rate_limit_ratenum,
6536                 NULL,
6537         },
6538 };
6539
6540 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6541 struct cmd_vf_rate_limit_result {
6542         cmdline_fixed_string_t set;
6543         cmdline_fixed_string_t port;
6544         uint8_t port_num;
6545         cmdline_fixed_string_t vf;
6546         uint8_t vf_num;
6547         cmdline_fixed_string_t rate;
6548         uint16_t rate_num;
6549         cmdline_fixed_string_t q_msk;
6550         uint64_t q_msk_val;
6551 };
6552
6553 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6554                 __attribute__((unused)) struct cmdline *cl,
6555                 __attribute__((unused)) void *data)
6556 {
6557         struct cmd_vf_rate_limit_result *res = parsed_result;
6558         int ret = 0;
6559
6560         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6561                 && (strcmp(res->vf, "vf") == 0)
6562                 && (strcmp(res->rate, "rate") == 0)
6563                 && (strcmp(res->q_msk, "queue_mask") == 0))
6564                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6565                                         res->rate_num, res->q_msk_val);
6566         if (ret < 0)
6567                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6568
6569 }
6570
6571 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6572         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6573                                 set, "set");
6574 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6575         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6576                                 port, "port");
6577 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6578         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6579                                 port_num, UINT8);
6580 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6581         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6582                                 vf, "vf");
6583 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6584         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6585                                 vf_num, UINT8);
6586 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6587         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6588                                 rate, "rate");
6589 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6590         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6591                                 rate_num, UINT16);
6592 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6593         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6594                                 q_msk, "queue_mask");
6595 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6596         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6597                                 q_msk_val, UINT64);
6598
6599 cmdline_parse_inst_t cmd_vf_rate_limit = {
6600         .f = cmd_vf_rate_limit_parsed,
6601         .data = (void *)0,
6602         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6603         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6604         "for queues of VF on port X",
6605         .tokens = {
6606                 (void *)&cmd_vf_rate_limit_set,
6607                 (void *)&cmd_vf_rate_limit_port,
6608                 (void *)&cmd_vf_rate_limit_portnum,
6609                 (void *)&cmd_vf_rate_limit_vf,
6610                 (void *)&cmd_vf_rate_limit_vfnum,
6611                 (void *)&cmd_vf_rate_limit_rate,
6612                 (void *)&cmd_vf_rate_limit_ratenum,
6613                 (void *)&cmd_vf_rate_limit_q_msk,
6614                 (void *)&cmd_vf_rate_limit_q_msk_val,
6615                 NULL,
6616         },
6617 };
6618
6619 /* *** ADD TUNNEL FILTER OF A PORT *** */
6620 struct cmd_tunnel_filter_result {
6621         cmdline_fixed_string_t cmd;
6622         cmdline_fixed_string_t what;
6623         uint8_t port_id;
6624         struct ether_addr outer_mac;
6625         struct ether_addr inner_mac;
6626         cmdline_ipaddr_t ip_value;
6627         uint16_t inner_vlan;
6628         cmdline_fixed_string_t tunnel_type;
6629         cmdline_fixed_string_t filter_type;
6630         uint32_t tenant_id;
6631         uint16_t queue_num;
6632 };
6633
6634 static void
6635 cmd_tunnel_filter_parsed(void *parsed_result,
6636                           __attribute__((unused)) struct cmdline *cl,
6637                           __attribute__((unused)) void *data)
6638 {
6639         struct cmd_tunnel_filter_result *res = parsed_result;
6640         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6641         int ret = 0;
6642
6643         tunnel_filter_conf.outer_mac = &res->outer_mac;
6644         tunnel_filter_conf.inner_mac = &res->inner_mac;
6645         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6646
6647         if (res->ip_value.family == AF_INET) {
6648                 tunnel_filter_conf.ip_addr.ipv4_addr =
6649                         res->ip_value.addr.ipv4.s_addr;
6650                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6651         } else {
6652                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6653                         &(res->ip_value.addr.ipv6),
6654                         sizeof(struct in6_addr));
6655                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6656         }
6657
6658         if (!strcmp(res->filter_type, "imac-ivlan"))
6659                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6660         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6661                 tunnel_filter_conf.filter_type =
6662                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6663         else if (!strcmp(res->filter_type, "imac-tenid"))
6664                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6665         else if (!strcmp(res->filter_type, "imac"))
6666                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6667         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6668                 tunnel_filter_conf.filter_type =
6669                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6670         else {
6671                 printf("The filter type is not supported");
6672                 return;
6673         }
6674
6675         if (!strcmp(res->tunnel_type, "vxlan"))
6676                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6677         else if (!strcmp(res->tunnel_type, "nvgre"))
6678                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
6679         else {
6680                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
6681                 return;
6682         }
6683
6684         tunnel_filter_conf.tenant_id = res->tenant_id;
6685         tunnel_filter_conf.queue_id = res->queue_num;
6686         if (!strcmp(res->what, "add"))
6687                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6688                                         RTE_ETH_FILTER_TUNNEL,
6689                                         RTE_ETH_FILTER_ADD,
6690                                         &tunnel_filter_conf);
6691         else
6692                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6693                                         RTE_ETH_FILTER_TUNNEL,
6694                                         RTE_ETH_FILTER_DELETE,
6695                                         &tunnel_filter_conf);
6696         if (ret < 0)
6697                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6698                                 strerror(-ret));
6699
6700 }
6701 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6702         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6703         cmd, "tunnel_filter");
6704 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6705         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6706         what, "add#rm");
6707 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6708         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6709         port_id, UINT8);
6710 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6711         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6712         outer_mac);
6713 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6714         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6715         inner_mac);
6716 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6717         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6718         inner_vlan, UINT16);
6719 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6720         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6721         ip_value);
6722 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6723         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6724         tunnel_type, "vxlan#nvgre");
6725
6726 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6727         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6728         filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6729                 "imac#omac-imac-tenid");
6730 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6731         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6732         tenant_id, UINT32);
6733 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6734         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6735         queue_num, UINT16);
6736
6737 cmdline_parse_inst_t cmd_tunnel_filter = {
6738         .f = cmd_tunnel_filter_parsed,
6739         .data = (void *)0,
6740         .help_str = "add/rm tunnel filter of a port: "
6741                         "tunnel_filter add port_id outer_mac inner_mac ip "
6742                         "inner_vlan tunnel_type(vxlan|nvgre) filter_type "
6743                         "(imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6744                         "imac|omac-imac-tenid) "
6745                         "tenant_id queue_num",
6746         .tokens = {
6747                 (void *)&cmd_tunnel_filter_cmd,
6748                 (void *)&cmd_tunnel_filter_what,
6749                 (void *)&cmd_tunnel_filter_port_id,
6750                 (void *)&cmd_tunnel_filter_outer_mac,
6751                 (void *)&cmd_tunnel_filter_inner_mac,
6752                 (void *)&cmd_tunnel_filter_ip_value,
6753                 (void *)&cmd_tunnel_filter_innner_vlan,
6754                 (void *)&cmd_tunnel_filter_tunnel_type,
6755                 (void *)&cmd_tunnel_filter_filter_type,
6756                 (void *)&cmd_tunnel_filter_tenant_id,
6757                 (void *)&cmd_tunnel_filter_queue_num,
6758                 NULL,
6759         },
6760 };
6761
6762 /* *** CONFIGURE TUNNEL UDP PORT *** */
6763 struct cmd_tunnel_udp_config {
6764         cmdline_fixed_string_t cmd;
6765         cmdline_fixed_string_t what;
6766         uint16_t udp_port;
6767         uint8_t port_id;
6768 };
6769
6770 static void
6771 cmd_tunnel_udp_config_parsed(void *parsed_result,
6772                           __attribute__((unused)) struct cmdline *cl,
6773                           __attribute__((unused)) void *data)
6774 {
6775         struct cmd_tunnel_udp_config *res = parsed_result;
6776         struct rte_eth_udp_tunnel tunnel_udp;
6777         int ret;
6778
6779         tunnel_udp.udp_port = res->udp_port;
6780
6781         if (!strcmp(res->cmd, "rx_vxlan_port"))
6782                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6783
6784         if (!strcmp(res->what, "add"))
6785                 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp);
6786         else
6787                 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp);
6788
6789         if (ret < 0)
6790                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6791 }
6792
6793 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6794         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6795                                 cmd, "rx_vxlan_port");
6796 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6797         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6798                                 what, "add#rm");
6799 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6800         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6801                                 udp_port, UINT16);
6802 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6803         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6804                                 port_id, UINT8);
6805
6806 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6807         .f = cmd_tunnel_udp_config_parsed,
6808         .data = (void *)0,
6809         .help_str = "add/rm an tunneling UDP port filter: "
6810                         "rx_vxlan_port add udp_port port_id",
6811         .tokens = {
6812                 (void *)&cmd_tunnel_udp_config_cmd,
6813                 (void *)&cmd_tunnel_udp_config_what,
6814                 (void *)&cmd_tunnel_udp_config_udp_port,
6815                 (void *)&cmd_tunnel_udp_config_port_id,
6816                 NULL,
6817         },
6818 };
6819
6820 /* *** GLOBAL CONFIG *** */
6821 struct cmd_global_config_result {
6822         cmdline_fixed_string_t cmd;
6823         uint8_t port_id;
6824         cmdline_fixed_string_t cfg_type;
6825         uint8_t len;
6826 };
6827
6828 static void
6829 cmd_global_config_parsed(void *parsed_result,
6830                          __attribute__((unused)) struct cmdline *cl,
6831                          __attribute__((unused)) void *data)
6832 {
6833         struct cmd_global_config_result *res = parsed_result;
6834         struct rte_eth_global_cfg conf;
6835         int ret;
6836
6837         memset(&conf, 0, sizeof(conf));
6838         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
6839         conf.cfg.gre_key_len = res->len;
6840         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
6841                                       RTE_ETH_FILTER_SET, &conf);
6842         if (ret != 0)
6843                 printf("Global config error\n");
6844 }
6845
6846 cmdline_parse_token_string_t cmd_global_config_cmd =
6847         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
6848                 "global_config");
6849 cmdline_parse_token_num_t cmd_global_config_port_id =
6850         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
6851 cmdline_parse_token_string_t cmd_global_config_type =
6852         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
6853                 cfg_type, "gre-key-len");
6854 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
6855         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
6856                 len, UINT8);
6857
6858 cmdline_parse_inst_t cmd_global_config = {
6859         .f = cmd_global_config_parsed,
6860         .data = (void *)NULL,
6861         .help_str = "global_config <port_id> gre-key-len <number>",
6862         .tokens = {
6863                 (void *)&cmd_global_config_cmd,
6864                 (void *)&cmd_global_config_port_id,
6865                 (void *)&cmd_global_config_type,
6866                 (void *)&cmd_global_config_gre_key_len,
6867                 NULL,
6868         },
6869 };
6870
6871 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6872 struct cmd_set_mirror_mask_result {
6873         cmdline_fixed_string_t set;
6874         cmdline_fixed_string_t port;
6875         uint8_t port_id;
6876         cmdline_fixed_string_t mirror;
6877         uint8_t rule_id;
6878         cmdline_fixed_string_t what;
6879         cmdline_fixed_string_t value;
6880         cmdline_fixed_string_t dstpool;
6881         uint8_t dstpool_id;
6882         cmdline_fixed_string_t on;
6883 };
6884
6885 cmdline_parse_token_string_t cmd_mirror_mask_set =
6886         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6887                                 set, "set");
6888 cmdline_parse_token_string_t cmd_mirror_mask_port =
6889         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6890                                 port, "port");
6891 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6892         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6893                                 port_id, UINT8);
6894 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6895         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6896                                 mirror, "mirror-rule");
6897 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6898         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6899                                 rule_id, UINT8);
6900 cmdline_parse_token_string_t cmd_mirror_mask_what =
6901         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6902                                 what, "pool-mirror-up#pool-mirror-down"
6903                                       "#vlan-mirror");
6904 cmdline_parse_token_string_t cmd_mirror_mask_value =
6905         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6906                                 value, NULL);
6907 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6908         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6909                                 dstpool, "dst-pool");
6910 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6911         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6912                                 dstpool_id, UINT8);
6913 cmdline_parse_token_string_t cmd_mirror_mask_on =
6914         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6915                                 on, "on#off");
6916
6917 static void
6918 cmd_set_mirror_mask_parsed(void *parsed_result,
6919                        __attribute__((unused)) struct cmdline *cl,
6920                        __attribute__((unused)) void *data)
6921 {
6922         int ret,nb_item,i;
6923         struct cmd_set_mirror_mask_result *res = parsed_result;
6924         struct rte_eth_mirror_conf mr_conf;
6925
6926         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6927
6928         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
6929
6930         mr_conf.dst_pool = res->dstpool_id;
6931
6932         if (!strcmp(res->what, "pool-mirror-up")) {
6933                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6934                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
6935         } else if (!strcmp(res->what, "pool-mirror-down")) {
6936                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6937                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
6938         } else if (!strcmp(res->what, "vlan-mirror")) {
6939                 mr_conf.rule_type = ETH_MIRROR_VLAN;
6940                 nb_item = parse_item_list(res->value, "vlan",
6941                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
6942                 if (nb_item <= 0)
6943                         return;
6944
6945                 for (i = 0; i < nb_item; i++) {
6946                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6947                                 printf("Invalid vlan_id: must be < 4096\n");
6948                                 return;
6949                         }
6950
6951                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6952                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6953                 }
6954         }
6955
6956         if (!strcmp(res->on, "on"))
6957                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6958                                                 res->rule_id, 1);
6959         else
6960                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6961                                                 res->rule_id, 0);
6962         if (ret < 0)
6963                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6964 }
6965
6966 cmdline_parse_inst_t cmd_set_mirror_mask = {
6967                 .f = cmd_set_mirror_mask_parsed,
6968                 .data = NULL,
6969                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
6970                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
6971                 .tokens = {
6972                         (void *)&cmd_mirror_mask_set,
6973                         (void *)&cmd_mirror_mask_port,
6974                         (void *)&cmd_mirror_mask_portid,
6975                         (void *)&cmd_mirror_mask_mirror,
6976                         (void *)&cmd_mirror_mask_ruleid,
6977                         (void *)&cmd_mirror_mask_what,
6978                         (void *)&cmd_mirror_mask_value,
6979                         (void *)&cmd_mirror_mask_dstpool,
6980                         (void *)&cmd_mirror_mask_poolid,
6981                         (void *)&cmd_mirror_mask_on,
6982                         NULL,
6983                 },
6984 };
6985
6986 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
6987 struct cmd_set_mirror_link_result {
6988         cmdline_fixed_string_t set;
6989         cmdline_fixed_string_t port;
6990         uint8_t port_id;
6991         cmdline_fixed_string_t mirror;
6992         uint8_t rule_id;
6993         cmdline_fixed_string_t what;
6994         cmdline_fixed_string_t dstpool;
6995         uint8_t dstpool_id;
6996         cmdline_fixed_string_t on;
6997 };
6998
6999 cmdline_parse_token_string_t cmd_mirror_link_set =
7000         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7001                                  set, "set");
7002 cmdline_parse_token_string_t cmd_mirror_link_port =
7003         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7004                                 port, "port");
7005 cmdline_parse_token_num_t cmd_mirror_link_portid =
7006         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7007                                 port_id, UINT8);
7008 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7009         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7010                                 mirror, "mirror-rule");
7011 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7012         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7013                             rule_id, UINT8);
7014 cmdline_parse_token_string_t cmd_mirror_link_what =
7015         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7016                                 what, "uplink-mirror#downlink-mirror");
7017 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7018         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7019                                 dstpool, "dst-pool");
7020 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7021         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7022                                 dstpool_id, UINT8);
7023 cmdline_parse_token_string_t cmd_mirror_link_on =
7024         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7025                                 on, "on#off");
7026
7027 static void
7028 cmd_set_mirror_link_parsed(void *parsed_result,
7029                        __attribute__((unused)) struct cmdline *cl,
7030                        __attribute__((unused)) void *data)
7031 {
7032         int ret;
7033         struct cmd_set_mirror_link_result *res = parsed_result;
7034         struct rte_eth_mirror_conf mr_conf;
7035
7036         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7037         if (!strcmp(res->what, "uplink-mirror"))
7038                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7039         else
7040                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7041
7042         mr_conf.dst_pool = res->dstpool_id;
7043
7044         if (!strcmp(res->on, "on"))
7045                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7046                                                 res->rule_id, 1);
7047         else
7048                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7049                                                 res->rule_id, 0);
7050
7051         /* check the return value and print it if is < 0 */
7052         if (ret < 0)
7053                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7054
7055 }
7056
7057 cmdline_parse_inst_t cmd_set_mirror_link = {
7058                 .f = cmd_set_mirror_link_parsed,
7059                 .data = NULL,
7060                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7061                         "downlink-mirror dst-pool Z on|off",
7062                 .tokens = {
7063                         (void *)&cmd_mirror_link_set,
7064                         (void *)&cmd_mirror_link_port,
7065                         (void *)&cmd_mirror_link_portid,
7066                         (void *)&cmd_mirror_link_mirror,
7067                         (void *)&cmd_mirror_link_ruleid,
7068                         (void *)&cmd_mirror_link_what,
7069                         (void *)&cmd_mirror_link_dstpool,
7070                         (void *)&cmd_mirror_link_poolid,
7071                         (void *)&cmd_mirror_link_on,
7072                         NULL,
7073                 },
7074 };
7075
7076 /* *** RESET VM MIRROR RULE *** */
7077 struct cmd_rm_mirror_rule_result {
7078         cmdline_fixed_string_t reset;
7079         cmdline_fixed_string_t port;
7080         uint8_t port_id;
7081         cmdline_fixed_string_t mirror;
7082         uint8_t rule_id;
7083 };
7084
7085 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7086         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7087                                  reset, "reset");
7088 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7089         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7090                                 port, "port");
7091 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7092         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7093                                 port_id, UINT8);
7094 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7095         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7096                                 mirror, "mirror-rule");
7097 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7098         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7099                                 rule_id, UINT8);
7100
7101 static void
7102 cmd_reset_mirror_rule_parsed(void *parsed_result,
7103                        __attribute__((unused)) struct cmdline *cl,
7104                        __attribute__((unused)) void *data)
7105 {
7106         int ret;
7107         struct cmd_set_mirror_link_result *res = parsed_result;
7108         /* check rule_id */
7109         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7110         if(ret < 0)
7111                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7112 }
7113
7114 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7115                 .f = cmd_reset_mirror_rule_parsed,
7116                 .data = NULL,
7117                 .help_str = "reset port X mirror-rule Y",
7118                 .tokens = {
7119                         (void *)&cmd_rm_mirror_rule_reset,
7120                         (void *)&cmd_rm_mirror_rule_port,
7121                         (void *)&cmd_rm_mirror_rule_portid,
7122                         (void *)&cmd_rm_mirror_rule_mirror,
7123                         (void *)&cmd_rm_mirror_rule_ruleid,
7124                         NULL,
7125                 },
7126 };
7127
7128 /* ******************************************************************************** */
7129
7130 struct cmd_dump_result {
7131         cmdline_fixed_string_t dump;
7132 };
7133
7134 static void
7135 dump_struct_sizes(void)
7136 {
7137 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7138         DUMP_SIZE(struct rte_mbuf);
7139         DUMP_SIZE(struct rte_mempool);
7140         DUMP_SIZE(struct rte_ring);
7141 #undef DUMP_SIZE
7142 }
7143
7144 static void cmd_dump_parsed(void *parsed_result,
7145                             __attribute__((unused)) struct cmdline *cl,
7146                             __attribute__((unused)) void *data)
7147 {
7148         struct cmd_dump_result *res = parsed_result;
7149
7150         if (!strcmp(res->dump, "dump_physmem"))
7151                 rte_dump_physmem_layout(stdout);
7152         else if (!strcmp(res->dump, "dump_memzone"))
7153                 rte_memzone_dump(stdout);
7154         else if (!strcmp(res->dump, "dump_log_history"))
7155                 rte_log_dump_history(stdout);
7156         else if (!strcmp(res->dump, "dump_struct_sizes"))
7157                 dump_struct_sizes();
7158         else if (!strcmp(res->dump, "dump_ring"))
7159                 rte_ring_list_dump(stdout);
7160         else if (!strcmp(res->dump, "dump_mempool"))
7161                 rte_mempool_list_dump(stdout);
7162         else if (!strcmp(res->dump, "dump_devargs"))
7163                 rte_eal_devargs_dump(stdout);
7164 }
7165
7166 cmdline_parse_token_string_t cmd_dump_dump =
7167         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7168                 "dump_physmem#"
7169                 "dump_memzone#"
7170                 "dump_log_history#"
7171                 "dump_struct_sizes#"
7172                 "dump_ring#"
7173                 "dump_mempool#"
7174                 "dump_devargs");
7175
7176 cmdline_parse_inst_t cmd_dump = {
7177         .f = cmd_dump_parsed,  /* function to call */
7178         .data = NULL,      /* 2nd arg of func */
7179         .help_str = "dump status",
7180         .tokens = {        /* token list, NULL terminated */
7181                 (void *)&cmd_dump_dump,
7182                 NULL,
7183         },
7184 };
7185
7186 /* ******************************************************************************** */
7187
7188 struct cmd_dump_one_result {
7189         cmdline_fixed_string_t dump;
7190         cmdline_fixed_string_t name;
7191 };
7192
7193 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7194                                 __attribute__((unused)) void *data)
7195 {
7196         struct cmd_dump_one_result *res = parsed_result;
7197
7198         if (!strcmp(res->dump, "dump_ring")) {
7199                 struct rte_ring *r;
7200                 r = rte_ring_lookup(res->name);
7201                 if (r == NULL) {
7202                         cmdline_printf(cl, "Cannot find ring\n");
7203                         return;
7204                 }
7205                 rte_ring_dump(stdout, r);
7206         } else if (!strcmp(res->dump, "dump_mempool")) {
7207                 struct rte_mempool *mp;
7208                 mp = rte_mempool_lookup(res->name);
7209                 if (mp == NULL) {
7210                         cmdline_printf(cl, "Cannot find mempool\n");
7211                         return;
7212                 }
7213                 rte_mempool_dump(stdout, mp);
7214         }
7215 }
7216
7217 cmdline_parse_token_string_t cmd_dump_one_dump =
7218         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7219                                  "dump_ring#dump_mempool");
7220
7221 cmdline_parse_token_string_t cmd_dump_one_name =
7222         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7223
7224 cmdline_parse_inst_t cmd_dump_one = {
7225         .f = cmd_dump_one_parsed,  /* function to call */
7226         .data = NULL,      /* 2nd arg of func */
7227         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7228         .tokens = {        /* token list, NULL terminated */
7229                 (void *)&cmd_dump_one_dump,
7230                 (void *)&cmd_dump_one_name,
7231                 NULL,
7232         },
7233 };
7234
7235 /* *** Add/Del syn filter *** */
7236 struct cmd_syn_filter_result {
7237         cmdline_fixed_string_t filter;
7238         uint8_t port_id;
7239         cmdline_fixed_string_t ops;
7240         cmdline_fixed_string_t priority;
7241         cmdline_fixed_string_t high;
7242         cmdline_fixed_string_t queue;
7243         uint16_t queue_id;
7244 };
7245
7246 static void
7247 cmd_syn_filter_parsed(void *parsed_result,
7248                         __attribute__((unused)) struct cmdline *cl,
7249                         __attribute__((unused)) void *data)
7250 {
7251         struct cmd_syn_filter_result *res = parsed_result;
7252         struct rte_eth_syn_filter syn_filter;
7253         int ret = 0;
7254
7255         ret = rte_eth_dev_filter_supported(res->port_id,
7256                                         RTE_ETH_FILTER_SYN);
7257         if (ret < 0) {
7258                 printf("syn filter is not supported on port %u.\n",
7259                                 res->port_id);
7260                 return;
7261         }
7262
7263         memset(&syn_filter, 0, sizeof(syn_filter));
7264
7265         if (!strcmp(res->ops, "add")) {
7266                 if (!strcmp(res->high, "high"))
7267                         syn_filter.hig_pri = 1;
7268                 else
7269                         syn_filter.hig_pri = 0;
7270
7271                 syn_filter.queue = res->queue_id;
7272                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7273                                                 RTE_ETH_FILTER_SYN,
7274                                                 RTE_ETH_FILTER_ADD,
7275                                                 &syn_filter);
7276         } else
7277                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7278                                                 RTE_ETH_FILTER_SYN,
7279                                                 RTE_ETH_FILTER_DELETE,
7280                                                 &syn_filter);
7281
7282         if (ret < 0)
7283                 printf("syn filter programming error: (%s)\n",
7284                                 strerror(-ret));
7285 }
7286
7287 cmdline_parse_token_string_t cmd_syn_filter_filter =
7288         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7289         filter, "syn_filter");
7290 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7291         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7292         port_id, UINT8);
7293 cmdline_parse_token_string_t cmd_syn_filter_ops =
7294         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7295         ops, "add#del");
7296 cmdline_parse_token_string_t cmd_syn_filter_priority =
7297         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7298                                 priority, "priority");
7299 cmdline_parse_token_string_t cmd_syn_filter_high =
7300         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7301                                 high, "high#low");
7302 cmdline_parse_token_string_t cmd_syn_filter_queue =
7303         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7304                                 queue, "queue");
7305 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7306         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7307                                 queue_id, UINT16);
7308
7309 cmdline_parse_inst_t cmd_syn_filter = {
7310         .f = cmd_syn_filter_parsed,
7311         .data = NULL,
7312         .help_str = "add/delete syn filter",
7313         .tokens = {
7314                 (void *)&cmd_syn_filter_filter,
7315                 (void *)&cmd_syn_filter_port_id,
7316                 (void *)&cmd_syn_filter_ops,
7317                 (void *)&cmd_syn_filter_priority,
7318                 (void *)&cmd_syn_filter_high,
7319                 (void *)&cmd_syn_filter_queue,
7320                 (void *)&cmd_syn_filter_queue_id,
7321                 NULL,
7322         },
7323 };
7324
7325 /* *** ADD/REMOVE A 2tuple FILTER *** */
7326 struct cmd_2tuple_filter_result {
7327         cmdline_fixed_string_t filter;
7328         uint8_t  port_id;
7329         cmdline_fixed_string_t ops;
7330         cmdline_fixed_string_t dst_port;
7331         uint16_t dst_port_value;
7332         cmdline_fixed_string_t protocol;
7333         uint8_t protocol_value;
7334         cmdline_fixed_string_t mask;
7335         uint8_t  mask_value;
7336         cmdline_fixed_string_t tcp_flags;
7337         uint8_t tcp_flags_value;
7338         cmdline_fixed_string_t priority;
7339         uint8_t  priority_value;
7340         cmdline_fixed_string_t queue;
7341         uint16_t  queue_id;
7342 };
7343
7344 static void
7345 cmd_2tuple_filter_parsed(void *parsed_result,
7346                         __attribute__((unused)) struct cmdline *cl,
7347                         __attribute__((unused)) void *data)
7348 {
7349         struct rte_eth_ntuple_filter filter;
7350         struct cmd_2tuple_filter_result *res = parsed_result;
7351         int ret = 0;
7352
7353         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7354         if (ret < 0) {
7355                 printf("ntuple filter is not supported on port %u.\n",
7356                         res->port_id);
7357                 return;
7358         }
7359
7360         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7361
7362         filter.flags = RTE_2TUPLE_FLAGS;
7363         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7364         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7365         filter.proto = res->protocol_value;
7366         filter.priority = res->priority_value;
7367         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7368                 printf("nonzero tcp_flags is only meaningful"
7369                         " when protocol is TCP.\n");
7370                 return;
7371         }
7372         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7373                 printf("invalid TCP flags.\n");
7374                 return;
7375         }
7376
7377         if (res->tcp_flags_value != 0) {
7378                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7379                 filter.tcp_flags = res->tcp_flags_value;
7380         }
7381
7382         /* need convert to big endian. */
7383         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7384         filter.queue = res->queue_id;
7385
7386         if (!strcmp(res->ops, "add"))
7387                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7388                                 RTE_ETH_FILTER_NTUPLE,
7389                                 RTE_ETH_FILTER_ADD,
7390                                 &filter);
7391         else
7392                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7393                                 RTE_ETH_FILTER_NTUPLE,
7394                                 RTE_ETH_FILTER_DELETE,
7395                                 &filter);
7396         if (ret < 0)
7397                 printf("2tuple filter programming error: (%s)\n",
7398                         strerror(-ret));
7399
7400 }
7401
7402 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7403         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7404                                  filter, "2tuple_filter");
7405 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7406         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7407                                 port_id, UINT8);
7408 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7409         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7410                                  ops, "add#del");
7411 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7412         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7413                                 dst_port, "dst_port");
7414 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7415         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7416                                 dst_port_value, UINT16);
7417 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7418         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7419                                 protocol, "protocol");
7420 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7421         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7422                                 protocol_value, UINT8);
7423 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7424         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7425                                 mask, "mask");
7426 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7427         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7428                                 mask_value, INT8);
7429 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7430         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7431                                 tcp_flags, "tcp_flags");
7432 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7433         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7434                                 tcp_flags_value, UINT8);
7435 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7436         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7437                                 priority, "priority");
7438 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7439         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7440                                 priority_value, UINT8);
7441 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7442         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7443                                 queue, "queue");
7444 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7445         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7446                                 queue_id, UINT16);
7447
7448 cmdline_parse_inst_t cmd_2tuple_filter = {
7449         .f = cmd_2tuple_filter_parsed,
7450         .data = NULL,
7451         .help_str = "add a 2tuple filter",
7452         .tokens = {
7453                 (void *)&cmd_2tuple_filter_filter,
7454                 (void *)&cmd_2tuple_filter_port_id,
7455                 (void *)&cmd_2tuple_filter_ops,
7456                 (void *)&cmd_2tuple_filter_dst_port,
7457                 (void *)&cmd_2tuple_filter_dst_port_value,
7458                 (void *)&cmd_2tuple_filter_protocol,
7459                 (void *)&cmd_2tuple_filter_protocol_value,
7460                 (void *)&cmd_2tuple_filter_mask,
7461                 (void *)&cmd_2tuple_filter_mask_value,
7462                 (void *)&cmd_2tuple_filter_tcp_flags,
7463                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7464                 (void *)&cmd_2tuple_filter_priority,
7465                 (void *)&cmd_2tuple_filter_priority_value,
7466                 (void *)&cmd_2tuple_filter_queue,
7467                 (void *)&cmd_2tuple_filter_queue_id,
7468                 NULL,
7469         },
7470 };
7471
7472 /* *** ADD/REMOVE A 5tuple FILTER *** */
7473 struct cmd_5tuple_filter_result {
7474         cmdline_fixed_string_t filter;
7475         uint8_t  port_id;
7476         cmdline_fixed_string_t ops;
7477         cmdline_fixed_string_t dst_ip;
7478         cmdline_ipaddr_t dst_ip_value;
7479         cmdline_fixed_string_t src_ip;
7480         cmdline_ipaddr_t src_ip_value;
7481         cmdline_fixed_string_t dst_port;
7482         uint16_t dst_port_value;
7483         cmdline_fixed_string_t src_port;
7484         uint16_t src_port_value;
7485         cmdline_fixed_string_t protocol;
7486         uint8_t protocol_value;
7487         cmdline_fixed_string_t mask;
7488         uint8_t  mask_value;
7489         cmdline_fixed_string_t tcp_flags;
7490         uint8_t tcp_flags_value;
7491         cmdline_fixed_string_t priority;
7492         uint8_t  priority_value;
7493         cmdline_fixed_string_t queue;
7494         uint16_t  queue_id;
7495 };
7496
7497 static void
7498 cmd_5tuple_filter_parsed(void *parsed_result,
7499                         __attribute__((unused)) struct cmdline *cl,
7500                         __attribute__((unused)) void *data)
7501 {
7502         struct rte_eth_ntuple_filter filter;
7503         struct cmd_5tuple_filter_result *res = parsed_result;
7504         int ret = 0;
7505
7506         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7507         if (ret < 0) {
7508                 printf("ntuple filter is not supported on port %u.\n",
7509                         res->port_id);
7510                 return;
7511         }
7512
7513         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7514
7515         filter.flags = RTE_5TUPLE_FLAGS;
7516         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7517         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7518         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7519         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7520         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7521         filter.proto = res->protocol_value;
7522         filter.priority = res->priority_value;
7523         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7524                 printf("nonzero tcp_flags is only meaningful"
7525                         " when protocol is TCP.\n");
7526                 return;
7527         }
7528         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7529                 printf("invalid TCP flags.\n");
7530                 return;
7531         }
7532
7533         if (res->tcp_flags_value != 0) {
7534                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7535                 filter.tcp_flags = res->tcp_flags_value;
7536         }
7537
7538         if (res->dst_ip_value.family == AF_INET)
7539                 /* no need to convert, already big endian. */
7540                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7541         else {
7542                 if (filter.dst_ip_mask == 0) {
7543                         printf("can not support ipv6 involved compare.\n");
7544                         return;
7545                 }
7546                 filter.dst_ip = 0;
7547         }
7548
7549         if (res->src_ip_value.family == AF_INET)
7550                 /* no need to convert, already big endian. */
7551                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7552         else {
7553                 if (filter.src_ip_mask == 0) {
7554                         printf("can not support ipv6 involved compare.\n");
7555                         return;
7556                 }
7557                 filter.src_ip = 0;
7558         }
7559         /* need convert to big endian. */
7560         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7561         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7562         filter.queue = res->queue_id;
7563
7564         if (!strcmp(res->ops, "add"))
7565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7566                                 RTE_ETH_FILTER_NTUPLE,
7567                                 RTE_ETH_FILTER_ADD,
7568                                 &filter);
7569         else
7570                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7571                                 RTE_ETH_FILTER_NTUPLE,
7572                                 RTE_ETH_FILTER_DELETE,
7573                                 &filter);
7574         if (ret < 0)
7575                 printf("5tuple filter programming error: (%s)\n",
7576                         strerror(-ret));
7577 }
7578
7579 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7580         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7581                                  filter, "5tuple_filter");
7582 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7583         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7584                                 port_id, UINT8);
7585 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7586         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7587                                  ops, "add#del");
7588 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7589         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7590                                 dst_ip, "dst_ip");
7591 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7592         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7593                                 dst_ip_value);
7594 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7595         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7596                                 src_ip, "src_ip");
7597 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7598         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7599                                 src_ip_value);
7600 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7601         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7602                                 dst_port, "dst_port");
7603 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7604         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7605                                 dst_port_value, UINT16);
7606 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7607         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7608                                 src_port, "src_port");
7609 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7610         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7611                                 src_port_value, UINT16);
7612 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7613         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7614                                 protocol, "protocol");
7615 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7616         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7617                                 protocol_value, UINT8);
7618 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7619         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7620                                 mask, "mask");
7621 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7622         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7623                                 mask_value, INT8);
7624 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7625         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7626                                 tcp_flags, "tcp_flags");
7627 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7628         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7629                                 tcp_flags_value, UINT8);
7630 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7631         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7632                                 priority, "priority");
7633 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7634         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7635                                 priority_value, UINT8);
7636 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7637         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7638                                 queue, "queue");
7639 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7640         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7641                                 queue_id, UINT16);
7642
7643 cmdline_parse_inst_t cmd_5tuple_filter = {
7644         .f = cmd_5tuple_filter_parsed,
7645         .data = NULL,
7646         .help_str = "add/del a 5tuple filter",
7647         .tokens = {
7648                 (void *)&cmd_5tuple_filter_filter,
7649                 (void *)&cmd_5tuple_filter_port_id,
7650                 (void *)&cmd_5tuple_filter_ops,
7651                 (void *)&cmd_5tuple_filter_dst_ip,
7652                 (void *)&cmd_5tuple_filter_dst_ip_value,
7653                 (void *)&cmd_5tuple_filter_src_ip,
7654                 (void *)&cmd_5tuple_filter_src_ip_value,
7655                 (void *)&cmd_5tuple_filter_dst_port,
7656                 (void *)&cmd_5tuple_filter_dst_port_value,
7657                 (void *)&cmd_5tuple_filter_src_port,
7658                 (void *)&cmd_5tuple_filter_src_port_value,
7659                 (void *)&cmd_5tuple_filter_protocol,
7660                 (void *)&cmd_5tuple_filter_protocol_value,
7661                 (void *)&cmd_5tuple_filter_mask,
7662                 (void *)&cmd_5tuple_filter_mask_value,
7663                 (void *)&cmd_5tuple_filter_tcp_flags,
7664                 (void *)&cmd_5tuple_filter_tcp_flags_value,
7665                 (void *)&cmd_5tuple_filter_priority,
7666                 (void *)&cmd_5tuple_filter_priority_value,
7667                 (void *)&cmd_5tuple_filter_queue,
7668                 (void *)&cmd_5tuple_filter_queue_id,
7669                 NULL,
7670         },
7671 };
7672
7673 /* *** ADD/REMOVE A flex FILTER *** */
7674 struct cmd_flex_filter_result {
7675         cmdline_fixed_string_t filter;
7676         cmdline_fixed_string_t ops;
7677         uint8_t port_id;
7678         cmdline_fixed_string_t len;
7679         uint8_t len_value;
7680         cmdline_fixed_string_t bytes;
7681         cmdline_fixed_string_t bytes_value;
7682         cmdline_fixed_string_t mask;
7683         cmdline_fixed_string_t mask_value;
7684         cmdline_fixed_string_t priority;
7685         uint8_t priority_value;
7686         cmdline_fixed_string_t queue;
7687         uint16_t queue_id;
7688 };
7689
7690 static int xdigit2val(unsigned char c)
7691 {
7692         int val;
7693         if (isdigit(c))
7694                 val = c - '0';
7695         else if (isupper(c))
7696                 val = c - 'A' + 10;
7697         else
7698                 val = c - 'a' + 10;
7699         return val;
7700 }
7701
7702 static void
7703 cmd_flex_filter_parsed(void *parsed_result,
7704                           __attribute__((unused)) struct cmdline *cl,
7705                           __attribute__((unused)) void *data)
7706 {
7707         int ret = 0;
7708         struct rte_eth_flex_filter filter;
7709         struct cmd_flex_filter_result *res = parsed_result;
7710         char *bytes_ptr, *mask_ptr;
7711         uint16_t len, i, j = 0;
7712         char c;
7713         int val;
7714         uint8_t byte = 0;
7715
7716         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
7717                 printf("the len exceed the max length 128\n");
7718                 return;
7719         }
7720         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
7721         filter.len = res->len_value;
7722         filter.priority = res->priority_value;
7723         filter.queue = res->queue_id;
7724         bytes_ptr = res->bytes_value;
7725         mask_ptr = res->mask_value;
7726
7727          /* translate bytes string to array. */
7728         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7729                 (bytes_ptr[1] == 'X')))
7730                 bytes_ptr += 2;
7731         len = strnlen(bytes_ptr, res->len_value * 2);
7732         if (len == 0 || (len % 8 != 0)) {
7733                 printf("please check len and bytes input\n");
7734                 return;
7735         }
7736         for (i = 0; i < len; i++) {
7737                 c = bytes_ptr[i];
7738                 if (isxdigit(c) == 0) {
7739                         /* invalid characters. */
7740                         printf("invalid input\n");
7741                         return;
7742                 }
7743                 val = xdigit2val(c);
7744                 if (i % 2) {
7745                         byte |= val;
7746                         filter.bytes[j] = byte;
7747                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
7748                         j++;
7749                         byte = 0;
7750                 } else
7751                         byte |= val << 4;
7752         }
7753         printf("\n");
7754          /* translate mask string to uint8_t array. */
7755         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7756                 (mask_ptr[1] == 'X')))
7757                 mask_ptr += 2;
7758         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
7759         if (len == 0) {
7760                 printf("invalid input\n");
7761                 return;
7762         }
7763         j = 0;
7764         byte = 0;
7765         for (i = 0; i < len; i++) {
7766                 c = mask_ptr[i];
7767                 if (isxdigit(c) == 0) {
7768                         /* invalid characters. */
7769                         printf("invalid input\n");
7770                         return;
7771                 }
7772                 val = xdigit2val(c);
7773                 if (i % 2) {
7774                         byte |= val;
7775                         filter.mask[j] = byte;
7776                         printf("mask[%d]:%02x ", j, filter.mask[j]);
7777                         j++;
7778                         byte = 0;
7779                 } else
7780                         byte |= val << 4;
7781         }
7782         printf("\n");
7783
7784         if (!strcmp(res->ops, "add"))
7785                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7786                                 RTE_ETH_FILTER_FLEXIBLE,
7787                                 RTE_ETH_FILTER_ADD,
7788                                 &filter);
7789         else
7790                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7791                                 RTE_ETH_FILTER_FLEXIBLE,
7792                                 RTE_ETH_FILTER_DELETE,
7793                                 &filter);
7794
7795         if (ret < 0)
7796                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7797 }
7798
7799 cmdline_parse_token_string_t cmd_flex_filter_filter =
7800         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7801                                 filter, "flex_filter");
7802 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7803         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7804                                 port_id, UINT8);
7805 cmdline_parse_token_string_t cmd_flex_filter_ops =
7806         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7807                                 ops, "add#del");
7808 cmdline_parse_token_string_t cmd_flex_filter_len =
7809         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7810                                 len, "len");
7811 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7812         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7813                                 len_value, UINT8);
7814 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7815         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7816                                 bytes, "bytes");
7817 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7818         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7819                                 bytes_value, NULL);
7820 cmdline_parse_token_string_t cmd_flex_filter_mask =
7821         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7822                                 mask, "mask");
7823 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7824         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7825                                 mask_value, NULL);
7826 cmdline_parse_token_string_t cmd_flex_filter_priority =
7827         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7828                                 priority, "priority");
7829 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7830         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7831                                 priority_value, UINT8);
7832 cmdline_parse_token_string_t cmd_flex_filter_queue =
7833         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7834                                 queue, "queue");
7835 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7836         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7837                                 queue_id, UINT16);
7838 cmdline_parse_inst_t cmd_flex_filter = {
7839         .f = cmd_flex_filter_parsed,
7840         .data = NULL,
7841         .help_str = "add/del a flex filter",
7842         .tokens = {
7843                 (void *)&cmd_flex_filter_filter,
7844                 (void *)&cmd_flex_filter_port_id,
7845                 (void *)&cmd_flex_filter_ops,
7846                 (void *)&cmd_flex_filter_len,
7847                 (void *)&cmd_flex_filter_len_value,
7848                 (void *)&cmd_flex_filter_bytes,
7849                 (void *)&cmd_flex_filter_bytes_value,
7850                 (void *)&cmd_flex_filter_mask,
7851                 (void *)&cmd_flex_filter_mask_value,
7852                 (void *)&cmd_flex_filter_priority,
7853                 (void *)&cmd_flex_filter_priority_value,
7854                 (void *)&cmd_flex_filter_queue,
7855                 (void *)&cmd_flex_filter_queue_id,
7856                 NULL,
7857         },
7858 };
7859
7860 /* *** Filters Control *** */
7861
7862 /* *** deal with ethertype filter *** */
7863 struct cmd_ethertype_filter_result {
7864         cmdline_fixed_string_t filter;
7865         uint8_t port_id;
7866         cmdline_fixed_string_t ops;
7867         cmdline_fixed_string_t mac;
7868         struct ether_addr mac_addr;
7869         cmdline_fixed_string_t ethertype;
7870         uint16_t ethertype_value;
7871         cmdline_fixed_string_t drop;
7872         cmdline_fixed_string_t queue;
7873         uint16_t  queue_id;
7874 };
7875
7876 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7877         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7878                                  filter, "ethertype_filter");
7879 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7880         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7881                               port_id, UINT8);
7882 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
7883         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7884                                  ops, "add#del");
7885 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
7886         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7887                                  mac, "mac_addr#mac_ignr");
7888 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
7889         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
7890                                      mac_addr);
7891 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
7892         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7893                                  ethertype, "ethertype");
7894 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
7895         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7896                               ethertype_value, UINT16);
7897 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
7898         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7899                                  drop, "drop#fwd");
7900 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
7901         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7902                                  queue, "queue");
7903 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
7904         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7905                               queue_id, UINT16);
7906
7907 static void
7908 cmd_ethertype_filter_parsed(void *parsed_result,
7909                           __attribute__((unused)) struct cmdline *cl,
7910                           __attribute__((unused)) void *data)
7911 {
7912         struct cmd_ethertype_filter_result *res = parsed_result;
7913         struct rte_eth_ethertype_filter filter;
7914         int ret = 0;
7915
7916         ret = rte_eth_dev_filter_supported(res->port_id,
7917                         RTE_ETH_FILTER_ETHERTYPE);
7918         if (ret < 0) {
7919                 printf("ethertype filter is not supported on port %u.\n",
7920                         res->port_id);
7921                 return;
7922         }
7923
7924         memset(&filter, 0, sizeof(filter));
7925         if (!strcmp(res->mac, "mac_addr")) {
7926                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
7927                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
7928                         sizeof(struct ether_addr));
7929         }
7930         if (!strcmp(res->drop, "drop"))
7931                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
7932         filter.ether_type = res->ethertype_value;
7933         filter.queue = res->queue_id;
7934
7935         if (!strcmp(res->ops, "add"))
7936                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7937                                 RTE_ETH_FILTER_ETHERTYPE,
7938                                 RTE_ETH_FILTER_ADD,
7939                                 &filter);
7940         else
7941                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7942                                 RTE_ETH_FILTER_ETHERTYPE,
7943                                 RTE_ETH_FILTER_DELETE,
7944                                 &filter);
7945         if (ret < 0)
7946                 printf("ethertype filter programming error: (%s)\n",
7947                         strerror(-ret));
7948 }
7949
7950 cmdline_parse_inst_t cmd_ethertype_filter = {
7951         .f = cmd_ethertype_filter_parsed,
7952         .data = NULL,
7953         .help_str = "add or delete an ethertype filter entry",
7954         .tokens = {
7955                 (void *)&cmd_ethertype_filter_filter,
7956                 (void *)&cmd_ethertype_filter_port_id,
7957                 (void *)&cmd_ethertype_filter_ops,
7958                 (void *)&cmd_ethertype_filter_mac,
7959                 (void *)&cmd_ethertype_filter_mac_addr,
7960                 (void *)&cmd_ethertype_filter_ethertype,
7961                 (void *)&cmd_ethertype_filter_ethertype_value,
7962                 (void *)&cmd_ethertype_filter_drop,
7963                 (void *)&cmd_ethertype_filter_queue,
7964                 (void *)&cmd_ethertype_filter_queue_id,
7965                 NULL,
7966         },
7967 };
7968
7969 /* *** deal with flow director filter *** */
7970 struct cmd_flow_director_result {
7971         cmdline_fixed_string_t flow_director_filter;
7972         uint8_t port_id;
7973         cmdline_fixed_string_t mode;
7974         cmdline_fixed_string_t mode_value;
7975         cmdline_fixed_string_t ops;
7976         cmdline_fixed_string_t flow;
7977         cmdline_fixed_string_t flow_type;
7978         cmdline_fixed_string_t ether;
7979         uint16_t ether_type;
7980         cmdline_fixed_string_t src;
7981         cmdline_ipaddr_t ip_src;
7982         uint16_t port_src;
7983         cmdline_fixed_string_t dst;
7984         cmdline_ipaddr_t ip_dst;
7985         uint16_t port_dst;
7986         cmdline_fixed_string_t verify_tag;
7987         uint32_t verify_tag_value;
7988         cmdline_fixed_string_t vlan;
7989         uint16_t vlan_value;
7990         cmdline_fixed_string_t flexbytes;
7991         cmdline_fixed_string_t flexbytes_value;
7992         cmdline_fixed_string_t pf_vf;
7993         cmdline_fixed_string_t drop;
7994         cmdline_fixed_string_t queue;
7995         uint16_t  queue_id;
7996         cmdline_fixed_string_t fd_id;
7997         uint32_t  fd_id_value;
7998         cmdline_fixed_string_t mac;
7999         struct ether_addr mac_addr;
8000         cmdline_fixed_string_t tunnel;
8001         cmdline_fixed_string_t tunnel_type;
8002         cmdline_fixed_string_t tunnel_id;
8003         uint32_t tunnel_id_value;
8004 };
8005
8006 static inline int
8007 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8008 {
8009         char s[256];
8010         const char *p, *p0 = q_arg;
8011         char *end;
8012         unsigned long int_fld;
8013         char *str_fld[max_num];
8014         int i;
8015         unsigned size;
8016         int ret = -1;
8017
8018         p = strchr(p0, '(');
8019         if (p == NULL)
8020                 return -1;
8021         ++p;
8022         p0 = strchr(p, ')');
8023         if (p0 == NULL)
8024                 return -1;
8025
8026         size = p0 - p;
8027         if (size >= sizeof(s))
8028                 return -1;
8029
8030         snprintf(s, sizeof(s), "%.*s", size, p);
8031         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8032         if (ret < 0 || ret > max_num)
8033                 return -1;
8034         for (i = 0; i < ret; i++) {
8035                 errno = 0;
8036                 int_fld = strtoul(str_fld[i], &end, 0);
8037                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8038                         return -1;
8039                 flexbytes[i] = (uint8_t)int_fld;
8040         }
8041         return ret;
8042 }
8043
8044 static uint16_t
8045 str2flowtype(char *string)
8046 {
8047         uint8_t i = 0;
8048         static const struct {
8049                 char str[32];
8050                 uint16_t type;
8051         } flowtype_str[] = {
8052                 {"raw", RTE_ETH_FLOW_RAW},
8053                 {"ipv4", RTE_ETH_FLOW_IPV4},
8054                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8055                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8056                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8057                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8058                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8059                 {"ipv6", RTE_ETH_FLOW_IPV6},
8060                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8061                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8062                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8063                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8064                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8065                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8066         };
8067
8068         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8069                 if (!strcmp(flowtype_str[i].str, string))
8070                         return flowtype_str[i].type;
8071         }
8072         return RTE_ETH_FLOW_UNKNOWN;
8073 }
8074
8075 static enum rte_eth_fdir_tunnel_type
8076 str2fdir_tunneltype(char *string)
8077 {
8078         uint8_t i = 0;
8079
8080         static const struct {
8081                 char str[32];
8082                 enum rte_eth_fdir_tunnel_type type;
8083         } tunneltype_str[] = {
8084                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8085                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8086         };
8087
8088         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8089                 if (!strcmp(tunneltype_str[i].str, string))
8090                         return tunneltype_str[i].type;
8091         }
8092         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8093 }
8094
8095 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8096 do { \
8097         if ((ip_addr).family == AF_INET) \
8098                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8099         else { \
8100                 printf("invalid parameter.\n"); \
8101                 return; \
8102         } \
8103 } while (0)
8104
8105 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8106 do { \
8107         if ((ip_addr).family == AF_INET6) \
8108                 (void)rte_memcpy(&(ip), \
8109                                  &((ip_addr).addr.ipv6), \
8110                                  sizeof(struct in6_addr)); \
8111         else { \
8112                 printf("invalid parameter.\n"); \
8113                 return; \
8114         } \
8115 } while (0)
8116
8117 static void
8118 cmd_flow_director_filter_parsed(void *parsed_result,
8119                           __attribute__((unused)) struct cmdline *cl,
8120                           __attribute__((unused)) void *data)
8121 {
8122         struct cmd_flow_director_result *res = parsed_result;
8123         struct rte_eth_fdir_filter entry;
8124         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8125         char *end;
8126         unsigned long vf_id;
8127         int ret = 0;
8128
8129         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8130         if (ret < 0) {
8131                 printf("flow director is not supported on port %u.\n",
8132                         res->port_id);
8133                 return;
8134         }
8135         memset(flexbytes, 0, sizeof(flexbytes));
8136         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8137
8138         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8139                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8140                         printf("Please set mode to MAC-VLAN.\n");
8141                         return;
8142                 }
8143         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8144                 if (strcmp(res->mode_value, "Tunnel")) {
8145                         printf("Please set mode to Tunnel.\n");
8146                         return;
8147                 }
8148         } else {
8149                 if (strcmp(res->mode_value, "IP")) {
8150                         printf("Please set mode to IP.\n");
8151                         return;
8152                 }
8153                 entry.input.flow_type = str2flowtype(res->flow_type);
8154         }
8155
8156         ret = parse_flexbytes(res->flexbytes_value,
8157                                         flexbytes,
8158                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8159         if (ret < 0) {
8160                 printf("error: Cannot parse flexbytes input.\n");
8161                 return;
8162         }
8163
8164         switch (entry.input.flow_type) {
8165         case RTE_ETH_FLOW_FRAG_IPV4:
8166         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8167         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8168         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8169                 IPV4_ADDR_TO_UINT(res->ip_dst,
8170                         entry.input.flow.ip4_flow.dst_ip);
8171                 IPV4_ADDR_TO_UINT(res->ip_src,
8172                         entry.input.flow.ip4_flow.src_ip);
8173                 /* need convert to big endian. */
8174                 entry.input.flow.udp4_flow.dst_port =
8175                                 rte_cpu_to_be_16(res->port_dst);
8176                 entry.input.flow.udp4_flow.src_port =
8177                                 rte_cpu_to_be_16(res->port_src);
8178                 break;
8179         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8180                 IPV4_ADDR_TO_UINT(res->ip_dst,
8181                         entry.input.flow.sctp4_flow.ip.dst_ip);
8182                 IPV4_ADDR_TO_UINT(res->ip_src,
8183                         entry.input.flow.sctp4_flow.ip.src_ip);
8184                 /* need convert to big endian. */
8185                 entry.input.flow.sctp4_flow.dst_port =
8186                                 rte_cpu_to_be_16(res->port_dst);
8187                 entry.input.flow.sctp4_flow.src_port =
8188                                 rte_cpu_to_be_16(res->port_src);
8189                 entry.input.flow.sctp4_flow.verify_tag =
8190                                 rte_cpu_to_be_32(res->verify_tag_value);
8191                 break;
8192         case RTE_ETH_FLOW_FRAG_IPV6:
8193         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8194         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8195         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8196                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8197                         entry.input.flow.ipv6_flow.dst_ip);
8198                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8199                         entry.input.flow.ipv6_flow.src_ip);
8200                 /* need convert to big endian. */
8201                 entry.input.flow.udp6_flow.dst_port =
8202                                 rte_cpu_to_be_16(res->port_dst);
8203                 entry.input.flow.udp6_flow.src_port =
8204                                 rte_cpu_to_be_16(res->port_src);
8205                 break;
8206         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8207                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8208                         entry.input.flow.sctp6_flow.ip.dst_ip);
8209                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8210                         entry.input.flow.sctp6_flow.ip.src_ip);
8211                 /* need convert to big endian. */
8212                 entry.input.flow.sctp6_flow.dst_port =
8213                                 rte_cpu_to_be_16(res->port_dst);
8214                 entry.input.flow.sctp6_flow.src_port =
8215                                 rte_cpu_to_be_16(res->port_src);
8216                 entry.input.flow.sctp6_flow.verify_tag =
8217                                 rte_cpu_to_be_32(res->verify_tag_value);
8218                 break;
8219         case RTE_ETH_FLOW_L2_PAYLOAD:
8220                 entry.input.flow.l2_flow.ether_type =
8221                         rte_cpu_to_be_16(res->ether_type);
8222                 break;
8223         default:
8224                 break;
8225         }
8226
8227         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8228                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8229                                  &res->mac_addr,
8230                                  sizeof(struct ether_addr));
8231
8232         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8233                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8234                                  &res->mac_addr,
8235                                  sizeof(struct ether_addr));
8236                 entry.input.flow.tunnel_flow.tunnel_type =
8237                         str2fdir_tunneltype(res->tunnel_type);
8238                 entry.input.flow.tunnel_flow.tunnel_id =
8239                         rte_cpu_to_be_32(res->tunnel_id_value);
8240         }
8241
8242         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8243                    flexbytes,
8244                    RTE_ETH_FDIR_MAX_FLEXLEN);
8245
8246         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8247
8248         entry.action.flex_off = 0;  /*use 0 by default */
8249         if (!strcmp(res->drop, "drop"))
8250                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8251         else
8252                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8253
8254         if (!strcmp(res->pf_vf, "pf"))
8255                 entry.input.flow_ext.is_vf = 0;
8256         else if (!strncmp(res->pf_vf, "vf", 2)) {
8257                 struct rte_eth_dev_info dev_info;
8258
8259                 memset(&dev_info, 0, sizeof(dev_info));
8260                 rte_eth_dev_info_get(res->port_id, &dev_info);
8261                 errno = 0;
8262                 vf_id = strtoul(res->pf_vf + 2, &end, 10);
8263                 if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
8264                         printf("invalid parameter %s.\n", res->pf_vf);
8265                         return;
8266                 }
8267                 entry.input.flow_ext.is_vf = 1;
8268                 entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8269         } else {
8270                 printf("invalid parameter %s.\n", res->pf_vf);
8271                 return;
8272         }
8273
8274         /* set to report FD ID by default */
8275         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8276         entry.action.rx_queue = res->queue_id;
8277         entry.soft_id = res->fd_id_value;
8278         if (!strcmp(res->ops, "add"))
8279                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8280                                              RTE_ETH_FILTER_ADD, &entry);
8281         else if (!strcmp(res->ops, "del"))
8282                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8283                                              RTE_ETH_FILTER_DELETE, &entry);
8284         else
8285                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8286                                              RTE_ETH_FILTER_UPDATE, &entry);
8287         if (ret < 0)
8288                 printf("flow director programming error: (%s)\n",
8289                         strerror(-ret));
8290 }
8291
8292 cmdline_parse_token_string_t cmd_flow_director_filter =
8293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8294                                  flow_director_filter, "flow_director_filter");
8295 cmdline_parse_token_num_t cmd_flow_director_port_id =
8296         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8297                               port_id, UINT8);
8298 cmdline_parse_token_string_t cmd_flow_director_ops =
8299         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8300                                  ops, "add#del#update");
8301 cmdline_parse_token_string_t cmd_flow_director_flow =
8302         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8303                                  flow, "flow");
8304 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8305         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8306                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8307                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8308 cmdline_parse_token_string_t cmd_flow_director_ether =
8309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8310                                  ether, "ether");
8311 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8312         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8313                               ether_type, UINT16);
8314 cmdline_parse_token_string_t cmd_flow_director_src =
8315         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8316                                  src, "src");
8317 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8318         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8319                                  ip_src);
8320 cmdline_parse_token_num_t cmd_flow_director_port_src =
8321         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8322                               port_src, UINT16);
8323 cmdline_parse_token_string_t cmd_flow_director_dst =
8324         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8325                                  dst, "dst");
8326 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8327         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8328                                  ip_dst);
8329 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8330         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8331                               port_dst, UINT16);
8332 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8334                                   verify_tag, "verify_tag");
8335 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8336         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8337                               verify_tag_value, UINT32);
8338 cmdline_parse_token_string_t cmd_flow_director_vlan =
8339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8340                                  vlan, "vlan");
8341 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8342         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8343                               vlan_value, UINT16);
8344 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8346                                  flexbytes, "flexbytes");
8347 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8349                               flexbytes_value, NULL);
8350 cmdline_parse_token_string_t cmd_flow_director_drop =
8351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8352                                  drop, "drop#fwd");
8353 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8355                               pf_vf, NULL);
8356 cmdline_parse_token_string_t cmd_flow_director_queue =
8357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8358                                  queue, "queue");
8359 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8360         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8361                               queue_id, UINT16);
8362 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8364                                  fd_id, "fd_id");
8365 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8366         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8367                               fd_id_value, UINT32);
8368
8369 cmdline_parse_token_string_t cmd_flow_director_mode =
8370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8371                                  mode, "mode");
8372 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8373         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8374                                  mode_value, "IP");
8375 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8377                                  mode_value, "MAC-VLAN");
8378 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8380                                  mode_value, "Tunnel");
8381 cmdline_parse_token_string_t cmd_flow_director_mac =
8382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8383                                  mac, "mac");
8384 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8385         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8386                                     mac_addr);
8387 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8389                                  tunnel, "tunnel");
8390 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8392                                  tunnel_type, "NVGRE#VxLAN");
8393 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8395                                  tunnel_id, "tunnel-id");
8396 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8397         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8398                               tunnel_id_value, UINT32);
8399
8400 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8401         .f = cmd_flow_director_filter_parsed,
8402         .data = NULL,
8403         .help_str = "add or delete an ip flow director entry on NIC",
8404         .tokens = {
8405                 (void *)&cmd_flow_director_filter,
8406                 (void *)&cmd_flow_director_port_id,
8407                 (void *)&cmd_flow_director_mode,
8408                 (void *)&cmd_flow_director_mode_ip,
8409                 (void *)&cmd_flow_director_ops,
8410                 (void *)&cmd_flow_director_flow,
8411                 (void *)&cmd_flow_director_flow_type,
8412                 (void *)&cmd_flow_director_src,
8413                 (void *)&cmd_flow_director_ip_src,
8414                 (void *)&cmd_flow_director_dst,
8415                 (void *)&cmd_flow_director_ip_dst,
8416                 (void *)&cmd_flow_director_vlan,
8417                 (void *)&cmd_flow_director_vlan_value,
8418                 (void *)&cmd_flow_director_flexbytes,
8419                 (void *)&cmd_flow_director_flexbytes_value,
8420                 (void *)&cmd_flow_director_drop,
8421                 (void *)&cmd_flow_director_pf_vf,
8422                 (void *)&cmd_flow_director_queue,
8423                 (void *)&cmd_flow_director_queue_id,
8424                 (void *)&cmd_flow_director_fd_id,
8425                 (void *)&cmd_flow_director_fd_id_value,
8426                 NULL,
8427         },
8428 };
8429
8430 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8431         .f = cmd_flow_director_filter_parsed,
8432         .data = NULL,
8433         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8434         .tokens = {
8435                 (void *)&cmd_flow_director_filter,
8436                 (void *)&cmd_flow_director_port_id,
8437                 (void *)&cmd_flow_director_mode,
8438                 (void *)&cmd_flow_director_mode_ip,
8439                 (void *)&cmd_flow_director_ops,
8440                 (void *)&cmd_flow_director_flow,
8441                 (void *)&cmd_flow_director_flow_type,
8442                 (void *)&cmd_flow_director_src,
8443                 (void *)&cmd_flow_director_ip_src,
8444                 (void *)&cmd_flow_director_port_src,
8445                 (void *)&cmd_flow_director_dst,
8446                 (void *)&cmd_flow_director_ip_dst,
8447                 (void *)&cmd_flow_director_port_dst,
8448                 (void *)&cmd_flow_director_vlan,
8449                 (void *)&cmd_flow_director_vlan_value,
8450                 (void *)&cmd_flow_director_flexbytes,
8451                 (void *)&cmd_flow_director_flexbytes_value,
8452                 (void *)&cmd_flow_director_drop,
8453                 (void *)&cmd_flow_director_pf_vf,
8454                 (void *)&cmd_flow_director_queue,
8455                 (void *)&cmd_flow_director_queue_id,
8456                 (void *)&cmd_flow_director_fd_id,
8457                 (void *)&cmd_flow_director_fd_id_value,
8458                 NULL,
8459         },
8460 };
8461
8462 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8463         .f = cmd_flow_director_filter_parsed,
8464         .data = NULL,
8465         .help_str = "add or delete a sctp flow director entry on NIC",
8466         .tokens = {
8467                 (void *)&cmd_flow_director_filter,
8468                 (void *)&cmd_flow_director_port_id,
8469                 (void *)&cmd_flow_director_mode,
8470                 (void *)&cmd_flow_director_mode_ip,
8471                 (void *)&cmd_flow_director_ops,
8472                 (void *)&cmd_flow_director_flow,
8473                 (void *)&cmd_flow_director_flow_type,
8474                 (void *)&cmd_flow_director_src,
8475                 (void *)&cmd_flow_director_ip_src,
8476                 (void *)&cmd_flow_director_port_dst,
8477                 (void *)&cmd_flow_director_dst,
8478                 (void *)&cmd_flow_director_ip_dst,
8479                 (void *)&cmd_flow_director_port_dst,
8480                 (void *)&cmd_flow_director_verify_tag,
8481                 (void *)&cmd_flow_director_verify_tag_value,
8482                 (void *)&cmd_flow_director_vlan,
8483                 (void *)&cmd_flow_director_vlan_value,
8484                 (void *)&cmd_flow_director_flexbytes,
8485                 (void *)&cmd_flow_director_flexbytes_value,
8486                 (void *)&cmd_flow_director_drop,
8487                 (void *)&cmd_flow_director_pf_vf,
8488                 (void *)&cmd_flow_director_queue,
8489                 (void *)&cmd_flow_director_queue_id,
8490                 (void *)&cmd_flow_director_fd_id,
8491                 (void *)&cmd_flow_director_fd_id_value,
8492                 NULL,
8493         },
8494 };
8495
8496 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
8497         .f = cmd_flow_director_filter_parsed,
8498         .data = NULL,
8499         .help_str = "add or delete a L2 flow director entry on NIC",
8500         .tokens = {
8501                 (void *)&cmd_flow_director_filter,
8502                 (void *)&cmd_flow_director_port_id,
8503                 (void *)&cmd_flow_director_mode,
8504                 (void *)&cmd_flow_director_mode_ip,
8505                 (void *)&cmd_flow_director_ops,
8506                 (void *)&cmd_flow_director_flow,
8507                 (void *)&cmd_flow_director_flow_type,
8508                 (void *)&cmd_flow_director_ether,
8509                 (void *)&cmd_flow_director_ether_type,
8510                 (void *)&cmd_flow_director_flexbytes,
8511                 (void *)&cmd_flow_director_flexbytes_value,
8512                 (void *)&cmd_flow_director_drop,
8513                 (void *)&cmd_flow_director_pf_vf,
8514                 (void *)&cmd_flow_director_queue,
8515                 (void *)&cmd_flow_director_queue_id,
8516                 (void *)&cmd_flow_director_fd_id,
8517                 (void *)&cmd_flow_director_fd_id_value,
8518                 NULL,
8519         },
8520 };
8521
8522 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
8523         .f = cmd_flow_director_filter_parsed,
8524         .data = NULL,
8525         .help_str = "add or delete a MAC VLAN flow director entry on NIC",
8526         .tokens = {
8527                 (void *)&cmd_flow_director_filter,
8528                 (void *)&cmd_flow_director_port_id,
8529                 (void *)&cmd_flow_director_mode,
8530                 (void *)&cmd_flow_director_mode_mac_vlan,
8531                 (void *)&cmd_flow_director_ops,
8532                 (void *)&cmd_flow_director_mac,
8533                 (void *)&cmd_flow_director_mac_addr,
8534                 (void *)&cmd_flow_director_vlan,
8535                 (void *)&cmd_flow_director_vlan_value,
8536                 (void *)&cmd_flow_director_flexbytes,
8537                 (void *)&cmd_flow_director_flexbytes_value,
8538                 (void *)&cmd_flow_director_drop,
8539                 (void *)&cmd_flow_director_queue,
8540                 (void *)&cmd_flow_director_queue_id,
8541                 (void *)&cmd_flow_director_fd_id,
8542                 (void *)&cmd_flow_director_fd_id_value,
8543                 NULL,
8544         },
8545 };
8546
8547 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
8548         .f = cmd_flow_director_filter_parsed,
8549         .data = NULL,
8550         .help_str = "add or delete a tunnel flow director entry on NIC",
8551         .tokens = {
8552                 (void *)&cmd_flow_director_filter,
8553                 (void *)&cmd_flow_director_port_id,
8554                 (void *)&cmd_flow_director_mode,
8555                 (void *)&cmd_flow_director_mode_tunnel,
8556                 (void *)&cmd_flow_director_ops,
8557                 (void *)&cmd_flow_director_mac,
8558                 (void *)&cmd_flow_director_mac_addr,
8559                 (void *)&cmd_flow_director_vlan,
8560                 (void *)&cmd_flow_director_vlan_value,
8561                 (void *)&cmd_flow_director_tunnel,
8562                 (void *)&cmd_flow_director_tunnel_type,
8563                 (void *)&cmd_flow_director_tunnel_id,
8564                 (void *)&cmd_flow_director_tunnel_id_value,
8565                 (void *)&cmd_flow_director_flexbytes,
8566                 (void *)&cmd_flow_director_flexbytes_value,
8567                 (void *)&cmd_flow_director_drop,
8568                 (void *)&cmd_flow_director_queue,
8569                 (void *)&cmd_flow_director_queue_id,
8570                 (void *)&cmd_flow_director_fd_id,
8571                 (void *)&cmd_flow_director_fd_id_value,
8572                 NULL,
8573         },
8574 };
8575
8576 struct cmd_flush_flow_director_result {
8577         cmdline_fixed_string_t flush_flow_director;
8578         uint8_t port_id;
8579 };
8580
8581 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8582         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8583                                  flush_flow_director, "flush_flow_director");
8584 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8585         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8586                               port_id, UINT8);
8587
8588 static void
8589 cmd_flush_flow_director_parsed(void *parsed_result,
8590                           __attribute__((unused)) struct cmdline *cl,
8591                           __attribute__((unused)) void *data)
8592 {
8593         struct cmd_flow_director_result *res = parsed_result;
8594         int ret = 0;
8595
8596         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8597         if (ret < 0) {
8598                 printf("flow director is not supported on port %u.\n",
8599                         res->port_id);
8600                 return;
8601         }
8602
8603         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8604                         RTE_ETH_FILTER_FLUSH, NULL);
8605         if (ret < 0)
8606                 printf("flow director table flushing error: (%s)\n",
8607                         strerror(-ret));
8608 }
8609
8610 cmdline_parse_inst_t cmd_flush_flow_director = {
8611         .f = cmd_flush_flow_director_parsed,
8612         .data = NULL,
8613         .help_str = "flush all flow director entries of a device on NIC",
8614         .tokens = {
8615                 (void *)&cmd_flush_flow_director_flush,
8616                 (void *)&cmd_flush_flow_director_port_id,
8617                 NULL,
8618         },
8619 };
8620
8621 /* *** deal with flow director mask *** */
8622 struct cmd_flow_director_mask_result {
8623         cmdline_fixed_string_t flow_director_mask;
8624         uint8_t port_id;
8625         cmdline_fixed_string_t mode;
8626         cmdline_fixed_string_t mode_value;
8627         cmdline_fixed_string_t vlan;
8628         uint16_t vlan_mask;
8629         cmdline_fixed_string_t src_mask;
8630         cmdline_ipaddr_t ipv4_src;
8631         cmdline_ipaddr_t ipv6_src;
8632         uint16_t port_src;
8633         cmdline_fixed_string_t dst_mask;
8634         cmdline_ipaddr_t ipv4_dst;
8635         cmdline_ipaddr_t ipv6_dst;
8636         uint16_t port_dst;
8637         cmdline_fixed_string_t mac;
8638         uint8_t mac_addr_byte_mask;
8639         cmdline_fixed_string_t tunnel_id;
8640         uint32_t tunnel_id_mask;
8641         cmdline_fixed_string_t tunnel_type;
8642         uint8_t tunnel_type_mask;
8643 };
8644
8645 static void
8646 cmd_flow_director_mask_parsed(void *parsed_result,
8647                           __attribute__((unused)) struct cmdline *cl,
8648                           __attribute__((unused)) void *data)
8649 {
8650         struct cmd_flow_director_mask_result *res = parsed_result;
8651         struct rte_eth_fdir_masks *mask;
8652         struct rte_port *port;
8653
8654         if (res->port_id > nb_ports) {
8655                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8656                 return;
8657         }
8658
8659         port = &ports[res->port_id];
8660         /** Check if the port is not started **/
8661         if (port->port_status != RTE_PORT_STOPPED) {
8662                 printf("Please stop port %d first\n", res->port_id);
8663                 return;
8664         }
8665
8666         mask = &port->dev_conf.fdir_conf.mask;
8667
8668         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8669                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8670                         printf("Please set mode to MAC-VLAN.\n");
8671                         return;
8672                 }
8673
8674                 mask->vlan_tci_mask = res->vlan_mask;
8675                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8676         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8677                 if (strcmp(res->mode_value, "Tunnel")) {
8678                         printf("Please set mode to Tunnel.\n");
8679                         return;
8680                 }
8681
8682                 mask->vlan_tci_mask = res->vlan_mask;
8683                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8684                 mask->tunnel_id_mask = res->tunnel_id_mask;
8685                 mask->tunnel_type_mask = res->tunnel_type_mask;
8686         } else {
8687                 if (strcmp(res->mode_value, "IP")) {
8688                         printf("Please set mode to IP.\n");
8689                         return;
8690                 }
8691
8692                 mask->vlan_tci_mask = res->vlan_mask;
8693                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
8694                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
8695                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
8696                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
8697                 mask->src_port_mask = res->port_src;
8698                 mask->dst_port_mask = res->port_dst;
8699         }
8700
8701         cmd_reconfig_device_queue(res->port_id, 1, 1);
8702 }
8703
8704 cmdline_parse_token_string_t cmd_flow_director_mask =
8705         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8706                                  flow_director_mask, "flow_director_mask");
8707 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
8708         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8709                               port_id, UINT8);
8710 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
8711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8712                                  vlan, "vlan");
8713 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
8714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8715                               vlan_mask, UINT16);
8716 cmdline_parse_token_string_t cmd_flow_director_mask_src =
8717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8718                                  src_mask, "src_mask");
8719 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
8720         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8721                                  ipv4_src);
8722 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
8723         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8724                                  ipv6_src);
8725 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
8726         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8727                               port_src, UINT16);
8728 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
8729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8730                                  dst_mask, "dst_mask");
8731 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
8732         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8733                                  ipv4_dst);
8734 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
8735         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8736                                  ipv6_dst);
8737 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
8738         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8739                               port_dst, UINT16);
8740
8741 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
8742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8743                                  mode, "mode");
8744 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
8745         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8746                                  mode_value, "IP");
8747 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
8748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8749                                  mode_value, "MAC-VLAN");
8750 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
8751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8752                                  mode_value, "Tunnel");
8753 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
8754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8755                                  mac, "mac");
8756 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
8757         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8758                               mac_addr_byte_mask, UINT8);
8759 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
8760         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8761                                  tunnel_type, "tunnel-type");
8762 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
8763         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8764                               tunnel_type_mask, UINT8);
8765 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
8766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8767                                  tunnel_id, "tunnel-id");
8768 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
8769         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8770                               tunnel_id_mask, UINT32);
8771
8772 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
8773         .f = cmd_flow_director_mask_parsed,
8774         .data = NULL,
8775         .help_str = "set IP mode flow director's mask on NIC",
8776         .tokens = {
8777                 (void *)&cmd_flow_director_mask,
8778                 (void *)&cmd_flow_director_mask_port_id,
8779                 (void *)&cmd_flow_director_mask_mode,
8780                 (void *)&cmd_flow_director_mask_mode_ip,
8781                 (void *)&cmd_flow_director_mask_vlan,
8782                 (void *)&cmd_flow_director_mask_vlan_value,
8783                 (void *)&cmd_flow_director_mask_src,
8784                 (void *)&cmd_flow_director_mask_ipv4_src,
8785                 (void *)&cmd_flow_director_mask_ipv6_src,
8786                 (void *)&cmd_flow_director_mask_port_src,
8787                 (void *)&cmd_flow_director_mask_dst,
8788                 (void *)&cmd_flow_director_mask_ipv4_dst,
8789                 (void *)&cmd_flow_director_mask_ipv6_dst,
8790                 (void *)&cmd_flow_director_mask_port_dst,
8791                 NULL,
8792         },
8793 };
8794
8795 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
8796         .f = cmd_flow_director_mask_parsed,
8797         .data = NULL,
8798         .help_str = "set MAC VLAN mode flow director's mask on NIC",
8799         .tokens = {
8800                 (void *)&cmd_flow_director_mask,
8801                 (void *)&cmd_flow_director_mask_port_id,
8802                 (void *)&cmd_flow_director_mask_mode,
8803                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
8804                 (void *)&cmd_flow_director_mask_vlan,
8805                 (void *)&cmd_flow_director_mask_vlan_value,
8806                 (void *)&cmd_flow_director_mask_mac,
8807                 (void *)&cmd_flow_director_mask_mac_value,
8808                 NULL,
8809         },
8810 };
8811
8812 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
8813         .f = cmd_flow_director_mask_parsed,
8814         .data = NULL,
8815         .help_str = "set tunnel mode flow director's mask on NIC",
8816         .tokens = {
8817                 (void *)&cmd_flow_director_mask,
8818                 (void *)&cmd_flow_director_mask_port_id,
8819                 (void *)&cmd_flow_director_mask_mode,
8820                 (void *)&cmd_flow_director_mask_mode_tunnel,
8821                 (void *)&cmd_flow_director_mask_vlan,
8822                 (void *)&cmd_flow_director_mask_vlan_value,
8823                 (void *)&cmd_flow_director_mask_mac,
8824                 (void *)&cmd_flow_director_mask_mac_value,
8825                 (void *)&cmd_flow_director_mask_tunnel_type,
8826                 (void *)&cmd_flow_director_mask_tunnel_type_value,
8827                 (void *)&cmd_flow_director_mask_tunnel_id,
8828                 (void *)&cmd_flow_director_mask_tunnel_id_value,
8829                 NULL,
8830         },
8831 };
8832
8833 /* *** deal with flow director mask on flexible payload *** */
8834 struct cmd_flow_director_flex_mask_result {
8835         cmdline_fixed_string_t flow_director_flexmask;
8836         uint8_t port_id;
8837         cmdline_fixed_string_t flow;
8838         cmdline_fixed_string_t flow_type;
8839         cmdline_fixed_string_t mask;
8840 };
8841
8842 static void
8843 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8844                           __attribute__((unused)) struct cmdline *cl,
8845                           __attribute__((unused)) void *data)
8846 {
8847         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8848         struct rte_eth_fdir_info fdir_info;
8849         struct rte_eth_fdir_flex_mask flex_mask;
8850         struct rte_port *port;
8851         uint32_t flow_type_mask;
8852         uint16_t i;
8853         int ret;
8854
8855         if (res->port_id > nb_ports) {
8856                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8857                 return;
8858         }
8859
8860         port = &ports[res->port_id];
8861         /** Check if the port is not started **/
8862         if (port->port_status != RTE_PORT_STOPPED) {
8863                 printf("Please stop port %d first\n", res->port_id);
8864                 return;
8865         }
8866
8867         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8868         ret = parse_flexbytes(res->mask,
8869                         flex_mask.mask,
8870                         RTE_ETH_FDIR_MAX_FLEXLEN);
8871         if (ret < 0) {
8872                 printf("error: Cannot parse mask input.\n");
8873                 return;
8874         }
8875
8876         memset(&fdir_info, 0, sizeof(fdir_info));
8877         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8878                                 RTE_ETH_FILTER_INFO, &fdir_info);
8879         if (ret < 0) {
8880                 printf("Cannot get FDir filter info\n");
8881                 return;
8882         }
8883
8884         if (!strcmp(res->flow_type, "none")) {
8885                 /* means don't specify the flow type */
8886                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
8887                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
8888                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
8889                                0, sizeof(struct rte_eth_fdir_flex_mask));
8890                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
8891                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
8892                                  &flex_mask,
8893                                  sizeof(struct rte_eth_fdir_flex_mask));
8894                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8895                 return;
8896         }
8897         flow_type_mask = fdir_info.flow_types_mask[0];
8898         if (!strcmp(res->flow_type, "all")) {
8899                 if (!flow_type_mask) {
8900                         printf("No flow type supported\n");
8901                         return;
8902                 }
8903                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
8904                         if (flow_type_mask & (1 << i)) {
8905                                 flex_mask.flow_type = i;
8906                                 fdir_set_flex_mask(res->port_id, &flex_mask);
8907                         }
8908                 }
8909                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8910                 return;
8911         }
8912         flex_mask.flow_type = str2flowtype(res->flow_type);
8913         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
8914                 printf("Flow type %s not supported on port %d\n",
8915                                 res->flow_type, res->port_id);
8916                 return;
8917         }
8918         fdir_set_flex_mask(res->port_id, &flex_mask);
8919         cmd_reconfig_device_queue(res->port_id, 1, 1);
8920 }
8921
8922 cmdline_parse_token_string_t cmd_flow_director_flexmask =
8923         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8924                                  flow_director_flexmask,
8925                                  "flow_director_flex_mask");
8926 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
8927         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8928                               port_id, UINT8);
8929 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
8930         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8931                                  flow, "flow");
8932 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
8933         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8934                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8935                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
8936 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
8937         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8938                                  mask, NULL);
8939
8940 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
8941         .f = cmd_flow_director_flex_mask_parsed,
8942         .data = NULL,
8943         .help_str = "set flow director's flex mask on NIC",
8944         .tokens = {
8945                 (void *)&cmd_flow_director_flexmask,
8946                 (void *)&cmd_flow_director_flexmask_port_id,
8947                 (void *)&cmd_flow_director_flexmask_flow,
8948                 (void *)&cmd_flow_director_flexmask_flow_type,
8949                 (void *)&cmd_flow_director_flexmask_mask,
8950                 NULL,
8951         },
8952 };
8953
8954 /* *** deal with flow director flexible payload configuration *** */
8955 struct cmd_flow_director_flexpayload_result {
8956         cmdline_fixed_string_t flow_director_flexpayload;
8957         uint8_t port_id;
8958         cmdline_fixed_string_t payload_layer;
8959         cmdline_fixed_string_t payload_cfg;
8960 };
8961
8962 static inline int
8963 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
8964 {
8965         char s[256];
8966         const char *p, *p0 = q_arg;
8967         char *end;
8968         unsigned long int_fld;
8969         char *str_fld[max_num];
8970         int i;
8971         unsigned size;
8972         int ret = -1;
8973
8974         p = strchr(p0, '(');
8975         if (p == NULL)
8976                 return -1;
8977         ++p;
8978         p0 = strchr(p, ')');
8979         if (p0 == NULL)
8980                 return -1;
8981
8982         size = p0 - p;
8983         if (size >= sizeof(s))
8984                 return -1;
8985
8986         snprintf(s, sizeof(s), "%.*s", size, p);
8987         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8988         if (ret < 0 || ret > max_num)
8989                 return -1;
8990         for (i = 0; i < ret; i++) {
8991                 errno = 0;
8992                 int_fld = strtoul(str_fld[i], &end, 0);
8993                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
8994                         return -1;
8995                 offsets[i] = (uint16_t)int_fld;
8996         }
8997         return ret;
8998 }
8999
9000 static void
9001 cmd_flow_director_flxpld_parsed(void *parsed_result,
9002                           __attribute__((unused)) struct cmdline *cl,
9003                           __attribute__((unused)) void *data)
9004 {
9005         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9006         struct rte_eth_flex_payload_cfg flex_cfg;
9007         struct rte_port *port;
9008         int ret = 0;
9009
9010         if (res->port_id > nb_ports) {
9011                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9012                 return;
9013         }
9014
9015         port = &ports[res->port_id];
9016         /** Check if the port is not started **/
9017         if (port->port_status != RTE_PORT_STOPPED) {
9018                 printf("Please stop port %d first\n", res->port_id);
9019                 return;
9020         }
9021
9022         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9023
9024         if (!strcmp(res->payload_layer, "raw"))
9025                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9026         else if (!strcmp(res->payload_layer, "l2"))
9027                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9028         else if (!strcmp(res->payload_layer, "l3"))
9029                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9030         else if (!strcmp(res->payload_layer, "l4"))
9031                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9032
9033         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9034                             RTE_ETH_FDIR_MAX_FLEXLEN);
9035         if (ret < 0) {
9036                 printf("error: Cannot parse flex payload input.\n");
9037                 return;
9038         }
9039
9040         fdir_set_flex_payload(res->port_id, &flex_cfg);
9041         cmd_reconfig_device_queue(res->port_id, 1, 1);
9042 }
9043
9044 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9046                                  flow_director_flexpayload,
9047                                  "flow_director_flex_payload");
9048 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9049         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9050                               port_id, UINT8);
9051 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9052         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9053                                  payload_layer, "raw#l2#l3#l4");
9054 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9055         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9056                                  payload_cfg, NULL);
9057
9058 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9059         .f = cmd_flow_director_flxpld_parsed,
9060         .data = NULL,
9061         .help_str = "set flow director's flex payload on NIC",
9062         .tokens = {
9063                 (void *)&cmd_flow_director_flexpayload,
9064                 (void *)&cmd_flow_director_flexpayload_port_id,
9065                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9066                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9067                 NULL,
9068         },
9069 };
9070
9071 /* *** Classification Filters Control *** */
9072 /* *** Get symmetric hash enable per port *** */
9073 struct cmd_get_sym_hash_ena_per_port_result {
9074         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9075         uint8_t port_id;
9076 };
9077
9078 static void
9079 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9080                                  __rte_unused struct cmdline *cl,
9081                                  __rte_unused void *data)
9082 {
9083         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9084         struct rte_eth_hash_filter_info info;
9085         int ret;
9086
9087         if (rte_eth_dev_filter_supported(res->port_id,
9088                                 RTE_ETH_FILTER_HASH) < 0) {
9089                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9090                                                         res->port_id);
9091                 return;
9092         }
9093
9094         memset(&info, 0, sizeof(info));
9095         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9096         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9097                                                 RTE_ETH_FILTER_GET, &info);
9098
9099         if (ret < 0) {
9100                 printf("Cannot get symmetric hash enable per port "
9101                                         "on port %u\n", res->port_id);
9102                 return;
9103         }
9104
9105         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9106                                 "enabled" : "disabled", res->port_id);
9107 }
9108
9109 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9110         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9111                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9112 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9113         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9114                 port_id, UINT8);
9115
9116 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9117         .f = cmd_get_sym_hash_per_port_parsed,
9118         .data = NULL,
9119         .help_str = "get_sym_hash_ena_per_port port_id",
9120         .tokens = {
9121                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9122                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9123                 NULL,
9124         },
9125 };
9126
9127 /* *** Set symmetric hash enable per port *** */
9128 struct cmd_set_sym_hash_ena_per_port_result {
9129         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9130         cmdline_fixed_string_t enable;
9131         uint8_t port_id;
9132 };
9133
9134 static void
9135 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9136                                  __rte_unused struct cmdline *cl,
9137                                  __rte_unused void *data)
9138 {
9139         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9140         struct rte_eth_hash_filter_info info;
9141         int ret;
9142
9143         if (rte_eth_dev_filter_supported(res->port_id,
9144                                 RTE_ETH_FILTER_HASH) < 0) {
9145                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9146                                                         res->port_id);
9147                 return;
9148         }
9149
9150         memset(&info, 0, sizeof(info));
9151         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9152         if (!strcmp(res->enable, "enable"))
9153                 info.info.enable = 1;
9154         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9155                                         RTE_ETH_FILTER_SET, &info);
9156         if (ret < 0) {
9157                 printf("Cannot set symmetric hash enable per port on "
9158                                         "port %u\n", res->port_id);
9159                 return;
9160         }
9161         printf("Symmetric hash has been set to %s on port %u\n",
9162                                         res->enable, res->port_id);
9163 }
9164
9165 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9166         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9167                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9168 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9169         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9170                 port_id, UINT8);
9171 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9172         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9173                 enable, "enable#disable");
9174
9175 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9176         .f = cmd_set_sym_hash_per_port_parsed,
9177         .data = NULL,
9178         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
9179         .tokens = {
9180                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9181                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9182                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9183                 NULL,
9184         },
9185 };
9186
9187 /* Get global config of hash function */
9188 struct cmd_get_hash_global_config_result {
9189         cmdline_fixed_string_t get_hash_global_config;
9190         uint8_t port_id;
9191 };
9192
9193 static char *
9194 flowtype_to_str(uint16_t ftype)
9195 {
9196         uint16_t i;
9197         static struct {
9198                 char str[16];
9199                 uint16_t ftype;
9200         } ftype_table[] = {
9201                 {"ipv4", RTE_ETH_FLOW_IPV4},
9202                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9203                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9204                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9205                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9206                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9207                 {"ipv6", RTE_ETH_FLOW_IPV6},
9208                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9209                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9210                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9211                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9212                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9213                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9214         };
9215
9216         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9217                 if (ftype_table[i].ftype == ftype)
9218                         return ftype_table[i].str;
9219         }
9220
9221         return NULL;
9222 }
9223
9224 static void
9225 cmd_get_hash_global_config_parsed(void *parsed_result,
9226                                   __rte_unused struct cmdline *cl,
9227                                   __rte_unused void *data)
9228 {
9229         struct cmd_get_hash_global_config_result *res = parsed_result;
9230         struct rte_eth_hash_filter_info info;
9231         uint32_t idx, offset;
9232         uint16_t i;
9233         char *str;
9234         int ret;
9235
9236         if (rte_eth_dev_filter_supported(res->port_id,
9237                         RTE_ETH_FILTER_HASH) < 0) {
9238                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9239                                                         res->port_id);
9240                 return;
9241         }
9242
9243         memset(&info, 0, sizeof(info));
9244         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9245         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9246                                         RTE_ETH_FILTER_GET, &info);
9247         if (ret < 0) {
9248                 printf("Cannot get hash global configurations by port %d\n",
9249                                                         res->port_id);
9250                 return;
9251         }
9252
9253         switch (info.info.global_conf.hash_func) {
9254         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9255                 printf("Hash function is Toeplitz\n");
9256                 break;
9257         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9258                 printf("Hash function is Simple XOR\n");
9259                 break;
9260         default:
9261                 printf("Unknown hash function\n");
9262                 break;
9263         }
9264
9265         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9266                 idx = i / UINT32_BIT;
9267                 offset = i % UINT32_BIT;
9268                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9269                                                 (1UL << offset)))
9270                         continue;
9271                 str = flowtype_to_str(i);
9272                 if (!str)
9273                         continue;
9274                 printf("Symmetric hash is %s globally for flow type %s "
9275                                                         "by port %d\n",
9276                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9277                         (1UL << offset)) ? "enabled" : "disabled"), str,
9278                                                         res->port_id);
9279         }
9280 }
9281
9282 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9283         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9284                 get_hash_global_config, "get_hash_global_config");
9285 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9286         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9287                 port_id, UINT8);
9288
9289 cmdline_parse_inst_t cmd_get_hash_global_config = {
9290         .f = cmd_get_hash_global_config_parsed,
9291         .data = NULL,
9292         .help_str = "get_hash_global_config port_id",
9293         .tokens = {
9294                 (void *)&cmd_get_hash_global_config_all,
9295                 (void *)&cmd_get_hash_global_config_port_id,
9296                 NULL,
9297         },
9298 };
9299
9300 /* Set global config of hash function */
9301 struct cmd_set_hash_global_config_result {
9302         cmdline_fixed_string_t set_hash_global_config;
9303         uint8_t port_id;
9304         cmdline_fixed_string_t hash_func;
9305         cmdline_fixed_string_t flow_type;
9306         cmdline_fixed_string_t enable;
9307 };
9308
9309 static void
9310 cmd_set_hash_global_config_parsed(void *parsed_result,
9311                                   __rte_unused struct cmdline *cl,
9312                                   __rte_unused void *data)
9313 {
9314         struct cmd_set_hash_global_config_result *res = parsed_result;
9315         struct rte_eth_hash_filter_info info;
9316         uint32_t ftype, idx, offset;
9317         int ret;
9318
9319         if (rte_eth_dev_filter_supported(res->port_id,
9320                                 RTE_ETH_FILTER_HASH) < 0) {
9321                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9322                                                         res->port_id);
9323                 return;
9324         }
9325         memset(&info, 0, sizeof(info));
9326         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9327         if (!strcmp(res->hash_func, "toeplitz"))
9328                 info.info.global_conf.hash_func =
9329                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9330         else if (!strcmp(res->hash_func, "simple_xor"))
9331                 info.info.global_conf.hash_func =
9332                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9333         else if (!strcmp(res->hash_func, "default"))
9334                 info.info.global_conf.hash_func =
9335                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9336
9337         ftype = str2flowtype(res->flow_type);
9338         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9339         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9340         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9341         if (!strcmp(res->enable, "enable"))
9342                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9343                                                 (1UL << offset);
9344         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9345                                         RTE_ETH_FILTER_SET, &info);
9346         if (ret < 0)
9347                 printf("Cannot set global hash configurations by port %d\n",
9348                                                         res->port_id);
9349         else
9350                 printf("Global hash configurations have been set "
9351                         "succcessfully by port %d\n", res->port_id);
9352 }
9353
9354 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9355         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9356                 set_hash_global_config, "set_hash_global_config");
9357 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9358         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9359                 port_id, UINT8);
9360 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9361         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9362                 hash_func, "toeplitz#simple_xor#default");
9363 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9364         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9365                 flow_type,
9366                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9367                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9368 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9370                 enable, "enable#disable");
9371
9372 cmdline_parse_inst_t cmd_set_hash_global_config = {
9373         .f = cmd_set_hash_global_config_parsed,
9374         .data = NULL,
9375         .help_str = "set_hash_global_config port_id "
9376                 "toeplitz|simple_xor|default "
9377                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
9378                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9379                 "enable|disable",
9380         .tokens = {
9381                 (void *)&cmd_set_hash_global_config_all,
9382                 (void *)&cmd_set_hash_global_config_port_id,
9383                 (void *)&cmd_set_hash_global_config_hash_func,
9384                 (void *)&cmd_set_hash_global_config_flow_type,
9385                 (void *)&cmd_set_hash_global_config_enable,
9386                 NULL,
9387         },
9388 };
9389
9390 /* Set hash input set */
9391 struct cmd_set_hash_input_set_result {
9392         cmdline_fixed_string_t set_hash_input_set;
9393         uint8_t port_id;
9394         cmdline_fixed_string_t flow_type;
9395         cmdline_fixed_string_t inset_field;
9396         cmdline_fixed_string_t select;
9397 };
9398
9399 static enum rte_eth_input_set_field
9400 str2inset(char *string)
9401 {
9402         uint16_t i;
9403
9404         static const struct {
9405                 char str[32];
9406                 enum rte_eth_input_set_field inset;
9407         } inset_table[] = {
9408                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9409                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9410                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9411                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9412                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9413                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9414                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9415                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9416                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9417                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9418                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9419                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9420                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9421                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9422                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9423                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9424                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9425                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9426                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9427                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9428                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9429                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9430                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9431                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9432                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9433                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9434                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9435                 {"none", RTE_ETH_INPUT_SET_NONE},
9436         };
9437
9438         for (i = 0; i < RTE_DIM(inset_table); i++) {
9439                 if (!strcmp(string, inset_table[i].str))
9440                         return inset_table[i].inset;
9441         }
9442
9443         return RTE_ETH_INPUT_SET_UNKNOWN;
9444 }
9445
9446 static void
9447 cmd_set_hash_input_set_parsed(void *parsed_result,
9448                               __rte_unused struct cmdline *cl,
9449                               __rte_unused void *data)
9450 {
9451         struct cmd_set_hash_input_set_result *res = parsed_result;
9452         struct rte_eth_hash_filter_info info;
9453
9454         memset(&info, 0, sizeof(info));
9455         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
9456         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9457         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9458         info.info.input_set_conf.inset_size = 1;
9459         if (!strcmp(res->select, "select"))
9460                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9461         else if (!strcmp(res->select, "add"))
9462                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9463         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9464                                 RTE_ETH_FILTER_SET, &info);
9465 }
9466
9467 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
9468         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9469                 set_hash_input_set, "set_hash_input_set");
9470 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
9471         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
9472                 port_id, UINT8);
9473 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
9474         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9475                 flow_type,
9476                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9477                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9478 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
9479         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9480                 inset_field,
9481                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9482                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
9483                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
9484                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
9485                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
9486                 "fld-8th#none");
9487 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
9488         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9489                 select, "select#add");
9490
9491 cmdline_parse_inst_t cmd_set_hash_input_set = {
9492         .f = cmd_set_hash_input_set_parsed,
9493         .data = NULL,
9494         .help_str = "set_hash_input_set <port_id> "
9495         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9496         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9497         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
9498         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
9499         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
9500         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9501         "fld-7th|fld-8th|none select|add",
9502         .tokens = {
9503                 (void *)&cmd_set_hash_input_set_cmd,
9504                 (void *)&cmd_set_hash_input_set_port_id,
9505                 (void *)&cmd_set_hash_input_set_flow_type,
9506                 (void *)&cmd_set_hash_input_set_field,
9507                 (void *)&cmd_set_hash_input_set_select,
9508                 NULL,
9509         },
9510 };
9511
9512 /* Set flow director input set */
9513 struct cmd_set_fdir_input_set_result {
9514         cmdline_fixed_string_t set_fdir_input_set;
9515         uint8_t port_id;
9516         cmdline_fixed_string_t flow_type;
9517         cmdline_fixed_string_t inset_field;
9518         cmdline_fixed_string_t select;
9519 };
9520
9521 static void
9522 cmd_set_fdir_input_set_parsed(void *parsed_result,
9523         __rte_unused struct cmdline *cl,
9524         __rte_unused void *data)
9525 {
9526         struct cmd_set_fdir_input_set_result *res = parsed_result;
9527         struct rte_eth_fdir_filter_info info;
9528
9529         memset(&info, 0, sizeof(info));
9530         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
9531         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9532         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9533         info.info.input_set_conf.inset_size = 1;
9534         if (!strcmp(res->select, "select"))
9535                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9536         else if (!strcmp(res->select, "add"))
9537                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9538         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9539                 RTE_ETH_FILTER_SET, &info);
9540 }
9541
9542 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
9543         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9544         set_fdir_input_set, "set_fdir_input_set");
9545 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
9546         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
9547         port_id, UINT8);
9548 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
9549         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9550         flow_type,
9551         "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9552         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9553 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
9554         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9555         inset_field,
9556         "src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#udp-src-port#udp-dst-port#"
9557         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
9558         "sctp-veri-tag#fld-1st#fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#"
9559         "fld-7th#fld-8th#none");
9560 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
9561         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9562         select, "select#add");
9563
9564 cmdline_parse_inst_t cmd_set_fdir_input_set = {
9565         .f = cmd_set_fdir_input_set_parsed,
9566         .data = NULL,
9567         .help_str = "set_fdir_input_set <port_id> "
9568         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9569         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9570         "src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|udp-src-port|udp-dst-port|"
9571         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|"
9572         "fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9573         "fld-7th|fld-8th|none select|add",
9574         .tokens = {
9575                 (void *)&cmd_set_fdir_input_set_cmd,
9576                 (void *)&cmd_set_fdir_input_set_port_id,
9577                 (void *)&cmd_set_fdir_input_set_flow_type,
9578                 (void *)&cmd_set_fdir_input_set_field,
9579                 (void *)&cmd_set_fdir_input_set_select,
9580                 NULL,
9581         },
9582 };
9583
9584 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
9585 struct cmd_mcast_addr_result {
9586         cmdline_fixed_string_t mcast_addr_cmd;
9587         cmdline_fixed_string_t what;
9588         uint8_t port_num;
9589         struct ether_addr mc_addr;
9590 };
9591
9592 static void cmd_mcast_addr_parsed(void *parsed_result,
9593                 __attribute__((unused)) struct cmdline *cl,
9594                 __attribute__((unused)) void *data)
9595 {
9596         struct cmd_mcast_addr_result *res = parsed_result;
9597
9598         if (!is_multicast_ether_addr(&res->mc_addr)) {
9599                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
9600                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
9601                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
9602                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
9603                 return;
9604         }
9605         if (strcmp(res->what, "add") == 0)
9606                 mcast_addr_add(res->port_num, &res->mc_addr);
9607         else
9608                 mcast_addr_remove(res->port_num, &res->mc_addr);
9609 }
9610
9611 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
9612         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
9613                                  mcast_addr_cmd, "mcast_addr");
9614 cmdline_parse_token_string_t cmd_mcast_addr_what =
9615         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
9616                                  "add#remove");
9617 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
9618         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
9619 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
9620         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
9621
9622 cmdline_parse_inst_t cmd_mcast_addr = {
9623         .f = cmd_mcast_addr_parsed,
9624         .data = (void *)0,
9625         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
9626         .tokens = {
9627                 (void *)&cmd_mcast_addr_cmd,
9628                 (void *)&cmd_mcast_addr_what,
9629                 (void *)&cmd_mcast_addr_portnum,
9630                 (void *)&cmd_mcast_addr_addr,
9631                 NULL,
9632         },
9633 };
9634
9635 /* ******************************************************************************** */
9636
9637 /* list of instructions */
9638 cmdline_parse_ctx_t main_ctx[] = {
9639         (cmdline_parse_inst_t *)&cmd_help_brief,
9640         (cmdline_parse_inst_t *)&cmd_help_long,
9641         (cmdline_parse_inst_t *)&cmd_quit,
9642         (cmdline_parse_inst_t *)&cmd_showport,
9643         (cmdline_parse_inst_t *)&cmd_showqueue,
9644         (cmdline_parse_inst_t *)&cmd_showportall,
9645         (cmdline_parse_inst_t *)&cmd_showcfg,
9646         (cmdline_parse_inst_t *)&cmd_start,
9647         (cmdline_parse_inst_t *)&cmd_start_tx_first,
9648         (cmdline_parse_inst_t *)&cmd_set_link_up,
9649         (cmdline_parse_inst_t *)&cmd_set_link_down,
9650         (cmdline_parse_inst_t *)&cmd_reset,
9651         (cmdline_parse_inst_t *)&cmd_set_numbers,
9652         (cmdline_parse_inst_t *)&cmd_set_txpkts,
9653         (cmdline_parse_inst_t *)&cmd_set_txsplit,
9654         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
9655         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
9656         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
9657         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
9658         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
9659         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
9660         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
9661         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
9662         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
9663         (cmdline_parse_inst_t *)&cmd_set_link_check,
9664 #ifdef RTE_NIC_BYPASS
9665         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
9666         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
9667         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
9668         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
9669 #endif
9670 #ifdef RTE_LIBRTE_PMD_BOND
9671         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
9672         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
9673         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
9674         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
9675         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
9676         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
9677         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
9678         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
9679         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
9680 #endif
9681         (cmdline_parse_inst_t *)&cmd_vlan_offload,
9682         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
9683         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
9684         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
9685         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
9686         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
9687         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
9688         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
9689         (cmdline_parse_inst_t *)&cmd_csum_set,
9690         (cmdline_parse_inst_t *)&cmd_csum_show,
9691         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
9692         (cmdline_parse_inst_t *)&cmd_tso_set,
9693         (cmdline_parse_inst_t *)&cmd_tso_show,
9694         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
9695         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
9696         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
9697         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
9698         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
9699         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
9700         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
9701         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
9702         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
9703         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
9704         (cmdline_parse_inst_t *)&cmd_config_dcb,
9705         (cmdline_parse_inst_t *)&cmd_read_reg,
9706         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
9707         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
9708         (cmdline_parse_inst_t *)&cmd_write_reg,
9709         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
9710         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
9711         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
9712         (cmdline_parse_inst_t *)&cmd_stop,
9713         (cmdline_parse_inst_t *)&cmd_mac_addr,
9714         (cmdline_parse_inst_t *)&cmd_set_qmap,
9715         (cmdline_parse_inst_t *)&cmd_operate_port,
9716         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
9717         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
9718         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
9719         (cmdline_parse_inst_t *)&cmd_config_speed_all,
9720         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
9721         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
9722         (cmdline_parse_inst_t *)&cmd_config_mtu,
9723         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
9724         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
9725         (cmdline_parse_inst_t *)&cmd_config_rss,
9726         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
9727         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
9728         (cmdline_parse_inst_t *)&cmd_showport_reta,
9729         (cmdline_parse_inst_t *)&cmd_config_burst,
9730         (cmdline_parse_inst_t *)&cmd_config_thresh,
9731         (cmdline_parse_inst_t *)&cmd_config_threshold,
9732         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
9733         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
9734         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
9735         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
9736         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
9737         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
9738         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
9739         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
9740         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
9741         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
9742         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
9743         (cmdline_parse_inst_t *)&cmd_global_config,
9744         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
9745         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
9746         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
9747         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
9748         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
9749         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
9750         (cmdline_parse_inst_t *)&cmd_dump,
9751         (cmdline_parse_inst_t *)&cmd_dump_one,
9752         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
9753         (cmdline_parse_inst_t *)&cmd_syn_filter,
9754         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
9755         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
9756         (cmdline_parse_inst_t *)&cmd_flex_filter,
9757         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
9758         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
9759         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
9760         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
9761         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
9762         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
9763         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
9764         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
9765         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
9766         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
9767         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
9768         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
9769         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
9770         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
9771         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
9772         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
9773         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
9774         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
9775         (cmdline_parse_inst_t *)&cmd_mcast_addr,
9776         NULL,
9777 };
9778
9779 /* prompt function, called from main on MASTER lcore */
9780 void
9781 prompt(void)
9782 {
9783         /* initialize non-constant commands */
9784         cmd_set_fwd_mode_init();
9785
9786         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
9787         if (testpmd_cl == NULL)
9788                 return;
9789         cmdline_interact(testpmd_cl);
9790         cmdline_stdin_exit(testpmd_cl);
9791 }
9792
9793 void
9794 prompt_exit(void)
9795 {
9796         if (testpmd_cl != NULL)
9797                 cmdline_quit(testpmd_cl);
9798 }
9799
9800 static void
9801 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
9802 {
9803         if (id == (portid_t)RTE_PORT_ALL) {
9804                 portid_t pid;
9805
9806                 FOREACH_PORT(pid, ports) {
9807                         /* check if need_reconfig has been set to 1 */
9808                         if (ports[pid].need_reconfig == 0)
9809                                 ports[pid].need_reconfig = dev;
9810                         /* check if need_reconfig_queues has been set to 1 */
9811                         if (ports[pid].need_reconfig_queues == 0)
9812                                 ports[pid].need_reconfig_queues = queue;
9813                 }
9814         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
9815                 /* check if need_reconfig has been set to 1 */
9816                 if (ports[id].need_reconfig == 0)
9817                         ports[id].need_reconfig = dev;
9818                 /* check if need_reconfig_queues has been set to 1 */
9819                 if (ports[id].need_reconfig_queues == 0)
9820                         ports[id].need_reconfig_queues = queue;
9821         }
9822 }
9823
9824 #ifdef RTE_NIC_BYPASS
9825 #include <rte_pci_dev_ids.h>
9826 uint8_t
9827 bypass_is_supported(portid_t port_id)
9828 {
9829         struct rte_port   *port;
9830         struct rte_pci_id *pci_id;
9831
9832         if (port_id_is_invalid(port_id, ENABLED_WARN))
9833                 return 0;
9834
9835         /* Get the device id. */
9836         port    = &ports[port_id];
9837         pci_id = &port->dev_info.pci_dev->id;
9838
9839         /* Check if NIC supports bypass. */
9840         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
9841                 return 1;
9842         }
9843         else {
9844                 printf("\tBypass not supported for port_id = %d.\n", port_id);
9845                 return 0;
9846         }
9847 }
9848 #endif