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