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