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