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