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