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