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