ethdev: rename and extend the mirror type
[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_malloc.h>
63 #include <rte_launch.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 #include <rte_eth_ctrl.h>
78
79 #include <cmdline_rdline.h>
80 #include <cmdline_parse.h>
81 #include <cmdline_parse_num.h>
82 #include <cmdline_parse_string.h>
83 #include <cmdline_parse_ipaddr.h>
84 #include <cmdline_parse_etheraddr.h>
85 #include <cmdline_socket.h>
86 #include <cmdline.h>
87 #include <rte_pci_dev_ids.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #endif
91
92 #include "testpmd.h"
93
94 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
95
96 #ifdef RTE_NIC_BYPASS
97 uint8_t bypass_is_supported(portid_t port_id);
98 #endif
99
100 /* *** Help command with introduction. *** */
101 struct cmd_help_brief_result {
102         cmdline_fixed_string_t help;
103 };
104
105 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
106                                   struct cmdline *cl,
107                                   __attribute__((unused)) void *data)
108 {
109         cmdline_printf(
110                 cl,
111                 "\n"
112                 "Help is available for the following sections:\n\n"
113                 "    help control    : Start and stop forwarding.\n"
114                 "    help display    : Displaying port, stats and config "
115                 "information.\n"
116                 "    help config     : Configuration information.\n"
117                 "    help ports      : Configuring ports.\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.\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 X rss reta (size) (mask0,mask1,...)\n"
190                         "    Display the rss redirection table entry indicated"
191                         " by masks on port X. size is used to indicate the"
192                         " hardware supported reta size\n\n"
193
194                         "show port rss-hash [key]\n"
195                         "    Display the RSS hash functions and RSS hash key"
196                         " of port X\n\n"
197
198                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
199                         "    Clear information for port_id, or all.\n\n"
200
201                         "show config (rxtx|cores|fwd)\n"
202                         "    Display the given configuration.\n\n"
203
204                         "read rxd (port_id) (queue_id) (rxd_id)\n"
205                         "    Display an RX descriptor of a port RX queue.\n\n"
206
207                         "read txd (port_id) (queue_id) (txd_id)\n"
208                         "    Display a TX descriptor of a port TX queue.\n\n"
209                 );
210         }
211
212         if (show_all || !strcmp(res->section, "config")) {
213                 cmdline_printf(
214                         cl,
215                         "\n"
216                         "Configuration:\n"
217                         "--------------\n"
218                         "Configuration changes only become active when"
219                         " forwarding is started/restarted.\n\n"
220
221                         "set default\n"
222                         "    Reset forwarding to the default configuration.\n\n"
223
224                         "set verbose (level)\n"
225                         "    Set the debug verbosity level X.\n\n"
226
227                         "set nbport (num)\n"
228                         "    Set number of ports.\n\n"
229
230                         "set nbcore (num)\n"
231                         "    Set number of cores.\n\n"
232
233                         "set coremask (mask)\n"
234                         "    Set the forwarding cores hexadecimal mask.\n\n"
235
236                         "set portmask (mask)\n"
237                         "    Set the forwarding ports hexadecimal mask.\n\n"
238
239                         "set burst (num)\n"
240                         "    Set number of packets per burst.\n\n"
241
242                         "set burst tx delay (microseconds) retry (num)\n"
243                         "    Set the transmit delay time and number of retries"
244                         " in mac_retry forwarding mode.\n\n"
245
246                         "set txpkts (x[,y]*)\n"
247                         "    Set the length of each segment of TXONLY"
248                         " packets.\n\n"
249
250                         "set corelist (x[,y]*)\n"
251                         "    Set the list of forwarding cores.\n\n"
252
253                         "set portlist (x[,y]*)\n"
254                         "    Set the list of forwarding ports.\n\n"
255
256                         "vlan set strip (on|off) (port_id)\n"
257                         "    Set the VLAN strip on a port.\n\n"
258
259                         "vlan set stripq (on|off) (port_id,queue_id)\n"
260                         "    Set the VLAN strip for a queue on a port.\n\n"
261
262                         "vlan set filter (on|off) (port_id)\n"
263                         "    Set the VLAN filter on a port.\n\n"
264
265                         "vlan set qinq (on|off) (port_id)\n"
266                         "    Set the VLAN QinQ (extended queue in queue)"
267                         " on a port.\n\n"
268
269                         "vlan set tpid (value) (port_id)\n"
270                         "    Set the outer VLAN TPID for Packet Filtering on"
271                         " a port\n\n"
272
273                         "rx_vlan add (vlan_id|all) (port_id)\n"
274                         "    Add a vlan_id, or all identifiers, to the set"
275                         " of VLAN identifiers filtered by port_id.\n\n"
276
277                         "rx_vlan rm (vlan_id|all) (port_id)\n"
278                         "    Remove a vlan_id, or all identifiers, from the set"
279                         " of VLAN identifiers filtered by port_id.\n\n"
280
281                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
282                         "    Add a vlan_id, to the set of VLAN identifiers"
283                         "filtered for VF(s) from port_id.\n\n"
284
285                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
286                         "    Remove a vlan_id, to the set of VLAN identifiers"
287                         "filtered for VF(s) from port_id.\n\n"
288
289                         "rx_vlan set tpid (value) (port_id)\n"
290                         "    Set the outer VLAN TPID for Packet Filtering on"
291                         " a port\n\n"
292
293                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
294                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
295                         "   add a tunnel filter of a port.\n\n"
296
297                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
298                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
299                         "   remove a tunnel filter of a port.\n\n"
300
301                         "rx_vxlan_port add (udp_port) (port_id)\n"
302                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
303
304                         "rx_vxlan_port rm (udp_port) (port_id)\n"
305                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
306
307                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
308                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
309                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
310
311                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
312                         "    Set port based TX VLAN insertion.\n\n"
313
314                         "tx_vlan reset (port_id)\n"
315                         "    Disable hardware insertion of a VLAN header in"
316                         " packets sent on a port.\n\n"
317
318                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
319                         "    Select hardware or software calculation of the"
320                         " checksum when transmitting a packet using the"
321                         " csum forward engine.\n"
322                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
323                         "    outer-ip concerns the outer IP layer in"
324                         " case the packet is recognized as a tunnel packet by"
325                         " the forward engine (vxlan, gre and ipip are supported)\n"
326                         "    Please check the NIC datasheet for HW limits.\n\n"
327
328                         "csum parse-tunnel (on|off) (tx_port_id)\n"
329                         "    If disabled, treat tunnel packets as non-tunneled"
330                         " packets (treat inner headers as payload). The port\n"
331                         "    argument is the port used for TX in csum forward"
332                         " engine.\n\n"
333
334                         "csum show (port_id)\n"
335                         "    Display tx checksum offload configuration\n\n"
336
337                         "tso set (segsize) (portid)\n"
338                         "    Enable TCP Segmentation Offload in csum forward"
339                         " engine.\n"
340                         "    Please check the NIC datasheet for HW limits.\n\n"
341
342                         "tso show (portid)"
343                         "    Display the status of TCP Segmentation Offload.\n\n"
344
345                         "set fwd (%s)\n"
346                         "    Set packet forwarding mode.\n\n"
347
348                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
349                         "    Add a MAC address on port_id.\n\n"
350
351                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
352                         "    Remove a MAC address from port_id.\n\n"
353
354                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
355                         "    Add a MAC address for a VF on the port.\n\n"
356
357                         "set port (port_id) uta (mac_address|all) (on|off)\n"
358                         "    Add/Remove a or all unicast hash filter(s)"
359                         "from port X.\n\n"
360
361                         "set promisc (port_id|all) (on|off)\n"
362                         "    Set the promiscuous mode on port_id, or all.\n\n"
363
364                         "set allmulti (port_id|all) (on|off)\n"
365                         "    Set the allmulti mode on port_id, or all.\n\n"
366
367                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
368                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
369                         " (on|off) autoneg (on|off) (port_id)\n"
370                         "set flow_ctrl rx (on|off) (portid)\n"
371                         "set flow_ctrl tx (on|off) (portid)\n"
372                         "set flow_ctrl high_water (high_water) (portid)\n"
373                         "set flow_ctrl low_water (low_water) (portid)\n"
374                         "set flow_ctrl pause_time (pause_time) (portid)\n"
375                         "set flow_ctrl send_xon (send_xon) (portid)\n"
376                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
377                         "set flow_ctrl autoneg (on|off) (port_id)\n"
378                         "    Set the link flow control parameter on a port.\n\n"
379
380                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
381                         " (low_water) (pause_time) (priority) (port_id)\n"
382                         "    Set the priority flow control parameter on a"
383                         " port.\n\n"
384
385                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
386                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
387                         " queue on port.\n"
388                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
389                         " on port 0 to mapping 5.\n\n"
390
391                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
392                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
393
394                         "set port (port_id) vf (vf_id) (mac_addr)"
395                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
396                         "   Add/Remove unicast or multicast MAC addr filter"
397                         " for a VF.\n\n"
398
399                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
400                         "|MPE) (on|off)\n"
401                         "    AUPE:accepts untagged VLAN;"
402                         "ROPE:accept unicast hash\n\n"
403                         "    BAM:accepts broadcast packets;"
404                         "MPE:accepts all multicast packets\n\n"
405                         "    Enable/Disable a VF receive mode of a port\n\n"
406
407                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
408                         "    Set rate limit for a queue of a port\n\n"
409
410                         "set port (port_id) vf (vf_id) rate (rate_num) "
411                         "queue_mask (queue_mask_value)\n"
412                         "    Set rate limit for queues in VF of a port\n\n"
413
414                         "set port (port_id) mirror-rule (rule_id)"
415                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
416                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
417                         "   Set pool or vlan type mirror rule on a port.\n"
418                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
419                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
420                         " to pool 0.\n\n"
421
422                         "set port (port_id) mirror-rule (rule_id)"
423                         " (uplink-mirror|downlink-mirror) dst-pool"
424                         " (pool_id) (on|off)\n"
425                         "   Set uplink or downlink type mirror rule on a port.\n"
426                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
427                         " 0 on' enable mirror income traffic to pool 0.\n\n"
428
429                         "reset port (port_id) mirror-rule (rule_id)\n"
430                         "   Reset a mirror rule.\n\n"
431
432                         "set flush_rx (on|off)\n"
433                         "   Flush (default) or don't flush RX streams before"
434                         " forwarding. Mainly used with PCAP drivers.\n\n"
435
436                         #ifdef RTE_NIC_BYPASS
437                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
438                         "   Set the bypass mode for the lowest port on bypass enabled"
439                         " NIC.\n\n"
440
441                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
442                         "mode (normal|bypass|isolate) (port_id)\n"
443                         "   Set the event required to initiate specified bypass mode for"
444                         " the lowest port on a bypass enabled NIC where:\n"
445                         "       timeout   = enable bypass after watchdog timeout.\n"
446                         "       os_on     = enable bypass when OS/board is powered on.\n"
447                         "       os_off    = enable bypass when OS/board is powered off.\n"
448                         "       power_on  = enable bypass when power supply is turned on.\n"
449                         "       power_off = enable bypass when power supply is turned off."
450                         "\n\n"
451
452                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
453                         "   Set the bypass watchdog timeout to 'n' seconds"
454                         " where 0 = instant.\n\n"
455
456                         "show bypass config (port_id)\n"
457                         "   Show the bypass configuration for a bypass enabled NIC"
458                         " using the lowest port on the NIC.\n\n"
459 #endif
460 #ifdef RTE_LIBRTE_PMD_BOND
461                         "create bonded device (mode) (socket)\n"
462                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
463
464                         "add bonding slave (slave_id) (port_id)\n"
465                         "       Add a slave device to a bonded device.\n\n"
466
467                         "remove bonding slave (slave_id) (port_id)\n"
468                         "       Remove a slave device from a bonded device.\n\n"
469
470                         "set bonding mode (value) (port_id)\n"
471                         "       Set the bonding mode on a bonded device.\n\n"
472
473                         "set bonding primary (slave_id) (port_id)\n"
474                         "       Set the primary slave for a bonded device.\n\n"
475
476                         "show bonding config (port_id)\n"
477                         "       Show the bonding config for port_id.\n\n"
478
479                         "set bonding mac_addr (port_id) (address)\n"
480                         "       Set the MAC address of a bonded device.\n\n"
481
482                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
483                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
484
485                         "set bonding mon_period (port_id) (value)\n"
486                         "       Set the bonding link status monitoring polling period in ms.\n\n"
487 #endif
488                         "set link-up port (port_id)\n"
489                         "       Set link up for a port.\n\n"
490
491                         "set link-down port (port_id)\n"
492                         "       Set link down for a port.\n\n"
493
494                         , list_pkt_forwarding_modes()
495                 );
496         }
497
498         if (show_all || !strcmp(res->section, "ports")) {
499
500                 cmdline_printf(
501                         cl,
502                         "\n"
503                         "Port Operations:\n"
504                         "----------------\n\n"
505
506                         "port start (port_id|all)\n"
507                         "    Start all ports or port_id.\n\n"
508
509                         "port stop (port_id|all)\n"
510                         "    Stop all ports or port_id.\n\n"
511
512                         "port close (port_id|all)\n"
513                         "    Close all ports or port_id.\n\n"
514
515                         "port attach (ident)\n"
516                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
517
518                         "port detach (port_id)\n"
519                         "    Detach physical or virtual dev by port_id\n\n"
520
521                         "port config (port_id|all)"
522                         " speed (10|100|1000|10000|40000|auto)"
523                         " duplex (half|full|auto)\n"
524                         "    Set speed and duplex for all ports or port_id\n\n"
525
526                         "port config all (rxq|txq|rxd|txd) (value)\n"
527                         "    Set number for rxq/txq/rxd/txd.\n\n"
528
529                         "port config all max-pkt-len (value)\n"
530                         "    Set the max packet length.\n\n"
531
532                         "port config all (crc-strip|rx-cksum|hw-vlan|hw-vlan-filter|"
533                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
534                         " (on|off)\n"
535                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
536                         " for ports.\n\n"
537
538                         "port config all rss (all|ip|tcp|udp|sctp|ether|none)\n"
539                         "    Set the RSS mode.\n\n"
540
541                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
542                         "    Set the RSS redirection table.\n\n"
543
544                         "port config (port_id) dcb vt (on|off) (traffic_class)"
545                         " pfc (on|off)\n"
546                         "    Set the DCB mode.\n\n"
547
548                         "port config all burst (value)\n"
549                         "    Set the number of packets per burst.\n\n"
550
551                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
552                         " (value)\n"
553                         "    Set the ring prefetch/host/writeback threshold"
554                         " for tx/rx queue.\n\n"
555
556                         "port config all (txfreet|txrst|rxfreet) (value)\n"
557                         "    Set free threshold for rx/tx, or set"
558                         " tx rs bit threshold.\n\n"
559                         "port config mtu X value\n"
560                         "    Set the MTU of port X to a given value\n\n"
561
562                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
563                         "    Start/stop a rx/tx queue of port X. Only take effect"
564                         " when port X is started\n"
565                 );
566         }
567
568         if (show_all || !strcmp(res->section, "registers")) {
569
570                 cmdline_printf(
571                         cl,
572                         "\n"
573                         "Registers:\n"
574                         "----------\n\n"
575
576                         "read reg (port_id) (address)\n"
577                         "    Display value of a port register.\n\n"
578
579                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
580                         "    Display a port register bit field.\n\n"
581
582                         "read regbit (port_id) (address) (bit_x)\n"
583                         "    Display a single port register bit.\n\n"
584
585                         "write reg (port_id) (address) (value)\n"
586                         "    Set value of a port register.\n\n"
587
588                         "write regfield (port_id) (address) (bit_x) (bit_y)"
589                         " (value)\n"
590                         "    Set bit field of a port register.\n\n"
591
592                         "write regbit (port_id) (address) (bit_x) (value)\n"
593                         "    Set single bit value of a port register.\n\n"
594                 );
595         }
596         if (show_all || !strcmp(res->section, "filters")) {
597
598                 cmdline_printf(
599                         cl,
600                         "\n"
601                         "filters:\n"
602                         "--------\n\n"
603
604                         "ethertype_filter (port_id) (add|del)"
605                         " (mac_addr|mac_ignr) (mac_address) ethertype"
606                         " (ether_type) (drop|fwd) queue (queue_id)\n"
607                         "    Add/Del an ethertype filter.\n\n"
608
609                         "2tuple_filter (port_id) (add|del)"
610                         " dst_port (dst_port_value) protocol (protocol_value)"
611                         " mask (mask_value) tcp_flags (tcp_flags_value)"
612                         " priority (prio_value) queue (queue_id)\n"
613                         "    Add/Del a 2tuple filter.\n\n"
614
615                         "5tuple_filter (port_id) (add|del)"
616                         " dst_ip (dst_address) src_ip (src_address)"
617                         " dst_port (dst_port_value) src_port (src_port_value)"
618                         " protocol (protocol_value)"
619                         " mask (mask_value) tcp_flags (tcp_flags_value)"
620                         " priority (prio_value) queue (queue_id)\n"
621                         "    Add/Del a 5tuple filter.\n\n"
622
623                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
624                         "    Add/Del syn filter.\n\n"
625
626                         "flex_filter (port_id) (add|del) len (len_value)"
627                         " bytes (bytes_value) mask (mask_value)"
628                         " priority (prio_value) queue (queue_id)\n"
629                         "    Add/Del a flex filter.\n\n"
630
631                         "flow_director_filter (port_id) (add|del|update)"
632                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
633                         " src (src_ip_address) dst (dst_ip_address)"
634                         " vlan (vlan_value) flexbytes (flexbytes_value)"
635                         " (drop|fwd) queue (queue_id) fd_id (fd_id_value)\n"
636                         "    Add/Del an IP type flow director filter.\n\n"
637
638                         "flow_director_filter (port_id) (add|del|update)"
639                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
640                         " src (src_ip_address) (src_port)"
641                         " dst (dst_ip_address) (dst_port)"
642                         " vlan (vlan_value) flexbytes (flexbytes_value)"
643                         " (drop|fwd) queue (queue_id) fd_id (fd_id_value)\n"
644                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
645
646                         "flow_director_filter (port_id) (add|del|update)"
647                         " flow (ipv4-sctp|ipv6-sctp)"
648                         " src (src_ip_address) (src_port)"
649                         " dst (dst_ip_address) (dst_port)"
650                         " tag (verification_tag) vlan (vlan_value)"
651                         " flexbytes (flexbytes_value) (drop|fwd)"
652                         " queue (queue_id) fd_id (fd_id_value)\n"
653                         "    Add/Del a SCTP type flow director filter.\n\n"
654
655                         "flush_flow_director (port_id)\n"
656                         "    Flush all flow director entries of a device.\n\n"
657
658                         "flow_director_mask (port_id) vlan (vlan_value)"
659                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
660                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
661                         "    Set flow director mask.\n\n"
662
663                         "flow_director_flex_mask (port_id)"
664                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
665                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|all)"
666                         " (mask)\n"
667                         "    Configure mask of flex payload.\n\n"
668
669                         "flow_director_flex_payload (port_id)"
670                         " (raw|l2|l3|l4) (config)\n"
671                         "    Configure flex payload selection.\n\n"
672
673                         "get_sym_hash_ena_per_port (port_id)\n"
674                         "    get symmetric hash enable configuration per port.\n\n"
675
676                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
677                         "    set symmetric hash enable configuration per port"
678                         " to enable or disable.\n\n"
679
680                         "get_hash_global_config (port_id)\n"
681                         "    Get the global configurations of hash filters.\n\n"
682
683                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
684                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
685                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
686                         " (enable|disable)\n"
687                         "    Set the global configurations of hash filters.\n\n"
688                 );
689         }
690 }
691
692 cmdline_parse_token_string_t cmd_help_long_help =
693         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
694
695 cmdline_parse_token_string_t cmd_help_long_section =
696         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
697                         "all#control#display#config#"
698                         "ports#registers#filters");
699
700 cmdline_parse_inst_t cmd_help_long = {
701         .f = cmd_help_long_parsed,
702         .data = NULL,
703         .help_str = "show help",
704         .tokens = {
705                 (void *)&cmd_help_long_help,
706                 (void *)&cmd_help_long_section,
707                 NULL,
708         },
709 };
710
711
712 /* *** start/stop/close all ports *** */
713 struct cmd_operate_port_result {
714         cmdline_fixed_string_t keyword;
715         cmdline_fixed_string_t name;
716         cmdline_fixed_string_t value;
717 };
718
719 static void cmd_operate_port_parsed(void *parsed_result,
720                                 __attribute__((unused)) struct cmdline *cl,
721                                 __attribute__((unused)) void *data)
722 {
723         struct cmd_operate_port_result *res = parsed_result;
724
725         if (!strcmp(res->name, "start"))
726                 start_port(RTE_PORT_ALL);
727         else if (!strcmp(res->name, "stop"))
728                 stop_port(RTE_PORT_ALL);
729         else if (!strcmp(res->name, "close"))
730                 close_port(RTE_PORT_ALL);
731         else
732                 printf("Unknown parameter\n");
733 }
734
735 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
736         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
737                                                                 "port");
738 cmdline_parse_token_string_t cmd_operate_port_all_port =
739         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
740                                                 "start#stop#close");
741 cmdline_parse_token_string_t cmd_operate_port_all_all =
742         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
743
744 cmdline_parse_inst_t cmd_operate_port = {
745         .f = cmd_operate_port_parsed,
746         .data = NULL,
747         .help_str = "port start|stop|close all: start/stop/close all ports",
748         .tokens = {
749                 (void *)&cmd_operate_port_all_cmd,
750                 (void *)&cmd_operate_port_all_port,
751                 (void *)&cmd_operate_port_all_all,
752                 NULL,
753         },
754 };
755
756 /* *** start/stop/close specific port *** */
757 struct cmd_operate_specific_port_result {
758         cmdline_fixed_string_t keyword;
759         cmdline_fixed_string_t name;
760         uint8_t value;
761 };
762
763 static void cmd_operate_specific_port_parsed(void *parsed_result,
764                         __attribute__((unused)) struct cmdline *cl,
765                                 __attribute__((unused)) void *data)
766 {
767         struct cmd_operate_specific_port_result *res = parsed_result;
768
769         if (!strcmp(res->name, "start"))
770                 start_port(res->value);
771         else if (!strcmp(res->name, "stop"))
772                 stop_port(res->value);
773         else if (!strcmp(res->name, "close"))
774                 close_port(res->value);
775         else
776                 printf("Unknown parameter\n");
777 }
778
779 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
780         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
781                                                         keyword, "port");
782 cmdline_parse_token_string_t cmd_operate_specific_port_port =
783         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
784                                                 name, "start#stop#close");
785 cmdline_parse_token_num_t cmd_operate_specific_port_id =
786         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
787                                                         value, UINT8);
788
789 cmdline_parse_inst_t cmd_operate_specific_port = {
790         .f = cmd_operate_specific_port_parsed,
791         .data = NULL,
792         .help_str = "port start|stop|close X: start/stop/close port X",
793         .tokens = {
794                 (void *)&cmd_operate_specific_port_cmd,
795                 (void *)&cmd_operate_specific_port_port,
796                 (void *)&cmd_operate_specific_port_id,
797                 NULL,
798         },
799 };
800
801 /* *** attach a specified port *** */
802 struct cmd_operate_attach_port_result {
803         cmdline_fixed_string_t port;
804         cmdline_fixed_string_t keyword;
805         cmdline_fixed_string_t identifier;
806 };
807
808 static void cmd_operate_attach_port_parsed(void *parsed_result,
809                                 __attribute__((unused)) struct cmdline *cl,
810                                 __attribute__((unused)) void *data)
811 {
812         struct cmd_operate_attach_port_result *res = parsed_result;
813
814         if (!strcmp(res->keyword, "attach"))
815                 attach_port(res->identifier);
816         else
817                 printf("Unknown parameter\n");
818 }
819
820 cmdline_parse_token_string_t cmd_operate_attach_port_port =
821         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
822                         port, "port");
823 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
824         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
825                         keyword, "attach");
826 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
827         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
828                         identifier, NULL);
829
830 cmdline_parse_inst_t cmd_operate_attach_port = {
831         .f = cmd_operate_attach_port_parsed,
832         .data = NULL,
833         .help_str = "port attach identifier, "
834                 "identifier: pci address or virtual dev name",
835         .tokens = {
836                 (void *)&cmd_operate_attach_port_port,
837                 (void *)&cmd_operate_attach_port_keyword,
838                 (void *)&cmd_operate_attach_port_identifier,
839                 NULL,
840         },
841 };
842
843 /* *** detach a specified port *** */
844 struct cmd_operate_detach_port_result {
845         cmdline_fixed_string_t port;
846         cmdline_fixed_string_t keyword;
847         uint8_t port_id;
848 };
849
850 static void cmd_operate_detach_port_parsed(void *parsed_result,
851                                 __attribute__((unused)) struct cmdline *cl,
852                                 __attribute__((unused)) void *data)
853 {
854         struct cmd_operate_detach_port_result *res = parsed_result;
855
856         if (!strcmp(res->keyword, "detach"))
857                 detach_port(res->port_id);
858         else
859                 printf("Unknown parameter\n");
860 }
861
862 cmdline_parse_token_string_t cmd_operate_detach_port_port =
863         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
864                         port, "port");
865 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
866         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
867                         keyword, "detach");
868 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
869         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
870                         port_id, UINT8);
871
872 cmdline_parse_inst_t cmd_operate_detach_port = {
873         .f = cmd_operate_detach_port_parsed,
874         .data = NULL,
875         .help_str = "port detach port_id",
876         .tokens = {
877                 (void *)&cmd_operate_detach_port_port,
878                 (void *)&cmd_operate_detach_port_keyword,
879                 (void *)&cmd_operate_detach_port_port_id,
880                 NULL,
881         },
882 };
883
884 /* *** configure speed for all ports *** */
885 struct cmd_config_speed_all {
886         cmdline_fixed_string_t port;
887         cmdline_fixed_string_t keyword;
888         cmdline_fixed_string_t all;
889         cmdline_fixed_string_t item1;
890         cmdline_fixed_string_t item2;
891         cmdline_fixed_string_t value1;
892         cmdline_fixed_string_t value2;
893 };
894
895 static void
896 cmd_config_speed_all_parsed(void *parsed_result,
897                         __attribute__((unused)) struct cmdline *cl,
898                         __attribute__((unused)) void *data)
899 {
900         struct cmd_config_speed_all *res = parsed_result;
901         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
902         uint16_t link_duplex = 0;
903         portid_t pid;
904
905         if (!all_ports_stopped()) {
906                 printf("Please stop all ports first\n");
907                 return;
908         }
909
910         if (!strcmp(res->value1, "10"))
911                 link_speed = ETH_LINK_SPEED_10;
912         else if (!strcmp(res->value1, "100"))
913                 link_speed = ETH_LINK_SPEED_100;
914         else if (!strcmp(res->value1, "1000"))
915                 link_speed = ETH_LINK_SPEED_1000;
916         else if (!strcmp(res->value1, "10000"))
917                 link_speed = ETH_LINK_SPEED_10G;
918         else if (!strcmp(res->value1, "40000"))
919                 link_speed = ETH_LINK_SPEED_40G;
920         else if (!strcmp(res->value1, "auto"))
921                 link_speed = ETH_LINK_SPEED_AUTONEG;
922         else {
923                 printf("Unknown parameter\n");
924                 return;
925         }
926
927         if (!strcmp(res->value2, "half"))
928                 link_duplex = ETH_LINK_HALF_DUPLEX;
929         else if (!strcmp(res->value2, "full"))
930                 link_duplex = ETH_LINK_FULL_DUPLEX;
931         else if (!strcmp(res->value2, "auto"))
932                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
933         else {
934                 printf("Unknown parameter\n");
935                 return;
936         }
937
938         FOREACH_PORT(pid, ports) {
939                 ports[pid].dev_conf.link_speed = link_speed;
940                 ports[pid].dev_conf.link_duplex = link_duplex;
941         }
942
943         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
944 }
945
946 cmdline_parse_token_string_t cmd_config_speed_all_port =
947         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
948 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
949         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
950                                                         "config");
951 cmdline_parse_token_string_t cmd_config_speed_all_all =
952         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
953 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
954         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
955 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
956         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
957                                                 "10#100#1000#10000#40000#auto");
958 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
959         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
960 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
961         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
962                                                 "half#full#auto");
963
964 cmdline_parse_inst_t cmd_config_speed_all = {
965         .f = cmd_config_speed_all_parsed,
966         .data = NULL,
967         .help_str = "port config all speed 10|100|1000|10000|40000|auto duplex "
968                                                         "half|full|auto",
969         .tokens = {
970                 (void *)&cmd_config_speed_all_port,
971                 (void *)&cmd_config_speed_all_keyword,
972                 (void *)&cmd_config_speed_all_all,
973                 (void *)&cmd_config_speed_all_item1,
974                 (void *)&cmd_config_speed_all_value1,
975                 (void *)&cmd_config_speed_all_item2,
976                 (void *)&cmd_config_speed_all_value2,
977                 NULL,
978         },
979 };
980
981 /* *** configure speed for specific port *** */
982 struct cmd_config_speed_specific {
983         cmdline_fixed_string_t port;
984         cmdline_fixed_string_t keyword;
985         uint8_t id;
986         cmdline_fixed_string_t item1;
987         cmdline_fixed_string_t item2;
988         cmdline_fixed_string_t value1;
989         cmdline_fixed_string_t value2;
990 };
991
992 static void
993 cmd_config_speed_specific_parsed(void *parsed_result,
994                                 __attribute__((unused)) struct cmdline *cl,
995                                 __attribute__((unused)) void *data)
996 {
997         struct cmd_config_speed_specific *res = parsed_result;
998         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
999         uint16_t link_duplex = 0;
1000
1001         if (!all_ports_stopped()) {
1002                 printf("Please stop all ports first\n");
1003                 return;
1004         }
1005
1006         if (port_id_is_invalid(res->id, ENABLED_WARN))
1007                 return;
1008
1009         if (!strcmp(res->value1, "10"))
1010                 link_speed = ETH_LINK_SPEED_10;
1011         else if (!strcmp(res->value1, "100"))
1012                 link_speed = ETH_LINK_SPEED_100;
1013         else if (!strcmp(res->value1, "1000"))
1014                 link_speed = ETH_LINK_SPEED_1000;
1015         else if (!strcmp(res->value1, "10000"))
1016                 link_speed = ETH_LINK_SPEED_10000;
1017         else if (!strcmp(res->value1, "40000"))
1018                 link_speed = ETH_LINK_SPEED_40G;
1019         else if (!strcmp(res->value1, "auto"))
1020                 link_speed = ETH_LINK_SPEED_AUTONEG;
1021         else {
1022                 printf("Unknown parameter\n");
1023                 return;
1024         }
1025
1026         if (!strcmp(res->value2, "half"))
1027                 link_duplex = ETH_LINK_HALF_DUPLEX;
1028         else if (!strcmp(res->value2, "full"))
1029                 link_duplex = ETH_LINK_FULL_DUPLEX;
1030         else if (!strcmp(res->value2, "auto"))
1031                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1032         else {
1033                 printf("Unknown parameter\n");
1034                 return;
1035         }
1036
1037         ports[res->id].dev_conf.link_speed = link_speed;
1038         ports[res->id].dev_conf.link_duplex = link_duplex;
1039
1040         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1041 }
1042
1043
1044 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1045         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1046                                                                 "port");
1047 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1048         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1049                                                                 "config");
1050 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1051         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1052 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1053         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1054                                                                 "speed");
1055 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1056         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1057                                                 "10#100#1000#10000#40000#auto");
1058 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1059         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1060                                                                 "duplex");
1061 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1062         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1063                                                         "half#full#auto");
1064
1065 cmdline_parse_inst_t cmd_config_speed_specific = {
1066         .f = cmd_config_speed_specific_parsed,
1067         .data = NULL,
1068         .help_str = "port config X speed 10|100|1000|10000|40000|auto duplex "
1069                                                         "half|full|auto",
1070         .tokens = {
1071                 (void *)&cmd_config_speed_specific_port,
1072                 (void *)&cmd_config_speed_specific_keyword,
1073                 (void *)&cmd_config_speed_specific_id,
1074                 (void *)&cmd_config_speed_specific_item1,
1075                 (void *)&cmd_config_speed_specific_value1,
1076                 (void *)&cmd_config_speed_specific_item2,
1077                 (void *)&cmd_config_speed_specific_value2,
1078                 NULL,
1079         },
1080 };
1081
1082 /* *** configure txq/rxq, txd/rxd *** */
1083 struct cmd_config_rx_tx {
1084         cmdline_fixed_string_t port;
1085         cmdline_fixed_string_t keyword;
1086         cmdline_fixed_string_t all;
1087         cmdline_fixed_string_t name;
1088         uint16_t value;
1089 };
1090
1091 static void
1092 cmd_config_rx_tx_parsed(void *parsed_result,
1093                         __attribute__((unused)) struct cmdline *cl,
1094                         __attribute__((unused)) void *data)
1095 {
1096         struct cmd_config_rx_tx *res = parsed_result;
1097
1098         if (!all_ports_stopped()) {
1099                 printf("Please stop all ports first\n");
1100                 return;
1101         }
1102
1103         if (!strcmp(res->name, "rxq")) {
1104                 if (res->value <= 0) {
1105                         printf("rxq %d invalid - must be > 0\n", res->value);
1106                         return;
1107                 }
1108                 nb_rxq = res->value;
1109         }
1110         else if (!strcmp(res->name, "txq")) {
1111                 if (res->value <= 0) {
1112                         printf("txq %d invalid - must be > 0\n", res->value);
1113                         return;
1114                 }
1115                 nb_txq = res->value;
1116         }
1117         else if (!strcmp(res->name, "rxd")) {
1118                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1119                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1120                                         res->value, RTE_TEST_RX_DESC_MAX);
1121                         return;
1122                 }
1123                 nb_rxd = res->value;
1124         } else if (!strcmp(res->name, "txd")) {
1125                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1126                         printf("txd %d invalid - must be > 0 && <= %d\n",
1127                                         res->value, RTE_TEST_TX_DESC_MAX);
1128                         return;
1129                 }
1130                 nb_txd = res->value;
1131         } else {
1132                 printf("Unknown parameter\n");
1133                 return;
1134         }
1135
1136         init_port_config();
1137
1138         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1139 }
1140
1141 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1142         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1143 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1144         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1145 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1147 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1148         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1149                                                 "rxq#txq#rxd#txd");
1150 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1151         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1152
1153 cmdline_parse_inst_t cmd_config_rx_tx = {
1154         .f = cmd_config_rx_tx_parsed,
1155         .data = NULL,
1156         .help_str = "port config all rxq|txq|rxd|txd value",
1157         .tokens = {
1158                 (void *)&cmd_config_rx_tx_port,
1159                 (void *)&cmd_config_rx_tx_keyword,
1160                 (void *)&cmd_config_rx_tx_all,
1161                 (void *)&cmd_config_rx_tx_name,
1162                 (void *)&cmd_config_rx_tx_value,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** config max packet length *** */
1168 struct cmd_config_max_pkt_len_result {
1169         cmdline_fixed_string_t port;
1170         cmdline_fixed_string_t keyword;
1171         cmdline_fixed_string_t all;
1172         cmdline_fixed_string_t name;
1173         uint32_t value;
1174 };
1175
1176 static void
1177 cmd_config_max_pkt_len_parsed(void *parsed_result,
1178                                 __attribute__((unused)) struct cmdline *cl,
1179                                 __attribute__((unused)) void *data)
1180 {
1181         struct cmd_config_max_pkt_len_result *res = parsed_result;
1182
1183         if (!all_ports_stopped()) {
1184                 printf("Please stop all ports first\n");
1185                 return;
1186         }
1187
1188         if (!strcmp(res->name, "max-pkt-len")) {
1189                 if (res->value < ETHER_MIN_LEN) {
1190                         printf("max-pkt-len can not be less than %d\n",
1191                                                         ETHER_MIN_LEN);
1192                         return;
1193                 }
1194                 if (res->value == rx_mode.max_rx_pkt_len)
1195                         return;
1196
1197                 rx_mode.max_rx_pkt_len = res->value;
1198                 if (res->value > ETHER_MAX_LEN)
1199                         rx_mode.jumbo_frame = 1;
1200                 else
1201                         rx_mode.jumbo_frame = 0;
1202         } else {
1203                 printf("Unknown parameter\n");
1204                 return;
1205         }
1206
1207         init_port_config();
1208
1209         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1210 }
1211
1212 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1213         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1214                                                                 "port");
1215 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1216         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1217                                                                 "config");
1218 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1219         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1220                                                                 "all");
1221 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1222         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1223                                                                 "max-pkt-len");
1224 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1225         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1226                                                                 UINT32);
1227
1228 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1229         .f = cmd_config_max_pkt_len_parsed,
1230         .data = NULL,
1231         .help_str = "port config all max-pkt-len value",
1232         .tokens = {
1233                 (void *)&cmd_config_max_pkt_len_port,
1234                 (void *)&cmd_config_max_pkt_len_keyword,
1235                 (void *)&cmd_config_max_pkt_len_all,
1236                 (void *)&cmd_config_max_pkt_len_name,
1237                 (void *)&cmd_config_max_pkt_len_value,
1238                 NULL,
1239         },
1240 };
1241
1242 /* *** configure port MTU *** */
1243 struct cmd_config_mtu_result {
1244         cmdline_fixed_string_t port;
1245         cmdline_fixed_string_t keyword;
1246         cmdline_fixed_string_t mtu;
1247         uint8_t port_id;
1248         uint16_t value;
1249 };
1250
1251 static void
1252 cmd_config_mtu_parsed(void *parsed_result,
1253                       __attribute__((unused)) struct cmdline *cl,
1254                       __attribute__((unused)) void *data)
1255 {
1256         struct cmd_config_mtu_result *res = parsed_result;
1257
1258         if (res->value < ETHER_MIN_LEN) {
1259                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1260                 return;
1261         }
1262         port_mtu_set(res->port_id, res->value);
1263 }
1264
1265 cmdline_parse_token_string_t cmd_config_mtu_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1267                                  "port");
1268 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1269         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1270                                  "config");
1271 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1272         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1273                                  "mtu");
1274 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1275         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1276 cmdline_parse_token_num_t cmd_config_mtu_value =
1277         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1278
1279 cmdline_parse_inst_t cmd_config_mtu = {
1280         .f = cmd_config_mtu_parsed,
1281         .data = NULL,
1282         .help_str = "port config mtu value",
1283         .tokens = {
1284                 (void *)&cmd_config_mtu_port,
1285                 (void *)&cmd_config_mtu_keyword,
1286                 (void *)&cmd_config_mtu_mtu,
1287                 (void *)&cmd_config_mtu_port_id,
1288                 (void *)&cmd_config_mtu_value,
1289                 NULL,
1290         },
1291 };
1292
1293 /* *** configure rx mode *** */
1294 struct cmd_config_rx_mode_flag {
1295         cmdline_fixed_string_t port;
1296         cmdline_fixed_string_t keyword;
1297         cmdline_fixed_string_t all;
1298         cmdline_fixed_string_t name;
1299         cmdline_fixed_string_t value;
1300 };
1301
1302 static void
1303 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1304                                 __attribute__((unused)) struct cmdline *cl,
1305                                 __attribute__((unused)) void *data)
1306 {
1307         struct cmd_config_rx_mode_flag *res = parsed_result;
1308
1309         if (!all_ports_stopped()) {
1310                 printf("Please stop all ports first\n");
1311                 return;
1312         }
1313
1314         if (!strcmp(res->name, "crc-strip")) {
1315                 if (!strcmp(res->value, "on"))
1316                         rx_mode.hw_strip_crc = 1;
1317                 else if (!strcmp(res->value, "off"))
1318                         rx_mode.hw_strip_crc = 0;
1319                 else {
1320                         printf("Unknown parameter\n");
1321                         return;
1322                 }
1323         } else if (!strcmp(res->name, "rx-cksum")) {
1324                 if (!strcmp(res->value, "on"))
1325                         rx_mode.hw_ip_checksum = 1;
1326                 else if (!strcmp(res->value, "off"))
1327                         rx_mode.hw_ip_checksum = 0;
1328                 else {
1329                         printf("Unknown parameter\n");
1330                         return;
1331                 }
1332         } else if (!strcmp(res->name, "hw-vlan")) {
1333                 if (!strcmp(res->value, "on")) {
1334                         rx_mode.hw_vlan_filter = 1;
1335                         rx_mode.hw_vlan_strip  = 1;
1336                 }
1337                 else if (!strcmp(res->value, "off")) {
1338                         rx_mode.hw_vlan_filter = 0;
1339                         rx_mode.hw_vlan_strip  = 0;
1340                 }
1341                 else {
1342                         printf("Unknown parameter\n");
1343                         return;
1344                 }
1345         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1346                 if (!strcmp(res->value, "on"))
1347                         rx_mode.hw_vlan_filter = 1;
1348                 else if (!strcmp(res->value, "off"))
1349                         rx_mode.hw_vlan_filter = 0;
1350                 else {
1351                         printf("Unknown parameter\n");
1352                         return;
1353                 }
1354         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1355                 if (!strcmp(res->value, "on"))
1356                         rx_mode.hw_vlan_strip  = 1;
1357                 else if (!strcmp(res->value, "off"))
1358                         rx_mode.hw_vlan_strip  = 0;
1359                 else {
1360                         printf("Unknown parameter\n");
1361                         return;
1362                 }
1363         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1364                 if (!strcmp(res->value, "on"))
1365                         rx_mode.hw_vlan_extend = 1;
1366                 else if (!strcmp(res->value, "off"))
1367                         rx_mode.hw_vlan_extend = 0;
1368                 else {
1369                         printf("Unknown parameter\n");
1370                         return;
1371                 }
1372         } else if (!strcmp(res->name, "drop-en")) {
1373                 if (!strcmp(res->value, "on"))
1374                         rx_drop_en = 1;
1375                 else if (!strcmp(res->value, "off"))
1376                         rx_drop_en = 0;
1377                 else {
1378                         printf("Unknown parameter\n");
1379                         return;
1380                 }
1381         } else {
1382                 printf("Unknown parameter\n");
1383                 return;
1384         }
1385
1386         init_port_config();
1387
1388         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1389 }
1390
1391 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1393 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1395                                                                 "config");
1396 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1398 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1400                                         "crc-strip#rx-cksum#hw-vlan#"
1401                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1402 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1403         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1404                                                         "on#off");
1405
1406 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1407         .f = cmd_config_rx_mode_flag_parsed,
1408         .data = NULL,
1409         .help_str = "port config all crc-strip|rx-cksum|hw-vlan|"
1410                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1411         .tokens = {
1412                 (void *)&cmd_config_rx_mode_flag_port,
1413                 (void *)&cmd_config_rx_mode_flag_keyword,
1414                 (void *)&cmd_config_rx_mode_flag_all,
1415                 (void *)&cmd_config_rx_mode_flag_name,
1416                 (void *)&cmd_config_rx_mode_flag_value,
1417                 NULL,
1418         },
1419 };
1420
1421 /* *** configure rss *** */
1422 struct cmd_config_rss {
1423         cmdline_fixed_string_t port;
1424         cmdline_fixed_string_t keyword;
1425         cmdline_fixed_string_t all;
1426         cmdline_fixed_string_t name;
1427         cmdline_fixed_string_t value;
1428 };
1429
1430 static void
1431 cmd_config_rss_parsed(void *parsed_result,
1432                         __attribute__((unused)) struct cmdline *cl,
1433                         __attribute__((unused)) void *data)
1434 {
1435         struct cmd_config_rss *res = parsed_result;
1436         struct rte_eth_rss_conf rss_conf;
1437         uint8_t i;
1438
1439         if (!strcmp(res->value, "all"))
1440                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1441                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1442                                         ETH_RSS_L2_PAYLOAD;
1443         else if (!strcmp(res->value, "ip"))
1444                 rss_conf.rss_hf = ETH_RSS_IP;
1445         else if (!strcmp(res->value, "udp"))
1446                 rss_conf.rss_hf = ETH_RSS_UDP;
1447         else if (!strcmp(res->value, "tcp"))
1448                 rss_conf.rss_hf = ETH_RSS_TCP;
1449         else if (!strcmp(res->value, "sctp"))
1450                 rss_conf.rss_hf = ETH_RSS_SCTP;
1451         else if (!strcmp(res->value, "ether"))
1452                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1453         else if (!strcmp(res->value, "none"))
1454                 rss_conf.rss_hf = 0;
1455         else {
1456                 printf("Unknown parameter\n");
1457                 return;
1458         }
1459         rss_conf.rss_key = NULL;
1460         for (i = 0; i < rte_eth_dev_count(); i++)
1461                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1462 }
1463
1464 cmdline_parse_token_string_t cmd_config_rss_port =
1465         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1466 cmdline_parse_token_string_t cmd_config_rss_keyword =
1467         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1468 cmdline_parse_token_string_t cmd_config_rss_all =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1470 cmdline_parse_token_string_t cmd_config_rss_name =
1471         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1472 cmdline_parse_token_string_t cmd_config_rss_value =
1473         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1474                 "all#ip#tcp#udp#sctp#ether#none");
1475
1476 cmdline_parse_inst_t cmd_config_rss = {
1477         .f = cmd_config_rss_parsed,
1478         .data = NULL,
1479         .help_str = "port config all rss all|ip|tcp|udp|sctp|ether|none",
1480         .tokens = {
1481                 (void *)&cmd_config_rss_port,
1482                 (void *)&cmd_config_rss_keyword,
1483                 (void *)&cmd_config_rss_all,
1484                 (void *)&cmd_config_rss_name,
1485                 (void *)&cmd_config_rss_value,
1486                 NULL,
1487         },
1488 };
1489
1490 /* *** configure rss hash key *** */
1491 struct cmd_config_rss_hash_key {
1492         cmdline_fixed_string_t port;
1493         cmdline_fixed_string_t config;
1494         uint8_t port_id;
1495         cmdline_fixed_string_t rss_hash_key;
1496         cmdline_fixed_string_t key;
1497 };
1498
1499 #define RSS_HASH_KEY_LENGTH 40
1500 static uint8_t
1501 hexa_digit_to_value(char hexa_digit)
1502 {
1503         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1504                 return (uint8_t) (hexa_digit - '0');
1505         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1506                 return (uint8_t) ((hexa_digit - 'a') + 10);
1507         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1508                 return (uint8_t) ((hexa_digit - 'A') + 10);
1509         /* Invalid hexa digit */
1510         return 0xFF;
1511 }
1512
1513 static uint8_t
1514 parse_and_check_key_hexa_digit(char *key, int idx)
1515 {
1516         uint8_t hexa_v;
1517
1518         hexa_v = hexa_digit_to_value(key[idx]);
1519         if (hexa_v == 0xFF)
1520                 printf("invalid key: character %c at position %d is not a "
1521                        "valid hexa digit\n", key[idx], idx);
1522         return hexa_v;
1523 }
1524
1525 static void
1526 cmd_config_rss_hash_key_parsed(void *parsed_result,
1527                                __attribute__((unused)) struct cmdline *cl,
1528                                __attribute__((unused)) void *data)
1529 {
1530         struct cmd_config_rss_hash_key *res = parsed_result;
1531         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1532         uint8_t xdgt0;
1533         uint8_t xdgt1;
1534         int i;
1535
1536         /* Check the length of the RSS hash key */
1537         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1538                 printf("key length: %d invalid - key must be a string of %d"
1539                        "hexa-decimal numbers\n", (int) strlen(res->key),
1540                        RSS_HASH_KEY_LENGTH * 2);
1541                 return;
1542         }
1543         /* Translate RSS hash key into binary representation */
1544         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1545                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1546                 if (xdgt0 == 0xFF)
1547                         return;
1548                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1549                 if (xdgt1 == 0xFF)
1550                         return;
1551                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1552         }
1553         port_rss_hash_key_update(res->port_id, hash_key);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1560                                  "config");
1561 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1562         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1563 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1565                                  rss_hash_key, "rss-hash-key");
1566 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1568
1569 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1570         .f = cmd_config_rss_hash_key_parsed,
1571         .data = NULL,
1572         .help_str = "port config X rss-hash-key 80 hexa digits",
1573         .tokens = {
1574                 (void *)&cmd_config_rss_hash_key_port,
1575                 (void *)&cmd_config_rss_hash_key_config,
1576                 (void *)&cmd_config_rss_hash_key_port_id,
1577                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1578                 (void *)&cmd_config_rss_hash_key_value,
1579                 NULL,
1580         },
1581 };
1582
1583 /* *** configure port rxq/txq start/stop *** */
1584 struct cmd_config_rxtx_queue {
1585         cmdline_fixed_string_t port;
1586         uint8_t portid;
1587         cmdline_fixed_string_t rxtxq;
1588         uint16_t qid;
1589         cmdline_fixed_string_t opname;
1590 };
1591
1592 static void
1593 cmd_config_rxtx_queue_parsed(void *parsed_result,
1594                         __attribute__((unused)) struct cmdline *cl,
1595                         __attribute__((unused)) void *data)
1596 {
1597         struct cmd_config_rxtx_queue *res = parsed_result;
1598         uint8_t isrx;
1599         uint8_t isstart;
1600         int ret = 0;
1601
1602         if (test_done == 0) {
1603                 printf("Please stop forwarding first\n");
1604                 return;
1605         }
1606
1607         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1608                 return;
1609
1610         if (port_is_started(res->portid) != 1) {
1611                 printf("Please start port %u first\n", res->portid);
1612                 return;
1613         }
1614
1615         if (!strcmp(res->rxtxq, "rxq"))
1616                 isrx = 1;
1617         else if (!strcmp(res->rxtxq, "txq"))
1618                 isrx = 0;
1619         else {
1620                 printf("Unknown parameter\n");
1621                 return;
1622         }
1623
1624         if (isrx && rx_queue_id_is_invalid(res->qid))
1625                 return;
1626         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1627                 return;
1628
1629         if (!strcmp(res->opname, "start"))
1630                 isstart = 1;
1631         else if (!strcmp(res->opname, "stop"))
1632                 isstart = 0;
1633         else {
1634                 printf("Unknown parameter\n");
1635                 return;
1636         }
1637
1638         if (isstart && isrx)
1639                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1640         else if (!isstart && isrx)
1641                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1642         else if (isstart && !isrx)
1643                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1644         else
1645                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1646
1647         if (ret == -ENOTSUP)
1648                 printf("Function not supported in PMD driver\n");
1649 }
1650
1651 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1653 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1654         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1655 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1657 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1658         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1659 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1661                                                 "start#stop");
1662
1663 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1664         .f = cmd_config_rxtx_queue_parsed,
1665         .data = NULL,
1666         .help_str = "port X rxq|txq ID start|stop",
1667         .tokens = {
1668                 (void *)&cmd_config_speed_all_port,
1669                 (void *)&cmd_config_rxtx_queue_portid,
1670                 (void *)&cmd_config_rxtx_queue_rxtxq,
1671                 (void *)&cmd_config_rxtx_queue_qid,
1672                 (void *)&cmd_config_rxtx_queue_opname,
1673                 NULL,
1674         },
1675 };
1676
1677 /* *** Configure RSS RETA *** */
1678 struct cmd_config_rss_reta {
1679         cmdline_fixed_string_t port;
1680         cmdline_fixed_string_t keyword;
1681         uint8_t port_id;
1682         cmdline_fixed_string_t name;
1683         cmdline_fixed_string_t list_name;
1684         cmdline_fixed_string_t list_of_items;
1685 };
1686
1687 static int
1688 parse_reta_config(const char *str,
1689                   struct rte_eth_rss_reta_entry64 *reta_conf,
1690                   uint16_t nb_entries)
1691 {
1692         int i;
1693         unsigned size;
1694         uint16_t hash_index, idx, shift;
1695         uint8_t nb_queue;
1696         char s[256];
1697         const char *p, *p0 = str;
1698         char *end;
1699         enum fieldnames {
1700                 FLD_HASH_INDEX = 0,
1701                 FLD_QUEUE,
1702                 _NUM_FLD
1703         };
1704         unsigned long int_fld[_NUM_FLD];
1705         char *str_fld[_NUM_FLD];
1706
1707         while ((p = strchr(p0,'(')) != NULL) {
1708                 ++p;
1709                 if((p0 = strchr(p,')')) == NULL)
1710                         return -1;
1711
1712                 size = p0 - p;
1713                 if(size >= sizeof(s))
1714                         return -1;
1715
1716                 snprintf(s, sizeof(s), "%.*s", size, p);
1717                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1718                         return -1;
1719                 for (i = 0; i < _NUM_FLD; i++) {
1720                         errno = 0;
1721                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1722                         if (errno != 0 || end == str_fld[i] ||
1723                                         int_fld[i] > 65535)
1724                                 return -1;
1725                 }
1726
1727                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1728                 nb_queue = (uint8_t)int_fld[FLD_QUEUE];
1729
1730                 if (hash_index >= nb_entries) {
1731                         printf("Invalid RETA hash index=%d\n", hash_index);
1732                         return -1;
1733                 }
1734
1735                 idx = hash_index / RTE_RETA_GROUP_SIZE;
1736                 shift = hash_index % RTE_RETA_GROUP_SIZE;
1737                 reta_conf[idx].mask |= (1ULL << shift);
1738                 reta_conf[idx].reta[shift] = nb_queue;
1739         }
1740
1741         return 0;
1742 }
1743
1744 static void
1745 cmd_set_rss_reta_parsed(void *parsed_result,
1746                         __attribute__((unused)) struct cmdline *cl,
1747                         __attribute__((unused)) void *data)
1748 {
1749         int ret;
1750         struct rte_eth_dev_info dev_info;
1751         struct rte_eth_rss_reta_entry64 reta_conf[8];
1752         struct cmd_config_rss_reta *res = parsed_result;
1753
1754         memset(&dev_info, 0, sizeof(dev_info));
1755         rte_eth_dev_info_get(res->port_id, &dev_info);
1756         if (dev_info.reta_size == 0) {
1757                 printf("Redirection table size is 0 which is "
1758                                         "invalid for RSS\n");
1759                 return;
1760         } else
1761                 printf("The reta size of port %d is %u\n",
1762                         res->port_id, dev_info.reta_size);
1763         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
1764                 printf("Currently do not support more than %u entries of "
1765                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
1766                 return;
1767         }
1768
1769         memset(reta_conf, 0, sizeof(reta_conf));
1770         if (!strcmp(res->list_name, "reta")) {
1771                 if (parse_reta_config(res->list_of_items, reta_conf,
1772                                                 dev_info.reta_size)) {
1773                         printf("Invalid RSS Redirection Table "
1774                                         "config entered\n");
1775                         return;
1776                 }
1777                 ret = rte_eth_dev_rss_reta_update(res->port_id,
1778                                 reta_conf, dev_info.reta_size);
1779                 if (ret != 0)
1780                         printf("Bad redirection table parameter, "
1781                                         "return code = %d \n", ret);
1782         }
1783 }
1784
1785 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1787 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1789 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1790         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1791 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1793 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1795 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1796         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1797                                  NULL);
1798 cmdline_parse_inst_t cmd_config_rss_reta = {
1799         .f = cmd_set_rss_reta_parsed,
1800         .data = NULL,
1801         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1802         .tokens = {
1803                 (void *)&cmd_config_rss_reta_port,
1804                 (void *)&cmd_config_rss_reta_keyword,
1805                 (void *)&cmd_config_rss_reta_port_id,
1806                 (void *)&cmd_config_rss_reta_name,
1807                 (void *)&cmd_config_rss_reta_list_name,
1808                 (void *)&cmd_config_rss_reta_list_of_items,
1809                 NULL,
1810         },
1811 };
1812
1813 /* *** SHOW PORT RETA INFO *** */
1814 struct cmd_showport_reta {
1815         cmdline_fixed_string_t show;
1816         cmdline_fixed_string_t port;
1817         uint8_t port_id;
1818         cmdline_fixed_string_t rss;
1819         cmdline_fixed_string_t reta;
1820         uint16_t size;
1821         cmdline_fixed_string_t list_of_items;
1822 };
1823
1824 static int
1825 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
1826                            uint16_t nb_entries,
1827                            char *str)
1828 {
1829         uint32_t size;
1830         const char *p, *p0 = str;
1831         char s[256];
1832         char *end;
1833         char *str_fld[8];
1834         uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE;
1835         int ret;
1836
1837         p = strchr(p0, '(');
1838         if (p == NULL)
1839                 return -1;
1840         p++;
1841         p0 = strchr(p, ')');
1842         if (p0 == NULL)
1843                 return -1;
1844         size = p0 - p;
1845         if (size >= sizeof(s)) {
1846                 printf("The string size exceeds the internal buffer size\n");
1847                 return -1;
1848         }
1849         snprintf(s, sizeof(s), "%.*s", size, p);
1850         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
1851         if (ret <= 0 || ret != num) {
1852                 printf("The bits of masks do not match the number of "
1853                                         "reta entries: %u\n", num);
1854                 return -1;
1855         }
1856         for (i = 0; i < ret; i++)
1857                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
1858
1859         return 0;
1860 }
1861
1862 static void
1863 cmd_showport_reta_parsed(void *parsed_result,
1864                          __attribute__((unused)) struct cmdline *cl,
1865                          __attribute__((unused)) void *data)
1866 {
1867         struct cmd_showport_reta *res = parsed_result;
1868         struct rte_eth_rss_reta_entry64 reta_conf[8];
1869         struct rte_eth_dev_info dev_info;
1870
1871         memset(&dev_info, 0, sizeof(dev_info));
1872         rte_eth_dev_info_get(res->port_id, &dev_info);
1873         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
1874                                 res->size > ETH_RSS_RETA_SIZE_512) {
1875                 printf("Invalid redirection table size: %u\n", res->size);
1876                 return;
1877         }
1878
1879         memset(reta_conf, 0, sizeof(reta_conf));
1880         if (showport_parse_reta_config(reta_conf, res->size,
1881                                 res->list_of_items) < 0) {
1882                 printf("Invalid string: %s for reta masks\n",
1883                                         res->list_of_items);
1884                 return;
1885         }
1886         port_rss_reta_info(res->port_id, reta_conf, res->size);
1887 }
1888
1889 cmdline_parse_token_string_t cmd_showport_reta_show =
1890         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1891 cmdline_parse_token_string_t cmd_showport_reta_port =
1892         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1893 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1894         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1895 cmdline_parse_token_string_t cmd_showport_reta_rss =
1896         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1897 cmdline_parse_token_string_t cmd_showport_reta_reta =
1898         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1899 cmdline_parse_token_num_t cmd_showport_reta_size =
1900         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
1901 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
1902         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
1903                                         list_of_items, NULL);
1904
1905 cmdline_parse_inst_t cmd_showport_reta = {
1906         .f = cmd_showport_reta_parsed,
1907         .data = NULL,
1908         .help_str = "show port X rss reta (size) (mask0,mask1,...)",
1909         .tokens = {
1910                 (void *)&cmd_showport_reta_show,
1911                 (void *)&cmd_showport_reta_port,
1912                 (void *)&cmd_showport_reta_port_id,
1913                 (void *)&cmd_showport_reta_rss,
1914                 (void *)&cmd_showport_reta_reta,
1915                 (void *)&cmd_showport_reta_size,
1916                 (void *)&cmd_showport_reta_list_of_items,
1917                 NULL,
1918         },
1919 };
1920
1921 /* *** Show RSS hash configuration *** */
1922 struct cmd_showport_rss_hash {
1923         cmdline_fixed_string_t show;
1924         cmdline_fixed_string_t port;
1925         uint8_t port_id;
1926         cmdline_fixed_string_t rss_hash;
1927         cmdline_fixed_string_t key; /* optional argument */
1928 };
1929
1930 static void cmd_showport_rss_hash_parsed(void *parsed_result,
1931                                 __attribute__((unused)) struct cmdline *cl,
1932                                 void *show_rss_key)
1933 {
1934         struct cmd_showport_rss_hash *res = parsed_result;
1935
1936         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
1937 }
1938
1939 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
1940         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
1941 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
1942         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
1943 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
1944         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
1945 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
1946         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
1947                                  "rss-hash");
1948 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
1949         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
1950
1951 cmdline_parse_inst_t cmd_showport_rss_hash = {
1952         .f = cmd_showport_rss_hash_parsed,
1953         .data = NULL,
1954         .help_str = "show port X rss-hash (X = port number)\n",
1955         .tokens = {
1956                 (void *)&cmd_showport_rss_hash_show,
1957                 (void *)&cmd_showport_rss_hash_port,
1958                 (void *)&cmd_showport_rss_hash_port_id,
1959                 (void *)&cmd_showport_rss_hash_rss_hash,
1960                 NULL,
1961         },
1962 };
1963
1964 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
1965         .f = cmd_showport_rss_hash_parsed,
1966         .data = (void *)1,
1967         .help_str = "show port X rss-hash key (X = port number)\n",
1968         .tokens = {
1969                 (void *)&cmd_showport_rss_hash_show,
1970                 (void *)&cmd_showport_rss_hash_port,
1971                 (void *)&cmd_showport_rss_hash_port_id,
1972                 (void *)&cmd_showport_rss_hash_rss_hash,
1973                 (void *)&cmd_showport_rss_hash_rss_key,
1974                 NULL,
1975         },
1976 };
1977
1978 /* *** Configure DCB *** */
1979 struct cmd_config_dcb {
1980         cmdline_fixed_string_t port;
1981         cmdline_fixed_string_t config;
1982         uint8_t port_id;
1983         cmdline_fixed_string_t dcb;
1984         cmdline_fixed_string_t vt;
1985         cmdline_fixed_string_t vt_en;
1986         uint8_t num_tcs;
1987         cmdline_fixed_string_t pfc;
1988         cmdline_fixed_string_t pfc_en;
1989 };
1990
1991 static void
1992 cmd_config_dcb_parsed(void *parsed_result,
1993                         __attribute__((unused)) struct cmdline *cl,
1994                         __attribute__((unused)) void *data)
1995 {
1996         struct cmd_config_dcb *res = parsed_result;
1997         struct dcb_config dcb_conf;
1998         portid_t port_id = res->port_id;
1999         struct rte_port *port;
2000
2001         port = &ports[port_id];
2002         /** Check if the port is not started **/
2003         if (port->port_status != RTE_PORT_STOPPED) {
2004                 printf("Please stop port %d first\n",port_id);
2005                 return;
2006         }
2007
2008         dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs;
2009         if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){
2010                 printf("The invalid number of traffic class,only 4 or 8 allowed\n");
2011                 return;
2012         }
2013
2014         /* DCB in VT mode */
2015         if (!strncmp(res->vt_en, "on",2))
2016                 dcb_conf.dcb_mode = DCB_VT_ENABLED;
2017         else
2018                 dcb_conf.dcb_mode = DCB_ENABLED;
2019
2020         if (!strncmp(res->pfc_en, "on",2)) {
2021                 dcb_conf.pfc_en = 1;
2022         }
2023         else
2024                 dcb_conf.pfc_en = 0;
2025
2026         if (init_port_dcb_config(port_id,&dcb_conf) != 0) {
2027                 printf("Cannot initialize network ports\n");
2028                 return;
2029         }
2030
2031         cmd_reconfig_device_queue(port_id, 1, 1);
2032 }
2033
2034 cmdline_parse_token_string_t cmd_config_dcb_port =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2036 cmdline_parse_token_string_t cmd_config_dcb_config =
2037         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2038 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2039         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2040 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2041         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2042 cmdline_parse_token_string_t cmd_config_dcb_vt =
2043         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2044 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2045         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2046 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2047         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2048 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2049         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2050 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2051         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2052
2053 cmdline_parse_inst_t cmd_config_dcb = {
2054         .f = cmd_config_dcb_parsed,
2055         .data = NULL,
2056         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
2057         .tokens = {
2058                 (void *)&cmd_config_dcb_port,
2059                 (void *)&cmd_config_dcb_config,
2060                 (void *)&cmd_config_dcb_port_id,
2061                 (void *)&cmd_config_dcb_dcb,
2062                 (void *)&cmd_config_dcb_vt,
2063                 (void *)&cmd_config_dcb_vt_en,
2064                 (void *)&cmd_config_dcb_num_tcs,
2065                 (void *)&cmd_config_dcb_pfc,
2066                 (void *)&cmd_config_dcb_pfc_en,
2067                 NULL,
2068         },
2069 };
2070
2071 /* *** configure number of packets per burst *** */
2072 struct cmd_config_burst {
2073         cmdline_fixed_string_t port;
2074         cmdline_fixed_string_t keyword;
2075         cmdline_fixed_string_t all;
2076         cmdline_fixed_string_t name;
2077         uint16_t value;
2078 };
2079
2080 static void
2081 cmd_config_burst_parsed(void *parsed_result,
2082                         __attribute__((unused)) struct cmdline *cl,
2083                         __attribute__((unused)) void *data)
2084 {
2085         struct cmd_config_burst *res = parsed_result;
2086
2087         if (!all_ports_stopped()) {
2088                 printf("Please stop all ports first\n");
2089                 return;
2090         }
2091
2092         if (!strcmp(res->name, "burst")) {
2093                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2094                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2095                         return;
2096                 }
2097                 nb_pkt_per_burst = res->value;
2098         } else {
2099                 printf("Unknown parameter\n");
2100                 return;
2101         }
2102
2103         init_port_config();
2104
2105         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2106 }
2107
2108 cmdline_parse_token_string_t cmd_config_burst_port =
2109         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2110 cmdline_parse_token_string_t cmd_config_burst_keyword =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2112 cmdline_parse_token_string_t cmd_config_burst_all =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2114 cmdline_parse_token_string_t cmd_config_burst_name =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2116 cmdline_parse_token_num_t cmd_config_burst_value =
2117         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2118
2119 cmdline_parse_inst_t cmd_config_burst = {
2120         .f = cmd_config_burst_parsed,
2121         .data = NULL,
2122         .help_str = "port config all burst value",
2123         .tokens = {
2124                 (void *)&cmd_config_burst_port,
2125                 (void *)&cmd_config_burst_keyword,
2126                 (void *)&cmd_config_burst_all,
2127                 (void *)&cmd_config_burst_name,
2128                 (void *)&cmd_config_burst_value,
2129                 NULL,
2130         },
2131 };
2132
2133 /* *** configure rx/tx queues *** */
2134 struct cmd_config_thresh {
2135         cmdline_fixed_string_t port;
2136         cmdline_fixed_string_t keyword;
2137         cmdline_fixed_string_t all;
2138         cmdline_fixed_string_t name;
2139         uint8_t value;
2140 };
2141
2142 static void
2143 cmd_config_thresh_parsed(void *parsed_result,
2144                         __attribute__((unused)) struct cmdline *cl,
2145                         __attribute__((unused)) void *data)
2146 {
2147         struct cmd_config_thresh *res = parsed_result;
2148
2149         if (!all_ports_stopped()) {
2150                 printf("Please stop all ports first\n");
2151                 return;
2152         }
2153
2154         if (!strcmp(res->name, "txpt"))
2155                 tx_pthresh = res->value;
2156         else if(!strcmp(res->name, "txht"))
2157                 tx_hthresh = res->value;
2158         else if(!strcmp(res->name, "txwt"))
2159                 tx_wthresh = res->value;
2160         else if(!strcmp(res->name, "rxpt"))
2161                 rx_pthresh = res->value;
2162         else if(!strcmp(res->name, "rxht"))
2163                 rx_hthresh = res->value;
2164         else if(!strcmp(res->name, "rxwt"))
2165                 rx_wthresh = res->value;
2166         else {
2167                 printf("Unknown parameter\n");
2168                 return;
2169         }
2170
2171         init_port_config();
2172
2173         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2174 }
2175
2176 cmdline_parse_token_string_t cmd_config_thresh_port =
2177         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2178 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2179         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2180 cmdline_parse_token_string_t cmd_config_thresh_all =
2181         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2182 cmdline_parse_token_string_t cmd_config_thresh_name =
2183         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2184                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2185 cmdline_parse_token_num_t cmd_config_thresh_value =
2186         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2187
2188 cmdline_parse_inst_t cmd_config_thresh = {
2189         .f = cmd_config_thresh_parsed,
2190         .data = NULL,
2191         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
2192         .tokens = {
2193                 (void *)&cmd_config_thresh_port,
2194                 (void *)&cmd_config_thresh_keyword,
2195                 (void *)&cmd_config_thresh_all,
2196                 (void *)&cmd_config_thresh_name,
2197                 (void *)&cmd_config_thresh_value,
2198                 NULL,
2199         },
2200 };
2201
2202 /* *** configure free/rs threshold *** */
2203 struct cmd_config_threshold {
2204         cmdline_fixed_string_t port;
2205         cmdline_fixed_string_t keyword;
2206         cmdline_fixed_string_t all;
2207         cmdline_fixed_string_t name;
2208         uint16_t value;
2209 };
2210
2211 static void
2212 cmd_config_threshold_parsed(void *parsed_result,
2213                         __attribute__((unused)) struct cmdline *cl,
2214                         __attribute__((unused)) void *data)
2215 {
2216         struct cmd_config_threshold *res = parsed_result;
2217
2218         if (!all_ports_stopped()) {
2219                 printf("Please stop all ports first\n");
2220                 return;
2221         }
2222
2223         if (!strcmp(res->name, "txfreet"))
2224                 tx_free_thresh = res->value;
2225         else if (!strcmp(res->name, "txrst"))
2226                 tx_rs_thresh = res->value;
2227         else if (!strcmp(res->name, "rxfreet"))
2228                 rx_free_thresh = res->value;
2229         else {
2230                 printf("Unknown parameter\n");
2231                 return;
2232         }
2233
2234         init_port_config();
2235
2236         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2237 }
2238
2239 cmdline_parse_token_string_t cmd_config_threshold_port =
2240         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2241 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2242         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2243                                                                 "config");
2244 cmdline_parse_token_string_t cmd_config_threshold_all =
2245         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2246 cmdline_parse_token_string_t cmd_config_threshold_name =
2247         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2248                                                 "txfreet#txrst#rxfreet");
2249 cmdline_parse_token_num_t cmd_config_threshold_value =
2250         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2251
2252 cmdline_parse_inst_t cmd_config_threshold = {
2253         .f = cmd_config_threshold_parsed,
2254         .data = NULL,
2255         .help_str = "port config all txfreet|txrst|rxfreet value",
2256         .tokens = {
2257                 (void *)&cmd_config_threshold_port,
2258                 (void *)&cmd_config_threshold_keyword,
2259                 (void *)&cmd_config_threshold_all,
2260                 (void *)&cmd_config_threshold_name,
2261                 (void *)&cmd_config_threshold_value,
2262                 NULL,
2263         },
2264 };
2265
2266 /* *** stop *** */
2267 struct cmd_stop_result {
2268         cmdline_fixed_string_t stop;
2269 };
2270
2271 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2272                             __attribute__((unused)) struct cmdline *cl,
2273                             __attribute__((unused)) void *data)
2274 {
2275         stop_packet_forwarding();
2276 }
2277
2278 cmdline_parse_token_string_t cmd_stop_stop =
2279         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2280
2281 cmdline_parse_inst_t cmd_stop = {
2282         .f = cmd_stop_parsed,
2283         .data = NULL,
2284         .help_str = "stop - stop packet forwarding",
2285         .tokens = {
2286                 (void *)&cmd_stop_stop,
2287                 NULL,
2288         },
2289 };
2290
2291 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2292
2293 unsigned int
2294 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2295                 unsigned int *parsed_items, int check_unique_values)
2296 {
2297         unsigned int nb_item;
2298         unsigned int value;
2299         unsigned int i;
2300         unsigned int j;
2301         int value_ok;
2302         char c;
2303
2304         /*
2305          * First parse all items in the list and store their value.
2306          */
2307         value = 0;
2308         nb_item = 0;
2309         value_ok = 0;
2310         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2311                 c = str[i];
2312                 if ((c >= '0') && (c <= '9')) {
2313                         value = (unsigned int) (value * 10 + (c - '0'));
2314                         value_ok = 1;
2315                         continue;
2316                 }
2317                 if (c != ',') {
2318                         printf("character %c is not a decimal digit\n", c);
2319                         return (0);
2320                 }
2321                 if (! value_ok) {
2322                         printf("No valid value before comma\n");
2323                         return (0);
2324                 }
2325                 if (nb_item < max_items) {
2326                         parsed_items[nb_item] = value;
2327                         value_ok = 0;
2328                         value = 0;
2329                 }
2330                 nb_item++;
2331         }
2332         if (nb_item >= max_items) {
2333                 printf("Number of %s = %u > %u (maximum items)\n",
2334                        item_name, nb_item + 1, max_items);
2335                 return (0);
2336         }
2337         parsed_items[nb_item++] = value;
2338         if (! check_unique_values)
2339                 return (nb_item);
2340
2341         /*
2342          * Then, check that all values in the list are differents.
2343          * No optimization here...
2344          */
2345         for (i = 0; i < nb_item; i++) {
2346                 for (j = i + 1; j < nb_item; j++) {
2347                         if (parsed_items[j] == parsed_items[i]) {
2348                                 printf("duplicated %s %u at index %u and %u\n",
2349                                        item_name, parsed_items[i], i, j);
2350                                 return (0);
2351                         }
2352                 }
2353         }
2354         return (nb_item);
2355 }
2356
2357 struct cmd_set_list_result {
2358         cmdline_fixed_string_t cmd_keyword;
2359         cmdline_fixed_string_t list_name;
2360         cmdline_fixed_string_t list_of_items;
2361 };
2362
2363 static void cmd_set_list_parsed(void *parsed_result,
2364                                 __attribute__((unused)) struct cmdline *cl,
2365                                 __attribute__((unused)) void *data)
2366 {
2367         struct cmd_set_list_result *res;
2368         union {
2369                 unsigned int lcorelist[RTE_MAX_LCORE];
2370                 unsigned int portlist[RTE_MAX_ETHPORTS];
2371         } parsed_items;
2372         unsigned int nb_item;
2373
2374         if (test_done == 0) {
2375                 printf("Please stop forwarding first\n");
2376                 return;
2377         }
2378
2379         res = parsed_result;
2380         if (!strcmp(res->list_name, "corelist")) {
2381                 nb_item = parse_item_list(res->list_of_items, "core",
2382                                           RTE_MAX_LCORE,
2383                                           parsed_items.lcorelist, 1);
2384                 if (nb_item > 0)
2385                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2386                 return;
2387         }
2388         if (!strcmp(res->list_name, "portlist")) {
2389                 nb_item = parse_item_list(res->list_of_items, "port",
2390                                           RTE_MAX_ETHPORTS,
2391                                           parsed_items.portlist, 1);
2392                 if (nb_item > 0)
2393                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2394         }
2395 }
2396
2397 cmdline_parse_token_string_t cmd_set_list_keyword =
2398         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2399                                  "set");
2400 cmdline_parse_token_string_t cmd_set_list_name =
2401         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2402                                  "corelist#portlist");
2403 cmdline_parse_token_string_t cmd_set_list_of_items =
2404         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2405                                  NULL);
2406
2407 cmdline_parse_inst_t cmd_set_fwd_list = {
2408         .f = cmd_set_list_parsed,
2409         .data = NULL,
2410         .help_str = "set corelist|portlist x[,y]*",
2411         .tokens = {
2412                 (void *)&cmd_set_list_keyword,
2413                 (void *)&cmd_set_list_name,
2414                 (void *)&cmd_set_list_of_items,
2415                 NULL,
2416         },
2417 };
2418
2419 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2420
2421 struct cmd_setmask_result {
2422         cmdline_fixed_string_t set;
2423         cmdline_fixed_string_t mask;
2424         uint64_t hexavalue;
2425 };
2426
2427 static void cmd_set_mask_parsed(void *parsed_result,
2428                                 __attribute__((unused)) struct cmdline *cl,
2429                                 __attribute__((unused)) void *data)
2430 {
2431         struct cmd_setmask_result *res = parsed_result;
2432
2433         if (test_done == 0) {
2434                 printf("Please stop forwarding first\n");
2435                 return;
2436         }
2437         if (!strcmp(res->mask, "coremask"))
2438                 set_fwd_lcores_mask(res->hexavalue);
2439         else if (!strcmp(res->mask, "portmask"))
2440                 set_fwd_ports_mask(res->hexavalue);
2441 }
2442
2443 cmdline_parse_token_string_t cmd_setmask_set =
2444         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2445 cmdline_parse_token_string_t cmd_setmask_mask =
2446         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2447                                  "coremask#portmask");
2448 cmdline_parse_token_num_t cmd_setmask_value =
2449         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2450
2451 cmdline_parse_inst_t cmd_set_fwd_mask = {
2452         .f = cmd_set_mask_parsed,
2453         .data = NULL,
2454         .help_str = "set coremask|portmask hexadecimal value",
2455         .tokens = {
2456                 (void *)&cmd_setmask_set,
2457                 (void *)&cmd_setmask_mask,
2458                 (void *)&cmd_setmask_value,
2459                 NULL,
2460         },
2461 };
2462
2463 /*
2464  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2465  */
2466 struct cmd_set_result {
2467         cmdline_fixed_string_t set;
2468         cmdline_fixed_string_t what;
2469         uint16_t value;
2470 };
2471
2472 static void cmd_set_parsed(void *parsed_result,
2473                            __attribute__((unused)) struct cmdline *cl,
2474                            __attribute__((unused)) void *data)
2475 {
2476         struct cmd_set_result *res = parsed_result;
2477         if (!strcmp(res->what, "nbport"))
2478                 set_fwd_ports_number(res->value);
2479         else if (!strcmp(res->what, "nbcore"))
2480                 set_fwd_lcores_number(res->value);
2481         else if (!strcmp(res->what, "burst"))
2482                 set_nb_pkt_per_burst(res->value);
2483         else if (!strcmp(res->what, "verbose"))
2484                 set_verbose_level(res->value);
2485 }
2486
2487 cmdline_parse_token_string_t cmd_set_set =
2488         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2489 cmdline_parse_token_string_t cmd_set_what =
2490         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2491                                  "nbport#nbcore#burst#verbose");
2492 cmdline_parse_token_num_t cmd_set_value =
2493         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2494
2495 cmdline_parse_inst_t cmd_set_numbers = {
2496         .f = cmd_set_parsed,
2497         .data = NULL,
2498         .help_str = "set nbport|nbcore|burst|verbose value",
2499         .tokens = {
2500                 (void *)&cmd_set_set,
2501                 (void *)&cmd_set_what,
2502                 (void *)&cmd_set_value,
2503                 NULL,
2504         },
2505 };
2506
2507 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2508
2509 struct cmd_set_txpkts_result {
2510         cmdline_fixed_string_t cmd_keyword;
2511         cmdline_fixed_string_t txpkts;
2512         cmdline_fixed_string_t seg_lengths;
2513 };
2514
2515 static void
2516 cmd_set_txpkts_parsed(void *parsed_result,
2517                       __attribute__((unused)) struct cmdline *cl,
2518                       __attribute__((unused)) void *data)
2519 {
2520         struct cmd_set_txpkts_result *res;
2521         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2522         unsigned int nb_segs;
2523
2524         res = parsed_result;
2525         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2526                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2527         if (nb_segs > 0)
2528                 set_tx_pkt_segments(seg_lengths, nb_segs);
2529 }
2530
2531 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2532         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2533                                  cmd_keyword, "set");
2534 cmdline_parse_token_string_t cmd_set_txpkts_name =
2535         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2536                                  txpkts, "txpkts");
2537 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2538         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2539                                  seg_lengths, NULL);
2540
2541 cmdline_parse_inst_t cmd_set_txpkts = {
2542         .f = cmd_set_txpkts_parsed,
2543         .data = NULL,
2544         .help_str = "set txpkts x[,y]*",
2545         .tokens = {
2546                 (void *)&cmd_set_txpkts_keyword,
2547                 (void *)&cmd_set_txpkts_name,
2548                 (void *)&cmd_set_txpkts_lengths,
2549                 NULL,
2550         },
2551 };
2552
2553 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2554 struct cmd_rx_vlan_filter_all_result {
2555         cmdline_fixed_string_t rx_vlan;
2556         cmdline_fixed_string_t what;
2557         cmdline_fixed_string_t all;
2558         uint8_t port_id;
2559 };
2560
2561 static void
2562 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2563                               __attribute__((unused)) struct cmdline *cl,
2564                               __attribute__((unused)) void *data)
2565 {
2566         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2567
2568         if (!strcmp(res->what, "add"))
2569                 rx_vlan_all_filter_set(res->port_id, 1);
2570         else
2571                 rx_vlan_all_filter_set(res->port_id, 0);
2572 }
2573
2574 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2575         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2576                                  rx_vlan, "rx_vlan");
2577 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2578         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2579                                  what, "add#rm");
2580 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2581         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2582                                  all, "all");
2583 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2584         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2585                               port_id, UINT8);
2586
2587 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2588         .f = cmd_rx_vlan_filter_all_parsed,
2589         .data = NULL,
2590         .help_str = "add/remove all identifiers to/from the set of VLAN "
2591         "Identifiers filtered by a port",
2592         .tokens = {
2593                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2594                 (void *)&cmd_rx_vlan_filter_all_what,
2595                 (void *)&cmd_rx_vlan_filter_all_all,
2596                 (void *)&cmd_rx_vlan_filter_all_portid,
2597                 NULL,
2598         },
2599 };
2600
2601 /* *** VLAN OFFLOAD SET ON A PORT *** */
2602 struct cmd_vlan_offload_result {
2603         cmdline_fixed_string_t vlan;
2604         cmdline_fixed_string_t set;
2605         cmdline_fixed_string_t what;
2606         cmdline_fixed_string_t on;
2607         cmdline_fixed_string_t port_id;
2608 };
2609
2610 static void
2611 cmd_vlan_offload_parsed(void *parsed_result,
2612                           __attribute__((unused)) struct cmdline *cl,
2613                           __attribute__((unused)) void *data)
2614 {
2615         int on;
2616         struct cmd_vlan_offload_result *res = parsed_result;
2617         char *str;
2618         int i, len = 0;
2619         portid_t port_id = 0;
2620         unsigned int tmp;
2621
2622         str = res->port_id;
2623         len = strnlen(str, STR_TOKEN_SIZE);
2624         i = 0;
2625         /* Get port_id first */
2626         while(i < len){
2627                 if(str[i] == ',')
2628                         break;
2629
2630                 i++;
2631         }
2632         str[i]='\0';
2633         tmp = strtoul(str, NULL, 0);
2634         /* If port_id greater that what portid_t can represent, return */
2635         if(tmp >= RTE_MAX_ETHPORTS)
2636                 return;
2637         port_id = (portid_t)tmp;
2638
2639         if (!strcmp(res->on, "on"))
2640                 on = 1;
2641         else
2642                 on = 0;
2643
2644         if (!strcmp(res->what, "strip"))
2645                 rx_vlan_strip_set(port_id,  on);
2646         else if(!strcmp(res->what, "stripq")){
2647                 uint16_t queue_id = 0;
2648
2649                 /* No queue_id, return */
2650                 if(i + 1 >= len) {
2651                         printf("must specify (port,queue_id)\n");
2652                         return;
2653                 }
2654                 tmp = strtoul(str + i + 1, NULL, 0);
2655                 /* If queue_id greater that what 16-bits can represent, return */
2656                 if(tmp > 0xffff)
2657                         return;
2658
2659                 queue_id = (uint16_t)tmp;
2660                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2661         }
2662         else if (!strcmp(res->what, "filter"))
2663                 rx_vlan_filter_set(port_id, on);
2664         else
2665                 vlan_extend_set(port_id, on);
2666
2667         return;
2668 }
2669
2670 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2671         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2672                                  vlan, "vlan");
2673 cmdline_parse_token_string_t cmd_vlan_offload_set =
2674         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2675                                  set, "set");
2676 cmdline_parse_token_string_t cmd_vlan_offload_what =
2677         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2678                                  what, "strip#filter#qinq#stripq");
2679 cmdline_parse_token_string_t cmd_vlan_offload_on =
2680         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2681                               on, "on#off");
2682 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2683         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2684                               port_id, NULL);
2685
2686 cmdline_parse_inst_t cmd_vlan_offload = {
2687         .f = cmd_vlan_offload_parsed,
2688         .data = NULL,
2689         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2690         " qinq(extended) for both rx/tx sides ",
2691         .tokens = {
2692                 (void *)&cmd_vlan_offload_vlan,
2693                 (void *)&cmd_vlan_offload_set,
2694                 (void *)&cmd_vlan_offload_what,
2695                 (void *)&cmd_vlan_offload_on,
2696                 (void *)&cmd_vlan_offload_portid,
2697                 NULL,
2698         },
2699 };
2700
2701 /* *** VLAN TPID SET ON A PORT *** */
2702 struct cmd_vlan_tpid_result {
2703         cmdline_fixed_string_t vlan;
2704         cmdline_fixed_string_t set;
2705         cmdline_fixed_string_t what;
2706         uint16_t tp_id;
2707         uint8_t port_id;
2708 };
2709
2710 static void
2711 cmd_vlan_tpid_parsed(void *parsed_result,
2712                           __attribute__((unused)) struct cmdline *cl,
2713                           __attribute__((unused)) void *data)
2714 {
2715         struct cmd_vlan_tpid_result *res = parsed_result;
2716         vlan_tpid_set(res->port_id, res->tp_id);
2717         return;
2718 }
2719
2720 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2721         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2722                                  vlan, "vlan");
2723 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2724         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2725                                  set, "set");
2726 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2727         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2728                                  what, "tpid");
2729 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2730         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2731                               tp_id, UINT16);
2732 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2733         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2734                               port_id, UINT8);
2735
2736 cmdline_parse_inst_t cmd_vlan_tpid = {
2737         .f = cmd_vlan_tpid_parsed,
2738         .data = NULL,
2739         .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
2740         .tokens = {
2741                 (void *)&cmd_vlan_tpid_vlan,
2742                 (void *)&cmd_vlan_tpid_set,
2743                 (void *)&cmd_vlan_tpid_what,
2744                 (void *)&cmd_vlan_tpid_tpid,
2745                 (void *)&cmd_vlan_tpid_portid,
2746                 NULL,
2747         },
2748 };
2749
2750 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2751 struct cmd_rx_vlan_filter_result {
2752         cmdline_fixed_string_t rx_vlan;
2753         cmdline_fixed_string_t what;
2754         uint16_t vlan_id;
2755         uint8_t port_id;
2756 };
2757
2758 static void
2759 cmd_rx_vlan_filter_parsed(void *parsed_result,
2760                           __attribute__((unused)) struct cmdline *cl,
2761                           __attribute__((unused)) void *data)
2762 {
2763         struct cmd_rx_vlan_filter_result *res = parsed_result;
2764
2765         if (!strcmp(res->what, "add"))
2766                 rx_vft_set(res->port_id, res->vlan_id, 1);
2767         else
2768                 rx_vft_set(res->port_id, res->vlan_id, 0);
2769 }
2770
2771 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2772         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2773                                  rx_vlan, "rx_vlan");
2774 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2775         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2776                                  what, "add#rm");
2777 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2778         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2779                               vlan_id, UINT16);
2780 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2781         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2782                               port_id, UINT8);
2783
2784 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2785         .f = cmd_rx_vlan_filter_parsed,
2786         .data = NULL,
2787         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2788         "Identifiers filtered by a port",
2789         .tokens = {
2790                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2791                 (void *)&cmd_rx_vlan_filter_what,
2792                 (void *)&cmd_rx_vlan_filter_vlanid,
2793                 (void *)&cmd_rx_vlan_filter_portid,
2794                 NULL,
2795         },
2796 };
2797
2798 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2799 struct cmd_tx_vlan_set_result {
2800         cmdline_fixed_string_t tx_vlan;
2801         cmdline_fixed_string_t set;
2802         uint8_t port_id;
2803         uint16_t vlan_id;
2804 };
2805
2806 static void
2807 cmd_tx_vlan_set_parsed(void *parsed_result,
2808                        __attribute__((unused)) struct cmdline *cl,
2809                        __attribute__((unused)) void *data)
2810 {
2811         struct cmd_tx_vlan_set_result *res = parsed_result;
2812         int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id);
2813
2814         if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
2815                 printf("Error, as QinQ has been enabled.\n");
2816                 return;
2817         }
2818
2819         tx_vlan_set(res->port_id, res->vlan_id);
2820 }
2821
2822 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2823         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2824                                  tx_vlan, "tx_vlan");
2825 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2826         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2827                                  set, "set");
2828 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2829         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2830                               vlan_id, UINT16);
2831 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2832         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2833                               port_id, UINT8);
2834
2835 cmdline_parse_inst_t cmd_tx_vlan_set = {
2836         .f = cmd_tx_vlan_set_parsed,
2837         .data = NULL,
2838         .help_str = "enable hardware insertion of a single VLAN header "
2839                 "with a given TAG Identifier in packets sent on a port",
2840         .tokens = {
2841                 (void *)&cmd_tx_vlan_set_tx_vlan,
2842                 (void *)&cmd_tx_vlan_set_set,
2843                 (void *)&cmd_tx_vlan_set_portid,
2844                 (void *)&cmd_tx_vlan_set_vlanid,
2845                 NULL,
2846         },
2847 };
2848
2849 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
2850 struct cmd_tx_vlan_set_qinq_result {
2851         cmdline_fixed_string_t tx_vlan;
2852         cmdline_fixed_string_t set;
2853         uint8_t port_id;
2854         uint16_t vlan_id;
2855         uint16_t vlan_id_outer;
2856 };
2857
2858 static void
2859 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
2860                             __attribute__((unused)) struct cmdline *cl,
2861                             __attribute__((unused)) void *data)
2862 {
2863         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
2864         int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id);
2865
2866         if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
2867                 printf("Error, as QinQ hasn't been enabled.\n");
2868                 return;
2869         }
2870
2871         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
2872 }
2873
2874 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
2875         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
2876                 tx_vlan, "tx_vlan");
2877 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
2878         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
2879                 set, "set");
2880 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
2881         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
2882                 port_id, UINT8);
2883 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
2884         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
2885                 vlan_id, UINT16);
2886 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
2887         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
2888                 vlan_id_outer, UINT16);
2889
2890 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
2891         .f = cmd_tx_vlan_set_qinq_parsed,
2892         .data = NULL,
2893         .help_str = "enable hardware insertion of double VLAN header "
2894                 "with given TAG Identifiers in packets sent on a port",
2895         .tokens = {
2896                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
2897                 (void *)&cmd_tx_vlan_set_qinq_set,
2898                 (void *)&cmd_tx_vlan_set_qinq_portid,
2899                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
2900                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
2901                 NULL,
2902         },
2903 };
2904
2905 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
2906 struct cmd_tx_vlan_set_pvid_result {
2907         cmdline_fixed_string_t tx_vlan;
2908         cmdline_fixed_string_t set;
2909         cmdline_fixed_string_t pvid;
2910         uint8_t port_id;
2911         uint16_t vlan_id;
2912         cmdline_fixed_string_t mode;
2913 };
2914
2915 static void
2916 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
2917                             __attribute__((unused)) struct cmdline *cl,
2918                             __attribute__((unused)) void *data)
2919 {
2920         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
2921
2922         if (strcmp(res->mode, "on") == 0)
2923                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
2924         else
2925                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
2926 }
2927
2928 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
2929         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2930                                  tx_vlan, "tx_vlan");
2931 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
2932         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2933                                  set, "set");
2934 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
2935         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2936                                  pvid, "pvid");
2937 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
2938         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2939                              port_id, UINT8);
2940 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
2941         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2942                               vlan_id, UINT16);
2943 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
2944         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
2945                                  mode, "on#off");
2946
2947 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
2948         .f = cmd_tx_vlan_set_pvid_parsed,
2949         .data = NULL,
2950         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
2951         .tokens = {
2952                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
2953                 (void *)&cmd_tx_vlan_set_pvid_set,
2954                 (void *)&cmd_tx_vlan_set_pvid_pvid,
2955                 (void *)&cmd_tx_vlan_set_pvid_port_id,
2956                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
2957                 (void *)&cmd_tx_vlan_set_pvid_mode,
2958                 NULL,
2959         },
2960 };
2961
2962 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2963 struct cmd_tx_vlan_reset_result {
2964         cmdline_fixed_string_t tx_vlan;
2965         cmdline_fixed_string_t reset;
2966         uint8_t port_id;
2967 };
2968
2969 static void
2970 cmd_tx_vlan_reset_parsed(void *parsed_result,
2971                          __attribute__((unused)) struct cmdline *cl,
2972                          __attribute__((unused)) void *data)
2973 {
2974         struct cmd_tx_vlan_reset_result *res = parsed_result;
2975
2976         tx_vlan_reset(res->port_id);
2977 }
2978
2979 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
2980         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2981                                  tx_vlan, "tx_vlan");
2982 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
2983         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
2984                                  reset, "reset");
2985 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
2986         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
2987                               port_id, UINT8);
2988
2989 cmdline_parse_inst_t cmd_tx_vlan_reset = {
2990         .f = cmd_tx_vlan_reset_parsed,
2991         .data = NULL,
2992         .help_str = "disable hardware insertion of a VLAN header in packets "
2993         "sent on a port",
2994         .tokens = {
2995                 (void *)&cmd_tx_vlan_reset_tx_vlan,
2996                 (void *)&cmd_tx_vlan_reset_reset,
2997                 (void *)&cmd_tx_vlan_reset_portid,
2998                 NULL,
2999         },
3000 };
3001
3002
3003 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3004 struct cmd_csum_result {
3005         cmdline_fixed_string_t csum;
3006         cmdline_fixed_string_t mode;
3007         cmdline_fixed_string_t proto;
3008         cmdline_fixed_string_t hwsw;
3009         uint8_t port_id;
3010 };
3011
3012 static void
3013 csum_show(int port_id)
3014 {
3015         struct rte_eth_dev_info dev_info;
3016         uint16_t ol_flags;
3017
3018         ol_flags = ports[port_id].tx_ol_flags;
3019         printf("Parse tunnel is %s\n",
3020                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3021         printf("IP checksum offload is %s\n",
3022                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3023         printf("UDP checksum offload is %s\n",
3024                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3025         printf("TCP checksum offload is %s\n",
3026                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3027         printf("SCTP checksum offload is %s\n",
3028                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3029         printf("Outer-Ip checksum offload is %s\n",
3030                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3031
3032         /* display warnings if configuration is not supported by the NIC */
3033         rte_eth_dev_info_get(port_id, &dev_info);
3034         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3035                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3036                 printf("Warning: hardware IP checksum enabled but not "
3037                         "supported by port %d\n", port_id);
3038         }
3039         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3040                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3041                 printf("Warning: hardware UDP checksum enabled but not "
3042                         "supported by port %d\n", port_id);
3043         }
3044         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3045                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3046                 printf("Warning: hardware TCP checksum enabled but not "
3047                         "supported by port %d\n", port_id);
3048         }
3049         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3050                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3051                 printf("Warning: hardware SCTP checksum enabled but not "
3052                         "supported by port %d\n", port_id);
3053         }
3054         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3055                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3056                 printf("Warning: hardware outer IP checksum enabled but not "
3057                         "supported by port %d\n", port_id);
3058         }
3059 }
3060
3061 static void
3062 cmd_csum_parsed(void *parsed_result,
3063                        __attribute__((unused)) struct cmdline *cl,
3064                        __attribute__((unused)) void *data)
3065 {
3066         struct cmd_csum_result *res = parsed_result;
3067         int hw = 0;
3068         uint16_t mask = 0;
3069
3070         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3071                 printf("invalid port %d\n", res->port_id);
3072                 return;
3073         }
3074
3075         if (!strcmp(res->mode, "set")) {
3076
3077                 if (!strcmp(res->hwsw, "hw"))
3078                         hw = 1;
3079
3080                 if (!strcmp(res->proto, "ip")) {
3081                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3082                 } else if (!strcmp(res->proto, "udp")) {
3083                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3084                 } else if (!strcmp(res->proto, "tcp")) {
3085                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3086                 } else if (!strcmp(res->proto, "sctp")) {
3087                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3088                 } else if (!strcmp(res->proto, "outer-ip")) {
3089                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3090                 }
3091
3092                 if (hw)
3093                         ports[res->port_id].tx_ol_flags |= mask;
3094                 else
3095                         ports[res->port_id].tx_ol_flags &= (~mask);
3096         }
3097         csum_show(res->port_id);
3098 }
3099
3100 cmdline_parse_token_string_t cmd_csum_csum =
3101         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3102                                 csum, "csum");
3103 cmdline_parse_token_string_t cmd_csum_mode =
3104         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3105                                 mode, "set");
3106 cmdline_parse_token_string_t cmd_csum_proto =
3107         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3108                                 proto, "ip#tcp#udp#sctp#outer-ip");
3109 cmdline_parse_token_string_t cmd_csum_hwsw =
3110         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3111                                 hwsw, "hw#sw");
3112 cmdline_parse_token_num_t cmd_csum_portid =
3113         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3114                                 port_id, UINT8);
3115
3116 cmdline_parse_inst_t cmd_csum_set = {
3117         .f = cmd_csum_parsed,
3118         .data = NULL,
3119         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
3120                 "using csum forward engine: csum set ip|tcp|udp|sctp|outer-ip hw|sw <port>",
3121         .tokens = {
3122                 (void *)&cmd_csum_csum,
3123                 (void *)&cmd_csum_mode,
3124                 (void *)&cmd_csum_proto,
3125                 (void *)&cmd_csum_hwsw,
3126                 (void *)&cmd_csum_portid,
3127                 NULL,
3128         },
3129 };
3130
3131 cmdline_parse_token_string_t cmd_csum_mode_show =
3132         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3133                                 mode, "show");
3134
3135 cmdline_parse_inst_t cmd_csum_show = {
3136         .f = cmd_csum_parsed,
3137         .data = NULL,
3138         .help_str = "show checksum offload configuration: csum show <port>",
3139         .tokens = {
3140                 (void *)&cmd_csum_csum,
3141                 (void *)&cmd_csum_mode_show,
3142                 (void *)&cmd_csum_portid,
3143                 NULL,
3144         },
3145 };
3146
3147 /* Enable/disable tunnel parsing */
3148 struct cmd_csum_tunnel_result {
3149         cmdline_fixed_string_t csum;
3150         cmdline_fixed_string_t parse;
3151         cmdline_fixed_string_t onoff;
3152         uint8_t port_id;
3153 };
3154
3155 static void
3156 cmd_csum_tunnel_parsed(void *parsed_result,
3157                        __attribute__((unused)) struct cmdline *cl,
3158                        __attribute__((unused)) void *data)
3159 {
3160         struct cmd_csum_tunnel_result *res = parsed_result;
3161
3162         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3163                 return;
3164
3165         if (!strcmp(res->onoff, "on"))
3166                 ports[res->port_id].tx_ol_flags |=
3167                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3168         else
3169                 ports[res->port_id].tx_ol_flags &=
3170                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3171
3172         csum_show(res->port_id);
3173 }
3174
3175 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3176         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3177                                 csum, "csum");
3178 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3179         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3180                                 parse, "parse_tunnel");
3181 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3182         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3183                                 onoff, "on#off");
3184 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3185         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3186                                 port_id, UINT8);
3187
3188 cmdline_parse_inst_t cmd_csum_tunnel = {
3189         .f = cmd_csum_tunnel_parsed,
3190         .data = NULL,
3191         .help_str = "enable/disable parsing of tunnels for csum engine: "
3192         "csum parse_tunnel on|off <tx-port>",
3193         .tokens = {
3194                 (void *)&cmd_csum_tunnel_csum,
3195                 (void *)&cmd_csum_tunnel_parse,
3196                 (void *)&cmd_csum_tunnel_onoff,
3197                 (void *)&cmd_csum_tunnel_portid,
3198                 NULL,
3199         },
3200 };
3201
3202 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3203 struct cmd_tso_set_result {
3204         cmdline_fixed_string_t tso;
3205         cmdline_fixed_string_t mode;
3206         uint16_t tso_segsz;
3207         uint8_t port_id;
3208 };
3209
3210 static void
3211 cmd_tso_set_parsed(void *parsed_result,
3212                        __attribute__((unused)) struct cmdline *cl,
3213                        __attribute__((unused)) void *data)
3214 {
3215         struct cmd_tso_set_result *res = parsed_result;
3216         struct rte_eth_dev_info dev_info;
3217
3218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3219                 return;
3220
3221         if (!strcmp(res->mode, "set"))
3222                 ports[res->port_id].tso_segsz = res->tso_segsz;
3223
3224         if (ports[res->port_id].tso_segsz == 0)
3225                 printf("TSO is disabled\n");
3226         else
3227                 printf("TSO segment size is %d\n",
3228                         ports[res->port_id].tso_segsz);
3229
3230         /* display warnings if configuration is not supported by the NIC */
3231         rte_eth_dev_info_get(res->port_id, &dev_info);
3232         if ((ports[res->port_id].tso_segsz != 0) &&
3233                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3234                 printf("Warning: TSO enabled but not "
3235                         "supported by port %d\n", res->port_id);
3236         }
3237 }
3238
3239 cmdline_parse_token_string_t cmd_tso_set_tso =
3240         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3241                                 tso, "tso");
3242 cmdline_parse_token_string_t cmd_tso_set_mode =
3243         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3244                                 mode, "set");
3245 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3246         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3247                                 tso_segsz, UINT16);
3248 cmdline_parse_token_num_t cmd_tso_set_portid =
3249         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3250                                 port_id, UINT8);
3251
3252 cmdline_parse_inst_t cmd_tso_set = {
3253         .f = cmd_tso_set_parsed,
3254         .data = NULL,
3255         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3256         "tso set <tso_segsz> <port>",
3257         .tokens = {
3258                 (void *)&cmd_tso_set_tso,
3259                 (void *)&cmd_tso_set_mode,
3260                 (void *)&cmd_tso_set_tso_segsz,
3261                 (void *)&cmd_tso_set_portid,
3262                 NULL,
3263         },
3264 };
3265
3266 cmdline_parse_token_string_t cmd_tso_show_mode =
3267         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3268                                 mode, "show");
3269
3270
3271 cmdline_parse_inst_t cmd_tso_show = {
3272         .f = cmd_tso_set_parsed,
3273         .data = NULL,
3274         .help_str = "Show TSO segment size for csum engine: "
3275         "tso show <port>",
3276         .tokens = {
3277                 (void *)&cmd_tso_set_tso,
3278                 (void *)&cmd_tso_show_mode,
3279                 (void *)&cmd_tso_set_portid,
3280                 NULL,
3281         },
3282 };
3283
3284 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3285 struct cmd_set_flush_rx {
3286         cmdline_fixed_string_t set;
3287         cmdline_fixed_string_t flush_rx;
3288         cmdline_fixed_string_t mode;
3289 };
3290
3291 static void
3292 cmd_set_flush_rx_parsed(void *parsed_result,
3293                 __attribute__((unused)) struct cmdline *cl,
3294                 __attribute__((unused)) void *data)
3295 {
3296         struct cmd_set_flush_rx *res = parsed_result;
3297         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3298 }
3299
3300 cmdline_parse_token_string_t cmd_setflushrx_set =
3301         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3302                         set, "set");
3303 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3304         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3305                         flush_rx, "flush_rx");
3306 cmdline_parse_token_string_t cmd_setflushrx_mode =
3307         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3308                         mode, "on#off");
3309
3310
3311 cmdline_parse_inst_t cmd_set_flush_rx = {
3312         .f = cmd_set_flush_rx_parsed,
3313         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3314         .data = NULL,
3315         .tokens = {
3316                 (void *)&cmd_setflushrx_set,
3317                 (void *)&cmd_setflushrx_flush_rx,
3318                 (void *)&cmd_setflushrx_mode,
3319                 NULL,
3320         },
3321 };
3322
3323 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3324 struct cmd_set_link_check {
3325         cmdline_fixed_string_t set;
3326         cmdline_fixed_string_t link_check;
3327         cmdline_fixed_string_t mode;
3328 };
3329
3330 static void
3331 cmd_set_link_check_parsed(void *parsed_result,
3332                 __attribute__((unused)) struct cmdline *cl,
3333                 __attribute__((unused)) void *data)
3334 {
3335         struct cmd_set_link_check *res = parsed_result;
3336         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3337 }
3338
3339 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3340         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3341                         set, "set");
3342 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3343         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3344                         link_check, "link_check");
3345 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3346         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3347                         mode, "on#off");
3348
3349
3350 cmdline_parse_inst_t cmd_set_link_check = {
3351         .f = cmd_set_link_check_parsed,
3352         .help_str = "set link_check on|off: enable/disable link status check "
3353                     "when starting/stopping a port",
3354         .data = NULL,
3355         .tokens = {
3356                 (void *)&cmd_setlinkcheck_set,
3357                 (void *)&cmd_setlinkcheck_link_check,
3358                 (void *)&cmd_setlinkcheck_mode,
3359                 NULL,
3360         },
3361 };
3362
3363 #ifdef RTE_NIC_BYPASS
3364 /* *** SET NIC BYPASS MODE *** */
3365 struct cmd_set_bypass_mode_result {
3366         cmdline_fixed_string_t set;
3367         cmdline_fixed_string_t bypass;
3368         cmdline_fixed_string_t mode;
3369         cmdline_fixed_string_t value;
3370         uint8_t port_id;
3371 };
3372
3373 static void
3374 cmd_set_bypass_mode_parsed(void *parsed_result,
3375                 __attribute__((unused)) struct cmdline *cl,
3376                 __attribute__((unused)) void *data)
3377 {
3378         struct cmd_set_bypass_mode_result *res = parsed_result;
3379         portid_t port_id = res->port_id;
3380         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3381
3382         if (!bypass_is_supported(port_id))
3383                 return;
3384
3385         if (!strcmp(res->value, "bypass"))
3386                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3387         else if (!strcmp(res->value, "isolate"))
3388                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3389         else
3390                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3391
3392         /* Set the bypass mode for the relevant port. */
3393         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3394                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3395         }
3396 }
3397
3398 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3399         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3400                         set, "set");
3401 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3402         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3403                         bypass, "bypass");
3404 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3405         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3406                         mode, "mode");
3407 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3408         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3409                         value, "normal#bypass#isolate");
3410 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3411         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3412                                 port_id, UINT8);
3413
3414 cmdline_parse_inst_t cmd_set_bypass_mode = {
3415         .f = cmd_set_bypass_mode_parsed,
3416         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3417                     "Set the NIC bypass mode for port_id",
3418         .data = NULL,
3419         .tokens = {
3420                 (void *)&cmd_setbypass_mode_set,
3421                 (void *)&cmd_setbypass_mode_bypass,
3422                 (void *)&cmd_setbypass_mode_mode,
3423                 (void *)&cmd_setbypass_mode_value,
3424                 (void *)&cmd_setbypass_mode_port,
3425                 NULL,
3426         },
3427 };
3428
3429 /* *** SET NIC BYPASS EVENT *** */
3430 struct cmd_set_bypass_event_result {
3431         cmdline_fixed_string_t set;
3432         cmdline_fixed_string_t bypass;
3433         cmdline_fixed_string_t event;
3434         cmdline_fixed_string_t event_value;
3435         cmdline_fixed_string_t mode;
3436         cmdline_fixed_string_t mode_value;
3437         uint8_t port_id;
3438 };
3439
3440 static void
3441 cmd_set_bypass_event_parsed(void *parsed_result,
3442                 __attribute__((unused)) struct cmdline *cl,
3443                 __attribute__((unused)) void *data)
3444 {
3445         int32_t rc;
3446         struct cmd_set_bypass_event_result *res = parsed_result;
3447         portid_t port_id = res->port_id;
3448         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3449         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3450
3451         if (!bypass_is_supported(port_id))
3452                 return;
3453
3454         if (!strcmp(res->event_value, "timeout"))
3455                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3456         else if (!strcmp(res->event_value, "os_on"))
3457                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3458         else if (!strcmp(res->event_value, "os_off"))
3459                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3460         else if (!strcmp(res->event_value, "power_on"))
3461                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3462         else if (!strcmp(res->event_value, "power_off"))
3463                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3464         else
3465                 bypass_event = RTE_BYPASS_EVENT_NONE;
3466
3467         if (!strcmp(res->mode_value, "bypass"))
3468                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3469         else if (!strcmp(res->mode_value, "isolate"))
3470                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3471         else
3472                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3473
3474         /* Set the watchdog timeout. */
3475         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3476
3477                 rc = -EINVAL;
3478                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3479                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3480                                 bypass_timeout)) != 0) {
3481                         printf("Failed to set timeout value %u "
3482                                 "for port %d, errto code: %d.\n",
3483                                 bypass_timeout, port_id, rc);
3484                 }
3485         }
3486
3487         /* Set the bypass event to transition to bypass mode. */
3488         if (0 != rte_eth_dev_bypass_event_store(port_id,
3489                         bypass_event, bypass_mode)) {
3490                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3491         }
3492
3493 }
3494
3495 cmdline_parse_token_string_t cmd_setbypass_event_set =
3496         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3497                         set, "set");
3498 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3499         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3500                         bypass, "bypass");
3501 cmdline_parse_token_string_t cmd_setbypass_event_event =
3502         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3503                         event, "event");
3504 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3505         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3506                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3507 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3508         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3509                         mode, "mode");
3510 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3511         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3512                         mode_value, "normal#bypass#isolate");
3513 cmdline_parse_token_num_t cmd_setbypass_event_port =
3514         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3515                                 port_id, UINT8);
3516
3517 cmdline_parse_inst_t cmd_set_bypass_event = {
3518         .f = cmd_set_bypass_event_parsed,
3519         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3520                     "mode (normal|bypass|isolate) (port_id): "
3521                     "Set the NIC bypass event mode for port_id",
3522         .data = NULL,
3523         .tokens = {
3524                 (void *)&cmd_setbypass_event_set,
3525                 (void *)&cmd_setbypass_event_bypass,
3526                 (void *)&cmd_setbypass_event_event,
3527                 (void *)&cmd_setbypass_event_event_value,
3528                 (void *)&cmd_setbypass_event_mode,
3529                 (void *)&cmd_setbypass_event_mode_value,
3530                 (void *)&cmd_setbypass_event_port,
3531                 NULL,
3532         },
3533 };
3534
3535
3536 /* *** SET NIC BYPASS TIMEOUT *** */
3537 struct cmd_set_bypass_timeout_result {
3538         cmdline_fixed_string_t set;
3539         cmdline_fixed_string_t bypass;
3540         cmdline_fixed_string_t timeout;
3541         cmdline_fixed_string_t value;
3542 };
3543
3544 static void
3545 cmd_set_bypass_timeout_parsed(void *parsed_result,
3546                 __attribute__((unused)) struct cmdline *cl,
3547                 __attribute__((unused)) void *data)
3548 {
3549         struct cmd_set_bypass_timeout_result *res = parsed_result;
3550
3551         if (!strcmp(res->value, "1.5"))
3552                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3553         else if (!strcmp(res->value, "2"))
3554                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3555         else if (!strcmp(res->value, "3"))
3556                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3557         else if (!strcmp(res->value, "4"))
3558                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3559         else if (!strcmp(res->value, "8"))
3560                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3561         else if (!strcmp(res->value, "16"))
3562                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3563         else if (!strcmp(res->value, "32"))
3564                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3565         else
3566                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3567 }
3568
3569 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3571                         set, "set");
3572 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3573         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3574                         bypass, "bypass");
3575 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3576         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3577                         timeout, "timeout");
3578 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3579         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3580                         value, "0#1.5#2#3#4#8#16#32");
3581
3582 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3583         .f = cmd_set_bypass_timeout_parsed,
3584         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3585                     "Set the NIC bypass watchdog timeout",
3586         .data = NULL,
3587         .tokens = {
3588                 (void *)&cmd_setbypass_timeout_set,
3589                 (void *)&cmd_setbypass_timeout_bypass,
3590                 (void *)&cmd_setbypass_timeout_timeout,
3591                 (void *)&cmd_setbypass_timeout_value,
3592                 NULL,
3593         },
3594 };
3595
3596 /* *** SHOW NIC BYPASS MODE *** */
3597 struct cmd_show_bypass_config_result {
3598         cmdline_fixed_string_t show;
3599         cmdline_fixed_string_t bypass;
3600         cmdline_fixed_string_t config;
3601         uint8_t port_id;
3602 };
3603
3604 static void
3605 cmd_show_bypass_config_parsed(void *parsed_result,
3606                 __attribute__((unused)) struct cmdline *cl,
3607                 __attribute__((unused)) void *data)
3608 {
3609         struct cmd_show_bypass_config_result *res = parsed_result;
3610         uint32_t event_mode;
3611         uint32_t bypass_mode;
3612         portid_t port_id = res->port_id;
3613         uint32_t timeout = bypass_timeout;
3614         int i;
3615
3616         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3617                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3618         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3619                 {"UNKNOWN", "normal", "bypass", "isolate"};
3620         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3621                 "NONE",
3622                 "OS/board on",
3623                 "power supply on",
3624                 "OS/board off",
3625                 "power supply off",
3626                 "timeout"};
3627         int num_events = (sizeof events) / (sizeof events[0]);
3628
3629         if (!bypass_is_supported(port_id))
3630                 return;
3631
3632         /* Display the bypass mode.*/
3633         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3634                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3635                 return;
3636         }
3637         else {
3638                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3639                         bypass_mode = RTE_BYPASS_MODE_NONE;
3640
3641                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3642         }
3643
3644         /* Display the bypass timeout.*/
3645         if (!RTE_BYPASS_TMT_VALID(timeout))
3646                 timeout = RTE_BYPASS_TMT_OFF;
3647
3648         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3649
3650         /* Display the bypass events and associated modes. */
3651         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3652
3653                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3654                         printf("\tFailed to get bypass mode for event = %s\n",
3655                                 events[i]);
3656                 } else {
3657                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3658                                 event_mode = RTE_BYPASS_MODE_NONE;
3659
3660                         printf("\tbypass event: %-16s = %s\n", events[i],
3661                                 modes[event_mode]);
3662                 }
3663         }
3664 }
3665
3666 cmdline_parse_token_string_t cmd_showbypass_config_show =
3667         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3668                         show, "show");
3669 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3670         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3671                         bypass, "bypass");
3672 cmdline_parse_token_string_t cmd_showbypass_config_config =
3673         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3674                         config, "config");
3675 cmdline_parse_token_num_t cmd_showbypass_config_port =
3676         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3677                                 port_id, UINT8);
3678
3679 cmdline_parse_inst_t cmd_show_bypass_config = {
3680         .f = cmd_show_bypass_config_parsed,
3681         .help_str = "show bypass config (port_id): "
3682                     "Show the NIC bypass config for port_id",
3683         .data = NULL,
3684         .tokens = {
3685                 (void *)&cmd_showbypass_config_show,
3686                 (void *)&cmd_showbypass_config_bypass,
3687                 (void *)&cmd_showbypass_config_config,
3688                 (void *)&cmd_showbypass_config_port,
3689                 NULL,
3690         },
3691 };
3692 #endif
3693
3694 #ifdef RTE_LIBRTE_PMD_BOND
3695 /* *** SET BONDING MODE *** */
3696 struct cmd_set_bonding_mode_result {
3697         cmdline_fixed_string_t set;
3698         cmdline_fixed_string_t bonding;
3699         cmdline_fixed_string_t mode;
3700         uint8_t value;
3701         uint8_t port_id;
3702 };
3703
3704 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3705                 __attribute__((unused))  struct cmdline *cl,
3706                 __attribute__((unused)) void *data)
3707 {
3708         struct cmd_set_bonding_mode_result *res = parsed_result;
3709         portid_t port_id = res->port_id;
3710
3711         /* Set the bonding mode for the relevant port. */
3712         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3713                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3714 }
3715
3716 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3717 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3718                 set, "set");
3719 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3720 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3721                 bonding, "bonding");
3722 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3724                 mode, "mode");
3725 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3726 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3727                 value, UINT8);
3728 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3729 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3730                 port_id, UINT8);
3731
3732 cmdline_parse_inst_t cmd_set_bonding_mode = {
3733                 .f = cmd_set_bonding_mode_parsed,
3734                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3735                 .data = NULL,
3736                 .tokens = {
3737                                 (void *) &cmd_setbonding_mode_set,
3738                                 (void *) &cmd_setbonding_mode_bonding,
3739                                 (void *) &cmd_setbonding_mode_mode,
3740                                 (void *) &cmd_setbonding_mode_value,
3741                                 (void *) &cmd_setbonding_mode_port,
3742                                 NULL
3743                 }
3744 };
3745
3746 /* *** SET BALANCE XMIT POLICY *** */
3747 struct cmd_set_bonding_balance_xmit_policy_result {
3748         cmdline_fixed_string_t set;
3749         cmdline_fixed_string_t bonding;
3750         cmdline_fixed_string_t balance_xmit_policy;
3751         uint8_t port_id;
3752         cmdline_fixed_string_t policy;
3753 };
3754
3755 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3756                 __attribute__((unused))  struct cmdline *cl,
3757                 __attribute__((unused)) void *data)
3758 {
3759         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3760         portid_t port_id = res->port_id;
3761         uint8_t policy;
3762
3763         if (!strcmp(res->policy, "l2")) {
3764                 policy = BALANCE_XMIT_POLICY_LAYER2;
3765         } else if (!strcmp(res->policy, "l23")) {
3766                 policy = BALANCE_XMIT_POLICY_LAYER23;
3767         } else if (!strcmp(res->policy, "l34")) {
3768                 policy = BALANCE_XMIT_POLICY_LAYER34;
3769         } else {
3770                 printf("\t Invalid xmit policy selection");
3771                 return;
3772         }
3773
3774         /* Set the bonding mode for the relevant port. */
3775         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3776                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3777                                 port_id);
3778         }
3779 }
3780
3781 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3783                 set, "set");
3784 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3785 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3786                 bonding, "bonding");
3787 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3788 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3789                 balance_xmit_policy, "balance_xmit_policy");
3790 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3791 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3792                 port_id, UINT8);
3793 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3794 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3795                 policy, "l2#l23#l34");
3796
3797 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3798                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3799                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3800                 .data = NULL,
3801                 .tokens = {
3802                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3803                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3804                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3805                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3806                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3807                                 NULL
3808                 }
3809 };
3810
3811 /* *** SHOW NIC BONDING CONFIGURATION *** */
3812 struct cmd_show_bonding_config_result {
3813         cmdline_fixed_string_t show;
3814         cmdline_fixed_string_t bonding;
3815         cmdline_fixed_string_t config;
3816         uint8_t port_id;
3817 };
3818
3819 static void cmd_show_bonding_config_parsed(void *parsed_result,
3820                 __attribute__((unused))  struct cmdline *cl,
3821                 __attribute__((unused)) void *data)
3822 {
3823         struct cmd_show_bonding_config_result *res = parsed_result;
3824         int bonding_mode;
3825         uint8_t slaves[RTE_MAX_ETHPORTS];
3826         int num_slaves, num_active_slaves;
3827         int primary_id;
3828         int i;
3829         portid_t port_id = res->port_id;
3830
3831         /* Display the bonding mode.*/
3832         bonding_mode = rte_eth_bond_mode_get(port_id);
3833         if (bonding_mode < 0) {
3834                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3835                 return;
3836         } else
3837                 printf("\tBonding mode: %d\n", bonding_mode);
3838
3839         if (bonding_mode == BONDING_MODE_BALANCE) {
3840                 int balance_xmit_policy;
3841
3842                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3843                 if (balance_xmit_policy < 0) {
3844                         printf("\tFailed to get balance xmit policy for port = %d\n",
3845                                         port_id);
3846                         return;
3847                 } else {
3848                         printf("\tBalance Xmit Policy: ");
3849
3850                         switch (balance_xmit_policy) {
3851                         case BALANCE_XMIT_POLICY_LAYER2:
3852                                 printf("BALANCE_XMIT_POLICY_LAYER2");
3853                                 break;
3854                         case BALANCE_XMIT_POLICY_LAYER23:
3855                                 printf("BALANCE_XMIT_POLICY_LAYER23");
3856                                 break;
3857                         case BALANCE_XMIT_POLICY_LAYER34:
3858                                 printf("BALANCE_XMIT_POLICY_LAYER34");
3859                                 break;
3860                         }
3861                         printf("\n");
3862                 }
3863         }
3864
3865         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
3866
3867         if (num_slaves < 0) {
3868                 printf("\tFailed to get slave list for port = %d\n", port_id);
3869                 return;
3870         }
3871         if (num_slaves > 0) {
3872                 printf("\tSlaves (%d): [", num_slaves);
3873                 for (i = 0; i < num_slaves - 1; i++)
3874                         printf("%d ", slaves[i]);
3875
3876                 printf("%d]\n", slaves[num_slaves - 1]);
3877         } else {
3878                 printf("\tSlaves: []\n");
3879
3880         }
3881
3882         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
3883                         RTE_MAX_ETHPORTS);
3884
3885         if (num_active_slaves < 0) {
3886                 printf("\tFailed to get active slave list for port = %d\n", port_id);
3887                 return;
3888         }
3889         if (num_active_slaves > 0) {
3890                 printf("\tActive Slaves (%d): [", num_active_slaves);
3891                 for (i = 0; i < num_active_slaves - 1; i++)
3892                         printf("%d ", slaves[i]);
3893
3894                 printf("%d]\n", slaves[num_active_slaves - 1]);
3895
3896         } else {
3897                 printf("\tActive Slaves: []\n");
3898
3899         }
3900
3901         primary_id = rte_eth_bond_primary_get(port_id);
3902         if (primary_id < 0) {
3903                 printf("\tFailed to get primary slave for port = %d\n", port_id);
3904                 return;
3905         } else
3906                 printf("\tPrimary: [%d]\n", primary_id);
3907
3908 }
3909
3910 cmdline_parse_token_string_t cmd_showbonding_config_show =
3911 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3912                 show, "show");
3913 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
3914 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3915                 bonding, "bonding");
3916 cmdline_parse_token_string_t cmd_showbonding_config_config =
3917 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
3918                 config, "config");
3919 cmdline_parse_token_num_t cmd_showbonding_config_port =
3920 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
3921                 port_id, UINT8);
3922
3923 cmdline_parse_inst_t cmd_show_bonding_config = {
3924                 .f = cmd_show_bonding_config_parsed,
3925                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
3926                 .data = NULL,
3927                 .tokens = {
3928                                 (void *)&cmd_showbonding_config_show,
3929                                 (void *)&cmd_showbonding_config_bonding,
3930                                 (void *)&cmd_showbonding_config_config,
3931                                 (void *)&cmd_showbonding_config_port,
3932                                 NULL
3933                 }
3934 };
3935
3936 /* *** SET BONDING PRIMARY *** */
3937 struct cmd_set_bonding_primary_result {
3938         cmdline_fixed_string_t set;
3939         cmdline_fixed_string_t bonding;
3940         cmdline_fixed_string_t primary;
3941         uint8_t slave_id;
3942         uint8_t port_id;
3943 };
3944
3945 static void cmd_set_bonding_primary_parsed(void *parsed_result,
3946                 __attribute__((unused))  struct cmdline *cl,
3947                 __attribute__((unused)) void *data)
3948 {
3949         struct cmd_set_bonding_primary_result *res = parsed_result;
3950         portid_t master_port_id = res->port_id;
3951         portid_t slave_port_id = res->slave_id;
3952
3953         /* Set the primary slave for a bonded device. */
3954         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
3955                 printf("\t Failed to set primary slave for port = %d.\n",
3956                                 master_port_id);
3957                 return;
3958         }
3959         init_port_config();
3960 }
3961
3962 cmdline_parse_token_string_t cmd_setbonding_primary_set =
3963 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3964                 set, "set");
3965 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
3966 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3967                 bonding, "bonding");
3968 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
3969 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
3970                 primary, "primary");
3971 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
3972 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3973                 slave_id, UINT8);
3974 cmdline_parse_token_num_t cmd_setbonding_primary_port =
3975 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
3976                 port_id, UINT8);
3977
3978 cmdline_parse_inst_t cmd_set_bonding_primary = {
3979                 .f = cmd_set_bonding_primary_parsed,
3980                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
3981                 .data = NULL,
3982                 .tokens = {
3983                                 (void *)&cmd_setbonding_primary_set,
3984                                 (void *)&cmd_setbonding_primary_bonding,
3985                                 (void *)&cmd_setbonding_primary_primary,
3986                                 (void *)&cmd_setbonding_primary_slave,
3987                                 (void *)&cmd_setbonding_primary_port,
3988                                 NULL
3989                 }
3990 };
3991
3992 /* *** ADD SLAVE *** */
3993 struct cmd_add_bonding_slave_result {
3994         cmdline_fixed_string_t add;
3995         cmdline_fixed_string_t bonding;
3996         cmdline_fixed_string_t slave;
3997         uint8_t slave_id;
3998         uint8_t port_id;
3999 };
4000
4001 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4002                 __attribute__((unused))  struct cmdline *cl,
4003                 __attribute__((unused)) void *data)
4004 {
4005         struct cmd_add_bonding_slave_result *res = parsed_result;
4006         portid_t master_port_id = res->port_id;
4007         portid_t slave_port_id = res->slave_id;
4008
4009         /* Set the primary slave for a bonded device. */
4010         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4011                 printf("\t Failed to add slave %d to master port = %d.\n",
4012                                 slave_port_id, master_port_id);
4013                 return;
4014         }
4015         init_port_config();
4016 }
4017
4018 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4019 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4020                 add, "add");
4021 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4022 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4023                 bonding, "bonding");
4024 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4025 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4026                 slave, "slave");
4027 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4028 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4029                 slave_id, UINT8);
4030 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4031 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4032                 port_id, UINT8);
4033
4034 cmdline_parse_inst_t cmd_add_bonding_slave = {
4035                 .f = cmd_add_bonding_slave_parsed,
4036                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4037                 .data = NULL,
4038                 .tokens = {
4039                                 (void *)&cmd_addbonding_slave_add,
4040                                 (void *)&cmd_addbonding_slave_bonding,
4041                                 (void *)&cmd_addbonding_slave_slave,
4042                                 (void *)&cmd_addbonding_slave_slaveid,
4043                                 (void *)&cmd_addbonding_slave_port,
4044                                 NULL
4045                 }
4046 };
4047
4048 /* *** REMOVE SLAVE *** */
4049 struct cmd_remove_bonding_slave_result {
4050         cmdline_fixed_string_t remove;
4051         cmdline_fixed_string_t bonding;
4052         cmdline_fixed_string_t slave;
4053         uint8_t slave_id;
4054         uint8_t port_id;
4055 };
4056
4057 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4058                 __attribute__((unused))  struct cmdline *cl,
4059                 __attribute__((unused)) void *data)
4060 {
4061         struct cmd_remove_bonding_slave_result *res = parsed_result;
4062         portid_t master_port_id = res->port_id;
4063         portid_t slave_port_id = res->slave_id;
4064
4065         /* Set the primary slave for a bonded device. */
4066         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4067                 printf("\t Failed to remove slave %d from master port = %d.\n",
4068                                 slave_port_id, master_port_id);
4069                 return;
4070         }
4071         init_port_config();
4072 }
4073
4074 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4075                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4076                                 remove, "remove");
4077 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4078                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4079                                 bonding, "bonding");
4080 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4081                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4082                                 slave, "slave");
4083 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4084                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4085                                 slave_id, UINT8);
4086 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4087                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4088                                 port_id, UINT8);
4089
4090 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4091                 .f = cmd_remove_bonding_slave_parsed,
4092                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4093                 .data = NULL,
4094                 .tokens = {
4095                                 (void *)&cmd_removebonding_slave_remove,
4096                                 (void *)&cmd_removebonding_slave_bonding,
4097                                 (void *)&cmd_removebonding_slave_slave,
4098                                 (void *)&cmd_removebonding_slave_slaveid,
4099                                 (void *)&cmd_removebonding_slave_port,
4100                                 NULL
4101                 }
4102 };
4103
4104 /* *** CREATE BONDED DEVICE *** */
4105 struct cmd_create_bonded_device_result {
4106         cmdline_fixed_string_t create;
4107         cmdline_fixed_string_t bonded;
4108         cmdline_fixed_string_t device;
4109         uint8_t mode;
4110         uint8_t socket;
4111 };
4112
4113 static int bond_dev_num = 0;
4114
4115 static void cmd_create_bonded_device_parsed(void *parsed_result,
4116                 __attribute__((unused))  struct cmdline *cl,
4117                 __attribute__((unused)) void *data)
4118 {
4119         struct cmd_create_bonded_device_result *res = parsed_result;
4120         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4121         int port_id;
4122
4123         if (test_done == 0) {
4124                 printf("Please stop forwarding first\n");
4125                 return;
4126         }
4127
4128         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
4129                         bond_dev_num++);
4130
4131         /* Create a new bonded device. */
4132         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4133         if (port_id < 0) {
4134                 printf("\t Failed to create bonded device.\n");
4135                 return;
4136         } else {
4137                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4138                                 port_id);
4139
4140                 /* Update number of ports */
4141                 nb_ports = rte_eth_dev_count();
4142                 reconfig(port_id, res->socket);
4143                 rte_eth_promiscuous_enable(port_id);
4144                 ports[port_id].enabled = 1;
4145         }
4146
4147 }
4148
4149 cmdline_parse_token_string_t cmd_createbonded_device_create =
4150                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4151                                 create, "create");
4152 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4153                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4154                                 bonded, "bonded");
4155 cmdline_parse_token_string_t cmd_createbonded_device_device =
4156                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4157                                 device, "device");
4158 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4159                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4160                                 mode, UINT8);
4161 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4162                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4163                                 socket, UINT8);
4164
4165 cmdline_parse_inst_t cmd_create_bonded_device = {
4166                 .f = cmd_create_bonded_device_parsed,
4167                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4168                 .data = NULL,
4169                 .tokens = {
4170                                 (void *)&cmd_createbonded_device_create,
4171                                 (void *)&cmd_createbonded_device_bonded,
4172                                 (void *)&cmd_createbonded_device_device,
4173                                 (void *)&cmd_createbonded_device_mode,
4174                                 (void *)&cmd_createbonded_device_socket,
4175                                 NULL
4176                 }
4177 };
4178
4179 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4180 struct cmd_set_bond_mac_addr_result {
4181         cmdline_fixed_string_t set;
4182         cmdline_fixed_string_t bonding;
4183         cmdline_fixed_string_t mac_addr;
4184         uint8_t port_num;
4185         struct ether_addr address;
4186 };
4187
4188 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4189                 __attribute__((unused))  struct cmdline *cl,
4190                 __attribute__((unused)) void *data)
4191 {
4192         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4193         int ret;
4194
4195         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4196                 return;
4197
4198         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4199
4200         /* check the return value and print it if is < 0 */
4201         if (ret < 0)
4202                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4203 }
4204
4205 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4206                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4207 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4208                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4209                                 "bonding");
4210 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4211                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4212                                 "mac_addr");
4213 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4214                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4215 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4216                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4217
4218 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4219                 .f = cmd_set_bond_mac_addr_parsed,
4220                 .data = (void *) 0,
4221                 .help_str = "set bonding mac_addr (port_id) (address): ",
4222                 .tokens = {
4223                                 (void *)&cmd_set_bond_mac_addr_set,
4224                                 (void *)&cmd_set_bond_mac_addr_bonding,
4225                                 (void *)&cmd_set_bond_mac_addr_mac,
4226                                 (void *)&cmd_set_bond_mac_addr_portnum,
4227                                 (void *)&cmd_set_bond_mac_addr_addr,
4228                                 NULL
4229                 }
4230 };
4231
4232
4233 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4234 struct cmd_set_bond_mon_period_result {
4235         cmdline_fixed_string_t set;
4236         cmdline_fixed_string_t bonding;
4237         cmdline_fixed_string_t mon_period;
4238         uint8_t port_num;
4239         uint32_t period_ms;
4240 };
4241
4242 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4243                 __attribute__((unused))  struct cmdline *cl,
4244                 __attribute__((unused)) void *data)
4245 {
4246         struct cmd_set_bond_mon_period_result *res = parsed_result;
4247         int ret;
4248
4249         if (res->port_num >= nb_ports) {
4250                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4251                 return;
4252         }
4253
4254         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4255
4256         /* check the return value and print it if is < 0 */
4257         if (ret < 0)
4258                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4259 }
4260
4261 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4262                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4263                                 set, "set");
4264 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4265                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4266                                 bonding, "bonding");
4267 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4268                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4269                                 mon_period,     "mon_period");
4270 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4271                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4272                                 port_num, UINT8);
4273 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4274                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4275                                 period_ms, UINT32);
4276
4277 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4278                 .f = cmd_set_bond_mon_period_parsed,
4279                 .data = (void *) 0,
4280                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4281                 .tokens = {
4282                                 (void *)&cmd_set_bond_mon_period_set,
4283                                 (void *)&cmd_set_bond_mon_period_bonding,
4284                                 (void *)&cmd_set_bond_mon_period_mon_period,
4285                                 (void *)&cmd_set_bond_mon_period_portnum,
4286                                 (void *)&cmd_set_bond_mon_period_period_ms,
4287                                 NULL
4288                 }
4289 };
4290
4291 #endif /* RTE_LIBRTE_PMD_BOND */
4292
4293 /* *** SET FORWARDING MODE *** */
4294 struct cmd_set_fwd_mode_result {
4295         cmdline_fixed_string_t set;
4296         cmdline_fixed_string_t fwd;
4297         cmdline_fixed_string_t mode;
4298 };
4299
4300 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4301                                     __attribute__((unused)) struct cmdline *cl,
4302                                     __attribute__((unused)) void *data)
4303 {
4304         struct cmd_set_fwd_mode_result *res = parsed_result;
4305
4306         set_pkt_forwarding_mode(res->mode);
4307 }
4308
4309 cmdline_parse_token_string_t cmd_setfwd_set =
4310         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4311 cmdline_parse_token_string_t cmd_setfwd_fwd =
4312         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4313 cmdline_parse_token_string_t cmd_setfwd_mode =
4314         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4315                 "" /* defined at init */);
4316
4317 cmdline_parse_inst_t cmd_set_fwd_mode = {
4318         .f = cmd_set_fwd_mode_parsed,
4319         .data = NULL,
4320         .help_str = NULL, /* defined at init */
4321         .tokens = {
4322                 (void *)&cmd_setfwd_set,
4323                 (void *)&cmd_setfwd_fwd,
4324                 (void *)&cmd_setfwd_mode,
4325                 NULL,
4326         },
4327 };
4328
4329 static void cmd_set_fwd_mode_init(void)
4330 {
4331         char *modes, *c;
4332         static char token[128];
4333         static char help[256];
4334         cmdline_parse_token_string_t *token_struct;
4335
4336         modes = list_pkt_forwarding_modes();
4337         snprintf(help, sizeof help, "set fwd %s - "
4338                 "set packet forwarding mode", modes);
4339         cmd_set_fwd_mode.help_str = help;
4340
4341         /* string token separator is # */
4342         for (c = token; *modes != '\0'; modes++)
4343                 if (*modes == '|')
4344                         *c++ = '#';
4345                 else
4346                         *c++ = *modes;
4347         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4348         token_struct->string_data.str = token;
4349 }
4350
4351 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4352 struct cmd_set_burst_tx_retry_result {
4353         cmdline_fixed_string_t set;
4354         cmdline_fixed_string_t burst;
4355         cmdline_fixed_string_t tx;
4356         cmdline_fixed_string_t delay;
4357         uint32_t time;
4358         cmdline_fixed_string_t retry;
4359         uint32_t retry_num;
4360 };
4361
4362 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4363                                         __attribute__((unused)) struct cmdline *cl,
4364                                         __attribute__((unused)) void *data)
4365 {
4366         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4367
4368         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4369                 && !strcmp(res->tx, "tx")) {
4370                 if (!strcmp(res->delay, "delay"))
4371                         burst_tx_delay_time = res->time;
4372                 if (!strcmp(res->retry, "retry"))
4373                         burst_tx_retry_num = res->retry_num;
4374         }
4375
4376 }
4377
4378 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4379         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4380 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4381         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4382                                  "burst");
4383 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4384         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4385 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4386         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4387 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4388         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4389 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4390         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4391 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4392         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4393
4394 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4395         .f = cmd_set_burst_tx_retry_parsed,
4396         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4397         .tokens = {
4398                 (void *)&cmd_set_burst_tx_retry_set,
4399                 (void *)&cmd_set_burst_tx_retry_burst,
4400                 (void *)&cmd_set_burst_tx_retry_tx,
4401                 (void *)&cmd_set_burst_tx_retry_delay,
4402                 (void *)&cmd_set_burst_tx_retry_time,
4403                 (void *)&cmd_set_burst_tx_retry_retry,
4404                 (void *)&cmd_set_burst_tx_retry_retry_num,
4405                 NULL,
4406         },
4407 };
4408
4409 /* *** SET PROMISC MODE *** */
4410 struct cmd_set_promisc_mode_result {
4411         cmdline_fixed_string_t set;
4412         cmdline_fixed_string_t promisc;
4413         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4414         uint8_t port_num;                /* valid if "allports" argument == 0 */
4415         cmdline_fixed_string_t mode;
4416 };
4417
4418 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4419                                         __attribute__((unused)) struct cmdline *cl,
4420                                         void *allports)
4421 {
4422         struct cmd_set_promisc_mode_result *res = parsed_result;
4423         int enable;
4424         portid_t i;
4425
4426         if (!strcmp(res->mode, "on"))
4427                 enable = 1;
4428         else
4429                 enable = 0;
4430
4431         /* all ports */
4432         if (allports) {
4433                 FOREACH_PORT(i, ports) {
4434                         if (enable)
4435                                 rte_eth_promiscuous_enable(i);
4436                         else
4437                                 rte_eth_promiscuous_disable(i);
4438                 }
4439         }
4440         else {
4441                 if (enable)
4442                         rte_eth_promiscuous_enable(res->port_num);
4443                 else
4444                         rte_eth_promiscuous_disable(res->port_num);
4445         }
4446 }
4447
4448 cmdline_parse_token_string_t cmd_setpromisc_set =
4449         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4450 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4451         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4452                                  "promisc");
4453 cmdline_parse_token_string_t cmd_setpromisc_portall =
4454         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4455                                  "all");
4456 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4457         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4458                               UINT8);
4459 cmdline_parse_token_string_t cmd_setpromisc_mode =
4460         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4461                                  "on#off");
4462
4463 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4464         .f = cmd_set_promisc_mode_parsed,
4465         .data = (void *)1,
4466         .help_str = "set promisc all on|off: set promisc mode for all ports",
4467         .tokens = {
4468                 (void *)&cmd_setpromisc_set,
4469                 (void *)&cmd_setpromisc_promisc,
4470                 (void *)&cmd_setpromisc_portall,
4471                 (void *)&cmd_setpromisc_mode,
4472                 NULL,
4473         },
4474 };
4475
4476 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4477         .f = cmd_set_promisc_mode_parsed,
4478         .data = (void *)0,
4479         .help_str = "set promisc X on|off: set promisc mode on port X",
4480         .tokens = {
4481                 (void *)&cmd_setpromisc_set,
4482                 (void *)&cmd_setpromisc_promisc,
4483                 (void *)&cmd_setpromisc_portnum,
4484                 (void *)&cmd_setpromisc_mode,
4485                 NULL,
4486         },
4487 };
4488
4489 /* *** SET ALLMULTI MODE *** */
4490 struct cmd_set_allmulti_mode_result {
4491         cmdline_fixed_string_t set;
4492         cmdline_fixed_string_t allmulti;
4493         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4494         uint8_t port_num;                /* valid if "allports" argument == 0 */
4495         cmdline_fixed_string_t mode;
4496 };
4497
4498 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4499                                         __attribute__((unused)) struct cmdline *cl,
4500                                         void *allports)
4501 {
4502         struct cmd_set_allmulti_mode_result *res = parsed_result;
4503         int enable;
4504         portid_t i;
4505
4506         if (!strcmp(res->mode, "on"))
4507                 enable = 1;
4508         else
4509                 enable = 0;
4510
4511         /* all ports */
4512         if (allports) {
4513                 FOREACH_PORT(i, ports) {
4514                         if (enable)
4515                                 rte_eth_allmulticast_enable(i);
4516                         else
4517                                 rte_eth_allmulticast_disable(i);
4518                 }
4519         }
4520         else {
4521                 if (enable)
4522                         rte_eth_allmulticast_enable(res->port_num);
4523                 else
4524                         rte_eth_allmulticast_disable(res->port_num);
4525         }
4526 }
4527
4528 cmdline_parse_token_string_t cmd_setallmulti_set =
4529         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4530 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4531         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4532                                  "allmulti");
4533 cmdline_parse_token_string_t cmd_setallmulti_portall =
4534         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4535                                  "all");
4536 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4537         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4538                               UINT8);
4539 cmdline_parse_token_string_t cmd_setallmulti_mode =
4540         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4541                                  "on#off");
4542
4543 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4544         .f = cmd_set_allmulti_mode_parsed,
4545         .data = (void *)1,
4546         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4547         .tokens = {
4548                 (void *)&cmd_setallmulti_set,
4549                 (void *)&cmd_setallmulti_allmulti,
4550                 (void *)&cmd_setallmulti_portall,
4551                 (void *)&cmd_setallmulti_mode,
4552                 NULL,
4553         },
4554 };
4555
4556 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4557         .f = cmd_set_allmulti_mode_parsed,
4558         .data = (void *)0,
4559         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4560         .tokens = {
4561                 (void *)&cmd_setallmulti_set,
4562                 (void *)&cmd_setallmulti_allmulti,
4563                 (void *)&cmd_setallmulti_portnum,
4564                 (void *)&cmd_setallmulti_mode,
4565                 NULL,
4566         },
4567 };
4568
4569 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4570 struct cmd_link_flow_ctrl_set_result {
4571         cmdline_fixed_string_t set;
4572         cmdline_fixed_string_t flow_ctrl;
4573         cmdline_fixed_string_t rx;
4574         cmdline_fixed_string_t rx_lfc_mode;
4575         cmdline_fixed_string_t tx;
4576         cmdline_fixed_string_t tx_lfc_mode;
4577         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4578         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4579         cmdline_fixed_string_t autoneg_str;
4580         cmdline_fixed_string_t autoneg;
4581         cmdline_fixed_string_t hw_str;
4582         uint32_t high_water;
4583         cmdline_fixed_string_t lw_str;
4584         uint32_t low_water;
4585         cmdline_fixed_string_t pt_str;
4586         uint16_t pause_time;
4587         cmdline_fixed_string_t xon_str;
4588         uint16_t send_xon;
4589         uint8_t  port_id;
4590 };
4591
4592 cmdline_parse_token_string_t cmd_lfc_set_set =
4593         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4594                                 set, "set");
4595 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4596         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4597                                 flow_ctrl, "flow_ctrl");
4598 cmdline_parse_token_string_t cmd_lfc_set_rx =
4599         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4600                                 rx, "rx");
4601 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4602         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4603                                 rx_lfc_mode, "on#off");
4604 cmdline_parse_token_string_t cmd_lfc_set_tx =
4605         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4606                                 tx, "tx");
4607 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4608         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4609                                 tx_lfc_mode, "on#off");
4610 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4611         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4612                                 hw_str, "high_water");
4613 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4614         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4615                                 high_water, UINT32);
4616 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4617         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4618                                 lw_str, "low_water");
4619 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4620         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4621                                 low_water, UINT32);
4622 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4623         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4624                                 pt_str, "pause_time");
4625 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4626         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4627                                 pause_time, UINT16);
4628 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4629         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4630                                 xon_str, "send_xon");
4631 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4632         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4633                                 send_xon, UINT16);
4634 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4635         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4636                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4637 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4638         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4639                                 mac_ctrl_frame_fwd_mode, "on#off");
4640 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4641         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4642                                 autoneg_str, "autoneg");
4643 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4644         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4645                                 autoneg, "on#off");
4646 cmdline_parse_token_num_t cmd_lfc_set_portid =
4647         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4648                                 port_id, UINT8);
4649
4650 /* forward declaration */
4651 static void
4652 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4653                               void *data);
4654
4655 cmdline_parse_inst_t cmd_link_flow_control_set = {
4656         .f = cmd_link_flow_ctrl_set_parsed,
4657         .data = NULL,
4658         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4659 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4660 autoneg on|off port_id",
4661         .tokens = {
4662                 (void *)&cmd_lfc_set_set,
4663                 (void *)&cmd_lfc_set_flow_ctrl,
4664                 (void *)&cmd_lfc_set_rx,
4665                 (void *)&cmd_lfc_set_rx_mode,
4666                 (void *)&cmd_lfc_set_tx,
4667                 (void *)&cmd_lfc_set_tx_mode,
4668                 (void *)&cmd_lfc_set_high_water,
4669                 (void *)&cmd_lfc_set_low_water,
4670                 (void *)&cmd_lfc_set_pause_time,
4671                 (void *)&cmd_lfc_set_send_xon,
4672                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4673                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4674                 (void *)&cmd_lfc_set_autoneg_str,
4675                 (void *)&cmd_lfc_set_autoneg,
4676                 (void *)&cmd_lfc_set_portid,
4677                 NULL,
4678         },
4679 };
4680
4681 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4682         .f = cmd_link_flow_ctrl_set_parsed,
4683         .data = (void *)&cmd_link_flow_control_set_rx,
4684         .help_str = "Change rx flow control parameter: set flow_ctrl "
4685                     "rx on|off port_id",
4686         .tokens = {
4687                 (void *)&cmd_lfc_set_set,
4688                 (void *)&cmd_lfc_set_flow_ctrl,
4689                 (void *)&cmd_lfc_set_rx,
4690                 (void *)&cmd_lfc_set_rx_mode,
4691                 (void *)&cmd_lfc_set_portid,
4692                 NULL,
4693         },
4694 };
4695
4696 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4697         .f = cmd_link_flow_ctrl_set_parsed,
4698         .data = (void *)&cmd_link_flow_control_set_tx,
4699         .help_str = "Change tx flow control parameter: set flow_ctrl "
4700                     "tx on|off port_id",
4701         .tokens = {
4702                 (void *)&cmd_lfc_set_set,
4703                 (void *)&cmd_lfc_set_flow_ctrl,
4704                 (void *)&cmd_lfc_set_tx,
4705                 (void *)&cmd_lfc_set_tx_mode,
4706                 (void *)&cmd_lfc_set_portid,
4707                 NULL,
4708         },
4709 };
4710
4711 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
4712         .f = cmd_link_flow_ctrl_set_parsed,
4713         .data = (void *)&cmd_link_flow_control_set_hw,
4714         .help_str = "Change high water flow control parameter: set flow_ctrl "
4715                     "high_water value port_id",
4716         .tokens = {
4717                 (void *)&cmd_lfc_set_set,
4718                 (void *)&cmd_lfc_set_flow_ctrl,
4719                 (void *)&cmd_lfc_set_high_water_str,
4720                 (void *)&cmd_lfc_set_high_water,
4721                 (void *)&cmd_lfc_set_portid,
4722                 NULL,
4723         },
4724 };
4725
4726 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
4727         .f = cmd_link_flow_ctrl_set_parsed,
4728         .data = (void *)&cmd_link_flow_control_set_lw,
4729         .help_str = "Change low water flow control parameter: set flow_ctrl "
4730                     "low_water value port_id",
4731         .tokens = {
4732                 (void *)&cmd_lfc_set_set,
4733                 (void *)&cmd_lfc_set_flow_ctrl,
4734                 (void *)&cmd_lfc_set_low_water_str,
4735                 (void *)&cmd_lfc_set_low_water,
4736                 (void *)&cmd_lfc_set_portid,
4737                 NULL,
4738         },
4739 };
4740
4741 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
4742         .f = cmd_link_flow_ctrl_set_parsed,
4743         .data = (void *)&cmd_link_flow_control_set_pt,
4744         .help_str = "Change pause time flow control parameter: set flow_ctrl "
4745                     "pause_time value port_id",
4746         .tokens = {
4747                 (void *)&cmd_lfc_set_set,
4748                 (void *)&cmd_lfc_set_flow_ctrl,
4749                 (void *)&cmd_lfc_set_pause_time_str,
4750                 (void *)&cmd_lfc_set_pause_time,
4751                 (void *)&cmd_lfc_set_portid,
4752                 NULL,
4753         },
4754 };
4755
4756 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
4757         .f = cmd_link_flow_ctrl_set_parsed,
4758         .data = (void *)&cmd_link_flow_control_set_xon,
4759         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
4760                     "send_xon value port_id",
4761         .tokens = {
4762                 (void *)&cmd_lfc_set_set,
4763                 (void *)&cmd_lfc_set_flow_ctrl,
4764                 (void *)&cmd_lfc_set_send_xon_str,
4765                 (void *)&cmd_lfc_set_send_xon,
4766                 (void *)&cmd_lfc_set_portid,
4767                 NULL,
4768         },
4769 };
4770
4771 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
4772         .f = cmd_link_flow_ctrl_set_parsed,
4773         .data = (void *)&cmd_link_flow_control_set_macfwd,
4774         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
4775                     "mac_ctrl_frame_fwd on|off port_id",
4776         .tokens = {
4777                 (void *)&cmd_lfc_set_set,
4778                 (void *)&cmd_lfc_set_flow_ctrl,
4779                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4780                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4781                 (void *)&cmd_lfc_set_portid,
4782                 NULL,
4783         },
4784 };
4785
4786 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
4787         .f = cmd_link_flow_ctrl_set_parsed,
4788         .data = (void *)&cmd_link_flow_control_set_autoneg,
4789         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
4790                     "autoneg on|off port_id",
4791         .tokens = {
4792                 (void *)&cmd_lfc_set_set,
4793                 (void *)&cmd_lfc_set_flow_ctrl,
4794                 (void *)&cmd_lfc_set_autoneg_str,
4795                 (void *)&cmd_lfc_set_autoneg,
4796                 (void *)&cmd_lfc_set_portid,
4797                 NULL,
4798         },
4799 };
4800
4801 static void
4802 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
4803                               __attribute__((unused)) struct cmdline *cl,
4804                               void *data)
4805 {
4806         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
4807         cmdline_parse_inst_t *cmd = data;
4808         struct rte_eth_fc_conf fc_conf;
4809         int rx_fc_en = 0;
4810         int tx_fc_en = 0;
4811         int ret;
4812
4813         /*
4814          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
4815          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
4816          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
4817          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
4818          */
4819         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
4820                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
4821         };
4822
4823         /* Partial command line, retrieve current configuration */
4824         if (cmd) {
4825                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
4826                 if (ret != 0) {
4827                         printf("cannot get current flow ctrl parameters, return"
4828                                "code = %d\n", ret);
4829                         return;
4830                 }
4831
4832                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
4833                     (fc_conf.mode == RTE_FC_FULL))
4834                         rx_fc_en = 1;
4835                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
4836                     (fc_conf.mode == RTE_FC_FULL))
4837                         tx_fc_en = 1;
4838         }
4839
4840         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
4841                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
4842
4843         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
4844                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
4845
4846         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
4847
4848         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
4849                 fc_conf.high_water = res->high_water;
4850
4851         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
4852                 fc_conf.low_water = res->low_water;
4853
4854         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
4855                 fc_conf.pause_time = res->pause_time;
4856
4857         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
4858                 fc_conf.send_xon = res->send_xon;
4859
4860         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
4861                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
4862                         fc_conf.mac_ctrl_frame_fwd = 1;
4863                 else
4864                         fc_conf.mac_ctrl_frame_fwd = 0;
4865         }
4866
4867         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
4868                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
4869
4870         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
4871         if (ret != 0)
4872                 printf("bad flow contrl parameter, return code = %d \n", ret);
4873 }
4874
4875 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
4876 struct cmd_priority_flow_ctrl_set_result {
4877         cmdline_fixed_string_t set;
4878         cmdline_fixed_string_t pfc_ctrl;
4879         cmdline_fixed_string_t rx;
4880         cmdline_fixed_string_t rx_pfc_mode;
4881         cmdline_fixed_string_t tx;
4882         cmdline_fixed_string_t tx_pfc_mode;
4883         uint32_t high_water;
4884         uint32_t low_water;
4885         uint16_t pause_time;
4886         uint8_t  priority;
4887         uint8_t  port_id;
4888 };
4889
4890 static void
4891 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
4892                        __attribute__((unused)) struct cmdline *cl,
4893                        __attribute__((unused)) void *data)
4894 {
4895         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
4896         struct rte_eth_pfc_conf pfc_conf;
4897         int rx_fc_enable, tx_fc_enable;
4898         int ret;
4899
4900         /*
4901          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
4902          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
4903          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
4904          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
4905          */
4906         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
4907                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
4908         };
4909
4910         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
4911         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
4912         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
4913         pfc_conf.fc.high_water = res->high_water;
4914         pfc_conf.fc.low_water  = res->low_water;
4915         pfc_conf.fc.pause_time = res->pause_time;
4916         pfc_conf.priority      = res->priority;
4917
4918         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
4919         if (ret != 0)
4920                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
4921 }
4922
4923 cmdline_parse_token_string_t cmd_pfc_set_set =
4924         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4925                                 set, "set");
4926 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
4927         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4928                                 pfc_ctrl, "pfc_ctrl");
4929 cmdline_parse_token_string_t cmd_pfc_set_rx =
4930         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4931                                 rx, "rx");
4932 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
4933         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4934                                 rx_pfc_mode, "on#off");
4935 cmdline_parse_token_string_t cmd_pfc_set_tx =
4936         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4937                                 tx, "tx");
4938 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
4939         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4940                                 tx_pfc_mode, "on#off");
4941 cmdline_parse_token_num_t cmd_pfc_set_high_water =
4942         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4943                                 high_water, UINT32);
4944 cmdline_parse_token_num_t cmd_pfc_set_low_water =
4945         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4946                                 low_water, UINT32);
4947 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
4948         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4949                                 pause_time, UINT16);
4950 cmdline_parse_token_num_t cmd_pfc_set_priority =
4951         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4952                                 priority, UINT8);
4953 cmdline_parse_token_num_t cmd_pfc_set_portid =
4954         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
4955                                 port_id, UINT8);
4956
4957 cmdline_parse_inst_t cmd_priority_flow_control_set = {
4958         .f = cmd_priority_flow_ctrl_set_parsed,
4959         .data = NULL,
4960         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
4961                         tx on|off high_water low_water pause_time priority port_id",
4962         .tokens = {
4963                 (void *)&cmd_pfc_set_set,
4964                 (void *)&cmd_pfc_set_flow_ctrl,
4965                 (void *)&cmd_pfc_set_rx,
4966                 (void *)&cmd_pfc_set_rx_mode,
4967                 (void *)&cmd_pfc_set_tx,
4968                 (void *)&cmd_pfc_set_tx_mode,
4969                 (void *)&cmd_pfc_set_high_water,
4970                 (void *)&cmd_pfc_set_low_water,
4971                 (void *)&cmd_pfc_set_pause_time,
4972                 (void *)&cmd_pfc_set_priority,
4973                 (void *)&cmd_pfc_set_portid,
4974                 NULL,
4975         },
4976 };
4977
4978 /* *** RESET CONFIGURATION *** */
4979 struct cmd_reset_result {
4980         cmdline_fixed_string_t reset;
4981         cmdline_fixed_string_t def;
4982 };
4983
4984 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
4985                              struct cmdline *cl,
4986                              __attribute__((unused)) void *data)
4987 {
4988         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
4989         set_def_fwd_config();
4990 }
4991
4992 cmdline_parse_token_string_t cmd_reset_set =
4993         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
4994 cmdline_parse_token_string_t cmd_reset_def =
4995         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
4996                                  "default");
4997
4998 cmdline_parse_inst_t cmd_reset = {
4999         .f = cmd_reset_parsed,
5000         .data = NULL,
5001         .help_str = "set default: reset default forwarding configuration",
5002         .tokens = {
5003                 (void *)&cmd_reset_set,
5004                 (void *)&cmd_reset_def,
5005                 NULL,
5006         },
5007 };
5008
5009 /* *** START FORWARDING *** */
5010 struct cmd_start_result {
5011         cmdline_fixed_string_t start;
5012 };
5013
5014 cmdline_parse_token_string_t cmd_start_start =
5015         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5016
5017 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5018                              __attribute__((unused)) struct cmdline *cl,
5019                              __attribute__((unused)) void *data)
5020 {
5021         start_packet_forwarding(0);
5022 }
5023
5024 cmdline_parse_inst_t cmd_start = {
5025         .f = cmd_start_parsed,
5026         .data = NULL,
5027         .help_str = "start packet forwarding",
5028         .tokens = {
5029                 (void *)&cmd_start_start,
5030                 NULL,
5031         },
5032 };
5033
5034 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5035 struct cmd_start_tx_first_result {
5036         cmdline_fixed_string_t start;
5037         cmdline_fixed_string_t tx_first;
5038 };
5039
5040 static void
5041 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5042                           __attribute__((unused)) struct cmdline *cl,
5043                           __attribute__((unused)) void *data)
5044 {
5045         start_packet_forwarding(1);
5046 }
5047
5048 cmdline_parse_token_string_t cmd_start_tx_first_start =
5049         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5050                                  "start");
5051 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5052         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5053                                  tx_first, "tx_first");
5054
5055 cmdline_parse_inst_t cmd_start_tx_first = {
5056         .f = cmd_start_tx_first_parsed,
5057         .data = NULL,
5058         .help_str = "start packet forwarding, after sending 1 burst of packets",
5059         .tokens = {
5060                 (void *)&cmd_start_tx_first_start,
5061                 (void *)&cmd_start_tx_first_tx_first,
5062                 NULL,
5063         },
5064 };
5065
5066 /* *** SET LINK UP *** */
5067 struct cmd_set_link_up_result {
5068         cmdline_fixed_string_t set;
5069         cmdline_fixed_string_t link_up;
5070         cmdline_fixed_string_t port;
5071         uint8_t port_id;
5072 };
5073
5074 cmdline_parse_token_string_t cmd_set_link_up_set =
5075         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5076 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5077         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5078                                 "link-up");
5079 cmdline_parse_token_string_t cmd_set_link_up_port =
5080         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5081 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5082         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5083
5084 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5085                              __attribute__((unused)) struct cmdline *cl,
5086                              __attribute__((unused)) void *data)
5087 {
5088         struct cmd_set_link_up_result *res = parsed_result;
5089         dev_set_link_up(res->port_id);
5090 }
5091
5092 cmdline_parse_inst_t cmd_set_link_up = {
5093         .f = cmd_set_link_up_parsed,
5094         .data = NULL,
5095         .help_str = "set link-up port (port id)",
5096         .tokens = {
5097                 (void *)&cmd_set_link_up_set,
5098                 (void *)&cmd_set_link_up_link_up,
5099                 (void *)&cmd_set_link_up_port,
5100                 (void *)&cmd_set_link_up_port_id,
5101                 NULL,
5102         },
5103 };
5104
5105 /* *** SET LINK DOWN *** */
5106 struct cmd_set_link_down_result {
5107         cmdline_fixed_string_t set;
5108         cmdline_fixed_string_t link_down;
5109         cmdline_fixed_string_t port;
5110         uint8_t port_id;
5111 };
5112
5113 cmdline_parse_token_string_t cmd_set_link_down_set =
5114         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5115 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5116         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5117                                 "link-down");
5118 cmdline_parse_token_string_t cmd_set_link_down_port =
5119         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5120 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5121         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5122
5123 static void cmd_set_link_down_parsed(
5124                                 __attribute__((unused)) void *parsed_result,
5125                                 __attribute__((unused)) struct cmdline *cl,
5126                                 __attribute__((unused)) void *data)
5127 {
5128         struct cmd_set_link_down_result *res = parsed_result;
5129         dev_set_link_down(res->port_id);
5130 }
5131
5132 cmdline_parse_inst_t cmd_set_link_down = {
5133         .f = cmd_set_link_down_parsed,
5134         .data = NULL,
5135         .help_str = "set link-down port (port id)",
5136         .tokens = {
5137                 (void *)&cmd_set_link_down_set,
5138                 (void *)&cmd_set_link_down_link_down,
5139                 (void *)&cmd_set_link_down_port,
5140                 (void *)&cmd_set_link_down_port_id,
5141                 NULL,
5142         },
5143 };
5144
5145 /* *** SHOW CFG *** */
5146 struct cmd_showcfg_result {
5147         cmdline_fixed_string_t show;
5148         cmdline_fixed_string_t cfg;
5149         cmdline_fixed_string_t what;
5150 };
5151
5152 static void cmd_showcfg_parsed(void *parsed_result,
5153                                __attribute__((unused)) struct cmdline *cl,
5154                                __attribute__((unused)) void *data)
5155 {
5156         struct cmd_showcfg_result *res = parsed_result;
5157         if (!strcmp(res->what, "rxtx"))
5158                 rxtx_config_display();
5159         else if (!strcmp(res->what, "cores"))
5160                 fwd_lcores_config_display();
5161         else if (!strcmp(res->what, "fwd"))
5162                 fwd_config_display();
5163 }
5164
5165 cmdline_parse_token_string_t cmd_showcfg_show =
5166         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5167 cmdline_parse_token_string_t cmd_showcfg_port =
5168         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5169 cmdline_parse_token_string_t cmd_showcfg_what =
5170         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5171                                  "rxtx#cores#fwd");
5172
5173 cmdline_parse_inst_t cmd_showcfg = {
5174         .f = cmd_showcfg_parsed,
5175         .data = NULL,
5176         .help_str = "show config rxtx|cores|fwd",
5177         .tokens = {
5178                 (void *)&cmd_showcfg_show,
5179                 (void *)&cmd_showcfg_port,
5180                 (void *)&cmd_showcfg_what,
5181                 NULL,
5182         },
5183 };
5184
5185 /* *** SHOW ALL PORT INFO *** */
5186 struct cmd_showportall_result {
5187         cmdline_fixed_string_t show;
5188         cmdline_fixed_string_t port;
5189         cmdline_fixed_string_t what;
5190         cmdline_fixed_string_t all;
5191 };
5192
5193 static void cmd_showportall_parsed(void *parsed_result,
5194                                 __attribute__((unused)) struct cmdline *cl,
5195                                 __attribute__((unused)) void *data)
5196 {
5197         portid_t i;
5198
5199         struct cmd_showportall_result *res = parsed_result;
5200         if (!strcmp(res->show, "clear")) {
5201                 if (!strcmp(res->what, "stats"))
5202                         FOREACH_PORT(i, ports)
5203                                 nic_stats_clear(i);
5204                 else if (!strcmp(res->what, "xstats"))
5205                         FOREACH_PORT(i, ports)
5206                                 nic_xstats_clear(i);
5207         } else if (!strcmp(res->what, "info"))
5208                 FOREACH_PORT(i, ports)
5209                         port_infos_display(i);
5210         else if (!strcmp(res->what, "stats"))
5211                 FOREACH_PORT(i, ports)
5212                         nic_stats_display(i);
5213         else if (!strcmp(res->what, "xstats"))
5214                 FOREACH_PORT(i, ports)
5215                         nic_xstats_display(i);
5216         else if (!strcmp(res->what, "fdir"))
5217                 FOREACH_PORT(i, ports)
5218                         fdir_get_infos(i);
5219         else if (!strcmp(res->what, "stat_qmap"))
5220                 FOREACH_PORT(i, ports)
5221                         nic_stats_mapping_display(i);
5222 }
5223
5224 cmdline_parse_token_string_t cmd_showportall_show =
5225         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5226                                  "show#clear");
5227 cmdline_parse_token_string_t cmd_showportall_port =
5228         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5229 cmdline_parse_token_string_t cmd_showportall_what =
5230         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5231                                  "info#stats#xstats#fdir#stat_qmap");
5232 cmdline_parse_token_string_t cmd_showportall_all =
5233         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5234 cmdline_parse_inst_t cmd_showportall = {
5235         .f = cmd_showportall_parsed,
5236         .data = NULL,
5237         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap all",
5238         .tokens = {
5239                 (void *)&cmd_showportall_show,
5240                 (void *)&cmd_showportall_port,
5241                 (void *)&cmd_showportall_what,
5242                 (void *)&cmd_showportall_all,
5243                 NULL,
5244         },
5245 };
5246
5247 /* *** SHOW PORT INFO *** */
5248 struct cmd_showport_result {
5249         cmdline_fixed_string_t show;
5250         cmdline_fixed_string_t port;
5251         cmdline_fixed_string_t what;
5252         uint8_t portnum;
5253 };
5254
5255 static void cmd_showport_parsed(void *parsed_result,
5256                                 __attribute__((unused)) struct cmdline *cl,
5257                                 __attribute__((unused)) void *data)
5258 {
5259         struct cmd_showport_result *res = parsed_result;
5260         if (!strcmp(res->show, "clear")) {
5261                 if (!strcmp(res->what, "stats"))
5262                         nic_stats_clear(res->portnum);
5263                 else if (!strcmp(res->what, "xstats"))
5264                         nic_xstats_clear(res->portnum);
5265         } else if (!strcmp(res->what, "info"))
5266                 port_infos_display(res->portnum);
5267         else if (!strcmp(res->what, "stats"))
5268                 nic_stats_display(res->portnum);
5269         else if (!strcmp(res->what, "xstats"))
5270                 nic_xstats_display(res->portnum);
5271         else if (!strcmp(res->what, "fdir"))
5272                  fdir_get_infos(res->portnum);
5273         else if (!strcmp(res->what, "stat_qmap"))
5274                 nic_stats_mapping_display(res->portnum);
5275 }
5276
5277 cmdline_parse_token_string_t cmd_showport_show =
5278         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5279                                  "show#clear");
5280 cmdline_parse_token_string_t cmd_showport_port =
5281         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5282 cmdline_parse_token_string_t cmd_showport_what =
5283         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5284                                  "info#stats#xstats#fdir#stat_qmap");
5285 cmdline_parse_token_num_t cmd_showport_portnum =
5286         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5287
5288 cmdline_parse_inst_t cmd_showport = {
5289         .f = cmd_showport_parsed,
5290         .data = NULL,
5291         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap X (X = port number)",
5292         .tokens = {
5293                 (void *)&cmd_showport_show,
5294                 (void *)&cmd_showport_port,
5295                 (void *)&cmd_showport_what,
5296                 (void *)&cmd_showport_portnum,
5297                 NULL,
5298         },
5299 };
5300
5301 /* *** READ PORT REGISTER *** */
5302 struct cmd_read_reg_result {
5303         cmdline_fixed_string_t read;
5304         cmdline_fixed_string_t reg;
5305         uint8_t port_id;
5306         uint32_t reg_off;
5307 };
5308
5309 static void
5310 cmd_read_reg_parsed(void *parsed_result,
5311                     __attribute__((unused)) struct cmdline *cl,
5312                     __attribute__((unused)) void *data)
5313 {
5314         struct cmd_read_reg_result *res = parsed_result;
5315         port_reg_display(res->port_id, res->reg_off);
5316 }
5317
5318 cmdline_parse_token_string_t cmd_read_reg_read =
5319         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5320 cmdline_parse_token_string_t cmd_read_reg_reg =
5321         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5322 cmdline_parse_token_num_t cmd_read_reg_port_id =
5323         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5324 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5325         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5326
5327 cmdline_parse_inst_t cmd_read_reg = {
5328         .f = cmd_read_reg_parsed,
5329         .data = NULL,
5330         .help_str = "read reg port_id reg_off",
5331         .tokens = {
5332                 (void *)&cmd_read_reg_read,
5333                 (void *)&cmd_read_reg_reg,
5334                 (void *)&cmd_read_reg_port_id,
5335                 (void *)&cmd_read_reg_reg_off,
5336                 NULL,
5337         },
5338 };
5339
5340 /* *** READ PORT REGISTER BIT FIELD *** */
5341 struct cmd_read_reg_bit_field_result {
5342         cmdline_fixed_string_t read;
5343         cmdline_fixed_string_t regfield;
5344         uint8_t port_id;
5345         uint32_t reg_off;
5346         uint8_t bit1_pos;
5347         uint8_t bit2_pos;
5348 };
5349
5350 static void
5351 cmd_read_reg_bit_field_parsed(void *parsed_result,
5352                               __attribute__((unused)) struct cmdline *cl,
5353                               __attribute__((unused)) void *data)
5354 {
5355         struct cmd_read_reg_bit_field_result *res = parsed_result;
5356         port_reg_bit_field_display(res->port_id, res->reg_off,
5357                                    res->bit1_pos, res->bit2_pos);
5358 }
5359
5360 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5361         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5362                                  "read");
5363 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5364         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5365                                  regfield, "regfield");
5366 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5367         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5368                               UINT8);
5369 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5370         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5371                               UINT32);
5372 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5373         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5374                               UINT8);
5375 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5376         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5377                               UINT8);
5378
5379 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5380         .f = cmd_read_reg_bit_field_parsed,
5381         .data = NULL,
5382         .help_str = "read regfield port_id reg_off bit_x bit_y "
5383         "(read register bit field between bit_x and bit_y included)",
5384         .tokens = {
5385                 (void *)&cmd_read_reg_bit_field_read,
5386                 (void *)&cmd_read_reg_bit_field_regfield,
5387                 (void *)&cmd_read_reg_bit_field_port_id,
5388                 (void *)&cmd_read_reg_bit_field_reg_off,
5389                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5390                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5391                 NULL,
5392         },
5393 };
5394
5395 /* *** READ PORT REGISTER BIT *** */
5396 struct cmd_read_reg_bit_result {
5397         cmdline_fixed_string_t read;
5398         cmdline_fixed_string_t regbit;
5399         uint8_t port_id;
5400         uint32_t reg_off;
5401         uint8_t bit_pos;
5402 };
5403
5404 static void
5405 cmd_read_reg_bit_parsed(void *parsed_result,
5406                         __attribute__((unused)) struct cmdline *cl,
5407                         __attribute__((unused)) void *data)
5408 {
5409         struct cmd_read_reg_bit_result *res = parsed_result;
5410         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5411 }
5412
5413 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5414         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5415 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5416         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5417                                  regbit, "regbit");
5418 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5419         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5420 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5421         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5422 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5423         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5424
5425 cmdline_parse_inst_t cmd_read_reg_bit = {
5426         .f = cmd_read_reg_bit_parsed,
5427         .data = NULL,
5428         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5429         .tokens = {
5430                 (void *)&cmd_read_reg_bit_read,
5431                 (void *)&cmd_read_reg_bit_regbit,
5432                 (void *)&cmd_read_reg_bit_port_id,
5433                 (void *)&cmd_read_reg_bit_reg_off,
5434                 (void *)&cmd_read_reg_bit_bit_pos,
5435                 NULL,
5436         },
5437 };
5438
5439 /* *** WRITE PORT REGISTER *** */
5440 struct cmd_write_reg_result {
5441         cmdline_fixed_string_t write;
5442         cmdline_fixed_string_t reg;
5443         uint8_t port_id;
5444         uint32_t reg_off;
5445         uint32_t value;
5446 };
5447
5448 static void
5449 cmd_write_reg_parsed(void *parsed_result,
5450                      __attribute__((unused)) struct cmdline *cl,
5451                      __attribute__((unused)) void *data)
5452 {
5453         struct cmd_write_reg_result *res = parsed_result;
5454         port_reg_set(res->port_id, res->reg_off, res->value);
5455 }
5456
5457 cmdline_parse_token_string_t cmd_write_reg_write =
5458         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5459 cmdline_parse_token_string_t cmd_write_reg_reg =
5460         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5461 cmdline_parse_token_num_t cmd_write_reg_port_id =
5462         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5463 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5464         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5465 cmdline_parse_token_num_t cmd_write_reg_value =
5466         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5467
5468 cmdline_parse_inst_t cmd_write_reg = {
5469         .f = cmd_write_reg_parsed,
5470         .data = NULL,
5471         .help_str = "write reg port_id reg_off reg_value",
5472         .tokens = {
5473                 (void *)&cmd_write_reg_write,
5474                 (void *)&cmd_write_reg_reg,
5475                 (void *)&cmd_write_reg_port_id,
5476                 (void *)&cmd_write_reg_reg_off,
5477                 (void *)&cmd_write_reg_value,
5478                 NULL,
5479         },
5480 };
5481
5482 /* *** WRITE PORT REGISTER BIT FIELD *** */
5483 struct cmd_write_reg_bit_field_result {
5484         cmdline_fixed_string_t write;
5485         cmdline_fixed_string_t regfield;
5486         uint8_t port_id;
5487         uint32_t reg_off;
5488         uint8_t bit1_pos;
5489         uint8_t bit2_pos;
5490         uint32_t value;
5491 };
5492
5493 static void
5494 cmd_write_reg_bit_field_parsed(void *parsed_result,
5495                                __attribute__((unused)) struct cmdline *cl,
5496                                __attribute__((unused)) void *data)
5497 {
5498         struct cmd_write_reg_bit_field_result *res = parsed_result;
5499         port_reg_bit_field_set(res->port_id, res->reg_off,
5500                           res->bit1_pos, res->bit2_pos, res->value);
5501 }
5502
5503 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5504         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5505                                  "write");
5506 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5507         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5508                                  regfield, "regfield");
5509 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5510         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5511                               UINT8);
5512 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5513         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5514                               UINT32);
5515 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5516         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5517                               UINT8);
5518 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5519         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5520                               UINT8);
5521 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5522         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5523                               UINT32);
5524
5525 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5526         .f = cmd_write_reg_bit_field_parsed,
5527         .data = NULL,
5528         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5529         "(set register bit field between bit_x and bit_y included)",
5530         .tokens = {
5531                 (void *)&cmd_write_reg_bit_field_write,
5532                 (void *)&cmd_write_reg_bit_field_regfield,
5533                 (void *)&cmd_write_reg_bit_field_port_id,
5534                 (void *)&cmd_write_reg_bit_field_reg_off,
5535                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5536                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5537                 (void *)&cmd_write_reg_bit_field_value,
5538                 NULL,
5539         },
5540 };
5541
5542 /* *** WRITE PORT REGISTER BIT *** */
5543 struct cmd_write_reg_bit_result {
5544         cmdline_fixed_string_t write;
5545         cmdline_fixed_string_t regbit;
5546         uint8_t port_id;
5547         uint32_t reg_off;
5548         uint8_t bit_pos;
5549         uint8_t value;
5550 };
5551
5552 static void
5553 cmd_write_reg_bit_parsed(void *parsed_result,
5554                          __attribute__((unused)) struct cmdline *cl,
5555                          __attribute__((unused)) void *data)
5556 {
5557         struct cmd_write_reg_bit_result *res = parsed_result;
5558         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5559 }
5560
5561 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5562         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5563                                  "write");
5564 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5565         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5566                                  regbit, "regbit");
5567 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5568         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5569 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5570         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5571 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5572         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5573 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5574         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5575
5576 cmdline_parse_inst_t cmd_write_reg_bit = {
5577         .f = cmd_write_reg_bit_parsed,
5578         .data = NULL,
5579         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5580         .tokens = {
5581                 (void *)&cmd_write_reg_bit_write,
5582                 (void *)&cmd_write_reg_bit_regbit,
5583                 (void *)&cmd_write_reg_bit_port_id,
5584                 (void *)&cmd_write_reg_bit_reg_off,
5585                 (void *)&cmd_write_reg_bit_bit_pos,
5586                 (void *)&cmd_write_reg_bit_value,
5587                 NULL,
5588         },
5589 };
5590
5591 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5592 struct cmd_read_rxd_txd_result {
5593         cmdline_fixed_string_t read;
5594         cmdline_fixed_string_t rxd_txd;
5595         uint8_t port_id;
5596         uint16_t queue_id;
5597         uint16_t desc_id;
5598 };
5599
5600 static void
5601 cmd_read_rxd_txd_parsed(void *parsed_result,
5602                         __attribute__((unused)) struct cmdline *cl,
5603                         __attribute__((unused)) void *data)
5604 {
5605         struct cmd_read_rxd_txd_result *res = parsed_result;
5606
5607         if (!strcmp(res->rxd_txd, "rxd"))
5608                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5609         else if (!strcmp(res->rxd_txd, "txd"))
5610                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5611 }
5612
5613 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5614         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5615 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5616         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5617                                  "rxd#txd");
5618 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5619         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5620 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5621         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5622 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5623         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5624
5625 cmdline_parse_inst_t cmd_read_rxd_txd = {
5626         .f = cmd_read_rxd_txd_parsed,
5627         .data = NULL,
5628         .help_str = "read rxd|txd port_id queue_id rxd_id",
5629         .tokens = {
5630                 (void *)&cmd_read_rxd_txd_read,
5631                 (void *)&cmd_read_rxd_txd_rxd_txd,
5632                 (void *)&cmd_read_rxd_txd_port_id,
5633                 (void *)&cmd_read_rxd_txd_queue_id,
5634                 (void *)&cmd_read_rxd_txd_desc_id,
5635                 NULL,
5636         },
5637 };
5638
5639 /* *** QUIT *** */
5640 struct cmd_quit_result {
5641         cmdline_fixed_string_t quit;
5642 };
5643
5644 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5645                             struct cmdline *cl,
5646                             __attribute__((unused)) void *data)
5647 {
5648         pmd_test_exit();
5649         cmdline_quit(cl);
5650 }
5651
5652 cmdline_parse_token_string_t cmd_quit_quit =
5653         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5654
5655 cmdline_parse_inst_t cmd_quit = {
5656         .f = cmd_quit_parsed,
5657         .data = NULL,
5658         .help_str = "exit application",
5659         .tokens = {
5660                 (void *)&cmd_quit_quit,
5661                 NULL,
5662         },
5663 };
5664
5665 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5666 struct cmd_mac_addr_result {
5667         cmdline_fixed_string_t mac_addr_cmd;
5668         cmdline_fixed_string_t what;
5669         uint8_t port_num;
5670         struct ether_addr address;
5671 };
5672
5673 static void cmd_mac_addr_parsed(void *parsed_result,
5674                 __attribute__((unused)) struct cmdline *cl,
5675                 __attribute__((unused)) void *data)
5676 {
5677         struct cmd_mac_addr_result *res = parsed_result;
5678         int ret;
5679
5680         if (strcmp(res->what, "add") == 0)
5681                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5682         else
5683                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5684
5685         /* check the return value and print it if is < 0 */
5686         if(ret < 0)
5687                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5688
5689 }
5690
5691 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5692         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5693                                 "mac_addr");
5694 cmdline_parse_token_string_t cmd_mac_addr_what =
5695         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5696                                 "add#remove");
5697 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5698                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5699 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5700                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5701
5702 cmdline_parse_inst_t cmd_mac_addr = {
5703         .f = cmd_mac_addr_parsed,
5704         .data = (void *)0,
5705         .help_str = "mac_addr add|remove X <address>: "
5706                         "add/remove MAC address on port X",
5707         .tokens = {
5708                 (void *)&cmd_mac_addr_cmd,
5709                 (void *)&cmd_mac_addr_what,
5710                 (void *)&cmd_mac_addr_portnum,
5711                 (void *)&cmd_mac_addr_addr,
5712                 NULL,
5713         },
5714 };
5715
5716
5717 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5718 struct cmd_set_qmap_result {
5719         cmdline_fixed_string_t set;
5720         cmdline_fixed_string_t qmap;
5721         cmdline_fixed_string_t what;
5722         uint8_t port_id;
5723         uint16_t queue_id;
5724         uint8_t map_value;
5725 };
5726
5727 static void
5728 cmd_set_qmap_parsed(void *parsed_result,
5729                        __attribute__((unused)) struct cmdline *cl,
5730                        __attribute__((unused)) void *data)
5731 {
5732         struct cmd_set_qmap_result *res = parsed_result;
5733         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5734
5735         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5736 }
5737
5738 cmdline_parse_token_string_t cmd_setqmap_set =
5739         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5740                                  set, "set");
5741 cmdline_parse_token_string_t cmd_setqmap_qmap =
5742         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5743                                  qmap, "stat_qmap");
5744 cmdline_parse_token_string_t cmd_setqmap_what =
5745         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5746                                  what, "tx#rx");
5747 cmdline_parse_token_num_t cmd_setqmap_portid =
5748         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5749                               port_id, UINT8);
5750 cmdline_parse_token_num_t cmd_setqmap_queueid =
5751         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5752                               queue_id, UINT16);
5753 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5754         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5755                               map_value, UINT8);
5756
5757 cmdline_parse_inst_t cmd_set_qmap = {
5758         .f = cmd_set_qmap_parsed,
5759         .data = NULL,
5760         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
5761         .tokens = {
5762                 (void *)&cmd_setqmap_set,
5763                 (void *)&cmd_setqmap_qmap,
5764                 (void *)&cmd_setqmap_what,
5765                 (void *)&cmd_setqmap_portid,
5766                 (void *)&cmd_setqmap_queueid,
5767                 (void *)&cmd_setqmap_mapvalue,
5768                 NULL,
5769         },
5770 };
5771
5772 /* *** CONFIGURE UNICAST HASH TABLE *** */
5773 struct cmd_set_uc_hash_table {
5774         cmdline_fixed_string_t set;
5775         cmdline_fixed_string_t port;
5776         uint8_t port_id;
5777         cmdline_fixed_string_t what;
5778         struct ether_addr address;
5779         cmdline_fixed_string_t mode;
5780 };
5781
5782 static void
5783 cmd_set_uc_hash_parsed(void *parsed_result,
5784                        __attribute__((unused)) struct cmdline *cl,
5785                        __attribute__((unused)) void *data)
5786 {
5787         int ret=0;
5788         struct cmd_set_uc_hash_table *res = parsed_result;
5789
5790         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5791
5792         if (strcmp(res->what, "uta") == 0)
5793                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
5794                                                 &res->address,(uint8_t)is_on);
5795         if (ret < 0)
5796                 printf("bad unicast hash table parameter, return code = %d \n", ret);
5797
5798 }
5799
5800 cmdline_parse_token_string_t cmd_set_uc_hash_set =
5801         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5802                                  set, "set");
5803 cmdline_parse_token_string_t cmd_set_uc_hash_port =
5804         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5805                                  port, "port");
5806 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
5807         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
5808                               port_id, UINT8);
5809 cmdline_parse_token_string_t cmd_set_uc_hash_what =
5810         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5811                                  what, "uta");
5812 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
5813         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
5814                                 address);
5815 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
5816         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
5817                                  mode, "on#off");
5818
5819 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
5820         .f = cmd_set_uc_hash_parsed,
5821         .data = NULL,
5822         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
5823         .tokens = {
5824                 (void *)&cmd_set_uc_hash_set,
5825                 (void *)&cmd_set_uc_hash_port,
5826                 (void *)&cmd_set_uc_hash_portid,
5827                 (void *)&cmd_set_uc_hash_what,
5828                 (void *)&cmd_set_uc_hash_mac,
5829                 (void *)&cmd_set_uc_hash_mode,
5830                 NULL,
5831         },
5832 };
5833
5834 struct cmd_set_uc_all_hash_table {
5835         cmdline_fixed_string_t set;
5836         cmdline_fixed_string_t port;
5837         uint8_t port_id;
5838         cmdline_fixed_string_t what;
5839         cmdline_fixed_string_t value;
5840         cmdline_fixed_string_t mode;
5841 };
5842
5843 static void
5844 cmd_set_uc_all_hash_parsed(void *parsed_result,
5845                        __attribute__((unused)) struct cmdline *cl,
5846                        __attribute__((unused)) void *data)
5847 {
5848         int ret=0;
5849         struct cmd_set_uc_all_hash_table *res = parsed_result;
5850
5851         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5852
5853         if ((strcmp(res->what, "uta") == 0) &&
5854                 (strcmp(res->value, "all") == 0))
5855                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
5856         if (ret < 0)
5857                 printf("bad unicast hash table parameter,"
5858                         "return code = %d \n", ret);
5859 }
5860
5861 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
5862         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5863                                  set, "set");
5864 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
5865         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5866                                  port, "port");
5867 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
5868         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
5869                               port_id, UINT8);
5870 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
5871         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5872                                  what, "uta");
5873 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
5874         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5875                                 value,"all");
5876 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
5877         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
5878                                  mode, "on#off");
5879
5880 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
5881         .f = cmd_set_uc_all_hash_parsed,
5882         .data = NULL,
5883         .help_str = "set port X uta all on|off (X = port number)",
5884         .tokens = {
5885                 (void *)&cmd_set_uc_all_hash_set,
5886                 (void *)&cmd_set_uc_all_hash_port,
5887                 (void *)&cmd_set_uc_all_hash_portid,
5888                 (void *)&cmd_set_uc_all_hash_what,
5889                 (void *)&cmd_set_uc_all_hash_value,
5890                 (void *)&cmd_set_uc_all_hash_mode,
5891                 NULL,
5892         },
5893 };
5894
5895 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
5896 struct cmd_set_vf_macvlan_filter {
5897         cmdline_fixed_string_t set;
5898         cmdline_fixed_string_t port;
5899         uint8_t port_id;
5900         cmdline_fixed_string_t vf;
5901         uint8_t vf_id;
5902         struct ether_addr address;
5903         cmdline_fixed_string_t filter_type;
5904         cmdline_fixed_string_t mode;
5905 };
5906
5907 static void
5908 cmd_set_vf_macvlan_parsed(void *parsed_result,
5909                        __attribute__((unused)) struct cmdline *cl,
5910                        __attribute__((unused)) void *data)
5911 {
5912         int is_on, ret = 0;
5913         struct cmd_set_vf_macvlan_filter *res = parsed_result;
5914         struct rte_eth_mac_filter filter;
5915
5916         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
5917
5918         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
5919
5920         /* set VF MAC filter */
5921         filter.is_vf = 1;
5922
5923         /* set VF ID */
5924         filter.dst_id = res->vf_id;
5925
5926         if (!strcmp(res->filter_type, "exact-mac"))
5927                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
5928         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
5929                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5930         else if (!strcmp(res->filter_type, "hashmac"))
5931                 filter.filter_type = RTE_MAC_HASH_MATCH;
5932         else if (!strcmp(res->filter_type, "hashmac-vlan"))
5933                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
5934
5935         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
5936
5937         if (is_on)
5938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
5939                                         RTE_ETH_FILTER_MACVLAN,
5940                                         RTE_ETH_FILTER_ADD,
5941                                          &filter);
5942         else
5943                 ret = rte_eth_dev_filter_ctrl(res->port_id,
5944                                         RTE_ETH_FILTER_MACVLAN,
5945                                         RTE_ETH_FILTER_DELETE,
5946                                         &filter);
5947
5948         if (ret < 0)
5949                 printf("bad set MAC hash parameter, return code = %d\n", ret);
5950
5951 }
5952
5953 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
5954         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5955                                  set, "set");
5956 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
5957         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5958                                  port, "port");
5959 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
5960         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5961                               port_id, UINT8);
5962 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
5963         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5964                                  vf, "vf");
5965 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
5966         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5967                                 vf_id, UINT8);
5968 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
5969         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5970                                 address);
5971 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
5972         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5973                                 filter_type, "exact-mac#exact-mac-vlan"
5974                                 "#hashmac#hashmac-vlan");
5975 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
5976         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
5977                                  mode, "on#off");
5978
5979 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
5980         .f = cmd_set_vf_macvlan_parsed,
5981         .data = NULL,
5982         .help_str = "set port (portid) vf (vfid) (mac-addr) "
5983                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
5984                         "on|off\n"
5985                         "exact match rule:exact match of MAC or MAC and VLAN; "
5986                         "hash match rule: hash match of MAC and exact match "
5987                         "of VLAN",
5988         .tokens = {
5989                 (void *)&cmd_set_vf_macvlan_set,
5990                 (void *)&cmd_set_vf_macvlan_port,
5991                 (void *)&cmd_set_vf_macvlan_portid,
5992                 (void *)&cmd_set_vf_macvlan_vf,
5993                 (void *)&cmd_set_vf_macvlan_vf_id,
5994                 (void *)&cmd_set_vf_macvlan_mac,
5995                 (void *)&cmd_set_vf_macvlan_filter_type,
5996                 (void *)&cmd_set_vf_macvlan_mode,
5997                 NULL,
5998         },
5999 };
6000
6001 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6002 struct cmd_set_vf_traffic {
6003         cmdline_fixed_string_t set;
6004         cmdline_fixed_string_t port;
6005         uint8_t port_id;
6006         cmdline_fixed_string_t vf;
6007         uint8_t vf_id;
6008         cmdline_fixed_string_t what;
6009         cmdline_fixed_string_t mode;
6010 };
6011
6012 static void
6013 cmd_set_vf_traffic_parsed(void *parsed_result,
6014                        __attribute__((unused)) struct cmdline *cl,
6015                        __attribute__((unused)) void *data)
6016 {
6017         struct cmd_set_vf_traffic *res = parsed_result;
6018         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6019         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6020
6021         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6022 }
6023
6024 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6025         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6026                                  set, "set");
6027 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6028         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6029                                  port, "port");
6030 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6031         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6032                               port_id, UINT8);
6033 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6034         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6035                                  vf, "vf");
6036 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6037         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6038                               vf_id, UINT8);
6039 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6040         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6041                                  what, "tx#rx");
6042 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6043         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6044                                  mode, "on#off");
6045
6046 cmdline_parse_inst_t cmd_set_vf_traffic = {
6047         .f = cmd_set_vf_traffic_parsed,
6048         .data = NULL,
6049         .help_str = "set port X vf Y rx|tx on|off"
6050                         "(X = port number,Y = vf id)",
6051         .tokens = {
6052                 (void *)&cmd_setvf_traffic_set,
6053                 (void *)&cmd_setvf_traffic_port,
6054                 (void *)&cmd_setvf_traffic_portid,
6055                 (void *)&cmd_setvf_traffic_vf,
6056                 (void *)&cmd_setvf_traffic_vfid,
6057                 (void *)&cmd_setvf_traffic_what,
6058                 (void *)&cmd_setvf_traffic_mode,
6059                 NULL,
6060         },
6061 };
6062
6063 /* *** CONFIGURE VF RECEIVE MODE *** */
6064 struct cmd_set_vf_rxmode {
6065         cmdline_fixed_string_t set;
6066         cmdline_fixed_string_t port;
6067         uint8_t port_id;
6068         cmdline_fixed_string_t vf;
6069         uint8_t vf_id;
6070         cmdline_fixed_string_t what;
6071         cmdline_fixed_string_t mode;
6072         cmdline_fixed_string_t on;
6073 };
6074
6075 static void
6076 cmd_set_vf_rxmode_parsed(void *parsed_result,
6077                        __attribute__((unused)) struct cmdline *cl,
6078                        __attribute__((unused)) void *data)
6079 {
6080         int ret;
6081         uint16_t rx_mode = 0;
6082         struct cmd_set_vf_rxmode *res = parsed_result;
6083
6084         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6085         if (!strcmp(res->what,"rxmode")) {
6086                 if (!strcmp(res->mode, "AUPE"))
6087                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6088                 else if (!strcmp(res->mode, "ROPE"))
6089                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6090                 else if (!strcmp(res->mode, "BAM"))
6091                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6092                 else if (!strncmp(res->mode, "MPE",3))
6093                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6094         }
6095
6096         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6097         if (ret < 0)
6098                 printf("bad VF receive mode parameter, return code = %d \n",
6099                 ret);
6100 }
6101
6102 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6103         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6104                                  set, "set");
6105 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6106         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6107                                  port, "port");
6108 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6109         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6110                               port_id, UINT8);
6111 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6112         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6113                                  vf, "vf");
6114 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6115         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6116                               vf_id, UINT8);
6117 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6118         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6119                                  what, "rxmode");
6120 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6121         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6122                                  mode, "AUPE#ROPE#BAM#MPE");
6123 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6124         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6125                                  on, "on#off");
6126
6127 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6128         .f = cmd_set_vf_rxmode_parsed,
6129         .data = NULL,
6130         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6131         .tokens = {
6132                 (void *)&cmd_set_vf_rxmode_set,
6133                 (void *)&cmd_set_vf_rxmode_port,
6134                 (void *)&cmd_set_vf_rxmode_portid,
6135                 (void *)&cmd_set_vf_rxmode_vf,
6136                 (void *)&cmd_set_vf_rxmode_vfid,
6137                 (void *)&cmd_set_vf_rxmode_what,
6138                 (void *)&cmd_set_vf_rxmode_mode,
6139                 (void *)&cmd_set_vf_rxmode_on,
6140                 NULL,
6141         },
6142 };
6143
6144 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6145 struct cmd_vf_mac_addr_result {
6146         cmdline_fixed_string_t mac_addr_cmd;
6147         cmdline_fixed_string_t what;
6148         cmdline_fixed_string_t port;
6149         uint8_t port_num;
6150         cmdline_fixed_string_t vf;
6151         uint8_t vf_num;
6152         struct ether_addr address;
6153 };
6154
6155 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6156                 __attribute__((unused)) struct cmdline *cl,
6157                 __attribute__((unused)) void *data)
6158 {
6159         struct cmd_vf_mac_addr_result *res = parsed_result;
6160         int ret = 0;
6161
6162         if (strcmp(res->what, "add") == 0)
6163                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6164                                         &res->address, res->vf_num);
6165         if(ret < 0)
6166                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6167
6168 }
6169
6170 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6171         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6172                                 mac_addr_cmd,"mac_addr");
6173 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6174         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6175                                 what,"add");
6176 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6177         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6178                                 port,"port");
6179 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6180         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6181                                 port_num, UINT8);
6182 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6183         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6184                                 vf,"vf");
6185 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6186         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6187                                 vf_num, UINT8);
6188 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6189         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6190                                 address);
6191
6192 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6193         .f = cmd_vf_mac_addr_parsed,
6194         .data = (void *)0,
6195         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6196         "Y = VF number)add MAC address filtering for a VF on port X",
6197         .tokens = {
6198                 (void *)&cmd_vf_mac_addr_cmd,
6199                 (void *)&cmd_vf_mac_addr_what,
6200                 (void *)&cmd_vf_mac_addr_port,
6201                 (void *)&cmd_vf_mac_addr_portnum,
6202                 (void *)&cmd_vf_mac_addr_vf,
6203                 (void *)&cmd_vf_mac_addr_vfnum,
6204                 (void *)&cmd_vf_mac_addr_addr,
6205                 NULL,
6206         },
6207 };
6208
6209 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6210 struct cmd_vf_rx_vlan_filter {
6211         cmdline_fixed_string_t rx_vlan;
6212         cmdline_fixed_string_t what;
6213         uint16_t vlan_id;
6214         cmdline_fixed_string_t port;
6215         uint8_t port_id;
6216         cmdline_fixed_string_t vf;
6217         uint64_t vf_mask;
6218 };
6219
6220 static void
6221 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6222                           __attribute__((unused)) struct cmdline *cl,
6223                           __attribute__((unused)) void *data)
6224 {
6225         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6226
6227         if (!strcmp(res->what, "add"))
6228                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6229         else
6230                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6231 }
6232
6233 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6234         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6235                                  rx_vlan, "rx_vlan");
6236 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6237         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6238                                  what, "add#rm");
6239 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6240         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6241                               vlan_id, UINT16);
6242 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6243         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6244                                  port, "port");
6245 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6246         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6247                               port_id, UINT8);
6248 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6249         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6250                                  vf, "vf");
6251 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6252         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6253                               vf_mask, UINT64);
6254
6255 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6256         .f = cmd_vf_rx_vlan_filter_parsed,
6257         .data = NULL,
6258         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6259                 "Y = port number,Z = hexadecimal VF mask)",
6260         .tokens = {
6261                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6262                 (void *)&cmd_vf_rx_vlan_filter_what,
6263                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6264                 (void *)&cmd_vf_rx_vlan_filter_port,
6265                 (void *)&cmd_vf_rx_vlan_filter_portid,
6266                 (void *)&cmd_vf_rx_vlan_filter_vf,
6267                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6268                 NULL,
6269         },
6270 };
6271
6272 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6273 struct cmd_queue_rate_limit_result {
6274         cmdline_fixed_string_t set;
6275         cmdline_fixed_string_t port;
6276         uint8_t port_num;
6277         cmdline_fixed_string_t queue;
6278         uint8_t queue_num;
6279         cmdline_fixed_string_t rate;
6280         uint16_t rate_num;
6281 };
6282
6283 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6284                 __attribute__((unused)) struct cmdline *cl,
6285                 __attribute__((unused)) void *data)
6286 {
6287         struct cmd_queue_rate_limit_result *res = parsed_result;
6288         int ret = 0;
6289
6290         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6291                 && (strcmp(res->queue, "queue") == 0)
6292                 && (strcmp(res->rate, "rate") == 0))
6293                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6294                                         res->rate_num);
6295         if (ret < 0)
6296                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6297
6298 }
6299
6300 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6301         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6302                                 set, "set");
6303 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6304         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6305                                 port, "port");
6306 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6307         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6308                                 port_num, UINT8);
6309 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6310         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6311                                 queue, "queue");
6312 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6313         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6314                                 queue_num, UINT8);
6315 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6316         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6317                                 rate, "rate");
6318 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6319         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6320                                 rate_num, UINT16);
6321
6322 cmdline_parse_inst_t cmd_queue_rate_limit = {
6323         .f = cmd_queue_rate_limit_parsed,
6324         .data = (void *)0,
6325         .help_str = "set port X queue Y rate Z:(X = port number,"
6326         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6327         .tokens = {
6328                 (void *)&cmd_queue_rate_limit_set,
6329                 (void *)&cmd_queue_rate_limit_port,
6330                 (void *)&cmd_queue_rate_limit_portnum,
6331                 (void *)&cmd_queue_rate_limit_queue,
6332                 (void *)&cmd_queue_rate_limit_queuenum,
6333                 (void *)&cmd_queue_rate_limit_rate,
6334                 (void *)&cmd_queue_rate_limit_ratenum,
6335                 NULL,
6336         },
6337 };
6338
6339 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6340 struct cmd_vf_rate_limit_result {
6341         cmdline_fixed_string_t set;
6342         cmdline_fixed_string_t port;
6343         uint8_t port_num;
6344         cmdline_fixed_string_t vf;
6345         uint8_t vf_num;
6346         cmdline_fixed_string_t rate;
6347         uint16_t rate_num;
6348         cmdline_fixed_string_t q_msk;
6349         uint64_t q_msk_val;
6350 };
6351
6352 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6353                 __attribute__((unused)) struct cmdline *cl,
6354                 __attribute__((unused)) void *data)
6355 {
6356         struct cmd_vf_rate_limit_result *res = parsed_result;
6357         int ret = 0;
6358
6359         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6360                 && (strcmp(res->vf, "vf") == 0)
6361                 && (strcmp(res->rate, "rate") == 0)
6362                 && (strcmp(res->q_msk, "queue_mask") == 0))
6363                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6364                                         res->rate_num, res->q_msk_val);
6365         if (ret < 0)
6366                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6367
6368 }
6369
6370 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6371         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6372                                 set, "set");
6373 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6374         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6375                                 port, "port");
6376 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6377         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6378                                 port_num, UINT8);
6379 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6380         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6381                                 vf, "vf");
6382 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6383         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6384                                 vf_num, UINT8);
6385 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6386         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6387                                 rate, "rate");
6388 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6389         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6390                                 rate_num, UINT16);
6391 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6392         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6393                                 q_msk, "queue_mask");
6394 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6395         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6396                                 q_msk_val, UINT64);
6397
6398 cmdline_parse_inst_t cmd_vf_rate_limit = {
6399         .f = cmd_vf_rate_limit_parsed,
6400         .data = (void *)0,
6401         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6402         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6403         "for queues of VF on port X",
6404         .tokens = {
6405                 (void *)&cmd_vf_rate_limit_set,
6406                 (void *)&cmd_vf_rate_limit_port,
6407                 (void *)&cmd_vf_rate_limit_portnum,
6408                 (void *)&cmd_vf_rate_limit_vf,
6409                 (void *)&cmd_vf_rate_limit_vfnum,
6410                 (void *)&cmd_vf_rate_limit_rate,
6411                 (void *)&cmd_vf_rate_limit_ratenum,
6412                 (void *)&cmd_vf_rate_limit_q_msk,
6413                 (void *)&cmd_vf_rate_limit_q_msk_val,
6414                 NULL,
6415         },
6416 };
6417
6418 /* *** ADD TUNNEL FILTER OF A PORT *** */
6419 struct cmd_tunnel_filter_result {
6420         cmdline_fixed_string_t cmd;
6421         cmdline_fixed_string_t what;
6422         uint8_t port_id;
6423         struct ether_addr outer_mac;
6424         struct ether_addr inner_mac;
6425         cmdline_ipaddr_t ip_value;
6426         uint16_t inner_vlan;
6427         cmdline_fixed_string_t tunnel_type;
6428         cmdline_fixed_string_t filter_type;
6429         uint32_t tenant_id;
6430         uint16_t queue_num;
6431 };
6432
6433 static void
6434 cmd_tunnel_filter_parsed(void *parsed_result,
6435                           __attribute__((unused)) struct cmdline *cl,
6436                           __attribute__((unused)) void *data)
6437 {
6438         struct cmd_tunnel_filter_result *res = parsed_result;
6439         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6440         int ret = 0;
6441
6442         tunnel_filter_conf.outer_mac = &res->outer_mac;
6443         tunnel_filter_conf.inner_mac = &res->inner_mac;
6444         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6445
6446         if (res->ip_value.family == AF_INET) {
6447                 tunnel_filter_conf.ip_addr.ipv4_addr =
6448                         res->ip_value.addr.ipv4.s_addr;
6449                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6450         } else {
6451                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6452                         &(res->ip_value.addr.ipv6),
6453                         sizeof(struct in6_addr));
6454                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6455         }
6456
6457         if (!strcmp(res->filter_type, "imac-ivlan"))
6458                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6459         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6460                 tunnel_filter_conf.filter_type =
6461                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6462         else if (!strcmp(res->filter_type, "imac-tenid"))
6463                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6464         else if (!strcmp(res->filter_type, "imac"))
6465                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6466         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6467                 tunnel_filter_conf.filter_type =
6468                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6469         else {
6470                 printf("The filter type is not supported");
6471                 return;
6472         }
6473
6474         if (!strcmp(res->tunnel_type, "vxlan"))
6475                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6476         else if (!strcmp(res->tunnel_type, "nvgre"))
6477                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
6478         else {
6479                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
6480                 return;
6481         }
6482
6483         tunnel_filter_conf.tenant_id = res->tenant_id;
6484         tunnel_filter_conf.queue_id = res->queue_num;
6485         if (!strcmp(res->what, "add"))
6486                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6487                                         RTE_ETH_FILTER_TUNNEL,
6488                                         RTE_ETH_FILTER_ADD,
6489                                         &tunnel_filter_conf);
6490         else
6491                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6492                                         RTE_ETH_FILTER_TUNNEL,
6493                                         RTE_ETH_FILTER_DELETE,
6494                                         &tunnel_filter_conf);
6495         if (ret < 0)
6496                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6497                                 strerror(-ret));
6498
6499 }
6500 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6501         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6502         cmd, "tunnel_filter");
6503 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6504         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6505         what, "add#rm");
6506 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6507         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6508         port_id, UINT8);
6509 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6510         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6511         outer_mac);
6512 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6513         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6514         inner_mac);
6515 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6516         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6517         inner_vlan, UINT16);
6518 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6519         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6520         ip_value);
6521 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6522         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6523         tunnel_type, "vxlan#nvgre");
6524
6525 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6526         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6527         filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6528                 "imac#omac-imac-tenid");
6529 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6530         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6531         tenant_id, UINT32);
6532 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6533         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6534         queue_num, UINT16);
6535
6536 cmdline_parse_inst_t cmd_tunnel_filter = {
6537         .f = cmd_tunnel_filter_parsed,
6538         .data = (void *)0,
6539         .help_str = "add/rm tunnel filter of a port: "
6540                         "tunnel_filter add port_id outer_mac inner_mac ip "
6541                         "inner_vlan tunnel_type(vxlan|nvgre) filter_type "
6542                         "(imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6543                         "imac|omac-imac-tenid) "
6544                         "tenant_id queue_num",
6545         .tokens = {
6546                 (void *)&cmd_tunnel_filter_cmd,
6547                 (void *)&cmd_tunnel_filter_what,
6548                 (void *)&cmd_tunnel_filter_port_id,
6549                 (void *)&cmd_tunnel_filter_outer_mac,
6550                 (void *)&cmd_tunnel_filter_inner_mac,
6551                 (void *)&cmd_tunnel_filter_ip_value,
6552                 (void *)&cmd_tunnel_filter_innner_vlan,
6553                 (void *)&cmd_tunnel_filter_tunnel_type,
6554                 (void *)&cmd_tunnel_filter_filter_type,
6555                 (void *)&cmd_tunnel_filter_tenant_id,
6556                 (void *)&cmd_tunnel_filter_queue_num,
6557                 NULL,
6558         },
6559 };
6560
6561 /* *** CONFIGURE TUNNEL UDP PORT *** */
6562 struct cmd_tunnel_udp_config {
6563         cmdline_fixed_string_t cmd;
6564         cmdline_fixed_string_t what;
6565         uint16_t udp_port;
6566         uint8_t port_id;
6567 };
6568
6569 static void
6570 cmd_tunnel_udp_config_parsed(void *parsed_result,
6571                           __attribute__((unused)) struct cmdline *cl,
6572                           __attribute__((unused)) void *data)
6573 {
6574         struct cmd_tunnel_udp_config *res = parsed_result;
6575         struct rte_eth_udp_tunnel tunnel_udp;
6576         int ret;
6577
6578         tunnel_udp.udp_port = res->udp_port;
6579
6580         if (!strcmp(res->cmd, "rx_vxlan_port"))
6581                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6582
6583         if (!strcmp(res->what, "add"))
6584                 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp);
6585         else
6586                 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp);
6587
6588         if (ret < 0)
6589                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6590 }
6591
6592 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6593         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6594                                 cmd, "rx_vxlan_port");
6595 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6596         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6597                                 what, "add#rm");
6598 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6599         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6600                                 udp_port, UINT16);
6601 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6602         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6603                                 port_id, UINT8);
6604
6605 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6606         .f = cmd_tunnel_udp_config_parsed,
6607         .data = (void *)0,
6608         .help_str = "add/rm an tunneling UDP port filter: "
6609                         "rx_vxlan_port add udp_port port_id",
6610         .tokens = {
6611                 (void *)&cmd_tunnel_udp_config_cmd,
6612                 (void *)&cmd_tunnel_udp_config_what,
6613                 (void *)&cmd_tunnel_udp_config_udp_port,
6614                 (void *)&cmd_tunnel_udp_config_port_id,
6615                 NULL,
6616         },
6617 };
6618
6619 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6620 struct cmd_set_mirror_mask_result {
6621         cmdline_fixed_string_t set;
6622         cmdline_fixed_string_t port;
6623         uint8_t port_id;
6624         cmdline_fixed_string_t mirror;
6625         uint8_t rule_id;
6626         cmdline_fixed_string_t what;
6627         cmdline_fixed_string_t value;
6628         cmdline_fixed_string_t dstpool;
6629         uint8_t dstpool_id;
6630         cmdline_fixed_string_t on;
6631 };
6632
6633 cmdline_parse_token_string_t cmd_mirror_mask_set =
6634         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6635                                 set, "set");
6636 cmdline_parse_token_string_t cmd_mirror_mask_port =
6637         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6638                                 port, "port");
6639 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6640         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6641                                 port_id, UINT8);
6642 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6643         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6644                                 mirror, "mirror-rule");
6645 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6646         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6647                                 rule_id, UINT8);
6648 cmdline_parse_token_string_t cmd_mirror_mask_what =
6649         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6650                                 what, "pool-mirror-up#pool-mirror-down"
6651                                       "#vlan-mirror");
6652 cmdline_parse_token_string_t cmd_mirror_mask_value =
6653         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6654                                 value, NULL);
6655 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6656         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6657                                 dstpool, "dst-pool");
6658 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6659         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6660                                 dstpool_id, UINT8);
6661 cmdline_parse_token_string_t cmd_mirror_mask_on =
6662         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6663                                 on, "on#off");
6664
6665 static void
6666 cmd_set_mirror_mask_parsed(void *parsed_result,
6667                        __attribute__((unused)) struct cmdline *cl,
6668                        __attribute__((unused)) void *data)
6669 {
6670         int ret,nb_item,i;
6671         struct cmd_set_mirror_mask_result *res = parsed_result;
6672         struct rte_eth_mirror_conf mr_conf;
6673
6674         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6675
6676         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
6677
6678         mr_conf.dst_pool = res->dstpool_id;
6679
6680         if (!strcmp(res->what, "pool-mirror-up")) {
6681                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6682                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
6683         } else if (!strcmp(res->what, "pool-mirror-down")) {
6684                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6685                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
6686         } else if (!strcmp(res->what, "vlan-mirror")) {
6687                 mr_conf.rule_type = ETH_MIRROR_VLAN;
6688                 nb_item = parse_item_list(res->value, "vlan",
6689                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
6690                 if (nb_item <= 0)
6691                         return;
6692
6693                 for (i = 0; i < nb_item; i++) {
6694                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6695                                 printf("Invalid vlan_id: must be < 4096\n");
6696                                 return;
6697                         }
6698
6699                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6700                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6701                 }
6702         }
6703
6704         if (!strcmp(res->on, "on"))
6705                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6706                                                 res->rule_id, 1);
6707         else
6708                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6709                                                 res->rule_id, 0);
6710         if (ret < 0)
6711                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6712 }
6713
6714 cmdline_parse_inst_t cmd_set_mirror_mask = {
6715                 .f = cmd_set_mirror_mask_parsed,
6716                 .data = NULL,
6717                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
6718                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
6719                 .tokens = {
6720                         (void *)&cmd_mirror_mask_set,
6721                         (void *)&cmd_mirror_mask_port,
6722                         (void *)&cmd_mirror_mask_portid,
6723                         (void *)&cmd_mirror_mask_mirror,
6724                         (void *)&cmd_mirror_mask_ruleid,
6725                         (void *)&cmd_mirror_mask_what,
6726                         (void *)&cmd_mirror_mask_value,
6727                         (void *)&cmd_mirror_mask_dstpool,
6728                         (void *)&cmd_mirror_mask_poolid,
6729                         (void *)&cmd_mirror_mask_on,
6730                         NULL,
6731                 },
6732 };
6733
6734 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
6735 struct cmd_set_mirror_link_result {
6736         cmdline_fixed_string_t set;
6737         cmdline_fixed_string_t port;
6738         uint8_t port_id;
6739         cmdline_fixed_string_t mirror;
6740         uint8_t rule_id;
6741         cmdline_fixed_string_t what;
6742         cmdline_fixed_string_t dstpool;
6743         uint8_t dstpool_id;
6744         cmdline_fixed_string_t on;
6745 };
6746
6747 cmdline_parse_token_string_t cmd_mirror_link_set =
6748         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6749                                  set, "set");
6750 cmdline_parse_token_string_t cmd_mirror_link_port =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6752                                 port, "port");
6753 cmdline_parse_token_num_t cmd_mirror_link_portid =
6754         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6755                                 port_id, UINT8);
6756 cmdline_parse_token_string_t cmd_mirror_link_mirror =
6757         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6758                                 mirror, "mirror-rule");
6759 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
6760         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6761                             rule_id, UINT8);
6762 cmdline_parse_token_string_t cmd_mirror_link_what =
6763         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6764                                 what, "uplink-mirror#downlink-mirror");
6765 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
6766         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6767                                 dstpool, "dst-pool");
6768 cmdline_parse_token_num_t cmd_mirror_link_poolid =
6769         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
6770                                 dstpool_id, UINT8);
6771 cmdline_parse_token_string_t cmd_mirror_link_on =
6772         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
6773                                 on, "on#off");
6774
6775 static void
6776 cmd_set_mirror_link_parsed(void *parsed_result,
6777                        __attribute__((unused)) struct cmdline *cl,
6778                        __attribute__((unused)) void *data)
6779 {
6780         int ret;
6781         struct cmd_set_mirror_link_result *res = parsed_result;
6782         struct rte_eth_mirror_conf mr_conf;
6783
6784         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6785         if (!strcmp(res->what, "uplink-mirror"))
6786                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
6787         else
6788                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
6789
6790         mr_conf.dst_pool = res->dstpool_id;
6791
6792         if (!strcmp(res->on, "on"))
6793                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6794                                                 res->rule_id, 1);
6795         else
6796                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6797                                                 res->rule_id, 0);
6798
6799         /* check the return value and print it if is < 0 */
6800         if (ret < 0)
6801                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6802
6803 }
6804
6805 cmdline_parse_inst_t cmd_set_mirror_link = {
6806                 .f = cmd_set_mirror_link_parsed,
6807                 .data = NULL,
6808                 .help_str = "set port X mirror-rule Y uplink-mirror|"
6809                         "downlink-mirror dst-pool Z on|off",
6810                 .tokens = {
6811                         (void *)&cmd_mirror_link_set,
6812                         (void *)&cmd_mirror_link_port,
6813                         (void *)&cmd_mirror_link_portid,
6814                         (void *)&cmd_mirror_link_mirror,
6815                         (void *)&cmd_mirror_link_ruleid,
6816                         (void *)&cmd_mirror_link_what,
6817                         (void *)&cmd_mirror_link_dstpool,
6818                         (void *)&cmd_mirror_link_poolid,
6819                         (void *)&cmd_mirror_link_on,
6820                         NULL,
6821                 },
6822 };
6823
6824 /* *** RESET VM MIRROR RULE *** */
6825 struct cmd_rm_mirror_rule_result {
6826         cmdline_fixed_string_t reset;
6827         cmdline_fixed_string_t port;
6828         uint8_t port_id;
6829         cmdline_fixed_string_t mirror;
6830         uint8_t rule_id;
6831 };
6832
6833 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
6834         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6835                                  reset, "reset");
6836 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
6837         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6838                                 port, "port");
6839 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
6840         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
6841                                 port_id, UINT8);
6842 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
6843         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
6844                                 mirror, "mirror-rule");
6845 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
6846         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
6847                                 rule_id, UINT8);
6848
6849 static void
6850 cmd_reset_mirror_rule_parsed(void *parsed_result,
6851                        __attribute__((unused)) struct cmdline *cl,
6852                        __attribute__((unused)) void *data)
6853 {
6854         int ret;
6855         struct cmd_set_mirror_link_result *res = parsed_result;
6856         /* check rule_id */
6857         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
6858         if(ret < 0)
6859                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
6860 }
6861
6862 cmdline_parse_inst_t cmd_reset_mirror_rule = {
6863                 .f = cmd_reset_mirror_rule_parsed,
6864                 .data = NULL,
6865                 .help_str = "reset port X mirror-rule Y",
6866                 .tokens = {
6867                         (void *)&cmd_rm_mirror_rule_reset,
6868                         (void *)&cmd_rm_mirror_rule_port,
6869                         (void *)&cmd_rm_mirror_rule_portid,
6870                         (void *)&cmd_rm_mirror_rule_mirror,
6871                         (void *)&cmd_rm_mirror_rule_ruleid,
6872                         NULL,
6873                 },
6874 };
6875
6876 /* ******************************************************************************** */
6877
6878 struct cmd_dump_result {
6879         cmdline_fixed_string_t dump;
6880 };
6881
6882 static void
6883 dump_struct_sizes(void)
6884 {
6885 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
6886         DUMP_SIZE(struct rte_mbuf);
6887         DUMP_SIZE(struct rte_mempool);
6888         DUMP_SIZE(struct rte_ring);
6889 #undef DUMP_SIZE
6890 }
6891
6892 static void cmd_dump_parsed(void *parsed_result,
6893                             __attribute__((unused)) struct cmdline *cl,
6894                             __attribute__((unused)) void *data)
6895 {
6896         struct cmd_dump_result *res = parsed_result;
6897
6898         if (!strcmp(res->dump, "dump_physmem"))
6899                 rte_dump_physmem_layout(stdout);
6900         else if (!strcmp(res->dump, "dump_memzone"))
6901                 rte_memzone_dump(stdout);
6902         else if (!strcmp(res->dump, "dump_log_history"))
6903                 rte_log_dump_history(stdout);
6904         else if (!strcmp(res->dump, "dump_struct_sizes"))
6905                 dump_struct_sizes();
6906         else if (!strcmp(res->dump, "dump_ring"))
6907                 rte_ring_list_dump(stdout);
6908         else if (!strcmp(res->dump, "dump_mempool"))
6909                 rte_mempool_list_dump(stdout);
6910         else if (!strcmp(res->dump, "dump_devargs"))
6911                 rte_eal_devargs_dump(stdout);
6912 }
6913
6914 cmdline_parse_token_string_t cmd_dump_dump =
6915         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
6916                 "dump_physmem#"
6917                 "dump_memzone#"
6918                 "dump_log_history#"
6919                 "dump_struct_sizes#"
6920                 "dump_ring#"
6921                 "dump_mempool#"
6922                 "dump_devargs");
6923
6924 cmdline_parse_inst_t cmd_dump = {
6925         .f = cmd_dump_parsed,  /* function to call */
6926         .data = NULL,      /* 2nd arg of func */
6927         .help_str = "dump status",
6928         .tokens = {        /* token list, NULL terminated */
6929                 (void *)&cmd_dump_dump,
6930                 NULL,
6931         },
6932 };
6933
6934 /* ******************************************************************************** */
6935
6936 struct cmd_dump_one_result {
6937         cmdline_fixed_string_t dump;
6938         cmdline_fixed_string_t name;
6939 };
6940
6941 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
6942                                 __attribute__((unused)) void *data)
6943 {
6944         struct cmd_dump_one_result *res = parsed_result;
6945
6946         if (!strcmp(res->dump, "dump_ring")) {
6947                 struct rte_ring *r;
6948                 r = rte_ring_lookup(res->name);
6949                 if (r == NULL) {
6950                         cmdline_printf(cl, "Cannot find ring\n");
6951                         return;
6952                 }
6953                 rte_ring_dump(stdout, r);
6954         } else if (!strcmp(res->dump, "dump_mempool")) {
6955                 struct rte_mempool *mp;
6956                 mp = rte_mempool_lookup(res->name);
6957                 if (mp == NULL) {
6958                         cmdline_printf(cl, "Cannot find mempool\n");
6959                         return;
6960                 }
6961                 rte_mempool_dump(stdout, mp);
6962         }
6963 }
6964
6965 cmdline_parse_token_string_t cmd_dump_one_dump =
6966         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
6967                                  "dump_ring#dump_mempool");
6968
6969 cmdline_parse_token_string_t cmd_dump_one_name =
6970         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
6971
6972 cmdline_parse_inst_t cmd_dump_one = {
6973         .f = cmd_dump_one_parsed,  /* function to call */
6974         .data = NULL,      /* 2nd arg of func */
6975         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
6976         .tokens = {        /* token list, NULL terminated */
6977                 (void *)&cmd_dump_one_dump,
6978                 (void *)&cmd_dump_one_name,
6979                 NULL,
6980         },
6981 };
6982
6983 /* *** Add/Del syn filter *** */
6984 struct cmd_syn_filter_result {
6985         cmdline_fixed_string_t filter;
6986         uint8_t port_id;
6987         cmdline_fixed_string_t ops;
6988         cmdline_fixed_string_t priority;
6989         cmdline_fixed_string_t high;
6990         cmdline_fixed_string_t queue;
6991         uint16_t queue_id;
6992 };
6993
6994 static void
6995 cmd_syn_filter_parsed(void *parsed_result,
6996                         __attribute__((unused)) struct cmdline *cl,
6997                         __attribute__((unused)) void *data)
6998 {
6999         struct cmd_syn_filter_result *res = parsed_result;
7000         struct rte_eth_syn_filter syn_filter;
7001         int ret = 0;
7002
7003         ret = rte_eth_dev_filter_supported(res->port_id,
7004                                         RTE_ETH_FILTER_SYN);
7005         if (ret < 0) {
7006                 printf("syn filter is not supported on port %u.\n",
7007                                 res->port_id);
7008                 return;
7009         }
7010
7011         memset(&syn_filter, 0, sizeof(syn_filter));
7012
7013         if (!strcmp(res->ops, "add")) {
7014                 if (!strcmp(res->high, "high"))
7015                         syn_filter.hig_pri = 1;
7016                 else
7017                         syn_filter.hig_pri = 0;
7018
7019                 syn_filter.queue = res->queue_id;
7020                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7021                                                 RTE_ETH_FILTER_SYN,
7022                                                 RTE_ETH_FILTER_ADD,
7023                                                 &syn_filter);
7024         } else
7025                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7026                                                 RTE_ETH_FILTER_SYN,
7027                                                 RTE_ETH_FILTER_DELETE,
7028                                                 &syn_filter);
7029
7030         if (ret < 0)
7031                 printf("syn filter programming error: (%s)\n",
7032                                 strerror(-ret));
7033 }
7034
7035 cmdline_parse_token_string_t cmd_syn_filter_filter =
7036         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7037         filter, "syn_filter");
7038 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7039         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7040         port_id, UINT8);
7041 cmdline_parse_token_string_t cmd_syn_filter_ops =
7042         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7043         ops, "add#del");
7044 cmdline_parse_token_string_t cmd_syn_filter_priority =
7045         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7046                                 priority, "priority");
7047 cmdline_parse_token_string_t cmd_syn_filter_high =
7048         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7049                                 high, "high#low");
7050 cmdline_parse_token_string_t cmd_syn_filter_queue =
7051         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7052                                 queue, "queue");
7053 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7054         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7055                                 queue_id, UINT16);
7056
7057 cmdline_parse_inst_t cmd_syn_filter = {
7058         .f = cmd_syn_filter_parsed,
7059         .data = NULL,
7060         .help_str = "add/delete syn filter",
7061         .tokens = {
7062                 (void *)&cmd_syn_filter_filter,
7063                 (void *)&cmd_syn_filter_port_id,
7064                 (void *)&cmd_syn_filter_ops,
7065                 (void *)&cmd_syn_filter_priority,
7066                 (void *)&cmd_syn_filter_high,
7067                 (void *)&cmd_syn_filter_queue,
7068                 (void *)&cmd_syn_filter_queue_id,
7069                 NULL,
7070         },
7071 };
7072
7073 /* *** ADD/REMOVE A 2tuple FILTER *** */
7074 struct cmd_2tuple_filter_result {
7075         cmdline_fixed_string_t filter;
7076         uint8_t  port_id;
7077         cmdline_fixed_string_t ops;
7078         cmdline_fixed_string_t dst_port;
7079         uint16_t dst_port_value;
7080         cmdline_fixed_string_t protocol;
7081         uint8_t protocol_value;
7082         cmdline_fixed_string_t mask;
7083         uint8_t  mask_value;
7084         cmdline_fixed_string_t tcp_flags;
7085         uint8_t tcp_flags_value;
7086         cmdline_fixed_string_t priority;
7087         uint8_t  priority_value;
7088         cmdline_fixed_string_t queue;
7089         uint16_t  queue_id;
7090 };
7091
7092 static void
7093 cmd_2tuple_filter_parsed(void *parsed_result,
7094                         __attribute__((unused)) struct cmdline *cl,
7095                         __attribute__((unused)) void *data)
7096 {
7097         struct rte_eth_ntuple_filter filter;
7098         struct cmd_2tuple_filter_result *res = parsed_result;
7099         int ret = 0;
7100
7101         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7102         if (ret < 0) {
7103                 printf("ntuple filter is not supported on port %u.\n",
7104                         res->port_id);
7105                 return;
7106         }
7107
7108         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7109
7110         filter.flags = RTE_2TUPLE_FLAGS;
7111         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7112         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7113         filter.proto = res->protocol_value;
7114         filter.priority = res->priority_value;
7115         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7116                 printf("nonzero tcp_flags is only meaningful"
7117                         " when protocol is TCP.\n");
7118                 return;
7119         }
7120         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7121                 printf("invalid TCP flags.\n");
7122                 return;
7123         }
7124
7125         if (res->tcp_flags_value != 0) {
7126                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7127                 filter.tcp_flags = res->tcp_flags_value;
7128         }
7129
7130         /* need convert to big endian. */
7131         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7132         filter.queue = res->queue_id;
7133
7134         if (!strcmp(res->ops, "add"))
7135                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7136                                 RTE_ETH_FILTER_NTUPLE,
7137                                 RTE_ETH_FILTER_ADD,
7138                                 &filter);
7139         else
7140                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7141                                 RTE_ETH_FILTER_NTUPLE,
7142                                 RTE_ETH_FILTER_DELETE,
7143                                 &filter);
7144         if (ret < 0)
7145                 printf("2tuple filter programming error: (%s)\n",
7146                         strerror(-ret));
7147
7148 }
7149
7150 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7151         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7152                                  filter, "2tuple_filter");
7153 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7154         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7155                                 port_id, UINT8);
7156 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7157         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7158                                  ops, "add#del");
7159 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7160         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7161                                 dst_port, "dst_port");
7162 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7163         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7164                                 dst_port_value, UINT16);
7165 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7166         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7167                                 protocol, "protocol");
7168 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7169         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7170                                 protocol_value, UINT8);
7171 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7172         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7173                                 mask, "mask");
7174 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7175         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7176                                 mask_value, INT8);
7177 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7178         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7179                                 tcp_flags, "tcp_flags");
7180 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7181         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7182                                 tcp_flags_value, UINT8);
7183 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7184         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7185                                 priority, "priority");
7186 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7187         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7188                                 priority_value, UINT8);
7189 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7190         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7191                                 queue, "queue");
7192 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7193         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7194                                 queue_id, UINT16);
7195
7196 cmdline_parse_inst_t cmd_2tuple_filter = {
7197         .f = cmd_2tuple_filter_parsed,
7198         .data = NULL,
7199         .help_str = "add a 2tuple filter",
7200         .tokens = {
7201                 (void *)&cmd_2tuple_filter_filter,
7202                 (void *)&cmd_2tuple_filter_port_id,
7203                 (void *)&cmd_2tuple_filter_ops,
7204                 (void *)&cmd_2tuple_filter_dst_port,
7205                 (void *)&cmd_2tuple_filter_dst_port_value,
7206                 (void *)&cmd_2tuple_filter_protocol,
7207                 (void *)&cmd_2tuple_filter_protocol_value,
7208                 (void *)&cmd_2tuple_filter_mask,
7209                 (void *)&cmd_2tuple_filter_mask_value,
7210                 (void *)&cmd_2tuple_filter_tcp_flags,
7211                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7212                 (void *)&cmd_2tuple_filter_priority,
7213                 (void *)&cmd_2tuple_filter_priority_value,
7214                 (void *)&cmd_2tuple_filter_queue,
7215                 (void *)&cmd_2tuple_filter_queue_id,
7216                 NULL,
7217         },
7218 };
7219
7220 /* *** ADD/REMOVE A 5tuple FILTER *** */
7221 struct cmd_5tuple_filter_result {
7222         cmdline_fixed_string_t filter;
7223         uint8_t  port_id;
7224         cmdline_fixed_string_t ops;
7225         cmdline_fixed_string_t dst_ip;
7226         cmdline_ipaddr_t dst_ip_value;
7227         cmdline_fixed_string_t src_ip;
7228         cmdline_ipaddr_t src_ip_value;
7229         cmdline_fixed_string_t dst_port;
7230         uint16_t dst_port_value;
7231         cmdline_fixed_string_t src_port;
7232         uint16_t src_port_value;
7233         cmdline_fixed_string_t protocol;
7234         uint8_t protocol_value;
7235         cmdline_fixed_string_t mask;
7236         uint8_t  mask_value;
7237         cmdline_fixed_string_t tcp_flags;
7238         uint8_t tcp_flags_value;
7239         cmdline_fixed_string_t priority;
7240         uint8_t  priority_value;
7241         cmdline_fixed_string_t queue;
7242         uint16_t  queue_id;
7243 };
7244
7245 static void
7246 cmd_5tuple_filter_parsed(void *parsed_result,
7247                         __attribute__((unused)) struct cmdline *cl,
7248                         __attribute__((unused)) void *data)
7249 {
7250         struct rte_eth_ntuple_filter filter;
7251         struct cmd_5tuple_filter_result *res = parsed_result;
7252         int ret = 0;
7253
7254         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7255         if (ret < 0) {
7256                 printf("ntuple filter is not supported on port %u.\n",
7257                         res->port_id);
7258                 return;
7259         }
7260
7261         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7262
7263         filter.flags = RTE_5TUPLE_FLAGS;
7264         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7265         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7266         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7267         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7268         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7269         filter.proto = res->protocol_value;
7270         filter.priority = res->priority_value;
7271         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7272                 printf("nonzero tcp_flags is only meaningful"
7273                         " when protocol is TCP.\n");
7274                 return;
7275         }
7276         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7277                 printf("invalid TCP flags.\n");
7278                 return;
7279         }
7280
7281         if (res->tcp_flags_value != 0) {
7282                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7283                 filter.tcp_flags = res->tcp_flags_value;
7284         }
7285
7286         if (res->dst_ip_value.family == AF_INET)
7287                 /* no need to convert, already big endian. */
7288                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7289         else {
7290                 if (filter.dst_ip_mask == 0) {
7291                         printf("can not support ipv6 involved compare.\n");
7292                         return;
7293                 }
7294                 filter.dst_ip = 0;
7295         }
7296
7297         if (res->src_ip_value.family == AF_INET)
7298                 /* no need to convert, already big endian. */
7299                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7300         else {
7301                 if (filter.src_ip_mask == 0) {
7302                         printf("can not support ipv6 involved compare.\n");
7303                         return;
7304                 }
7305                 filter.src_ip = 0;
7306         }
7307         /* need convert to big endian. */
7308         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7309         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7310         filter.queue = res->queue_id;
7311
7312         if (!strcmp(res->ops, "add"))
7313                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7314                                 RTE_ETH_FILTER_NTUPLE,
7315                                 RTE_ETH_FILTER_ADD,
7316                                 &filter);
7317         else
7318                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7319                                 RTE_ETH_FILTER_NTUPLE,
7320                                 RTE_ETH_FILTER_DELETE,
7321                                 &filter);
7322         if (ret < 0)
7323                 printf("5tuple filter programming error: (%s)\n",
7324                         strerror(-ret));
7325 }
7326
7327 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7328         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7329                                  filter, "5tuple_filter");
7330 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7331         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7332                                 port_id, UINT8);
7333 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7334         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7335                                  ops, "add#del");
7336 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7337         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7338                                 dst_ip, "dst_ip");
7339 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7340         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7341                                 dst_ip_value);
7342 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7343         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7344                                 src_ip, "src_ip");
7345 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7346         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7347                                 src_ip_value);
7348 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7349         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7350                                 dst_port, "dst_port");
7351 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7352         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7353                                 dst_port_value, UINT16);
7354 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7355         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7356                                 src_port, "src_port");
7357 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7358         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7359                                 src_port_value, UINT16);
7360 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7361         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7362                                 protocol, "protocol");
7363 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7364         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7365                                 protocol_value, UINT8);
7366 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7367         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7368                                 mask, "mask");
7369 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7370         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7371                                 mask_value, INT8);
7372 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7373         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7374                                 tcp_flags, "tcp_flags");
7375 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7376         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7377                                 tcp_flags_value, UINT8);
7378 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7379         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7380                                 priority, "priority");
7381 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7382         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7383                                 priority_value, UINT8);
7384 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7385         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7386                                 queue, "queue");
7387 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7388         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7389                                 queue_id, UINT16);
7390
7391 cmdline_parse_inst_t cmd_5tuple_filter = {
7392         .f = cmd_5tuple_filter_parsed,
7393         .data = NULL,
7394         .help_str = "add/del a 5tuple filter",
7395         .tokens = {
7396                 (void *)&cmd_5tuple_filter_filter,
7397                 (void *)&cmd_5tuple_filter_port_id,
7398                 (void *)&cmd_5tuple_filter_ops,
7399                 (void *)&cmd_5tuple_filter_dst_ip,
7400                 (void *)&cmd_5tuple_filter_dst_ip_value,
7401                 (void *)&cmd_5tuple_filter_src_ip,
7402                 (void *)&cmd_5tuple_filter_src_ip_value,
7403                 (void *)&cmd_5tuple_filter_dst_port,
7404                 (void *)&cmd_5tuple_filter_dst_port_value,
7405                 (void *)&cmd_5tuple_filter_src_port,
7406                 (void *)&cmd_5tuple_filter_src_port_value,
7407                 (void *)&cmd_5tuple_filter_protocol,
7408                 (void *)&cmd_5tuple_filter_protocol_value,
7409                 (void *)&cmd_5tuple_filter_mask,
7410                 (void *)&cmd_5tuple_filter_mask_value,
7411                 (void *)&cmd_5tuple_filter_tcp_flags,
7412                 (void *)&cmd_5tuple_filter_tcp_flags_value,
7413                 (void *)&cmd_5tuple_filter_priority,
7414                 (void *)&cmd_5tuple_filter_priority_value,
7415                 (void *)&cmd_5tuple_filter_queue,
7416                 (void *)&cmd_5tuple_filter_queue_id,
7417                 NULL,
7418         },
7419 };
7420
7421 /* *** ADD/REMOVE A flex FILTER *** */
7422 struct cmd_flex_filter_result {
7423         cmdline_fixed_string_t filter;
7424         cmdline_fixed_string_t ops;
7425         uint8_t port_id;
7426         cmdline_fixed_string_t len;
7427         uint8_t len_value;
7428         cmdline_fixed_string_t bytes;
7429         cmdline_fixed_string_t bytes_value;
7430         cmdline_fixed_string_t mask;
7431         cmdline_fixed_string_t mask_value;
7432         cmdline_fixed_string_t priority;
7433         uint8_t priority_value;
7434         cmdline_fixed_string_t queue;
7435         uint16_t queue_id;
7436 };
7437
7438 static int xdigit2val(unsigned char c)
7439 {
7440         int val;
7441         if (isdigit(c))
7442                 val = c - '0';
7443         else if (isupper(c))
7444                 val = c - 'A' + 10;
7445         else
7446                 val = c - 'a' + 10;
7447         return val;
7448 }
7449
7450 static void
7451 cmd_flex_filter_parsed(void *parsed_result,
7452                           __attribute__((unused)) struct cmdline *cl,
7453                           __attribute__((unused)) void *data)
7454 {
7455         int ret = 0;
7456         struct rte_eth_flex_filter filter;
7457         struct cmd_flex_filter_result *res = parsed_result;
7458         char *bytes_ptr, *mask_ptr;
7459         uint16_t len, i, j = 0;
7460         char c;
7461         int val;
7462         uint8_t byte = 0;
7463
7464         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
7465                 printf("the len exceed the max length 128\n");
7466                 return;
7467         }
7468         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
7469         filter.len = res->len_value;
7470         filter.priority = res->priority_value;
7471         filter.queue = res->queue_id;
7472         bytes_ptr = res->bytes_value;
7473         mask_ptr = res->mask_value;
7474
7475          /* translate bytes string to array. */
7476         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7477                 (bytes_ptr[1] == 'X')))
7478                 bytes_ptr += 2;
7479         len = strnlen(bytes_ptr, res->len_value * 2);
7480         if (len == 0 || (len % 8 != 0)) {
7481                 printf("please check len and bytes input\n");
7482                 return;
7483         }
7484         for (i = 0; i < len; i++) {
7485                 c = bytes_ptr[i];
7486                 if (isxdigit(c) == 0) {
7487                         /* invalid characters. */
7488                         printf("invalid input\n");
7489                         return;
7490                 }
7491                 val = xdigit2val(c);
7492                 if (i % 2) {
7493                         byte |= val;
7494                         filter.bytes[j] = byte;
7495                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
7496                         j++;
7497                         byte = 0;
7498                 } else
7499                         byte |= val << 4;
7500         }
7501         printf("\n");
7502          /* translate mask string to uint8_t array. */
7503         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7504                 (mask_ptr[1] == 'X')))
7505                 mask_ptr += 2;
7506         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
7507         if (len == 0) {
7508                 printf("invalid input\n");
7509                 return;
7510         }
7511         j = 0;
7512         byte = 0;
7513         for (i = 0; i < len; i++) {
7514                 c = mask_ptr[i];
7515                 if (isxdigit(c) == 0) {
7516                         /* invalid characters. */
7517                         printf("invalid input\n");
7518                         return;
7519                 }
7520                 val = xdigit2val(c);
7521                 if (i % 2) {
7522                         byte |= val;
7523                         filter.mask[j] = byte;
7524                         printf("mask[%d]:%02x ", j, filter.mask[j]);
7525                         j++;
7526                         byte = 0;
7527                 } else
7528                         byte |= val << 4;
7529         }
7530         printf("\n");
7531
7532         if (!strcmp(res->ops, "add"))
7533                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7534                                 RTE_ETH_FILTER_FLEXIBLE,
7535                                 RTE_ETH_FILTER_ADD,
7536                                 &filter);
7537         else
7538                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7539                                 RTE_ETH_FILTER_FLEXIBLE,
7540                                 RTE_ETH_FILTER_DELETE,
7541                                 &filter);
7542
7543         if (ret < 0)
7544                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7545 }
7546
7547 cmdline_parse_token_string_t cmd_flex_filter_filter =
7548         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7549                                 filter, "flex_filter");
7550 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7551         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7552                                 port_id, UINT8);
7553 cmdline_parse_token_string_t cmd_flex_filter_ops =
7554         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7555                                 ops, "add#del");
7556 cmdline_parse_token_string_t cmd_flex_filter_len =
7557         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7558                                 len, "len");
7559 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7560         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7561                                 len_value, UINT8);
7562 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7563         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7564                                 bytes, "bytes");
7565 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7566         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7567                                 bytes_value, NULL);
7568 cmdline_parse_token_string_t cmd_flex_filter_mask =
7569         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7570                                 mask, "mask");
7571 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7572         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7573                                 mask_value, NULL);
7574 cmdline_parse_token_string_t cmd_flex_filter_priority =
7575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7576                                 priority, "priority");
7577 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7579                                 priority_value, UINT8);
7580 cmdline_parse_token_string_t cmd_flex_filter_queue =
7581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7582                                 queue, "queue");
7583 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7584         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7585                                 queue_id, UINT16);
7586 cmdline_parse_inst_t cmd_flex_filter = {
7587         .f = cmd_flex_filter_parsed,
7588         .data = NULL,
7589         .help_str = "add/del a flex filter",
7590         .tokens = {
7591                 (void *)&cmd_flex_filter_filter,
7592                 (void *)&cmd_flex_filter_port_id,
7593                 (void *)&cmd_flex_filter_ops,
7594                 (void *)&cmd_flex_filter_len,
7595                 (void *)&cmd_flex_filter_len_value,
7596                 (void *)&cmd_flex_filter_bytes,
7597                 (void *)&cmd_flex_filter_bytes_value,
7598                 (void *)&cmd_flex_filter_mask,
7599                 (void *)&cmd_flex_filter_mask_value,
7600                 (void *)&cmd_flex_filter_priority,
7601                 (void *)&cmd_flex_filter_priority_value,
7602                 (void *)&cmd_flex_filter_queue,
7603                 (void *)&cmd_flex_filter_queue_id,
7604                 NULL,
7605         },
7606 };
7607
7608 /* *** Filters Control *** */
7609
7610 /* *** deal with ethertype filter *** */
7611 struct cmd_ethertype_filter_result {
7612         cmdline_fixed_string_t filter;
7613         uint8_t port_id;
7614         cmdline_fixed_string_t ops;
7615         cmdline_fixed_string_t mac;
7616         struct ether_addr mac_addr;
7617         cmdline_fixed_string_t ethertype;
7618         uint16_t ethertype_value;
7619         cmdline_fixed_string_t drop;
7620         cmdline_fixed_string_t queue;
7621         uint16_t  queue_id;
7622 };
7623
7624 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7625         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7626                                  filter, "ethertype_filter");
7627 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7628         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7629                               port_id, UINT8);
7630 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
7631         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7632                                  ops, "add#del");
7633 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
7634         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7635                                  mac, "mac_addr#mac_ignr");
7636 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
7637         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
7638                                      mac_addr);
7639 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
7640         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7641                                  ethertype, "ethertype");
7642 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
7643         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7644                               ethertype_value, UINT16);
7645 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
7646         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7647                                  drop, "drop#fwd");
7648 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
7649         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7650                                  queue, "queue");
7651 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
7652         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7653                               queue_id, UINT16);
7654
7655 static void
7656 cmd_ethertype_filter_parsed(void *parsed_result,
7657                           __attribute__((unused)) struct cmdline *cl,
7658                           __attribute__((unused)) void *data)
7659 {
7660         struct cmd_ethertype_filter_result *res = parsed_result;
7661         struct rte_eth_ethertype_filter filter;
7662         int ret = 0;
7663
7664         ret = rte_eth_dev_filter_supported(res->port_id,
7665                         RTE_ETH_FILTER_ETHERTYPE);
7666         if (ret < 0) {
7667                 printf("ethertype filter is not supported on port %u.\n",
7668                         res->port_id);
7669                 return;
7670         }
7671
7672         memset(&filter, 0, sizeof(filter));
7673         if (!strcmp(res->mac, "mac_addr")) {
7674                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
7675                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
7676                         sizeof(struct ether_addr));
7677         }
7678         if (!strcmp(res->drop, "drop"))
7679                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
7680         filter.ether_type = res->ethertype_value;
7681         filter.queue = res->queue_id;
7682
7683         if (!strcmp(res->ops, "add"))
7684                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7685                                 RTE_ETH_FILTER_ETHERTYPE,
7686                                 RTE_ETH_FILTER_ADD,
7687                                 &filter);
7688         else
7689                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7690                                 RTE_ETH_FILTER_ETHERTYPE,
7691                                 RTE_ETH_FILTER_DELETE,
7692                                 &filter);
7693         if (ret < 0)
7694                 printf("ethertype filter programming error: (%s)\n",
7695                         strerror(-ret));
7696 }
7697
7698 cmdline_parse_inst_t cmd_ethertype_filter = {
7699         .f = cmd_ethertype_filter_parsed,
7700         .data = NULL,
7701         .help_str = "add or delete an ethertype filter entry",
7702         .tokens = {
7703                 (void *)&cmd_ethertype_filter_filter,
7704                 (void *)&cmd_ethertype_filter_port_id,
7705                 (void *)&cmd_ethertype_filter_ops,
7706                 (void *)&cmd_ethertype_filter_mac,
7707                 (void *)&cmd_ethertype_filter_mac_addr,
7708                 (void *)&cmd_ethertype_filter_ethertype,
7709                 (void *)&cmd_ethertype_filter_ethertype_value,
7710                 (void *)&cmd_ethertype_filter_drop,
7711                 (void *)&cmd_ethertype_filter_queue,
7712                 (void *)&cmd_ethertype_filter_queue_id,
7713                 NULL,
7714         },
7715 };
7716
7717 /* *** deal with flow director filter *** */
7718 struct cmd_flow_director_result {
7719         cmdline_fixed_string_t flow_director_filter;
7720         uint8_t port_id;
7721         cmdline_fixed_string_t ops;
7722         cmdline_fixed_string_t flow;
7723         cmdline_fixed_string_t flow_type;
7724         cmdline_fixed_string_t src;
7725         cmdline_ipaddr_t ip_src;
7726         uint16_t port_src;
7727         cmdline_fixed_string_t dst;
7728         cmdline_ipaddr_t ip_dst;
7729         uint16_t port_dst;
7730         cmdline_fixed_string_t verify_tag;
7731         uint32_t verify_tag_value;
7732         cmdline_fixed_string_t vlan;
7733         uint16_t vlan_value;
7734         cmdline_fixed_string_t flexbytes;
7735         cmdline_fixed_string_t flexbytes_value;
7736         cmdline_fixed_string_t drop;
7737         cmdline_fixed_string_t queue;
7738         uint16_t  queue_id;
7739         cmdline_fixed_string_t fd_id;
7740         uint32_t  fd_id_value;
7741 };
7742
7743 static inline int
7744 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
7745 {
7746         char s[256];
7747         const char *p, *p0 = q_arg;
7748         char *end;
7749         unsigned long int_fld;
7750         char *str_fld[max_num];
7751         int i;
7752         unsigned size;
7753         int ret = -1;
7754
7755         p = strchr(p0, '(');
7756         if (p == NULL)
7757                 return -1;
7758         ++p;
7759         p0 = strchr(p, ')');
7760         if (p0 == NULL)
7761                 return -1;
7762
7763         size = p0 - p;
7764         if (size >= sizeof(s))
7765                 return -1;
7766
7767         snprintf(s, sizeof(s), "%.*s", size, p);
7768         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
7769         if (ret < 0 || ret > max_num)
7770                 return -1;
7771         for (i = 0; i < ret; i++) {
7772                 errno = 0;
7773                 int_fld = strtoul(str_fld[i], &end, 0);
7774                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
7775                         return -1;
7776                 flexbytes[i] = (uint8_t)int_fld;
7777         }
7778         return ret;
7779 }
7780
7781 static uint16_t
7782 str2flowtype(char *string)
7783 {
7784         uint8_t i = 0;
7785         static const struct {
7786                 char str[32];
7787                 uint16_t type;
7788         } flowtype_str[] = {
7789                 {"raw", RTE_ETH_FLOW_RAW},
7790                 {"ipv4", RTE_ETH_FLOW_IPV4},
7791                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
7792                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
7793                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
7794                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
7795                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
7796                 {"ipv6", RTE_ETH_FLOW_IPV6},
7797                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
7798                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
7799                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
7800                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
7801                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
7802                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
7803         };
7804
7805         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
7806                 if (!strcmp(flowtype_str[i].str, string))
7807                         return flowtype_str[i].type;
7808         }
7809         return RTE_ETH_FLOW_UNKNOWN;
7810 }
7811
7812 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
7813 do { \
7814         if ((ip_addr).family == AF_INET) \
7815                 (ip) = (ip_addr).addr.ipv4.s_addr; \
7816         else { \
7817                 printf("invalid parameter.\n"); \
7818                 return; \
7819         } \
7820 } while (0)
7821
7822 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
7823 do { \
7824         if ((ip_addr).family == AF_INET6) \
7825                 (void)rte_memcpy(&(ip), \
7826                                  &((ip_addr).addr.ipv6), \
7827                                  sizeof(struct in6_addr)); \
7828         else { \
7829                 printf("invalid parameter.\n"); \
7830                 return; \
7831         } \
7832 } while (0)
7833
7834 static void
7835 cmd_flow_director_filter_parsed(void *parsed_result,
7836                           __attribute__((unused)) struct cmdline *cl,
7837                           __attribute__((unused)) void *data)
7838 {
7839         struct cmd_flow_director_result *res = parsed_result;
7840         struct rte_eth_fdir_filter entry;
7841         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
7842         int ret = 0;
7843
7844         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
7845         if (ret < 0) {
7846                 printf("flow director is not supported on port %u.\n",
7847                         res->port_id);
7848                 return;
7849         }
7850         memset(flexbytes, 0, sizeof(flexbytes));
7851         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
7852         ret = parse_flexbytes(res->flexbytes_value,
7853                                         flexbytes,
7854                                         RTE_ETH_FDIR_MAX_FLEXLEN);
7855         if (ret < 0) {
7856                 printf("error: Cannot parse flexbytes input.\n");
7857                 return;
7858         }
7859
7860         entry.input.flow_type = str2flowtype(res->flow_type);
7861         switch (entry.input.flow_type) {
7862         case RTE_ETH_FLOW_FRAG_IPV4:
7863         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
7864         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
7865         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
7866                 IPV4_ADDR_TO_UINT(res->ip_dst,
7867                         entry.input.flow.ip4_flow.dst_ip);
7868                 IPV4_ADDR_TO_UINT(res->ip_src,
7869                         entry.input.flow.ip4_flow.src_ip);
7870                 /* need convert to big endian. */
7871                 entry.input.flow.udp4_flow.dst_port =
7872                                 rte_cpu_to_be_16(res->port_dst);
7873                 entry.input.flow.udp4_flow.src_port =
7874                                 rte_cpu_to_be_16(res->port_src);
7875                 break;
7876         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
7877                 IPV4_ADDR_TO_UINT(res->ip_dst,
7878                         entry.input.flow.sctp4_flow.ip.dst_ip);
7879                 IPV4_ADDR_TO_UINT(res->ip_src,
7880                         entry.input.flow.sctp4_flow.ip.src_ip);
7881                 /* need convert to big endian. */
7882                 entry.input.flow.sctp4_flow.verify_tag =
7883                                 rte_cpu_to_be_32(res->verify_tag_value);
7884                 break;
7885         case RTE_ETH_FLOW_FRAG_IPV6:
7886         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
7887         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
7888         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
7889                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
7890                         entry.input.flow.ipv6_flow.dst_ip);
7891                 IPV6_ADDR_TO_ARRAY(res->ip_src,
7892                         entry.input.flow.ipv6_flow.src_ip);
7893                 /* need convert to big endian. */
7894                 entry.input.flow.udp6_flow.dst_port =
7895                                 rte_cpu_to_be_16(res->port_dst);
7896                 entry.input.flow.udp6_flow.src_port =
7897                                 rte_cpu_to_be_16(res->port_src);
7898                 break;
7899         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
7900                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
7901                         entry.input.flow.sctp6_flow.ip.dst_ip);
7902                 IPV6_ADDR_TO_ARRAY(res->ip_src,
7903                         entry.input.flow.sctp6_flow.ip.src_ip);
7904                 /* need convert to big endian. */
7905                 entry.input.flow.sctp6_flow.verify_tag =
7906                                 rte_cpu_to_be_32(res->verify_tag_value);
7907                 break;
7908         default:
7909                 printf("invalid parameter.\n");
7910                 return;
7911         }
7912         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
7913                    flexbytes,
7914                    RTE_ETH_FDIR_MAX_FLEXLEN);
7915
7916         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
7917
7918         entry.action.flex_off = 0;  /*use 0 by default */
7919         if (!strcmp(res->drop, "drop"))
7920                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
7921         else
7922                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
7923         /* set to report FD ID by default */
7924         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
7925         entry.action.rx_queue = res->queue_id;
7926         entry.soft_id = res->fd_id_value;
7927         if (!strcmp(res->ops, "add"))
7928                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
7929                                              RTE_ETH_FILTER_ADD, &entry);
7930         else if (!strcmp(res->ops, "del"))
7931                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
7932                                              RTE_ETH_FILTER_DELETE, &entry);
7933         else
7934                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
7935                                              RTE_ETH_FILTER_UPDATE, &entry);
7936         if (ret < 0)
7937                 printf("flow director programming error: (%s)\n",
7938                         strerror(-ret));
7939 }
7940
7941 cmdline_parse_token_string_t cmd_flow_director_filter =
7942         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7943                                  flow_director_filter, "flow_director_filter");
7944 cmdline_parse_token_num_t cmd_flow_director_port_id =
7945         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
7946                               port_id, UINT8);
7947 cmdline_parse_token_string_t cmd_flow_director_ops =
7948         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7949                                  ops, "add#del#update");
7950 cmdline_parse_token_string_t cmd_flow_director_flow =
7951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7952                                  flow, "flow");
7953 cmdline_parse_token_string_t cmd_flow_director_flow_type =
7954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7955                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
7956                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp");
7957 cmdline_parse_token_string_t cmd_flow_director_src =
7958         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7959                                  src, "src");
7960 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
7961         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
7962                                  ip_src);
7963 cmdline_parse_token_num_t cmd_flow_director_port_src =
7964         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
7965                               port_src, UINT16);
7966 cmdline_parse_token_string_t cmd_flow_director_dst =
7967         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7968                                  dst, "dst");
7969 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
7970         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
7971                                  ip_dst);
7972 cmdline_parse_token_num_t cmd_flow_director_port_dst =
7973         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
7974                               port_dst, UINT16);
7975 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
7976         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7977                                   verify_tag, "verify_tag");
7978 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
7979         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
7980                               verify_tag_value, UINT32);
7981 cmdline_parse_token_string_t cmd_flow_director_vlan =
7982         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7983                                  vlan, "vlan");
7984 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
7985         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
7986                               vlan_value, UINT16);
7987 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
7988         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7989                                  flexbytes, "flexbytes");
7990 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
7991         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7992                               flexbytes_value, NULL);
7993 cmdline_parse_token_string_t cmd_flow_director_drop =
7994         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7995                                  drop, "drop#fwd");
7996 cmdline_parse_token_string_t cmd_flow_director_queue =
7997         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
7998                                  queue, "queue");
7999 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8000         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8001                               queue_id, UINT16);
8002 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8003         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8004                                  fd_id, "fd_id");
8005 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8006         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8007                               fd_id_value, UINT32);
8008
8009 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8010         .f = cmd_flow_director_filter_parsed,
8011         .data = NULL,
8012         .help_str = "add or delete an ip flow director entry on NIC",
8013         .tokens = {
8014                 (void *)&cmd_flow_director_filter,
8015                 (void *)&cmd_flow_director_port_id,
8016                 (void *)&cmd_flow_director_ops,
8017                 (void *)&cmd_flow_director_flow,
8018                 (void *)&cmd_flow_director_flow_type,
8019                 (void *)&cmd_flow_director_src,
8020                 (void *)&cmd_flow_director_ip_src,
8021                 (void *)&cmd_flow_director_dst,
8022                 (void *)&cmd_flow_director_ip_dst,
8023                 (void *)&cmd_flow_director_vlan,
8024                 (void *)&cmd_flow_director_vlan_value,
8025                 (void *)&cmd_flow_director_flexbytes,
8026                 (void *)&cmd_flow_director_flexbytes_value,
8027                 (void *)&cmd_flow_director_drop,
8028                 (void *)&cmd_flow_director_queue,
8029                 (void *)&cmd_flow_director_queue_id,
8030                 (void *)&cmd_flow_director_fd_id,
8031                 (void *)&cmd_flow_director_fd_id_value,
8032                 NULL,
8033         },
8034 };
8035
8036 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8037         .f = cmd_flow_director_filter_parsed,
8038         .data = NULL,
8039         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8040         .tokens = {
8041                 (void *)&cmd_flow_director_filter,
8042                 (void *)&cmd_flow_director_port_id,
8043                 (void *)&cmd_flow_director_ops,
8044                 (void *)&cmd_flow_director_flow,
8045                 (void *)&cmd_flow_director_flow_type,
8046                 (void *)&cmd_flow_director_src,
8047                 (void *)&cmd_flow_director_ip_src,
8048                 (void *)&cmd_flow_director_port_src,
8049                 (void *)&cmd_flow_director_dst,
8050                 (void *)&cmd_flow_director_ip_dst,
8051                 (void *)&cmd_flow_director_port_dst,
8052                 (void *)&cmd_flow_director_vlan,
8053                 (void *)&cmd_flow_director_vlan_value,
8054                 (void *)&cmd_flow_director_flexbytes,
8055                 (void *)&cmd_flow_director_flexbytes_value,
8056                 (void *)&cmd_flow_director_drop,
8057                 (void *)&cmd_flow_director_queue,
8058                 (void *)&cmd_flow_director_queue_id,
8059                 (void *)&cmd_flow_director_fd_id,
8060                 (void *)&cmd_flow_director_fd_id_value,
8061                 NULL,
8062         },
8063 };
8064
8065 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8066         .f = cmd_flow_director_filter_parsed,
8067         .data = NULL,
8068         .help_str = "add or delete a sctp flow director entry on NIC",
8069         .tokens = {
8070                 (void *)&cmd_flow_director_filter,
8071                 (void *)&cmd_flow_director_port_id,
8072                 (void *)&cmd_flow_director_ops,
8073                 (void *)&cmd_flow_director_flow,
8074                 (void *)&cmd_flow_director_flow_type,
8075                 (void *)&cmd_flow_director_src,
8076                 (void *)&cmd_flow_director_ip_src,
8077                 (void *)&cmd_flow_director_port_dst,
8078                 (void *)&cmd_flow_director_dst,
8079                 (void *)&cmd_flow_director_ip_dst,
8080                 (void *)&cmd_flow_director_port_dst,
8081                 (void *)&cmd_flow_director_verify_tag,
8082                 (void *)&cmd_flow_director_verify_tag_value,
8083                 (void *)&cmd_flow_director_vlan,
8084                 (void *)&cmd_flow_director_vlan_value,
8085                 (void *)&cmd_flow_director_flexbytes,
8086                 (void *)&cmd_flow_director_flexbytes_value,
8087                 (void *)&cmd_flow_director_drop,
8088                 (void *)&cmd_flow_director_queue,
8089                 (void *)&cmd_flow_director_queue_id,
8090                 (void *)&cmd_flow_director_fd_id,
8091                 (void *)&cmd_flow_director_fd_id_value,
8092                 NULL,
8093         },
8094 };
8095
8096 struct cmd_flush_flow_director_result {
8097         cmdline_fixed_string_t flush_flow_director;
8098         uint8_t port_id;
8099 };
8100
8101 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8102         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8103                                  flush_flow_director, "flush_flow_director");
8104 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8105         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8106                               port_id, UINT8);
8107
8108 static void
8109 cmd_flush_flow_director_parsed(void *parsed_result,
8110                           __attribute__((unused)) struct cmdline *cl,
8111                           __attribute__((unused)) void *data)
8112 {
8113         struct cmd_flow_director_result *res = parsed_result;
8114         int ret = 0;
8115
8116         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8117         if (ret < 0) {
8118                 printf("flow director is not supported on port %u.\n",
8119                         res->port_id);
8120                 return;
8121         }
8122
8123         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8124                         RTE_ETH_FILTER_FLUSH, NULL);
8125         if (ret < 0)
8126                 printf("flow director table flushing error: (%s)\n",
8127                         strerror(-ret));
8128 }
8129
8130 cmdline_parse_inst_t cmd_flush_flow_director = {
8131         .f = cmd_flush_flow_director_parsed,
8132         .data = NULL,
8133         .help_str = "flush all flow director entries of a device on NIC",
8134         .tokens = {
8135                 (void *)&cmd_flush_flow_director_flush,
8136                 (void *)&cmd_flush_flow_director_port_id,
8137                 NULL,
8138         },
8139 };
8140
8141 /* *** deal with flow director mask *** */
8142 struct cmd_flow_director_mask_result {
8143         cmdline_fixed_string_t flow_director_mask;
8144         uint8_t port_id;
8145         cmdline_fixed_string_t vlan;
8146         uint16_t vlan_value;
8147         cmdline_fixed_string_t src_mask;
8148         cmdline_ipaddr_t ipv4_src;
8149         cmdline_ipaddr_t ipv6_src;
8150         uint16_t port_src;
8151         cmdline_fixed_string_t dst_mask;
8152         cmdline_ipaddr_t ipv4_dst;
8153         cmdline_ipaddr_t ipv6_dst;
8154         uint16_t port_dst;
8155 };
8156
8157 static void
8158 cmd_flow_director_mask_parsed(void *parsed_result,
8159                           __attribute__((unused)) struct cmdline *cl,
8160                           __attribute__((unused)) void *data)
8161 {
8162         struct cmd_flow_director_mask_result *res = parsed_result;
8163         struct rte_eth_fdir_masks *mask;
8164         struct rte_port *port;
8165
8166         if (res->port_id > nb_ports) {
8167                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8168                 return;
8169         }
8170
8171         port = &ports[res->port_id];
8172         /** Check if the port is not started **/
8173         if (port->port_status != RTE_PORT_STOPPED) {
8174                 printf("Please stop port %d first\n", res->port_id);
8175                 return;
8176         }
8177         mask = &port->dev_conf.fdir_conf.mask;
8178
8179         mask->vlan_tci_mask = res->vlan_value;
8180         IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
8181         IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
8182         IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
8183         IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
8184         mask->src_port_mask = res->port_src;
8185         mask->dst_port_mask = res->port_dst;
8186
8187         cmd_reconfig_device_queue(res->port_id, 1, 1);
8188 }
8189
8190 cmdline_parse_token_string_t cmd_flow_director_mask =
8191         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8192                                  flow_director_mask, "flow_director_mask");
8193 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
8194         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8195                               port_id, UINT8);
8196 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
8197         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8198                                  vlan, "vlan");
8199 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
8200         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8201                               vlan_value, UINT16);
8202 cmdline_parse_token_string_t cmd_flow_director_mask_src =
8203         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8204                                  src_mask, "src_mask");
8205 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
8206         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8207                                  ipv4_src);
8208 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
8209         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8210                                  ipv6_src);
8211 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
8212         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8213                               port_src, UINT16);
8214 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
8215         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8216                                  dst_mask, "dst_mask");
8217 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
8218         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8219                                  ipv4_dst);
8220 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
8221         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8222                                  ipv6_dst);
8223 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
8224         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8225                               port_dst, UINT16);
8226 cmdline_parse_inst_t cmd_set_flow_director_mask = {
8227         .f = cmd_flow_director_mask_parsed,
8228         .data = NULL,
8229         .help_str = "set flow director's mask on NIC",
8230         .tokens = {
8231                 (void *)&cmd_flow_director_mask,
8232                 (void *)&cmd_flow_director_mask_port_id,
8233                 (void *)&cmd_flow_director_mask_vlan,
8234                 (void *)&cmd_flow_director_mask_vlan_value,
8235                 (void *)&cmd_flow_director_mask_src,
8236                 (void *)&cmd_flow_director_mask_ipv4_src,
8237                 (void *)&cmd_flow_director_mask_ipv6_src,
8238                 (void *)&cmd_flow_director_mask_port_src,
8239                 (void *)&cmd_flow_director_mask_dst,
8240                 (void *)&cmd_flow_director_mask_ipv4_dst,
8241                 (void *)&cmd_flow_director_mask_ipv6_dst,
8242                 (void *)&cmd_flow_director_mask_port_dst,
8243                 NULL,
8244         },
8245 };
8246
8247 /* *** deal with flow director mask on flexible payload *** */
8248 struct cmd_flow_director_flex_mask_result {
8249         cmdline_fixed_string_t flow_director_flexmask;
8250         uint8_t port_id;
8251         cmdline_fixed_string_t flow;
8252         cmdline_fixed_string_t flow_type;
8253         cmdline_fixed_string_t mask;
8254 };
8255
8256 static void
8257 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8258                           __attribute__((unused)) struct cmdline *cl,
8259                           __attribute__((unused)) void *data)
8260 {
8261         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8262         struct rte_eth_fdir_info fdir_info;
8263         struct rte_eth_fdir_flex_mask flex_mask;
8264         struct rte_port *port;
8265         uint32_t flow_type_mask;
8266         uint16_t i;
8267         int ret;
8268
8269         if (res->port_id > nb_ports) {
8270                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8271                 return;
8272         }
8273
8274         port = &ports[res->port_id];
8275         /** Check if the port is not started **/
8276         if (port->port_status != RTE_PORT_STOPPED) {
8277                 printf("Please stop port %d first\n", res->port_id);
8278                 return;
8279         }
8280
8281         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8282         ret = parse_flexbytes(res->mask,
8283                         flex_mask.mask,
8284                         RTE_ETH_FDIR_MAX_FLEXLEN);
8285         if (ret < 0) {
8286                 printf("error: Cannot parse mask input.\n");
8287                 return;
8288         }
8289
8290         memset(&fdir_info, 0, sizeof(fdir_info));
8291         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8292                                 RTE_ETH_FILTER_INFO, &fdir_info);
8293         if (ret < 0) {
8294                 printf("Cannot get FDir filter info\n");
8295                 return;
8296         }
8297
8298         if (!strcmp(res->flow_type, "none")) {
8299                 /* means don't specify the flow type */
8300                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
8301                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
8302                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
8303                                0, sizeof(struct rte_eth_fdir_flex_mask));
8304                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
8305                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
8306                                  &flex_mask,
8307                                  sizeof(struct rte_eth_fdir_flex_mask));
8308                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8309                 return;
8310         }
8311         flow_type_mask = fdir_info.flow_types_mask[0];
8312         if (!strcmp(res->flow_type, "all")) {
8313                 if (!flow_type_mask) {
8314                         printf("No flow type supported\n");
8315                         return;
8316                 }
8317                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
8318                         if (flow_type_mask & (1 << i)) {
8319                                 flex_mask.flow_type = i;
8320                                 fdir_set_flex_mask(res->port_id, &flex_mask);
8321                         }
8322                 }
8323                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8324                 return;
8325         }
8326         flex_mask.flow_type = str2flowtype(res->flow_type);
8327         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
8328                 printf("Flow type %s not supported on port %d\n",
8329                                 res->flow_type, res->port_id);
8330                 return;
8331         }
8332         fdir_set_flex_mask(res->port_id, &flex_mask);
8333         cmd_reconfig_device_queue(res->port_id, 1, 1);
8334 }
8335
8336 cmdline_parse_token_string_t cmd_flow_director_flexmask =
8337         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8338                                  flow_director_flexmask,
8339                                  "flow_director_flex_mask");
8340 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
8341         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8342                               port_id, UINT8);
8343 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
8344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8345                                  flow, "flow");
8346 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
8347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8348                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8349                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#all");
8350 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
8351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8352                                  mask, NULL);
8353
8354 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
8355         .f = cmd_flow_director_flex_mask_parsed,
8356         .data = NULL,
8357         .help_str = "set flow director's flex mask on NIC",
8358         .tokens = {
8359                 (void *)&cmd_flow_director_flexmask,
8360                 (void *)&cmd_flow_director_flexmask_port_id,
8361                 (void *)&cmd_flow_director_flexmask_flow,
8362                 (void *)&cmd_flow_director_flexmask_flow_type,
8363                 (void *)&cmd_flow_director_flexmask_mask,
8364                 NULL,
8365         },
8366 };
8367
8368 /* *** deal with flow director flexible payload configuration *** */
8369 struct cmd_flow_director_flexpayload_result {
8370         cmdline_fixed_string_t flow_director_flexpayload;
8371         uint8_t port_id;
8372         cmdline_fixed_string_t payload_layer;
8373         cmdline_fixed_string_t payload_cfg;
8374 };
8375
8376 static inline int
8377 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
8378 {
8379         char s[256];
8380         const char *p, *p0 = q_arg;
8381         char *end;
8382         unsigned long int_fld;
8383         char *str_fld[max_num];
8384         int i;
8385         unsigned size;
8386         int ret = -1;
8387
8388         p = strchr(p0, '(');
8389         if (p == NULL)
8390                 return -1;
8391         ++p;
8392         p0 = strchr(p, ')');
8393         if (p0 == NULL)
8394                 return -1;
8395
8396         size = p0 - p;
8397         if (size >= sizeof(s))
8398                 return -1;
8399
8400         snprintf(s, sizeof(s), "%.*s", size, p);
8401         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8402         if (ret < 0 || ret > max_num)
8403                 return -1;
8404         for (i = 0; i < ret; i++) {
8405                 errno = 0;
8406                 int_fld = strtoul(str_fld[i], &end, 0);
8407                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
8408                         return -1;
8409                 offsets[i] = (uint16_t)int_fld;
8410         }
8411         return ret;
8412 }
8413
8414 static void
8415 cmd_flow_director_flxpld_parsed(void *parsed_result,
8416                           __attribute__((unused)) struct cmdline *cl,
8417                           __attribute__((unused)) void *data)
8418 {
8419         struct cmd_flow_director_flexpayload_result *res = parsed_result;
8420         struct rte_eth_flex_payload_cfg flex_cfg;
8421         struct rte_port *port;
8422         int ret = 0;
8423
8424         if (res->port_id > nb_ports) {
8425                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8426                 return;
8427         }
8428
8429         port = &ports[res->port_id];
8430         /** Check if the port is not started **/
8431         if (port->port_status != RTE_PORT_STOPPED) {
8432                 printf("Please stop port %d first\n", res->port_id);
8433                 return;
8434         }
8435
8436         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
8437
8438         if (!strcmp(res->payload_layer, "raw"))
8439                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
8440         else if (!strcmp(res->payload_layer, "l2"))
8441                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
8442         else if (!strcmp(res->payload_layer, "l3"))
8443                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
8444         else if (!strcmp(res->payload_layer, "l4"))
8445                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
8446
8447         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
8448                             RTE_ETH_FDIR_MAX_FLEXLEN);
8449         if (ret < 0) {
8450                 printf("error: Cannot parse flex payload input.\n");
8451                 return;
8452         }
8453
8454         fdir_set_flex_payload(res->port_id, &flex_cfg);
8455         cmd_reconfig_device_queue(res->port_id, 1, 1);
8456 }
8457
8458 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
8459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8460                                  flow_director_flexpayload,
8461                                  "flow_director_flex_payload");
8462 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
8463         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8464                               port_id, UINT8);
8465 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
8466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8467                                  payload_layer, "raw#l2#l3#l4");
8468 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
8469         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
8470                                  payload_cfg, NULL);
8471
8472 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
8473         .f = cmd_flow_director_flxpld_parsed,
8474         .data = NULL,
8475         .help_str = "set flow director's flex payload on NIC",
8476         .tokens = {
8477                 (void *)&cmd_flow_director_flexpayload,
8478                 (void *)&cmd_flow_director_flexpayload_port_id,
8479                 (void *)&cmd_flow_director_flexpayload_payload_layer,
8480                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
8481                 NULL,
8482         },
8483 };
8484
8485 /* *** Classification Filters Control *** */
8486 /* *** Get symmetric hash enable per port *** */
8487 struct cmd_get_sym_hash_ena_per_port_result {
8488         cmdline_fixed_string_t get_sym_hash_ena_per_port;
8489         uint8_t port_id;
8490 };
8491
8492 static void
8493 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
8494                                  __rte_unused struct cmdline *cl,
8495                                  __rte_unused void *data)
8496 {
8497         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
8498         struct rte_eth_hash_filter_info info;
8499         int ret;
8500
8501         if (rte_eth_dev_filter_supported(res->port_id,
8502                                 RTE_ETH_FILTER_HASH) < 0) {
8503                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
8504                                                         res->port_id);
8505                 return;
8506         }
8507
8508         memset(&info, 0, sizeof(info));
8509         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
8510         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8511                                                 RTE_ETH_FILTER_GET, &info);
8512
8513         if (ret < 0) {
8514                 printf("Cannot get symmetric hash enable per port "
8515                                         "on port %u\n", res->port_id);
8516                 return;
8517         }
8518
8519         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
8520                                 "enabled" : "disabled", res->port_id);
8521 }
8522
8523 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
8524         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
8525                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
8526 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
8527         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
8528                 port_id, UINT8);
8529
8530 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
8531         .f = cmd_get_sym_hash_per_port_parsed,
8532         .data = NULL,
8533         .help_str = "get_sym_hash_ena_per_port port_id",
8534         .tokens = {
8535                 (void *)&cmd_get_sym_hash_ena_per_port_all,
8536                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
8537                 NULL,
8538         },
8539 };
8540
8541 /* *** Set symmetric hash enable per port *** */
8542 struct cmd_set_sym_hash_ena_per_port_result {
8543         cmdline_fixed_string_t set_sym_hash_ena_per_port;
8544         cmdline_fixed_string_t enable;
8545         uint8_t port_id;
8546 };
8547
8548 static void
8549 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
8550                                  __rte_unused struct cmdline *cl,
8551                                  __rte_unused void *data)
8552 {
8553         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
8554         struct rte_eth_hash_filter_info info;
8555         int ret;
8556
8557         if (rte_eth_dev_filter_supported(res->port_id,
8558                                 RTE_ETH_FILTER_HASH) < 0) {
8559                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
8560                                                         res->port_id);
8561                 return;
8562         }
8563
8564         memset(&info, 0, sizeof(info));
8565         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
8566         if (!strcmp(res->enable, "enable"))
8567                 info.info.enable = 1;
8568         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8569                                         RTE_ETH_FILTER_SET, &info);
8570         if (ret < 0) {
8571                 printf("Cannot set symmetric hash enable per port on "
8572                                         "port %u\n", res->port_id);
8573                 return;
8574         }
8575         printf("Symmetric hash has been set to %s on port %u\n",
8576                                         res->enable, res->port_id);
8577 }
8578
8579 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
8580         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8581                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
8582 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
8583         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8584                 port_id, UINT8);
8585 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
8586         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
8587                 enable, "enable#disable");
8588
8589 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
8590         .f = cmd_set_sym_hash_per_port_parsed,
8591         .data = NULL,
8592         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
8593         .tokens = {
8594                 (void *)&cmd_set_sym_hash_ena_per_port_all,
8595                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
8596                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
8597                 NULL,
8598         },
8599 };
8600
8601 /* Get global config of hash function */
8602 struct cmd_get_hash_global_config_result {
8603         cmdline_fixed_string_t get_hash_global_config;
8604         uint8_t port_id;
8605 };
8606
8607 static char *
8608 flowtype_to_str(uint16_t ftype)
8609 {
8610         uint16_t i;
8611         static struct {
8612                 char str[16];
8613                 uint16_t ftype;
8614         } ftype_table[] = {
8615                 {"ipv4", RTE_ETH_FLOW_IPV4},
8616                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8617                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8618                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8619                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8620                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8621                 {"ipv6", RTE_ETH_FLOW_IPV6},
8622                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8623                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8624                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8625                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8626                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8627                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8628         };
8629
8630         for (i = 0; i < RTE_DIM(ftype_table); i++) {
8631                 if (ftype_table[i].ftype == ftype)
8632                         return ftype_table[i].str;
8633         }
8634
8635         return NULL;
8636 }
8637
8638 static void
8639 cmd_get_hash_global_config_parsed(void *parsed_result,
8640                                   __rte_unused struct cmdline *cl,
8641                                   __rte_unused void *data)
8642 {
8643         struct cmd_get_hash_global_config_result *res = parsed_result;
8644         struct rte_eth_hash_filter_info info;
8645         uint32_t idx, offset;
8646         uint16_t i;
8647         char *str;
8648         int ret;
8649
8650         if (rte_eth_dev_filter_supported(res->port_id,
8651                         RTE_ETH_FILTER_HASH) < 0) {
8652                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
8653                                                         res->port_id);
8654                 return;
8655         }
8656
8657         memset(&info, 0, sizeof(info));
8658         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
8659         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8660                                         RTE_ETH_FILTER_GET, &info);
8661         if (ret < 0) {
8662                 printf("Cannot get hash global configurations by port %d\n",
8663                                                         res->port_id);
8664                 return;
8665         }
8666
8667         switch (info.info.global_conf.hash_func) {
8668         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
8669                 printf("Hash function is Toeplitz\n");
8670                 break;
8671         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
8672                 printf("Hash function is Simple XOR\n");
8673                 break;
8674         default:
8675                 printf("Unknown hash function\n");
8676                 break;
8677         }
8678
8679         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
8680                 idx = i / UINT32_BIT;
8681                 offset = i % UINT32_BIT;
8682                 if (!(info.info.global_conf.valid_bit_mask[idx] &
8683                                                 (1UL << offset)))
8684                         continue;
8685                 str = flowtype_to_str(i);
8686                 if (!str)
8687                         continue;
8688                 printf("Symmetric hash is %s globally for flow type %s "
8689                                                         "by port %d\n",
8690                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
8691                         (1UL << offset)) ? "enabled" : "disabled"), str,
8692                                                         res->port_id);
8693         }
8694 }
8695
8696 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
8697         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
8698                 get_hash_global_config, "get_hash_global_config");
8699 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
8700         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
8701                 port_id, UINT8);
8702
8703 cmdline_parse_inst_t cmd_get_hash_global_config = {
8704         .f = cmd_get_hash_global_config_parsed,
8705         .data = NULL,
8706         .help_str = "get_hash_global_config port_id",
8707         .tokens = {
8708                 (void *)&cmd_get_hash_global_config_all,
8709                 (void *)&cmd_get_hash_global_config_port_id,
8710                 NULL,
8711         },
8712 };
8713
8714 /* Set global config of hash function */
8715 struct cmd_set_hash_global_config_result {
8716         cmdline_fixed_string_t set_hash_global_config;
8717         uint8_t port_id;
8718         cmdline_fixed_string_t hash_func;
8719         cmdline_fixed_string_t flow_type;
8720         cmdline_fixed_string_t enable;
8721 };
8722
8723 static void
8724 cmd_set_hash_global_config_parsed(void *parsed_result,
8725                                   __rte_unused struct cmdline *cl,
8726                                   __rte_unused void *data)
8727 {
8728         struct cmd_set_hash_global_config_result *res = parsed_result;
8729         struct rte_eth_hash_filter_info info;
8730         uint32_t ftype, idx, offset;
8731         int ret;
8732
8733         if (rte_eth_dev_filter_supported(res->port_id,
8734                                 RTE_ETH_FILTER_HASH) < 0) {
8735                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
8736                                                         res->port_id);
8737                 return;
8738         }
8739         memset(&info, 0, sizeof(info));
8740         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
8741         if (!strcmp(res->hash_func, "toeplitz"))
8742                 info.info.global_conf.hash_func =
8743                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
8744         else if (!strcmp(res->hash_func, "simple_xor"))
8745                 info.info.global_conf.hash_func =
8746                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
8747         else if (!strcmp(res->hash_func, "default"))
8748                 info.info.global_conf.hash_func =
8749                         RTE_ETH_HASH_FUNCTION_DEFAULT;
8750
8751         ftype = str2flowtype(res->flow_type);
8752         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
8753         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
8754         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
8755         if (!strcmp(res->enable, "enable"))
8756                 info.info.global_conf.sym_hash_enable_mask[idx] |=
8757                                                 (1UL << offset);
8758         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
8759                                         RTE_ETH_FILTER_SET, &info);
8760         if (ret < 0)
8761                 printf("Cannot set global hash configurations by port %d\n",
8762                                                         res->port_id);
8763         else
8764                 printf("Global hash configurations have been set "
8765                         "succcessfully by port %d\n", res->port_id);
8766 }
8767
8768 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
8769         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8770                 set_hash_global_config, "set_hash_global_config");
8771 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
8772         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
8773                 port_id, UINT8);
8774 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
8775         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8776                 hash_func, "toeplitz#simple_xor#default");
8777 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
8778         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8779                 flow_type,
8780                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
8781                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
8782 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
8783         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
8784                 enable, "enable#disable");
8785
8786 cmdline_parse_inst_t cmd_set_hash_global_config = {
8787         .f = cmd_set_hash_global_config_parsed,
8788         .data = NULL,
8789         .help_str = "set_hash_global_config port_id "
8790                 "toeplitz|simple_xor|default "
8791                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
8792                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
8793                 "enable|disable",
8794         .tokens = {
8795                 (void *)&cmd_set_hash_global_config_all,
8796                 (void *)&cmd_set_hash_global_config_port_id,
8797                 (void *)&cmd_set_hash_global_config_hash_func,
8798                 (void *)&cmd_set_hash_global_config_flow_type,
8799                 (void *)&cmd_set_hash_global_config_enable,
8800                 NULL,
8801         },
8802 };
8803
8804 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
8805 struct cmd_mcast_addr_result {
8806         cmdline_fixed_string_t mcast_addr_cmd;
8807         cmdline_fixed_string_t what;
8808         uint8_t port_num;
8809         struct ether_addr mc_addr;
8810 };
8811
8812 static void cmd_mcast_addr_parsed(void *parsed_result,
8813                 __attribute__((unused)) struct cmdline *cl,
8814                 __attribute__((unused)) void *data)
8815 {
8816         struct cmd_mcast_addr_result *res = parsed_result;
8817
8818         if (!is_multicast_ether_addr(&res->mc_addr)) {
8819                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
8820                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
8821                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
8822                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
8823                 return;
8824         }
8825         if (strcmp(res->what, "add") == 0)
8826                 mcast_addr_add(res->port_num, &res->mc_addr);
8827         else
8828                 mcast_addr_remove(res->port_num, &res->mc_addr);
8829 }
8830
8831 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
8832         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
8833                                  mcast_addr_cmd, "mcast_addr");
8834 cmdline_parse_token_string_t cmd_mcast_addr_what =
8835         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
8836                                  "add#remove");
8837 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
8838         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
8839 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
8840         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8841
8842 cmdline_parse_inst_t cmd_mcast_addr = {
8843         .f = cmd_mcast_addr_parsed,
8844         .data = (void *)0,
8845         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
8846         .tokens = {
8847                 (void *)&cmd_mcast_addr_cmd,
8848                 (void *)&cmd_mcast_addr_what,
8849                 (void *)&cmd_mcast_addr_portnum,
8850                 (void *)&cmd_mcast_addr_addr,
8851                 NULL,
8852         },
8853 };
8854
8855 /* ******************************************************************************** */
8856
8857 /* list of instructions */
8858 cmdline_parse_ctx_t main_ctx[] = {
8859         (cmdline_parse_inst_t *)&cmd_help_brief,
8860         (cmdline_parse_inst_t *)&cmd_help_long,
8861         (cmdline_parse_inst_t *)&cmd_quit,
8862         (cmdline_parse_inst_t *)&cmd_showport,
8863         (cmdline_parse_inst_t *)&cmd_showportall,
8864         (cmdline_parse_inst_t *)&cmd_showcfg,
8865         (cmdline_parse_inst_t *)&cmd_start,
8866         (cmdline_parse_inst_t *)&cmd_start_tx_first,
8867         (cmdline_parse_inst_t *)&cmd_set_link_up,
8868         (cmdline_parse_inst_t *)&cmd_set_link_down,
8869         (cmdline_parse_inst_t *)&cmd_reset,
8870         (cmdline_parse_inst_t *)&cmd_set_numbers,
8871         (cmdline_parse_inst_t *)&cmd_set_txpkts,
8872         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
8873         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
8874         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
8875         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
8876         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
8877         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
8878         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
8879         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
8880         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
8881         (cmdline_parse_inst_t *)&cmd_set_link_check,
8882 #ifdef RTE_NIC_BYPASS
8883         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
8884         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
8885         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
8886         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
8887 #endif
8888 #ifdef RTE_LIBRTE_PMD_BOND
8889         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
8890         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
8891         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
8892         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
8893         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
8894         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
8895         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
8896         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
8897         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
8898 #endif
8899         (cmdline_parse_inst_t *)&cmd_vlan_offload,
8900         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
8901         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
8902         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
8903         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
8904         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
8905         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
8906         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
8907         (cmdline_parse_inst_t *)&cmd_csum_set,
8908         (cmdline_parse_inst_t *)&cmd_csum_show,
8909         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
8910         (cmdline_parse_inst_t *)&cmd_tso_set,
8911         (cmdline_parse_inst_t *)&cmd_tso_show,
8912         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
8913         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
8914         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
8915         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
8916         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
8917         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
8918         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
8919         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
8920         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
8921         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
8922         (cmdline_parse_inst_t *)&cmd_config_dcb,
8923         (cmdline_parse_inst_t *)&cmd_read_reg,
8924         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
8925         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
8926         (cmdline_parse_inst_t *)&cmd_write_reg,
8927         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
8928         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
8929         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
8930         (cmdline_parse_inst_t *)&cmd_stop,
8931         (cmdline_parse_inst_t *)&cmd_mac_addr,
8932         (cmdline_parse_inst_t *)&cmd_set_qmap,
8933         (cmdline_parse_inst_t *)&cmd_operate_port,
8934         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
8935         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
8936         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
8937         (cmdline_parse_inst_t *)&cmd_config_speed_all,
8938         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
8939         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
8940         (cmdline_parse_inst_t *)&cmd_config_mtu,
8941         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
8942         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
8943         (cmdline_parse_inst_t *)&cmd_config_rss,
8944         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
8945         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
8946         (cmdline_parse_inst_t *)&cmd_showport_reta,
8947         (cmdline_parse_inst_t *)&cmd_config_burst,
8948         (cmdline_parse_inst_t *)&cmd_config_thresh,
8949         (cmdline_parse_inst_t *)&cmd_config_threshold,
8950         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
8951         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
8952         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
8953         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
8954         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
8955         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
8956         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
8957         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
8958         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
8959         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
8960         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
8961         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
8962         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
8963         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
8964         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
8965         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
8966         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
8967         (cmdline_parse_inst_t *)&cmd_dump,
8968         (cmdline_parse_inst_t *)&cmd_dump_one,
8969         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
8970         (cmdline_parse_inst_t *)&cmd_syn_filter,
8971         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
8972         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
8973         (cmdline_parse_inst_t *)&cmd_flex_filter,
8974         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
8975         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
8976         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
8977         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
8978         (cmdline_parse_inst_t *)&cmd_set_flow_director_mask,
8979         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
8980         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
8981         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
8982         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
8983         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
8984         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
8985         (cmdline_parse_inst_t *)&cmd_mcast_addr,
8986         NULL,
8987 };
8988
8989 /* prompt function, called from main on MASTER lcore */
8990 void
8991 prompt(void)
8992 {
8993         struct cmdline *cl;
8994
8995         /* initialize non-constant commands */
8996         cmd_set_fwd_mode_init();
8997
8998         cl = cmdline_stdin_new(main_ctx, "testpmd> ");
8999         if (cl == NULL) {
9000                 return;
9001         }
9002         cmdline_interact(cl);
9003         cmdline_stdin_exit(cl);
9004 }
9005
9006 static void
9007 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
9008 {
9009         if (id == (portid_t)RTE_PORT_ALL) {
9010                 portid_t pid;
9011
9012                 FOREACH_PORT(pid, ports) {
9013                         /* check if need_reconfig has been set to 1 */
9014                         if (ports[pid].need_reconfig == 0)
9015                                 ports[pid].need_reconfig = dev;
9016                         /* check if need_reconfig_queues has been set to 1 */
9017                         if (ports[pid].need_reconfig_queues == 0)
9018                                 ports[pid].need_reconfig_queues = queue;
9019                 }
9020         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
9021                 /* check if need_reconfig has been set to 1 */
9022                 if (ports[id].need_reconfig == 0)
9023                         ports[id].need_reconfig = dev;
9024                 /* check if need_reconfig_queues has been set to 1 */
9025                 if (ports[id].need_reconfig_queues == 0)
9026                         ports[id].need_reconfig_queues = queue;
9027         }
9028 }
9029
9030 #ifdef RTE_NIC_BYPASS
9031 uint8_t
9032 bypass_is_supported(portid_t port_id)
9033 {
9034         struct rte_port   *port;
9035         struct rte_pci_id *pci_id;
9036
9037         if (port_id_is_invalid(port_id, ENABLED_WARN))
9038                 return 0;
9039
9040         /* Get the device id. */
9041         port    = &ports[port_id];
9042         pci_id = &port->dev_info.pci_dev->id;
9043
9044         /* Check if NIC supports bypass. */
9045         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
9046                 return 1;
9047         }
9048         else {
9049                 printf("\tBypass not supported for port_id = %d.\n", port_id);
9050                 return 0;
9051         }
9052 }
9053 #endif