i40e: support autoneg or force link speed
[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_launch.h>
63 #include <rte_tailq.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77
78 #include <cmdline_rdline.h>
79 #include <cmdline_parse.h>
80 #include <cmdline_parse_num.h>
81 #include <cmdline_parse_string.h>
82 #include <cmdline_parse_ipaddr.h>
83 #include <cmdline_parse_etheraddr.h>
84 #include <cmdline_socket.h>
85 #include <cmdline.h>
86 #include <rte_pci_dev_ids.h>
87 #ifdef RTE_LIBRTE_PMD_BOND
88 #include <rte_eth_bond.h>
89 #endif
90
91 #include "testpmd.h"
92
93 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
94
95 #ifdef RTE_NIC_BYPASS
96 uint8_t bypass_is_supported(portid_t port_id);
97 #endif
98
99 /* *** Help command with introduction. *** */
100 struct cmd_help_brief_result {
101         cmdline_fixed_string_t help;
102 };
103
104 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
105                                   struct cmdline *cl,
106                                   __attribute__((unused)) void *data)
107 {
108         cmdline_printf(
109                 cl,
110                 "\n"
111                 "Help is available for the following sections:\n\n"
112                 "    help control    : Start and stop forwarding.\n"
113                 "    help display    : Displaying port, stats and config "
114                 "information.\n"
115                 "    help config     : Configuration information.\n"
116                 "    help ports      : Configuring ports.\n"
117                 "    help flowdir    : Flow Director filter help.\n"
118                 "    help registers  : Reading and setting port registers.\n"
119                 "    help filters    : Filters configuration help.\n"
120                 "    help all        : All of the above sections.\n\n"
121         );
122
123 }
124
125 cmdline_parse_token_string_t cmd_help_brief_help =
126         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
127
128 cmdline_parse_inst_t cmd_help_brief = {
129         .f = cmd_help_brief_parsed,
130         .data = NULL,
131         .help_str = "show help",
132         .tokens = {
133                 (void *)&cmd_help_brief_help,
134                 NULL,
135         },
136 };
137
138 /* *** Help command with help sections. *** */
139 struct cmd_help_long_result {
140         cmdline_fixed_string_t help;
141         cmdline_fixed_string_t section;
142 };
143
144 static void cmd_help_long_parsed(void *parsed_result,
145                                  struct cmdline *cl,
146                                  __attribute__((unused)) void *data)
147 {
148         int show_all = 0;
149         struct cmd_help_long_result *res = parsed_result;
150
151         if (!strcmp(res->section, "all"))
152                 show_all = 1;
153
154         if (show_all || !strcmp(res->section, "control")) {
155
156                 cmdline_printf(
157                         cl,
158                         "\n"
159                         "Control forwarding:\n"
160                         "-------------------\n\n"
161
162                         "start\n"
163                         "    Start packet forwarding with current configuration.\n\n"
164
165                         "start tx_first\n"
166                         "    Start packet forwarding with current config"
167                         " after sending one burst of packets.\n\n"
168
169                         "stop\n"
170                         "    Stop packet forwarding, and display accumulated"
171                         " statistics.\n\n"
172
173                         "quit\n"
174                         "    Quit to prompt in Linux and reboot on Baremetal.\n\n"
175                 );
176         }
177
178         if (show_all || !strcmp(res->section, "display")) {
179
180                 cmdline_printf(
181                         cl,
182                         "\n"
183                         "Display:\n"
184                         "--------\n\n"
185
186                         "show port (info|stats|fdir|stat_qmap) (port_id|all)\n"
187                         "    Display information for port_id, or all.\n\n"
188
189                         "show port rss-hash [key]\n"
190                         "    Display the RSS hash functions and RSS hash key"
191                         " of port X\n\n"
192
193                         "clear port (info|stats|fdir|stat_qmap) (port_id|all)\n"
194                         "    Clear information for port_id, or all.\n\n"
195
196                         "show config (rxtx|cores|fwd)\n"
197                         "    Display the given configuration.\n\n"
198
199                         "read rxd (port_id) (queue_id) (rxd_id)\n"
200                         "    Display an RX descriptor of a port RX queue.\n\n"
201
202                         "read txd (port_id) (queue_id) (txd_id)\n"
203                         "    Display a TX descriptor of a port TX queue.\n\n"
204                 );
205         }
206
207         if (show_all || !strcmp(res->section, "config")) {
208                 cmdline_printf(
209                         cl,
210                         "\n"
211                         "Configuration:\n"
212                         "--------------\n"
213                         "Configuration changes only become active when"
214                         " forwarding is started/restarted.\n\n"
215
216                         "set default\n"
217                         "    Reset forwarding to the default configuration.\n\n"
218
219                         "set verbose (level)\n"
220                         "    Set the debug verbosity level X.\n\n"
221
222                         "set nbport (num)\n"
223                         "    Set number of ports.\n\n"
224
225                         "set nbcore (num)\n"
226                         "    Set number of cores.\n\n"
227
228                         "set coremask (mask)\n"
229                         "    Set the forwarding cores hexadecimal mask.\n\n"
230
231                         "set portmask (mask)\n"
232                         "    Set the forwarding ports hexadecimal mask.\n\n"
233
234                         "set burst (num)\n"
235                         "    Set number of packets per burst.\n\n"
236
237                         "set burst tx delay (microseconds) retry (num)\n"
238                         "    Set the transmit delay time and number of retries"
239                         " in mac_retry forwarding mode.\n\n"
240
241                         "set txpkts (x[,y]*)\n"
242                         "    Set the length of each segment of TXONLY"
243                         " packets.\n\n"
244
245                         "set corelist (x[,y]*)\n"
246                         "    Set the list of forwarding cores.\n\n"
247
248                         "set portlist (x[,y]*)\n"
249                         "    Set the list of forwarding ports.\n\n"
250
251                         "vlan set strip (on|off) (port_id)\n"
252                         "    Set the VLAN strip on a port.\n\n"
253
254                         "vlan set stripq (on|off) (port_id,queue_id)\n"
255                         "    Set the VLAN strip for a queue on a port.\n\n"
256
257                         "vlan set filter (on|off) (port_id)\n"
258                         "    Set the VLAN filter on a port.\n\n"
259
260                         "vlan set qinq (on|off) (port_id)\n"
261                         "    Set the VLAN QinQ (extended queue in queue)"
262                         " on a port.\n\n"
263
264                         "vlan set tpid (value) (port_id)\n"
265                         "    Set the outer VLAN TPID for Packet Filtering on"
266                         " a port\n\n"
267
268                         "rx_vlan add (vlan_id|all) (port_id)\n"
269                         "    Add a vlan_id, or all identifiers, to the set"
270                         " of VLAN identifiers filtered by port_id.\n\n"
271
272                         "rx_vlan rm (vlan_id|all) (port_id)\n"
273                         "    Remove a vlan_id, or all identifiers, from the set"
274                         " of VLAN identifiers filtered by port_id.\n\n"
275
276                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
277                         "    Add a vlan_id, to the set of VLAN identifiers"
278                         "filtered for VF(s) from port_id.\n\n"
279
280                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
281                         "    Remove a vlan_id, to the set of VLAN identifiers"
282                         "filtered for VF(s) from port_id.\n\n"
283
284                         "rx_vlan set tpid (value) (port_id)\n"
285                         "    Set the outer VLAN TPID for Packet Filtering on"
286                         " a port\n\n"
287
288                         "tx_vlan set vlan_id (port_id)\n"
289                         "    Set hardware insertion of VLAN ID in packets sent"
290                         " on a port.\n\n"
291
292                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
293                         "    Set port based TX VLAN insertion.\n\n"
294
295                         "tx_vlan reset (port_id)\n"
296                         "    Disable hardware insertion of a VLAN header in"
297                         " packets sent on a port.\n\n"
298
299                         "tx_checksum set mask (port_id)\n"
300                         "    Enable hardware insertion of checksum offload with"
301                         " the 4-bit mask, 0~0xf, in packets sent on a port.\n"
302                         "        bit 0 - insert ip   checksum offload if set\n"
303                         "        bit 1 - insert udp  checksum offload if set\n"
304                         "        bit 2 - insert tcp  checksum offload if set\n"
305                         "        bit 3 - insert sctp checksum offload if set\n"
306                         "    Please check the NIC datasheet for HW limits.\n\n"
307
308                         "set fwd (%s)\n"
309                         "    Set packet forwarding mode.\n\n"
310
311                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
312                         "    Add a MAC address on port_id.\n\n"
313
314                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
315                         "    Remove a MAC address from port_id.\n\n"
316
317                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
318                         "    Add a MAC address for a VF on the port.\n\n"
319
320                         "set port (port_id) uta (mac_address|all) (on|off)\n"
321                         "    Add/Remove a or all unicast hash filter(s)"
322                         "from port X.\n\n"
323
324                         "set promisc (port_id|all) (on|off)\n"
325                         "    Set the promiscuous mode on port_id, or all.\n\n"
326
327                         "set allmulti (port_id|all) (on|off)\n"
328                         "    Set the allmulti mode on port_id, or all.\n\n"
329
330                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
331                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
332                         " (on|off) autoneg (on|off) (port_id)\n"
333                         "set flow_ctrl rx (on|off) (portid)\n"
334                         "set flow_ctrl tx (on|off) (portid)\n"
335                         "set flow_ctrl high_water (high_water) (portid)\n"
336                         "set flow_ctrl low_water (low_water) (portid)\n"
337                         "set flow_ctrl pause_time (pause_time) (portid)\n"
338                         "set flow_ctrl send_xon (send_xon) (portid)\n"
339                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
340                         "set flow_ctrl autoneg (on|off) (port_id)\n"
341                         "    Set the link flow control parameter on a port.\n\n"
342
343                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
344                         " (low_water) (pause_time) (priority) (port_id)\n"
345                         "    Set the priority flow control parameter on a"
346                         " port.\n\n"
347
348                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
349                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
350                         " queue on port.\n"
351                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
352                         " on port 0 to mapping 5.\n\n"
353
354                         "set port (port_id) vf (vf_id) rx|tx on|off \n"
355                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
356
357                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
358                         "|MPE) (on|off)\n"
359                         "    AUPE:accepts untagged VLAN;"
360                         "ROPE:accept unicast hash\n\n"
361                         "    BAM:accepts broadcast packets;"
362                         "MPE:accepts all multicast packets\n\n"
363                         "    Enable/Disable a VF receive mode of a port\n\n"
364
365                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
366                         "    Set rate limit for a queue of a port\n\n"
367
368                         "set port (port_id) vf (vf_id) rate (rate_num) "
369                         "queue_mask (queue_mask_value)\n"
370                         "    Set rate limit for queues in VF of a port\n\n"
371
372                         "set port (port_id) mirror-rule (rule_id)"
373                         "(pool-mirror|vlan-mirror)\n"
374                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
375                         "   Set pool or vlan type mirror rule on a port.\n"
376                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
377                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
378                         " to pool 0.\n\n"
379
380                         "set port (port_id) mirror-rule (rule_id)"
381                         " (uplink-mirror|downlink-mirror) dst-pool"
382                         " (pool_id) (on|off)\n"
383                         "   Set uplink or downlink type mirror rule on a port.\n"
384                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
385                         " 0 on' enable mirror income traffic to pool 0.\n\n"
386
387                         "reset port (port_id) mirror-rule (rule_id)\n"
388                         "   Reset a mirror rule.\n\n"
389
390                         "set flush_rx (on|off)\n"
391                         "   Flush (default) or don't flush RX streams before"
392                         " forwarding. Mainly used with PCAP drivers.\n\n"
393
394                         #ifdef RTE_NIC_BYPASS
395                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
396                         "   Set the bypass mode for the lowest port on bypass enabled"
397                         " NIC.\n\n"
398
399                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
400                         "mode (normal|bypass|isolate) (port_id)\n"
401                         "   Set the event required to initiate specified bypass mode for"
402                         " the lowest port on a bypass enabled NIC where:\n"
403                         "       timeout   = enable bypass after watchdog timeout.\n"
404                         "       os_on     = enable bypass when OS/board is powered on.\n"
405                         "       os_off    = enable bypass when OS/board is powered off.\n"
406                         "       power_on  = enable bypass when power supply is turned on.\n"
407                         "       power_off = enable bypass when power supply is turned off."
408                         "\n\n"
409
410                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
411                         "   Set the bypass watchdog timeout to 'n' seconds"
412                         " where 0 = instant.\n\n"
413
414                         "show bypass config (port_id)\n"
415                         "   Show the bypass configuration for a bypass enabled NIC"
416                         " using the lowest port on the NIC.\n\n"
417 #endif
418 #ifdef RTE_LIBRTE_PMD_BOND
419                         "create bonded device (mode) (socket)\n"
420                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
421
422                         "add bonding slave (slave_id) (port_id)\n"
423                         "       Add a slave device to a bonded device.\n\n"
424
425                         "remove bonding slave (slave_id) (port_id)\n"
426                         "       Remove a slave device from a bonded device.\n\n"
427
428                         "set bonding mode (value) (port_id)\n"
429                         "       Set the bonding mode on a bonded device.\n\n"
430
431                         "set bonding primary (slave_id) (port_id)\n"
432                         "       Set the primary slave for a bonded device.\n\n"
433
434                         "show bonding config (port_id)\n"
435                         "       Show the bonding config for port_id.\n\n"
436
437                         "set bonding mac_addr (port_id) (address)\n"
438                         "       Set the MAC address of a bonded device.\n\n"
439
440                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
441                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
442 #endif
443
444                         , list_pkt_forwarding_modes()
445                 );
446         }
447
448
449         if (show_all || !strcmp(res->section, "flowdir")) {
450
451                 cmdline_printf(
452                         cl,
453                         "\n"
454                         "Flow director mode:\n"
455                         "-------------------\n\n"
456
457                         "add_signature_filter (port_id) (ip|udp|tcp|sctp)"
458                         " src (src_ip_address) (src_port)"
459                         " dst (dst_ip_address) (dst_port)"
460                         " flexbytes (flexbytes_values) vlan (vlan_id)"
461                         " queue (queue_id)\n"
462                         "    Add a signature filter.\n\n"
463
464                         "upd_signature_filter (port_id) (ip|udp|tcp|sctp)"
465                         " src (src_ip_address) (src_port)"
466                         " dst (dst_ip_address) (dst_port)"
467                         " flexbytes (flexbytes_values) vlan (vlan_id)"
468                         " queue (queue_id)\n"
469                         "    Update a signature filter.\n\n"
470
471                         "rm_signature_filter (port_id) (ip|udp|tcp|sctp)"
472                         " src (src_ip_address) (src_port)"
473                         " dst (dst_ip_address) (dst_port)"
474                         " flexbytes (flexbytes_values) vlan (vlan_id)\n"
475                         "    Remove a signature filter.\n\n"
476
477                         "add_perfect_filter (port_id) (ip|udp|tcp|sctp)"
478                         " src (src_ip_address) (src_port)"
479                         " dst (dst_ip_address) (dst_port)"
480                         " flexbytes (flexbytes_values) vlan (vlan_id)"
481                         " queue (queue_id) soft (soft_id)\n"
482                         "    Add a perfect filter.\n\n"
483
484                         "upd_perfect_filter (port_id) (ip|udp|tcp|sctp)"
485                         " src (src_ip_address) (src_port)"
486                         " dst (dst_ip_address) (dst_port)"
487                         " flexbytes (flexbytes_values) vlan (vlan_id)"
488                         " queue (queue_id)\n"
489                         "    Update a perfect filter.\n\n"
490
491                         "rm_perfect_filter (port_id) (ip|udp|tcp|sctp)"
492                         " src (src_ip_address) (src_port)"
493                         " dst (dst_ip_address) (dst_port)"
494                         " flexbytes (flexbytes_values) vlan (vlan_id)"
495                         " soft (soft_id)\n"
496                         "    Remove a perfect filter.\n\n"
497
498                         "set_masks_filter (port_id) only_ip_flow (0|1)"
499                         " src_mask (ip_src_mask) (src_port_mask)"
500                         " dst_mask (ip_dst_mask) (dst_port_mask)"
501                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)\n"
502                         "    Set IPv4 filter masks.\n\n"
503
504                         "set_ipv6_masks_filter (port_id) only_ip_flow (0|1)"
505                         " src_mask (ip_src_mask) (src_port_mask)"
506                         " dst_mask (ip_dst_mask) (dst_port_mask)"
507                         " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)"
508                         " compare_dst (0|1)\n"
509                         "    Set IPv6 filter masks.\n\n"
510                 );
511         }
512
513         if (show_all || !strcmp(res->section, "ports")) {
514
515                 cmdline_printf(
516                         cl,
517                         "\n"
518                         "Port Operations:\n"
519                         "----------------\n\n"
520
521                         "port start (port_id|all)\n"
522                         "    Start all ports or port_id.\n\n"
523
524                         "port stop (port_id|all)\n"
525                         "    Stop all ports or port_id.\n\n"
526
527                         "port close (port_id|all)\n"
528                         "    Close all ports or port_id.\n\n"
529
530                         "port config (port_id|all)"
531                         " speed (10|100|1000|10000|40000|auto)"
532                         " duplex (half|full|auto)\n"
533                         "    Set speed and duplex for all ports or port_id\n\n"
534
535                         "port config all (rxq|txq|rxd|txd) (value)\n"
536                         "    Set number for rxq/txq/rxd/txd.\n\n"
537
538                         "port config all max-pkt-len (value)\n"
539                         "    Set the max packet length.\n\n"
540
541                         "port config all (crc-strip|rx-cksum|hw-vlan|drop-en)"
542                         " (on|off)\n"
543                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
544                         " for ports.\n\n"
545
546                         "port config all rss (ip|udp|none)\n"
547                         "    Set the RSS mode.\n\n"
548
549                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
550                         "    Set the RSS redirection table.\n\n"
551
552                         "port config (port_id) dcb vt (on|off) (traffic_class)"
553                         " pfc (on|off)\n"
554                         "    Set the DCB mode.\n\n"
555
556                         "port config all burst (value)\n"
557                         "    Set the number of packets per burst.\n\n"
558
559                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
560                         " (value)\n"
561                         "    Set the ring prefetch/host/writeback threshold"
562                         " for tx/rx queue.\n\n"
563
564                         "port config all (txfreet|txrst|rxfreet) (value)\n"
565                         "    Set free threshold for rx/tx, or set"
566                         " tx rs bit threshold.\n\n"
567                         "port config mtu X value\n"
568                         "    Set the MTU of port X to a given value\n\n"
569                 );
570         }
571
572         if (show_all || !strcmp(res->section, "registers")) {
573
574                 cmdline_printf(
575                         cl,
576                         "\n"
577                         "Registers:\n"
578                         "----------\n\n"
579
580                         "read reg (port_id) (address)\n"
581                         "    Display value of a port register.\n\n"
582
583                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
584                         "    Display a port register bit field.\n\n"
585
586                         "read regbit (port_id) (address) (bit_x)\n"
587                         "    Display a single port register bit.\n\n"
588
589                         "write reg (port_id) (address) (value)\n"
590                         "    Set value of a port register.\n\n"
591
592                         "write regfield (port_id) (address) (bit_x) (bit_y)"
593                         " (value)\n"
594                         "    Set bit field of a port register.\n\n"
595
596                         "write regbit (port_id) (address) (bit_x) (value)\n"
597                         "    Set single bit value of a port register.\n\n"
598                 );
599         }
600         if (show_all || !strcmp(res->section, "filters")) {
601
602                 cmdline_printf(
603                         cl,
604                         "\n"
605                         "filters:\n"
606                         "--------\n\n"
607
608                         "add_ethertype_filter (port_id) ethertype (eth_value)"
609                         " priority (enable|disable)(pri_value) queue (queue_id) index (idx)\n"
610                         "    add an ethertype filter.\n\n"
611
612                         "remove_ethertype_filter (port_id) index (idx)\n"
613                         "    remove an ethertype filter.\n\n"
614
615                         "get_ethertype_filter (port_id) index (idx)\n"
616                         "    get info of a ethertype filter.\n\n"
617
618                         "add_2tuple_filter (port_id) protocol (pro_value) (pro_mask)"
619                         " dst_port (port_value) (port_mask) flags (flg_value) priority (prio_value)"
620                         " queue (queue_id) index (idx)\n"
621                         "    add a 2tuple filter.\n\n"
622
623                         "remove_2tuple_filter (port_id) index (idx)\n"
624                         "    remove a 2tuple filter.\n\n"
625
626                         "get_2tuple_filter (port_id) index (idx)\n"
627                         "    get info of a 2tuple filter.\n\n"
628
629                         "add_5tuple_filter (port_id) dst_ip (dst_address) src_ip (src_address)"
630                         " dst_port (dst_port_value) src_port (src_port_value) protocol (protocol_value)"
631                         " mask (mask_value) flags (flags_value) priority (prio_value)"
632                         " queue (queue_id) index (idx)\n"
633                         "    add a 5tuple filter.\n\n"
634
635                         "remove_5tuple_filter (port_id) index (idx)\n"
636                         "    remove a 5tuple filter.\n\n"
637
638                         "get_5tuple_filter (port_id) index (idx)\n"
639                         "    get info of a 5tuple filter.\n\n"
640
641                         "add_syn_filter (port_id) priority (high|low) queue (queue_id)"
642                         "    add syn filter.\n\n"
643
644                         "remove_syn_filter (port_id)"
645                         "    remove syn filter.\n\n"
646
647                         "get_syn_filter (port_id) "
648                         "    get syn filter info.\n\n"
649
650                         "add_flex_filter (port_id) len (len_value) bytes (bytes_string) mask (mask_value)"
651                         " priority (prio_value) queue (queue_id) index (idx)\n"
652                         "    add a flex filter.\n\n"
653
654                         "remove_flex_filter (port_id) index (idx)\n"
655                         "    remove a flex filter.\n\n"
656
657                         "get_flex_filter (port_id) index (idx)\n"
658                         "    get info of a flex filter.\n\n"
659                 );
660         }
661 }
662
663 cmdline_parse_token_string_t cmd_help_long_help =
664         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
665
666 cmdline_parse_token_string_t cmd_help_long_section =
667         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
668                         "all#control#display#config#flowdir#"
669                         "ports#registers#filters");
670
671 cmdline_parse_inst_t cmd_help_long = {
672         .f = cmd_help_long_parsed,
673         .data = NULL,
674         .help_str = "show help",
675         .tokens = {
676                 (void *)&cmd_help_long_help,
677                 (void *)&cmd_help_long_section,
678                 NULL,
679         },
680 };
681
682
683 /* *** start/stop/close all ports *** */
684 struct cmd_operate_port_result {
685         cmdline_fixed_string_t keyword;
686         cmdline_fixed_string_t name;
687         cmdline_fixed_string_t value;
688 };
689
690 static void cmd_operate_port_parsed(void *parsed_result,
691                                 __attribute__((unused)) struct cmdline *cl,
692                                 __attribute__((unused)) void *data)
693 {
694         struct cmd_operate_port_result *res = parsed_result;
695
696         if (!strcmp(res->name, "start"))
697                 start_port(RTE_PORT_ALL);
698         else if (!strcmp(res->name, "stop"))
699                 stop_port(RTE_PORT_ALL);
700         else if (!strcmp(res->name, "close"))
701                 close_port(RTE_PORT_ALL);
702         else
703                 printf("Unknown parameter\n");
704 }
705
706 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
707         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
708                                                                 "port");
709 cmdline_parse_token_string_t cmd_operate_port_all_port =
710         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
711                                                 "start#stop#close");
712 cmdline_parse_token_string_t cmd_operate_port_all_all =
713         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
714
715 cmdline_parse_inst_t cmd_operate_port = {
716         .f = cmd_operate_port_parsed,
717         .data = NULL,
718         .help_str = "port start|stop|close all: start/stop/close all ports",
719         .tokens = {
720                 (void *)&cmd_operate_port_all_cmd,
721                 (void *)&cmd_operate_port_all_port,
722                 (void *)&cmd_operate_port_all_all,
723                 NULL,
724         },
725 };
726
727 /* *** start/stop/close specific port *** */
728 struct cmd_operate_specific_port_result {
729         cmdline_fixed_string_t keyword;
730         cmdline_fixed_string_t name;
731         uint8_t value;
732 };
733
734 static void cmd_operate_specific_port_parsed(void *parsed_result,
735                         __attribute__((unused)) struct cmdline *cl,
736                                 __attribute__((unused)) void *data)
737 {
738         struct cmd_operate_specific_port_result *res = parsed_result;
739
740         if (!strcmp(res->name, "start"))
741                 start_port(res->value);
742         else if (!strcmp(res->name, "stop"))
743                 stop_port(res->value);
744         else if (!strcmp(res->name, "close"))
745                 close_port(res->value);
746         else
747                 printf("Unknown parameter\n");
748 }
749
750 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
751         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
752                                                         keyword, "port");
753 cmdline_parse_token_string_t cmd_operate_specific_port_port =
754         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
755                                                 name, "start#stop#close");
756 cmdline_parse_token_num_t cmd_operate_specific_port_id =
757         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
758                                                         value, UINT8);
759
760 cmdline_parse_inst_t cmd_operate_specific_port = {
761         .f = cmd_operate_specific_port_parsed,
762         .data = NULL,
763         .help_str = "port start|stop|close X: start/stop/close port X",
764         .tokens = {
765                 (void *)&cmd_operate_specific_port_cmd,
766                 (void *)&cmd_operate_specific_port_port,
767                 (void *)&cmd_operate_specific_port_id,
768                 NULL,
769         },
770 };
771
772 /* *** configure speed for all ports *** */
773 struct cmd_config_speed_all {
774         cmdline_fixed_string_t port;
775         cmdline_fixed_string_t keyword;
776         cmdline_fixed_string_t all;
777         cmdline_fixed_string_t item1;
778         cmdline_fixed_string_t item2;
779         cmdline_fixed_string_t value1;
780         cmdline_fixed_string_t value2;
781 };
782
783 static void
784 cmd_config_speed_all_parsed(void *parsed_result,
785                         __attribute__((unused)) struct cmdline *cl,
786                         __attribute__((unused)) void *data)
787 {
788         struct cmd_config_speed_all *res = parsed_result;
789         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
790         uint16_t link_duplex = 0;
791         portid_t pid;
792
793         if (!all_ports_stopped()) {
794                 printf("Please stop all ports first\n");
795                 return;
796         }
797
798         if (!strcmp(res->value1, "10"))
799                 link_speed = ETH_LINK_SPEED_10;
800         else if (!strcmp(res->value1, "100"))
801                 link_speed = ETH_LINK_SPEED_100;
802         else if (!strcmp(res->value1, "1000"))
803                 link_speed = ETH_LINK_SPEED_1000;
804         else if (!strcmp(res->value1, "10000"))
805                 link_speed = ETH_LINK_SPEED_10G;
806         else if (!strcmp(res->value1, "40000"))
807                 link_speed = ETH_LINK_SPEED_40G;
808         else if (!strcmp(res->value1, "auto"))
809                 link_speed = ETH_LINK_SPEED_AUTONEG;
810         else {
811                 printf("Unknown parameter\n");
812                 return;
813         }
814
815         if (!strcmp(res->value2, "half"))
816                 link_duplex = ETH_LINK_HALF_DUPLEX;
817         else if (!strcmp(res->value2, "full"))
818                 link_duplex = ETH_LINK_FULL_DUPLEX;
819         else if (!strcmp(res->value2, "auto"))
820                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
821         else {
822                 printf("Unknown parameter\n");
823                 return;
824         }
825
826         for (pid = 0; pid < nb_ports; pid++) {
827                 ports[pid].dev_conf.link_speed = link_speed;
828                 ports[pid].dev_conf.link_duplex = link_duplex;
829         }
830
831         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
832 }
833
834 cmdline_parse_token_string_t cmd_config_speed_all_port =
835         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
836 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
837         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
838                                                         "config");
839 cmdline_parse_token_string_t cmd_config_speed_all_all =
840         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
841 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
842         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
843 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
844         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
845                                                 "10#100#1000#10000#40000#auto");
846 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
847         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
848 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
849         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
850                                                 "half#full#auto");
851
852 cmdline_parse_inst_t cmd_config_speed_all = {
853         .f = cmd_config_speed_all_parsed,
854         .data = NULL,
855         .help_str = "port config all speed 10|100|1000|10000|40000|auto duplex "
856                                                         "half|full|auto",
857         .tokens = {
858                 (void *)&cmd_config_speed_all_port,
859                 (void *)&cmd_config_speed_all_keyword,
860                 (void *)&cmd_config_speed_all_all,
861                 (void *)&cmd_config_speed_all_item1,
862                 (void *)&cmd_config_speed_all_value1,
863                 (void *)&cmd_config_speed_all_item2,
864                 (void *)&cmd_config_speed_all_value2,
865                 NULL,
866         },
867 };
868
869 /* *** configure speed for specific port *** */
870 struct cmd_config_speed_specific {
871         cmdline_fixed_string_t port;
872         cmdline_fixed_string_t keyword;
873         uint8_t id;
874         cmdline_fixed_string_t item1;
875         cmdline_fixed_string_t item2;
876         cmdline_fixed_string_t value1;
877         cmdline_fixed_string_t value2;
878 };
879
880 static void
881 cmd_config_speed_specific_parsed(void *parsed_result,
882                                 __attribute__((unused)) struct cmdline *cl,
883                                 __attribute__((unused)) void *data)
884 {
885         struct cmd_config_speed_specific *res = parsed_result;
886         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
887         uint16_t link_duplex = 0;
888
889         if (!all_ports_stopped()) {
890                 printf("Please stop all ports first\n");
891                 return;
892         }
893
894         if (res->id >= nb_ports) {
895                 printf("Port id %d must be less than %d\n", res->id, nb_ports);
896                 return;
897         }
898
899         if (!strcmp(res->value1, "10"))
900                 link_speed = ETH_LINK_SPEED_10;
901         else if (!strcmp(res->value1, "100"))
902                 link_speed = ETH_LINK_SPEED_100;
903         else if (!strcmp(res->value1, "1000"))
904                 link_speed = ETH_LINK_SPEED_1000;
905         else if (!strcmp(res->value1, "10000"))
906                 link_speed = ETH_LINK_SPEED_10000;
907         else if (!strcmp(res->value1, "40000"))
908                 link_speed = ETH_LINK_SPEED_40G;
909         else if (!strcmp(res->value1, "auto"))
910                 link_speed = ETH_LINK_SPEED_AUTONEG;
911         else {
912                 printf("Unknown parameter\n");
913                 return;
914         }
915
916         if (!strcmp(res->value2, "half"))
917                 link_duplex = ETH_LINK_HALF_DUPLEX;
918         else if (!strcmp(res->value2, "full"))
919                 link_duplex = ETH_LINK_FULL_DUPLEX;
920         else if (!strcmp(res->value2, "auto"))
921                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
922         else {
923                 printf("Unknown parameter\n");
924                 return;
925         }
926
927         ports[res->id].dev_conf.link_speed = link_speed;
928         ports[res->id].dev_conf.link_duplex = link_duplex;
929
930         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
931 }
932
933
934 cmdline_parse_token_string_t cmd_config_speed_specific_port =
935         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
936                                                                 "port");
937 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
938         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
939                                                                 "config");
940 cmdline_parse_token_num_t cmd_config_speed_specific_id =
941         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
942 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
943         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
944                                                                 "speed");
945 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
946         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
947                                                 "10#100#1000#10000#40000#auto");
948 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
949         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
950                                                                 "duplex");
951 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
952         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
953                                                         "half#full#auto");
954
955 cmdline_parse_inst_t cmd_config_speed_specific = {
956         .f = cmd_config_speed_specific_parsed,
957         .data = NULL,
958         .help_str = "port config X speed 10|100|1000|10000|40000|auto duplex "
959                                                         "half|full|auto",
960         .tokens = {
961                 (void *)&cmd_config_speed_specific_port,
962                 (void *)&cmd_config_speed_specific_keyword,
963                 (void *)&cmd_config_speed_specific_id,
964                 (void *)&cmd_config_speed_specific_item1,
965                 (void *)&cmd_config_speed_specific_value1,
966                 (void *)&cmd_config_speed_specific_item2,
967                 (void *)&cmd_config_speed_specific_value2,
968                 NULL,
969         },
970 };
971
972 /* *** configure txq/rxq, txd/rxd *** */
973 struct cmd_config_rx_tx {
974         cmdline_fixed_string_t port;
975         cmdline_fixed_string_t keyword;
976         cmdline_fixed_string_t all;
977         cmdline_fixed_string_t name;
978         uint16_t value;
979 };
980
981 static void
982 cmd_config_rx_tx_parsed(void *parsed_result,
983                         __attribute__((unused)) struct cmdline *cl,
984                         __attribute__((unused)) void *data)
985 {
986         struct cmd_config_rx_tx *res = parsed_result;
987
988         if (!all_ports_stopped()) {
989                 printf("Please stop all ports first\n");
990                 return;
991         }
992
993         if (!strcmp(res->name, "rxq")) {
994                 if (res->value <= 0) {
995                         printf("rxq %d invalid - must be > 0\n", res->value);
996                         return;
997                 }
998                 nb_rxq = res->value;
999         }
1000         else if (!strcmp(res->name, "txq")) {
1001                 if (res->value <= 0) {
1002                         printf("txq %d invalid - must be > 0\n", res->value);
1003                         return;
1004                 }
1005                 nb_txq = res->value;
1006         }
1007         else if (!strcmp(res->name, "rxd")) {
1008                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1009                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1010                                         res->value, RTE_TEST_RX_DESC_MAX);
1011                         return;
1012                 }
1013                 nb_rxd = res->value;
1014         } else if (!strcmp(res->name, "txd")) {
1015                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1016                         printf("txd %d invalid - must be > 0 && <= %d\n",
1017                                         res->value, RTE_TEST_TX_DESC_MAX);
1018                         return;
1019                 }
1020                 nb_txd = res->value;
1021         } else {
1022                 printf("Unknown parameter\n");
1023                 return;
1024         }
1025
1026         init_port_config();
1027
1028         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1029 }
1030
1031 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1032         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1033 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1034         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1035 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1036         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1037 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1038         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1039                                                 "rxq#txq#rxd#txd");
1040 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1041         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1042
1043 cmdline_parse_inst_t cmd_config_rx_tx = {
1044         .f = cmd_config_rx_tx_parsed,
1045         .data = NULL,
1046         .help_str = "port config all rxq|txq|rxd|txd value",
1047         .tokens = {
1048                 (void *)&cmd_config_rx_tx_port,
1049                 (void *)&cmd_config_rx_tx_keyword,
1050                 (void *)&cmd_config_rx_tx_all,
1051                 (void *)&cmd_config_rx_tx_name,
1052                 (void *)&cmd_config_rx_tx_value,
1053                 NULL,
1054         },
1055 };
1056
1057 /* *** config max packet length *** */
1058 struct cmd_config_max_pkt_len_result {
1059         cmdline_fixed_string_t port;
1060         cmdline_fixed_string_t keyword;
1061         cmdline_fixed_string_t all;
1062         cmdline_fixed_string_t name;
1063         uint32_t value;
1064 };
1065
1066 static void
1067 cmd_config_max_pkt_len_parsed(void *parsed_result,
1068                                 __attribute__((unused)) struct cmdline *cl,
1069                                 __attribute__((unused)) void *data)
1070 {
1071         struct cmd_config_max_pkt_len_result *res = parsed_result;
1072
1073         if (!all_ports_stopped()) {
1074                 printf("Please stop all ports first\n");
1075                 return;
1076         }
1077
1078         if (!strcmp(res->name, "max-pkt-len")) {
1079                 if (res->value < ETHER_MIN_LEN) {
1080                         printf("max-pkt-len can not be less than %d\n",
1081                                                         ETHER_MIN_LEN);
1082                         return;
1083                 }
1084                 if (res->value == rx_mode.max_rx_pkt_len)
1085                         return;
1086
1087                 rx_mode.max_rx_pkt_len = res->value;
1088                 if (res->value > ETHER_MAX_LEN)
1089                         rx_mode.jumbo_frame = 1;
1090                 else
1091                         rx_mode.jumbo_frame = 0;
1092         } else {
1093                 printf("Unknown parameter\n");
1094                 return;
1095         }
1096
1097         init_port_config();
1098
1099         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1100 }
1101
1102 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1103         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1104                                                                 "port");
1105 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1106         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1107                                                                 "config");
1108 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1109         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1110                                                                 "all");
1111 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1112         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1113                                                                 "max-pkt-len");
1114 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1115         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1116                                                                 UINT32);
1117
1118 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1119         .f = cmd_config_max_pkt_len_parsed,
1120         .data = NULL,
1121         .help_str = "port config all max-pkt-len value",
1122         .tokens = {
1123                 (void *)&cmd_config_max_pkt_len_port,
1124                 (void *)&cmd_config_max_pkt_len_keyword,
1125                 (void *)&cmd_config_max_pkt_len_all,
1126                 (void *)&cmd_config_max_pkt_len_name,
1127                 (void *)&cmd_config_max_pkt_len_value,
1128                 NULL,
1129         },
1130 };
1131
1132 /* *** configure port MTU *** */
1133 struct cmd_config_mtu_result {
1134         cmdline_fixed_string_t port;
1135         cmdline_fixed_string_t keyword;
1136         cmdline_fixed_string_t mtu;
1137         uint8_t port_id;
1138         uint16_t value;
1139 };
1140
1141 static void
1142 cmd_config_mtu_parsed(void *parsed_result,
1143                       __attribute__((unused)) struct cmdline *cl,
1144                       __attribute__((unused)) void *data)
1145 {
1146         struct cmd_config_mtu_result *res = parsed_result;
1147
1148         if (res->value < ETHER_MIN_LEN) {
1149                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1150                 return;
1151         }
1152         port_mtu_set(res->port_id, res->value);
1153 }
1154
1155 cmdline_parse_token_string_t cmd_config_mtu_port =
1156         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1157                                  "port");
1158 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1159         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1160                                  "config");
1161 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1162         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1163                                  "mtu");
1164 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1165         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1166 cmdline_parse_token_num_t cmd_config_mtu_value =
1167         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1168
1169 cmdline_parse_inst_t cmd_config_mtu = {
1170         .f = cmd_config_mtu_parsed,
1171         .data = NULL,
1172         .help_str = "port config mtu value",
1173         .tokens = {
1174                 (void *)&cmd_config_mtu_port,
1175                 (void *)&cmd_config_mtu_keyword,
1176                 (void *)&cmd_config_mtu_mtu,
1177                 (void *)&cmd_config_mtu_port_id,
1178                 (void *)&cmd_config_mtu_value,
1179                 NULL,
1180         },
1181 };
1182
1183 /* *** configure rx mode *** */
1184 struct cmd_config_rx_mode_flag {
1185         cmdline_fixed_string_t port;
1186         cmdline_fixed_string_t keyword;
1187         cmdline_fixed_string_t all;
1188         cmdline_fixed_string_t name;
1189         cmdline_fixed_string_t value;
1190 };
1191
1192 static void
1193 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1194                                 __attribute__((unused)) struct cmdline *cl,
1195                                 __attribute__((unused)) void *data)
1196 {
1197         struct cmd_config_rx_mode_flag *res = parsed_result;
1198
1199         if (!all_ports_stopped()) {
1200                 printf("Please stop all ports first\n");
1201                 return;
1202         }
1203
1204         if (!strcmp(res->name, "crc-strip")) {
1205                 if (!strcmp(res->value, "on"))
1206                         rx_mode.hw_strip_crc = 1;
1207                 else if (!strcmp(res->value, "off"))
1208                         rx_mode.hw_strip_crc = 0;
1209                 else {
1210                         printf("Unknown parameter\n");
1211                         return;
1212                 }
1213         } else if (!strcmp(res->name, "rx-cksum")) {
1214                 if (!strcmp(res->value, "on"))
1215                         rx_mode.hw_ip_checksum = 1;
1216                 else if (!strcmp(res->value, "off"))
1217                         rx_mode.hw_ip_checksum = 0;
1218                 else {
1219                         printf("Unknown parameter\n");
1220                         return;
1221                 }
1222         } else if (!strcmp(res->name, "hw-vlan")) {
1223                 if (!strcmp(res->value, "on")) {
1224                         rx_mode.hw_vlan_filter = 1;
1225                         rx_mode.hw_vlan_strip  = 1;
1226                 }
1227                 else if (!strcmp(res->value, "off")) {
1228                         rx_mode.hw_vlan_filter = 0;
1229                         rx_mode.hw_vlan_strip  = 0;
1230                 }
1231                 else {
1232                         printf("Unknown parameter\n");
1233                         return;
1234                 }
1235         } else if (!strcmp(res->name, "drop-en")) {
1236                 if (!strcmp(res->value, "on"))
1237                         rx_drop_en = 1;
1238                 else if (!strcmp(res->value, "off"))
1239                         rx_drop_en = 0;
1240                 else {
1241                         printf("Unknown parameter\n");
1242                         return;
1243                 }
1244         } else {
1245                 printf("Unknown parameter\n");
1246                 return;
1247         }
1248
1249         init_port_config();
1250
1251         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1252 }
1253
1254 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1255         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1256 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1257         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1258                                                                 "config");
1259 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1260         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1261 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1262         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1263                                         "crc-strip#rx-cksum#hw-vlan");
1264 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1265         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1266                                                         "on#off");
1267
1268 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1269         .f = cmd_config_rx_mode_flag_parsed,
1270         .data = NULL,
1271         .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off",
1272         .tokens = {
1273                 (void *)&cmd_config_rx_mode_flag_port,
1274                 (void *)&cmd_config_rx_mode_flag_keyword,
1275                 (void *)&cmd_config_rx_mode_flag_all,
1276                 (void *)&cmd_config_rx_mode_flag_name,
1277                 (void *)&cmd_config_rx_mode_flag_value,
1278                 NULL,
1279         },
1280 };
1281
1282 /* *** configure rss *** */
1283 struct cmd_config_rss {
1284         cmdline_fixed_string_t port;
1285         cmdline_fixed_string_t keyword;
1286         cmdline_fixed_string_t all;
1287         cmdline_fixed_string_t name;
1288         cmdline_fixed_string_t value;
1289 };
1290
1291 static void
1292 cmd_config_rss_parsed(void *parsed_result,
1293                         __attribute__((unused)) struct cmdline *cl,
1294                         __attribute__((unused)) void *data)
1295 {
1296         struct cmd_config_rss *res = parsed_result;
1297         struct rte_eth_rss_conf rss_conf;
1298         uint8_t i;
1299
1300         if (!strcmp(res->value, "ip"))
1301                 rss_conf.rss_hf = ETH_RSS_IP;
1302         else if (!strcmp(res->value, "udp"))
1303                 rss_conf.rss_hf = ETH_RSS_UDP;
1304         else if (!strcmp(res->value, "none"))
1305                 rss_conf.rss_hf = 0;
1306         else {
1307                 printf("Unknown parameter\n");
1308                 return;
1309         }
1310         rss_conf.rss_key = NULL;
1311         for (i = 0; i < rte_eth_dev_count(); i++)
1312                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1313 }
1314
1315 cmdline_parse_token_string_t cmd_config_rss_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1317 cmdline_parse_token_string_t cmd_config_rss_keyword =
1318         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1319 cmdline_parse_token_string_t cmd_config_rss_all =
1320         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1321 cmdline_parse_token_string_t cmd_config_rss_name =
1322         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1323 cmdline_parse_token_string_t cmd_config_rss_value =
1324         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none");
1325
1326 cmdline_parse_inst_t cmd_config_rss = {
1327         .f = cmd_config_rss_parsed,
1328         .data = NULL,
1329         .help_str = "port config all rss ip|udp|none",
1330         .tokens = {
1331                 (void *)&cmd_config_rss_port,
1332                 (void *)&cmd_config_rss_keyword,
1333                 (void *)&cmd_config_rss_all,
1334                 (void *)&cmd_config_rss_name,
1335                 (void *)&cmd_config_rss_value,
1336                 NULL,
1337         },
1338 };
1339
1340 /* *** configure rss hash key *** */
1341 struct cmd_config_rss_hash_key {
1342         cmdline_fixed_string_t port;
1343         cmdline_fixed_string_t config;
1344         uint8_t port_id;
1345         cmdline_fixed_string_t rss_hash_key;
1346         cmdline_fixed_string_t key;
1347 };
1348
1349 #define RSS_HASH_KEY_LENGTH 40
1350 static uint8_t
1351 hexa_digit_to_value(char hexa_digit)
1352 {
1353         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1354                 return (uint8_t) (hexa_digit - '0');
1355         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1356                 return (uint8_t) ((hexa_digit - 'a') + 10);
1357         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1358                 return (uint8_t) ((hexa_digit - 'A') + 10);
1359         /* Invalid hexa digit */
1360         return 0xFF;
1361 }
1362
1363 static uint8_t
1364 parse_and_check_key_hexa_digit(char *key, int idx)
1365 {
1366         uint8_t hexa_v;
1367
1368         hexa_v = hexa_digit_to_value(key[idx]);
1369         if (hexa_v == 0xFF)
1370                 printf("invalid key: character %c at position %d is not a "
1371                        "valid hexa digit\n", key[idx], idx);
1372         return hexa_v;
1373 }
1374
1375 static void
1376 cmd_config_rss_hash_key_parsed(void *parsed_result,
1377                                __attribute__((unused)) struct cmdline *cl,
1378                                __attribute__((unused)) void *data)
1379 {
1380         struct cmd_config_rss_hash_key *res = parsed_result;
1381         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1382         uint8_t xdgt0;
1383         uint8_t xdgt1;
1384         int i;
1385
1386         /* Check the length of the RSS hash key */
1387         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1388                 printf("key length: %d invalid - key must be a string of %d"
1389                        "hexa-decimal numbers\n", (int) strlen(res->key),
1390                        RSS_HASH_KEY_LENGTH * 2);
1391                 return;
1392         }
1393         /* Translate RSS hash key into binary representation */
1394         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1395                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1396                 if (xdgt0 == 0xFF)
1397                         return;
1398                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1399                 if (xdgt1 == 0xFF)
1400                         return;
1401                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1402         }
1403         port_rss_hash_key_update(res->port_id, hash_key);
1404 }
1405
1406 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1408 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1409         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1410                                  "config");
1411 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1412         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1413 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1415                                  rss_hash_key, "rss-hash-key");
1416 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1418
1419 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1420         .f = cmd_config_rss_hash_key_parsed,
1421         .data = NULL,
1422         .help_str = "port config X rss-hash-key 80 hexa digits",
1423         .tokens = {
1424                 (void *)&cmd_config_rss_hash_key_port,
1425                 (void *)&cmd_config_rss_hash_key_config,
1426                 (void *)&cmd_config_rss_hash_key_port_id,
1427                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1428                 (void *)&cmd_config_rss_hash_key_value,
1429                 NULL,
1430         },
1431 };
1432
1433 /* *** Configure RSS RETA *** */
1434 struct cmd_config_rss_reta {
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t keyword;
1437         uint8_t port_id;
1438         cmdline_fixed_string_t name;
1439         cmdline_fixed_string_t list_name;
1440         cmdline_fixed_string_t list_of_items;
1441 };
1442
1443 static int
1444 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
1445 {
1446         int i;
1447         unsigned size;
1448         uint8_t hash_index;
1449         uint8_t nb_queue;
1450         char s[256];
1451         const char *p, *p0 = str;
1452         char *end;
1453         enum fieldnames {
1454                 FLD_HASH_INDEX = 0,
1455                 FLD_QUEUE,
1456                 _NUM_FLD
1457         };
1458         unsigned long int_fld[_NUM_FLD];
1459         char *str_fld[_NUM_FLD];
1460
1461         while ((p = strchr(p0,'(')) != NULL) {
1462                 ++p;
1463                 if((p0 = strchr(p,')')) == NULL)
1464                         return -1;
1465
1466                 size = p0 - p;
1467                 if(size >= sizeof(s))
1468                         return -1;
1469
1470                 snprintf(s, sizeof(s), "%.*s", size, p);
1471                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1472                         return -1;
1473                 for (i = 0; i < _NUM_FLD; i++) {
1474                         errno = 0;
1475                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1476                         if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
1477                                 return -1;
1478                 }
1479
1480                 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX];
1481                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1482
1483                 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) {
1484                         printf("Invalid RETA hash index=%d",hash_index);
1485                         return -1;
1486                 }
1487
1488                 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2)
1489                         reta_conf->mask_lo |= (1ULL << hash_index);
1490                 else
1491                         reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2));
1492
1493                 reta_conf->reta[hash_index] = nb_queue;
1494         }
1495
1496         return 0;
1497 }
1498
1499 static void
1500 cmd_set_rss_reta_parsed(void *parsed_result,
1501                                 __attribute__((unused)) struct cmdline *cl,
1502                                 __attribute__((unused)) void *data)
1503 {
1504         int ret;
1505         struct rte_eth_rss_reta reta_conf;
1506         struct cmd_config_rss_reta *res = parsed_result;
1507
1508         memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta));
1509         if (!strcmp(res->list_name, "reta")) {
1510                 if (parse_reta_config(res->list_of_items, &reta_conf)) {
1511                         printf("Invalid RSS Redirection Table config entered\n");
1512                         return;
1513                 }
1514                 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf);
1515                 if (ret != 0)
1516                         printf("Bad redirection table parameter, return code = %d \n",ret);
1517         }
1518 }
1519
1520 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1521         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1522 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1523         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1524 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1525         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1526 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1527         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1528 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1529         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1530 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1531         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1532                                  NULL);
1533 cmdline_parse_inst_t cmd_config_rss_reta = {
1534         .f = cmd_set_rss_reta_parsed,
1535         .data = NULL,
1536         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1537         .tokens = {
1538                 (void *)&cmd_config_rss_reta_port,
1539                 (void *)&cmd_config_rss_reta_keyword,
1540                 (void *)&cmd_config_rss_reta_port_id,
1541                 (void *)&cmd_config_rss_reta_name,
1542                 (void *)&cmd_config_rss_reta_list_name,
1543                 (void *)&cmd_config_rss_reta_list_of_items,
1544                 NULL,
1545         },
1546 };
1547
1548 /* *** SHOW PORT RETA INFO *** */
1549 struct cmd_showport_reta {
1550         cmdline_fixed_string_t show;
1551         cmdline_fixed_string_t port;
1552         uint8_t port_id;
1553         cmdline_fixed_string_t rss;
1554         cmdline_fixed_string_t reta;
1555         uint64_t mask_lo;
1556         uint64_t mask_hi;
1557 };
1558
1559 static void cmd_showport_reta_parsed(void *parsed_result,
1560                                 __attribute__((unused)) struct cmdline *cl,
1561                                 __attribute__((unused)) void *data)
1562 {
1563         struct cmd_showport_reta *res = parsed_result;
1564         struct rte_eth_rss_reta reta_conf;
1565
1566         if ((res->mask_lo == 0) && (res->mask_hi == 0)) {
1567                 printf("Invalid RSS Redirection Table config entered\n");
1568                 return;
1569         }
1570
1571         reta_conf.mask_lo = res->mask_lo;
1572         reta_conf.mask_hi = res->mask_hi;
1573
1574         port_rss_reta_info(res->port_id,&reta_conf);
1575 }
1576
1577 cmdline_parse_token_string_t cmd_showport_reta_show =
1578         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1579 cmdline_parse_token_string_t cmd_showport_reta_port =
1580         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1581 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1582         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1583 cmdline_parse_token_string_t cmd_showport_reta_rss =
1584         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1585 cmdline_parse_token_string_t cmd_showport_reta_reta =
1586         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1587 cmdline_parse_token_num_t cmd_showport_reta_mask_lo =
1588         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64);
1589 cmdline_parse_token_num_t cmd_showport_reta_mask_hi =
1590         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64);
1591
1592 cmdline_parse_inst_t cmd_showport_reta = {
1593         .f = cmd_showport_reta_parsed,
1594         .data = NULL,
1595         .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\
1596                         (mask_lo and mask_hi is UINT64)",
1597         .tokens = {
1598                 (void *)&cmd_showport_reta_show,
1599                 (void *)&cmd_showport_reta_port,
1600                 (void *)&cmd_showport_reta_port_id,
1601                 (void *)&cmd_showport_reta_rss,
1602                 (void *)&cmd_showport_reta_reta,
1603                 (void *)&cmd_showport_reta_mask_lo,
1604                 (void *)&cmd_showport_reta_mask_hi,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** Show RSS hash configuration *** */
1610 struct cmd_showport_rss_hash {
1611         cmdline_fixed_string_t show;
1612         cmdline_fixed_string_t port;
1613         uint8_t port_id;
1614         cmdline_fixed_string_t rss_hash;
1615         cmdline_fixed_string_t key; /* optional argument */
1616 };
1617
1618 static void cmd_showport_rss_hash_parsed(void *parsed_result,
1619                                 __attribute__((unused)) struct cmdline *cl,
1620                                 void *show_rss_key)
1621 {
1622         struct cmd_showport_rss_hash *res = parsed_result;
1623
1624         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
1625 }
1626
1627 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
1628         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
1629 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
1630         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
1631 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
1633 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
1634         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
1635                                  "rss-hash");
1636 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
1637         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
1638
1639 cmdline_parse_inst_t cmd_showport_rss_hash = {
1640         .f = cmd_showport_rss_hash_parsed,
1641         .data = NULL,
1642         .help_str = "show port X rss-hash (X = port number)\n",
1643         .tokens = {
1644                 (void *)&cmd_showport_rss_hash_show,
1645                 (void *)&cmd_showport_rss_hash_port,
1646                 (void *)&cmd_showport_rss_hash_port_id,
1647                 (void *)&cmd_showport_rss_hash_rss_hash,
1648                 NULL,
1649         },
1650 };
1651
1652 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
1653         .f = cmd_showport_rss_hash_parsed,
1654         .data = (void *)1,
1655         .help_str = "show port X rss-hash key (X = port number)\n",
1656         .tokens = {
1657                 (void *)&cmd_showport_rss_hash_show,
1658                 (void *)&cmd_showport_rss_hash_port,
1659                 (void *)&cmd_showport_rss_hash_port_id,
1660                 (void *)&cmd_showport_rss_hash_rss_hash,
1661                 (void *)&cmd_showport_rss_hash_rss_key,
1662                 NULL,
1663         },
1664 };
1665
1666 /* *** Configure DCB *** */
1667 struct cmd_config_dcb {
1668         cmdline_fixed_string_t port;
1669         cmdline_fixed_string_t config;
1670         uint8_t port_id;
1671         cmdline_fixed_string_t dcb;
1672         cmdline_fixed_string_t vt;
1673         cmdline_fixed_string_t vt_en;
1674         uint8_t num_tcs;
1675         cmdline_fixed_string_t pfc;
1676         cmdline_fixed_string_t pfc_en;
1677 };
1678
1679 static void
1680 cmd_config_dcb_parsed(void *parsed_result,
1681                         __attribute__((unused)) struct cmdline *cl,
1682                         __attribute__((unused)) void *data)
1683 {
1684         struct cmd_config_dcb *res = parsed_result;
1685         struct dcb_config dcb_conf;
1686         portid_t port_id = res->port_id;
1687         struct rte_port *port;
1688
1689         port = &ports[port_id];
1690         /** Check if the port is not started **/
1691         if (port->port_status != RTE_PORT_STOPPED) {
1692                 printf("Please stop port %d first\n",port_id);
1693                 return;
1694         }
1695
1696         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
1697         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
1698                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
1699                 return;
1700         }
1701
1702         /* DCB in VT mode */
1703         if (!strncmp(res->vt_en, "on",2))
1704                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
1705         else
1706                 dcb_conf.dcb_mode = DCB_ENABLED;
1707
1708         if (!strncmp(res->pfc_en, "on",2)) {
1709                 dcb_conf.pfc_en = 1;
1710         }
1711         else
1712                 dcb_conf.pfc_en = 0;
1713
1714         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
1715                 printf("Cannot initialize network ports\n");
1716                 return;
1717         }
1718
1719         cmd_reconfig_device_queue(port_id, 1, 1);
1720 }
1721
1722 cmdline_parse_token_string_t cmd_config_dcb_port =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
1724 cmdline_parse_token_string_t cmd_config_dcb_config =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
1726 cmdline_parse_token_num_t cmd_config_dcb_port_id =
1727         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
1728 cmdline_parse_token_string_t cmd_config_dcb_dcb =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
1730 cmdline_parse_token_string_t cmd_config_dcb_vt =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
1732 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
1734 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
1735         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
1736 cmdline_parse_token_string_t cmd_config_dcb_pfc=
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
1738 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
1740
1741 cmdline_parse_inst_t cmd_config_dcb = {
1742         .f = cmd_config_dcb_parsed,
1743         .data = NULL,
1744         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
1745         .tokens = {
1746                 (void *)&cmd_config_dcb_port,
1747                 (void *)&cmd_config_dcb_config,
1748                 (void *)&cmd_config_dcb_port_id,
1749                 (void *)&cmd_config_dcb_dcb,
1750                 (void *)&cmd_config_dcb_vt,
1751                 (void *)&cmd_config_dcb_vt_en,
1752                 (void *)&cmd_config_dcb_num_tcs,
1753                 (void *)&cmd_config_dcb_pfc,
1754                 (void *)&cmd_config_dcb_pfc_en,
1755                 NULL,
1756         },
1757 };
1758
1759 /* *** configure number of packets per burst *** */
1760 struct cmd_config_burst {
1761         cmdline_fixed_string_t port;
1762         cmdline_fixed_string_t keyword;
1763         cmdline_fixed_string_t all;
1764         cmdline_fixed_string_t name;
1765         uint16_t value;
1766 };
1767
1768 static void
1769 cmd_config_burst_parsed(void *parsed_result,
1770                         __attribute__((unused)) struct cmdline *cl,
1771                         __attribute__((unused)) void *data)
1772 {
1773         struct cmd_config_burst *res = parsed_result;
1774
1775         if (!all_ports_stopped()) {
1776                 printf("Please stop all ports first\n");
1777                 return;
1778         }
1779
1780         if (!strcmp(res->name, "burst")) {
1781                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
1782                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
1783                         return;
1784                 }
1785                 nb_pkt_per_burst = res->value;
1786         } else {
1787                 printf("Unknown parameter\n");
1788                 return;
1789         }
1790
1791         init_port_config();
1792
1793         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1794 }
1795
1796 cmdline_parse_token_string_t cmd_config_burst_port =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
1798 cmdline_parse_token_string_t cmd_config_burst_keyword =
1799         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
1800 cmdline_parse_token_string_t cmd_config_burst_all =
1801         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
1802 cmdline_parse_token_string_t cmd_config_burst_name =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
1804 cmdline_parse_token_num_t cmd_config_burst_value =
1805         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
1806
1807 cmdline_parse_inst_t cmd_config_burst = {
1808         .f = cmd_config_burst_parsed,
1809         .data = NULL,
1810         .help_str = "port config all burst value",
1811         .tokens = {
1812                 (void *)&cmd_config_burst_port,
1813                 (void *)&cmd_config_burst_keyword,
1814                 (void *)&cmd_config_burst_all,
1815                 (void *)&cmd_config_burst_name,
1816                 (void *)&cmd_config_burst_value,
1817                 NULL,
1818         },
1819 };
1820
1821 /* *** configure rx/tx queues *** */
1822 struct cmd_config_thresh {
1823         cmdline_fixed_string_t port;
1824         cmdline_fixed_string_t keyword;
1825         cmdline_fixed_string_t all;
1826         cmdline_fixed_string_t name;
1827         uint8_t value;
1828 };
1829
1830 static void
1831 cmd_config_thresh_parsed(void *parsed_result,
1832                         __attribute__((unused)) struct cmdline *cl,
1833                         __attribute__((unused)) void *data)
1834 {
1835         struct cmd_config_thresh *res = parsed_result;
1836
1837         if (!all_ports_stopped()) {
1838                 printf("Please stop all ports first\n");
1839                 return;
1840         }
1841
1842         if (!strcmp(res->name, "txpt"))
1843                 tx_thresh.pthresh = res->value;
1844         else if(!strcmp(res->name, "txht"))
1845                 tx_thresh.hthresh = res->value;
1846         else if(!strcmp(res->name, "txwt"))
1847                 tx_thresh.wthresh = res->value;
1848         else if(!strcmp(res->name, "rxpt"))
1849                 rx_thresh.pthresh = res->value;
1850         else if(!strcmp(res->name, "rxht"))
1851                 rx_thresh.hthresh = res->value;
1852         else if(!strcmp(res->name, "rxwt"))
1853                 rx_thresh.wthresh = res->value;
1854         else {
1855                 printf("Unknown parameter\n");
1856                 return;
1857         }
1858
1859         init_port_config();
1860
1861         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1862 }
1863
1864 cmdline_parse_token_string_t cmd_config_thresh_port =
1865         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
1866 cmdline_parse_token_string_t cmd_config_thresh_keyword =
1867         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
1868 cmdline_parse_token_string_t cmd_config_thresh_all =
1869         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
1870 cmdline_parse_token_string_t cmd_config_thresh_name =
1871         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
1872                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
1873 cmdline_parse_token_num_t cmd_config_thresh_value =
1874         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
1875
1876 cmdline_parse_inst_t cmd_config_thresh = {
1877         .f = cmd_config_thresh_parsed,
1878         .data = NULL,
1879         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
1880         .tokens = {
1881                 (void *)&cmd_config_thresh_port,
1882                 (void *)&cmd_config_thresh_keyword,
1883                 (void *)&cmd_config_thresh_all,
1884                 (void *)&cmd_config_thresh_name,
1885                 (void *)&cmd_config_thresh_value,
1886                 NULL,
1887         },
1888 };
1889
1890 /* *** configure free/rs threshold *** */
1891 struct cmd_config_threshold {
1892         cmdline_fixed_string_t port;
1893         cmdline_fixed_string_t keyword;
1894         cmdline_fixed_string_t all;
1895         cmdline_fixed_string_t name;
1896         uint16_t value;
1897 };
1898
1899 static void
1900 cmd_config_threshold_parsed(void *parsed_result,
1901                         __attribute__((unused)) struct cmdline *cl,
1902                         __attribute__((unused)) void *data)
1903 {
1904         struct cmd_config_threshold *res = parsed_result;
1905
1906         if (!all_ports_stopped()) {
1907                 printf("Please stop all ports first\n");
1908                 return;
1909         }
1910
1911         if (!strcmp(res->name, "txfreet"))
1912                 tx_free_thresh = res->value;
1913         else if (!strcmp(res->name, "txrst"))
1914                 tx_rs_thresh = res->value;
1915         else if (!strcmp(res->name, "rxfreet"))
1916                 rx_free_thresh = res->value;
1917         else {
1918                 printf("Unknown parameter\n");
1919                 return;
1920         }
1921
1922         init_port_config();
1923
1924         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1925 }
1926
1927 cmdline_parse_token_string_t cmd_config_threshold_port =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
1929 cmdline_parse_token_string_t cmd_config_threshold_keyword =
1930         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
1931                                                                 "config");
1932 cmdline_parse_token_string_t cmd_config_threshold_all =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
1934 cmdline_parse_token_string_t cmd_config_threshold_name =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
1936                                                 "txfreet#txrst#rxfreet");
1937 cmdline_parse_token_num_t cmd_config_threshold_value =
1938         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
1939
1940 cmdline_parse_inst_t cmd_config_threshold = {
1941         .f = cmd_config_threshold_parsed,
1942         .data = NULL,
1943         .help_str = "port config all txfreet|txrst|rxfreet value",
1944         .tokens = {
1945                 (void *)&cmd_config_threshold_port,
1946                 (void *)&cmd_config_threshold_keyword,
1947                 (void *)&cmd_config_threshold_all,
1948                 (void *)&cmd_config_threshold_name,
1949                 (void *)&cmd_config_threshold_value,
1950                 NULL,
1951         },
1952 };
1953
1954 /* *** stop *** */
1955 struct cmd_stop_result {
1956         cmdline_fixed_string_t stop;
1957 };
1958
1959 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
1960                             __attribute__((unused)) struct cmdline *cl,
1961                             __attribute__((unused)) void *data)
1962 {
1963         stop_packet_forwarding();
1964 }
1965
1966 cmdline_parse_token_string_t cmd_stop_stop =
1967         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
1968
1969 cmdline_parse_inst_t cmd_stop = {
1970         .f = cmd_stop_parsed,
1971         .data = NULL,
1972         .help_str = "stop - stop packet forwarding",
1973         .tokens = {
1974                 (void *)&cmd_stop_stop,
1975                 NULL,
1976         },
1977 };
1978
1979 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
1980
1981 static unsigned int
1982 parse_item_list(char* str, const char* item_name, unsigned int max_items,
1983                 unsigned int *parsed_items, int check_unique_values)
1984 {
1985         unsigned int nb_item;
1986         unsigned int value;
1987         unsigned int i;
1988         unsigned int j;
1989         int value_ok;
1990         char c;
1991
1992         /*
1993          * First parse all items in the list and store their value.
1994          */
1995         value = 0;
1996         nb_item = 0;
1997         value_ok = 0;
1998         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
1999                 c = str[i];
2000                 if ((c >= '0') && (c <= '9')) {
2001                         value = (unsigned int) (value * 10 + (c - '0'));
2002                         value_ok = 1;
2003                         continue;
2004                 }
2005                 if (c != ',') {
2006                         printf("character %c is not a decimal digit\n", c);
2007                         return (0);
2008                 }
2009                 if (! value_ok) {
2010                         printf("No valid value before comma\n");
2011                         return (0);
2012                 }
2013                 if (nb_item < max_items) {
2014                         parsed_items[nb_item] = value;
2015                         value_ok = 0;
2016                         value = 0;
2017                 }
2018                 nb_item++;
2019         }
2020         if (nb_item >= max_items) {
2021                 printf("Number of %s = %u > %u (maximum items)\n",
2022                        item_name, nb_item + 1, max_items);
2023                 return (0);
2024         }
2025         parsed_items[nb_item++] = value;
2026         if (! check_unique_values)
2027                 return (nb_item);
2028
2029         /*
2030          * Then, check that all values in the list are differents.
2031          * No optimization here...
2032          */
2033         for (i = 0; i < nb_item; i++) {
2034                 for (j = i + 1; j < nb_item; j++) {
2035                         if (parsed_items[j] == parsed_items[i]) {
2036                                 printf("duplicated %s %u at index %u and %u\n",
2037                                        item_name, parsed_items[i], i, j);
2038                                 return (0);
2039                         }
2040                 }
2041         }
2042         return (nb_item);
2043 }
2044
2045 struct cmd_set_list_result {
2046         cmdline_fixed_string_t cmd_keyword;
2047         cmdline_fixed_string_t list_name;
2048         cmdline_fixed_string_t list_of_items;
2049 };
2050
2051 static void cmd_set_list_parsed(void *parsed_result,
2052                                 __attribute__((unused)) struct cmdline *cl,
2053                                 __attribute__((unused)) void *data)
2054 {
2055         struct cmd_set_list_result *res;
2056         union {
2057                 unsigned int lcorelist[RTE_MAX_LCORE];
2058                 unsigned int portlist[RTE_MAX_ETHPORTS];
2059         } parsed_items;
2060         unsigned int nb_item;
2061
2062         res = parsed_result;
2063         if (!strcmp(res->list_name, "corelist")) {
2064                 nb_item = parse_item_list(res->list_of_items, "core",
2065                                           RTE_MAX_LCORE,
2066                                           parsed_items.lcorelist, 1);
2067                 if (nb_item > 0)
2068                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2069                 return;
2070         }
2071         if (!strcmp(res->list_name, "portlist")) {
2072                 nb_item = parse_item_list(res->list_of_items, "port",
2073                                           RTE_MAX_ETHPORTS,
2074                                           parsed_items.portlist, 1);
2075                 if (nb_item > 0)
2076                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2077         }
2078 }
2079
2080 cmdline_parse_token_string_t cmd_set_list_keyword =
2081         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2082                                  "set");
2083 cmdline_parse_token_string_t cmd_set_list_name =
2084         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2085                                  "corelist#portlist");
2086 cmdline_parse_token_string_t cmd_set_list_of_items =
2087         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2088                                  NULL);
2089
2090 cmdline_parse_inst_t cmd_set_fwd_list = {
2091         .f = cmd_set_list_parsed,
2092         .data = NULL,
2093         .help_str = "set corelist|portlist x[,y]*",
2094         .tokens = {
2095                 (void *)&cmd_set_list_keyword,
2096                 (void *)&cmd_set_list_name,
2097                 (void *)&cmd_set_list_of_items,
2098                 NULL,
2099         },
2100 };
2101
2102 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2103
2104 struct cmd_setmask_result {
2105         cmdline_fixed_string_t set;
2106         cmdline_fixed_string_t mask;
2107         uint64_t hexavalue;
2108 };
2109
2110 static void cmd_set_mask_parsed(void *parsed_result,
2111                                 __attribute__((unused)) struct cmdline *cl,
2112                                 __attribute__((unused)) void *data)
2113 {
2114         struct cmd_setmask_result *res = parsed_result;
2115
2116         if (!strcmp(res->mask, "coremask"))
2117                 set_fwd_lcores_mask(res->hexavalue);
2118         else if (!strcmp(res->mask, "portmask"))
2119                 set_fwd_ports_mask(res->hexavalue);
2120 }
2121
2122 cmdline_parse_token_string_t cmd_setmask_set =
2123         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2124 cmdline_parse_token_string_t cmd_setmask_mask =
2125         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2126                                  "coremask#portmask");
2127 cmdline_parse_token_num_t cmd_setmask_value =
2128         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2129
2130 cmdline_parse_inst_t cmd_set_fwd_mask = {
2131         .f = cmd_set_mask_parsed,
2132         .data = NULL,
2133         .help_str = "set coremask|portmask hexadecimal value",
2134         .tokens = {
2135                 (void *)&cmd_setmask_set,
2136                 (void *)&cmd_setmask_mask,
2137                 (void *)&cmd_setmask_value,
2138                 NULL,
2139         },
2140 };
2141
2142 /*
2143  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2144  */
2145 struct cmd_set_result {
2146         cmdline_fixed_string_t set;
2147         cmdline_fixed_string_t what;
2148         uint16_t value;
2149 };
2150
2151 static void cmd_set_parsed(void *parsed_result,
2152                            __attribute__((unused)) struct cmdline *cl,
2153                            __attribute__((unused)) void *data)
2154 {
2155         struct cmd_set_result *res = parsed_result;
2156         if (!strcmp(res->what, "nbport"))
2157                 set_fwd_ports_number(res->value);
2158         else if (!strcmp(res->what, "nbcore"))
2159                 set_fwd_lcores_number(res->value);
2160         else if (!strcmp(res->what, "burst"))
2161                 set_nb_pkt_per_burst(res->value);
2162         else if (!strcmp(res->what, "verbose"))
2163                 set_verbose_level(res->value);
2164 }
2165
2166 cmdline_parse_token_string_t cmd_set_set =
2167         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2168 cmdline_parse_token_string_t cmd_set_what =
2169         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2170                                  "nbport#nbcore#burst#verbose");
2171 cmdline_parse_token_num_t cmd_set_value =
2172         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2173
2174 cmdline_parse_inst_t cmd_set_numbers = {
2175         .f = cmd_set_parsed,
2176         .data = NULL,
2177         .help_str = "set nbport|nbcore|burst|verbose value",
2178         .tokens = {
2179                 (void *)&cmd_set_set,
2180                 (void *)&cmd_set_what,
2181                 (void *)&cmd_set_value,
2182                 NULL,
2183         },
2184 };
2185
2186 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2187
2188 struct cmd_set_txpkts_result {
2189         cmdline_fixed_string_t cmd_keyword;
2190         cmdline_fixed_string_t txpkts;
2191         cmdline_fixed_string_t seg_lengths;
2192 };
2193
2194 static void
2195 cmd_set_txpkts_parsed(void *parsed_result,
2196                       __attribute__((unused)) struct cmdline *cl,
2197                       __attribute__((unused)) void *data)
2198 {
2199         struct cmd_set_txpkts_result *res;
2200         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2201         unsigned int nb_segs;
2202
2203         res = parsed_result;
2204         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2205                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2206         if (nb_segs > 0)
2207                 set_tx_pkt_segments(seg_lengths, nb_segs);
2208 }
2209
2210 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2211         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2212                                  cmd_keyword, "set");
2213 cmdline_parse_token_string_t cmd_set_txpkts_name =
2214         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2215                                  txpkts, "txpkts");
2216 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2217         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2218                                  seg_lengths, NULL);
2219
2220 cmdline_parse_inst_t cmd_set_txpkts = {
2221         .f = cmd_set_txpkts_parsed,
2222         .data = NULL,
2223         .help_str = "set txpkts x[,y]*",
2224         .tokens = {
2225                 (void *)&cmd_set_txpkts_keyword,
2226                 (void *)&cmd_set_txpkts_name,
2227                 (void *)&cmd_set_txpkts_lengths,
2228                 NULL,
2229         },
2230 };
2231
2232 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2233 struct cmd_rx_vlan_filter_all_result {
2234         cmdline_fixed_string_t rx_vlan;
2235         cmdline_fixed_string_t what;
2236         cmdline_fixed_string_t all;
2237         uint8_t port_id;
2238 };
2239
2240 static void
2241 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2242                               __attribute__((unused)) struct cmdline *cl,
2243                               __attribute__((unused)) void *data)
2244 {
2245         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2246
2247         if (!strcmp(res->what, "add"))
2248                 rx_vlan_all_filter_set(res->port_id, 1);
2249         else
2250                 rx_vlan_all_filter_set(res->port_id, 0);
2251 }
2252
2253 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2254         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2255                                  rx_vlan, "rx_vlan");
2256 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2257         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2258                                  what, "add#rm");
2259 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2260         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2261                                  all, "all");
2262 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2263         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2264                               port_id, UINT8);
2265
2266 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2267         .f = cmd_rx_vlan_filter_all_parsed,
2268         .data = NULL,
2269         .help_str = "add/remove all identifiers to/from the set of VLAN "
2270         "Identifiers filtered by a port",
2271         .tokens = {
2272                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2273                 (void *)&cmd_rx_vlan_filter_all_what,
2274                 (void *)&cmd_rx_vlan_filter_all_all,
2275                 (void *)&cmd_rx_vlan_filter_all_portid,
2276                 NULL,
2277         },
2278 };
2279
2280 /* *** VLAN OFFLOAD SET ON A PORT *** */
2281 struct cmd_vlan_offload_result {
2282         cmdline_fixed_string_t vlan;
2283         cmdline_fixed_string_t set;
2284         cmdline_fixed_string_t what;
2285         cmdline_fixed_string_t on;
2286         cmdline_fixed_string_t port_id;
2287 };
2288
2289 static void
2290 cmd_vlan_offload_parsed(void *parsed_result,
2291                           __attribute__((unused)) struct cmdline *cl,
2292                           __attribute__((unused)) void *data)
2293 {
2294         int on;
2295         struct cmd_vlan_offload_result *res = parsed_result;
2296         char *str;
2297         int i, len = 0;
2298         portid_t port_id = 0;
2299         unsigned int tmp;
2300
2301         str = res->port_id;
2302         len = strnlen(str, STR_TOKEN_SIZE);
2303         i = 0;
2304         /* Get port_id first */
2305         while(i < len){
2306                 if(str[i] == ',')
2307                         break;
2308
2309                 i++;
2310         }
2311         str[i]='\0';
2312         tmp = strtoul(str, NULL, 0);
2313         /* If port_id greater that what portid_t can represent, return */
2314         if(tmp >= RTE_MAX_ETHPORTS)
2315                 return;
2316         port_id = (portid_t)tmp;
2317
2318         if (!strcmp(res->on, "on"))
2319                 on = 1;
2320         else
2321                 on = 0;
2322
2323         if (!strcmp(res->what, "strip"))
2324                 rx_vlan_strip_set(port_id,  on);
2325         else if(!strcmp(res->what, "stripq")){
2326                 uint16_t queue_id = 0;
2327
2328                 /* No queue_id, return */
2329                 if(i + 1 >= len) {
2330                         printf("must specify (port,queue_id)\n");
2331                         return;
2332                 }
2333                 tmp = strtoul(str + i + 1, NULL, 0);
2334                 /* If queue_id greater that what 16-bits can represent, return */
2335                 if(tmp > 0xffff)
2336                         return;
2337
2338                 queue_id = (uint16_t)tmp;
2339                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2340         }
2341         else if (!strcmp(res->what, "filter"))
2342                 rx_vlan_filter_set(port_id, on);
2343         else
2344                 vlan_extend_set(port_id, on);
2345
2346         return;
2347 }
2348
2349 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2350         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2351                                  vlan, "vlan");
2352 cmdline_parse_token_string_t cmd_vlan_offload_set =
2353         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2354                                  set, "set");
2355 cmdline_parse_token_string_t cmd_vlan_offload_what =
2356         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2357                                  what, "strip#filter#qinq#stripq");
2358 cmdline_parse_token_string_t cmd_vlan_offload_on =
2359         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2360                               on, "on#off");
2361 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2362         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2363                               port_id, NULL);
2364
2365 cmdline_parse_inst_t cmd_vlan_offload = {
2366         .f = cmd_vlan_offload_parsed,
2367         .data = NULL,
2368         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2369         " qinq(extended) for both rx/tx sides ",
2370         .tokens = {
2371                 (void *)&cmd_vlan_offload_vlan,
2372                 (void *)&cmd_vlan_offload_set,
2373                 (void *)&cmd_vlan_offload_what,
2374                 (void *)&cmd_vlan_offload_on,
2375                 (void *)&cmd_vlan_offload_portid,
2376                 NULL,
2377         },
2378 };
2379
2380 /* *** VLAN TPID SET ON A PORT *** */
2381 struct cmd_vlan_tpid_result {
2382         cmdline_fixed_string_t vlan;
2383         cmdline_fixed_string_t set;
2384         cmdline_fixed_string_t what;
2385         uint16_t tp_id;
2386         uint8_t port_id;
2387 };
2388
2389 static void
2390 cmd_vlan_tpid_parsed(void *parsed_result,
2391                           __attribute__((unused)) struct cmdline *cl,
2392                           __attribute__((unused)) void *data)
2393 {
2394         struct cmd_vlan_tpid_result *res = parsed_result;
2395         vlan_tpid_set(res->port_id, res->tp_id);
2396         return;
2397 }
2398
2399 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2400         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2401                                  vlan, "vlan");
2402 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2403         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2404                                  set, "set");
2405 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2406         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2407                                  what, "tpid");
2408 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2409         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2410                               tp_id, UINT16);
2411 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2412         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2413                               port_id, UINT8);
2414
2415 cmdline_parse_inst_t cmd_vlan_tpid = {
2416         .f = cmd_vlan_tpid_parsed,
2417         .data = NULL,
2418         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2419         .tokens = {
2420                 (void *)&cmd_vlan_tpid_vlan,
2421                 (void *)&cmd_vlan_tpid_set,
2422                 (void *)&cmd_vlan_tpid_what,
2423                 (void *)&cmd_vlan_tpid_tpid,
2424                 (void *)&cmd_vlan_tpid_portid,
2425                 NULL,
2426         },
2427 };
2428
2429 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2430 struct cmd_rx_vlan_filter_result {
2431         cmdline_fixed_string_t rx_vlan;
2432         cmdline_fixed_string_t what;
2433         uint16_t vlan_id;
2434         uint8_t port_id;
2435 };
2436
2437 static void
2438 cmd_rx_vlan_filter_parsed(void *parsed_result,
2439                           __attribute__((unused)) struct cmdline *cl,
2440                           __attribute__((unused)) void *data)
2441 {
2442         struct cmd_rx_vlan_filter_result *res = parsed_result;
2443
2444         if (!strcmp(res->what, "add"))
2445                 rx_vft_set(res->port_id, res->vlan_id, 1);
2446         else
2447                 rx_vft_set(res->port_id, res->vlan_id, 0);
2448 }
2449
2450 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2451         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2452                                  rx_vlan, "rx_vlan");
2453 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2454         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2455                                  what, "add#rm");
2456 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2457         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2458                               vlan_id, UINT16);
2459 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2460         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2461                               port_id, UINT8);
2462
2463 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2464         .f = cmd_rx_vlan_filter_parsed,
2465         .data = NULL,
2466         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2467         "Identifiers filtered by a port",
2468         .tokens = {
2469                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2470                 (void *)&cmd_rx_vlan_filter_what,
2471                 (void *)&cmd_rx_vlan_filter_vlanid,
2472                 (void *)&cmd_rx_vlan_filter_portid,
2473                 NULL,
2474         },
2475 };
2476
2477 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2478 struct cmd_tx_vlan_set_result {
2479         cmdline_fixed_string_t tx_vlan;
2480         cmdline_fixed_string_t set;
2481         uint16_t vlan_id;
2482         uint8_t port_id;
2483 };
2484
2485 static void
2486 cmd_tx_vlan_set_parsed(void *parsed_result,
2487                        __attribute__((unused)) struct cmdline *cl,
2488                        __attribute__((unused)) void *data)
2489 {
2490         struct cmd_tx_vlan_set_result *res = parsed_result;
2491         tx_vlan_set(res->port_id, res->vlan_id);
2492 }
2493
2494 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2495         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2496                                  tx_vlan, "tx_vlan");
2497 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2498         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2499                                  set, "set");
2500 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2501         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2502                               vlan_id, UINT16);
2503 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2504         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2505                               port_id, UINT8);
2506
2507 cmdline_parse_inst_t cmd_tx_vlan_set = {
2508         .f = cmd_tx_vlan_set_parsed,
2509         .data = NULL,
2510         .help_str = "enable hardware insertion of a VLAN header with a given "
2511         "TAG Identifier in packets sent on a port",
2512         .tokens = {
2513                 (void *)&cmd_tx_vlan_set_tx_vlan,
2514                 (void *)&cmd_tx_vlan_set_set,
2515                 (void *)&cmd_tx_vlan_set_vlanid,
2516                 (void *)&cmd_tx_vlan_set_portid,
2517                 NULL,
2518         },
2519 };
2520
2521 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
2522 struct cmd_tx_vlan_set_pvid_result {
2523         cmdline_fixed_string_t tx_vlan;
2524         cmdline_fixed_string_t set;
2525         cmdline_fixed_string_t pvid;
2526         uint8_t port_id;
2527         uint16_t vlan_id;
2528         cmdline_fixed_string_t mode;
2529 };
2530
2531 static void
2532 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
2533                             __attribute__((unused)) struct cmdline *cl,
2534                             __attribute__((unused)) void *data)
2535 {
2536         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
2537
2538         if (strcmp(res->mode, "on") == 0)
2539                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
2540         else
2541                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
2542 }
2543
2544 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
2545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2546                                  tx_vlan, "tx_vlan");
2547 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
2548         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2549                                  set, "set");
2550 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
2551         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2552                                  pvid, "pvid");
2553 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
2554         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2555                              port_id, UINT8);
2556 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
2557         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2558                               vlan_id, UINT16);
2559 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
2560         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2561                                  mode, "on#off");
2562
2563 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
2564         .f = cmd_tx_vlan_set_pvid_parsed,
2565         .data = NULL,
2566         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
2567         .tokens = {
2568                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
2569                 (void *)&cmd_tx_vlan_set_pvid_set,
2570                 (void *)&cmd_tx_vlan_set_pvid_pvid,
2571                 (void *)&cmd_tx_vlan_set_pvid_port_id,
2572                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
2573                 (void *)&cmd_tx_vlan_set_pvid_mode,
2574                 NULL,
2575         },
2576 };
2577
2578 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2579 struct cmd_tx_vlan_reset_result {
2580         cmdline_fixed_string_t tx_vlan;
2581         cmdline_fixed_string_t reset;
2582         uint8_t port_id;
2583 };
2584
2585 static void
2586 cmd_tx_vlan_reset_parsed(void *parsed_result,
2587                          __attribute__((unused)) struct cmdline *cl,
2588                          __attribute__((unused)) void *data)
2589 {
2590         struct cmd_tx_vlan_reset_result *res = parsed_result;
2591
2592         tx_vlan_reset(res->port_id);
2593 }
2594
2595 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2596         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2597                                  tx_vlan, "tx_vlan");
2598 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2599         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2600                                  reset, "reset");
2601 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2602         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2603                               port_id, UINT8);
2604
2605 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2606         .f = cmd_tx_vlan_reset_parsed,
2607         .data = NULL,
2608         .help_str = "disable hardware insertion of a VLAN header in packets "
2609         "sent on a port",
2610         .tokens = {
2611                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2612                 (void *)&cmd_tx_vlan_reset_reset,
2613                 (void *)&cmd_tx_vlan_reset_portid,
2614                 NULL,
2615         },
2616 };
2617
2618
2619 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
2620 struct cmd_tx_cksum_set_result {
2621         cmdline_fixed_string_t tx_cksum;
2622         cmdline_fixed_string_t set;
2623         uint8_t cksum_mask;
2624         uint8_t port_id;
2625 };
2626
2627 static void
2628 cmd_tx_cksum_set_parsed(void *parsed_result,
2629                        __attribute__((unused)) struct cmdline *cl,
2630                        __attribute__((unused)) void *data)
2631 {
2632         struct cmd_tx_cksum_set_result *res = parsed_result;
2633
2634         tx_cksum_set(res->port_id, res->cksum_mask);
2635 }
2636
2637 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum =
2638         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2639                                 tx_cksum, "tx_checksum");
2640 cmdline_parse_token_string_t cmd_tx_cksum_set_set =
2641         TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result,
2642                                 set, "set");
2643 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask =
2644         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2645                                 cksum_mask, UINT8);
2646 cmdline_parse_token_num_t cmd_tx_cksum_set_portid =
2647         TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result,
2648                                 port_id, UINT8);
2649
2650 cmdline_parse_inst_t cmd_tx_cksum_set = {
2651         .f = cmd_tx_cksum_set_parsed,
2652         .data = NULL,
2653         .help_str = "enable hardware insertion of L3/L4checksum with a given "
2654         "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip"
2655         "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP",
2656         .tokens = {
2657                 (void *)&cmd_tx_cksum_set_tx_cksum,
2658                 (void *)&cmd_tx_cksum_set_set,
2659                 (void *)&cmd_tx_cksum_set_cksum_mask,
2660                 (void *)&cmd_tx_cksum_set_portid,
2661                 NULL,
2662         },
2663 };
2664
2665 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
2666 struct cmd_set_flush_rx {
2667         cmdline_fixed_string_t set;
2668         cmdline_fixed_string_t flush_rx;
2669         cmdline_fixed_string_t mode;
2670 };
2671
2672 static void
2673 cmd_set_flush_rx_parsed(void *parsed_result,
2674                 __attribute__((unused)) struct cmdline *cl,
2675                 __attribute__((unused)) void *data)
2676 {
2677         struct cmd_set_flush_rx *res = parsed_result;
2678         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2679 }
2680
2681 cmdline_parse_token_string_t cmd_setflushrx_set =
2682         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2683                         set, "set");
2684 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
2685         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2686                         flush_rx, "flush_rx");
2687 cmdline_parse_token_string_t cmd_setflushrx_mode =
2688         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
2689                         mode, "on#off");
2690
2691
2692 cmdline_parse_inst_t cmd_set_flush_rx = {
2693         .f = cmd_set_flush_rx_parsed,
2694         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
2695         .data = NULL,
2696         .tokens = {
2697                 (void *)&cmd_setflushrx_set,
2698                 (void *)&cmd_setflushrx_flush_rx,
2699                 (void *)&cmd_setflushrx_mode,
2700                 NULL,
2701         },
2702 };
2703
2704 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
2705 struct cmd_set_link_check {
2706         cmdline_fixed_string_t set;
2707         cmdline_fixed_string_t link_check;
2708         cmdline_fixed_string_t mode;
2709 };
2710
2711 static void
2712 cmd_set_link_check_parsed(void *parsed_result,
2713                 __attribute__((unused)) struct cmdline *cl,
2714                 __attribute__((unused)) void *data)
2715 {
2716         struct cmd_set_link_check *res = parsed_result;
2717         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
2718 }
2719
2720 cmdline_parse_token_string_t cmd_setlinkcheck_set =
2721         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2722                         set, "set");
2723 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
2724         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2725                         link_check, "link_check");
2726 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
2727         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
2728                         mode, "on#off");
2729
2730
2731 cmdline_parse_inst_t cmd_set_link_check = {
2732         .f = cmd_set_link_check_parsed,
2733         .help_str = "set link_check on|off: enable/disable link status check "
2734                     "when starting/stopping a port",
2735         .data = NULL,
2736         .tokens = {
2737                 (void *)&cmd_setlinkcheck_set,
2738                 (void *)&cmd_setlinkcheck_link_check,
2739                 (void *)&cmd_setlinkcheck_mode,
2740                 NULL,
2741         },
2742 };
2743
2744 #ifdef RTE_NIC_BYPASS
2745 /* *** SET NIC BYPASS MODE *** */
2746 struct cmd_set_bypass_mode_result {
2747         cmdline_fixed_string_t set;
2748         cmdline_fixed_string_t bypass;
2749         cmdline_fixed_string_t mode;
2750         cmdline_fixed_string_t value;
2751         uint8_t port_id;
2752 };
2753
2754 static void
2755 cmd_set_bypass_mode_parsed(void *parsed_result,
2756                 __attribute__((unused)) struct cmdline *cl,
2757                 __attribute__((unused)) void *data)
2758 {
2759         struct cmd_set_bypass_mode_result *res = parsed_result;
2760         portid_t port_id = res->port_id;
2761         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2762
2763         if (!bypass_is_supported(port_id))
2764                 return;
2765
2766         if (!strcmp(res->value, "bypass"))
2767                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2768         else if (!strcmp(res->value, "isolate"))
2769                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2770         else
2771                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2772
2773         /* Set the bypass mode for the relevant port. */
2774         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
2775                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
2776         }
2777 }
2778
2779 cmdline_parse_token_string_t cmd_setbypass_mode_set =
2780         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2781                         set, "set");
2782 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
2783         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2784                         bypass, "bypass");
2785 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
2786         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2787                         mode, "mode");
2788 cmdline_parse_token_string_t cmd_setbypass_mode_value =
2789         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
2790                         value, "normal#bypass#isolate");
2791 cmdline_parse_token_num_t cmd_setbypass_mode_port =
2792         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
2793                                 port_id, UINT8);
2794
2795 cmdline_parse_inst_t cmd_set_bypass_mode = {
2796         .f = cmd_set_bypass_mode_parsed,
2797         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
2798                     "Set the NIC bypass mode for port_id",
2799         .data = NULL,
2800         .tokens = {
2801                 (void *)&cmd_setbypass_mode_set,
2802                 (void *)&cmd_setbypass_mode_bypass,
2803                 (void *)&cmd_setbypass_mode_mode,
2804                 (void *)&cmd_setbypass_mode_value,
2805                 (void *)&cmd_setbypass_mode_port,
2806                 NULL,
2807         },
2808 };
2809
2810 /* *** SET NIC BYPASS EVENT *** */
2811 struct cmd_set_bypass_event_result {
2812         cmdline_fixed_string_t set;
2813         cmdline_fixed_string_t bypass;
2814         cmdline_fixed_string_t event;
2815         cmdline_fixed_string_t event_value;
2816         cmdline_fixed_string_t mode;
2817         cmdline_fixed_string_t mode_value;
2818         uint8_t port_id;
2819 };
2820
2821 static void
2822 cmd_set_bypass_event_parsed(void *parsed_result,
2823                 __attribute__((unused)) struct cmdline *cl,
2824                 __attribute__((unused)) void *data)
2825 {
2826         int32_t rc;
2827         struct cmd_set_bypass_event_result *res = parsed_result;
2828         portid_t port_id = res->port_id;
2829         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
2830         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
2831
2832         if (!bypass_is_supported(port_id))
2833                 return;
2834
2835         if (!strcmp(res->event_value, "timeout"))
2836                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
2837         else if (!strcmp(res->event_value, "os_on"))
2838                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
2839         else if (!strcmp(res->event_value, "os_off"))
2840                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
2841         else if (!strcmp(res->event_value, "power_on"))
2842                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
2843         else if (!strcmp(res->event_value, "power_off"))
2844                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
2845         else
2846                 bypass_event = RTE_BYPASS_EVENT_NONE;
2847
2848         if (!strcmp(res->mode_value, "bypass"))
2849                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
2850         else if (!strcmp(res->mode_value, "isolate"))
2851                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
2852         else
2853                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
2854
2855         /* Set the watchdog timeout. */
2856         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
2857
2858                 rc = -EINVAL;
2859                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
2860                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
2861                                 bypass_timeout)) != 0) {
2862                         printf("Failed to set timeout value %u "
2863                                 "for port %d, errto code: %d.\n",
2864                                 bypass_timeout, port_id, rc);
2865                 }
2866         }
2867
2868         /* Set the bypass event to transition to bypass mode. */
2869         if (0 != rte_eth_dev_bypass_event_store(port_id,
2870                         bypass_event, bypass_mode)) {
2871                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
2872         }
2873
2874 }
2875
2876 cmdline_parse_token_string_t cmd_setbypass_event_set =
2877         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2878                         set, "set");
2879 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
2880         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2881                         bypass, "bypass");
2882 cmdline_parse_token_string_t cmd_setbypass_event_event =
2883         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2884                         event, "event");
2885 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
2886         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2887                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
2888 cmdline_parse_token_string_t cmd_setbypass_event_mode =
2889         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2890                         mode, "mode");
2891 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
2892         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
2893                         mode_value, "normal#bypass#isolate");
2894 cmdline_parse_token_num_t cmd_setbypass_event_port =
2895         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
2896                                 port_id, UINT8);
2897
2898 cmdline_parse_inst_t cmd_set_bypass_event = {
2899         .f = cmd_set_bypass_event_parsed,
2900         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
2901                     "mode (normal|bypass|isolate) (port_id): "
2902                     "Set the NIC bypass event mode for port_id",
2903         .data = NULL,
2904         .tokens = {
2905                 (void *)&cmd_setbypass_event_set,
2906                 (void *)&cmd_setbypass_event_bypass,
2907                 (void *)&cmd_setbypass_event_event,
2908                 (void *)&cmd_setbypass_event_event_value,
2909                 (void *)&cmd_setbypass_event_mode,
2910                 (void *)&cmd_setbypass_event_mode_value,
2911                 (void *)&cmd_setbypass_event_port,
2912                 NULL,
2913         },
2914 };
2915
2916
2917 /* *** SET NIC BYPASS TIMEOUT *** */
2918 struct cmd_set_bypass_timeout_result {
2919         cmdline_fixed_string_t set;
2920         cmdline_fixed_string_t bypass;
2921         cmdline_fixed_string_t timeout;
2922         cmdline_fixed_string_t value;
2923 };
2924
2925 static void
2926 cmd_set_bypass_timeout_parsed(void *parsed_result,
2927                 __attribute__((unused)) struct cmdline *cl,
2928                 __attribute__((unused)) void *data)
2929 {
2930         struct cmd_set_bypass_timeout_result *res = parsed_result;
2931
2932         if (!strcmp(res->value, "1.5"))
2933                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
2934         else if (!strcmp(res->value, "2"))
2935                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
2936         else if (!strcmp(res->value, "3"))
2937                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
2938         else if (!strcmp(res->value, "4"))
2939                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
2940         else if (!strcmp(res->value, "8"))
2941                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
2942         else if (!strcmp(res->value, "16"))
2943                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
2944         else if (!strcmp(res->value, "32"))
2945                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
2946         else
2947                 bypass_timeout = RTE_BYPASS_TMT_OFF;
2948 }
2949
2950 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
2951         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2952                         set, "set");
2953 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
2954         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2955                         bypass, "bypass");
2956 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
2957         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2958                         timeout, "timeout");
2959 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
2960         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
2961                         value, "0#1.5#2#3#4#8#16#32");
2962
2963 cmdline_parse_inst_t cmd_set_bypass_timeout = {
2964         .f = cmd_set_bypass_timeout_parsed,
2965         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
2966                     "Set the NIC bypass watchdog timeout",
2967         .data = NULL,
2968         .tokens = {
2969                 (void *)&cmd_setbypass_timeout_set,
2970                 (void *)&cmd_setbypass_timeout_bypass,
2971                 (void *)&cmd_setbypass_timeout_timeout,
2972                 (void *)&cmd_setbypass_timeout_value,
2973                 NULL,
2974         },
2975 };
2976
2977 /* *** SHOW NIC BYPASS MODE *** */
2978 struct cmd_show_bypass_config_result {
2979         cmdline_fixed_string_t show;
2980         cmdline_fixed_string_t bypass;
2981         cmdline_fixed_string_t config;
2982         uint8_t port_id;
2983 };
2984
2985 static void
2986 cmd_show_bypass_config_parsed(void *parsed_result,
2987                 __attribute__((unused)) struct cmdline *cl,
2988                 __attribute__((unused)) void *data)
2989 {
2990         struct cmd_show_bypass_config_result *res = parsed_result;
2991         uint32_t event_mode;
2992         uint32_t bypass_mode;
2993         portid_t port_id = res->port_id;
2994         uint32_t timeout = bypass_timeout;
2995         int i;
2996
2997         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
2998                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
2999         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3000                 {"UNKNOWN", "normal", "bypass", "isolate"};
3001         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3002                 "NONE",
3003                 "OS/board on",
3004                 "power supply on",
3005                 "OS/board off",
3006                 "power supply off",
3007                 "timeout"};
3008         int num_events = (sizeof events) / (sizeof events[0]);
3009
3010         if (!bypass_is_supported(port_id))
3011                 return;
3012
3013         /* Display the bypass mode.*/
3014         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3015                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3016                 return;
3017         }
3018         else {
3019                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3020                         bypass_mode = RTE_BYPASS_MODE_NONE;
3021
3022                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3023         }
3024
3025         /* Display the bypass timeout.*/
3026         if (!RTE_BYPASS_TMT_VALID(timeout))
3027                 timeout = RTE_BYPASS_TMT_OFF;
3028
3029         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3030
3031         /* Display the bypass events and associated modes. */
3032         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3033
3034                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3035                         printf("\tFailed to get bypass mode for event = %s\n",
3036                                 events[i]);
3037                 } else {
3038                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3039                                 event_mode = RTE_BYPASS_MODE_NONE;
3040
3041                         printf("\tbypass event: %-16s = %s\n", events[i],
3042                                 modes[event_mode]);
3043                 }
3044         }
3045 }
3046
3047 cmdline_parse_token_string_t cmd_showbypass_config_show =
3048         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3049                         show, "show");
3050 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3051         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3052                         bypass, "bypass");
3053 cmdline_parse_token_string_t cmd_showbypass_config_config =
3054         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3055                         config, "config");
3056 cmdline_parse_token_num_t cmd_showbypass_config_port =
3057         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3058                                 port_id, UINT8);
3059
3060 cmdline_parse_inst_t cmd_show_bypass_config = {
3061         .f = cmd_show_bypass_config_parsed,
3062         .help_str = "show bypass config (port_id): "
3063                     "Show the NIC bypass config for port_id",
3064         .data = NULL,
3065         .tokens = {
3066                 (void *)&cmd_showbypass_config_show,
3067                 (void *)&cmd_showbypass_config_bypass,
3068                 (void *)&cmd_showbypass_config_config,
3069                 (void *)&cmd_showbypass_config_port,
3070                 NULL,
3071         },
3072 };
3073 #endif
3074
3075 #ifdef RTE_LIBRTE_PMD_BOND
3076 /* *** SET BONDING MODE *** */
3077 struct cmd_set_bonding_mode_result {
3078         cmdline_fixed_string_t set;
3079         cmdline_fixed_string_t bonding;
3080         cmdline_fixed_string_t mode;
3081         uint8_t value;
3082         uint8_t port_id;
3083 };
3084
3085 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3086                 __attribute__((unused))  struct cmdline *cl,
3087                 __attribute__((unused)) void *data)
3088 {
3089         struct cmd_set_bonding_mode_result *res = parsed_result;
3090         portid_t port_id = res->port_id;
3091
3092         /* Set the bonding mode for the relevant port. */
3093         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3094                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3095 }
3096
3097 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3098 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3099                 set, "set");
3100 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3101 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3102                 bonding, "bonding");
3103 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3104 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3105                 mode, "mode");
3106 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3107 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3108                 value, UINT8);
3109 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3110 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3111                 port_id, UINT8);
3112
3113 cmdline_parse_inst_t cmd_set_bonding_mode = {
3114                 .f = cmd_set_bonding_mode_parsed,
3115                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3116                 .data = NULL,
3117                 .tokens = {
3118                                 (void *) &cmd_setbonding_mode_set,
3119                                 (void *) &cmd_setbonding_mode_bonding,
3120                                 (void *) &cmd_setbonding_mode_mode,
3121                                 (void *) &cmd_setbonding_mode_value,
3122                                 (void *) &cmd_setbonding_mode_port,
3123                                 NULL
3124                 }
3125 };
3126
3127 /* *** SET BALANCE XMIT POLICY *** */
3128 struct cmd_set_bonding_balance_xmit_policy_result {
3129         cmdline_fixed_string_t set;
3130         cmdline_fixed_string_t bonding;
3131         cmdline_fixed_string_t balance_xmit_policy;
3132         uint8_t port_id;
3133         cmdline_fixed_string_t policy;
3134 };
3135
3136 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3137                 __attribute__((unused))  struct cmdline *cl,
3138                 __attribute__((unused)) void *data)
3139 {
3140         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3141         portid_t port_id = res->port_id;
3142         uint8_t policy;
3143
3144         if (!strcmp(res->policy, "l2")) {
3145                 policy = BALANCE_XMIT_POLICY_LAYER2;
3146         } else if (!strcmp(res->policy, "l23")) {
3147                 policy = BALANCE_XMIT_POLICY_LAYER23;
3148         } else if (!strcmp(res->policy, "l34")) {
3149                 policy = BALANCE_XMIT_POLICY_LAYER34;
3150         } else {
3151                 printf("\t Invalid xmit policy selection");
3152                 return;
3153         }
3154
3155         /* Set the bonding mode for the relevant port. */
3156         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3157                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3158                                 port_id);
3159         }
3160 }
3161
3162 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3163 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3164                 set, "set");
3165 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3166 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3167                 bonding, "bonding");
3168 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3169 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3170                 balance_xmit_policy, "balance_xmit_policy");
3171 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3172 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3173                 port_id, UINT8);
3174 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3175 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3176                 policy, "l2#l23#l34");
3177
3178 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3179                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3180                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3181                 .data = NULL,
3182                 .tokens = {
3183                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3184                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3185                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3186                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3187                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3188                                 NULL
3189                 }
3190 };
3191
3192 /* *** SHOW NIC BONDING CONFIGURATION *** */
3193 struct cmd_show_bonding_config_result {
3194         cmdline_fixed_string_t show;
3195         cmdline_fixed_string_t bonding;
3196         cmdline_fixed_string_t config;
3197         uint8_t port_id;
3198 };
3199
3200 static void cmd_show_bonding_config_parsed(void *parsed_result,
3201                 __attribute__((unused))  struct cmdline *cl,
3202                 __attribute__((unused)) void *data)
3203 {
3204         struct cmd_show_bonding_config_result *res = parsed_result;
3205         int bonding_mode;
3206         uint8_t slaves[RTE_MAX_ETHPORTS];
3207         int num_slaves, num_active_slaves;
3208         int primary_id;
3209         int i;
3210         portid_t port_id = res->port_id;
3211
3212         /* Display the bonding mode.*/
3213         bonding_mode = rte_eth_bond_mode_get(port_id);
3214         if (bonding_mode < 0) {
3215                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3216                 return;
3217         } else
3218                 printf("\tBonding mode: %d\n", bonding_mode);
3219
3220         if (bonding_mode == BONDING_MODE_BALANCE) {
3221                 int balance_xmit_policy;
3222
3223                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3224                 if (balance_xmit_policy < 0) {
3225                         printf("\tFailed to get balance xmit policy for port = %d\n",
3226                                         port_id);
3227                         return;
3228                 } else {
3229                         printf("\tBalance Xmit Policy: ");
3230
3231                         switch (balance_xmit_policy) {
3232                         case BALANCE_XMIT_POLICY_LAYER2:
3233                                 printf("BALANCE_XMIT_POLICY_LAYER2");
3234                                 break;
3235                         case BALANCE_XMIT_POLICY_LAYER23:
3236                                 printf("BALANCE_XMIT_POLICY_LAYER23");
3237                                 break;
3238                         case BALANCE_XMIT_POLICY_LAYER34:
3239                                 printf("BALANCE_XMIT_POLICY_LAYER34");
3240                                 break;
3241                         }
3242                         printf("\n");
3243                 }
3244         }
3245
3246         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
3247
3248         if (num_slaves < 0) {
3249                 printf("\tFailed to get slave list for port = %d\n", port_id);
3250                 return;
3251         }
3252         if (num_slaves > 0) {
3253                 printf("\tSlaves (%d): [", num_slaves);
3254                 for (i = 0; i < num_slaves - 1; i++)
3255                         printf("%d ", slaves[i]);
3256
3257                 printf("%d]\n", slaves[num_slaves - 1]);
3258         } else {
3259                 printf("\tSlaves: []\n");
3260
3261         }
3262
3263         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
3264                         RTE_MAX_ETHPORTS);
3265
3266         if (num_active_slaves < 0) {
3267                 printf("\tFailed to get active slave list for port = %d\n", port_id);
3268                 return;
3269         }
3270         if (num_active_slaves > 0) {
3271                 printf("\tActive Slaves (%d): [", num_active_slaves);
3272                 for (i = 0; i < num_active_slaves - 1; i++)
3273                         printf("%d ", slaves[i]);
3274
3275                 printf("%d]\n", slaves[num_active_slaves - 1]);
3276
3277         } else {
3278                 printf("\tActive Slaves: []\n");
3279
3280         }
3281
3282         primary_id = rte_eth_bond_primary_get(port_id);
3283         if (primary_id < 0) {
3284                 printf("\tFailed to get primary slave for port = %d\n", port_id);
3285                 return;
3286         } else
3287                 printf("\tPrimary: [%d]\n", primary_id);
3288
3289 }
3290
3291 cmdline_parse_token_string_t cmd_showbonding_config_show =
3292 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3293                 show, "show");
3294 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
3295 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3296                 bonding, "bonding");
3297 cmdline_parse_token_string_t cmd_showbonding_config_config =
3298 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3299                 config, "config");
3300 cmdline_parse_token_num_t cmd_showbonding_config_port =
3301 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
3302                 port_id, UINT8);
3303
3304 cmdline_parse_inst_t cmd_show_bonding_config = {
3305                 .f = cmd_show_bonding_config_parsed,
3306                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
3307                 .data = NULL,
3308                 .tokens = {
3309                                 (void *)&cmd_showbonding_config_show,
3310                                 (void *)&cmd_showbonding_config_bonding,
3311                                 (void *)&cmd_showbonding_config_config,
3312                                 (void *)&cmd_showbonding_config_port,
3313                                 NULL
3314                 }
3315 };
3316
3317 /* *** SET BONDING PRIMARY *** */
3318 struct cmd_set_bonding_primary_result {
3319         cmdline_fixed_string_t set;
3320         cmdline_fixed_string_t bonding;
3321         cmdline_fixed_string_t primary;
3322         uint8_t slave_id;
3323         uint8_t port_id;
3324 };
3325
3326 static void cmd_set_bonding_primary_parsed(void *parsed_result,
3327                 __attribute__((unused))  struct cmdline *cl,
3328                 __attribute__((unused)) void *data)
3329 {
3330         struct cmd_set_bonding_primary_result *res = parsed_result;
3331         portid_t master_port_id = res->port_id;
3332         portid_t slave_port_id = res->slave_id;
3333
3334         /* Set the primary slave for a bonded device. */
3335         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
3336                 printf("\t Failed to set primary slave for port = %d.\n",
3337                                 master_port_id);
3338                 return;
3339         }
3340         init_port_config();
3341 }
3342
3343 cmdline_parse_token_string_t cmd_setbonding_primary_set =
3344 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3345                 set, "set");
3346 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
3347 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3348                 bonding, "bonding");
3349 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
3350 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3351                 primary, "primary");
3352 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
3353 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3354                 slave_id, UINT8);
3355 cmdline_parse_token_num_t cmd_setbonding_primary_port =
3356 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3357                 port_id, UINT8);
3358
3359 cmdline_parse_inst_t cmd_set_bonding_primary = {
3360                 .f = cmd_set_bonding_primary_parsed,
3361                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
3362                 .data = NULL,
3363                 .tokens = {
3364                                 (void *)&cmd_setbonding_primary_set,
3365                                 (void *)&cmd_setbonding_primary_bonding,
3366                                 (void *)&cmd_setbonding_primary_primary,
3367                                 (void *)&cmd_setbonding_primary_slave,
3368                                 (void *)&cmd_setbonding_primary_port,
3369                                 NULL
3370                 }
3371 };
3372
3373 /* *** ADD SLAVE *** */
3374 struct cmd_add_bonding_slave_result {
3375         cmdline_fixed_string_t add;
3376         cmdline_fixed_string_t bonding;
3377         cmdline_fixed_string_t slave;
3378         uint8_t slave_id;
3379         uint8_t port_id;
3380 };
3381
3382 static void cmd_add_bonding_slave_parsed(void *parsed_result,
3383                 __attribute__((unused))  struct cmdline *cl,
3384                 __attribute__((unused)) void *data)
3385 {
3386         struct cmd_add_bonding_slave_result *res = parsed_result;
3387         portid_t master_port_id = res->port_id;
3388         portid_t slave_port_id = res->slave_id;
3389
3390         /* Set the primary slave for a bonded device. */
3391         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
3392                 printf("\t Failed to add slave %d to master port = %d.\n",
3393                                 slave_port_id, master_port_id);
3394                 return;
3395         }
3396         init_port_config();
3397 }
3398
3399 cmdline_parse_token_string_t cmd_addbonding_slave_add =
3400 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3401                 add, "add");
3402 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
3403 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3404                 bonding, "bonding");
3405 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
3406 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
3407                 slave, "slave");
3408 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
3409 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
3410                 slave_id, UINT8);
3411 cmdline_parse_token_num_t cmd_addbonding_slave_port =
3412 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
3413                 port_id, UINT8);
3414
3415 cmdline_parse_inst_t cmd_add_bonding_slave = {
3416                 .f = cmd_add_bonding_slave_parsed,
3417                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
3418                 .data = NULL,
3419                 .tokens = {
3420                                 (void *)&cmd_addbonding_slave_add,
3421                                 (void *)&cmd_addbonding_slave_bonding,
3422                                 (void *)&cmd_addbonding_slave_slave,
3423                                 (void *)&cmd_addbonding_slave_slaveid,
3424                                 (void *)&cmd_addbonding_slave_port,
3425                                 NULL
3426                 }
3427 };
3428
3429 /* *** REMOVE SLAVE *** */
3430 struct cmd_remove_bonding_slave_result {
3431         cmdline_fixed_string_t remove;
3432         cmdline_fixed_string_t bonding;
3433         cmdline_fixed_string_t slave;
3434         uint8_t slave_id;
3435         uint8_t port_id;
3436 };
3437
3438 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
3439                 __attribute__((unused))  struct cmdline *cl,
3440                 __attribute__((unused)) void *data)
3441 {
3442         struct cmd_remove_bonding_slave_result *res = parsed_result;
3443         portid_t master_port_id = res->port_id;
3444         portid_t slave_port_id = res->slave_id;
3445
3446         /* Set the primary slave for a bonded device. */
3447         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
3448                 printf("\t Failed to remove slave %d from master port = %d.\n",
3449                                 slave_port_id, master_port_id);
3450                 return;
3451         }
3452         init_port_config();
3453 }
3454
3455 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
3456                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3457                                 remove, "remove");
3458 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
3459                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3460                                 bonding, "bonding");
3461 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
3462                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
3463                                 slave, "slave");
3464 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
3465                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
3466                                 slave_id, UINT8);
3467 cmdline_parse_token_num_t cmd_removebonding_slave_port =
3468                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
3469                                 port_id, UINT8);
3470
3471 cmdline_parse_inst_t cmd_remove_bonding_slave = {
3472                 .f = cmd_remove_bonding_slave_parsed,
3473                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
3474                 .data = NULL,
3475                 .tokens = {
3476                                 (void *)&cmd_removebonding_slave_remove,
3477                                 (void *)&cmd_removebonding_slave_bonding,
3478                                 (void *)&cmd_removebonding_slave_slave,
3479                                 (void *)&cmd_removebonding_slave_slaveid,
3480                                 (void *)&cmd_removebonding_slave_port,
3481                                 NULL
3482                 }
3483 };
3484
3485 /* *** CREATE BONDED DEVICE *** */
3486 struct cmd_create_bonded_device_result {
3487         cmdline_fixed_string_t create;
3488         cmdline_fixed_string_t bonded;
3489         cmdline_fixed_string_t device;
3490         uint8_t mode;
3491         uint8_t socket;
3492 };
3493
3494 static int bond_dev_num = 0;
3495
3496 static void cmd_create_bonded_device_parsed(void *parsed_result,
3497                 __attribute__((unused))  struct cmdline *cl,
3498                 __attribute__((unused)) void *data)
3499 {
3500         struct cmd_create_bonded_device_result *res = parsed_result;
3501         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
3502         int port_id;
3503
3504         if (test_done == 0) {
3505                 printf("Please stop forwarding first\n");
3506                 return;
3507         }
3508
3509         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
3510                         bond_dev_num++);
3511
3512         /* Create a new bonded device. */
3513         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
3514         if (port_id < 0) {
3515                 printf("\t Failed to create bonded device.\n");
3516                 return;
3517         } else {
3518                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
3519                                 port_id);
3520
3521                 /* Update number of ports */
3522                 nb_ports = rte_eth_dev_count();
3523                 reconfig(port_id);
3524                 rte_eth_promiscuous_enable(port_id);
3525         }
3526
3527 }
3528
3529 cmdline_parse_token_string_t cmd_createbonded_device_create =
3530                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3531                                 create, "create");
3532 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
3533                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3534                                 bonded, "bonded");
3535 cmdline_parse_token_string_t cmd_createbonded_device_device =
3536                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
3537                                 device, "device");
3538 cmdline_parse_token_num_t cmd_createbonded_device_mode =
3539                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
3540                                 mode, UINT8);
3541 cmdline_parse_token_num_t cmd_createbonded_device_socket =
3542                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
3543                                 socket, UINT8);
3544
3545 cmdline_parse_inst_t cmd_create_bonded_device = {
3546                 .f = cmd_create_bonded_device_parsed,
3547                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
3548                 .data = NULL,
3549                 .tokens = {
3550                                 (void *)&cmd_createbonded_device_create,
3551                                 (void *)&cmd_createbonded_device_bonded,
3552                                 (void *)&cmd_createbonded_device_device,
3553                                 (void *)&cmd_createbonded_device_mode,
3554                                 (void *)&cmd_createbonded_device_socket,
3555                                 NULL
3556                 }
3557 };
3558
3559 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
3560 struct cmd_set_bond_mac_addr_result {
3561         cmdline_fixed_string_t set;
3562         cmdline_fixed_string_t bonding;
3563         cmdline_fixed_string_t mac_addr;
3564         uint8_t port_num;
3565         struct ether_addr address;
3566 };
3567
3568 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
3569                 __attribute__((unused))  struct cmdline *cl,
3570                 __attribute__((unused)) void *data)
3571 {
3572         struct cmd_set_bond_mac_addr_result *res = parsed_result;
3573         int ret;
3574
3575         if (res->port_num >= nb_ports) {
3576                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
3577                 return;
3578         }
3579
3580         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
3581
3582         /* check the return value and print it if is < 0 */
3583         if (ret < 0)
3584                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
3585 }
3586
3587 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
3588                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
3589 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
3590                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
3591                                 "bonding");
3592 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
3593                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
3594                                 "mac_addr");
3595 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
3596                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
3597 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
3598                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
3599
3600 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
3601                 .f = cmd_set_bond_mac_addr_parsed,
3602                 .data = (void *) 0,
3603                 .help_str = "set bonding mac_addr (port_id) (address): ",
3604                 .tokens = {
3605                                 (void *)&cmd_set_bond_mac_addr_set,
3606                                 (void *)&cmd_set_bond_mac_addr_bonding,
3607                                 (void *)&cmd_set_bond_mac_addr_mac,
3608                                 (void *)&cmd_set_bond_mac_addr_portnum,
3609                                 (void *)&cmd_set_bond_mac_addr_addr,
3610                                 NULL
3611                 }
3612 };
3613
3614 #endif /* RTE_LIBRTE_PMD_BOND */
3615
3616 /* *** SET FORWARDING MODE *** */
3617 struct cmd_set_fwd_mode_result {
3618         cmdline_fixed_string_t set;
3619         cmdline_fixed_string_t fwd;
3620         cmdline_fixed_string_t mode;
3621 };
3622
3623 static void cmd_set_fwd_mode_parsed(void *parsed_result,
3624                                     __attribute__((unused)) struct cmdline *cl,
3625                                     __attribute__((unused)) void *data)
3626 {
3627         struct cmd_set_fwd_mode_result *res = parsed_result;
3628
3629         set_pkt_forwarding_mode(res->mode);
3630 }
3631
3632 cmdline_parse_token_string_t cmd_setfwd_set =
3633         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
3634 cmdline_parse_token_string_t cmd_setfwd_fwd =
3635         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
3636 cmdline_parse_token_string_t cmd_setfwd_mode =
3637         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
3638                 "" /* defined at init */);
3639
3640 cmdline_parse_inst_t cmd_set_fwd_mode = {
3641         .f = cmd_set_fwd_mode_parsed,
3642         .data = NULL,
3643         .help_str = NULL, /* defined at init */
3644         .tokens = {
3645                 (void *)&cmd_setfwd_set,
3646                 (void *)&cmd_setfwd_fwd,
3647                 (void *)&cmd_setfwd_mode,
3648                 NULL,
3649         },
3650 };
3651
3652 static void cmd_set_fwd_mode_init(void)
3653 {
3654         char *modes, *c;
3655         static char token[128];
3656         static char help[256];
3657         cmdline_parse_token_string_t *token_struct;
3658
3659         modes = list_pkt_forwarding_modes();
3660         snprintf(help, sizeof help, "set fwd %s - "
3661                 "set packet forwarding mode", modes);
3662         cmd_set_fwd_mode.help_str = help;
3663
3664         /* string token separator is # */
3665         for (c = token; *modes != '\0'; modes++)
3666                 if (*modes == '|')
3667                         *c++ = '#';
3668                 else
3669                         *c++ = *modes;
3670         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
3671         token_struct->string_data.str = token;
3672 }
3673
3674 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
3675 struct cmd_set_burst_tx_retry_result {
3676         cmdline_fixed_string_t set;
3677         cmdline_fixed_string_t burst;
3678         cmdline_fixed_string_t tx;
3679         cmdline_fixed_string_t delay;
3680         uint32_t time;
3681         cmdline_fixed_string_t retry;
3682         uint32_t retry_num;
3683 };
3684
3685 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
3686                                         __attribute__((unused)) struct cmdline *cl,
3687                                         __attribute__((unused)) void *data)
3688 {
3689         struct cmd_set_burst_tx_retry_result *res = parsed_result;
3690
3691         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
3692                 && !strcmp(res->tx, "tx")) {
3693                 if (!strcmp(res->delay, "delay"))
3694                         burst_tx_delay_time = res->time;
3695                 if (!strcmp(res->retry, "retry"))
3696                         burst_tx_retry_num = res->retry_num;
3697         }
3698
3699 }
3700
3701 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
3702         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
3703 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
3704         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
3705                                  "burst");
3706 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
3707         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
3708 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
3709         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
3710 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
3711         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
3712 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
3713         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
3714 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
3715         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
3716
3717 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
3718         .f = cmd_set_burst_tx_retry_parsed,
3719         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
3720         .tokens = {
3721                 (void *)&cmd_set_burst_tx_retry_set,
3722                 (void *)&cmd_set_burst_tx_retry_burst,
3723                 (void *)&cmd_set_burst_tx_retry_tx,
3724                 (void *)&cmd_set_burst_tx_retry_delay,
3725                 (void *)&cmd_set_burst_tx_retry_time,
3726                 (void *)&cmd_set_burst_tx_retry_retry,
3727                 (void *)&cmd_set_burst_tx_retry_retry_num,
3728                 NULL,
3729         },
3730 };
3731
3732 /* *** SET PROMISC MODE *** */
3733 struct cmd_set_promisc_mode_result {
3734         cmdline_fixed_string_t set;
3735         cmdline_fixed_string_t promisc;
3736         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
3737         uint8_t port_num;                /* valid if "allports" argument == 0 */
3738         cmdline_fixed_string_t mode;
3739 };
3740
3741 static void cmd_set_promisc_mode_parsed(void *parsed_result,
3742                                         __attribute__((unused)) struct cmdline *cl,
3743                                         void *allports)
3744 {
3745         struct cmd_set_promisc_mode_result *res = parsed_result;
3746         int enable;
3747         portid_t i;
3748
3749         if (!strcmp(res->mode, "on"))
3750                 enable = 1;
3751         else
3752                 enable = 0;
3753
3754         /* all ports */
3755         if (allports) {
3756                 for (i = 0; i < nb_ports; i++) {
3757                         if (enable)
3758                                 rte_eth_promiscuous_enable(i);
3759                         else
3760                                 rte_eth_promiscuous_disable(i);
3761                 }
3762         }
3763         else {
3764                 if (enable)
3765                         rte_eth_promiscuous_enable(res->port_num);
3766                 else
3767                         rte_eth_promiscuous_disable(res->port_num);
3768         }
3769 }
3770
3771 cmdline_parse_token_string_t cmd_setpromisc_set =
3772         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
3773 cmdline_parse_token_string_t cmd_setpromisc_promisc =
3774         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
3775                                  "promisc");
3776 cmdline_parse_token_string_t cmd_setpromisc_portall =
3777         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
3778                                  "all");
3779 cmdline_parse_token_num_t cmd_setpromisc_portnum =
3780         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
3781                               UINT8);
3782 cmdline_parse_token_string_t cmd_setpromisc_mode =
3783         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
3784                                  "on#off");
3785
3786 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
3787         .f = cmd_set_promisc_mode_parsed,
3788         .data = (void *)1,
3789         .help_str = "set promisc all on|off: set promisc mode for all ports",
3790         .tokens = {
3791                 (void *)&cmd_setpromisc_set,
3792                 (void *)&cmd_setpromisc_promisc,
3793                 (void *)&cmd_setpromisc_portall,
3794                 (void *)&cmd_setpromisc_mode,
3795                 NULL,
3796         },
3797 };
3798
3799 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
3800         .f = cmd_set_promisc_mode_parsed,
3801         .data = (void *)0,
3802         .help_str = "set promisc X on|off: set promisc mode on port X",
3803         .tokens = {
3804                 (void *)&cmd_setpromisc_set,
3805                 (void *)&cmd_setpromisc_promisc,
3806                 (void *)&cmd_setpromisc_portnum,
3807                 (void *)&cmd_setpromisc_mode,
3808                 NULL,
3809         },
3810 };
3811
3812 /* *** SET ALLMULTI MODE *** */
3813 struct cmd_set_allmulti_mode_result {
3814         cmdline_fixed_string_t set;
3815         cmdline_fixed_string_t allmulti;
3816         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
3817         uint8_t port_num;                /* valid if "allports" argument == 0 */
3818         cmdline_fixed_string_t mode;
3819 };
3820
3821 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
3822                                         __attribute__((unused)) struct cmdline *cl,
3823                                         void *allports)
3824 {
3825         struct cmd_set_allmulti_mode_result *res = parsed_result;
3826         int enable;
3827         portid_t i;
3828
3829         if (!strcmp(res->mode, "on"))
3830                 enable = 1;
3831         else
3832                 enable = 0;
3833
3834         /* all ports */
3835         if (allports) {
3836                 for (i = 0; i < nb_ports; i++) {
3837                         if (enable)
3838                                 rte_eth_allmulticast_enable(i);
3839                         else
3840                                 rte_eth_allmulticast_disable(i);
3841                 }
3842         }
3843         else {
3844                 if (enable)
3845                         rte_eth_allmulticast_enable(res->port_num);
3846                 else
3847                         rte_eth_allmulticast_disable(res->port_num);
3848         }
3849 }
3850
3851 cmdline_parse_token_string_t cmd_setallmulti_set =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
3853 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
3854         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
3855                                  "allmulti");
3856 cmdline_parse_token_string_t cmd_setallmulti_portall =
3857         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
3858                                  "all");
3859 cmdline_parse_token_num_t cmd_setallmulti_portnum =
3860         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
3861                               UINT8);
3862 cmdline_parse_token_string_t cmd_setallmulti_mode =
3863         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
3864                                  "on#off");
3865
3866 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
3867         .f = cmd_set_allmulti_mode_parsed,
3868         .data = (void *)1,
3869         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
3870         .tokens = {
3871                 (void *)&cmd_setallmulti_set,
3872                 (void *)&cmd_setallmulti_allmulti,
3873                 (void *)&cmd_setallmulti_portall,
3874                 (void *)&cmd_setallmulti_mode,
3875                 NULL,
3876         },
3877 };
3878
3879 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
3880         .f = cmd_set_allmulti_mode_parsed,
3881         .data = (void *)0,
3882         .help_str = "set allmulti X on|off: set allmulti mode on port X",
3883         .tokens = {
3884                 (void *)&cmd_setallmulti_set,
3885                 (void *)&cmd_setallmulti_allmulti,
3886                 (void *)&cmd_setallmulti_portnum,
3887                 (void *)&cmd_setallmulti_mode,
3888                 NULL,
3889         },
3890 };
3891
3892 /* *** ADD/REMOVE A PKT FILTER *** */
3893 struct cmd_pkt_filter_result {
3894         cmdline_fixed_string_t pkt_filter;
3895         uint8_t  port_id;
3896         cmdline_fixed_string_t protocol;
3897         cmdline_fixed_string_t src;
3898         cmdline_ipaddr_t ip_src;
3899         uint16_t port_src;
3900         cmdline_fixed_string_t dst;
3901         cmdline_ipaddr_t ip_dst;
3902         uint16_t port_dst;
3903         cmdline_fixed_string_t flexbytes;
3904         uint16_t flexbytes_value;
3905         cmdline_fixed_string_t vlan;
3906         uint16_t  vlan_id;
3907         cmdline_fixed_string_t queue;
3908         int8_t  queue_id;
3909         cmdline_fixed_string_t soft;
3910         uint8_t  soft_id;
3911 };
3912
3913 static void
3914 cmd_pkt_filter_parsed(void *parsed_result,
3915                           __attribute__((unused)) struct cmdline *cl,
3916                           __attribute__((unused)) void *data)
3917 {
3918         struct rte_fdir_filter fdir_filter;
3919         struct cmd_pkt_filter_result *res = parsed_result;
3920
3921         memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
3922
3923         if (res->ip_src.family == AF_INET)
3924                 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
3925         else
3926                 memcpy(&(fdir_filter.ip_src.ipv6_addr),
3927                        &(res->ip_src.addr.ipv6),
3928                        sizeof(struct in6_addr));
3929
3930         if (res->ip_dst.family == AF_INET)
3931                 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
3932         else
3933                 memcpy(&(fdir_filter.ip_dst.ipv6_addr),
3934                        &(res->ip_dst.addr.ipv6),
3935                        sizeof(struct in6_addr));
3936
3937         fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
3938         fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
3939
3940         if (!strcmp(res->protocol, "udp"))
3941                 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
3942         else if (!strcmp(res->protocol, "tcp"))
3943                 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
3944         else if (!strcmp(res->protocol, "sctp"))
3945                 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
3946         else /* default only IP */
3947                 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
3948
3949         if (res->ip_dst.family == AF_INET6)
3950                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
3951         else
3952                 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
3953
3954         fdir_filter.vlan_id    = rte_cpu_to_be_16(res->vlan_id);
3955         fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
3956
3957         if (!strcmp(res->pkt_filter, "add_signature_filter"))
3958                 fdir_add_signature_filter(res->port_id, res->queue_id,
3959                                           &fdir_filter);
3960         else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
3961                 fdir_update_signature_filter(res->port_id, res->queue_id,
3962                                              &fdir_filter);
3963         else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
3964                 fdir_remove_signature_filter(res->port_id, &fdir_filter);
3965         else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
3966                 fdir_add_perfect_filter(res->port_id, res->soft_id,
3967                                         res->queue_id,
3968                                         (uint8_t) (res->queue_id < 0),
3969                                         &fdir_filter);
3970         else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
3971                 fdir_update_perfect_filter(res->port_id, res->soft_id,
3972                                            res->queue_id,
3973                                            (uint8_t) (res->queue_id < 0),
3974                                            &fdir_filter);
3975         else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
3976                 fdir_remove_perfect_filter(res->port_id, res->soft_id,
3977                                            &fdir_filter);
3978
3979 }
3980
3981
3982 cmdline_parse_token_num_t cmd_pkt_filter_port_id =
3983         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3984                               port_id, UINT8);
3985 cmdline_parse_token_string_t cmd_pkt_filter_protocol =
3986         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3987                                  protocol, "ip#tcp#udp#sctp");
3988 cmdline_parse_token_string_t cmd_pkt_filter_src =
3989         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3990                                  src, "src");
3991 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
3992         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
3993                                  ip_src);
3994 cmdline_parse_token_num_t cmd_pkt_filter_port_src =
3995         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
3996                               port_src, UINT16);
3997 cmdline_parse_token_string_t cmd_pkt_filter_dst =
3998         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
3999                                  dst, "dst");
4000 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
4001         TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
4002                                  ip_dst);
4003 cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
4004         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4005                               port_dst, UINT16);
4006 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
4007         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4008                                  flexbytes, "flexbytes");
4009 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
4010         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4011                               flexbytes_value, UINT16);
4012 cmdline_parse_token_string_t cmd_pkt_filter_vlan =
4013         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4014                                  vlan, "vlan");
4015 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
4016         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4017                               vlan_id, UINT16);
4018 cmdline_parse_token_string_t cmd_pkt_filter_queue =
4019         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4020                                  queue, "queue");
4021 cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
4022         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4023                               queue_id, INT8);
4024 cmdline_parse_token_string_t cmd_pkt_filter_soft =
4025         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4026                                  soft, "soft");
4027 cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
4028         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
4029                               soft_id, UINT16);
4030
4031
4032 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
4033         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4034                                  pkt_filter, "add_signature_filter");
4035 cmdline_parse_inst_t cmd_add_signature_filter = {
4036         .f = cmd_pkt_filter_parsed,
4037         .data = NULL,
4038         .help_str = "add a signature filter",
4039         .tokens = {
4040                 (void *)&cmd_pkt_filter_add_signature_filter,
4041                 (void *)&cmd_pkt_filter_port_id,
4042                 (void *)&cmd_pkt_filter_protocol,
4043                 (void *)&cmd_pkt_filter_src,
4044                 (void *)&cmd_pkt_filter_ip_src,
4045                 (void *)&cmd_pkt_filter_port_src,
4046                 (void *)&cmd_pkt_filter_dst,
4047                 (void *)&cmd_pkt_filter_ip_dst,
4048                 (void *)&cmd_pkt_filter_port_dst,
4049                 (void *)&cmd_pkt_filter_flexbytes,
4050                 (void *)&cmd_pkt_filter_flexbytes_value,
4051                 (void *)&cmd_pkt_filter_vlan,
4052                 (void *)&cmd_pkt_filter_vlan_id,
4053                 (void *)&cmd_pkt_filter_queue,
4054                 (void *)&cmd_pkt_filter_queue_id,
4055                 NULL,
4056         },
4057 };
4058
4059
4060 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
4061         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4062                                  pkt_filter, "upd_signature_filter");
4063 cmdline_parse_inst_t cmd_upd_signature_filter = {
4064         .f = cmd_pkt_filter_parsed,
4065         .data = NULL,
4066         .help_str = "update a signature filter",
4067         .tokens = {
4068                 (void *)&cmd_pkt_filter_upd_signature_filter,
4069                 (void *)&cmd_pkt_filter_port_id,
4070                 (void *)&cmd_pkt_filter_protocol,
4071                 (void *)&cmd_pkt_filter_src,
4072                 (void *)&cmd_pkt_filter_ip_src,
4073                 (void *)&cmd_pkt_filter_port_src,
4074                 (void *)&cmd_pkt_filter_dst,
4075                 (void *)&cmd_pkt_filter_ip_dst,
4076                 (void *)&cmd_pkt_filter_port_dst,
4077                 (void *)&cmd_pkt_filter_flexbytes,
4078                 (void *)&cmd_pkt_filter_flexbytes_value,
4079                 (void *)&cmd_pkt_filter_vlan,
4080                 (void *)&cmd_pkt_filter_vlan_id,
4081                 (void *)&cmd_pkt_filter_queue,
4082                 (void *)&cmd_pkt_filter_queue_id,
4083                 NULL,
4084         },
4085 };
4086
4087
4088 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
4089         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4090                                  pkt_filter, "rm_signature_filter");
4091 cmdline_parse_inst_t cmd_rm_signature_filter = {
4092         .f = cmd_pkt_filter_parsed,
4093         .data = NULL,
4094         .help_str = "remove a signature filter",
4095         .tokens = {
4096                 (void *)&cmd_pkt_filter_rm_signature_filter,
4097                 (void *)&cmd_pkt_filter_port_id,
4098                 (void *)&cmd_pkt_filter_protocol,
4099                 (void *)&cmd_pkt_filter_src,
4100                 (void *)&cmd_pkt_filter_ip_src,
4101                 (void *)&cmd_pkt_filter_port_src,
4102                 (void *)&cmd_pkt_filter_dst,
4103                 (void *)&cmd_pkt_filter_ip_dst,
4104                 (void *)&cmd_pkt_filter_port_dst,
4105                 (void *)&cmd_pkt_filter_flexbytes,
4106                 (void *)&cmd_pkt_filter_flexbytes_value,
4107                 (void *)&cmd_pkt_filter_vlan,
4108                 (void *)&cmd_pkt_filter_vlan_id,
4109                 NULL
4110                 },
4111 };
4112
4113
4114 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
4115         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4116                                  pkt_filter, "add_perfect_filter");
4117 cmdline_parse_inst_t cmd_add_perfect_filter = {
4118         .f = cmd_pkt_filter_parsed,
4119         .data = NULL,
4120         .help_str = "add a perfect filter",
4121         .tokens = {
4122                 (void *)&cmd_pkt_filter_add_perfect_filter,
4123                 (void *)&cmd_pkt_filter_port_id,
4124                 (void *)&cmd_pkt_filter_protocol,
4125                 (void *)&cmd_pkt_filter_src,
4126                 (void *)&cmd_pkt_filter_ip_src,
4127                 (void *)&cmd_pkt_filter_port_src,
4128                 (void *)&cmd_pkt_filter_dst,
4129                 (void *)&cmd_pkt_filter_ip_dst,
4130                 (void *)&cmd_pkt_filter_port_dst,
4131                 (void *)&cmd_pkt_filter_flexbytes,
4132                 (void *)&cmd_pkt_filter_flexbytes_value,
4133                 (void *)&cmd_pkt_filter_vlan,
4134                 (void *)&cmd_pkt_filter_vlan_id,
4135                 (void *)&cmd_pkt_filter_queue,
4136                 (void *)&cmd_pkt_filter_queue_id,
4137                 (void *)&cmd_pkt_filter_soft,
4138                 (void *)&cmd_pkt_filter_soft_id,
4139                 NULL,
4140         },
4141 };
4142
4143
4144 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
4145         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4146                                  pkt_filter, "upd_perfect_filter");
4147 cmdline_parse_inst_t cmd_upd_perfect_filter = {
4148         .f = cmd_pkt_filter_parsed,
4149         .data = NULL,
4150         .help_str = "update a perfect filter",
4151         .tokens = {
4152                 (void *)&cmd_pkt_filter_upd_perfect_filter,
4153                 (void *)&cmd_pkt_filter_port_id,
4154                 (void *)&cmd_pkt_filter_protocol,
4155                 (void *)&cmd_pkt_filter_src,
4156                 (void *)&cmd_pkt_filter_ip_src,
4157                 (void *)&cmd_pkt_filter_port_src,
4158                 (void *)&cmd_pkt_filter_dst,
4159                 (void *)&cmd_pkt_filter_ip_dst,
4160                 (void *)&cmd_pkt_filter_port_dst,
4161                 (void *)&cmd_pkt_filter_flexbytes,
4162                 (void *)&cmd_pkt_filter_flexbytes_value,
4163                 (void *)&cmd_pkt_filter_vlan,
4164                 (void *)&cmd_pkt_filter_vlan_id,
4165                 (void *)&cmd_pkt_filter_queue,
4166                 (void *)&cmd_pkt_filter_queue_id,
4167                 (void *)&cmd_pkt_filter_soft,
4168                 (void *)&cmd_pkt_filter_soft_id,
4169                 NULL,
4170         },
4171 };
4172
4173
4174 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
4175         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
4176                                  pkt_filter, "rm_perfect_filter");
4177 cmdline_parse_inst_t cmd_rm_perfect_filter = {
4178         .f = cmd_pkt_filter_parsed,
4179         .data = NULL,
4180         .help_str = "remove a perfect filter",
4181         .tokens = {
4182                 (void *)&cmd_pkt_filter_rm_perfect_filter,
4183                 (void *)&cmd_pkt_filter_port_id,
4184                 (void *)&cmd_pkt_filter_protocol,
4185                 (void *)&cmd_pkt_filter_src,
4186                 (void *)&cmd_pkt_filter_ip_src,
4187                 (void *)&cmd_pkt_filter_port_src,
4188                 (void *)&cmd_pkt_filter_dst,
4189                 (void *)&cmd_pkt_filter_ip_dst,
4190                 (void *)&cmd_pkt_filter_port_dst,
4191                 (void *)&cmd_pkt_filter_flexbytes,
4192                 (void *)&cmd_pkt_filter_flexbytes_value,
4193                 (void *)&cmd_pkt_filter_vlan,
4194                 (void *)&cmd_pkt_filter_vlan_id,
4195                 (void *)&cmd_pkt_filter_soft,
4196                 (void *)&cmd_pkt_filter_soft_id,
4197                 NULL,
4198         },
4199 };
4200
4201 /* *** SETUP MASKS FILTER *** */
4202 struct cmd_pkt_filter_masks_result {
4203         cmdline_fixed_string_t filter_mask;
4204         uint8_t  port_id;
4205         cmdline_fixed_string_t src_mask;
4206         uint32_t ip_src_mask;
4207         uint16_t ipv6_src_mask;
4208         uint16_t port_src_mask;
4209         cmdline_fixed_string_t dst_mask;
4210         uint32_t ip_dst_mask;
4211         uint16_t ipv6_dst_mask;
4212         uint16_t port_dst_mask;
4213         cmdline_fixed_string_t flexbytes;
4214         uint8_t flexbytes_value;
4215         cmdline_fixed_string_t vlan_id;
4216         uint8_t  vlan_id_value;
4217         cmdline_fixed_string_t vlan_prio;
4218         uint8_t  vlan_prio_value;
4219         cmdline_fixed_string_t only_ip_flow;
4220         uint8_t  only_ip_flow_value;
4221         cmdline_fixed_string_t comp_ipv6_dst;
4222         uint8_t  comp_ipv6_dst_value;
4223 };
4224
4225 static void
4226 cmd_pkt_filter_masks_parsed(void *parsed_result,
4227                           __attribute__((unused)) struct cmdline *cl,
4228                           __attribute__((unused)) void *data)
4229 {
4230         struct rte_fdir_masks fdir_masks;
4231         struct cmd_pkt_filter_masks_result *res = parsed_result;
4232
4233         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
4234
4235         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
4236         fdir_masks.vlan_id       = res->vlan_id_value;
4237         fdir_masks.vlan_prio     = res->vlan_prio_value;
4238         fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
4239         fdir_masks.src_ipv4_mask = res->ip_src_mask;
4240         fdir_masks.src_port_mask = res->port_src_mask;
4241         fdir_masks.dst_port_mask = res->port_dst_mask;
4242         fdir_masks.flexbytes     = res->flexbytes_value;
4243
4244         fdir_set_masks(res->port_id, &fdir_masks);
4245 }
4246
4247 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =
4248         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4249                                  filter_mask, "set_masks_filter");
4250 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id =
4251         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4252                               port_id, UINT8);
4253 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow =
4254         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4255                                  only_ip_flow, "only_ip_flow");
4256 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value =
4257         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4258                               only_ip_flow_value, UINT8);
4259 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask =
4260         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4261                                  src_mask, "src_mask");
4262 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask =
4263         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4264                               ip_src_mask, UINT32);
4265 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask =
4266         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4267                               port_src_mask, UINT16);
4268 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask =
4269         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4270                                  dst_mask, "dst_mask");
4271 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask =
4272         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4273                               ip_dst_mask, UINT32);
4274 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask =
4275         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4276                               port_dst_mask, UINT16);
4277 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes =
4278         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4279                                  flexbytes, "flexbytes");
4280 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value =
4281         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4282                               flexbytes_value, UINT8);
4283 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id =
4284         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4285                                  vlan_id, "vlan_id");
4286 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value =
4287         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4288                               vlan_id_value, UINT8);
4289 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio =
4290         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4291                                  vlan_prio, "vlan_prio");
4292 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value =
4293         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4294                               vlan_prio_value, UINT8);
4295
4296 cmdline_parse_inst_t cmd_set_masks_filter = {
4297         .f = cmd_pkt_filter_masks_parsed,
4298         .data = NULL,
4299         .help_str = "setup masks filter",
4300         .tokens = {
4301                 (void *)&cmd_pkt_filter_masks_filter_mask,
4302                 (void *)&cmd_pkt_filter_masks_port_id,
4303                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
4304                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
4305                 (void *)&cmd_pkt_filter_masks_src_mask,
4306                 (void *)&cmd_pkt_filter_masks_ip_src_mask,
4307                 (void *)&cmd_pkt_filter_masks_port_src_mask,
4308                 (void *)&cmd_pkt_filter_masks_dst_mask,
4309                 (void *)&cmd_pkt_filter_masks_ip_dst_mask,
4310                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
4311                 (void *)&cmd_pkt_filter_masks_flexbytes,
4312                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
4313                 (void *)&cmd_pkt_filter_masks_vlan_id,
4314                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
4315                 (void *)&cmd_pkt_filter_masks_vlan_prio,
4316                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
4317                 NULL,
4318         },
4319 };
4320
4321 static void
4322 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result,
4323                           __attribute__((unused)) struct cmdline *cl,
4324                           __attribute__((unused)) void *data)
4325 {
4326         struct rte_fdir_masks fdir_masks;
4327         struct cmd_pkt_filter_masks_result *res = parsed_result;
4328
4329         memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
4330
4331         fdir_masks.set_ipv6_mask = 1;
4332         fdir_masks.only_ip_flow  = res->only_ip_flow_value;
4333         fdir_masks.vlan_id       = res->vlan_id_value;
4334         fdir_masks.vlan_prio     = res->vlan_prio_value;
4335         fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask;
4336         fdir_masks.src_ipv6_mask = res->ipv6_src_mask;
4337         fdir_masks.src_port_mask = res->port_src_mask;
4338         fdir_masks.dst_port_mask = res->port_dst_mask;
4339         fdir_masks.flexbytes     = res->flexbytes_value;
4340         fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value;
4341
4342         fdir_set_masks(res->port_id, &fdir_masks);
4343 }
4344
4345 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 =
4346         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4347                                  filter_mask, "set_ipv6_masks_filter");
4348 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value =
4349         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4350                               ipv6_src_mask, UINT16);
4351 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value =
4352         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4353                               ipv6_dst_mask, UINT16);
4354
4355 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst =
4356         TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result,
4357                                  comp_ipv6_dst, "compare_dst");
4358 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value =
4359         TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result,
4360                               comp_ipv6_dst_value, UINT8);
4361
4362 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = {
4363         .f = cmd_pkt_filter_masks_ipv6_parsed,
4364         .data = NULL,
4365         .help_str = "setup ipv6 masks filter",
4366         .tokens = {
4367                 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6,
4368                 (void *)&cmd_pkt_filter_masks_port_id,
4369                 (void *)&cmd_pkt_filter_masks_only_ip_flow,
4370                 (void *)&cmd_pkt_filter_masks_only_ip_flow_value,
4371                 (void *)&cmd_pkt_filter_masks_src_mask,
4372                 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value,
4373                 (void *)&cmd_pkt_filter_masks_port_src_mask,
4374                 (void *)&cmd_pkt_filter_masks_dst_mask,
4375                 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value,
4376                 (void *)&cmd_pkt_filter_masks_port_dst_mask,
4377                 (void *)&cmd_pkt_filter_masks_flexbytes,
4378                 (void *)&cmd_pkt_filter_masks_flexbytes_value,
4379                 (void *)&cmd_pkt_filter_masks_vlan_id,
4380                 (void *)&cmd_pkt_filter_masks_vlan_id_value,
4381                 (void *)&cmd_pkt_filter_masks_vlan_prio,
4382                 (void *)&cmd_pkt_filter_masks_vlan_prio_value,
4383                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst,
4384                 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value,
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;
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, "info"))
5024                 for (i = 0; i < nb_ports; i++)
5025                         port_infos_display(i);
5026         else if (!strcmp(res->what, "stats"))
5027                 for (i = 0; i < nb_ports; i++)
5028                         nic_stats_display(i);
5029         else if (!strcmp(res->what, "fdir"))
5030                 for (i = 0; i < nb_ports; i++)
5031                         fdir_get_infos(i);
5032         else if (!strcmp(res->what, "stat_qmap"))
5033                 for (i = 0; i < nb_ports; i++)
5034                         nic_stats_mapping_display(i);
5035 }
5036
5037 cmdline_parse_token_string_t cmd_showportall_show =
5038         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5039                                  "show#clear");
5040 cmdline_parse_token_string_t cmd_showportall_port =
5041         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5042 cmdline_parse_token_string_t cmd_showportall_what =
5043         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5044                                  "info#stats#fdir#stat_qmap");
5045 cmdline_parse_token_string_t cmd_showportall_all =
5046         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5047 cmdline_parse_inst_t cmd_showportall = {
5048         .f = cmd_showportall_parsed,
5049         .data = NULL,
5050         .help_str = "show|clear port info|stats|fdir|stat_qmap all",
5051         .tokens = {
5052                 (void *)&cmd_showportall_show,
5053                 (void *)&cmd_showportall_port,
5054                 (void *)&cmd_showportall_what,
5055                 (void *)&cmd_showportall_all,
5056                 NULL,
5057         },
5058 };
5059
5060 /* *** SHOW PORT INFO *** */
5061 struct cmd_showport_result {
5062         cmdline_fixed_string_t show;
5063         cmdline_fixed_string_t port;
5064         cmdline_fixed_string_t what;
5065         uint8_t portnum;
5066 };
5067
5068 static void cmd_showport_parsed(void *parsed_result,
5069                                 __attribute__((unused)) struct cmdline *cl,
5070                                 __attribute__((unused)) void *data)
5071 {
5072         struct cmd_showport_result *res = parsed_result;
5073         if (!strcmp(res->show, "clear")) {
5074                 if (!strcmp(res->what, "stats"))
5075                         nic_stats_clear(res->portnum);
5076         } else if (!strcmp(res->what, "info"))
5077                 port_infos_display(res->portnum);
5078         else if (!strcmp(res->what, "stats"))
5079                 nic_stats_display(res->portnum);
5080         else if (!strcmp(res->what, "fdir"))
5081                  fdir_get_infos(res->portnum);
5082         else if (!strcmp(res->what, "stat_qmap"))
5083                 nic_stats_mapping_display(res->portnum);
5084 }
5085
5086 cmdline_parse_token_string_t cmd_showport_show =
5087         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5088                                  "show#clear");
5089 cmdline_parse_token_string_t cmd_showport_port =
5090         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5091 cmdline_parse_token_string_t cmd_showport_what =
5092         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5093                                  "info#stats#fdir#stat_qmap");
5094 cmdline_parse_token_num_t cmd_showport_portnum =
5095         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
5096
5097 cmdline_parse_inst_t cmd_showport = {
5098         .f = cmd_showport_parsed,
5099         .data = NULL,
5100         .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
5101         .tokens = {
5102                 (void *)&cmd_showport_show,
5103                 (void *)&cmd_showport_port,
5104                 (void *)&cmd_showport_what,
5105                 (void *)&cmd_showport_portnum,
5106                 NULL,
5107         },
5108 };
5109
5110 /* *** READ PORT REGISTER *** */
5111 struct cmd_read_reg_result {
5112         cmdline_fixed_string_t read;
5113         cmdline_fixed_string_t reg;
5114         uint8_t port_id;
5115         uint32_t reg_off;
5116 };
5117
5118 static void
5119 cmd_read_reg_parsed(void *parsed_result,
5120                     __attribute__((unused)) struct cmdline *cl,
5121                     __attribute__((unused)) void *data)
5122 {
5123         struct cmd_read_reg_result *res = parsed_result;
5124         port_reg_display(res->port_id, res->reg_off);
5125 }
5126
5127 cmdline_parse_token_string_t cmd_read_reg_read =
5128         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5129 cmdline_parse_token_string_t cmd_read_reg_reg =
5130         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5131 cmdline_parse_token_num_t cmd_read_reg_port_id =
5132         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5133 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5134         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5135
5136 cmdline_parse_inst_t cmd_read_reg = {
5137         .f = cmd_read_reg_parsed,
5138         .data = NULL,
5139         .help_str = "read reg port_id reg_off",
5140         .tokens = {
5141                 (void *)&cmd_read_reg_read,
5142                 (void *)&cmd_read_reg_reg,
5143                 (void *)&cmd_read_reg_port_id,
5144                 (void *)&cmd_read_reg_reg_off,
5145                 NULL,
5146         },
5147 };
5148
5149 /* *** READ PORT REGISTER BIT FIELD *** */
5150 struct cmd_read_reg_bit_field_result {
5151         cmdline_fixed_string_t read;
5152         cmdline_fixed_string_t regfield;
5153         uint8_t port_id;
5154         uint32_t reg_off;
5155         uint8_t bit1_pos;
5156         uint8_t bit2_pos;
5157 };
5158
5159 static void
5160 cmd_read_reg_bit_field_parsed(void *parsed_result,
5161                               __attribute__((unused)) struct cmdline *cl,
5162                               __attribute__((unused)) void *data)
5163 {
5164         struct cmd_read_reg_bit_field_result *res = parsed_result;
5165         port_reg_bit_field_display(res->port_id, res->reg_off,
5166                                    res->bit1_pos, res->bit2_pos);
5167 }
5168
5169 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5170         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5171                                  "read");
5172 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5173         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5174                                  regfield, "regfield");
5175 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5176         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5177                               UINT8);
5178 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5179         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5180                               UINT32);
5181 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5182         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5183                               UINT8);
5184 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5185         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5186                               UINT8);
5187
5188 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5189         .f = cmd_read_reg_bit_field_parsed,
5190         .data = NULL,
5191         .help_str = "read regfield port_id reg_off bit_x bit_y "
5192         "(read register bit field between bit_x and bit_y included)",
5193         .tokens = {
5194                 (void *)&cmd_read_reg_bit_field_read,
5195                 (void *)&cmd_read_reg_bit_field_regfield,
5196                 (void *)&cmd_read_reg_bit_field_port_id,
5197                 (void *)&cmd_read_reg_bit_field_reg_off,
5198                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5199                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5200                 NULL,
5201         },
5202 };
5203
5204 /* *** READ PORT REGISTER BIT *** */
5205 struct cmd_read_reg_bit_result {
5206         cmdline_fixed_string_t read;
5207         cmdline_fixed_string_t regbit;
5208         uint8_t port_id;
5209         uint32_t reg_off;
5210         uint8_t bit_pos;
5211 };
5212
5213 static void
5214 cmd_read_reg_bit_parsed(void *parsed_result,
5215                         __attribute__((unused)) struct cmdline *cl,
5216                         __attribute__((unused)) void *data)
5217 {
5218         struct cmd_read_reg_bit_result *res = parsed_result;
5219         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5220 }
5221
5222 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5223         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5224 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5225         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5226                                  regbit, "regbit");
5227 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5228         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5229 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5230         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5231 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5232         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5233
5234 cmdline_parse_inst_t cmd_read_reg_bit = {
5235         .f = cmd_read_reg_bit_parsed,
5236         .data = NULL,
5237         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5238         .tokens = {
5239                 (void *)&cmd_read_reg_bit_read,
5240                 (void *)&cmd_read_reg_bit_regbit,
5241                 (void *)&cmd_read_reg_bit_port_id,
5242                 (void *)&cmd_read_reg_bit_reg_off,
5243                 (void *)&cmd_read_reg_bit_bit_pos,
5244                 NULL,
5245         },
5246 };
5247
5248 /* *** WRITE PORT REGISTER *** */
5249 struct cmd_write_reg_result {
5250         cmdline_fixed_string_t write;
5251         cmdline_fixed_string_t reg;
5252         uint8_t port_id;
5253         uint32_t reg_off;
5254         uint32_t value;
5255 };
5256
5257 static void
5258 cmd_write_reg_parsed(void *parsed_result,
5259                      __attribute__((unused)) struct cmdline *cl,
5260                      __attribute__((unused)) void *data)
5261 {
5262         struct cmd_write_reg_result *res = parsed_result;
5263         port_reg_set(res->port_id, res->reg_off, res->value);
5264 }
5265
5266 cmdline_parse_token_string_t cmd_write_reg_write =
5267         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5268 cmdline_parse_token_string_t cmd_write_reg_reg =
5269         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5270 cmdline_parse_token_num_t cmd_write_reg_port_id =
5271         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5272 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5273         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5274 cmdline_parse_token_num_t cmd_write_reg_value =
5275         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5276
5277 cmdline_parse_inst_t cmd_write_reg = {
5278         .f = cmd_write_reg_parsed,
5279         .data = NULL,
5280         .help_str = "write reg port_id reg_off reg_value",
5281         .tokens = {
5282                 (void *)&cmd_write_reg_write,
5283                 (void *)&cmd_write_reg_reg,
5284                 (void *)&cmd_write_reg_port_id,
5285                 (void *)&cmd_write_reg_reg_off,
5286                 (void *)&cmd_write_reg_value,
5287                 NULL,
5288         },
5289 };
5290
5291 /* *** WRITE PORT REGISTER BIT FIELD *** */
5292 struct cmd_write_reg_bit_field_result {
5293         cmdline_fixed_string_t write;
5294         cmdline_fixed_string_t regfield;
5295         uint8_t port_id;
5296         uint32_t reg_off;
5297         uint8_t bit1_pos;
5298         uint8_t bit2_pos;
5299         uint32_t value;
5300 };
5301
5302 static void
5303 cmd_write_reg_bit_field_parsed(void *parsed_result,
5304                                __attribute__((unused)) struct cmdline *cl,
5305                                __attribute__((unused)) void *data)
5306 {
5307         struct cmd_write_reg_bit_field_result *res = parsed_result;
5308         port_reg_bit_field_set(res->port_id, res->reg_off,
5309                           res->bit1_pos, res->bit2_pos, res->value);
5310 }
5311
5312 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5313         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5314                                  "write");
5315 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5316         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5317                                  regfield, "regfield");
5318 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5319         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5320                               UINT8);
5321 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5322         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5323                               UINT32);
5324 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5325         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5326                               UINT8);
5327 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5328         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5329                               UINT8);
5330 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5331         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5332                               UINT32);
5333
5334 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5335         .f = cmd_write_reg_bit_field_parsed,
5336         .data = NULL,
5337         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5338         "(set register bit field between bit_x and bit_y included)",
5339         .tokens = {
5340                 (void *)&cmd_write_reg_bit_field_write,
5341                 (void *)&cmd_write_reg_bit_field_regfield,
5342                 (void *)&cmd_write_reg_bit_field_port_id,
5343                 (void *)&cmd_write_reg_bit_field_reg_off,
5344                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5345                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5346                 (void *)&cmd_write_reg_bit_field_value,
5347                 NULL,
5348         },
5349 };
5350
5351 /* *** WRITE PORT REGISTER BIT *** */
5352 struct cmd_write_reg_bit_result {
5353         cmdline_fixed_string_t write;
5354         cmdline_fixed_string_t regbit;
5355         uint8_t port_id;
5356         uint32_t reg_off;
5357         uint8_t bit_pos;
5358         uint8_t value;
5359 };
5360
5361 static void
5362 cmd_write_reg_bit_parsed(void *parsed_result,
5363                          __attribute__((unused)) struct cmdline *cl,
5364                          __attribute__((unused)) void *data)
5365 {
5366         struct cmd_write_reg_bit_result *res = parsed_result;
5367         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5368 }
5369
5370 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5371         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5372                                  "write");
5373 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5374         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5375                                  regbit, "regbit");
5376 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5377         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5378 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5379         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5380 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5381         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5382 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5383         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5384
5385 cmdline_parse_inst_t cmd_write_reg_bit = {
5386         .f = cmd_write_reg_bit_parsed,
5387         .data = NULL,
5388         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5389         .tokens = {
5390                 (void *)&cmd_write_reg_bit_write,
5391                 (void *)&cmd_write_reg_bit_regbit,
5392                 (void *)&cmd_write_reg_bit_port_id,
5393                 (void *)&cmd_write_reg_bit_reg_off,
5394                 (void *)&cmd_write_reg_bit_bit_pos,
5395                 (void *)&cmd_write_reg_bit_value,
5396                 NULL,
5397         },
5398 };
5399
5400 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5401 struct cmd_read_rxd_txd_result {
5402         cmdline_fixed_string_t read;
5403         cmdline_fixed_string_t rxd_txd;
5404         uint8_t port_id;
5405         uint16_t queue_id;
5406         uint16_t desc_id;
5407 };
5408
5409 static void
5410 cmd_read_rxd_txd_parsed(void *parsed_result,
5411                         __attribute__((unused)) struct cmdline *cl,
5412                         __attribute__((unused)) void *data)
5413 {
5414         struct cmd_read_rxd_txd_result *res = parsed_result;
5415
5416         if (!strcmp(res->rxd_txd, "rxd"))
5417                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5418         else if (!strcmp(res->rxd_txd, "txd"))
5419                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5420 }
5421
5422 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5423         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5424 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5425         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5426                                  "rxd#txd");
5427 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5428         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5429 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5430         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5431 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5432         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5433
5434 cmdline_parse_inst_t cmd_read_rxd_txd = {
5435         .f = cmd_read_rxd_txd_parsed,
5436         .data = NULL,
5437         .help_str = "read rxd|txd port_id queue_id rxd_id",
5438         .tokens = {
5439                 (void *)&cmd_read_rxd_txd_read,
5440                 (void *)&cmd_read_rxd_txd_rxd_txd,
5441                 (void *)&cmd_read_rxd_txd_port_id,
5442                 (void *)&cmd_read_rxd_txd_queue_id,
5443                 (void *)&cmd_read_rxd_txd_desc_id,
5444                 NULL,
5445         },
5446 };
5447
5448 /* *** QUIT *** */
5449 struct cmd_quit_result {
5450         cmdline_fixed_string_t quit;
5451 };
5452
5453 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5454                             struct cmdline *cl,
5455                             __attribute__((unused)) void *data)
5456 {
5457         pmd_test_exit();
5458         cmdline_quit(cl);
5459 }
5460
5461 cmdline_parse_token_string_t cmd_quit_quit =
5462         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5463
5464 cmdline_parse_inst_t cmd_quit = {
5465         .f = cmd_quit_parsed,
5466         .data = NULL,
5467         .help_str = "exit application",
5468         .tokens = {
5469                 (void *)&cmd_quit_quit,
5470                 NULL,
5471         },
5472 };
5473
5474 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5475 struct cmd_mac_addr_result {
5476         cmdline_fixed_string_t mac_addr_cmd;
5477         cmdline_fixed_string_t what;
5478         uint8_t port_num;
5479         struct ether_addr address;
5480 };
5481
5482 static void cmd_mac_addr_parsed(void *parsed_result,
5483                 __attribute__((unused)) struct cmdline *cl,
5484                 __attribute__((unused)) void *data)
5485 {
5486         struct cmd_mac_addr_result *res = parsed_result;
5487         int ret;
5488
5489         if (strcmp(res->what, "add") == 0)
5490                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5491         else
5492                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5493
5494         /* check the return value and print it if is < 0 */
5495         if(ret < 0)
5496                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5497
5498 }
5499
5500 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5501         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5502                                 "mac_addr");
5503 cmdline_parse_token_string_t cmd_mac_addr_what =
5504         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5505                                 "add#remove");
5506 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5507                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5508 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5509                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5510
5511 cmdline_parse_inst_t cmd_mac_addr = {
5512         .f = cmd_mac_addr_parsed,
5513         .data = (void *)0,
5514         .help_str = "mac_addr add|remove X <address>: "
5515                         "add/remove MAC address on port X",
5516         .tokens = {
5517                 (void *)&cmd_mac_addr_cmd,
5518                 (void *)&cmd_mac_addr_what,
5519                 (void *)&cmd_mac_addr_portnum,
5520                 (void *)&cmd_mac_addr_addr,
5521                 NULL,
5522         },
5523 };
5524
5525
5526 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5527 struct cmd_set_qmap_result {
5528         cmdline_fixed_string_t set;
5529         cmdline_fixed_string_t qmap;
5530         cmdline_fixed_string_t what;
5531         uint8_t port_id;
5532         uint16_t queue_id;
5533         uint8_t map_value;
5534 };
5535
5536 static void
5537 cmd_set_qmap_parsed(void *parsed_result,
5538                        __attribute__((unused)) struct cmdline *cl,
5539                        __attribute__((unused)) void *data)
5540 {
5541         struct cmd_set_qmap_result *res = parsed_result;
5542         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5543
5544         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5545 }
5546
5547 cmdline_parse_token_string_t cmd_setqmap_set =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5549                                  set, "set");
5550 cmdline_parse_token_string_t cmd_setqmap_qmap =
5551         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5552                                  qmap, "stat_qmap");
5553 cmdline_parse_token_string_t cmd_setqmap_what =
5554         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5555                                  what, "tx#rx");
5556 cmdline_parse_token_num_t cmd_setqmap_portid =
5557         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5558                               port_id, UINT8);
5559 cmdline_parse_token_num_t cmd_setqmap_queueid =
5560         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5561                               queue_id, UINT16);
5562 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5563         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5564                               map_value, UINT8);
5565
5566 cmdline_parse_inst_t cmd_set_qmap = {
5567         .f = cmd_set_qmap_parsed,
5568         .data = NULL,
5569         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
5570         .tokens = {
5571                 (void *)&cmd_setqmap_set,
5572                 (void *)&cmd_setqmap_qmap,
5573                 (void *)&cmd_setqmap_what,
5574                 (void *)&cmd_setqmap_portid,
5575                 (void *)&cmd_setqmap_queueid,
5576                 (void *)&cmd_setqmap_mapvalue,
5577                 NULL,
5578         },
5579 };
5580
5581 /* *** CONFIGURE UNICAST HASH TABLE *** */
5582 struct cmd_set_uc_hash_table {
5583         cmdline_fixed_string_t set;
5584         cmdline_fixed_string_t port;
5585         uint8_t port_id;
5586         cmdline_fixed_string_t what;
5587         struct ether_addr address;
5588         cmdline_fixed_string_t mode;
5589 };
5590
5591 static void
5592 cmd_set_uc_hash_parsed(void *parsed_result,
5593                        __attribute__((unused)) struct cmdline *cl,
5594                        __attribute__((unused)) void *data)
5595 {
5596         int ret=0;
5597         struct cmd_set_uc_hash_table *res = parsed_result;
5598
5599         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5600
5601         if (strcmp(res->what, "uta") == 0)
5602                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
5603                                                 &res->address,(uint8_t)is_on);
5604         if (ret < 0)
5605                 printf("bad unicast hash table parameter, return code = %d \n", ret);
5606
5607 }
5608
5609 cmdline_parse_token_string_t cmd_set_uc_hash_set =
5610         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5611                                  set, "set");
5612 cmdline_parse_token_string_t cmd_set_uc_hash_port =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5614                                  port, "port");
5615 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
5616         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
5617                               port_id, UINT8);
5618 cmdline_parse_token_string_t cmd_set_uc_hash_what =
5619         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5620                                  what, "uta");
5621 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
5622         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
5623                                 address);
5624 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5626                                  mode, "on#off");
5627
5628 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
5629         .f = cmd_set_uc_hash_parsed,
5630         .data = NULL,
5631         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
5632         .tokens = {
5633                 (void *)&cmd_set_uc_hash_set,
5634                 (void *)&cmd_set_uc_hash_port,
5635                 (void *)&cmd_set_uc_hash_portid,
5636                 (void *)&cmd_set_uc_hash_what,
5637                 (void *)&cmd_set_uc_hash_mac,
5638                 (void *)&cmd_set_uc_hash_mode,
5639                 NULL,
5640         },
5641 };
5642
5643 struct cmd_set_uc_all_hash_table {
5644         cmdline_fixed_string_t set;
5645         cmdline_fixed_string_t port;
5646         uint8_t port_id;
5647         cmdline_fixed_string_t what;
5648         cmdline_fixed_string_t value;
5649         cmdline_fixed_string_t mode;
5650 };
5651
5652 static void
5653 cmd_set_uc_all_hash_parsed(void *parsed_result,
5654                        __attribute__((unused)) struct cmdline *cl,
5655                        __attribute__((unused)) void *data)
5656 {
5657         int ret=0;
5658         struct cmd_set_uc_all_hash_table *res = parsed_result;
5659
5660         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5661
5662         if ((strcmp(res->what, "uta") == 0) &&
5663                 (strcmp(res->value, "all") == 0))
5664                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
5665         if (ret < 0)
5666                 printf("bad unicast hash table parameter,"
5667                         "return code = %d \n", ret);
5668 }
5669
5670 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
5671         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5672                                  set, "set");
5673 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
5674         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5675                                  port, "port");
5676 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
5677         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
5678                               port_id, UINT8);
5679 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
5680         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5681                                  what, "uta");
5682 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
5683         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5684                                 value,"all");
5685 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
5686         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5687                                  mode, "on#off");
5688
5689 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
5690         .f = cmd_set_uc_all_hash_parsed,
5691         .data = NULL,
5692         .help_str = "set port X uta all on|off (X = port number)",
5693         .tokens = {
5694                 (void *)&cmd_set_uc_all_hash_set,
5695                 (void *)&cmd_set_uc_all_hash_port,
5696                 (void *)&cmd_set_uc_all_hash_portid,
5697                 (void *)&cmd_set_uc_all_hash_what,
5698                 (void *)&cmd_set_uc_all_hash_value,
5699                 (void *)&cmd_set_uc_all_hash_mode,
5700                 NULL,
5701         },
5702 };
5703
5704 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
5705 struct cmd_set_vf_traffic {
5706         cmdline_fixed_string_t set;
5707         cmdline_fixed_string_t port;
5708         uint8_t port_id;
5709         cmdline_fixed_string_t vf;
5710         uint8_t vf_id;
5711         cmdline_fixed_string_t what;
5712         cmdline_fixed_string_t mode;
5713 };
5714
5715 static void
5716 cmd_set_vf_traffic_parsed(void *parsed_result,
5717                        __attribute__((unused)) struct cmdline *cl,
5718                        __attribute__((unused)) void *data)
5719 {
5720         struct cmd_set_vf_traffic *res = parsed_result;
5721         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
5722         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5723
5724         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
5725 }
5726
5727 cmdline_parse_token_string_t cmd_setvf_traffic_set =
5728         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
5729                                  set, "set");
5730 cmdline_parse_token_string_t cmd_setvf_traffic_port =
5731         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
5732                                  port, "port");
5733 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
5734         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
5735                               port_id, UINT8);
5736 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
5737         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
5738                                  vf, "vf");
5739 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
5740         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
5741                               vf_id, UINT8);
5742 cmdline_parse_token_string_t cmd_setvf_traffic_what =
5743         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
5744                                  what, "tx#rx");
5745 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
5746         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
5747                                  mode, "on#off");
5748
5749 cmdline_parse_inst_t cmd_set_vf_traffic = {
5750         .f = cmd_set_vf_traffic_parsed,
5751         .data = NULL,
5752         .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)",
5753         .tokens = {
5754                 (void *)&cmd_setvf_traffic_set,
5755                 (void *)&cmd_setvf_traffic_port,
5756                 (void *)&cmd_setvf_traffic_portid,
5757                 (void *)&cmd_setvf_traffic_vf,
5758                 (void *)&cmd_setvf_traffic_vfid,
5759                 (void *)&cmd_setvf_traffic_what,
5760                 (void *)&cmd_setvf_traffic_mode,
5761                 NULL,
5762         },
5763 };
5764
5765 /* *** CONFIGURE VF RECEIVE MODE *** */
5766 struct cmd_set_vf_rxmode {
5767         cmdline_fixed_string_t set;
5768         cmdline_fixed_string_t port;
5769         uint8_t port_id;
5770         cmdline_fixed_string_t vf;
5771         uint8_t vf_id;
5772         cmdline_fixed_string_t what;
5773         cmdline_fixed_string_t mode;
5774         cmdline_fixed_string_t on;
5775 };
5776
5777 static void
5778 cmd_set_vf_rxmode_parsed(void *parsed_result,
5779                        __attribute__((unused)) struct cmdline *cl,
5780                        __attribute__((unused)) void *data)
5781 {
5782         int ret;
5783         uint16_t rx_mode = 0;
5784         struct cmd_set_vf_rxmode *res = parsed_result;
5785
5786         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
5787         if (!strcmp(res->what,"rxmode")) {
5788                 if (!strcmp(res->mode, "AUPE"))
5789                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
5790                 else if (!strcmp(res->mode, "ROPE"))
5791                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
5792                 else if (!strcmp(res->mode, "BAM"))
5793                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
5794                 else if (!strncmp(res->mode, "MPE",3))
5795                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
5796         }
5797
5798         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
5799         if (ret < 0)
5800                 printf("bad VF receive mode parameter, return code = %d \n",
5801                 ret);
5802 }
5803
5804 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
5805         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5806                                  set, "set");
5807 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
5808         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5809                                  port, "port");
5810 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
5811         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
5812                               port_id, UINT8);
5813 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
5814         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5815                                  vf, "vf");
5816 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
5817         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
5818                               vf_id, UINT8);
5819 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
5820         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5821                                  what, "rxmode");
5822 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
5823         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5824                                  mode, "AUPE#ROPE#BAM#MPE");
5825 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
5826         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
5827                                  on, "on#off");
5828
5829 cmdline_parse_inst_t cmd_set_vf_rxmode = {
5830         .f = cmd_set_vf_rxmode_parsed,
5831         .data = NULL,
5832         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
5833         .tokens = {
5834                 (void *)&cmd_set_vf_rxmode_set,
5835                 (void *)&cmd_set_vf_rxmode_port,
5836                 (void *)&cmd_set_vf_rxmode_portid,
5837                 (void *)&cmd_set_vf_rxmode_vf,
5838                 (void *)&cmd_set_vf_rxmode_vfid,
5839                 (void *)&cmd_set_vf_rxmode_what,
5840                 (void *)&cmd_set_vf_rxmode_mode,
5841                 (void *)&cmd_set_vf_rxmode_on,
5842                 NULL,
5843         },
5844 };
5845
5846 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
5847 struct cmd_vf_mac_addr_result {
5848         cmdline_fixed_string_t mac_addr_cmd;
5849         cmdline_fixed_string_t what;
5850         cmdline_fixed_string_t port;
5851         uint8_t port_num;
5852         cmdline_fixed_string_t vf;
5853         uint8_t vf_num;
5854         struct ether_addr address;
5855 };
5856
5857 static void cmd_vf_mac_addr_parsed(void *parsed_result,
5858                 __attribute__((unused)) struct cmdline *cl,
5859                 __attribute__((unused)) void *data)
5860 {
5861         struct cmd_vf_mac_addr_result *res = parsed_result;
5862         int ret = 0;
5863
5864         if (strcmp(res->what, "add") == 0)
5865                 ret = rte_eth_dev_mac_addr_add(res->port_num,
5866                                         &res->address, res->vf_num);
5867         if(ret < 0)
5868                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
5869
5870 }
5871
5872 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
5873         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
5874                                 mac_addr_cmd,"mac_addr");
5875 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
5876         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
5877                                 what,"add");
5878 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
5879         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
5880                                 port,"port");
5881 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
5882         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
5883                                 port_num, UINT8);
5884 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
5885         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
5886                                 vf,"vf");
5887 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
5888         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
5889                                 vf_num, UINT8);
5890 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
5891         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
5892                                 address);
5893
5894 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
5895         .f = cmd_vf_mac_addr_parsed,
5896         .data = (void *)0,
5897         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
5898         "Y = VF number)add MAC address filtering for a VF on port X",
5899         .tokens = {
5900                 (void *)&cmd_vf_mac_addr_cmd,
5901                 (void *)&cmd_vf_mac_addr_what,
5902                 (void *)&cmd_vf_mac_addr_port,
5903                 (void *)&cmd_vf_mac_addr_portnum,
5904                 (void *)&cmd_vf_mac_addr_vf,
5905                 (void *)&cmd_vf_mac_addr_vfnum,
5906                 (void *)&cmd_vf_mac_addr_addr,
5907                 NULL,
5908         },
5909 };
5910
5911 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
5912 struct cmd_vf_rx_vlan_filter {
5913         cmdline_fixed_string_t rx_vlan;
5914         cmdline_fixed_string_t what;
5915         uint16_t vlan_id;
5916         cmdline_fixed_string_t port;
5917         uint8_t port_id;
5918         cmdline_fixed_string_t vf;
5919         uint64_t vf_mask;
5920 };
5921
5922 static void
5923 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
5924                           __attribute__((unused)) struct cmdline *cl,
5925                           __attribute__((unused)) void *data)
5926 {
5927         struct cmd_vf_rx_vlan_filter *res = parsed_result;
5928
5929         if (!strcmp(res->what, "add"))
5930                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
5931         else
5932                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
5933 }
5934
5935 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
5936         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5937                                  rx_vlan, "rx_vlan");
5938 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
5939         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5940                                  what, "add#rm");
5941 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
5942         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5943                               vlan_id, UINT16);
5944 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
5945         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5946                                  port, "port");
5947 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
5948         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5949                               port_id, UINT8);
5950 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
5951         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5952                                  vf, "vf");
5953 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
5954         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
5955                               vf_mask, UINT64);
5956
5957 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
5958         .f = cmd_vf_rx_vlan_filter_parsed,
5959         .data = NULL,
5960         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
5961                 "Y = port number,Z = hexadecimal VF mask)",
5962         .tokens = {
5963                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
5964                 (void *)&cmd_vf_rx_vlan_filter_what,
5965                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
5966                 (void *)&cmd_vf_rx_vlan_filter_port,
5967                 (void *)&cmd_vf_rx_vlan_filter_portid,
5968                 (void *)&cmd_vf_rx_vlan_filter_vf,
5969                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
5970                 NULL,
5971         },
5972 };
5973
5974 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
5975 struct cmd_queue_rate_limit_result {
5976         cmdline_fixed_string_t set;
5977         cmdline_fixed_string_t port;
5978         uint8_t port_num;
5979         cmdline_fixed_string_t queue;
5980         uint8_t queue_num;
5981         cmdline_fixed_string_t rate;
5982         uint16_t rate_num;
5983 };
5984
5985 static void cmd_queue_rate_limit_parsed(void *parsed_result,
5986                 __attribute__((unused)) struct cmdline *cl,
5987                 __attribute__((unused)) void *data)
5988 {
5989         struct cmd_queue_rate_limit_result *res = parsed_result;
5990         int ret = 0;
5991
5992         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
5993                 && (strcmp(res->queue, "queue") == 0)
5994                 && (strcmp(res->rate, "rate") == 0))
5995                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
5996                                         res->rate_num);
5997         if (ret < 0)
5998                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
5999
6000 }
6001
6002 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6003         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6004                                 set, "set");
6005 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6006         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6007                                 port, "port");
6008 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6009         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6010                                 port_num, UINT8);
6011 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6012         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6013                                 queue, "queue");
6014 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6015         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6016                                 queue_num, UINT8);
6017 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6018         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6019                                 rate, "rate");
6020 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6021         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6022                                 rate_num, UINT16);
6023
6024 cmdline_parse_inst_t cmd_queue_rate_limit = {
6025         .f = cmd_queue_rate_limit_parsed,
6026         .data = (void *)0,
6027         .help_str = "set port X queue Y rate Z:(X = port number,"
6028         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6029         .tokens = {
6030                 (void *)&cmd_queue_rate_limit_set,
6031                 (void *)&cmd_queue_rate_limit_port,
6032                 (void *)&cmd_queue_rate_limit_portnum,
6033                 (void *)&cmd_queue_rate_limit_queue,
6034                 (void *)&cmd_queue_rate_limit_queuenum,
6035                 (void *)&cmd_queue_rate_limit_rate,
6036                 (void *)&cmd_queue_rate_limit_ratenum,
6037                 NULL,
6038         },
6039 };
6040
6041 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6042 struct cmd_vf_rate_limit_result {
6043         cmdline_fixed_string_t set;
6044         cmdline_fixed_string_t port;
6045         uint8_t port_num;
6046         cmdline_fixed_string_t vf;
6047         uint8_t vf_num;
6048         cmdline_fixed_string_t rate;
6049         uint16_t rate_num;
6050         cmdline_fixed_string_t q_msk;
6051         uint64_t q_msk_val;
6052 };
6053
6054 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6055                 __attribute__((unused)) struct cmdline *cl,
6056                 __attribute__((unused)) void *data)
6057 {
6058         struct cmd_vf_rate_limit_result *res = parsed_result;
6059         int ret = 0;
6060
6061         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6062                 && (strcmp(res->vf, "vf") == 0)
6063                 && (strcmp(res->rate, "rate") == 0)
6064                 && (strcmp(res->q_msk, "queue_mask") == 0))
6065                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6066                                         res->rate_num, res->q_msk_val);
6067         if (ret < 0)
6068                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6069
6070 }
6071
6072 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6073         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6074                                 set, "set");
6075 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6076         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6077                                 port, "port");
6078 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6079         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6080                                 port_num, UINT8);
6081 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6082         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6083                                 vf, "vf");
6084 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6085         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6086                                 vf_num, UINT8);
6087 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6088         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6089                                 rate, "rate");
6090 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6091         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6092                                 rate_num, UINT16);
6093 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6094         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6095                                 q_msk, "queue_mask");
6096 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6097         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6098                                 q_msk_val, UINT64);
6099
6100 cmdline_parse_inst_t cmd_vf_rate_limit = {
6101         .f = cmd_vf_rate_limit_parsed,
6102         .data = (void *)0,
6103         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6104         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6105         "for queues of VF on port X",
6106         .tokens = {
6107                 (void *)&cmd_vf_rate_limit_set,
6108                 (void *)&cmd_vf_rate_limit_port,
6109                 (void *)&cmd_vf_rate_limit_portnum,
6110                 (void *)&cmd_vf_rate_limit_vf,
6111                 (void *)&cmd_vf_rate_limit_vfnum,
6112                 (void *)&cmd_vf_rate_limit_rate,
6113                 (void *)&cmd_vf_rate_limit_ratenum,
6114                 (void *)&cmd_vf_rate_limit_q_msk,
6115                 (void *)&cmd_vf_rate_limit_q_msk_val,
6116                 NULL,
6117         },
6118 };
6119
6120 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6121 struct cmd_set_mirror_mask_result {
6122         cmdline_fixed_string_t set;
6123         cmdline_fixed_string_t port;
6124         uint8_t port_id;
6125         cmdline_fixed_string_t mirror;
6126         uint8_t rule_id;
6127         cmdline_fixed_string_t what;
6128         cmdline_fixed_string_t value;
6129         cmdline_fixed_string_t dstpool;
6130         uint8_t dstpool_id;
6131         cmdline_fixed_string_t on;
6132 };
6133
6134 cmdline_parse_token_string_t cmd_mirror_mask_set =
6135         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6136                                 set, "set");
6137 cmdline_parse_token_string_t cmd_mirror_mask_port =
6138         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6139                                 port, "port");
6140 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6141         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6142                                 port_id, UINT8);
6143 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6144         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6145                                 mirror, "mirror-rule");
6146 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6147         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6148                                 rule_id, UINT8);
6149 cmdline_parse_token_string_t cmd_mirror_mask_what =
6150         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6151                                 what, "pool-mirror#vlan-mirror");
6152 cmdline_parse_token_string_t cmd_mirror_mask_value =
6153         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6154                                 value, NULL);
6155 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6156         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6157                                 dstpool, "dst-pool");
6158 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6159         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6160                                 dstpool_id, UINT8);
6161 cmdline_parse_token_string_t cmd_mirror_mask_on =
6162         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6163                                 on, "on#off");
6164
6165 static void
6166 cmd_set_mirror_mask_parsed(void *parsed_result,
6167                        __attribute__((unused)) struct cmdline *cl,
6168                        __attribute__((unused)) void *data)
6169 {
6170         int ret,nb_item,i;
6171         struct cmd_set_mirror_mask_result *res = parsed_result;
6172         struct rte_eth_vmdq_mirror_conf mr_conf;
6173
6174         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
6175
6176         unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS];
6177
6178         mr_conf.dst_pool = res->dstpool_id;
6179
6180         if (!strcmp(res->what, "pool-mirror")) {
6181                 mr_conf.pool_mask = strtoull(res->value,NULL,16);
6182                 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR;
6183         } else if(!strcmp(res->what, "vlan-mirror")) {
6184                 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR;
6185                 nb_item = parse_item_list(res->value, "core",
6186                                         ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1);
6187                 if (nb_item <= 0)
6188                         return;
6189
6190                 for(i=0; i < nb_item; i++) {
6191                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6192                                 printf("Invalid vlan_id: must be < 4096\n");
6193                                 return;
6194                         }
6195
6196                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6197                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6198                 }
6199         }
6200
6201         if(!strcmp(res->on, "on"))
6202                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
6203                                                 res->rule_id, 1);
6204         else
6205                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
6206                                                 res->rule_id, 0);
6207         if(ret < 0)
6208                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6209 }
6210
6211 cmdline_parse_inst_t cmd_set_mirror_mask = {
6212                 .f = cmd_set_mirror_mask_parsed,
6213                 .data = NULL,
6214                 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror "
6215                                 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
6216                 .tokens = {
6217                         (void *)&cmd_mirror_mask_set,
6218                         (void *)&cmd_mirror_mask_port,
6219                         (void *)&cmd_mirror_mask_portid,
6220                         (void *)&cmd_mirror_mask_mirror,
6221                         (void *)&cmd_mirror_mask_ruleid,
6222                         (void *)&cmd_mirror_mask_what,
6223                         (void *)&cmd_mirror_mask_value,
6224                         (void *)&cmd_mirror_mask_dstpool,
6225                         (void *)&cmd_mirror_mask_poolid,
6226                         (void *)&cmd_mirror_mask_on,
6227                         NULL,
6228                 },
6229 };
6230
6231 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
6232 struct cmd_set_mirror_link_result {
6233         cmdline_fixed_string_t set;
6234         cmdline_fixed_string_t port;
6235         uint8_t port_id;
6236         cmdline_fixed_string_t mirror;
6237         uint8_t rule_id;
6238         cmdline_fixed_string_t what;
6239         cmdline_fixed_string_t dstpool;
6240         uint8_t dstpool_id;
6241         cmdline_fixed_string_t on;
6242 };
6243
6244 cmdline_parse_token_string_t cmd_mirror_link_set =
6245         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6246                                  set, "set");
6247 cmdline_parse_token_string_t cmd_mirror_link_port =
6248         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6249                                 port, "port");
6250 cmdline_parse_token_num_t cmd_mirror_link_portid =
6251         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6252                                 port_id, UINT8);
6253 cmdline_parse_token_string_t cmd_mirror_link_mirror =
6254         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6255                                 mirror, "mirror-rule");
6256 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
6257         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6258                             rule_id, UINT8);
6259 cmdline_parse_token_string_t cmd_mirror_link_what =
6260         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6261                                 what, "uplink-mirror#downlink-mirror");
6262 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
6263         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6264                                 dstpool, "dst-pool");
6265 cmdline_parse_token_num_t cmd_mirror_link_poolid =
6266         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6267                                 dstpool_id, UINT8);
6268 cmdline_parse_token_string_t cmd_mirror_link_on =
6269         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6270                                 on, "on#off");
6271
6272 static void
6273 cmd_set_mirror_link_parsed(void *parsed_result,
6274                        __attribute__((unused)) struct cmdline *cl,
6275                        __attribute__((unused)) void *data)
6276 {
6277         int ret;
6278         struct cmd_set_mirror_link_result *res = parsed_result;
6279         struct rte_eth_vmdq_mirror_conf mr_conf;
6280
6281         memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf));
6282         if(!strcmp(res->what, "uplink-mirror")) {
6283                 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR;
6284         }else if(!strcmp(res->what, "downlink-mirror"))
6285                 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR;
6286
6287         mr_conf.dst_pool = res->dstpool_id;
6288
6289         if(!strcmp(res->on, "on"))
6290                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
6291                                                 res->rule_id, 1);
6292         else
6293                 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf,
6294                                                 res->rule_id, 0);
6295
6296         /* check the return value and print it if is < 0 */
6297         if(ret < 0)
6298                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6299
6300 }
6301
6302 cmdline_parse_inst_t cmd_set_mirror_link = {
6303                 .f = cmd_set_mirror_link_parsed,
6304                 .data = NULL,
6305                 .help_str = "set port X mirror-rule Y uplink-mirror|"
6306                         "downlink-mirror dst-pool Z on|off",
6307                 .tokens = {
6308                         (void *)&cmd_mirror_link_set,
6309                         (void *)&cmd_mirror_link_port,
6310                         (void *)&cmd_mirror_link_portid,
6311                         (void *)&cmd_mirror_link_mirror,
6312                         (void *)&cmd_mirror_link_ruleid,
6313                         (void *)&cmd_mirror_link_what,
6314                         (void *)&cmd_mirror_link_dstpool,
6315                         (void *)&cmd_mirror_link_poolid,
6316                         (void *)&cmd_mirror_link_on,
6317                         NULL,
6318                 },
6319 };
6320
6321 /* *** RESET VM MIRROR RULE *** */
6322 struct cmd_rm_mirror_rule_result {
6323         cmdline_fixed_string_t reset;
6324         cmdline_fixed_string_t port;
6325         uint8_t port_id;
6326         cmdline_fixed_string_t mirror;
6327         uint8_t rule_id;
6328 };
6329
6330 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
6331         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6332                                  reset, "reset");
6333 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
6334         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6335                                 port, "port");
6336 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
6337         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
6338                                 port_id, UINT8);
6339 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
6340         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6341                                 mirror, "mirror-rule");
6342 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
6343         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
6344                                 rule_id, UINT8);
6345
6346 static void
6347 cmd_reset_mirror_rule_parsed(void *parsed_result,
6348                        __attribute__((unused)) struct cmdline *cl,
6349                        __attribute__((unused)) void *data)
6350 {
6351         int ret;
6352         struct cmd_set_mirror_link_result *res = parsed_result;
6353         /* check rule_id */
6354         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
6355         if(ret < 0)
6356                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
6357 }
6358
6359 cmdline_parse_inst_t cmd_reset_mirror_rule = {
6360                 .f = cmd_reset_mirror_rule_parsed,
6361                 .data = NULL,
6362                 .help_str = "reset port X mirror-rule Y",
6363                 .tokens = {
6364                         (void *)&cmd_rm_mirror_rule_reset,
6365                         (void *)&cmd_rm_mirror_rule_port,
6366                         (void *)&cmd_rm_mirror_rule_portid,
6367                         (void *)&cmd_rm_mirror_rule_mirror,
6368                         (void *)&cmd_rm_mirror_rule_ruleid,
6369                         NULL,
6370                 },
6371 };
6372
6373 /* ******************************************************************************** */
6374
6375 struct cmd_dump_result {
6376         cmdline_fixed_string_t dump;
6377 };
6378
6379 static void
6380 dump_struct_sizes(void)
6381 {
6382 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
6383         DUMP_SIZE(struct rte_mbuf);
6384         DUMP_SIZE(struct rte_pktmbuf);
6385         DUMP_SIZE(struct rte_ctrlmbuf);
6386         DUMP_SIZE(struct rte_mempool);
6387         DUMP_SIZE(struct rte_ring);
6388 #undef DUMP_SIZE
6389 }
6390
6391 static void cmd_dump_parsed(void *parsed_result,
6392                             __attribute__((unused)) struct cmdline *cl,
6393                             __attribute__((unused)) void *data)
6394 {
6395         struct cmd_dump_result *res = parsed_result;
6396
6397         if (!strcmp(res->dump, "dump_physmem"))
6398                 rte_dump_physmem_layout(stdout);
6399         else if (!strcmp(res->dump, "dump_memzone"))
6400                 rte_memzone_dump(stdout);
6401         else if (!strcmp(res->dump, "dump_log_history"))
6402                 rte_log_dump_history(stdout);
6403         else if (!strcmp(res->dump, "dump_struct_sizes"))
6404                 dump_struct_sizes();
6405         else if (!strcmp(res->dump, "dump_ring"))
6406                 rte_ring_list_dump(stdout);
6407         else if (!strcmp(res->dump, "dump_mempool"))
6408                 rte_mempool_list_dump(stdout);
6409         else if (!strcmp(res->dump, "dump_devargs"))
6410                 rte_eal_devargs_dump(stdout);
6411 }
6412
6413 cmdline_parse_token_string_t cmd_dump_dump =
6414         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
6415                 "dump_physmem#"
6416                 "dump_memzone#"
6417                 "dump_log_history#"
6418                 "dump_struct_sizes#"
6419                 "dump_ring#"
6420                 "dump_mempool#"
6421                 "dump_devargs");
6422
6423 cmdline_parse_inst_t cmd_dump = {
6424         .f = cmd_dump_parsed,  /* function to call */
6425         .data = NULL,      /* 2nd arg of func */
6426         .help_str = "dump status",
6427         .tokens = {        /* token list, NULL terminated */
6428                 (void *)&cmd_dump_dump,
6429                 NULL,
6430         },
6431 };
6432
6433 /* ******************************************************************************** */
6434
6435 struct cmd_dump_one_result {
6436         cmdline_fixed_string_t dump;
6437         cmdline_fixed_string_t name;
6438 };
6439
6440 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
6441                                 __attribute__((unused)) void *data)
6442 {
6443         struct cmd_dump_one_result *res = parsed_result;
6444
6445         if (!strcmp(res->dump, "dump_ring")) {
6446                 struct rte_ring *r;
6447                 r = rte_ring_lookup(res->name);
6448                 if (r == NULL) {
6449                         cmdline_printf(cl, "Cannot find ring\n");
6450                         return;
6451                 }
6452                 rte_ring_dump(stdout, r);
6453         } else if (!strcmp(res->dump, "dump_mempool")) {
6454                 struct rte_mempool *mp;
6455                 mp = rte_mempool_lookup(res->name);
6456                 if (mp == NULL) {
6457                         cmdline_printf(cl, "Cannot find mempool\n");
6458                         return;
6459                 }
6460                 rte_mempool_dump(stdout, mp);
6461         }
6462 }
6463
6464 cmdline_parse_token_string_t cmd_dump_one_dump =
6465         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
6466                                  "dump_ring#dump_mempool");
6467
6468 cmdline_parse_token_string_t cmd_dump_one_name =
6469         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
6470
6471 cmdline_parse_inst_t cmd_dump_one = {
6472         .f = cmd_dump_one_parsed,  /* function to call */
6473         .data = NULL,      /* 2nd arg of func */
6474         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
6475         .tokens = {        /* token list, NULL terminated */
6476                 (void *)&cmd_dump_one_dump,
6477                 (void *)&cmd_dump_one_name,
6478                 NULL,
6479         },
6480 };
6481
6482 /* *** ADD/REMOVE an ethertype FILTER *** */
6483 struct cmd_ethertype_filter_result {
6484         cmdline_fixed_string_t filter;
6485         uint8_t port_id;
6486         cmdline_fixed_string_t ethertype;
6487         uint16_t ethertype_value;
6488         cmdline_fixed_string_t priority;
6489         cmdline_fixed_string_t priority_en;
6490         uint8_t priority_value;
6491         cmdline_fixed_string_t queue;
6492         uint16_t queue_id;
6493         cmdline_fixed_string_t index;
6494         uint16_t index_value;
6495 };
6496
6497 static void
6498 cmd_ethertype_filter_parsed(void *parsed_result,
6499                         __attribute__((unused)) struct cmdline *cl,
6500                         __attribute__((unused)) void *data)
6501 {
6502         int ret = 0;
6503         struct cmd_ethertype_filter_result *res = parsed_result;
6504         struct rte_ethertype_filter filter;
6505
6506         memset(&filter, 0, sizeof(struct rte_ethertype_filter));
6507         filter.ethertype = rte_cpu_to_le_16(res->ethertype_value);
6508         filter.priority = res->priority_value;
6509
6510         if (!strcmp(res->priority_en, "enable"))
6511                 filter.priority_en = 1;
6512         if (!strcmp(res->filter, "add_ethertype_filter"))
6513                 ret = rte_eth_dev_add_ethertype_filter(res->port_id,
6514                                 res->index_value,
6515                                 &filter, res->queue_id);
6516         else if (!strcmp(res->filter, "remove_ethertype_filter"))
6517                 ret = rte_eth_dev_remove_ethertype_filter(res->port_id,
6518                                 res->index_value);
6519         else if (!strcmp(res->filter, "get_ethertype_filter"))
6520                 get_ethertype_filter(res->port_id, res->index_value);
6521
6522         if (ret < 0)
6523                 printf("ethertype filter setting error: (%s)\n",
6524                         strerror(-ret));
6525 }
6526
6527 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
6528         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
6529                                 port_id, UINT8);
6530 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
6531         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6532                                 ethertype, "ethertype");
6533 cmdline_parse_token_ipaddr_t cmd_ethertype_filter_ethertype_value =
6534         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
6535                                 ethertype_value, UINT16);
6536 cmdline_parse_token_string_t cmd_ethertype_filter_priority =
6537         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6538                                 priority, "priority");
6539 cmdline_parse_token_string_t cmd_ethertype_filter_priority_en =
6540         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6541                                 priority_en, "enable#disable");
6542 cmdline_parse_token_num_t cmd_ethertype_filter_priority_value =
6543         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
6544                                 priority_value, UINT8);
6545 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
6546         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6547                                 queue, "queue");
6548 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
6549         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
6550                                 queue_id, UINT16);
6551 cmdline_parse_token_string_t cmd_ethertype_filter_index =
6552         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6553                                 index, "index");
6554 cmdline_parse_token_num_t cmd_ethertype_filter_index_value =
6555         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
6556                                 index_value, UINT16);
6557 cmdline_parse_token_string_t cmd_ethertype_filter_add_filter =
6558         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6559                                 filter, "add_ethertype_filter");
6560 cmdline_parse_inst_t cmd_add_ethertype_filter = {
6561         .f = cmd_ethertype_filter_parsed,
6562         .data = NULL,
6563         .help_str = "add an ethertype filter",
6564         .tokens = {
6565                 (void *)&cmd_ethertype_filter_add_filter,
6566                 (void *)&cmd_ethertype_filter_port_id,
6567                 (void *)&cmd_ethertype_filter_ethertype,
6568                 (void *)&cmd_ethertype_filter_ethertype_value,
6569                 (void *)&cmd_ethertype_filter_priority,
6570                 (void *)&cmd_ethertype_filter_priority_en,
6571                 (void *)&cmd_ethertype_filter_priority_value,
6572                 (void *)&cmd_ethertype_filter_queue,
6573                 (void *)&cmd_ethertype_filter_queue_id,
6574                 (void *)&cmd_ethertype_filter_index,
6575                 (void *)&cmd_ethertype_filter_index_value,
6576                 NULL,
6577         },
6578 };
6579
6580 cmdline_parse_token_string_t cmd_ethertype_filter_remove_filter =
6581         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6582                                  filter, "remove_ethertype_filter");
6583 cmdline_parse_inst_t cmd_remove_ethertype_filter = {
6584         .f = cmd_ethertype_filter_parsed,
6585         .data = NULL,
6586         .help_str = "remove an ethertype filter",
6587         .tokens = {
6588                 (void *)&cmd_ethertype_filter_remove_filter,
6589                 (void *)&cmd_ethertype_filter_port_id,
6590                 (void *)&cmd_ethertype_filter_index,
6591                 (void *)&cmd_ethertype_filter_index_value,
6592                 NULL,
6593         },
6594 };
6595 cmdline_parse_token_string_t cmd_ethertype_filter_get_filter =
6596         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
6597                                  filter, "get_ethertype_filter");
6598 cmdline_parse_inst_t cmd_get_ethertype_filter = {
6599         .f = cmd_ethertype_filter_parsed,
6600         .data = NULL,
6601         .help_str = "get an ethertype filter",
6602         .tokens = {
6603                 (void *)&cmd_ethertype_filter_get_filter,
6604                 (void *)&cmd_ethertype_filter_port_id,
6605                 (void *)&cmd_ethertype_filter_index,
6606                 (void *)&cmd_ethertype_filter_index_value,
6607                 NULL,
6608         },
6609 };
6610
6611 /* *** set SYN filter *** */
6612 struct cmd_set_syn_filter_result {
6613         cmdline_fixed_string_t filter;
6614         uint8_t port_id;
6615         cmdline_fixed_string_t priority;
6616         cmdline_fixed_string_t high;
6617         cmdline_fixed_string_t queue;
6618         uint16_t  queue_id;
6619 };
6620
6621 static void
6622 cmd_set_syn_filter_parsed(void *parsed_result,
6623                         __attribute__((unused)) struct cmdline *cl,
6624                         __attribute__((unused)) void *data)
6625 {
6626         int ret = 0;
6627         struct cmd_set_syn_filter_result *res = parsed_result;
6628         struct rte_syn_filter filter;
6629
6630         if (!strcmp(res->filter, "add_syn_filter")) {
6631                 if (!strcmp(res->high, "high"))
6632                         filter.hig_pri = 1;
6633                 else
6634                         filter.hig_pri = 0;
6635                 ret = rte_eth_dev_add_syn_filter(res->port_id,
6636                                 &filter, res->queue_id);
6637         } else if (!strcmp(res->filter, "remove_syn_filter"))
6638                 ret = rte_eth_dev_remove_syn_filter(res->port_id);
6639         else if (!strcmp(res->filter, "get_syn_filter"))
6640                 get_syn_filter(res->port_id);
6641         if (ret < 0)
6642                 printf("syn filter setting error: (%s)\n", strerror(-ret));
6643
6644 }
6645 cmdline_parse_token_num_t cmd_syn_filter_portid =
6646         TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
6647                                 port_id, UINT8);
6648 cmdline_parse_token_string_t cmd_syn_filter_priority =
6649         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6650                                 priority, "priority");
6651 cmdline_parse_token_string_t cmd_syn_filter_high =
6652         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6653                                 high, "high#low");
6654 cmdline_parse_token_string_t cmd_syn_filter_queue =
6655         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6656                                 queue, "queue");
6657 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
6658         TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
6659                                 queue_id, UINT16);
6660 cmdline_parse_token_string_t cmd_syn_filter_add_filter =
6661         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6662                                 filter, "add_syn_filter");
6663 cmdline_parse_token_string_t cmd_syn_filter_remove_filter =
6664         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6665                                 filter, "remove_syn_filter");
6666 cmdline_parse_inst_t cmd_add_syn_filter = {
6667                 .f = cmd_set_syn_filter_parsed,
6668                 .data = NULL,
6669                 .help_str = "add syn filter",
6670                 .tokens = {
6671                         (void *)&cmd_syn_filter_add_filter,
6672                         (void *)&cmd_syn_filter_portid,
6673                         (void *)&cmd_syn_filter_priority,
6674                         (void *)&cmd_syn_filter_high,
6675                         (void *)&cmd_syn_filter_queue,
6676                         (void *)&cmd_syn_filter_queue_id,
6677                         NULL,
6678                 },
6679 };
6680 cmdline_parse_inst_t cmd_remove_syn_filter = {
6681                 .f = cmd_set_syn_filter_parsed,
6682                 .data = NULL,
6683                 .help_str = "remove syn filter",
6684                 .tokens = {
6685                         (void *)&cmd_syn_filter_remove_filter,
6686                         (void *)&cmd_syn_filter_portid,
6687                         NULL,
6688                 },
6689 };
6690
6691 cmdline_parse_token_string_t cmd_syn_filter_get_filter =
6692         TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
6693                                 filter, "get_syn_filter");
6694
6695 cmdline_parse_inst_t cmd_get_syn_filter = {
6696                 .f = cmd_set_syn_filter_parsed,
6697                 .data = NULL,
6698                 .help_str = "get syn filter",
6699                 .tokens = {
6700                         (void *)&cmd_syn_filter_get_filter,
6701                         (void *)&cmd_syn_filter_portid,
6702                         NULL,
6703                 },
6704 };
6705
6706 /* *** ADD/REMOVE A 2tuple FILTER *** */
6707 struct cmd_2tuple_filter_result {
6708         cmdline_fixed_string_t filter;
6709         uint8_t port_id;
6710         cmdline_fixed_string_t protocol;
6711         uint8_t protocol_value;
6712         uint8_t protocol_mask;
6713         cmdline_fixed_string_t dst_port;
6714         uint16_t dst_port_value;
6715         uint16_t dst_port_mask;
6716         cmdline_fixed_string_t flags;
6717         uint8_t flags_value;
6718         cmdline_fixed_string_t priority;
6719         uint8_t priority_value;
6720         cmdline_fixed_string_t queue;
6721         uint16_t queue_id;
6722         cmdline_fixed_string_t index;
6723         uint16_t index_value;
6724 };
6725
6726 static void
6727 cmd_2tuple_filter_parsed(void *parsed_result,
6728                         __attribute__((unused)) struct cmdline *cl,
6729                         __attribute__((unused)) void *data)
6730 {
6731         int ret = 0;
6732         struct rte_2tuple_filter filter;
6733         struct cmd_2tuple_filter_result *res = parsed_result;
6734
6735         memset(&filter, 0, sizeof(struct rte_2tuple_filter));
6736
6737         if (!strcmp(res->filter, "add_2tuple_filter")) {
6738                 /* need convert to big endian. */
6739                 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
6740                 filter.protocol = res->protocol_value;
6741                 filter.dst_port_mask = (res->dst_port_mask) ? 0 : 1;
6742                 filter.protocol_mask = (res->protocol_mask) ? 0 : 1;
6743                 filter.priority = res->priority_value;
6744                 filter.tcp_flags = res->flags_value;
6745                 ret = rte_eth_dev_add_2tuple_filter(res->port_id,
6746                         res->index_value, &filter, res->queue_id);
6747         } else if (!strcmp(res->filter, "remove_2tuple_filter"))
6748                 ret = rte_eth_dev_remove_2tuple_filter(res->port_id,
6749                         res->index_value);
6750         else if (!strcmp(res->filter, "get_2tuple_filter"))
6751                 get_2tuple_filter(res->port_id, res->index_value);
6752
6753         if (ret < 0)
6754                 printf("2tuple filter setting error: (%s)\n", strerror(-ret));
6755 }
6756
6757 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
6758         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6759                                 port_id, UINT8);
6760 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
6761         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6762                                  protocol, "protocol");
6763 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
6764         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6765                                  protocol_value, UINT8);
6766 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_mask =
6767         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6768                                 protocol_mask, UINT8);
6769 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
6770         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6771                                 dst_port, "dst_port");
6772 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
6773         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6774                                 dst_port_value, UINT16);
6775 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_mask =
6776         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6777                                 dst_port_mask, UINT16);
6778 cmdline_parse_token_string_t cmd_2tuple_filter_flags =
6779         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6780                                 flags, "flags");
6781 cmdline_parse_token_num_t cmd_2tuple_filter_flags_value =
6782         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6783                                 flags_value, UINT8);
6784 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
6785         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6786                                 priority, "priority");
6787 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
6788         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6789                                 priority_value, UINT8);
6790 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
6791         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6792                                 queue, "queue");
6793 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
6794         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6795                                 queue_id, UINT16);
6796 cmdline_parse_token_string_t cmd_2tuple_filter_index =
6797         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6798                                 index, "index");
6799 cmdline_parse_token_num_t cmd_2tuple_filter_index_value =
6800         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
6801                                 index_value, UINT16);
6802 cmdline_parse_token_string_t cmd_2tuple_filter_add_filter =
6803         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6804                                 filter, "add_2tuple_filter");
6805 cmdline_parse_inst_t cmd_add_2tuple_filter = {
6806         .f = cmd_2tuple_filter_parsed,
6807         .data = NULL,
6808         .help_str = "add a 2tuple filter",
6809         .tokens = {
6810                 (void *)&cmd_2tuple_filter_add_filter,
6811                 (void *)&cmd_2tuple_filter_port_id,
6812                 (void *)&cmd_2tuple_filter_protocol,
6813                 (void *)&cmd_2tuple_filter_protocol_value,
6814                 (void *)&cmd_2tuple_filter_protocol_mask,
6815                 (void *)&cmd_2tuple_filter_dst_port,
6816                 (void *)&cmd_2tuple_filter_dst_port_value,
6817                 (void *)&cmd_2tuple_filter_dst_port_mask,
6818                 (void *)&cmd_2tuple_filter_flags,
6819                 (void *)&cmd_2tuple_filter_flags_value,
6820                 (void *)&cmd_2tuple_filter_priority,
6821                 (void *)&cmd_2tuple_filter_priority_value,
6822                 (void *)&cmd_2tuple_filter_queue,
6823                 (void *)&cmd_2tuple_filter_queue_id,
6824                 (void *)&cmd_2tuple_filter_index,
6825                 (void *)&cmd_2tuple_filter_index_value,
6826                 NULL,
6827         },
6828 };
6829
6830 cmdline_parse_token_string_t cmd_2tuple_filter_remove_filter =
6831         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6832                                 filter, "remove_2tuple_filter");
6833 cmdline_parse_inst_t cmd_remove_2tuple_filter = {
6834         .f = cmd_2tuple_filter_parsed,
6835         .data = NULL,
6836         .help_str = "remove a 2tuple filter",
6837         .tokens = {
6838                 (void *)&cmd_2tuple_filter_remove_filter,
6839                 (void *)&cmd_2tuple_filter_port_id,
6840                 (void *)&cmd_2tuple_filter_index,
6841                 (void *)&cmd_2tuple_filter_index_value,
6842                 NULL,
6843         },
6844 };
6845 cmdline_parse_token_string_t cmd_2tuple_filter_get_filter =
6846         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
6847                                 filter, "get_2tuple_filter");
6848 cmdline_parse_inst_t cmd_get_2tuple_filter = {
6849         .f = cmd_2tuple_filter_parsed,
6850         .data = NULL,
6851         .help_str = "get a 2tuple filter",
6852         .tokens = {
6853                 (void *)&cmd_2tuple_filter_get_filter,
6854                 (void *)&cmd_2tuple_filter_port_id,
6855                 (void *)&cmd_2tuple_filter_index,
6856                 (void *)&cmd_2tuple_filter_index_value,
6857                 NULL,
6858         },
6859 };
6860
6861 /* *** ADD/REMOVE A 5tuple FILTER *** */
6862 struct cmd_5tuple_filter_result {
6863         cmdline_fixed_string_t filter;
6864         uint8_t  port_id;
6865         cmdline_fixed_string_t dst_ip;
6866         cmdline_ipaddr_t dst_ip_value;
6867         cmdline_fixed_string_t src_ip;
6868         cmdline_ipaddr_t src_ip_value;
6869         cmdline_fixed_string_t dst_port;
6870         uint16_t dst_port_value;
6871         cmdline_fixed_string_t src_port;
6872         uint16_t src_port_value;
6873         cmdline_fixed_string_t protocol;
6874         uint8_t protocol_value;
6875         cmdline_fixed_string_t mask;
6876         uint8_t  mask_value;
6877         cmdline_fixed_string_t flags;
6878         uint8_t flags_value;
6879         cmdline_fixed_string_t priority;
6880         uint8_t  priority_value;
6881         cmdline_fixed_string_t queue;
6882         uint16_t  queue_id;
6883         cmdline_fixed_string_t index;
6884         uint16_t  index_value;
6885 };
6886
6887 static void
6888 cmd_5tuple_filter_parsed(void *parsed_result,
6889                         __attribute__((unused)) struct cmdline *cl,
6890                         __attribute__((unused)) void *data)
6891 {
6892         int ret = 0;
6893         struct rte_5tuple_filter filter;
6894         struct cmd_5tuple_filter_result *res = parsed_result;
6895
6896         memset(&filter, 0, sizeof(struct rte_5tuple_filter));
6897
6898         if (!strcmp(res->filter, "add_5tuple_filter")) {
6899                 filter.dst_ip_mask = (res->mask_value & 0x10) ? 0 : 1;
6900                 filter.src_ip_mask = (res->mask_value & 0x08) ? 0 : 1;
6901                 filter.dst_port_mask = (res->mask_value & 0x04) ? 0 : 1;
6902                 filter.src_port_mask = (res->mask_value & 0x02) ? 0 : 1;
6903                 filter.protocol = res->protocol_value;
6904                 filter.protocol_mask = (res->mask_value & 0x01) ? 0 : 1;
6905                 filter.priority = res->priority_value;
6906                 filter.tcp_flags = res->flags_value;
6907
6908                 if (res->dst_ip_value.family == AF_INET)
6909                         /* no need to convert, already big endian. */
6910                         filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
6911                 else {
6912                         if (filter.dst_ip_mask == 0) {
6913                                 printf("can not support ipv6 involved compare.\n");
6914                                 return;
6915                         }
6916                         filter.dst_ip = 0;
6917                 }
6918
6919                 if (res->src_ip_value.family == AF_INET)
6920                         /* no need to convert, already big endian. */
6921                         filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
6922                 else {
6923                         if (filter.src_ip_mask == 0) {
6924                                 printf("can not support ipv6 involved compare.\n");
6925                                 return;
6926                         }
6927                         filter.src_ip = 0;
6928                 }
6929                 /* need convert to big endian. */
6930                 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
6931                 filter.src_port = rte_cpu_to_be_16(res->src_port_value);
6932
6933                 ret = rte_eth_dev_add_5tuple_filter(res->port_id,
6934                         res->index_value, &filter, res->queue_id);
6935         } else if (!strcmp(res->filter, "remove_5tuple_filter"))
6936                 ret = rte_eth_dev_remove_5tuple_filter(res->port_id,
6937                         res->index_value);
6938         else if (!strcmp(res->filter, "get_5tuple_filter"))
6939                 get_5tuple_filter(res->port_id, res->index_value);
6940         if (ret < 0)
6941                 printf("5tuple filter setting error: (%s)\n", strerror(-ret));
6942 }
6943
6944
6945 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
6946         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6947                                 port_id, UINT8);
6948 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
6949         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6950                                 dst_ip, "dst_ip");
6951 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
6952         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
6953                                 dst_ip_value);
6954 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
6955         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6956                                 src_ip, "src_ip");
6957 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
6958         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
6959                                 src_ip_value);
6960 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
6961         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6962                                 dst_port, "dst_port");
6963 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
6964         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6965                                 dst_port_value, UINT16);
6966 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
6967         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6968                                 src_port, "src_port");
6969 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
6970         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6971                                 src_port_value, UINT16);
6972 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
6973         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6974                                 protocol, "protocol");
6975 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
6976         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6977                                 protocol_value, UINT8);
6978 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
6979         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6980                                 mask, "mask");
6981 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
6982         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6983                                 mask_value, INT8);
6984 cmdline_parse_token_string_t cmd_5tuple_filter_flags =
6985         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6986                                 flags, "flags");
6987 cmdline_parse_token_num_t cmd_5tuple_filter_flags_value =
6988         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6989                                 flags_value, UINT8);
6990 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
6991         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6992                                 priority, "priority");
6993 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
6994         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
6995                                 priority_value, UINT8);
6996 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
6997         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
6998                                 queue, "queue");
6999 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7000         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7001                                 queue_id, UINT16);
7002 cmdline_parse_token_string_t cmd_5tuple_filter_index =
7003         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7004                                 index, "index");
7005 cmdline_parse_token_num_t cmd_5tuple_filter_index_value =
7006         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7007                                 index_value, UINT16);
7008
7009 cmdline_parse_token_string_t cmd_5tuple_filter_add_filter =
7010         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7011                                  filter, "add_5tuple_filter");
7012 cmdline_parse_inst_t cmd_add_5tuple_filter = {
7013         .f = cmd_5tuple_filter_parsed,
7014         .data = NULL,
7015         .help_str = "add a 5tuple filter",
7016         .tokens = {
7017                 (void *)&cmd_5tuple_filter_add_filter,
7018                 (void *)&cmd_5tuple_filter_port_id,
7019                 (void *)&cmd_5tuple_filter_dst_ip,
7020                 (void *)&cmd_5tuple_filter_dst_ip_value,
7021                 (void *)&cmd_5tuple_filter_src_ip,
7022                 (void *)&cmd_5tuple_filter_src_ip_value,
7023                 (void *)&cmd_5tuple_filter_dst_port,
7024                 (void *)&cmd_5tuple_filter_dst_port_value,
7025                 (void *)&cmd_5tuple_filter_src_port,
7026                 (void *)&cmd_5tuple_filter_src_port_value,
7027                 (void *)&cmd_5tuple_filter_protocol,
7028                 (void *)&cmd_5tuple_filter_protocol_value,
7029                 (void *)&cmd_5tuple_filter_mask,
7030                 (void *)&cmd_5tuple_filter_mask_value,
7031                 (void *)&cmd_5tuple_filter_flags,
7032                 (void *)&cmd_5tuple_filter_flags_value,
7033                 (void *)&cmd_5tuple_filter_priority,
7034                 (void *)&cmd_5tuple_filter_priority_value,
7035                 (void *)&cmd_5tuple_filter_queue,
7036                 (void *)&cmd_5tuple_filter_queue_id,
7037                 (void *)&cmd_5tuple_filter_index,
7038                 (void *)&cmd_5tuple_filter_index_value,
7039                 NULL,
7040         },
7041 };
7042
7043 cmdline_parse_token_string_t cmd_5tuple_filter_remove_filter =
7044         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7045                                 filter, "remove_5tuple_filter");
7046 cmdline_parse_inst_t cmd_remove_5tuple_filter = {
7047         .f = cmd_5tuple_filter_parsed,
7048         .data = NULL,
7049         .help_str = "remove a 5tuple filter",
7050         .tokens = {
7051                 (void *)&cmd_5tuple_filter_remove_filter,
7052                 (void *)&cmd_5tuple_filter_port_id,
7053                 (void *)&cmd_5tuple_filter_index,
7054                 (void *)&cmd_5tuple_filter_index_value,
7055                 NULL,
7056         },
7057 };
7058
7059 cmdline_parse_token_string_t cmd_5tuple_filter_get_filter =
7060         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7061                                 filter, "get_5tuple_filter");
7062 cmdline_parse_inst_t cmd_get_5tuple_filter = {
7063         .f = cmd_5tuple_filter_parsed,
7064         .data = NULL,
7065         .help_str = "get a 5tuple filter",
7066         .tokens = {
7067                 (void *)&cmd_5tuple_filter_get_filter,
7068                 (void *)&cmd_5tuple_filter_port_id,
7069                 (void *)&cmd_5tuple_filter_index,
7070                 (void *)&cmd_5tuple_filter_index_value,
7071                 NULL,
7072         },
7073 };
7074
7075 /* *** ADD/REMOVE A flex FILTER *** */
7076 struct cmd_flex_filter_result {
7077         cmdline_fixed_string_t filter;
7078         uint8_t port_id;
7079         cmdline_fixed_string_t len;
7080         uint8_t len_value;
7081         cmdline_fixed_string_t bytes;
7082         cmdline_fixed_string_t bytes_value;
7083         cmdline_fixed_string_t mask;
7084         cmdline_fixed_string_t mask_value;
7085         cmdline_fixed_string_t priority;
7086         uint8_t priority_value;
7087         cmdline_fixed_string_t queue;
7088         uint16_t queue_id;
7089         cmdline_fixed_string_t index;
7090         uint16_t index_value;
7091 };
7092
7093 static int xdigit2val(unsigned char c)
7094 {
7095         int val;
7096         if (isdigit(c))
7097                 val = c - '0';
7098         else if (isupper(c))
7099                 val = c - 'A' + 10;
7100         else
7101                 val = c - 'a' + 10;
7102         return val;
7103 }
7104
7105 static void
7106 cmd_flex_filter_parsed(void *parsed_result,
7107                           __attribute__((unused)) struct cmdline *cl,
7108                           __attribute__((unused)) void *data)
7109 {
7110         int ret = 0;
7111         struct rte_flex_filter filter;
7112         struct cmd_flex_filter_result *res = parsed_result;
7113         char *bytes_ptr, *mask_ptr;
7114         uint16_t len, i, j;
7115         char c;
7116         int val, mod = 0;
7117         uint32_t dword = 0;
7118         uint8_t byte = 0;
7119         uint8_t hex = 0;
7120
7121         if (!strcmp(res->filter, "add_flex_filter")) {
7122                 if (res->len_value > 128) {
7123                         printf("the len exceed the max length 128\n");
7124                         return;
7125                 }
7126                 memset(&filter, 0, sizeof(struct rte_flex_filter));
7127                 filter.len = res->len_value;
7128                 filter.priority = res->priority_value;
7129                 bytes_ptr = res->bytes_value;
7130                 mask_ptr = res->mask_value;
7131
7132                 j = 0;
7133                  /* translate bytes string to uint_32 array. */
7134                 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7135                         (bytes_ptr[1] == 'X')))
7136                         bytes_ptr += 2;
7137                 len = strnlen(bytes_ptr, res->len_value * 2);
7138                 if (len == 0 || (len % 8 != 0)) {
7139                         printf("please check len and bytes input\n");
7140                         return;
7141                 }
7142                 for (i = 0; i < len; i++) {
7143                         c = bytes_ptr[i];
7144                         if (isxdigit(c) == 0) {
7145                                 /* invalid characters. */
7146                                 printf("invalid input\n");
7147                                 return;
7148                         }
7149                         val = xdigit2val(c);
7150                         mod = i % 8;
7151                         if (i % 2) {
7152                                 byte |= val;
7153                                 dword |= byte << (4 * mod - 4);
7154                                 byte = 0;
7155                         } else
7156                                 byte |= val << 4;
7157                         if (mod == 7) {
7158                                 filter.dwords[j] = dword;
7159                                 printf("dwords[%d]:%08x ", j, filter.dwords[j]);
7160                                 j++;
7161                                 dword = 0;
7162                         }
7163                 }
7164                 printf("\n");
7165                  /* translate mask string to uint8_t array. */
7166                 j = 0;
7167                 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7168                         (mask_ptr[1] == 'X')))
7169                         mask_ptr += 2;
7170                 len = strnlen(mask_ptr, (res->len_value+3)/4);
7171                 if (len == 0) {
7172                         printf("invalid input\n");
7173                         return;
7174                 }
7175                 for (i = 0; i < len; i++) {
7176                         c = mask_ptr[i];
7177                         if (isxdigit(c) == 0) {
7178                                 /* invalid characters. */
7179                                 printf("invalid input\n");
7180                                 return;
7181                         }
7182                         val = xdigit2val(c);
7183                         hex |= (uint8_t)(val & 0x8) >> 3;
7184                         hex |= (uint8_t)(val & 0x4) >> 1;
7185                         hex |= (uint8_t)(val & 0x2) << 1;
7186                         hex |= (uint8_t)(val & 0x1) << 3;
7187                         if (i % 2) {
7188                                 byte |= hex << 4;
7189                                 filter.mask[j] = byte;
7190                                 printf("mask[%d]:%02x ", j, filter.mask[j]);
7191                                 j++;
7192                                 byte = 0;
7193                         } else
7194                                 byte |= hex;
7195                         hex = 0;
7196                 }
7197                 printf("\n");
7198                 printf("call function rte_eth_dev_add_flex_filter: "
7199                         "index = %d, queue-id = %d, len = %d, priority = %d\n",
7200                         res->index_value, res->queue_id,
7201                         filter.len, filter.priority);
7202                 ret = rte_eth_dev_add_flex_filter(res->port_id, res->index_value,
7203                                 &filter, res->queue_id);
7204
7205         } else if (!strcmp(res->filter, "remove_flex_filter"))
7206                 ret = rte_eth_dev_remove_flex_filter(res->port_id,
7207                         res->index_value);
7208         else if (!strcmp(res->filter, "get_flex_filter"))
7209                 get_flex_filter(res->port_id, res->index_value);
7210
7211         if (ret < 0)
7212                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7213 }
7214
7215 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7216         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7217                                 port_id, UINT8);
7218 cmdline_parse_token_string_t cmd_flex_filter_len =
7219         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7220                                 len, "len");
7221 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7222         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7223                                 len_value, UINT8);
7224 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7225         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7226                                 bytes, "bytes");
7227 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7228         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7229                                 bytes_value, NULL);
7230 cmdline_parse_token_string_t cmd_flex_filter_mask =
7231         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7232                                 mask, "mask");
7233 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7234         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7235                                 mask_value, NULL);
7236 cmdline_parse_token_string_t cmd_flex_filter_priority =
7237         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7238                                 priority, "priority");
7239 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7240         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7241                                 priority_value, UINT8);
7242 cmdline_parse_token_string_t cmd_flex_filter_queue =
7243         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7244                                 queue, "queue");
7245 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7246         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7247                                 queue_id, UINT16);
7248 cmdline_parse_token_string_t cmd_flex_filter_index =
7249         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7250                                 index, "index");
7251 cmdline_parse_token_num_t cmd_flex_filter_index_value =
7252         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7253                                 index_value, UINT16);
7254 cmdline_parse_token_string_t cmd_flex_filter_add_filter =
7255         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7256                                 filter, "add_flex_filter");
7257 cmdline_parse_inst_t cmd_add_flex_filter = {
7258         .f = cmd_flex_filter_parsed,
7259         .data = NULL,
7260         .help_str = "add a flex filter",
7261         .tokens = {
7262                 (void *)&cmd_flex_filter_add_filter,
7263                 (void *)&cmd_flex_filter_port_id,
7264                 (void *)&cmd_flex_filter_len,
7265                 (void *)&cmd_flex_filter_len_value,
7266                 (void *)&cmd_flex_filter_bytes,
7267                 (void *)&cmd_flex_filter_bytes_value,
7268                 (void *)&cmd_flex_filter_mask,
7269                 (void *)&cmd_flex_filter_mask_value,
7270                 (void *)&cmd_flex_filter_priority,
7271                 (void *)&cmd_flex_filter_priority_value,
7272                 (void *)&cmd_flex_filter_queue,
7273                 (void *)&cmd_flex_filter_queue_id,
7274                 (void *)&cmd_flex_filter_index,
7275                 (void *)&cmd_flex_filter_index_value,
7276                 NULL,
7277         },
7278 };
7279
7280 cmdline_parse_token_string_t cmd_flex_filter_remove_filter =
7281         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7282                                 filter, "remove_flex_filter");
7283 cmdline_parse_inst_t cmd_remove_flex_filter = {
7284         .f = cmd_flex_filter_parsed,
7285         .data = NULL,
7286         .help_str = "remove a flex filter",
7287         .tokens = {
7288                 (void *)&cmd_flex_filter_remove_filter,
7289                 (void *)&cmd_flex_filter_port_id,
7290                 (void *)&cmd_flex_filter_index,
7291                 (void *)&cmd_flex_filter_index_value,
7292                 NULL,
7293         },
7294 };
7295
7296 cmdline_parse_token_string_t cmd_flex_filter_get_filter =
7297         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7298                                 filter, "get_flex_filter");
7299 cmdline_parse_inst_t cmd_get_flex_filter = {
7300         .f = cmd_flex_filter_parsed,
7301         .data = NULL,
7302         .help_str = "get a flex filter",
7303         .tokens = {
7304                 (void *)&cmd_flex_filter_get_filter,
7305                 (void *)&cmd_flex_filter_port_id,
7306                 (void *)&cmd_flex_filter_index,
7307                 (void *)&cmd_flex_filter_index_value,
7308                 NULL,
7309         },
7310 };
7311
7312 /* ******************************************************************************** */
7313
7314 /* list of instructions */
7315 cmdline_parse_ctx_t main_ctx[] = {
7316         (cmdline_parse_inst_t *)&cmd_help_brief,
7317         (cmdline_parse_inst_t *)&cmd_help_long,
7318         (cmdline_parse_inst_t *)&cmd_quit,
7319         (cmdline_parse_inst_t *)&cmd_showport,
7320         (cmdline_parse_inst_t *)&cmd_showportall,
7321         (cmdline_parse_inst_t *)&cmd_showcfg,
7322         (cmdline_parse_inst_t *)&cmd_start,
7323         (cmdline_parse_inst_t *)&cmd_start_tx_first,
7324         (cmdline_parse_inst_t *)&cmd_set_link_up,
7325         (cmdline_parse_inst_t *)&cmd_set_link_down,
7326         (cmdline_parse_inst_t *)&cmd_reset,
7327         (cmdline_parse_inst_t *)&cmd_set_numbers,
7328         (cmdline_parse_inst_t *)&cmd_set_txpkts,
7329         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
7330         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
7331         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
7332         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
7333         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
7334         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
7335         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
7336         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
7337         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
7338         (cmdline_parse_inst_t *)&cmd_set_link_check,
7339 #ifdef RTE_NIC_BYPASS
7340         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
7341         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
7342         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
7343         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
7344 #endif
7345 #ifdef RTE_LIBRTE_PMD_BOND
7346         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
7347         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
7348         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
7349         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
7350         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
7351         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
7352         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
7353         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
7354 #endif
7355         (cmdline_parse_inst_t *)&cmd_vlan_offload,
7356         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
7357         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
7358         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
7359         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
7360         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
7361         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
7362         (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
7363         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
7364         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
7365         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
7366         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
7367         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
7368         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
7369         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
7370         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
7371         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
7372         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
7373         (cmdline_parse_inst_t *)&cmd_config_dcb,
7374         (cmdline_parse_inst_t *)&cmd_read_reg,
7375         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
7376         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
7377         (cmdline_parse_inst_t *)&cmd_write_reg,
7378         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
7379         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
7380         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
7381         (cmdline_parse_inst_t *)&cmd_add_signature_filter,
7382         (cmdline_parse_inst_t *)&cmd_upd_signature_filter,
7383         (cmdline_parse_inst_t *)&cmd_rm_signature_filter,
7384         (cmdline_parse_inst_t *)&cmd_add_perfect_filter,
7385         (cmdline_parse_inst_t *)&cmd_upd_perfect_filter,
7386         (cmdline_parse_inst_t *)&cmd_rm_perfect_filter,
7387         (cmdline_parse_inst_t *)&cmd_set_masks_filter,
7388         (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter,
7389         (cmdline_parse_inst_t *)&cmd_stop,
7390         (cmdline_parse_inst_t *)&cmd_mac_addr,
7391         (cmdline_parse_inst_t *)&cmd_set_qmap,
7392         (cmdline_parse_inst_t *)&cmd_operate_port,
7393         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
7394         (cmdline_parse_inst_t *)&cmd_config_speed_all,
7395         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
7396         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
7397         (cmdline_parse_inst_t *)&cmd_config_mtu,
7398         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
7399         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
7400         (cmdline_parse_inst_t *)&cmd_config_rss,
7401         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
7402         (cmdline_parse_inst_t *)&cmd_showport_reta,
7403         (cmdline_parse_inst_t *)&cmd_config_burst,
7404         (cmdline_parse_inst_t *)&cmd_config_thresh,
7405         (cmdline_parse_inst_t *)&cmd_config_threshold,
7406         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
7407         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
7408         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
7409         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
7410         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
7411         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
7412         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
7413         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
7414         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
7415         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
7416         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
7417         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
7418         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
7419         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
7420         (cmdline_parse_inst_t *)&cmd_dump,
7421         (cmdline_parse_inst_t *)&cmd_dump_one,
7422         (cmdline_parse_inst_t *)&cmd_add_ethertype_filter,
7423         (cmdline_parse_inst_t *)&cmd_remove_ethertype_filter,
7424         (cmdline_parse_inst_t *)&cmd_get_ethertype_filter,
7425         (cmdline_parse_inst_t *)&cmd_add_syn_filter,
7426         (cmdline_parse_inst_t *)&cmd_remove_syn_filter,
7427         (cmdline_parse_inst_t *)&cmd_get_syn_filter,
7428         (cmdline_parse_inst_t *)&cmd_add_2tuple_filter,
7429         (cmdline_parse_inst_t *)&cmd_remove_2tuple_filter,
7430         (cmdline_parse_inst_t *)&cmd_get_2tuple_filter,
7431         (cmdline_parse_inst_t *)&cmd_add_5tuple_filter,
7432         (cmdline_parse_inst_t *)&cmd_remove_5tuple_filter,
7433         (cmdline_parse_inst_t *)&cmd_get_5tuple_filter,
7434         (cmdline_parse_inst_t *)&cmd_add_flex_filter,
7435         (cmdline_parse_inst_t *)&cmd_remove_flex_filter,
7436         (cmdline_parse_inst_t *)&cmd_get_flex_filter,
7437         NULL,
7438 };
7439
7440 /* prompt function, called from main on MASTER lcore */
7441 void
7442 prompt(void)
7443 {
7444         struct cmdline *cl;
7445
7446         /* initialize non-constant commands */
7447         cmd_set_fwd_mode_init();
7448
7449         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
7450         if (cl == NULL) {
7451                 return;
7452         }
7453         cmdline_interact(cl);
7454         cmdline_stdin_exit(cl);
7455 }
7456
7457 static void
7458 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
7459 {
7460         if (id < nb_ports) {
7461                 /* check if need_reconfig has been set to 1 */
7462                 if (ports[id].need_reconfig == 0)
7463                         ports[id].need_reconfig = dev;
7464                 /* check if need_reconfig_queues has been set to 1 */
7465                 if (ports[id].need_reconfig_queues == 0)
7466                         ports[id].need_reconfig_queues = queue;
7467         } else {
7468                 portid_t pid;
7469
7470                 for (pid = 0; pid < nb_ports; pid++) {
7471                         /* check if need_reconfig has been set to 1 */
7472                         if (ports[pid].need_reconfig == 0)
7473                                 ports[pid].need_reconfig = dev;
7474                         /* check if need_reconfig_queues has been set to 1 */
7475                         if (ports[pid].need_reconfig_queues == 0)
7476                                 ports[pid].need_reconfig_queues = queue;
7477                 }
7478         }
7479 }
7480
7481 #ifdef RTE_NIC_BYPASS
7482 uint8_t
7483 bypass_is_supported(portid_t port_id)
7484 {
7485         struct rte_port   *port;
7486         struct rte_pci_id *pci_id;
7487
7488         if (port_id >= nb_ports) {
7489                 printf("\tPort id must be less than %d.\n", nb_ports);
7490                 return 0;
7491         }
7492
7493         /* Get the device id. */
7494         port    = &ports[port_id];
7495         pci_id = &port->dev_info.pci_dev->id;
7496
7497         /* Check if NIC supports bypass. */
7498         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
7499                 return 1;
7500         }
7501         else {
7502                 printf("\tBypass not supported for port_id = %d.\n", port_id);
7503                 return 0;
7504         }
7505 }
7506 #endif