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