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