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