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