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