08fe63f3a3b62d4ffea11a4217d60fcabac90a16
[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 port_id 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 NON-TUNNELED 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 for non-tunneled packets is disabled\n");
3499         else
3500                 printf("TSO segment size for non-tunneled packets 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 of non-tunneled packets "
3529         "for csum engine (0 to disable): 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 of non-tunneled packets "
3548         "for csum engine: 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 HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3558 struct cmd_tunnel_tso_set_result {
3559         cmdline_fixed_string_t tso;
3560         cmdline_fixed_string_t mode;
3561         uint16_t tso_segsz;
3562         uint8_t port_id;
3563 };
3564
3565 static void
3566 check_tunnel_tso_nic_support(uint8_t port_id)
3567 {
3568         struct rte_eth_dev_info dev_info;
3569
3570         rte_eth_dev_info_get(port_id, &dev_info);
3571         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3572                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3573                        "supported by port %d\n", port_id);
3574         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3575                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3576                         "supported by port %d\n", port_id);
3577         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3578                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3579                        "supported by port %d\n", port_id);
3580         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3581                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3582                        "supported by port %d\n", port_id);
3583 }
3584
3585 static void
3586 cmd_tunnel_tso_set_parsed(void *parsed_result,
3587                           __attribute__((unused)) struct cmdline *cl,
3588                           __attribute__((unused)) void *data)
3589 {
3590         struct cmd_tunnel_tso_set_result *res = parsed_result;
3591
3592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3593                 return;
3594
3595         if (!strcmp(res->mode, "set"))
3596                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3597
3598         if (ports[res->port_id].tunnel_tso_segsz == 0)
3599                 printf("TSO for tunneled packets is disabled\n");
3600         else {
3601                 printf("TSO segment size for tunneled packets is %d\n",
3602                         ports[res->port_id].tunnel_tso_segsz);
3603
3604                 /* Below conditions are needed to make it work:
3605                  * (1) tunnel TSO is supported by the NIC;
3606                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3607                  * are recognized;
3608                  * (3) for tunneled pkts with outer L3 of IPv4,
3609                  * "csum set outer-ip" must be set to hw, because after tso,
3610                  * total_len of outer IP header is changed, and the checksum
3611                  * of outer IP header calculated by sw should be wrong; that
3612                  * is not necessary for IPv6 tunneled pkts because there's no
3613                  * checksum in IP header anymore.
3614                  */
3615                 check_tunnel_tso_nic_support(res->port_id);
3616
3617                 if (!(ports[res->port_id].tx_ol_flags &
3618                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3619                         printf("Warning: csum parse_tunnel must be set "
3620                                 "so that tunneled packets are recognized\n");
3621                 if (!(ports[res->port_id].tx_ol_flags &
3622                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3623                         printf("Warning: csum set outer-ip must be set to hw "
3624                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3625         }
3626 }
3627
3628 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3629         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3630                                 tso, "tunnel_tso");
3631 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3632         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3633                                 mode, "set");
3634 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3635         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3636                                 tso_segsz, UINT16);
3637 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3638         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3639                                 port_id, UINT8);
3640
3641 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3642         .f = cmd_tunnel_tso_set_parsed,
3643         .data = NULL,
3644         .help_str = "Set TSO segment size of tunneled packets for csum engine "
3645         "(0 to disable): tunnel_tso set <tso_segsz> <port>",
3646         .tokens = {
3647                 (void *)&cmd_tunnel_tso_set_tso,
3648                 (void *)&cmd_tunnel_tso_set_mode,
3649                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3650                 (void *)&cmd_tunnel_tso_set_portid,
3651                 NULL,
3652         },
3653 };
3654
3655 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3656         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3657                                 mode, "show");
3658
3659
3660 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3661         .f = cmd_tunnel_tso_set_parsed,
3662         .data = NULL,
3663         .help_str = "Show TSO segment size of tunneled packets "
3664         "for csum engine: tunnel_tso show <port>",
3665         .tokens = {
3666                 (void *)&cmd_tunnel_tso_set_tso,
3667                 (void *)&cmd_tunnel_tso_show_mode,
3668                 (void *)&cmd_tunnel_tso_set_portid,
3669                 NULL,
3670         },
3671 };
3672
3673 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3674 struct cmd_set_flush_rx {
3675         cmdline_fixed_string_t set;
3676         cmdline_fixed_string_t flush_rx;
3677         cmdline_fixed_string_t mode;
3678 };
3679
3680 static void
3681 cmd_set_flush_rx_parsed(void *parsed_result,
3682                 __attribute__((unused)) struct cmdline *cl,
3683                 __attribute__((unused)) void *data)
3684 {
3685         struct cmd_set_flush_rx *res = parsed_result;
3686         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3687 }
3688
3689 cmdline_parse_token_string_t cmd_setflushrx_set =
3690         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3691                         set, "set");
3692 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3693         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3694                         flush_rx, "flush_rx");
3695 cmdline_parse_token_string_t cmd_setflushrx_mode =
3696         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3697                         mode, "on#off");
3698
3699
3700 cmdline_parse_inst_t cmd_set_flush_rx = {
3701         .f = cmd_set_flush_rx_parsed,
3702         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3703         .data = NULL,
3704         .tokens = {
3705                 (void *)&cmd_setflushrx_set,
3706                 (void *)&cmd_setflushrx_flush_rx,
3707                 (void *)&cmd_setflushrx_mode,
3708                 NULL,
3709         },
3710 };
3711
3712 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3713 struct cmd_set_link_check {
3714         cmdline_fixed_string_t set;
3715         cmdline_fixed_string_t link_check;
3716         cmdline_fixed_string_t mode;
3717 };
3718
3719 static void
3720 cmd_set_link_check_parsed(void *parsed_result,
3721                 __attribute__((unused)) struct cmdline *cl,
3722                 __attribute__((unused)) void *data)
3723 {
3724         struct cmd_set_link_check *res = parsed_result;
3725         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3726 }
3727
3728 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3729         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3730                         set, "set");
3731 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3732         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3733                         link_check, "link_check");
3734 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3735         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3736                         mode, "on#off");
3737
3738
3739 cmdline_parse_inst_t cmd_set_link_check = {
3740         .f = cmd_set_link_check_parsed,
3741         .help_str = "set link_check on|off: enable/disable link status check "
3742                     "when starting/stopping a port",
3743         .data = NULL,
3744         .tokens = {
3745                 (void *)&cmd_setlinkcheck_set,
3746                 (void *)&cmd_setlinkcheck_link_check,
3747                 (void *)&cmd_setlinkcheck_mode,
3748                 NULL,
3749         },
3750 };
3751
3752 #ifdef RTE_NIC_BYPASS
3753 /* *** SET NIC BYPASS MODE *** */
3754 struct cmd_set_bypass_mode_result {
3755         cmdline_fixed_string_t set;
3756         cmdline_fixed_string_t bypass;
3757         cmdline_fixed_string_t mode;
3758         cmdline_fixed_string_t value;
3759         uint8_t port_id;
3760 };
3761
3762 static void
3763 cmd_set_bypass_mode_parsed(void *parsed_result,
3764                 __attribute__((unused)) struct cmdline *cl,
3765                 __attribute__((unused)) void *data)
3766 {
3767         struct cmd_set_bypass_mode_result *res = parsed_result;
3768         portid_t port_id = res->port_id;
3769         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3770
3771         if (!strcmp(res->value, "bypass"))
3772                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3773         else if (!strcmp(res->value, "isolate"))
3774                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3775         else
3776                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3777
3778         /* Set the bypass mode for the relevant port. */
3779         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3780                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3781         }
3782 }
3783
3784 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3785         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3786                         set, "set");
3787 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3789                         bypass, "bypass");
3790 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3791         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3792                         mode, "mode");
3793 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3794         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3795                         value, "normal#bypass#isolate");
3796 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3797         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3798                                 port_id, UINT8);
3799
3800 cmdline_parse_inst_t cmd_set_bypass_mode = {
3801         .f = cmd_set_bypass_mode_parsed,
3802         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3803                     "Set the NIC bypass mode for port_id",
3804         .data = NULL,
3805         .tokens = {
3806                 (void *)&cmd_setbypass_mode_set,
3807                 (void *)&cmd_setbypass_mode_bypass,
3808                 (void *)&cmd_setbypass_mode_mode,
3809                 (void *)&cmd_setbypass_mode_value,
3810                 (void *)&cmd_setbypass_mode_port,
3811                 NULL,
3812         },
3813 };
3814
3815 /* *** SET NIC BYPASS EVENT *** */
3816 struct cmd_set_bypass_event_result {
3817         cmdline_fixed_string_t set;
3818         cmdline_fixed_string_t bypass;
3819         cmdline_fixed_string_t event;
3820         cmdline_fixed_string_t event_value;
3821         cmdline_fixed_string_t mode;
3822         cmdline_fixed_string_t mode_value;
3823         uint8_t port_id;
3824 };
3825
3826 static void
3827 cmd_set_bypass_event_parsed(void *parsed_result,
3828                 __attribute__((unused)) struct cmdline *cl,
3829                 __attribute__((unused)) void *data)
3830 {
3831         int32_t rc;
3832         struct cmd_set_bypass_event_result *res = parsed_result;
3833         portid_t port_id = res->port_id;
3834         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3835         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3836
3837         if (!strcmp(res->event_value, "timeout"))
3838                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3839         else if (!strcmp(res->event_value, "os_on"))
3840                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3841         else if (!strcmp(res->event_value, "os_off"))
3842                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3843         else if (!strcmp(res->event_value, "power_on"))
3844                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3845         else if (!strcmp(res->event_value, "power_off"))
3846                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3847         else
3848                 bypass_event = RTE_BYPASS_EVENT_NONE;
3849
3850         if (!strcmp(res->mode_value, "bypass"))
3851                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3852         else if (!strcmp(res->mode_value, "isolate"))
3853                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3854         else
3855                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3856
3857         /* Set the watchdog timeout. */
3858         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3859
3860                 rc = -EINVAL;
3861                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3862                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3863                                 bypass_timeout)) != 0) {
3864                         printf("Failed to set timeout value %u "
3865                                 "for port %d, errto code: %d.\n",
3866                                 bypass_timeout, port_id, rc);
3867                 }
3868         }
3869
3870         /* Set the bypass event to transition to bypass mode. */
3871         if (0 != rte_eth_dev_bypass_event_store(port_id,
3872                         bypass_event, bypass_mode)) {
3873                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3874         }
3875
3876 }
3877
3878 cmdline_parse_token_string_t cmd_setbypass_event_set =
3879         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3880                         set, "set");
3881 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3882         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3883                         bypass, "bypass");
3884 cmdline_parse_token_string_t cmd_setbypass_event_event =
3885         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3886                         event, "event");
3887 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3888         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3889                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3890 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3892                         mode, "mode");
3893 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3894         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3895                         mode_value, "normal#bypass#isolate");
3896 cmdline_parse_token_num_t cmd_setbypass_event_port =
3897         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3898                                 port_id, UINT8);
3899
3900 cmdline_parse_inst_t cmd_set_bypass_event = {
3901         .f = cmd_set_bypass_event_parsed,
3902         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3903                     "mode (normal|bypass|isolate) (port_id): "
3904                     "Set the NIC bypass event mode for port_id",
3905         .data = NULL,
3906         .tokens = {
3907                 (void *)&cmd_setbypass_event_set,
3908                 (void *)&cmd_setbypass_event_bypass,
3909                 (void *)&cmd_setbypass_event_event,
3910                 (void *)&cmd_setbypass_event_event_value,
3911                 (void *)&cmd_setbypass_event_mode,
3912                 (void *)&cmd_setbypass_event_mode_value,
3913                 (void *)&cmd_setbypass_event_port,
3914                 NULL,
3915         },
3916 };
3917
3918
3919 /* *** SET NIC BYPASS TIMEOUT *** */
3920 struct cmd_set_bypass_timeout_result {
3921         cmdline_fixed_string_t set;
3922         cmdline_fixed_string_t bypass;
3923         cmdline_fixed_string_t timeout;
3924         cmdline_fixed_string_t value;
3925 };
3926
3927 static void
3928 cmd_set_bypass_timeout_parsed(void *parsed_result,
3929                 __attribute__((unused)) struct cmdline *cl,
3930                 __attribute__((unused)) void *data)
3931 {
3932         struct cmd_set_bypass_timeout_result *res = parsed_result;
3933
3934         if (!strcmp(res->value, "1.5"))
3935                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3936         else if (!strcmp(res->value, "2"))
3937                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3938         else if (!strcmp(res->value, "3"))
3939                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3940         else if (!strcmp(res->value, "4"))
3941                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3942         else if (!strcmp(res->value, "8"))
3943                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3944         else if (!strcmp(res->value, "16"))
3945                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3946         else if (!strcmp(res->value, "32"))
3947                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3948         else
3949                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3950 }
3951
3952 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3953         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3954                         set, "set");
3955 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3956         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3957                         bypass, "bypass");
3958 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3959         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3960                         timeout, "timeout");
3961 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3962         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3963                         value, "0#1.5#2#3#4#8#16#32");
3964
3965 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3966         .f = cmd_set_bypass_timeout_parsed,
3967         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3968                     "Set the NIC bypass watchdog timeout",
3969         .data = NULL,
3970         .tokens = {
3971                 (void *)&cmd_setbypass_timeout_set,
3972                 (void *)&cmd_setbypass_timeout_bypass,
3973                 (void *)&cmd_setbypass_timeout_timeout,
3974                 (void *)&cmd_setbypass_timeout_value,
3975                 NULL,
3976         },
3977 };
3978
3979 /* *** SHOW NIC BYPASS MODE *** */
3980 struct cmd_show_bypass_config_result {
3981         cmdline_fixed_string_t show;
3982         cmdline_fixed_string_t bypass;
3983         cmdline_fixed_string_t config;
3984         uint8_t port_id;
3985 };
3986
3987 static void
3988 cmd_show_bypass_config_parsed(void *parsed_result,
3989                 __attribute__((unused)) struct cmdline *cl,
3990                 __attribute__((unused)) void *data)
3991 {
3992         struct cmd_show_bypass_config_result *res = parsed_result;
3993         uint32_t event_mode;
3994         uint32_t bypass_mode;
3995         portid_t port_id = res->port_id;
3996         uint32_t timeout = bypass_timeout;
3997         int i;
3998
3999         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
4000                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4001         static const char * const modes[RTE_BYPASS_MODE_NUM] =
4002                 {"UNKNOWN", "normal", "bypass", "isolate"};
4003         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
4004                 "NONE",
4005                 "OS/board on",
4006                 "power supply on",
4007                 "OS/board off",
4008                 "power supply off",
4009                 "timeout"};
4010         int num_events = (sizeof events) / (sizeof events[0]);
4011
4012         /* Display the bypass mode.*/
4013         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
4014                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4015                 return;
4016         }
4017         else {
4018                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
4019                         bypass_mode = RTE_BYPASS_MODE_NONE;
4020
4021                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4022         }
4023
4024         /* Display the bypass timeout.*/
4025         if (!RTE_BYPASS_TMT_VALID(timeout))
4026                 timeout = RTE_BYPASS_TMT_OFF;
4027
4028         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4029
4030         /* Display the bypass events and associated modes. */
4031         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
4032
4033                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
4034                         printf("\tFailed to get bypass mode for event = %s\n",
4035                                 events[i]);
4036                 } else {
4037                         if (!RTE_BYPASS_MODE_VALID(event_mode))
4038                                 event_mode = RTE_BYPASS_MODE_NONE;
4039
4040                         printf("\tbypass event: %-16s = %s\n", events[i],
4041                                 modes[event_mode]);
4042                 }
4043         }
4044 }
4045
4046 cmdline_parse_token_string_t cmd_showbypass_config_show =
4047         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4048                         show, "show");
4049 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4050         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4051                         bypass, "bypass");
4052 cmdline_parse_token_string_t cmd_showbypass_config_config =
4053         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4054                         config, "config");
4055 cmdline_parse_token_num_t cmd_showbypass_config_port =
4056         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4057                                 port_id, UINT8);
4058
4059 cmdline_parse_inst_t cmd_show_bypass_config = {
4060         .f = cmd_show_bypass_config_parsed,
4061         .help_str = "show bypass config (port_id): "
4062                     "Show the NIC bypass config for port_id",
4063         .data = NULL,
4064         .tokens = {
4065                 (void *)&cmd_showbypass_config_show,
4066                 (void *)&cmd_showbypass_config_bypass,
4067                 (void *)&cmd_showbypass_config_config,
4068                 (void *)&cmd_showbypass_config_port,
4069                 NULL,
4070         },
4071 };
4072 #endif
4073
4074 #ifdef RTE_LIBRTE_PMD_BOND
4075 /* *** SET BONDING MODE *** */
4076 struct cmd_set_bonding_mode_result {
4077         cmdline_fixed_string_t set;
4078         cmdline_fixed_string_t bonding;
4079         cmdline_fixed_string_t mode;
4080         uint8_t value;
4081         uint8_t port_id;
4082 };
4083
4084 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4085                 __attribute__((unused))  struct cmdline *cl,
4086                 __attribute__((unused)) void *data)
4087 {
4088         struct cmd_set_bonding_mode_result *res = parsed_result;
4089         portid_t port_id = res->port_id;
4090
4091         /* Set the bonding mode for the relevant port. */
4092         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4093                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4094 }
4095
4096 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4097 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4098                 set, "set");
4099 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4100 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4101                 bonding, "bonding");
4102 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4103 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4104                 mode, "mode");
4105 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4106 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4107                 value, UINT8);
4108 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4109 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4110                 port_id, UINT8);
4111
4112 cmdline_parse_inst_t cmd_set_bonding_mode = {
4113                 .f = cmd_set_bonding_mode_parsed,
4114                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
4115                 .data = NULL,
4116                 .tokens = {
4117                                 (void *) &cmd_setbonding_mode_set,
4118                                 (void *) &cmd_setbonding_mode_bonding,
4119                                 (void *) &cmd_setbonding_mode_mode,
4120                                 (void *) &cmd_setbonding_mode_value,
4121                                 (void *) &cmd_setbonding_mode_port,
4122                                 NULL
4123                 }
4124 };
4125
4126 /* *** SET BALANCE XMIT POLICY *** */
4127 struct cmd_set_bonding_balance_xmit_policy_result {
4128         cmdline_fixed_string_t set;
4129         cmdline_fixed_string_t bonding;
4130         cmdline_fixed_string_t balance_xmit_policy;
4131         uint8_t port_id;
4132         cmdline_fixed_string_t policy;
4133 };
4134
4135 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4136                 __attribute__((unused))  struct cmdline *cl,
4137                 __attribute__((unused)) void *data)
4138 {
4139         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4140         portid_t port_id = res->port_id;
4141         uint8_t policy;
4142
4143         if (!strcmp(res->policy, "l2")) {
4144                 policy = BALANCE_XMIT_POLICY_LAYER2;
4145         } else if (!strcmp(res->policy, "l23")) {
4146                 policy = BALANCE_XMIT_POLICY_LAYER23;
4147         } else if (!strcmp(res->policy, "l34")) {
4148                 policy = BALANCE_XMIT_POLICY_LAYER34;
4149         } else {
4150                 printf("\t Invalid xmit policy selection");
4151                 return;
4152         }
4153
4154         /* Set the bonding mode for the relevant port. */
4155         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4156                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4157                                 port_id);
4158         }
4159 }
4160
4161 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4162 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4163                 set, "set");
4164 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4165 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4166                 bonding, "bonding");
4167 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4168 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4169                 balance_xmit_policy, "balance_xmit_policy");
4170 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4171 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4172                 port_id, UINT8);
4173 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4174 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4175                 policy, "l2#l23#l34");
4176
4177 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4178                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4179                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
4180                 .data = NULL,
4181                 .tokens = {
4182                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4183                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4184                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4185                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4186                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4187                                 NULL
4188                 }
4189 };
4190
4191 /* *** SHOW NIC BONDING CONFIGURATION *** */
4192 struct cmd_show_bonding_config_result {
4193         cmdline_fixed_string_t show;
4194         cmdline_fixed_string_t bonding;
4195         cmdline_fixed_string_t config;
4196         uint8_t port_id;
4197 };
4198
4199 static void cmd_show_bonding_config_parsed(void *parsed_result,
4200                 __attribute__((unused))  struct cmdline *cl,
4201                 __attribute__((unused)) void *data)
4202 {
4203         struct cmd_show_bonding_config_result *res = parsed_result;
4204         int bonding_mode;
4205         uint8_t slaves[RTE_MAX_ETHPORTS];
4206         int num_slaves, num_active_slaves;
4207         int primary_id;
4208         int i;
4209         portid_t port_id = res->port_id;
4210
4211         /* Display the bonding mode.*/
4212         bonding_mode = rte_eth_bond_mode_get(port_id);
4213         if (bonding_mode < 0) {
4214                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4215                 return;
4216         } else
4217                 printf("\tBonding mode: %d\n", bonding_mode);
4218
4219         if (bonding_mode == BONDING_MODE_BALANCE) {
4220                 int balance_xmit_policy;
4221
4222                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4223                 if (balance_xmit_policy < 0) {
4224                         printf("\tFailed to get balance xmit policy for port = %d\n",
4225                                         port_id);
4226                         return;
4227                 } else {
4228                         printf("\tBalance Xmit Policy: ");
4229
4230                         switch (balance_xmit_policy) {
4231                         case BALANCE_XMIT_POLICY_LAYER2:
4232                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4233                                 break;
4234                         case BALANCE_XMIT_POLICY_LAYER23:
4235                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4236                                 break;
4237                         case BALANCE_XMIT_POLICY_LAYER34:
4238                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4239                                 break;
4240                         }
4241                         printf("\n");
4242                 }
4243         }
4244
4245         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4246
4247         if (num_slaves < 0) {
4248                 printf("\tFailed to get slave list for port = %d\n", port_id);
4249                 return;
4250         }
4251         if (num_slaves > 0) {
4252                 printf("\tSlaves (%d): [", num_slaves);
4253                 for (i = 0; i < num_slaves - 1; i++)
4254                         printf("%d ", slaves[i]);
4255
4256                 printf("%d]\n", slaves[num_slaves - 1]);
4257         } else {
4258                 printf("\tSlaves: []\n");
4259
4260         }
4261
4262         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4263                         RTE_MAX_ETHPORTS);
4264
4265         if (num_active_slaves < 0) {
4266                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4267                 return;
4268         }
4269         if (num_active_slaves > 0) {
4270                 printf("\tActive Slaves (%d): [", num_active_slaves);
4271                 for (i = 0; i < num_active_slaves - 1; i++)
4272                         printf("%d ", slaves[i]);
4273
4274                 printf("%d]\n", slaves[num_active_slaves - 1]);
4275
4276         } else {
4277                 printf("\tActive Slaves: []\n");
4278
4279         }
4280
4281         primary_id = rte_eth_bond_primary_get(port_id);
4282         if (primary_id < 0) {
4283                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4284                 return;
4285         } else
4286                 printf("\tPrimary: [%d]\n", primary_id);
4287
4288 }
4289
4290 cmdline_parse_token_string_t cmd_showbonding_config_show =
4291 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4292                 show, "show");
4293 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4294 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4295                 bonding, "bonding");
4296 cmdline_parse_token_string_t cmd_showbonding_config_config =
4297 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4298                 config, "config");
4299 cmdline_parse_token_num_t cmd_showbonding_config_port =
4300 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4301                 port_id, UINT8);
4302
4303 cmdline_parse_inst_t cmd_show_bonding_config = {
4304                 .f = cmd_show_bonding_config_parsed,
4305                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
4306                 .data = NULL,
4307                 .tokens = {
4308                                 (void *)&cmd_showbonding_config_show,
4309                                 (void *)&cmd_showbonding_config_bonding,
4310                                 (void *)&cmd_showbonding_config_config,
4311                                 (void *)&cmd_showbonding_config_port,
4312                                 NULL
4313                 }
4314 };
4315
4316 /* *** SET BONDING PRIMARY *** */
4317 struct cmd_set_bonding_primary_result {
4318         cmdline_fixed_string_t set;
4319         cmdline_fixed_string_t bonding;
4320         cmdline_fixed_string_t primary;
4321         uint8_t slave_id;
4322         uint8_t port_id;
4323 };
4324
4325 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4326                 __attribute__((unused))  struct cmdline *cl,
4327                 __attribute__((unused)) void *data)
4328 {
4329         struct cmd_set_bonding_primary_result *res = parsed_result;
4330         portid_t master_port_id = res->port_id;
4331         portid_t slave_port_id = res->slave_id;
4332
4333         /* Set the primary slave for a bonded device. */
4334         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4335                 printf("\t Failed to set primary slave for port = %d.\n",
4336                                 master_port_id);
4337                 return;
4338         }
4339         init_port_config();
4340 }
4341
4342 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4343 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4344                 set, "set");
4345 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4346 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4347                 bonding, "bonding");
4348 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4349 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4350                 primary, "primary");
4351 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4352 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4353                 slave_id, UINT8);
4354 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4355 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4356                 port_id, UINT8);
4357
4358 cmdline_parse_inst_t cmd_set_bonding_primary = {
4359                 .f = cmd_set_bonding_primary_parsed,
4360                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
4361                 .data = NULL,
4362                 .tokens = {
4363                                 (void *)&cmd_setbonding_primary_set,
4364                                 (void *)&cmd_setbonding_primary_bonding,
4365                                 (void *)&cmd_setbonding_primary_primary,
4366                                 (void *)&cmd_setbonding_primary_slave,
4367                                 (void *)&cmd_setbonding_primary_port,
4368                                 NULL
4369                 }
4370 };
4371
4372 /* *** ADD SLAVE *** */
4373 struct cmd_add_bonding_slave_result {
4374         cmdline_fixed_string_t add;
4375         cmdline_fixed_string_t bonding;
4376         cmdline_fixed_string_t slave;
4377         uint8_t slave_id;
4378         uint8_t port_id;
4379 };
4380
4381 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4382                 __attribute__((unused))  struct cmdline *cl,
4383                 __attribute__((unused)) void *data)
4384 {
4385         struct cmd_add_bonding_slave_result *res = parsed_result;
4386         portid_t master_port_id = res->port_id;
4387         portid_t slave_port_id = res->slave_id;
4388
4389         /* Set the primary slave for a bonded device. */
4390         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4391                 printf("\t Failed to add slave %d to master port = %d.\n",
4392                                 slave_port_id, master_port_id);
4393                 return;
4394         }
4395         init_port_config();
4396         set_port_slave_flag(slave_port_id);
4397 }
4398
4399 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4400 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4401                 add, "add");
4402 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4403 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4404                 bonding, "bonding");
4405 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4406 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4407                 slave, "slave");
4408 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4409 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4410                 slave_id, UINT8);
4411 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4412 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4413                 port_id, UINT8);
4414
4415 cmdline_parse_inst_t cmd_add_bonding_slave = {
4416                 .f = cmd_add_bonding_slave_parsed,
4417                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4418                 .data = NULL,
4419                 .tokens = {
4420                                 (void *)&cmd_addbonding_slave_add,
4421                                 (void *)&cmd_addbonding_slave_bonding,
4422                                 (void *)&cmd_addbonding_slave_slave,
4423                                 (void *)&cmd_addbonding_slave_slaveid,
4424                                 (void *)&cmd_addbonding_slave_port,
4425                                 NULL
4426                 }
4427 };
4428
4429 /* *** REMOVE SLAVE *** */
4430 struct cmd_remove_bonding_slave_result {
4431         cmdline_fixed_string_t remove;
4432         cmdline_fixed_string_t bonding;
4433         cmdline_fixed_string_t slave;
4434         uint8_t slave_id;
4435         uint8_t port_id;
4436 };
4437
4438 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4439                 __attribute__((unused))  struct cmdline *cl,
4440                 __attribute__((unused)) void *data)
4441 {
4442         struct cmd_remove_bonding_slave_result *res = parsed_result;
4443         portid_t master_port_id = res->port_id;
4444         portid_t slave_port_id = res->slave_id;
4445
4446         /* Set the primary slave for a bonded device. */
4447         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4448                 printf("\t Failed to remove slave %d from master port = %d.\n",
4449                                 slave_port_id, master_port_id);
4450                 return;
4451         }
4452         init_port_config();
4453         clear_port_slave_flag(slave_port_id);
4454 }
4455
4456 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4457                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4458                                 remove, "remove");
4459 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4460                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4461                                 bonding, "bonding");
4462 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4463                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4464                                 slave, "slave");
4465 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4466                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4467                                 slave_id, UINT8);
4468 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4469                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4470                                 port_id, UINT8);
4471
4472 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4473                 .f = cmd_remove_bonding_slave_parsed,
4474                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4475                 .data = NULL,
4476                 .tokens = {
4477                                 (void *)&cmd_removebonding_slave_remove,
4478                                 (void *)&cmd_removebonding_slave_bonding,
4479                                 (void *)&cmd_removebonding_slave_slave,
4480                                 (void *)&cmd_removebonding_slave_slaveid,
4481                                 (void *)&cmd_removebonding_slave_port,
4482                                 NULL
4483                 }
4484 };
4485
4486 /* *** CREATE BONDED DEVICE *** */
4487 struct cmd_create_bonded_device_result {
4488         cmdline_fixed_string_t create;
4489         cmdline_fixed_string_t bonded;
4490         cmdline_fixed_string_t device;
4491         uint8_t mode;
4492         uint8_t socket;
4493 };
4494
4495 static int bond_dev_num = 0;
4496
4497 static void cmd_create_bonded_device_parsed(void *parsed_result,
4498                 __attribute__((unused))  struct cmdline *cl,
4499                 __attribute__((unused)) void *data)
4500 {
4501         struct cmd_create_bonded_device_result *res = parsed_result;
4502         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4503         int port_id;
4504
4505         if (test_done == 0) {
4506                 printf("Please stop forwarding first\n");
4507                 return;
4508         }
4509
4510         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d",
4511                         bond_dev_num++);
4512
4513         /* Create a new bonded device. */
4514         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4515         if (port_id < 0) {
4516                 printf("\t Failed to create bonded device.\n");
4517                 return;
4518         } else {
4519                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4520                                 port_id);
4521
4522                 /* Update number of ports */
4523                 nb_ports = rte_eth_dev_count();
4524                 reconfig(port_id, res->socket);
4525                 rte_eth_promiscuous_enable(port_id);
4526                 ports[port_id].enabled = 1;
4527         }
4528
4529 }
4530
4531 cmdline_parse_token_string_t cmd_createbonded_device_create =
4532                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4533                                 create, "create");
4534 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4535                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4536                                 bonded, "bonded");
4537 cmdline_parse_token_string_t cmd_createbonded_device_device =
4538                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4539                                 device, "device");
4540 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4541                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4542                                 mode, UINT8);
4543 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4544                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4545                                 socket, UINT8);
4546
4547 cmdline_parse_inst_t cmd_create_bonded_device = {
4548                 .f = cmd_create_bonded_device_parsed,
4549                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4550                 .data = NULL,
4551                 .tokens = {
4552                                 (void *)&cmd_createbonded_device_create,
4553                                 (void *)&cmd_createbonded_device_bonded,
4554                                 (void *)&cmd_createbonded_device_device,
4555                                 (void *)&cmd_createbonded_device_mode,
4556                                 (void *)&cmd_createbonded_device_socket,
4557                                 NULL
4558                 }
4559 };
4560
4561 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4562 struct cmd_set_bond_mac_addr_result {
4563         cmdline_fixed_string_t set;
4564         cmdline_fixed_string_t bonding;
4565         cmdline_fixed_string_t mac_addr;
4566         uint8_t port_num;
4567         struct ether_addr address;
4568 };
4569
4570 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4571                 __attribute__((unused))  struct cmdline *cl,
4572                 __attribute__((unused)) void *data)
4573 {
4574         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4575         int ret;
4576
4577         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4578                 return;
4579
4580         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4581
4582         /* check the return value and print it if is < 0 */
4583         if (ret < 0)
4584                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4585 }
4586
4587 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4588                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4589 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4590                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4591                                 "bonding");
4592 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4593                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4594                                 "mac_addr");
4595 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4596                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4597 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4598                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4599
4600 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4601                 .f = cmd_set_bond_mac_addr_parsed,
4602                 .data = (void *) 0,
4603                 .help_str = "set bonding mac_addr (port_id) (address): ",
4604                 .tokens = {
4605                                 (void *)&cmd_set_bond_mac_addr_set,
4606                                 (void *)&cmd_set_bond_mac_addr_bonding,
4607                                 (void *)&cmd_set_bond_mac_addr_mac,
4608                                 (void *)&cmd_set_bond_mac_addr_portnum,
4609                                 (void *)&cmd_set_bond_mac_addr_addr,
4610                                 NULL
4611                 }
4612 };
4613
4614
4615 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4616 struct cmd_set_bond_mon_period_result {
4617         cmdline_fixed_string_t set;
4618         cmdline_fixed_string_t bonding;
4619         cmdline_fixed_string_t mon_period;
4620         uint8_t port_num;
4621         uint32_t period_ms;
4622 };
4623
4624 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4625                 __attribute__((unused))  struct cmdline *cl,
4626                 __attribute__((unused)) void *data)
4627 {
4628         struct cmd_set_bond_mon_period_result *res = parsed_result;
4629         int ret;
4630
4631         if (res->port_num >= nb_ports) {
4632                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4633                 return;
4634         }
4635
4636         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4637
4638         /* check the return value and print it if is < 0 */
4639         if (ret < 0)
4640                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4641 }
4642
4643 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4644                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4645                                 set, "set");
4646 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4647                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4648                                 bonding, "bonding");
4649 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4650                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4651                                 mon_period,     "mon_period");
4652 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4653                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4654                                 port_num, UINT8);
4655 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4656                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4657                                 period_ms, UINT32);
4658
4659 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4660                 .f = cmd_set_bond_mon_period_parsed,
4661                 .data = (void *) 0,
4662                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4663                 .tokens = {
4664                                 (void *)&cmd_set_bond_mon_period_set,
4665                                 (void *)&cmd_set_bond_mon_period_bonding,
4666                                 (void *)&cmd_set_bond_mon_period_mon_period,
4667                                 (void *)&cmd_set_bond_mon_period_portnum,
4668                                 (void *)&cmd_set_bond_mon_period_period_ms,
4669                                 NULL
4670                 }
4671 };
4672
4673 #endif /* RTE_LIBRTE_PMD_BOND */
4674
4675 /* *** SET FORWARDING MODE *** */
4676 struct cmd_set_fwd_mode_result {
4677         cmdline_fixed_string_t set;
4678         cmdline_fixed_string_t fwd;
4679         cmdline_fixed_string_t mode;
4680 };
4681
4682 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4683                                     __attribute__((unused)) struct cmdline *cl,
4684                                     __attribute__((unused)) void *data)
4685 {
4686         struct cmd_set_fwd_mode_result *res = parsed_result;
4687
4688         retry_enabled = 0;
4689         set_pkt_forwarding_mode(res->mode);
4690 }
4691
4692 cmdline_parse_token_string_t cmd_setfwd_set =
4693         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4694 cmdline_parse_token_string_t cmd_setfwd_fwd =
4695         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4696 cmdline_parse_token_string_t cmd_setfwd_mode =
4697         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4698                 "" /* defined at init */);
4699
4700 cmdline_parse_inst_t cmd_set_fwd_mode = {
4701         .f = cmd_set_fwd_mode_parsed,
4702         .data = NULL,
4703         .help_str = NULL, /* defined at init */
4704         .tokens = {
4705                 (void *)&cmd_setfwd_set,
4706                 (void *)&cmd_setfwd_fwd,
4707                 (void *)&cmd_setfwd_mode,
4708                 NULL,
4709         },
4710 };
4711
4712 static void cmd_set_fwd_mode_init(void)
4713 {
4714         char *modes, *c;
4715         static char token[128];
4716         static char help[256];
4717         cmdline_parse_token_string_t *token_struct;
4718
4719         modes = list_pkt_forwarding_modes();
4720         snprintf(help, sizeof help, "set fwd %s - "
4721                 "set packet forwarding mode", modes);
4722         cmd_set_fwd_mode.help_str = help;
4723
4724         /* string token separator is # */
4725         for (c = token; *modes != '\0'; modes++)
4726                 if (*modes == '|')
4727                         *c++ = '#';
4728                 else
4729                         *c++ = *modes;
4730         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4731         token_struct->string_data.str = token;
4732 }
4733
4734 /* *** SET RETRY FORWARDING MODE *** */
4735 struct cmd_set_fwd_retry_mode_result {
4736         cmdline_fixed_string_t set;
4737         cmdline_fixed_string_t fwd;
4738         cmdline_fixed_string_t mode;
4739         cmdline_fixed_string_t retry;
4740 };
4741
4742 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
4743                             __attribute__((unused)) struct cmdline *cl,
4744                             __attribute__((unused)) void *data)
4745 {
4746         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
4747
4748         retry_enabled = 1;
4749         set_pkt_forwarding_mode(res->mode);
4750 }
4751
4752 cmdline_parse_token_string_t cmd_setfwd_retry_set =
4753         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4754                         set, "set");
4755 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
4756         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4757                         fwd, "fwd");
4758 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
4759         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4760                         mode,
4761                 "" /* defined at init */);
4762 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
4763         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4764                         retry, "retry");
4765
4766 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
4767         .f = cmd_set_fwd_retry_mode_parsed,
4768         .data = NULL,
4769         .help_str = NULL, /* defined at init */
4770         .tokens = {
4771                 (void *)&cmd_setfwd_retry_set,
4772                 (void *)&cmd_setfwd_retry_fwd,
4773                 (void *)&cmd_setfwd_retry_mode,
4774                 (void *)&cmd_setfwd_retry_retry,
4775                 NULL,
4776         },
4777 };
4778
4779 static void cmd_set_fwd_retry_mode_init(void)
4780 {
4781         char *modes, *c;
4782         static char token[128];
4783         static char help[256];
4784         cmdline_parse_token_string_t *token_struct;
4785
4786         modes = list_pkt_forwarding_retry_modes();
4787         snprintf(help, sizeof(help), "set fwd %s retry - "
4788                 "set packet forwarding mode with retry", modes);
4789         cmd_set_fwd_retry_mode.help_str = help;
4790
4791         /* string token separator is # */
4792         for (c = token; *modes != '\0'; modes++)
4793                 if (*modes == '|')
4794                         *c++ = '#';
4795                 else
4796                         *c++ = *modes;
4797         token_struct = (cmdline_parse_token_string_t *)
4798                 cmd_set_fwd_retry_mode.tokens[2];
4799         token_struct->string_data.str = token;
4800 }
4801
4802 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4803 struct cmd_set_burst_tx_retry_result {
4804         cmdline_fixed_string_t set;
4805         cmdline_fixed_string_t burst;
4806         cmdline_fixed_string_t tx;
4807         cmdline_fixed_string_t delay;
4808         uint32_t time;
4809         cmdline_fixed_string_t retry;
4810         uint32_t retry_num;
4811 };
4812
4813 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4814                                         __attribute__((unused)) struct cmdline *cl,
4815                                         __attribute__((unused)) void *data)
4816 {
4817         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4818
4819         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4820                 && !strcmp(res->tx, "tx")) {
4821                 if (!strcmp(res->delay, "delay"))
4822                         burst_tx_delay_time = res->time;
4823                 if (!strcmp(res->retry, "retry"))
4824                         burst_tx_retry_num = res->retry_num;
4825         }
4826
4827 }
4828
4829 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4830         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4831 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4832         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4833                                  "burst");
4834 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4835         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4836 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4837         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4838 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4839         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4840 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4841         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4842 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4843         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4844
4845 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4846         .f = cmd_set_burst_tx_retry_parsed,
4847         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4848         .tokens = {
4849                 (void *)&cmd_set_burst_tx_retry_set,
4850                 (void *)&cmd_set_burst_tx_retry_burst,
4851                 (void *)&cmd_set_burst_tx_retry_tx,
4852                 (void *)&cmd_set_burst_tx_retry_delay,
4853                 (void *)&cmd_set_burst_tx_retry_time,
4854                 (void *)&cmd_set_burst_tx_retry_retry,
4855                 (void *)&cmd_set_burst_tx_retry_retry_num,
4856                 NULL,
4857         },
4858 };
4859
4860 /* *** SET PROMISC MODE *** */
4861 struct cmd_set_promisc_mode_result {
4862         cmdline_fixed_string_t set;
4863         cmdline_fixed_string_t promisc;
4864         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4865         uint8_t port_num;                /* valid if "allports" argument == 0 */
4866         cmdline_fixed_string_t mode;
4867 };
4868
4869 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4870                                         __attribute__((unused)) struct cmdline *cl,
4871                                         void *allports)
4872 {
4873         struct cmd_set_promisc_mode_result *res = parsed_result;
4874         int enable;
4875         portid_t i;
4876
4877         if (!strcmp(res->mode, "on"))
4878                 enable = 1;
4879         else
4880                 enable = 0;
4881
4882         /* all ports */
4883         if (allports) {
4884                 FOREACH_PORT(i, ports) {
4885                         if (enable)
4886                                 rte_eth_promiscuous_enable(i);
4887                         else
4888                                 rte_eth_promiscuous_disable(i);
4889                 }
4890         }
4891         else {
4892                 if (enable)
4893                         rte_eth_promiscuous_enable(res->port_num);
4894                 else
4895                         rte_eth_promiscuous_disable(res->port_num);
4896         }
4897 }
4898
4899 cmdline_parse_token_string_t cmd_setpromisc_set =
4900         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4901 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4902         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4903                                  "promisc");
4904 cmdline_parse_token_string_t cmd_setpromisc_portall =
4905         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4906                                  "all");
4907 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4908         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4909                               UINT8);
4910 cmdline_parse_token_string_t cmd_setpromisc_mode =
4911         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4912                                  "on#off");
4913
4914 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4915         .f = cmd_set_promisc_mode_parsed,
4916         .data = (void *)1,
4917         .help_str = "set promisc all on|off: set promisc mode for all ports",
4918         .tokens = {
4919                 (void *)&cmd_setpromisc_set,
4920                 (void *)&cmd_setpromisc_promisc,
4921                 (void *)&cmd_setpromisc_portall,
4922                 (void *)&cmd_setpromisc_mode,
4923                 NULL,
4924         },
4925 };
4926
4927 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4928         .f = cmd_set_promisc_mode_parsed,
4929         .data = (void *)0,
4930         .help_str = "set promisc X on|off: set promisc mode on port X",
4931         .tokens = {
4932                 (void *)&cmd_setpromisc_set,
4933                 (void *)&cmd_setpromisc_promisc,
4934                 (void *)&cmd_setpromisc_portnum,
4935                 (void *)&cmd_setpromisc_mode,
4936                 NULL,
4937         },
4938 };
4939
4940 /* *** SET ALLMULTI MODE *** */
4941 struct cmd_set_allmulti_mode_result {
4942         cmdline_fixed_string_t set;
4943         cmdline_fixed_string_t allmulti;
4944         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4945         uint8_t port_num;                /* valid if "allports" argument == 0 */
4946         cmdline_fixed_string_t mode;
4947 };
4948
4949 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4950                                         __attribute__((unused)) struct cmdline *cl,
4951                                         void *allports)
4952 {
4953         struct cmd_set_allmulti_mode_result *res = parsed_result;
4954         int enable;
4955         portid_t i;
4956
4957         if (!strcmp(res->mode, "on"))
4958                 enable = 1;
4959         else
4960                 enable = 0;
4961
4962         /* all ports */
4963         if (allports) {
4964                 FOREACH_PORT(i, ports) {
4965                         if (enable)
4966                                 rte_eth_allmulticast_enable(i);
4967                         else
4968                                 rte_eth_allmulticast_disable(i);
4969                 }
4970         }
4971         else {
4972                 if (enable)
4973                         rte_eth_allmulticast_enable(res->port_num);
4974                 else
4975                         rte_eth_allmulticast_disable(res->port_num);
4976         }
4977 }
4978
4979 cmdline_parse_token_string_t cmd_setallmulti_set =
4980         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4981 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4982         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4983                                  "allmulti");
4984 cmdline_parse_token_string_t cmd_setallmulti_portall =
4985         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4986                                  "all");
4987 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4988         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4989                               UINT8);
4990 cmdline_parse_token_string_t cmd_setallmulti_mode =
4991         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4992                                  "on#off");
4993
4994 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4995         .f = cmd_set_allmulti_mode_parsed,
4996         .data = (void *)1,
4997         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4998         .tokens = {
4999                 (void *)&cmd_setallmulti_set,
5000                 (void *)&cmd_setallmulti_allmulti,
5001                 (void *)&cmd_setallmulti_portall,
5002                 (void *)&cmd_setallmulti_mode,
5003                 NULL,
5004         },
5005 };
5006
5007 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5008         .f = cmd_set_allmulti_mode_parsed,
5009         .data = (void *)0,
5010         .help_str = "set allmulti X on|off: set allmulti mode on port X",
5011         .tokens = {
5012                 (void *)&cmd_setallmulti_set,
5013                 (void *)&cmd_setallmulti_allmulti,
5014                 (void *)&cmd_setallmulti_portnum,
5015                 (void *)&cmd_setallmulti_mode,
5016                 NULL,
5017         },
5018 };
5019
5020 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5021 struct cmd_link_flow_ctrl_set_result {
5022         cmdline_fixed_string_t set;
5023         cmdline_fixed_string_t flow_ctrl;
5024         cmdline_fixed_string_t rx;
5025         cmdline_fixed_string_t rx_lfc_mode;
5026         cmdline_fixed_string_t tx;
5027         cmdline_fixed_string_t tx_lfc_mode;
5028         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5029         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5030         cmdline_fixed_string_t autoneg_str;
5031         cmdline_fixed_string_t autoneg;
5032         cmdline_fixed_string_t hw_str;
5033         uint32_t high_water;
5034         cmdline_fixed_string_t lw_str;
5035         uint32_t low_water;
5036         cmdline_fixed_string_t pt_str;
5037         uint16_t pause_time;
5038         cmdline_fixed_string_t xon_str;
5039         uint16_t send_xon;
5040         uint8_t  port_id;
5041 };
5042
5043 cmdline_parse_token_string_t cmd_lfc_set_set =
5044         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5045                                 set, "set");
5046 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5047         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5048                                 flow_ctrl, "flow_ctrl");
5049 cmdline_parse_token_string_t cmd_lfc_set_rx =
5050         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5051                                 rx, "rx");
5052 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5053         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5054                                 rx_lfc_mode, "on#off");
5055 cmdline_parse_token_string_t cmd_lfc_set_tx =
5056         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5057                                 tx, "tx");
5058 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5059         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5060                                 tx_lfc_mode, "on#off");
5061 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5062         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5063                                 hw_str, "high_water");
5064 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5065         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5066                                 high_water, UINT32);
5067 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5068         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5069                                 lw_str, "low_water");
5070 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5071         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5072                                 low_water, UINT32);
5073 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5074         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5075                                 pt_str, "pause_time");
5076 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5077         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5078                                 pause_time, UINT16);
5079 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5080         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5081                                 xon_str, "send_xon");
5082 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5083         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5084                                 send_xon, UINT16);
5085 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5086         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5087                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5088 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5089         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5090                                 mac_ctrl_frame_fwd_mode, "on#off");
5091 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5092         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5093                                 autoneg_str, "autoneg");
5094 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5095         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5096                                 autoneg, "on#off");
5097 cmdline_parse_token_num_t cmd_lfc_set_portid =
5098         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5099                                 port_id, UINT8);
5100
5101 /* forward declaration */
5102 static void
5103 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5104                               void *data);
5105
5106 cmdline_parse_inst_t cmd_link_flow_control_set = {
5107         .f = cmd_link_flow_ctrl_set_parsed,
5108         .data = NULL,
5109         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
5110 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
5111 autoneg on|off port_id",
5112         .tokens = {
5113                 (void *)&cmd_lfc_set_set,
5114                 (void *)&cmd_lfc_set_flow_ctrl,
5115                 (void *)&cmd_lfc_set_rx,
5116                 (void *)&cmd_lfc_set_rx_mode,
5117                 (void *)&cmd_lfc_set_tx,
5118                 (void *)&cmd_lfc_set_tx_mode,
5119                 (void *)&cmd_lfc_set_high_water,
5120                 (void *)&cmd_lfc_set_low_water,
5121                 (void *)&cmd_lfc_set_pause_time,
5122                 (void *)&cmd_lfc_set_send_xon,
5123                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5124                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5125                 (void *)&cmd_lfc_set_autoneg_str,
5126                 (void *)&cmd_lfc_set_autoneg,
5127                 (void *)&cmd_lfc_set_portid,
5128                 NULL,
5129         },
5130 };
5131
5132 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5133         .f = cmd_link_flow_ctrl_set_parsed,
5134         .data = (void *)&cmd_link_flow_control_set_rx,
5135         .help_str = "Change rx flow control parameter: set flow_ctrl "
5136                     "rx on|off port_id",
5137         .tokens = {
5138                 (void *)&cmd_lfc_set_set,
5139                 (void *)&cmd_lfc_set_flow_ctrl,
5140                 (void *)&cmd_lfc_set_rx,
5141                 (void *)&cmd_lfc_set_rx_mode,
5142                 (void *)&cmd_lfc_set_portid,
5143                 NULL,
5144         },
5145 };
5146
5147 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5148         .f = cmd_link_flow_ctrl_set_parsed,
5149         .data = (void *)&cmd_link_flow_control_set_tx,
5150         .help_str = "Change tx flow control parameter: set flow_ctrl "
5151                     "tx on|off port_id",
5152         .tokens = {
5153                 (void *)&cmd_lfc_set_set,
5154                 (void *)&cmd_lfc_set_flow_ctrl,
5155                 (void *)&cmd_lfc_set_tx,
5156                 (void *)&cmd_lfc_set_tx_mode,
5157                 (void *)&cmd_lfc_set_portid,
5158                 NULL,
5159         },
5160 };
5161
5162 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5163         .f = cmd_link_flow_ctrl_set_parsed,
5164         .data = (void *)&cmd_link_flow_control_set_hw,
5165         .help_str = "Change high water flow control parameter: set flow_ctrl "
5166                     "high_water value port_id",
5167         .tokens = {
5168                 (void *)&cmd_lfc_set_set,
5169                 (void *)&cmd_lfc_set_flow_ctrl,
5170                 (void *)&cmd_lfc_set_high_water_str,
5171                 (void *)&cmd_lfc_set_high_water,
5172                 (void *)&cmd_lfc_set_portid,
5173                 NULL,
5174         },
5175 };
5176
5177 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5178         .f = cmd_link_flow_ctrl_set_parsed,
5179         .data = (void *)&cmd_link_flow_control_set_lw,
5180         .help_str = "Change low water flow control parameter: set flow_ctrl "
5181                     "low_water value port_id",
5182         .tokens = {
5183                 (void *)&cmd_lfc_set_set,
5184                 (void *)&cmd_lfc_set_flow_ctrl,
5185                 (void *)&cmd_lfc_set_low_water_str,
5186                 (void *)&cmd_lfc_set_low_water,
5187                 (void *)&cmd_lfc_set_portid,
5188                 NULL,
5189         },
5190 };
5191
5192 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5193         .f = cmd_link_flow_ctrl_set_parsed,
5194         .data = (void *)&cmd_link_flow_control_set_pt,
5195         .help_str = "Change pause time flow control parameter: set flow_ctrl "
5196                     "pause_time value port_id",
5197         .tokens = {
5198                 (void *)&cmd_lfc_set_set,
5199                 (void *)&cmd_lfc_set_flow_ctrl,
5200                 (void *)&cmd_lfc_set_pause_time_str,
5201                 (void *)&cmd_lfc_set_pause_time,
5202                 (void *)&cmd_lfc_set_portid,
5203                 NULL,
5204         },
5205 };
5206
5207 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5208         .f = cmd_link_flow_ctrl_set_parsed,
5209         .data = (void *)&cmd_link_flow_control_set_xon,
5210         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
5211                     "send_xon value port_id",
5212         .tokens = {
5213                 (void *)&cmd_lfc_set_set,
5214                 (void *)&cmd_lfc_set_flow_ctrl,
5215                 (void *)&cmd_lfc_set_send_xon_str,
5216                 (void *)&cmd_lfc_set_send_xon,
5217                 (void *)&cmd_lfc_set_portid,
5218                 NULL,
5219         },
5220 };
5221
5222 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5223         .f = cmd_link_flow_ctrl_set_parsed,
5224         .data = (void *)&cmd_link_flow_control_set_macfwd,
5225         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
5226                     "mac_ctrl_frame_fwd on|off port_id",
5227         .tokens = {
5228                 (void *)&cmd_lfc_set_set,
5229                 (void *)&cmd_lfc_set_flow_ctrl,
5230                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5231                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5232                 (void *)&cmd_lfc_set_portid,
5233                 NULL,
5234         },
5235 };
5236
5237 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5238         .f = cmd_link_flow_ctrl_set_parsed,
5239         .data = (void *)&cmd_link_flow_control_set_autoneg,
5240         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
5241                     "autoneg on|off port_id",
5242         .tokens = {
5243                 (void *)&cmd_lfc_set_set,
5244                 (void *)&cmd_lfc_set_flow_ctrl,
5245                 (void *)&cmd_lfc_set_autoneg_str,
5246                 (void *)&cmd_lfc_set_autoneg,
5247                 (void *)&cmd_lfc_set_portid,
5248                 NULL,
5249         },
5250 };
5251
5252 static void
5253 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5254                               __attribute__((unused)) struct cmdline *cl,
5255                               void *data)
5256 {
5257         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5258         cmdline_parse_inst_t *cmd = data;
5259         struct rte_eth_fc_conf fc_conf;
5260         int rx_fc_en = 0;
5261         int tx_fc_en = 0;
5262         int ret;
5263
5264         /*
5265          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5266          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5267          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5268          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5269          */
5270         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5271                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5272         };
5273
5274         /* Partial command line, retrieve current configuration */
5275         if (cmd) {
5276                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5277                 if (ret != 0) {
5278                         printf("cannot get current flow ctrl parameters, return"
5279                                "code = %d\n", ret);
5280                         return;
5281                 }
5282
5283                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5284                     (fc_conf.mode == RTE_FC_FULL))
5285                         rx_fc_en = 1;
5286                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5287                     (fc_conf.mode == RTE_FC_FULL))
5288                         tx_fc_en = 1;
5289         }
5290
5291         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5292                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5293
5294         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5295                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5296
5297         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5298
5299         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5300                 fc_conf.high_water = res->high_water;
5301
5302         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5303                 fc_conf.low_water = res->low_water;
5304
5305         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5306                 fc_conf.pause_time = res->pause_time;
5307
5308         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5309                 fc_conf.send_xon = res->send_xon;
5310
5311         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5312                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5313                         fc_conf.mac_ctrl_frame_fwd = 1;
5314                 else
5315                         fc_conf.mac_ctrl_frame_fwd = 0;
5316         }
5317
5318         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5319                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5320
5321         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5322         if (ret != 0)
5323                 printf("bad flow contrl parameter, return code = %d \n", ret);
5324 }
5325
5326 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5327 struct cmd_priority_flow_ctrl_set_result {
5328         cmdline_fixed_string_t set;
5329         cmdline_fixed_string_t pfc_ctrl;
5330         cmdline_fixed_string_t rx;
5331         cmdline_fixed_string_t rx_pfc_mode;
5332         cmdline_fixed_string_t tx;
5333         cmdline_fixed_string_t tx_pfc_mode;
5334         uint32_t high_water;
5335         uint32_t low_water;
5336         uint16_t pause_time;
5337         uint8_t  priority;
5338         uint8_t  port_id;
5339 };
5340
5341 static void
5342 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5343                        __attribute__((unused)) struct cmdline *cl,
5344                        __attribute__((unused)) void *data)
5345 {
5346         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5347         struct rte_eth_pfc_conf pfc_conf;
5348         int rx_fc_enable, tx_fc_enable;
5349         int ret;
5350
5351         /*
5352          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5353          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5354          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5355          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5356          */
5357         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5358                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5359         };
5360
5361         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5362         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5363         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5364         pfc_conf.fc.high_water = res->high_water;
5365         pfc_conf.fc.low_water  = res->low_water;
5366         pfc_conf.fc.pause_time = res->pause_time;
5367         pfc_conf.priority      = res->priority;
5368
5369         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5370         if (ret != 0)
5371                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5372 }
5373
5374 cmdline_parse_token_string_t cmd_pfc_set_set =
5375         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5376                                 set, "set");
5377 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5378         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5379                                 pfc_ctrl, "pfc_ctrl");
5380 cmdline_parse_token_string_t cmd_pfc_set_rx =
5381         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5382                                 rx, "rx");
5383 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5384         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5385                                 rx_pfc_mode, "on#off");
5386 cmdline_parse_token_string_t cmd_pfc_set_tx =
5387         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5388                                 tx, "tx");
5389 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5390         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5391                                 tx_pfc_mode, "on#off");
5392 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5393         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5394                                 high_water, UINT32);
5395 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5396         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5397                                 low_water, UINT32);
5398 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5399         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5400                                 pause_time, UINT16);
5401 cmdline_parse_token_num_t cmd_pfc_set_priority =
5402         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5403                                 priority, UINT8);
5404 cmdline_parse_token_num_t cmd_pfc_set_portid =
5405         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5406                                 port_id, UINT8);
5407
5408 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5409         .f = cmd_priority_flow_ctrl_set_parsed,
5410         .data = NULL,
5411         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5412                         tx on|off high_water low_water pause_time priority port_id",
5413         .tokens = {
5414                 (void *)&cmd_pfc_set_set,
5415                 (void *)&cmd_pfc_set_flow_ctrl,
5416                 (void *)&cmd_pfc_set_rx,
5417                 (void *)&cmd_pfc_set_rx_mode,
5418                 (void *)&cmd_pfc_set_tx,
5419                 (void *)&cmd_pfc_set_tx_mode,
5420                 (void *)&cmd_pfc_set_high_water,
5421                 (void *)&cmd_pfc_set_low_water,
5422                 (void *)&cmd_pfc_set_pause_time,
5423                 (void *)&cmd_pfc_set_priority,
5424                 (void *)&cmd_pfc_set_portid,
5425                 NULL,
5426         },
5427 };
5428
5429 /* *** RESET CONFIGURATION *** */
5430 struct cmd_reset_result {
5431         cmdline_fixed_string_t reset;
5432         cmdline_fixed_string_t def;
5433 };
5434
5435 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5436                              struct cmdline *cl,
5437                              __attribute__((unused)) void *data)
5438 {
5439         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5440         set_def_fwd_config();
5441 }
5442
5443 cmdline_parse_token_string_t cmd_reset_set =
5444         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5445 cmdline_parse_token_string_t cmd_reset_def =
5446         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5447                                  "default");
5448
5449 cmdline_parse_inst_t cmd_reset = {
5450         .f = cmd_reset_parsed,
5451         .data = NULL,
5452         .help_str = "set default: reset default forwarding configuration",
5453         .tokens = {
5454                 (void *)&cmd_reset_set,
5455                 (void *)&cmd_reset_def,
5456                 NULL,
5457         },
5458 };
5459
5460 /* *** START FORWARDING *** */
5461 struct cmd_start_result {
5462         cmdline_fixed_string_t start;
5463 };
5464
5465 cmdline_parse_token_string_t cmd_start_start =
5466         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5467
5468 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5469                              __attribute__((unused)) struct cmdline *cl,
5470                              __attribute__((unused)) void *data)
5471 {
5472         start_packet_forwarding(0);
5473 }
5474
5475 cmdline_parse_inst_t cmd_start = {
5476         .f = cmd_start_parsed,
5477         .data = NULL,
5478         .help_str = "start packet forwarding",
5479         .tokens = {
5480                 (void *)&cmd_start_start,
5481                 NULL,
5482         },
5483 };
5484
5485 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5486 struct cmd_start_tx_first_result {
5487         cmdline_fixed_string_t start;
5488         cmdline_fixed_string_t tx_first;
5489 };
5490
5491 static void
5492 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5493                           __attribute__((unused)) struct cmdline *cl,
5494                           __attribute__((unused)) void *data)
5495 {
5496         start_packet_forwarding(1);
5497 }
5498
5499 cmdline_parse_token_string_t cmd_start_tx_first_start =
5500         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5501                                  "start");
5502 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5503         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5504                                  tx_first, "tx_first");
5505
5506 cmdline_parse_inst_t cmd_start_tx_first = {
5507         .f = cmd_start_tx_first_parsed,
5508         .data = NULL,
5509         .help_str = "start packet forwarding, after sending 1 burst of packets",
5510         .tokens = {
5511                 (void *)&cmd_start_tx_first_start,
5512                 (void *)&cmd_start_tx_first_tx_first,
5513                 NULL,
5514         },
5515 };
5516
5517 /* *** START FORWARDING WITH N TX BURST FIRST *** */
5518 struct cmd_start_tx_first_n_result {
5519         cmdline_fixed_string_t start;
5520         cmdline_fixed_string_t tx_first;
5521         uint32_t tx_num;
5522 };
5523
5524 static void
5525 cmd_start_tx_first_n_parsed(void *parsed_result,
5526                           __attribute__((unused)) struct cmdline *cl,
5527                           __attribute__((unused)) void *data)
5528 {
5529         struct cmd_start_tx_first_n_result *res = parsed_result;
5530
5531         start_packet_forwarding(res->tx_num);
5532 }
5533
5534 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
5535         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5536                         start, "start");
5537 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
5538         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5539                         tx_first, "tx_first");
5540 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
5541         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
5542                         tx_num, UINT32);
5543
5544 cmdline_parse_inst_t cmd_start_tx_first_n = {
5545         .f = cmd_start_tx_first_n_parsed,
5546         .data = NULL,
5547         .help_str = "start packet forwarding, after sending <num> "
5548                 "bursts of packets",
5549         .tokens = {
5550                 (void *)&cmd_start_tx_first_n_start,
5551                 (void *)&cmd_start_tx_first_n_tx_first,
5552                 (void *)&cmd_start_tx_first_n_tx_num,
5553                 NULL,
5554         },
5555 };
5556
5557 /* *** SET LINK UP *** */
5558 struct cmd_set_link_up_result {
5559         cmdline_fixed_string_t set;
5560         cmdline_fixed_string_t link_up;
5561         cmdline_fixed_string_t port;
5562         uint8_t port_id;
5563 };
5564
5565 cmdline_parse_token_string_t cmd_set_link_up_set =
5566         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5567 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5569                                 "link-up");
5570 cmdline_parse_token_string_t cmd_set_link_up_port =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5572 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5573         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5574
5575 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5576                              __attribute__((unused)) struct cmdline *cl,
5577                              __attribute__((unused)) void *data)
5578 {
5579         struct cmd_set_link_up_result *res = parsed_result;
5580         dev_set_link_up(res->port_id);
5581 }
5582
5583 cmdline_parse_inst_t cmd_set_link_up = {
5584         .f = cmd_set_link_up_parsed,
5585         .data = NULL,
5586         .help_str = "set link-up port (port id)",
5587         .tokens = {
5588                 (void *)&cmd_set_link_up_set,
5589                 (void *)&cmd_set_link_up_link_up,
5590                 (void *)&cmd_set_link_up_port,
5591                 (void *)&cmd_set_link_up_port_id,
5592                 NULL,
5593         },
5594 };
5595
5596 /* *** SET LINK DOWN *** */
5597 struct cmd_set_link_down_result {
5598         cmdline_fixed_string_t set;
5599         cmdline_fixed_string_t link_down;
5600         cmdline_fixed_string_t port;
5601         uint8_t port_id;
5602 };
5603
5604 cmdline_parse_token_string_t cmd_set_link_down_set =
5605         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5606 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5607         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5608                                 "link-down");
5609 cmdline_parse_token_string_t cmd_set_link_down_port =
5610         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5611 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5612         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5613
5614 static void cmd_set_link_down_parsed(
5615                                 __attribute__((unused)) void *parsed_result,
5616                                 __attribute__((unused)) struct cmdline *cl,
5617                                 __attribute__((unused)) void *data)
5618 {
5619         struct cmd_set_link_down_result *res = parsed_result;
5620         dev_set_link_down(res->port_id);
5621 }
5622
5623 cmdline_parse_inst_t cmd_set_link_down = {
5624         .f = cmd_set_link_down_parsed,
5625         .data = NULL,
5626         .help_str = "set link-down port (port id)",
5627         .tokens = {
5628                 (void *)&cmd_set_link_down_set,
5629                 (void *)&cmd_set_link_down_link_down,
5630                 (void *)&cmd_set_link_down_port,
5631                 (void *)&cmd_set_link_down_port_id,
5632                 NULL,
5633         },
5634 };
5635
5636 /* *** SHOW CFG *** */
5637 struct cmd_showcfg_result {
5638         cmdline_fixed_string_t show;
5639         cmdline_fixed_string_t cfg;
5640         cmdline_fixed_string_t what;
5641 };
5642
5643 static void cmd_showcfg_parsed(void *parsed_result,
5644                                __attribute__((unused)) struct cmdline *cl,
5645                                __attribute__((unused)) void *data)
5646 {
5647         struct cmd_showcfg_result *res = parsed_result;
5648         if (!strcmp(res->what, "rxtx"))
5649                 rxtx_config_display();
5650         else if (!strcmp(res->what, "cores"))
5651                 fwd_lcores_config_display();
5652         else if (!strcmp(res->what, "fwd"))
5653                 pkt_fwd_config_display(&cur_fwd_config);
5654         else if (!strcmp(res->what, "txpkts"))
5655                 show_tx_pkt_segments();
5656 }
5657
5658 cmdline_parse_token_string_t cmd_showcfg_show =
5659         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5660 cmdline_parse_token_string_t cmd_showcfg_port =
5661         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5662 cmdline_parse_token_string_t cmd_showcfg_what =
5663         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5664                                  "rxtx#cores#fwd#txpkts");
5665
5666 cmdline_parse_inst_t cmd_showcfg = {
5667         .f = cmd_showcfg_parsed,
5668         .data = NULL,
5669         .help_str = "show config rxtx|cores|fwd|txpkts",
5670         .tokens = {
5671                 (void *)&cmd_showcfg_show,
5672                 (void *)&cmd_showcfg_port,
5673                 (void *)&cmd_showcfg_what,
5674                 NULL,
5675         },
5676 };
5677
5678 /* *** SHOW ALL PORT INFO *** */
5679 struct cmd_showportall_result {
5680         cmdline_fixed_string_t show;
5681         cmdline_fixed_string_t port;
5682         cmdline_fixed_string_t what;
5683         cmdline_fixed_string_t all;
5684 };
5685
5686 static void cmd_showportall_parsed(void *parsed_result,
5687                                 __attribute__((unused)) struct cmdline *cl,
5688                                 __attribute__((unused)) void *data)
5689 {
5690         portid_t i;
5691
5692         struct cmd_showportall_result *res = parsed_result;
5693         if (!strcmp(res->show, "clear")) {
5694                 if (!strcmp(res->what, "stats"))
5695                         FOREACH_PORT(i, ports)
5696                                 nic_stats_clear(i);
5697                 else if (!strcmp(res->what, "xstats"))
5698                         FOREACH_PORT(i, ports)
5699                                 nic_xstats_clear(i);
5700         } else if (!strcmp(res->what, "info"))
5701                 FOREACH_PORT(i, ports)
5702                         port_infos_display(i);
5703         else if (!strcmp(res->what, "stats"))
5704                 FOREACH_PORT(i, ports)
5705                         nic_stats_display(i);
5706         else if (!strcmp(res->what, "xstats"))
5707                 FOREACH_PORT(i, ports)
5708                         nic_xstats_display(i);
5709         else if (!strcmp(res->what, "fdir"))
5710                 FOREACH_PORT(i, ports)
5711                         fdir_get_infos(i);
5712         else if (!strcmp(res->what, "stat_qmap"))
5713                 FOREACH_PORT(i, ports)
5714                         nic_stats_mapping_display(i);
5715         else if (!strcmp(res->what, "dcb_tc"))
5716                 FOREACH_PORT(i, ports)
5717                         port_dcb_info_display(i);
5718 }
5719
5720 cmdline_parse_token_string_t cmd_showportall_show =
5721         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5722                                  "show#clear");
5723 cmdline_parse_token_string_t cmd_showportall_port =
5724         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5725 cmdline_parse_token_string_t cmd_showportall_what =
5726         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5727                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5728 cmdline_parse_token_string_t cmd_showportall_all =
5729         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5730 cmdline_parse_inst_t cmd_showportall = {
5731         .f = cmd_showportall_parsed,
5732         .data = NULL,
5733         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all",
5734         .tokens = {
5735                 (void *)&cmd_showportall_show,
5736                 (void *)&cmd_showportall_port,
5737                 (void *)&cmd_showportall_what,
5738                 (void *)&cmd_showportall_all,
5739                 NULL,
5740         },
5741 };
5742
5743 /* *** SHOW PORT INFO *** */
5744 struct cmd_showport_result {
5745         cmdline_fixed_string_t show;
5746         cmdline_fixed_string_t port;
5747         cmdline_fixed_string_t what;
5748         uint8_t portnum;
5749 };
5750
5751 static void cmd_showport_parsed(void *parsed_result,
5752                                 __attribute__((unused)) struct cmdline *cl,
5753                                 __attribute__((unused)) void *data)
5754 {
5755         struct cmd_showport_result *res = parsed_result;
5756         if (!strcmp(res->show, "clear")) {
5757                 if (!strcmp(res->what, "stats"))
5758                         nic_stats_clear(res->portnum);
5759                 else if (!strcmp(res->what, "xstats"))
5760                         nic_xstats_clear(res->portnum);
5761         } else if (!strcmp(res->what, "info"))
5762                 port_infos_display(res->portnum);
5763         else if (!strcmp(res->what, "stats"))
5764                 nic_stats_display(res->portnum);
5765         else if (!strcmp(res->what, "xstats"))
5766                 nic_xstats_display(res->portnum);
5767         else if (!strcmp(res->what, "fdir"))
5768                  fdir_get_infos(res->portnum);
5769         else if (!strcmp(res->what, "stat_qmap"))
5770                 nic_stats_mapping_display(res->portnum);
5771         else if (!strcmp(res->what, "dcb_tc"))
5772                 port_dcb_info_display(res->portnum);
5773 }
5774
5775 cmdline_parse_token_string_t cmd_showport_show =
5776         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5777                                  "show#clear");
5778 cmdline_parse_token_string_t cmd_showport_port =
5779         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5780 cmdline_parse_token_string_t cmd_showport_what =
5781         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5782                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5783 cmdline_parse_token_num_t cmd_showport_portnum =
5784         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5785
5786 cmdline_parse_inst_t cmd_showport = {
5787         .f = cmd_showport_parsed,
5788         .data = NULL,
5789         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc X (X = port number)",
5790         .tokens = {
5791                 (void *)&cmd_showport_show,
5792                 (void *)&cmd_showport_port,
5793                 (void *)&cmd_showport_what,
5794                 (void *)&cmd_showport_portnum,
5795                 NULL,
5796         },
5797 };
5798
5799 /* *** SHOW QUEUE INFO *** */
5800 struct cmd_showqueue_result {
5801         cmdline_fixed_string_t show;
5802         cmdline_fixed_string_t type;
5803         cmdline_fixed_string_t what;
5804         uint8_t portnum;
5805         uint16_t queuenum;
5806 };
5807
5808 static void
5809 cmd_showqueue_parsed(void *parsed_result,
5810         __attribute__((unused)) struct cmdline *cl,
5811         __attribute__((unused)) void *data)
5812 {
5813         struct cmd_showqueue_result *res = parsed_result;
5814
5815         if (!strcmp(res->type, "rxq"))
5816                 rx_queue_infos_display(res->portnum, res->queuenum);
5817         else if (!strcmp(res->type, "txq"))
5818                 tx_queue_infos_display(res->portnum, res->queuenum);
5819 }
5820
5821 cmdline_parse_token_string_t cmd_showqueue_show =
5822         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5823 cmdline_parse_token_string_t cmd_showqueue_type =
5824         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5825 cmdline_parse_token_string_t cmd_showqueue_what =
5826         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5827 cmdline_parse_token_num_t cmd_showqueue_portnum =
5828         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5829 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5830         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5831
5832 cmdline_parse_inst_t cmd_showqueue = {
5833         .f = cmd_showqueue_parsed,
5834         .data = NULL,
5835         .help_str = "show rxq|txq info <port number> <queue_number>",
5836         .tokens = {
5837                 (void *)&cmd_showqueue_show,
5838                 (void *)&cmd_showqueue_type,
5839                 (void *)&cmd_showqueue_what,
5840                 (void *)&cmd_showqueue_portnum,
5841                 (void *)&cmd_showqueue_queuenum,
5842                 NULL,
5843         },
5844 };
5845
5846 /* *** READ PORT REGISTER *** */
5847 struct cmd_read_reg_result {
5848         cmdline_fixed_string_t read;
5849         cmdline_fixed_string_t reg;
5850         uint8_t port_id;
5851         uint32_t reg_off;
5852 };
5853
5854 static void
5855 cmd_read_reg_parsed(void *parsed_result,
5856                     __attribute__((unused)) struct cmdline *cl,
5857                     __attribute__((unused)) void *data)
5858 {
5859         struct cmd_read_reg_result *res = parsed_result;
5860         port_reg_display(res->port_id, res->reg_off);
5861 }
5862
5863 cmdline_parse_token_string_t cmd_read_reg_read =
5864         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5865 cmdline_parse_token_string_t cmd_read_reg_reg =
5866         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5867 cmdline_parse_token_num_t cmd_read_reg_port_id =
5868         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5869 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5870         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5871
5872 cmdline_parse_inst_t cmd_read_reg = {
5873         .f = cmd_read_reg_parsed,
5874         .data = NULL,
5875         .help_str = "read reg port_id reg_off",
5876         .tokens = {
5877                 (void *)&cmd_read_reg_read,
5878                 (void *)&cmd_read_reg_reg,
5879                 (void *)&cmd_read_reg_port_id,
5880                 (void *)&cmd_read_reg_reg_off,
5881                 NULL,
5882         },
5883 };
5884
5885 /* *** READ PORT REGISTER BIT FIELD *** */
5886 struct cmd_read_reg_bit_field_result {
5887         cmdline_fixed_string_t read;
5888         cmdline_fixed_string_t regfield;
5889         uint8_t port_id;
5890         uint32_t reg_off;
5891         uint8_t bit1_pos;
5892         uint8_t bit2_pos;
5893 };
5894
5895 static void
5896 cmd_read_reg_bit_field_parsed(void *parsed_result,
5897                               __attribute__((unused)) struct cmdline *cl,
5898                               __attribute__((unused)) void *data)
5899 {
5900         struct cmd_read_reg_bit_field_result *res = parsed_result;
5901         port_reg_bit_field_display(res->port_id, res->reg_off,
5902                                    res->bit1_pos, res->bit2_pos);
5903 }
5904
5905 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5906         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5907                                  "read");
5908 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5909         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5910                                  regfield, "regfield");
5911 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5912         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5913                               UINT8);
5914 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5915         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5916                               UINT32);
5917 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5918         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5919                               UINT8);
5920 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5921         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5922                               UINT8);
5923
5924 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5925         .f = cmd_read_reg_bit_field_parsed,
5926         .data = NULL,
5927         .help_str = "read regfield port_id reg_off bit_x bit_y "
5928         "(read register bit field between bit_x and bit_y included)",
5929         .tokens = {
5930                 (void *)&cmd_read_reg_bit_field_read,
5931                 (void *)&cmd_read_reg_bit_field_regfield,
5932                 (void *)&cmd_read_reg_bit_field_port_id,
5933                 (void *)&cmd_read_reg_bit_field_reg_off,
5934                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5935                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5936                 NULL,
5937         },
5938 };
5939
5940 /* *** READ PORT REGISTER BIT *** */
5941 struct cmd_read_reg_bit_result {
5942         cmdline_fixed_string_t read;
5943         cmdline_fixed_string_t regbit;
5944         uint8_t port_id;
5945         uint32_t reg_off;
5946         uint8_t bit_pos;
5947 };
5948
5949 static void
5950 cmd_read_reg_bit_parsed(void *parsed_result,
5951                         __attribute__((unused)) struct cmdline *cl,
5952                         __attribute__((unused)) void *data)
5953 {
5954         struct cmd_read_reg_bit_result *res = parsed_result;
5955         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5956 }
5957
5958 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5959         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5960 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5961         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5962                                  regbit, "regbit");
5963 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5964         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5965 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5966         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5967 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5968         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5969
5970 cmdline_parse_inst_t cmd_read_reg_bit = {
5971         .f = cmd_read_reg_bit_parsed,
5972         .data = NULL,
5973         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5974         .tokens = {
5975                 (void *)&cmd_read_reg_bit_read,
5976                 (void *)&cmd_read_reg_bit_regbit,
5977                 (void *)&cmd_read_reg_bit_port_id,
5978                 (void *)&cmd_read_reg_bit_reg_off,
5979                 (void *)&cmd_read_reg_bit_bit_pos,
5980                 NULL,
5981         },
5982 };
5983
5984 /* *** WRITE PORT REGISTER *** */
5985 struct cmd_write_reg_result {
5986         cmdline_fixed_string_t write;
5987         cmdline_fixed_string_t reg;
5988         uint8_t port_id;
5989         uint32_t reg_off;
5990         uint32_t value;
5991 };
5992
5993 static void
5994 cmd_write_reg_parsed(void *parsed_result,
5995                      __attribute__((unused)) struct cmdline *cl,
5996                      __attribute__((unused)) void *data)
5997 {
5998         struct cmd_write_reg_result *res = parsed_result;
5999         port_reg_set(res->port_id, res->reg_off, res->value);
6000 }
6001
6002 cmdline_parse_token_string_t cmd_write_reg_write =
6003         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6004 cmdline_parse_token_string_t cmd_write_reg_reg =
6005         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6006 cmdline_parse_token_num_t cmd_write_reg_port_id =
6007         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6008 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6009         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6010 cmdline_parse_token_num_t cmd_write_reg_value =
6011         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6012
6013 cmdline_parse_inst_t cmd_write_reg = {
6014         .f = cmd_write_reg_parsed,
6015         .data = NULL,
6016         .help_str = "write reg port_id reg_off reg_value",
6017         .tokens = {
6018                 (void *)&cmd_write_reg_write,
6019                 (void *)&cmd_write_reg_reg,
6020                 (void *)&cmd_write_reg_port_id,
6021                 (void *)&cmd_write_reg_reg_off,
6022                 (void *)&cmd_write_reg_value,
6023                 NULL,
6024         },
6025 };
6026
6027 /* *** WRITE PORT REGISTER BIT FIELD *** */
6028 struct cmd_write_reg_bit_field_result {
6029         cmdline_fixed_string_t write;
6030         cmdline_fixed_string_t regfield;
6031         uint8_t port_id;
6032         uint32_t reg_off;
6033         uint8_t bit1_pos;
6034         uint8_t bit2_pos;
6035         uint32_t value;
6036 };
6037
6038 static void
6039 cmd_write_reg_bit_field_parsed(void *parsed_result,
6040                                __attribute__((unused)) struct cmdline *cl,
6041                                __attribute__((unused)) void *data)
6042 {
6043         struct cmd_write_reg_bit_field_result *res = parsed_result;
6044         port_reg_bit_field_set(res->port_id, res->reg_off,
6045                           res->bit1_pos, res->bit2_pos, res->value);
6046 }
6047
6048 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6049         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6050                                  "write");
6051 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6052         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6053                                  regfield, "regfield");
6054 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6056                               UINT8);
6057 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6059                               UINT32);
6060 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6062                               UINT8);
6063 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6064         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6065                               UINT8);
6066 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6067         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6068                               UINT32);
6069
6070 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6071         .f = cmd_write_reg_bit_field_parsed,
6072         .data = NULL,
6073         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
6074         "(set register bit field between bit_x and bit_y included)",
6075         .tokens = {
6076                 (void *)&cmd_write_reg_bit_field_write,
6077                 (void *)&cmd_write_reg_bit_field_regfield,
6078                 (void *)&cmd_write_reg_bit_field_port_id,
6079                 (void *)&cmd_write_reg_bit_field_reg_off,
6080                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6081                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6082                 (void *)&cmd_write_reg_bit_field_value,
6083                 NULL,
6084         },
6085 };
6086
6087 /* *** WRITE PORT REGISTER BIT *** */
6088 struct cmd_write_reg_bit_result {
6089         cmdline_fixed_string_t write;
6090         cmdline_fixed_string_t regbit;
6091         uint8_t port_id;
6092         uint32_t reg_off;
6093         uint8_t bit_pos;
6094         uint8_t value;
6095 };
6096
6097 static void
6098 cmd_write_reg_bit_parsed(void *parsed_result,
6099                          __attribute__((unused)) struct cmdline *cl,
6100                          __attribute__((unused)) void *data)
6101 {
6102         struct cmd_write_reg_bit_result *res = parsed_result;
6103         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6104 }
6105
6106 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6107         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6108                                  "write");
6109 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6110         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6111                                  regbit, "regbit");
6112 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6113         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6114 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6115         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6116 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6117         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6118 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6119         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6120
6121 cmdline_parse_inst_t cmd_write_reg_bit = {
6122         .f = cmd_write_reg_bit_parsed,
6123         .data = NULL,
6124         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
6125         .tokens = {
6126                 (void *)&cmd_write_reg_bit_write,
6127                 (void *)&cmd_write_reg_bit_regbit,
6128                 (void *)&cmd_write_reg_bit_port_id,
6129                 (void *)&cmd_write_reg_bit_reg_off,
6130                 (void *)&cmd_write_reg_bit_bit_pos,
6131                 (void *)&cmd_write_reg_bit_value,
6132                 NULL,
6133         },
6134 };
6135
6136 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6137 struct cmd_read_rxd_txd_result {
6138         cmdline_fixed_string_t read;
6139         cmdline_fixed_string_t rxd_txd;
6140         uint8_t port_id;
6141         uint16_t queue_id;
6142         uint16_t desc_id;
6143 };
6144
6145 static void
6146 cmd_read_rxd_txd_parsed(void *parsed_result,
6147                         __attribute__((unused)) struct cmdline *cl,
6148                         __attribute__((unused)) void *data)
6149 {
6150         struct cmd_read_rxd_txd_result *res = parsed_result;
6151
6152         if (!strcmp(res->rxd_txd, "rxd"))
6153                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6154         else if (!strcmp(res->rxd_txd, "txd"))
6155                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6156 }
6157
6158 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6159         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6160 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6161         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6162                                  "rxd#txd");
6163 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6164         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6165 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6166         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6167 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6168         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6169
6170 cmdline_parse_inst_t cmd_read_rxd_txd = {
6171         .f = cmd_read_rxd_txd_parsed,
6172         .data = NULL,
6173         .help_str = "read rxd|txd port_id queue_id rxd_id",
6174         .tokens = {
6175                 (void *)&cmd_read_rxd_txd_read,
6176                 (void *)&cmd_read_rxd_txd_rxd_txd,
6177                 (void *)&cmd_read_rxd_txd_port_id,
6178                 (void *)&cmd_read_rxd_txd_queue_id,
6179                 (void *)&cmd_read_rxd_txd_desc_id,
6180                 NULL,
6181         },
6182 };
6183
6184 /* *** QUIT *** */
6185 struct cmd_quit_result {
6186         cmdline_fixed_string_t quit;
6187 };
6188
6189 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6190                             struct cmdline *cl,
6191                             __attribute__((unused)) void *data)
6192 {
6193         pmd_test_exit();
6194         cmdline_quit(cl);
6195 }
6196
6197 cmdline_parse_token_string_t cmd_quit_quit =
6198         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6199
6200 cmdline_parse_inst_t cmd_quit = {
6201         .f = cmd_quit_parsed,
6202         .data = NULL,
6203         .help_str = "exit application",
6204         .tokens = {
6205                 (void *)&cmd_quit_quit,
6206                 NULL,
6207         },
6208 };
6209
6210 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6211 struct cmd_mac_addr_result {
6212         cmdline_fixed_string_t mac_addr_cmd;
6213         cmdline_fixed_string_t what;
6214         uint8_t port_num;
6215         struct ether_addr address;
6216 };
6217
6218 static void cmd_mac_addr_parsed(void *parsed_result,
6219                 __attribute__((unused)) struct cmdline *cl,
6220                 __attribute__((unused)) void *data)
6221 {
6222         struct cmd_mac_addr_result *res = parsed_result;
6223         int ret;
6224
6225         if (strcmp(res->what, "add") == 0)
6226                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6227         else
6228                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6229
6230         /* check the return value and print it if is < 0 */
6231         if(ret < 0)
6232                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6233
6234 }
6235
6236 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6237         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6238                                 "mac_addr");
6239 cmdline_parse_token_string_t cmd_mac_addr_what =
6240         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6241                                 "add#remove");
6242 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6243                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6244 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6245                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6246
6247 cmdline_parse_inst_t cmd_mac_addr = {
6248         .f = cmd_mac_addr_parsed,
6249         .data = (void *)0,
6250         .help_str = "mac_addr add|remove X <address>: "
6251                         "add/remove MAC address on port X",
6252         .tokens = {
6253                 (void *)&cmd_mac_addr_cmd,
6254                 (void *)&cmd_mac_addr_what,
6255                 (void *)&cmd_mac_addr_portnum,
6256                 (void *)&cmd_mac_addr_addr,
6257                 NULL,
6258         },
6259 };
6260
6261
6262 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6263 struct cmd_set_qmap_result {
6264         cmdline_fixed_string_t set;
6265         cmdline_fixed_string_t qmap;
6266         cmdline_fixed_string_t what;
6267         uint8_t port_id;
6268         uint16_t queue_id;
6269         uint8_t map_value;
6270 };
6271
6272 static void
6273 cmd_set_qmap_parsed(void *parsed_result,
6274                        __attribute__((unused)) struct cmdline *cl,
6275                        __attribute__((unused)) void *data)
6276 {
6277         struct cmd_set_qmap_result *res = parsed_result;
6278         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6279
6280         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6281 }
6282
6283 cmdline_parse_token_string_t cmd_setqmap_set =
6284         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6285                                  set, "set");
6286 cmdline_parse_token_string_t cmd_setqmap_qmap =
6287         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6288                                  qmap, "stat_qmap");
6289 cmdline_parse_token_string_t cmd_setqmap_what =
6290         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6291                                  what, "tx#rx");
6292 cmdline_parse_token_num_t cmd_setqmap_portid =
6293         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6294                               port_id, UINT8);
6295 cmdline_parse_token_num_t cmd_setqmap_queueid =
6296         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6297                               queue_id, UINT16);
6298 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6299         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6300                               map_value, UINT8);
6301
6302 cmdline_parse_inst_t cmd_set_qmap = {
6303         .f = cmd_set_qmap_parsed,
6304         .data = NULL,
6305         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
6306         .tokens = {
6307                 (void *)&cmd_setqmap_set,
6308                 (void *)&cmd_setqmap_qmap,
6309                 (void *)&cmd_setqmap_what,
6310                 (void *)&cmd_setqmap_portid,
6311                 (void *)&cmd_setqmap_queueid,
6312                 (void *)&cmd_setqmap_mapvalue,
6313                 NULL,
6314         },
6315 };
6316
6317 /* *** CONFIGURE UNICAST HASH TABLE *** */
6318 struct cmd_set_uc_hash_table {
6319         cmdline_fixed_string_t set;
6320         cmdline_fixed_string_t port;
6321         uint8_t port_id;
6322         cmdline_fixed_string_t what;
6323         struct ether_addr address;
6324         cmdline_fixed_string_t mode;
6325 };
6326
6327 static void
6328 cmd_set_uc_hash_parsed(void *parsed_result,
6329                        __attribute__((unused)) struct cmdline *cl,
6330                        __attribute__((unused)) void *data)
6331 {
6332         int ret=0;
6333         struct cmd_set_uc_hash_table *res = parsed_result;
6334
6335         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6336
6337         if (strcmp(res->what, "uta") == 0)
6338                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6339                                                 &res->address,(uint8_t)is_on);
6340         if (ret < 0)
6341                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6342
6343 }
6344
6345 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6347                                  set, "set");
6348 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6349         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6350                                  port, "port");
6351 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6352         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6353                               port_id, UINT8);
6354 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6355         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6356                                  what, "uta");
6357 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6358         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6359                                 address);
6360 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6361         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6362                                  mode, "on#off");
6363
6364 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6365         .f = cmd_set_uc_hash_parsed,
6366         .data = NULL,
6367         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6368         .tokens = {
6369                 (void *)&cmd_set_uc_hash_set,
6370                 (void *)&cmd_set_uc_hash_port,
6371                 (void *)&cmd_set_uc_hash_portid,
6372                 (void *)&cmd_set_uc_hash_what,
6373                 (void *)&cmd_set_uc_hash_mac,
6374                 (void *)&cmd_set_uc_hash_mode,
6375                 NULL,
6376         },
6377 };
6378
6379 struct cmd_set_uc_all_hash_table {
6380         cmdline_fixed_string_t set;
6381         cmdline_fixed_string_t port;
6382         uint8_t port_id;
6383         cmdline_fixed_string_t what;
6384         cmdline_fixed_string_t value;
6385         cmdline_fixed_string_t mode;
6386 };
6387
6388 static void
6389 cmd_set_uc_all_hash_parsed(void *parsed_result,
6390                        __attribute__((unused)) struct cmdline *cl,
6391                        __attribute__((unused)) void *data)
6392 {
6393         int ret=0;
6394         struct cmd_set_uc_all_hash_table *res = parsed_result;
6395
6396         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6397
6398         if ((strcmp(res->what, "uta") == 0) &&
6399                 (strcmp(res->value, "all") == 0))
6400                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6401         if (ret < 0)
6402                 printf("bad unicast hash table parameter,"
6403                         "return code = %d \n", ret);
6404 }
6405
6406 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6407         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6408                                  set, "set");
6409 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6411                                  port, "port");
6412 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6413         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6414                               port_id, UINT8);
6415 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6417                                  what, "uta");
6418 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6420                                 value,"all");
6421 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6422         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6423                                  mode, "on#off");
6424
6425 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6426         .f = cmd_set_uc_all_hash_parsed,
6427         .data = NULL,
6428         .help_str = "set port X uta all on|off (X = port number)",
6429         .tokens = {
6430                 (void *)&cmd_set_uc_all_hash_set,
6431                 (void *)&cmd_set_uc_all_hash_port,
6432                 (void *)&cmd_set_uc_all_hash_portid,
6433                 (void *)&cmd_set_uc_all_hash_what,
6434                 (void *)&cmd_set_uc_all_hash_value,
6435                 (void *)&cmd_set_uc_all_hash_mode,
6436                 NULL,
6437         },
6438 };
6439
6440 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6441 struct cmd_set_vf_macvlan_filter {
6442         cmdline_fixed_string_t set;
6443         cmdline_fixed_string_t port;
6444         uint8_t port_id;
6445         cmdline_fixed_string_t vf;
6446         uint8_t vf_id;
6447         struct ether_addr address;
6448         cmdline_fixed_string_t filter_type;
6449         cmdline_fixed_string_t mode;
6450 };
6451
6452 static void
6453 cmd_set_vf_macvlan_parsed(void *parsed_result,
6454                        __attribute__((unused)) struct cmdline *cl,
6455                        __attribute__((unused)) void *data)
6456 {
6457         int is_on, ret = 0;
6458         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6459         struct rte_eth_mac_filter filter;
6460
6461         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6462
6463         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6464
6465         /* set VF MAC filter */
6466         filter.is_vf = 1;
6467
6468         /* set VF ID */
6469         filter.dst_id = res->vf_id;
6470
6471         if (!strcmp(res->filter_type, "exact-mac"))
6472                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6473         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6474                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6475         else if (!strcmp(res->filter_type, "hashmac"))
6476                 filter.filter_type = RTE_MAC_HASH_MATCH;
6477         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6478                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6479
6480         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6481
6482         if (is_on)
6483                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6484                                         RTE_ETH_FILTER_MACVLAN,
6485                                         RTE_ETH_FILTER_ADD,
6486                                          &filter);
6487         else
6488                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6489                                         RTE_ETH_FILTER_MACVLAN,
6490                                         RTE_ETH_FILTER_DELETE,
6491                                         &filter);
6492
6493         if (ret < 0)
6494                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6495
6496 }
6497
6498 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6499         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6500                                  set, "set");
6501 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6503                                  port, "port");
6504 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6505         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6506                               port_id, UINT8);
6507 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6508         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6509                                  vf, "vf");
6510 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6511         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6512                                 vf_id, UINT8);
6513 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6514         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6515                                 address);
6516 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6517         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6518                                 filter_type, "exact-mac#exact-mac-vlan"
6519                                 "#hashmac#hashmac-vlan");
6520 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6521         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6522                                  mode, "on#off");
6523
6524 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6525         .f = cmd_set_vf_macvlan_parsed,
6526         .data = NULL,
6527         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6528                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6529                         "on|off\n"
6530                         "exact match rule:exact match of MAC or MAC and VLAN; "
6531                         "hash match rule: hash match of MAC and exact match "
6532                         "of VLAN",
6533         .tokens = {
6534                 (void *)&cmd_set_vf_macvlan_set,
6535                 (void *)&cmd_set_vf_macvlan_port,
6536                 (void *)&cmd_set_vf_macvlan_portid,
6537                 (void *)&cmd_set_vf_macvlan_vf,
6538                 (void *)&cmd_set_vf_macvlan_vf_id,
6539                 (void *)&cmd_set_vf_macvlan_mac,
6540                 (void *)&cmd_set_vf_macvlan_filter_type,
6541                 (void *)&cmd_set_vf_macvlan_mode,
6542                 NULL,
6543         },
6544 };
6545
6546 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6547 struct cmd_set_vf_traffic {
6548         cmdline_fixed_string_t set;
6549         cmdline_fixed_string_t port;
6550         uint8_t port_id;
6551         cmdline_fixed_string_t vf;
6552         uint8_t vf_id;
6553         cmdline_fixed_string_t what;
6554         cmdline_fixed_string_t mode;
6555 };
6556
6557 static void
6558 cmd_set_vf_traffic_parsed(void *parsed_result,
6559                        __attribute__((unused)) struct cmdline *cl,
6560                        __attribute__((unused)) void *data)
6561 {
6562         struct cmd_set_vf_traffic *res = parsed_result;
6563         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6564         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6565
6566         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6567 }
6568
6569 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6570         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6571                                  set, "set");
6572 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6573         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6574                                  port, "port");
6575 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6576         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6577                               port_id, UINT8);
6578 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6579         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6580                                  vf, "vf");
6581 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6582         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6583                               vf_id, UINT8);
6584 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6585         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6586                                  what, "tx#rx");
6587 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6588         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6589                                  mode, "on#off");
6590
6591 cmdline_parse_inst_t cmd_set_vf_traffic = {
6592         .f = cmd_set_vf_traffic_parsed,
6593         .data = NULL,
6594         .help_str = "set port X vf Y rx|tx on|off"
6595                         "(X = port number,Y = vf id)",
6596         .tokens = {
6597                 (void *)&cmd_setvf_traffic_set,
6598                 (void *)&cmd_setvf_traffic_port,
6599                 (void *)&cmd_setvf_traffic_portid,
6600                 (void *)&cmd_setvf_traffic_vf,
6601                 (void *)&cmd_setvf_traffic_vfid,
6602                 (void *)&cmd_setvf_traffic_what,
6603                 (void *)&cmd_setvf_traffic_mode,
6604                 NULL,
6605         },
6606 };
6607
6608 /* *** CONFIGURE VF RECEIVE MODE *** */
6609 struct cmd_set_vf_rxmode {
6610         cmdline_fixed_string_t set;
6611         cmdline_fixed_string_t port;
6612         uint8_t port_id;
6613         cmdline_fixed_string_t vf;
6614         uint8_t vf_id;
6615         cmdline_fixed_string_t what;
6616         cmdline_fixed_string_t mode;
6617         cmdline_fixed_string_t on;
6618 };
6619
6620 static void
6621 cmd_set_vf_rxmode_parsed(void *parsed_result,
6622                        __attribute__((unused)) struct cmdline *cl,
6623                        __attribute__((unused)) void *data)
6624 {
6625         int ret;
6626         uint16_t rx_mode = 0;
6627         struct cmd_set_vf_rxmode *res = parsed_result;
6628
6629         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6630         if (!strcmp(res->what,"rxmode")) {
6631                 if (!strcmp(res->mode, "AUPE"))
6632                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6633                 else if (!strcmp(res->mode, "ROPE"))
6634                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6635                 else if (!strcmp(res->mode, "BAM"))
6636                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6637                 else if (!strncmp(res->mode, "MPE",3))
6638                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6639         }
6640
6641         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6642         if (ret < 0)
6643                 printf("bad VF receive mode parameter, return code = %d \n",
6644                 ret);
6645 }
6646
6647 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6648         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6649                                  set, "set");
6650 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6651         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6652                                  port, "port");
6653 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6654         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6655                               port_id, UINT8);
6656 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6657         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6658                                  vf, "vf");
6659 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6660         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6661                               vf_id, UINT8);
6662 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6663         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6664                                  what, "rxmode");
6665 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6666         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6667                                  mode, "AUPE#ROPE#BAM#MPE");
6668 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6670                                  on, "on#off");
6671
6672 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6673         .f = cmd_set_vf_rxmode_parsed,
6674         .data = NULL,
6675         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6676         .tokens = {
6677                 (void *)&cmd_set_vf_rxmode_set,
6678                 (void *)&cmd_set_vf_rxmode_port,
6679                 (void *)&cmd_set_vf_rxmode_portid,
6680                 (void *)&cmd_set_vf_rxmode_vf,
6681                 (void *)&cmd_set_vf_rxmode_vfid,
6682                 (void *)&cmd_set_vf_rxmode_what,
6683                 (void *)&cmd_set_vf_rxmode_mode,
6684                 (void *)&cmd_set_vf_rxmode_on,
6685                 NULL,
6686         },
6687 };
6688
6689 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6690 struct cmd_vf_mac_addr_result {
6691         cmdline_fixed_string_t mac_addr_cmd;
6692         cmdline_fixed_string_t what;
6693         cmdline_fixed_string_t port;
6694         uint8_t port_num;
6695         cmdline_fixed_string_t vf;
6696         uint8_t vf_num;
6697         struct ether_addr address;
6698 };
6699
6700 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6701                 __attribute__((unused)) struct cmdline *cl,
6702                 __attribute__((unused)) void *data)
6703 {
6704         struct cmd_vf_mac_addr_result *res = parsed_result;
6705         int ret = 0;
6706
6707         if (strcmp(res->what, "add") == 0)
6708                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6709                                         &res->address, res->vf_num);
6710         if(ret < 0)
6711                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6712
6713 }
6714
6715 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6716         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6717                                 mac_addr_cmd,"mac_addr");
6718 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6719         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6720                                 what,"add");
6721 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6722         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6723                                 port,"port");
6724 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6725         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6726                                 port_num, UINT8);
6727 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6728         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6729                                 vf,"vf");
6730 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6731         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6732                                 vf_num, UINT8);
6733 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6734         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6735                                 address);
6736
6737 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6738         .f = cmd_vf_mac_addr_parsed,
6739         .data = (void *)0,
6740         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6741         "Y = VF number)add MAC address filtering for a VF on port X",
6742         .tokens = {
6743                 (void *)&cmd_vf_mac_addr_cmd,
6744                 (void *)&cmd_vf_mac_addr_what,
6745                 (void *)&cmd_vf_mac_addr_port,
6746                 (void *)&cmd_vf_mac_addr_portnum,
6747                 (void *)&cmd_vf_mac_addr_vf,
6748                 (void *)&cmd_vf_mac_addr_vfnum,
6749                 (void *)&cmd_vf_mac_addr_addr,
6750                 NULL,
6751         },
6752 };
6753
6754 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6755 struct cmd_vf_rx_vlan_filter {
6756         cmdline_fixed_string_t rx_vlan;
6757         cmdline_fixed_string_t what;
6758         uint16_t vlan_id;
6759         cmdline_fixed_string_t port;
6760         uint8_t port_id;
6761         cmdline_fixed_string_t vf;
6762         uint64_t vf_mask;
6763 };
6764
6765 static void
6766 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6767                           __attribute__((unused)) struct cmdline *cl,
6768                           __attribute__((unused)) void *data)
6769 {
6770         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6771
6772         if (!strcmp(res->what, "add"))
6773                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6774         else
6775                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6776 }
6777
6778 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6779         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6780                                  rx_vlan, "rx_vlan");
6781 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6782         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6783                                  what, "add#rm");
6784 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6785         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6786                               vlan_id, UINT16);
6787 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6788         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6789                                  port, "port");
6790 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6791         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6792                               port_id, UINT8);
6793 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6794         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6795                                  vf, "vf");
6796 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6797         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6798                               vf_mask, UINT64);
6799
6800 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6801         .f = cmd_vf_rx_vlan_filter_parsed,
6802         .data = NULL,
6803         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6804                 "Y = port number,Z = hexadecimal VF mask)",
6805         .tokens = {
6806                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6807                 (void *)&cmd_vf_rx_vlan_filter_what,
6808                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6809                 (void *)&cmd_vf_rx_vlan_filter_port,
6810                 (void *)&cmd_vf_rx_vlan_filter_portid,
6811                 (void *)&cmd_vf_rx_vlan_filter_vf,
6812                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6813                 NULL,
6814         },
6815 };
6816
6817 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6818 struct cmd_queue_rate_limit_result {
6819         cmdline_fixed_string_t set;
6820         cmdline_fixed_string_t port;
6821         uint8_t port_num;
6822         cmdline_fixed_string_t queue;
6823         uint8_t queue_num;
6824         cmdline_fixed_string_t rate;
6825         uint16_t rate_num;
6826 };
6827
6828 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6829                 __attribute__((unused)) struct cmdline *cl,
6830                 __attribute__((unused)) void *data)
6831 {
6832         struct cmd_queue_rate_limit_result *res = parsed_result;
6833         int ret = 0;
6834
6835         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6836                 && (strcmp(res->queue, "queue") == 0)
6837                 && (strcmp(res->rate, "rate") == 0))
6838                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6839                                         res->rate_num);
6840         if (ret < 0)
6841                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6842
6843 }
6844
6845 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6846         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6847                                 set, "set");
6848 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6849         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6850                                 port, "port");
6851 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6852         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6853                                 port_num, UINT8);
6854 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6855         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6856                                 queue, "queue");
6857 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6858         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6859                                 queue_num, UINT8);
6860 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6861         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6862                                 rate, "rate");
6863 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6864         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6865                                 rate_num, UINT16);
6866
6867 cmdline_parse_inst_t cmd_queue_rate_limit = {
6868         .f = cmd_queue_rate_limit_parsed,
6869         .data = (void *)0,
6870         .help_str = "set port X queue Y rate Z:(X = port number,"
6871         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6872         .tokens = {
6873                 (void *)&cmd_queue_rate_limit_set,
6874                 (void *)&cmd_queue_rate_limit_port,
6875                 (void *)&cmd_queue_rate_limit_portnum,
6876                 (void *)&cmd_queue_rate_limit_queue,
6877                 (void *)&cmd_queue_rate_limit_queuenum,
6878                 (void *)&cmd_queue_rate_limit_rate,
6879                 (void *)&cmd_queue_rate_limit_ratenum,
6880                 NULL,
6881         },
6882 };
6883
6884 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6885 struct cmd_vf_rate_limit_result {
6886         cmdline_fixed_string_t set;
6887         cmdline_fixed_string_t port;
6888         uint8_t port_num;
6889         cmdline_fixed_string_t vf;
6890         uint8_t vf_num;
6891         cmdline_fixed_string_t rate;
6892         uint16_t rate_num;
6893         cmdline_fixed_string_t q_msk;
6894         uint64_t q_msk_val;
6895 };
6896
6897 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6898                 __attribute__((unused)) struct cmdline *cl,
6899                 __attribute__((unused)) void *data)
6900 {
6901         struct cmd_vf_rate_limit_result *res = parsed_result;
6902         int ret = 0;
6903
6904         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6905                 && (strcmp(res->vf, "vf") == 0)
6906                 && (strcmp(res->rate, "rate") == 0)
6907                 && (strcmp(res->q_msk, "queue_mask") == 0))
6908                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6909                                         res->rate_num, res->q_msk_val);
6910         if (ret < 0)
6911                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6912
6913 }
6914
6915 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6916         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6917                                 set, "set");
6918 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6919         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6920                                 port, "port");
6921 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6922         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6923                                 port_num, UINT8);
6924 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6925         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6926                                 vf, "vf");
6927 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6928         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6929                                 vf_num, UINT8);
6930 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6931         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6932                                 rate, "rate");
6933 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6934         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6935                                 rate_num, UINT16);
6936 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6937         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6938                                 q_msk, "queue_mask");
6939 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6940         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6941                                 q_msk_val, UINT64);
6942
6943 cmdline_parse_inst_t cmd_vf_rate_limit = {
6944         .f = cmd_vf_rate_limit_parsed,
6945         .data = (void *)0,
6946         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6947         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6948         "for queues of VF on port X",
6949         .tokens = {
6950                 (void *)&cmd_vf_rate_limit_set,
6951                 (void *)&cmd_vf_rate_limit_port,
6952                 (void *)&cmd_vf_rate_limit_portnum,
6953                 (void *)&cmd_vf_rate_limit_vf,
6954                 (void *)&cmd_vf_rate_limit_vfnum,
6955                 (void *)&cmd_vf_rate_limit_rate,
6956                 (void *)&cmd_vf_rate_limit_ratenum,
6957                 (void *)&cmd_vf_rate_limit_q_msk,
6958                 (void *)&cmd_vf_rate_limit_q_msk_val,
6959                 NULL,
6960         },
6961 };
6962
6963 /* *** ADD TUNNEL FILTER OF A PORT *** */
6964 struct cmd_tunnel_filter_result {
6965         cmdline_fixed_string_t cmd;
6966         cmdline_fixed_string_t what;
6967         uint8_t port_id;
6968         struct ether_addr outer_mac;
6969         struct ether_addr inner_mac;
6970         cmdline_ipaddr_t ip_value;
6971         uint16_t inner_vlan;
6972         cmdline_fixed_string_t tunnel_type;
6973         cmdline_fixed_string_t filter_type;
6974         uint32_t tenant_id;
6975         uint16_t queue_num;
6976 };
6977
6978 static void
6979 cmd_tunnel_filter_parsed(void *parsed_result,
6980                           __attribute__((unused)) struct cmdline *cl,
6981                           __attribute__((unused)) void *data)
6982 {
6983         struct cmd_tunnel_filter_result *res = parsed_result;
6984         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6985         int ret = 0;
6986
6987         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
6988
6989         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
6990         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
6991         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6992
6993         if (res->ip_value.family == AF_INET) {
6994                 tunnel_filter_conf.ip_addr.ipv4_addr =
6995                         res->ip_value.addr.ipv4.s_addr;
6996                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6997         } else {
6998                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6999                         &(res->ip_value.addr.ipv6),
7000                         sizeof(struct in6_addr));
7001                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7002         }
7003
7004         if (!strcmp(res->filter_type, "imac-ivlan"))
7005                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7006         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7007                 tunnel_filter_conf.filter_type =
7008                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7009         else if (!strcmp(res->filter_type, "imac-tenid"))
7010                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7011         else if (!strcmp(res->filter_type, "imac"))
7012                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7013         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7014                 tunnel_filter_conf.filter_type =
7015                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7016         else if (!strcmp(res->filter_type, "oip"))
7017                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7018         else if (!strcmp(res->filter_type, "iip"))
7019                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7020         else {
7021                 printf("The filter type is not supported");
7022                 return;
7023         }
7024
7025         if (!strcmp(res->tunnel_type, "vxlan"))
7026                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7027         else if (!strcmp(res->tunnel_type, "nvgre"))
7028                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7029         else if (!strcmp(res->tunnel_type, "ipingre"))
7030                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7031         else {
7032                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7033                 return;
7034         }
7035
7036         tunnel_filter_conf.tenant_id = res->tenant_id;
7037         tunnel_filter_conf.queue_id = res->queue_num;
7038         if (!strcmp(res->what, "add"))
7039                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7040                                         RTE_ETH_FILTER_TUNNEL,
7041                                         RTE_ETH_FILTER_ADD,
7042                                         &tunnel_filter_conf);
7043         else
7044                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7045                                         RTE_ETH_FILTER_TUNNEL,
7046                                         RTE_ETH_FILTER_DELETE,
7047                                         &tunnel_filter_conf);
7048         if (ret < 0)
7049                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7050                                 strerror(-ret));
7051
7052 }
7053 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7054         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7055         cmd, "tunnel_filter");
7056 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7057         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7058         what, "add#rm");
7059 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7060         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7061         port_id, UINT8);
7062 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7063         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7064         outer_mac);
7065 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7066         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7067         inner_mac);
7068 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7069         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7070         inner_vlan, UINT16);
7071 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7072         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7073         ip_value);
7074 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7075         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7076         tunnel_type, "vxlan#nvgre#ipingre");
7077
7078 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7079         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7080         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7081                 "imac#omac-imac-tenid");
7082 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7083         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7084         tenant_id, UINT32);
7085 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7086         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7087         queue_num, UINT16);
7088
7089 cmdline_parse_inst_t cmd_tunnel_filter = {
7090         .f = cmd_tunnel_filter_parsed,
7091         .data = (void *)0,
7092         .help_str = "add/rm tunnel filter of a port: "
7093                         "tunnel_filter add port_id outer_mac inner_mac ip "
7094                         "inner_vlan tunnel_type(vxlan|nvgre|ipingre) filter_type "
7095                         "(oip|iip|imac-ivlan|imac-ivlan-tenid|imac-tenid|"
7096                         "imac|omac-imac-tenid) "
7097                         "tenant_id queue_num",
7098         .tokens = {
7099                 (void *)&cmd_tunnel_filter_cmd,
7100                 (void *)&cmd_tunnel_filter_what,
7101                 (void *)&cmd_tunnel_filter_port_id,
7102                 (void *)&cmd_tunnel_filter_outer_mac,
7103                 (void *)&cmd_tunnel_filter_inner_mac,
7104                 (void *)&cmd_tunnel_filter_ip_value,
7105                 (void *)&cmd_tunnel_filter_innner_vlan,
7106                 (void *)&cmd_tunnel_filter_tunnel_type,
7107                 (void *)&cmd_tunnel_filter_filter_type,
7108                 (void *)&cmd_tunnel_filter_tenant_id,
7109                 (void *)&cmd_tunnel_filter_queue_num,
7110                 NULL,
7111         },
7112 };
7113
7114 /* *** CONFIGURE TUNNEL UDP PORT *** */
7115 struct cmd_tunnel_udp_config {
7116         cmdline_fixed_string_t cmd;
7117         cmdline_fixed_string_t what;
7118         uint16_t udp_port;
7119         uint8_t port_id;
7120 };
7121
7122 static void
7123 cmd_tunnel_udp_config_parsed(void *parsed_result,
7124                           __attribute__((unused)) struct cmdline *cl,
7125                           __attribute__((unused)) void *data)
7126 {
7127         struct cmd_tunnel_udp_config *res = parsed_result;
7128         struct rte_eth_udp_tunnel tunnel_udp;
7129         int ret;
7130
7131         tunnel_udp.udp_port = res->udp_port;
7132
7133         if (!strcmp(res->cmd, "rx_vxlan_port"))
7134                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7135
7136         if (!strcmp(res->what, "add"))
7137                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7138                                                       &tunnel_udp);
7139         else
7140                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7141                                                          &tunnel_udp);
7142
7143         if (ret < 0)
7144                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7145 }
7146
7147 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7148         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7149                                 cmd, "rx_vxlan_port");
7150 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7151         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7152                                 what, "add#rm");
7153 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7154         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7155                                 udp_port, UINT16);
7156 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7157         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7158                                 port_id, UINT8);
7159
7160 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7161         .f = cmd_tunnel_udp_config_parsed,
7162         .data = (void *)0,
7163         .help_str = "add/rm an tunneling UDP port filter: "
7164                         "rx_vxlan_port add udp_port port_id",
7165         .tokens = {
7166                 (void *)&cmd_tunnel_udp_config_cmd,
7167                 (void *)&cmd_tunnel_udp_config_what,
7168                 (void *)&cmd_tunnel_udp_config_udp_port,
7169                 (void *)&cmd_tunnel_udp_config_port_id,
7170                 NULL,
7171         },
7172 };
7173
7174 /* *** GLOBAL CONFIG *** */
7175 struct cmd_global_config_result {
7176         cmdline_fixed_string_t cmd;
7177         uint8_t port_id;
7178         cmdline_fixed_string_t cfg_type;
7179         uint8_t len;
7180 };
7181
7182 static void
7183 cmd_global_config_parsed(void *parsed_result,
7184                          __attribute__((unused)) struct cmdline *cl,
7185                          __attribute__((unused)) void *data)
7186 {
7187         struct cmd_global_config_result *res = parsed_result;
7188         struct rte_eth_global_cfg conf;
7189         int ret;
7190
7191         memset(&conf, 0, sizeof(conf));
7192         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7193         conf.cfg.gre_key_len = res->len;
7194         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7195                                       RTE_ETH_FILTER_SET, &conf);
7196         if (ret != 0)
7197                 printf("Global config error\n");
7198 }
7199
7200 cmdline_parse_token_string_t cmd_global_config_cmd =
7201         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7202                 "global_config");
7203 cmdline_parse_token_num_t cmd_global_config_port_id =
7204         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7205 cmdline_parse_token_string_t cmd_global_config_type =
7206         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7207                 cfg_type, "gre-key-len");
7208 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7209         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7210                 len, UINT8);
7211
7212 cmdline_parse_inst_t cmd_global_config = {
7213         .f = cmd_global_config_parsed,
7214         .data = (void *)NULL,
7215         .help_str = "global_config <port_id> gre-key-len <number>",
7216         .tokens = {
7217                 (void *)&cmd_global_config_cmd,
7218                 (void *)&cmd_global_config_port_id,
7219                 (void *)&cmd_global_config_type,
7220                 (void *)&cmd_global_config_gre_key_len,
7221                 NULL,
7222         },
7223 };
7224
7225 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7226 struct cmd_set_mirror_mask_result {
7227         cmdline_fixed_string_t set;
7228         cmdline_fixed_string_t port;
7229         uint8_t port_id;
7230         cmdline_fixed_string_t mirror;
7231         uint8_t rule_id;
7232         cmdline_fixed_string_t what;
7233         cmdline_fixed_string_t value;
7234         cmdline_fixed_string_t dstpool;
7235         uint8_t dstpool_id;
7236         cmdline_fixed_string_t on;
7237 };
7238
7239 cmdline_parse_token_string_t cmd_mirror_mask_set =
7240         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7241                                 set, "set");
7242 cmdline_parse_token_string_t cmd_mirror_mask_port =
7243         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7244                                 port, "port");
7245 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7246         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7247                                 port_id, UINT8);
7248 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7249         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7250                                 mirror, "mirror-rule");
7251 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7252         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7253                                 rule_id, UINT8);
7254 cmdline_parse_token_string_t cmd_mirror_mask_what =
7255         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7256                                 what, "pool-mirror-up#pool-mirror-down"
7257                                       "#vlan-mirror");
7258 cmdline_parse_token_string_t cmd_mirror_mask_value =
7259         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7260                                 value, NULL);
7261 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7262         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7263                                 dstpool, "dst-pool");
7264 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7265         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7266                                 dstpool_id, UINT8);
7267 cmdline_parse_token_string_t cmd_mirror_mask_on =
7268         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7269                                 on, "on#off");
7270
7271 static void
7272 cmd_set_mirror_mask_parsed(void *parsed_result,
7273                        __attribute__((unused)) struct cmdline *cl,
7274                        __attribute__((unused)) void *data)
7275 {
7276         int ret,nb_item,i;
7277         struct cmd_set_mirror_mask_result *res = parsed_result;
7278         struct rte_eth_mirror_conf mr_conf;
7279
7280         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7281
7282         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7283
7284         mr_conf.dst_pool = res->dstpool_id;
7285
7286         if (!strcmp(res->what, "pool-mirror-up")) {
7287                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7288                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7289         } else if (!strcmp(res->what, "pool-mirror-down")) {
7290                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7291                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7292         } else if (!strcmp(res->what, "vlan-mirror")) {
7293                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7294                 nb_item = parse_item_list(res->value, "vlan",
7295                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7296                 if (nb_item <= 0)
7297                         return;
7298
7299                 for (i = 0; i < nb_item; i++) {
7300                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7301                                 printf("Invalid vlan_id: must be < 4096\n");
7302                                 return;
7303                         }
7304
7305                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7306                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7307                 }
7308         }
7309
7310         if (!strcmp(res->on, "on"))
7311                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7312                                                 res->rule_id, 1);
7313         else
7314                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7315                                                 res->rule_id, 0);
7316         if (ret < 0)
7317                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7318 }
7319
7320 cmdline_parse_inst_t cmd_set_mirror_mask = {
7321                 .f = cmd_set_mirror_mask_parsed,
7322                 .data = NULL,
7323                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
7324                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
7325                 .tokens = {
7326                         (void *)&cmd_mirror_mask_set,
7327                         (void *)&cmd_mirror_mask_port,
7328                         (void *)&cmd_mirror_mask_portid,
7329                         (void *)&cmd_mirror_mask_mirror,
7330                         (void *)&cmd_mirror_mask_ruleid,
7331                         (void *)&cmd_mirror_mask_what,
7332                         (void *)&cmd_mirror_mask_value,
7333                         (void *)&cmd_mirror_mask_dstpool,
7334                         (void *)&cmd_mirror_mask_poolid,
7335                         (void *)&cmd_mirror_mask_on,
7336                         NULL,
7337                 },
7338 };
7339
7340 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
7341 struct cmd_set_mirror_link_result {
7342         cmdline_fixed_string_t set;
7343         cmdline_fixed_string_t port;
7344         uint8_t port_id;
7345         cmdline_fixed_string_t mirror;
7346         uint8_t rule_id;
7347         cmdline_fixed_string_t what;
7348         cmdline_fixed_string_t dstpool;
7349         uint8_t dstpool_id;
7350         cmdline_fixed_string_t on;
7351 };
7352
7353 cmdline_parse_token_string_t cmd_mirror_link_set =
7354         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7355                                  set, "set");
7356 cmdline_parse_token_string_t cmd_mirror_link_port =
7357         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7358                                 port, "port");
7359 cmdline_parse_token_num_t cmd_mirror_link_portid =
7360         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7361                                 port_id, UINT8);
7362 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7363         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7364                                 mirror, "mirror-rule");
7365 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7366         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7367                             rule_id, UINT8);
7368 cmdline_parse_token_string_t cmd_mirror_link_what =
7369         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7370                                 what, "uplink-mirror#downlink-mirror");
7371 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7373                                 dstpool, "dst-pool");
7374 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7375         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7376                                 dstpool_id, UINT8);
7377 cmdline_parse_token_string_t cmd_mirror_link_on =
7378         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7379                                 on, "on#off");
7380
7381 static void
7382 cmd_set_mirror_link_parsed(void *parsed_result,
7383                        __attribute__((unused)) struct cmdline *cl,
7384                        __attribute__((unused)) void *data)
7385 {
7386         int ret;
7387         struct cmd_set_mirror_link_result *res = parsed_result;
7388         struct rte_eth_mirror_conf mr_conf;
7389
7390         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7391         if (!strcmp(res->what, "uplink-mirror"))
7392                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7393         else
7394                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7395
7396         mr_conf.dst_pool = res->dstpool_id;
7397
7398         if (!strcmp(res->on, "on"))
7399                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7400                                                 res->rule_id, 1);
7401         else
7402                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7403                                                 res->rule_id, 0);
7404
7405         /* check the return value and print it if is < 0 */
7406         if (ret < 0)
7407                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7408
7409 }
7410
7411 cmdline_parse_inst_t cmd_set_mirror_link = {
7412                 .f = cmd_set_mirror_link_parsed,
7413                 .data = NULL,
7414                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7415                         "downlink-mirror dst-pool Z on|off",
7416                 .tokens = {
7417                         (void *)&cmd_mirror_link_set,
7418                         (void *)&cmd_mirror_link_port,
7419                         (void *)&cmd_mirror_link_portid,
7420                         (void *)&cmd_mirror_link_mirror,
7421                         (void *)&cmd_mirror_link_ruleid,
7422                         (void *)&cmd_mirror_link_what,
7423                         (void *)&cmd_mirror_link_dstpool,
7424                         (void *)&cmd_mirror_link_poolid,
7425                         (void *)&cmd_mirror_link_on,
7426                         NULL,
7427                 },
7428 };
7429
7430 /* *** RESET VM MIRROR RULE *** */
7431 struct cmd_rm_mirror_rule_result {
7432         cmdline_fixed_string_t reset;
7433         cmdline_fixed_string_t port;
7434         uint8_t port_id;
7435         cmdline_fixed_string_t mirror;
7436         uint8_t rule_id;
7437 };
7438
7439 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7440         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7441                                  reset, "reset");
7442 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7443         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7444                                 port, "port");
7445 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7446         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7447                                 port_id, UINT8);
7448 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7449         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7450                                 mirror, "mirror-rule");
7451 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7452         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7453                                 rule_id, UINT8);
7454
7455 static void
7456 cmd_reset_mirror_rule_parsed(void *parsed_result,
7457                        __attribute__((unused)) struct cmdline *cl,
7458                        __attribute__((unused)) void *data)
7459 {
7460         int ret;
7461         struct cmd_set_mirror_link_result *res = parsed_result;
7462         /* check rule_id */
7463         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7464         if(ret < 0)
7465                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7466 }
7467
7468 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7469                 .f = cmd_reset_mirror_rule_parsed,
7470                 .data = NULL,
7471                 .help_str = "reset port X mirror-rule Y",
7472                 .tokens = {
7473                         (void *)&cmd_rm_mirror_rule_reset,
7474                         (void *)&cmd_rm_mirror_rule_port,
7475                         (void *)&cmd_rm_mirror_rule_portid,
7476                         (void *)&cmd_rm_mirror_rule_mirror,
7477                         (void *)&cmd_rm_mirror_rule_ruleid,
7478                         NULL,
7479                 },
7480 };
7481
7482 /* ******************************************************************************** */
7483
7484 struct cmd_dump_result {
7485         cmdline_fixed_string_t dump;
7486 };
7487
7488 static void
7489 dump_struct_sizes(void)
7490 {
7491 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7492         DUMP_SIZE(struct rte_mbuf);
7493         DUMP_SIZE(struct rte_mempool);
7494         DUMP_SIZE(struct rte_ring);
7495 #undef DUMP_SIZE
7496 }
7497
7498 static void cmd_dump_parsed(void *parsed_result,
7499                             __attribute__((unused)) struct cmdline *cl,
7500                             __attribute__((unused)) void *data)
7501 {
7502         struct cmd_dump_result *res = parsed_result;
7503
7504         if (!strcmp(res->dump, "dump_physmem"))
7505                 rte_dump_physmem_layout(stdout);
7506         else if (!strcmp(res->dump, "dump_memzone"))
7507                 rte_memzone_dump(stdout);
7508         else if (!strcmp(res->dump, "dump_struct_sizes"))
7509                 dump_struct_sizes();
7510         else if (!strcmp(res->dump, "dump_ring"))
7511                 rte_ring_list_dump(stdout);
7512         else if (!strcmp(res->dump, "dump_mempool"))
7513                 rte_mempool_list_dump(stdout);
7514         else if (!strcmp(res->dump, "dump_devargs"))
7515                 rte_eal_devargs_dump(stdout);
7516 }
7517
7518 cmdline_parse_token_string_t cmd_dump_dump =
7519         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7520                 "dump_physmem#"
7521                 "dump_memzone#"
7522                 "dump_struct_sizes#"
7523                 "dump_ring#"
7524                 "dump_mempool#"
7525                 "dump_devargs");
7526
7527 cmdline_parse_inst_t cmd_dump = {
7528         .f = cmd_dump_parsed,  /* function to call */
7529         .data = NULL,      /* 2nd arg of func */
7530         .help_str = "dump status",
7531         .tokens = {        /* token list, NULL terminated */
7532                 (void *)&cmd_dump_dump,
7533                 NULL,
7534         },
7535 };
7536
7537 /* ******************************************************************************** */
7538
7539 struct cmd_dump_one_result {
7540         cmdline_fixed_string_t dump;
7541         cmdline_fixed_string_t name;
7542 };
7543
7544 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7545                                 __attribute__((unused)) void *data)
7546 {
7547         struct cmd_dump_one_result *res = parsed_result;
7548
7549         if (!strcmp(res->dump, "dump_ring")) {
7550                 struct rte_ring *r;
7551                 r = rte_ring_lookup(res->name);
7552                 if (r == NULL) {
7553                         cmdline_printf(cl, "Cannot find ring\n");
7554                         return;
7555                 }
7556                 rte_ring_dump(stdout, r);
7557         } else if (!strcmp(res->dump, "dump_mempool")) {
7558                 struct rte_mempool *mp;
7559                 mp = rte_mempool_lookup(res->name);
7560                 if (mp == NULL) {
7561                         cmdline_printf(cl, "Cannot find mempool\n");
7562                         return;
7563                 }
7564                 rte_mempool_dump(stdout, mp);
7565         }
7566 }
7567
7568 cmdline_parse_token_string_t cmd_dump_one_dump =
7569         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7570                                  "dump_ring#dump_mempool");
7571
7572 cmdline_parse_token_string_t cmd_dump_one_name =
7573         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7574
7575 cmdline_parse_inst_t cmd_dump_one = {
7576         .f = cmd_dump_one_parsed,  /* function to call */
7577         .data = NULL,      /* 2nd arg of func */
7578         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7579         .tokens = {        /* token list, NULL terminated */
7580                 (void *)&cmd_dump_one_dump,
7581                 (void *)&cmd_dump_one_name,
7582                 NULL,
7583         },
7584 };
7585
7586 /* *** Add/Del syn filter *** */
7587 struct cmd_syn_filter_result {
7588         cmdline_fixed_string_t filter;
7589         uint8_t port_id;
7590         cmdline_fixed_string_t ops;
7591         cmdline_fixed_string_t priority;
7592         cmdline_fixed_string_t high;
7593         cmdline_fixed_string_t queue;
7594         uint16_t queue_id;
7595 };
7596
7597 static void
7598 cmd_syn_filter_parsed(void *parsed_result,
7599                         __attribute__((unused)) struct cmdline *cl,
7600                         __attribute__((unused)) void *data)
7601 {
7602         struct cmd_syn_filter_result *res = parsed_result;
7603         struct rte_eth_syn_filter syn_filter;
7604         int ret = 0;
7605
7606         ret = rte_eth_dev_filter_supported(res->port_id,
7607                                         RTE_ETH_FILTER_SYN);
7608         if (ret < 0) {
7609                 printf("syn filter is not supported on port %u.\n",
7610                                 res->port_id);
7611                 return;
7612         }
7613
7614         memset(&syn_filter, 0, sizeof(syn_filter));
7615
7616         if (!strcmp(res->ops, "add")) {
7617                 if (!strcmp(res->high, "high"))
7618                         syn_filter.hig_pri = 1;
7619                 else
7620                         syn_filter.hig_pri = 0;
7621
7622                 syn_filter.queue = res->queue_id;
7623                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7624                                                 RTE_ETH_FILTER_SYN,
7625                                                 RTE_ETH_FILTER_ADD,
7626                                                 &syn_filter);
7627         } else
7628                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7629                                                 RTE_ETH_FILTER_SYN,
7630                                                 RTE_ETH_FILTER_DELETE,
7631                                                 &syn_filter);
7632
7633         if (ret < 0)
7634                 printf("syn filter programming error: (%s)\n",
7635                                 strerror(-ret));
7636 }
7637
7638 cmdline_parse_token_string_t cmd_syn_filter_filter =
7639         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7640         filter, "syn_filter");
7641 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7642         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7643         port_id, UINT8);
7644 cmdline_parse_token_string_t cmd_syn_filter_ops =
7645         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7646         ops, "add#del");
7647 cmdline_parse_token_string_t cmd_syn_filter_priority =
7648         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7649                                 priority, "priority");
7650 cmdline_parse_token_string_t cmd_syn_filter_high =
7651         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7652                                 high, "high#low");
7653 cmdline_parse_token_string_t cmd_syn_filter_queue =
7654         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7655                                 queue, "queue");
7656 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7657         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7658                                 queue_id, UINT16);
7659
7660 cmdline_parse_inst_t cmd_syn_filter = {
7661         .f = cmd_syn_filter_parsed,
7662         .data = NULL,
7663         .help_str = "add/delete syn filter",
7664         .tokens = {
7665                 (void *)&cmd_syn_filter_filter,
7666                 (void *)&cmd_syn_filter_port_id,
7667                 (void *)&cmd_syn_filter_ops,
7668                 (void *)&cmd_syn_filter_priority,
7669                 (void *)&cmd_syn_filter_high,
7670                 (void *)&cmd_syn_filter_queue,
7671                 (void *)&cmd_syn_filter_queue_id,
7672                 NULL,
7673         },
7674 };
7675
7676 /* *** ADD/REMOVE A 2tuple FILTER *** */
7677 struct cmd_2tuple_filter_result {
7678         cmdline_fixed_string_t filter;
7679         uint8_t  port_id;
7680         cmdline_fixed_string_t ops;
7681         cmdline_fixed_string_t dst_port;
7682         uint16_t dst_port_value;
7683         cmdline_fixed_string_t protocol;
7684         uint8_t protocol_value;
7685         cmdline_fixed_string_t mask;
7686         uint8_t  mask_value;
7687         cmdline_fixed_string_t tcp_flags;
7688         uint8_t tcp_flags_value;
7689         cmdline_fixed_string_t priority;
7690         uint8_t  priority_value;
7691         cmdline_fixed_string_t queue;
7692         uint16_t  queue_id;
7693 };
7694
7695 static void
7696 cmd_2tuple_filter_parsed(void *parsed_result,
7697                         __attribute__((unused)) struct cmdline *cl,
7698                         __attribute__((unused)) void *data)
7699 {
7700         struct rte_eth_ntuple_filter filter;
7701         struct cmd_2tuple_filter_result *res = parsed_result;
7702         int ret = 0;
7703
7704         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7705         if (ret < 0) {
7706                 printf("ntuple filter is not supported on port %u.\n",
7707                         res->port_id);
7708                 return;
7709         }
7710
7711         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7712
7713         filter.flags = RTE_2TUPLE_FLAGS;
7714         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7715         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7716         filter.proto = res->protocol_value;
7717         filter.priority = res->priority_value;
7718         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7719                 printf("nonzero tcp_flags is only meaningful"
7720                         " when protocol is TCP.\n");
7721                 return;
7722         }
7723         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7724                 printf("invalid TCP flags.\n");
7725                 return;
7726         }
7727
7728         if (res->tcp_flags_value != 0) {
7729                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7730                 filter.tcp_flags = res->tcp_flags_value;
7731         }
7732
7733         /* need convert to big endian. */
7734         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7735         filter.queue = res->queue_id;
7736
7737         if (!strcmp(res->ops, "add"))
7738                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7739                                 RTE_ETH_FILTER_NTUPLE,
7740                                 RTE_ETH_FILTER_ADD,
7741                                 &filter);
7742         else
7743                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7744                                 RTE_ETH_FILTER_NTUPLE,
7745                                 RTE_ETH_FILTER_DELETE,
7746                                 &filter);
7747         if (ret < 0)
7748                 printf("2tuple filter programming error: (%s)\n",
7749                         strerror(-ret));
7750
7751 }
7752
7753 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7754         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7755                                  filter, "2tuple_filter");
7756 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7757         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7758                                 port_id, UINT8);
7759 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7760         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7761                                  ops, "add#del");
7762 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7763         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7764                                 dst_port, "dst_port");
7765 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7766         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7767                                 dst_port_value, UINT16);
7768 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7769         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7770                                 protocol, "protocol");
7771 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7772         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7773                                 protocol_value, UINT8);
7774 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7775         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7776                                 mask, "mask");
7777 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7778         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7779                                 mask_value, INT8);
7780 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7781         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7782                                 tcp_flags, "tcp_flags");
7783 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7784         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7785                                 tcp_flags_value, UINT8);
7786 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7787         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7788                                 priority, "priority");
7789 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7790         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7791                                 priority_value, UINT8);
7792 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7793         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7794                                 queue, "queue");
7795 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7796         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7797                                 queue_id, UINT16);
7798
7799 cmdline_parse_inst_t cmd_2tuple_filter = {
7800         .f = cmd_2tuple_filter_parsed,
7801         .data = NULL,
7802         .help_str = "add a 2tuple filter",
7803         .tokens = {
7804                 (void *)&cmd_2tuple_filter_filter,
7805                 (void *)&cmd_2tuple_filter_port_id,
7806                 (void *)&cmd_2tuple_filter_ops,
7807                 (void *)&cmd_2tuple_filter_dst_port,
7808                 (void *)&cmd_2tuple_filter_dst_port_value,
7809                 (void *)&cmd_2tuple_filter_protocol,
7810                 (void *)&cmd_2tuple_filter_protocol_value,
7811                 (void *)&cmd_2tuple_filter_mask,
7812                 (void *)&cmd_2tuple_filter_mask_value,
7813                 (void *)&cmd_2tuple_filter_tcp_flags,
7814                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7815                 (void *)&cmd_2tuple_filter_priority,
7816                 (void *)&cmd_2tuple_filter_priority_value,
7817                 (void *)&cmd_2tuple_filter_queue,
7818                 (void *)&cmd_2tuple_filter_queue_id,
7819                 NULL,
7820         },
7821 };
7822
7823 /* *** ADD/REMOVE A 5tuple FILTER *** */
7824 struct cmd_5tuple_filter_result {
7825         cmdline_fixed_string_t filter;
7826         uint8_t  port_id;
7827         cmdline_fixed_string_t ops;
7828         cmdline_fixed_string_t dst_ip;
7829         cmdline_ipaddr_t dst_ip_value;
7830         cmdline_fixed_string_t src_ip;
7831         cmdline_ipaddr_t src_ip_value;
7832         cmdline_fixed_string_t dst_port;
7833         uint16_t dst_port_value;
7834         cmdline_fixed_string_t src_port;
7835         uint16_t src_port_value;
7836         cmdline_fixed_string_t protocol;
7837         uint8_t protocol_value;
7838         cmdline_fixed_string_t mask;
7839         uint8_t  mask_value;
7840         cmdline_fixed_string_t tcp_flags;
7841         uint8_t tcp_flags_value;
7842         cmdline_fixed_string_t priority;
7843         uint8_t  priority_value;
7844         cmdline_fixed_string_t queue;
7845         uint16_t  queue_id;
7846 };
7847
7848 static void
7849 cmd_5tuple_filter_parsed(void *parsed_result,
7850                         __attribute__((unused)) struct cmdline *cl,
7851                         __attribute__((unused)) void *data)
7852 {
7853         struct rte_eth_ntuple_filter filter;
7854         struct cmd_5tuple_filter_result *res = parsed_result;
7855         int ret = 0;
7856
7857         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7858         if (ret < 0) {
7859                 printf("ntuple filter is not supported on port %u.\n",
7860                         res->port_id);
7861                 return;
7862         }
7863
7864         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7865
7866         filter.flags = RTE_5TUPLE_FLAGS;
7867         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7868         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7869         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7870         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7871         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7872         filter.proto = res->protocol_value;
7873         filter.priority = res->priority_value;
7874         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7875                 printf("nonzero tcp_flags is only meaningful"
7876                         " when protocol is TCP.\n");
7877                 return;
7878         }
7879         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7880                 printf("invalid TCP flags.\n");
7881                 return;
7882         }
7883
7884         if (res->tcp_flags_value != 0) {
7885                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7886                 filter.tcp_flags = res->tcp_flags_value;
7887         }
7888
7889         if (res->dst_ip_value.family == AF_INET)
7890                 /* no need to convert, already big endian. */
7891                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7892         else {
7893                 if (filter.dst_ip_mask == 0) {
7894                         printf("can not support ipv6 involved compare.\n");
7895                         return;
7896                 }
7897                 filter.dst_ip = 0;
7898         }
7899
7900         if (res->src_ip_value.family == AF_INET)
7901                 /* no need to convert, already big endian. */
7902                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7903         else {
7904                 if (filter.src_ip_mask == 0) {
7905                         printf("can not support ipv6 involved compare.\n");
7906                         return;
7907                 }
7908                 filter.src_ip = 0;
7909         }
7910         /* need convert to big endian. */
7911         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7912         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7913         filter.queue = res->queue_id;
7914
7915         if (!strcmp(res->ops, "add"))
7916                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7917                                 RTE_ETH_FILTER_NTUPLE,
7918                                 RTE_ETH_FILTER_ADD,
7919                                 &filter);
7920         else
7921                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7922                                 RTE_ETH_FILTER_NTUPLE,
7923                                 RTE_ETH_FILTER_DELETE,
7924                                 &filter);
7925         if (ret < 0)
7926                 printf("5tuple filter programming error: (%s)\n",
7927                         strerror(-ret));
7928 }
7929
7930 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7931         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7932                                  filter, "5tuple_filter");
7933 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7934         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7935                                 port_id, UINT8);
7936 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7937         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7938                                  ops, "add#del");
7939 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7940         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7941                                 dst_ip, "dst_ip");
7942 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7943         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7944                                 dst_ip_value);
7945 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7946         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7947                                 src_ip, "src_ip");
7948 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7949         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7950                                 src_ip_value);
7951 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7952         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7953                                 dst_port, "dst_port");
7954 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7955         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7956                                 dst_port_value, UINT16);
7957 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7958         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7959                                 src_port, "src_port");
7960 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7961         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7962                                 src_port_value, UINT16);
7963 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7964         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7965                                 protocol, "protocol");
7966 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7967         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7968                                 protocol_value, UINT8);
7969 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7970         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7971                                 mask, "mask");
7972 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7973         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7974                                 mask_value, INT8);
7975 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7976         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7977                                 tcp_flags, "tcp_flags");
7978 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7979         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7980                                 tcp_flags_value, UINT8);
7981 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7982         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7983                                 priority, "priority");
7984 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7985         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7986                                 priority_value, UINT8);
7987 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7988         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7989                                 queue, "queue");
7990 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7991         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7992                                 queue_id, UINT16);
7993
7994 cmdline_parse_inst_t cmd_5tuple_filter = {
7995         .f = cmd_5tuple_filter_parsed,
7996         .data = NULL,
7997         .help_str = "add/del a 5tuple filter",
7998         .tokens = {
7999                 (void *)&cmd_5tuple_filter_filter,
8000                 (void *)&cmd_5tuple_filter_port_id,
8001                 (void *)&cmd_5tuple_filter_ops,
8002                 (void *)&cmd_5tuple_filter_dst_ip,
8003                 (void *)&cmd_5tuple_filter_dst_ip_value,
8004                 (void *)&cmd_5tuple_filter_src_ip,
8005                 (void *)&cmd_5tuple_filter_src_ip_value,
8006                 (void *)&cmd_5tuple_filter_dst_port,
8007                 (void *)&cmd_5tuple_filter_dst_port_value,
8008                 (void *)&cmd_5tuple_filter_src_port,
8009                 (void *)&cmd_5tuple_filter_src_port_value,
8010                 (void *)&cmd_5tuple_filter_protocol,
8011                 (void *)&cmd_5tuple_filter_protocol_value,
8012                 (void *)&cmd_5tuple_filter_mask,
8013                 (void *)&cmd_5tuple_filter_mask_value,
8014                 (void *)&cmd_5tuple_filter_tcp_flags,
8015                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8016                 (void *)&cmd_5tuple_filter_priority,
8017                 (void *)&cmd_5tuple_filter_priority_value,
8018                 (void *)&cmd_5tuple_filter_queue,
8019                 (void *)&cmd_5tuple_filter_queue_id,
8020                 NULL,
8021         },
8022 };
8023
8024 /* *** ADD/REMOVE A flex FILTER *** */
8025 struct cmd_flex_filter_result {
8026         cmdline_fixed_string_t filter;
8027         cmdline_fixed_string_t ops;
8028         uint8_t port_id;
8029         cmdline_fixed_string_t len;
8030         uint8_t len_value;
8031         cmdline_fixed_string_t bytes;
8032         cmdline_fixed_string_t bytes_value;
8033         cmdline_fixed_string_t mask;
8034         cmdline_fixed_string_t mask_value;
8035         cmdline_fixed_string_t priority;
8036         uint8_t priority_value;
8037         cmdline_fixed_string_t queue;
8038         uint16_t queue_id;
8039 };
8040
8041 static int xdigit2val(unsigned char c)
8042 {
8043         int val;
8044         if (isdigit(c))
8045                 val = c - '0';
8046         else if (isupper(c))
8047                 val = c - 'A' + 10;
8048         else
8049                 val = c - 'a' + 10;
8050         return val;
8051 }
8052
8053 static void
8054 cmd_flex_filter_parsed(void *parsed_result,
8055                           __attribute__((unused)) struct cmdline *cl,
8056                           __attribute__((unused)) void *data)
8057 {
8058         int ret = 0;
8059         struct rte_eth_flex_filter filter;
8060         struct cmd_flex_filter_result *res = parsed_result;
8061         char *bytes_ptr, *mask_ptr;
8062         uint16_t len, i, j = 0;
8063         char c;
8064         int val;
8065         uint8_t byte = 0;
8066
8067         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8068                 printf("the len exceed the max length 128\n");
8069                 return;
8070         }
8071         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8072         filter.len = res->len_value;
8073         filter.priority = res->priority_value;
8074         filter.queue = res->queue_id;
8075         bytes_ptr = res->bytes_value;
8076         mask_ptr = res->mask_value;
8077
8078          /* translate bytes string to array. */
8079         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8080                 (bytes_ptr[1] == 'X')))
8081                 bytes_ptr += 2;
8082         len = strnlen(bytes_ptr, res->len_value * 2);
8083         if (len == 0 || (len % 8 != 0)) {
8084                 printf("please check len and bytes input\n");
8085                 return;
8086         }
8087         for (i = 0; i < len; i++) {
8088                 c = bytes_ptr[i];
8089                 if (isxdigit(c) == 0) {
8090                         /* invalid characters. */
8091                         printf("invalid input\n");
8092                         return;
8093                 }
8094                 val = xdigit2val(c);
8095                 if (i % 2) {
8096                         byte |= val;
8097                         filter.bytes[j] = byte;
8098                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8099                         j++;
8100                         byte = 0;
8101                 } else
8102                         byte |= val << 4;
8103         }
8104         printf("\n");
8105          /* translate mask string to uint8_t array. */
8106         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8107                 (mask_ptr[1] == 'X')))
8108                 mask_ptr += 2;
8109         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8110         if (len == 0) {
8111                 printf("invalid input\n");
8112                 return;
8113         }
8114         j = 0;
8115         byte = 0;
8116         for (i = 0; i < len; i++) {
8117                 c = mask_ptr[i];
8118                 if (isxdigit(c) == 0) {
8119                         /* invalid characters. */
8120                         printf("invalid input\n");
8121                         return;
8122                 }
8123                 val = xdigit2val(c);
8124                 if (i % 2) {
8125                         byte |= val;
8126                         filter.mask[j] = byte;
8127                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8128                         j++;
8129                         byte = 0;
8130                 } else
8131                         byte |= val << 4;
8132         }
8133         printf("\n");
8134
8135         if (!strcmp(res->ops, "add"))
8136                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8137                                 RTE_ETH_FILTER_FLEXIBLE,
8138                                 RTE_ETH_FILTER_ADD,
8139                                 &filter);
8140         else
8141                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8142                                 RTE_ETH_FILTER_FLEXIBLE,
8143                                 RTE_ETH_FILTER_DELETE,
8144                                 &filter);
8145
8146         if (ret < 0)
8147                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8148 }
8149
8150 cmdline_parse_token_string_t cmd_flex_filter_filter =
8151         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8152                                 filter, "flex_filter");
8153 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8154         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8155                                 port_id, UINT8);
8156 cmdline_parse_token_string_t cmd_flex_filter_ops =
8157         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8158                                 ops, "add#del");
8159 cmdline_parse_token_string_t cmd_flex_filter_len =
8160         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8161                                 len, "len");
8162 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8163         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8164                                 len_value, UINT8);
8165 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8166         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8167                                 bytes, "bytes");
8168 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8169         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8170                                 bytes_value, NULL);
8171 cmdline_parse_token_string_t cmd_flex_filter_mask =
8172         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8173                                 mask, "mask");
8174 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8175         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8176                                 mask_value, NULL);
8177 cmdline_parse_token_string_t cmd_flex_filter_priority =
8178         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8179                                 priority, "priority");
8180 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8181         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8182                                 priority_value, UINT8);
8183 cmdline_parse_token_string_t cmd_flex_filter_queue =
8184         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8185                                 queue, "queue");
8186 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8187         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8188                                 queue_id, UINT16);
8189 cmdline_parse_inst_t cmd_flex_filter = {
8190         .f = cmd_flex_filter_parsed,
8191         .data = NULL,
8192         .help_str = "add/del a flex filter",
8193         .tokens = {
8194                 (void *)&cmd_flex_filter_filter,
8195                 (void *)&cmd_flex_filter_port_id,
8196                 (void *)&cmd_flex_filter_ops,
8197                 (void *)&cmd_flex_filter_len,
8198                 (void *)&cmd_flex_filter_len_value,
8199                 (void *)&cmd_flex_filter_bytes,
8200                 (void *)&cmd_flex_filter_bytes_value,
8201                 (void *)&cmd_flex_filter_mask,
8202                 (void *)&cmd_flex_filter_mask_value,
8203                 (void *)&cmd_flex_filter_priority,
8204                 (void *)&cmd_flex_filter_priority_value,
8205                 (void *)&cmd_flex_filter_queue,
8206                 (void *)&cmd_flex_filter_queue_id,
8207                 NULL,
8208         },
8209 };
8210
8211 /* *** Filters Control *** */
8212
8213 /* *** deal with ethertype filter *** */
8214 struct cmd_ethertype_filter_result {
8215         cmdline_fixed_string_t filter;
8216         uint8_t port_id;
8217         cmdline_fixed_string_t ops;
8218         cmdline_fixed_string_t mac;
8219         struct ether_addr mac_addr;
8220         cmdline_fixed_string_t ethertype;
8221         uint16_t ethertype_value;
8222         cmdline_fixed_string_t drop;
8223         cmdline_fixed_string_t queue;
8224         uint16_t  queue_id;
8225 };
8226
8227 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8228         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8229                                  filter, "ethertype_filter");
8230 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8231         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8232                               port_id, UINT8);
8233 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8234         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8235                                  ops, "add#del");
8236 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8237         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8238                                  mac, "mac_addr#mac_ignr");
8239 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8240         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8241                                      mac_addr);
8242 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8243         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8244                                  ethertype, "ethertype");
8245 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8246         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8247                               ethertype_value, UINT16);
8248 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8249         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8250                                  drop, "drop#fwd");
8251 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8252         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8253                                  queue, "queue");
8254 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8255         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8256                               queue_id, UINT16);
8257
8258 static void
8259 cmd_ethertype_filter_parsed(void *parsed_result,
8260                           __attribute__((unused)) struct cmdline *cl,
8261                           __attribute__((unused)) void *data)
8262 {
8263         struct cmd_ethertype_filter_result *res = parsed_result;
8264         struct rte_eth_ethertype_filter filter;
8265         int ret = 0;
8266
8267         ret = rte_eth_dev_filter_supported(res->port_id,
8268                         RTE_ETH_FILTER_ETHERTYPE);
8269         if (ret < 0) {
8270                 printf("ethertype filter is not supported on port %u.\n",
8271                         res->port_id);
8272                 return;
8273         }
8274
8275         memset(&filter, 0, sizeof(filter));
8276         if (!strcmp(res->mac, "mac_addr")) {
8277                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8278                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8279                         sizeof(struct ether_addr));
8280         }
8281         if (!strcmp(res->drop, "drop"))
8282                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8283         filter.ether_type = res->ethertype_value;
8284         filter.queue = res->queue_id;
8285
8286         if (!strcmp(res->ops, "add"))
8287                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8288                                 RTE_ETH_FILTER_ETHERTYPE,
8289                                 RTE_ETH_FILTER_ADD,
8290                                 &filter);
8291         else
8292                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8293                                 RTE_ETH_FILTER_ETHERTYPE,
8294                                 RTE_ETH_FILTER_DELETE,
8295                                 &filter);
8296         if (ret < 0)
8297                 printf("ethertype filter programming error: (%s)\n",
8298                         strerror(-ret));
8299 }
8300
8301 cmdline_parse_inst_t cmd_ethertype_filter = {
8302         .f = cmd_ethertype_filter_parsed,
8303         .data = NULL,
8304         .help_str = "add or delete an ethertype filter entry",
8305         .tokens = {
8306                 (void *)&cmd_ethertype_filter_filter,
8307                 (void *)&cmd_ethertype_filter_port_id,
8308                 (void *)&cmd_ethertype_filter_ops,
8309                 (void *)&cmd_ethertype_filter_mac,
8310                 (void *)&cmd_ethertype_filter_mac_addr,
8311                 (void *)&cmd_ethertype_filter_ethertype,
8312                 (void *)&cmd_ethertype_filter_ethertype_value,
8313                 (void *)&cmd_ethertype_filter_drop,
8314                 (void *)&cmd_ethertype_filter_queue,
8315                 (void *)&cmd_ethertype_filter_queue_id,
8316                 NULL,
8317         },
8318 };
8319
8320 /* *** deal with flow director filter *** */
8321 struct cmd_flow_director_result {
8322         cmdline_fixed_string_t flow_director_filter;
8323         uint8_t port_id;
8324         cmdline_fixed_string_t mode;
8325         cmdline_fixed_string_t mode_value;
8326         cmdline_fixed_string_t ops;
8327         cmdline_fixed_string_t flow;
8328         cmdline_fixed_string_t flow_type;
8329         cmdline_fixed_string_t ether;
8330         uint16_t ether_type;
8331         cmdline_fixed_string_t src;
8332         cmdline_ipaddr_t ip_src;
8333         uint16_t port_src;
8334         cmdline_fixed_string_t dst;
8335         cmdline_ipaddr_t ip_dst;
8336         uint16_t port_dst;
8337         cmdline_fixed_string_t verify_tag;
8338         uint32_t verify_tag_value;
8339         cmdline_ipaddr_t tos;
8340         uint8_t tos_value;
8341         cmdline_ipaddr_t proto;
8342         uint8_t proto_value;
8343         cmdline_ipaddr_t ttl;
8344         uint8_t ttl_value;
8345         cmdline_fixed_string_t vlan;
8346         uint16_t vlan_value;
8347         cmdline_fixed_string_t flexbytes;
8348         cmdline_fixed_string_t flexbytes_value;
8349         cmdline_fixed_string_t pf_vf;
8350         cmdline_fixed_string_t drop;
8351         cmdline_fixed_string_t queue;
8352         uint16_t  queue_id;
8353         cmdline_fixed_string_t fd_id;
8354         uint32_t  fd_id_value;
8355         cmdline_fixed_string_t mac;
8356         struct ether_addr mac_addr;
8357         cmdline_fixed_string_t tunnel;
8358         cmdline_fixed_string_t tunnel_type;
8359         cmdline_fixed_string_t tunnel_id;
8360         uint32_t tunnel_id_value;
8361 };
8362
8363 static inline int
8364 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8365 {
8366         char s[256];
8367         const char *p, *p0 = q_arg;
8368         char *end;
8369         unsigned long int_fld;
8370         char *str_fld[max_num];
8371         int i;
8372         unsigned size;
8373         int ret = -1;
8374
8375         p = strchr(p0, '(');
8376         if (p == NULL)
8377                 return -1;
8378         ++p;
8379         p0 = strchr(p, ')');
8380         if (p0 == NULL)
8381                 return -1;
8382
8383         size = p0 - p;
8384         if (size >= sizeof(s))
8385                 return -1;
8386
8387         snprintf(s, sizeof(s), "%.*s", size, p);
8388         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8389         if (ret < 0 || ret > max_num)
8390                 return -1;
8391         for (i = 0; i < ret; i++) {
8392                 errno = 0;
8393                 int_fld = strtoul(str_fld[i], &end, 0);
8394                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8395                         return -1;
8396                 flexbytes[i] = (uint8_t)int_fld;
8397         }
8398         return ret;
8399 }
8400
8401 static uint16_t
8402 str2flowtype(char *string)
8403 {
8404         uint8_t i = 0;
8405         static const struct {
8406                 char str[32];
8407                 uint16_t type;
8408         } flowtype_str[] = {
8409                 {"raw", RTE_ETH_FLOW_RAW},
8410                 {"ipv4", RTE_ETH_FLOW_IPV4},
8411                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8412                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8413                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8414                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8415                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8416                 {"ipv6", RTE_ETH_FLOW_IPV6},
8417                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8418                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8419                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8420                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8421                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8422                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8423         };
8424
8425         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8426                 if (!strcmp(flowtype_str[i].str, string))
8427                         return flowtype_str[i].type;
8428         }
8429         return RTE_ETH_FLOW_UNKNOWN;
8430 }
8431
8432 static enum rte_eth_fdir_tunnel_type
8433 str2fdir_tunneltype(char *string)
8434 {
8435         uint8_t i = 0;
8436
8437         static const struct {
8438                 char str[32];
8439                 enum rte_eth_fdir_tunnel_type type;
8440         } tunneltype_str[] = {
8441                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8442                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8443         };
8444
8445         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8446                 if (!strcmp(tunneltype_str[i].str, string))
8447                         return tunneltype_str[i].type;
8448         }
8449         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8450 }
8451
8452 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8453 do { \
8454         if ((ip_addr).family == AF_INET) \
8455                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8456         else { \
8457                 printf("invalid parameter.\n"); \
8458                 return; \
8459         } \
8460 } while (0)
8461
8462 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8463 do { \
8464         if ((ip_addr).family == AF_INET6) \
8465                 (void)rte_memcpy(&(ip), \
8466                                  &((ip_addr).addr.ipv6), \
8467                                  sizeof(struct in6_addr)); \
8468         else { \
8469                 printf("invalid parameter.\n"); \
8470                 return; \
8471         } \
8472 } while (0)
8473
8474 static void
8475 cmd_flow_director_filter_parsed(void *parsed_result,
8476                           __attribute__((unused)) struct cmdline *cl,
8477                           __attribute__((unused)) void *data)
8478 {
8479         struct cmd_flow_director_result *res = parsed_result;
8480         struct rte_eth_fdir_filter entry;
8481         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8482         char *end;
8483         unsigned long vf_id;
8484         int ret = 0;
8485
8486         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8487         if (ret < 0) {
8488                 printf("flow director is not supported on port %u.\n",
8489                         res->port_id);
8490                 return;
8491         }
8492         memset(flexbytes, 0, sizeof(flexbytes));
8493         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8494
8495         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8496                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8497                         printf("Please set mode to MAC-VLAN.\n");
8498                         return;
8499                 }
8500         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8501                 if (strcmp(res->mode_value, "Tunnel")) {
8502                         printf("Please set mode to Tunnel.\n");
8503                         return;
8504                 }
8505         } else {
8506                 if (strcmp(res->mode_value, "IP")) {
8507                         printf("Please set mode to IP.\n");
8508                         return;
8509                 }
8510                 entry.input.flow_type = str2flowtype(res->flow_type);
8511         }
8512
8513         ret = parse_flexbytes(res->flexbytes_value,
8514                                         flexbytes,
8515                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8516         if (ret < 0) {
8517                 printf("error: Cannot parse flexbytes input.\n");
8518                 return;
8519         }
8520
8521         switch (entry.input.flow_type) {
8522         case RTE_ETH_FLOW_FRAG_IPV4:
8523         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8524                 entry.input.flow.ip4_flow.proto = res->proto_value;
8525         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8526         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8527                 IPV4_ADDR_TO_UINT(res->ip_dst,
8528                         entry.input.flow.ip4_flow.dst_ip);
8529                 IPV4_ADDR_TO_UINT(res->ip_src,
8530                         entry.input.flow.ip4_flow.src_ip);
8531                 entry.input.flow.ip4_flow.tos = res->tos_value;
8532                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8533                 /* need convert to big endian. */
8534                 entry.input.flow.udp4_flow.dst_port =
8535                                 rte_cpu_to_be_16(res->port_dst);
8536                 entry.input.flow.udp4_flow.src_port =
8537                                 rte_cpu_to_be_16(res->port_src);
8538                 break;
8539         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8540                 IPV4_ADDR_TO_UINT(res->ip_dst,
8541                         entry.input.flow.sctp4_flow.ip.dst_ip);
8542                 IPV4_ADDR_TO_UINT(res->ip_src,
8543                         entry.input.flow.sctp4_flow.ip.src_ip);
8544                 entry.input.flow.ip4_flow.tos = res->tos_value;
8545                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8546                 /* need convert to big endian. */
8547                 entry.input.flow.sctp4_flow.dst_port =
8548                                 rte_cpu_to_be_16(res->port_dst);
8549                 entry.input.flow.sctp4_flow.src_port =
8550                                 rte_cpu_to_be_16(res->port_src);
8551                 entry.input.flow.sctp4_flow.verify_tag =
8552                                 rte_cpu_to_be_32(res->verify_tag_value);
8553                 break;
8554         case RTE_ETH_FLOW_FRAG_IPV6:
8555         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8556                 entry.input.flow.ipv6_flow.proto = res->proto_value;
8557         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8558         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8559                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8560                         entry.input.flow.ipv6_flow.dst_ip);
8561                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8562                         entry.input.flow.ipv6_flow.src_ip);
8563                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8564                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8565                 /* need convert to big endian. */
8566                 entry.input.flow.udp6_flow.dst_port =
8567                                 rte_cpu_to_be_16(res->port_dst);
8568                 entry.input.flow.udp6_flow.src_port =
8569                                 rte_cpu_to_be_16(res->port_src);
8570                 break;
8571         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8572                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8573                         entry.input.flow.sctp6_flow.ip.dst_ip);
8574                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8575                         entry.input.flow.sctp6_flow.ip.src_ip);
8576                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8577                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8578                 /* need convert to big endian. */
8579                 entry.input.flow.sctp6_flow.dst_port =
8580                                 rte_cpu_to_be_16(res->port_dst);
8581                 entry.input.flow.sctp6_flow.src_port =
8582                                 rte_cpu_to_be_16(res->port_src);
8583                 entry.input.flow.sctp6_flow.verify_tag =
8584                                 rte_cpu_to_be_32(res->verify_tag_value);
8585                 break;
8586         case RTE_ETH_FLOW_L2_PAYLOAD:
8587                 entry.input.flow.l2_flow.ether_type =
8588                         rte_cpu_to_be_16(res->ether_type);
8589                 break;
8590         default:
8591                 break;
8592         }
8593
8594         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8595                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8596                                  &res->mac_addr,
8597                                  sizeof(struct ether_addr));
8598
8599         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8600                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8601                                  &res->mac_addr,
8602                                  sizeof(struct ether_addr));
8603                 entry.input.flow.tunnel_flow.tunnel_type =
8604                         str2fdir_tunneltype(res->tunnel_type);
8605                 entry.input.flow.tunnel_flow.tunnel_id =
8606                         rte_cpu_to_be_32(res->tunnel_id_value);
8607         }
8608
8609         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8610                    flexbytes,
8611                    RTE_ETH_FDIR_MAX_FLEXLEN);
8612
8613         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8614
8615         entry.action.flex_off = 0;  /*use 0 by default */
8616         if (!strcmp(res->drop, "drop"))
8617                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8618         else
8619                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8620
8621         if (!strcmp(res->pf_vf, "pf"))
8622                 entry.input.flow_ext.is_vf = 0;
8623         else if (!strncmp(res->pf_vf, "vf", 2)) {
8624                 struct rte_eth_dev_info dev_info;
8625
8626                 memset(&dev_info, 0, sizeof(dev_info));
8627                 rte_eth_dev_info_get(res->port_id, &dev_info);
8628                 errno = 0;
8629                 vf_id = strtoul(res->pf_vf + 2, &end, 10);
8630                 if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
8631                         printf("invalid parameter %s.\n", res->pf_vf);
8632                         return;
8633                 }
8634                 entry.input.flow_ext.is_vf = 1;
8635                 entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8636         } else {
8637                 printf("invalid parameter %s.\n", res->pf_vf);
8638                 return;
8639         }
8640
8641         /* set to report FD ID by default */
8642         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8643         entry.action.rx_queue = res->queue_id;
8644         entry.soft_id = res->fd_id_value;
8645         if (!strcmp(res->ops, "add"))
8646                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8647                                              RTE_ETH_FILTER_ADD, &entry);
8648         else if (!strcmp(res->ops, "del"))
8649                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8650                                              RTE_ETH_FILTER_DELETE, &entry);
8651         else
8652                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8653                                              RTE_ETH_FILTER_UPDATE, &entry);
8654         if (ret < 0)
8655                 printf("flow director programming error: (%s)\n",
8656                         strerror(-ret));
8657 }
8658
8659 cmdline_parse_token_string_t cmd_flow_director_filter =
8660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8661                                  flow_director_filter, "flow_director_filter");
8662 cmdline_parse_token_num_t cmd_flow_director_port_id =
8663         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8664                               port_id, UINT8);
8665 cmdline_parse_token_string_t cmd_flow_director_ops =
8666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8667                                  ops, "add#del#update");
8668 cmdline_parse_token_string_t cmd_flow_director_flow =
8669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8670                                  flow, "flow");
8671 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8672         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8673                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8674                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8675 cmdline_parse_token_string_t cmd_flow_director_ether =
8676         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8677                                  ether, "ether");
8678 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8679         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8680                               ether_type, UINT16);
8681 cmdline_parse_token_string_t cmd_flow_director_src =
8682         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8683                                  src, "src");
8684 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8685         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8686                                  ip_src);
8687 cmdline_parse_token_num_t cmd_flow_director_port_src =
8688         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8689                               port_src, UINT16);
8690 cmdline_parse_token_string_t cmd_flow_director_dst =
8691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8692                                  dst, "dst");
8693 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8694         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8695                                  ip_dst);
8696 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8697         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8698                               port_dst, UINT16);
8699 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8701                                   verify_tag, "verify_tag");
8702 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8703         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8704                               verify_tag_value, UINT32);
8705 cmdline_parse_token_string_t cmd_flow_director_tos =
8706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8707                                  tos, "tos");
8708 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8709         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8710                               tos_value, UINT8);
8711 cmdline_parse_token_string_t cmd_flow_director_proto =
8712         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8713                                  proto, "proto");
8714 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8715         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8716                               proto_value, UINT8);
8717 cmdline_parse_token_string_t cmd_flow_director_ttl =
8718         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8719                                  ttl, "ttl");
8720 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8721         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8722                               ttl_value, UINT8);
8723 cmdline_parse_token_string_t cmd_flow_director_vlan =
8724         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8725                                  vlan, "vlan");
8726 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8727         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8728                               vlan_value, UINT16);
8729 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8731                                  flexbytes, "flexbytes");
8732 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8734                               flexbytes_value, NULL);
8735 cmdline_parse_token_string_t cmd_flow_director_drop =
8736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8737                                  drop, "drop#fwd");
8738 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8739         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8740                               pf_vf, NULL);
8741 cmdline_parse_token_string_t cmd_flow_director_queue =
8742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8743                                  queue, "queue");
8744 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8746                               queue_id, UINT16);
8747 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8749                                  fd_id, "fd_id");
8750 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8752                               fd_id_value, UINT32);
8753
8754 cmdline_parse_token_string_t cmd_flow_director_mode =
8755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8756                                  mode, "mode");
8757 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8758         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8759                                  mode_value, "IP");
8760 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8761         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8762                                  mode_value, "MAC-VLAN");
8763 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8764         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8765                                  mode_value, "Tunnel");
8766 cmdline_parse_token_string_t cmd_flow_director_mac =
8767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8768                                  mac, "mac");
8769 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8770         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8771                                     mac_addr);
8772 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8773         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8774                                  tunnel, "tunnel");
8775 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8776         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8777                                  tunnel_type, "NVGRE#VxLAN");
8778 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8779         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8780                                  tunnel_id, "tunnel-id");
8781 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8782         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8783                               tunnel_id_value, UINT32);
8784
8785 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8786         .f = cmd_flow_director_filter_parsed,
8787         .data = NULL,
8788         .help_str = "add or delete an ip flow director entry on NIC",
8789         .tokens = {
8790                 (void *)&cmd_flow_director_filter,
8791                 (void *)&cmd_flow_director_port_id,
8792                 (void *)&cmd_flow_director_mode,
8793                 (void *)&cmd_flow_director_mode_ip,
8794                 (void *)&cmd_flow_director_ops,
8795                 (void *)&cmd_flow_director_flow,
8796                 (void *)&cmd_flow_director_flow_type,
8797                 (void *)&cmd_flow_director_src,
8798                 (void *)&cmd_flow_director_ip_src,
8799                 (void *)&cmd_flow_director_dst,
8800                 (void *)&cmd_flow_director_ip_dst,
8801                 (void *)&cmd_flow_director_tos,
8802                 (void *)&cmd_flow_director_tos_value,
8803                 (void *)&cmd_flow_director_proto,
8804                 (void *)&cmd_flow_director_proto_value,
8805                 (void *)&cmd_flow_director_ttl,
8806                 (void *)&cmd_flow_director_ttl_value,
8807                 (void *)&cmd_flow_director_vlan,
8808                 (void *)&cmd_flow_director_vlan_value,
8809                 (void *)&cmd_flow_director_flexbytes,
8810                 (void *)&cmd_flow_director_flexbytes_value,
8811                 (void *)&cmd_flow_director_drop,
8812                 (void *)&cmd_flow_director_pf_vf,
8813                 (void *)&cmd_flow_director_queue,
8814                 (void *)&cmd_flow_director_queue_id,
8815                 (void *)&cmd_flow_director_fd_id,
8816                 (void *)&cmd_flow_director_fd_id_value,
8817                 NULL,
8818         },
8819 };
8820
8821 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8822         .f = cmd_flow_director_filter_parsed,
8823         .data = NULL,
8824         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8825         .tokens = {
8826                 (void *)&cmd_flow_director_filter,
8827                 (void *)&cmd_flow_director_port_id,
8828                 (void *)&cmd_flow_director_mode,
8829                 (void *)&cmd_flow_director_mode_ip,
8830                 (void *)&cmd_flow_director_ops,
8831                 (void *)&cmd_flow_director_flow,
8832                 (void *)&cmd_flow_director_flow_type,
8833                 (void *)&cmd_flow_director_src,
8834                 (void *)&cmd_flow_director_ip_src,
8835                 (void *)&cmd_flow_director_port_src,
8836                 (void *)&cmd_flow_director_dst,
8837                 (void *)&cmd_flow_director_ip_dst,
8838                 (void *)&cmd_flow_director_port_dst,
8839                 (void *)&cmd_flow_director_tos,
8840                 (void *)&cmd_flow_director_tos_value,
8841                 (void *)&cmd_flow_director_ttl,
8842                 (void *)&cmd_flow_director_ttl_value,
8843                 (void *)&cmd_flow_director_vlan,
8844                 (void *)&cmd_flow_director_vlan_value,
8845                 (void *)&cmd_flow_director_flexbytes,
8846                 (void *)&cmd_flow_director_flexbytes_value,
8847                 (void *)&cmd_flow_director_drop,
8848                 (void *)&cmd_flow_director_pf_vf,
8849                 (void *)&cmd_flow_director_queue,
8850                 (void *)&cmd_flow_director_queue_id,
8851                 (void *)&cmd_flow_director_fd_id,
8852                 (void *)&cmd_flow_director_fd_id_value,
8853                 NULL,
8854         },
8855 };
8856
8857 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8858         .f = cmd_flow_director_filter_parsed,
8859         .data = NULL,
8860         .help_str = "add or delete a sctp flow director entry on NIC",
8861         .tokens = {
8862                 (void *)&cmd_flow_director_filter,
8863                 (void *)&cmd_flow_director_port_id,
8864                 (void *)&cmd_flow_director_mode,
8865                 (void *)&cmd_flow_director_mode_ip,
8866                 (void *)&cmd_flow_director_ops,
8867                 (void *)&cmd_flow_director_flow,
8868                 (void *)&cmd_flow_director_flow_type,
8869                 (void *)&cmd_flow_director_src,
8870                 (void *)&cmd_flow_director_ip_src,
8871                 (void *)&cmd_flow_director_port_dst,
8872                 (void *)&cmd_flow_director_dst,
8873                 (void *)&cmd_flow_director_ip_dst,
8874                 (void *)&cmd_flow_director_port_dst,
8875                 (void *)&cmd_flow_director_verify_tag,
8876                 (void *)&cmd_flow_director_verify_tag_value,
8877                 (void *)&cmd_flow_director_tos,
8878                 (void *)&cmd_flow_director_tos_value,
8879                 (void *)&cmd_flow_director_ttl,
8880                 (void *)&cmd_flow_director_ttl_value,
8881                 (void *)&cmd_flow_director_vlan,
8882                 (void *)&cmd_flow_director_vlan_value,
8883                 (void *)&cmd_flow_director_flexbytes,
8884                 (void *)&cmd_flow_director_flexbytes_value,
8885                 (void *)&cmd_flow_director_drop,
8886                 (void *)&cmd_flow_director_pf_vf,
8887                 (void *)&cmd_flow_director_queue,
8888                 (void *)&cmd_flow_director_queue_id,
8889                 (void *)&cmd_flow_director_fd_id,
8890                 (void *)&cmd_flow_director_fd_id_value,
8891                 NULL,
8892         },
8893 };
8894
8895 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
8896         .f = cmd_flow_director_filter_parsed,
8897         .data = NULL,
8898         .help_str = "add or delete a L2 flow director entry on NIC",
8899         .tokens = {
8900                 (void *)&cmd_flow_director_filter,
8901                 (void *)&cmd_flow_director_port_id,
8902                 (void *)&cmd_flow_director_mode,
8903                 (void *)&cmd_flow_director_mode_ip,
8904                 (void *)&cmd_flow_director_ops,
8905                 (void *)&cmd_flow_director_flow,
8906                 (void *)&cmd_flow_director_flow_type,
8907                 (void *)&cmd_flow_director_ether,
8908                 (void *)&cmd_flow_director_ether_type,
8909                 (void *)&cmd_flow_director_flexbytes,
8910                 (void *)&cmd_flow_director_flexbytes_value,
8911                 (void *)&cmd_flow_director_drop,
8912                 (void *)&cmd_flow_director_pf_vf,
8913                 (void *)&cmd_flow_director_queue,
8914                 (void *)&cmd_flow_director_queue_id,
8915                 (void *)&cmd_flow_director_fd_id,
8916                 (void *)&cmd_flow_director_fd_id_value,
8917                 NULL,
8918         },
8919 };
8920
8921 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
8922         .f = cmd_flow_director_filter_parsed,
8923         .data = NULL,
8924         .help_str = "add or delete a MAC VLAN flow director entry on NIC",
8925         .tokens = {
8926                 (void *)&cmd_flow_director_filter,
8927                 (void *)&cmd_flow_director_port_id,
8928                 (void *)&cmd_flow_director_mode,
8929                 (void *)&cmd_flow_director_mode_mac_vlan,
8930                 (void *)&cmd_flow_director_ops,
8931                 (void *)&cmd_flow_director_mac,
8932                 (void *)&cmd_flow_director_mac_addr,
8933                 (void *)&cmd_flow_director_vlan,
8934                 (void *)&cmd_flow_director_vlan_value,
8935                 (void *)&cmd_flow_director_flexbytes,
8936                 (void *)&cmd_flow_director_flexbytes_value,
8937                 (void *)&cmd_flow_director_drop,
8938                 (void *)&cmd_flow_director_queue,
8939                 (void *)&cmd_flow_director_queue_id,
8940                 (void *)&cmd_flow_director_fd_id,
8941                 (void *)&cmd_flow_director_fd_id_value,
8942                 NULL,
8943         },
8944 };
8945
8946 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
8947         .f = cmd_flow_director_filter_parsed,
8948         .data = NULL,
8949         .help_str = "add or delete a tunnel flow director entry on NIC",
8950         .tokens = {
8951                 (void *)&cmd_flow_director_filter,
8952                 (void *)&cmd_flow_director_port_id,
8953                 (void *)&cmd_flow_director_mode,
8954                 (void *)&cmd_flow_director_mode_tunnel,
8955                 (void *)&cmd_flow_director_ops,
8956                 (void *)&cmd_flow_director_mac,
8957                 (void *)&cmd_flow_director_mac_addr,
8958                 (void *)&cmd_flow_director_vlan,
8959                 (void *)&cmd_flow_director_vlan_value,
8960                 (void *)&cmd_flow_director_tunnel,
8961                 (void *)&cmd_flow_director_tunnel_type,
8962                 (void *)&cmd_flow_director_tunnel_id,
8963                 (void *)&cmd_flow_director_tunnel_id_value,
8964                 (void *)&cmd_flow_director_flexbytes,
8965                 (void *)&cmd_flow_director_flexbytes_value,
8966                 (void *)&cmd_flow_director_drop,
8967                 (void *)&cmd_flow_director_queue,
8968                 (void *)&cmd_flow_director_queue_id,
8969                 (void *)&cmd_flow_director_fd_id,
8970                 (void *)&cmd_flow_director_fd_id_value,
8971                 NULL,
8972         },
8973 };
8974
8975 struct cmd_flush_flow_director_result {
8976         cmdline_fixed_string_t flush_flow_director;
8977         uint8_t port_id;
8978 };
8979
8980 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8981         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8982                                  flush_flow_director, "flush_flow_director");
8983 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8984         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8985                               port_id, UINT8);
8986
8987 static void
8988 cmd_flush_flow_director_parsed(void *parsed_result,
8989                           __attribute__((unused)) struct cmdline *cl,
8990                           __attribute__((unused)) void *data)
8991 {
8992         struct cmd_flow_director_result *res = parsed_result;
8993         int ret = 0;
8994
8995         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8996         if (ret < 0) {
8997                 printf("flow director is not supported on port %u.\n",
8998                         res->port_id);
8999                 return;
9000         }
9001
9002         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9003                         RTE_ETH_FILTER_FLUSH, NULL);
9004         if (ret < 0)
9005                 printf("flow director table flushing error: (%s)\n",
9006                         strerror(-ret));
9007 }
9008
9009 cmdline_parse_inst_t cmd_flush_flow_director = {
9010         .f = cmd_flush_flow_director_parsed,
9011         .data = NULL,
9012         .help_str = "flush all flow director entries of a device on NIC",
9013         .tokens = {
9014                 (void *)&cmd_flush_flow_director_flush,
9015                 (void *)&cmd_flush_flow_director_port_id,
9016                 NULL,
9017         },
9018 };
9019
9020 /* *** deal with flow director mask *** */
9021 struct cmd_flow_director_mask_result {
9022         cmdline_fixed_string_t flow_director_mask;
9023         uint8_t port_id;
9024         cmdline_fixed_string_t mode;
9025         cmdline_fixed_string_t mode_value;
9026         cmdline_fixed_string_t vlan;
9027         uint16_t vlan_mask;
9028         cmdline_fixed_string_t src_mask;
9029         cmdline_ipaddr_t ipv4_src;
9030         cmdline_ipaddr_t ipv6_src;
9031         uint16_t port_src;
9032         cmdline_fixed_string_t dst_mask;
9033         cmdline_ipaddr_t ipv4_dst;
9034         cmdline_ipaddr_t ipv6_dst;
9035         uint16_t port_dst;
9036         cmdline_fixed_string_t mac;
9037         uint8_t mac_addr_byte_mask;
9038         cmdline_fixed_string_t tunnel_id;
9039         uint32_t tunnel_id_mask;
9040         cmdline_fixed_string_t tunnel_type;
9041         uint8_t tunnel_type_mask;
9042 };
9043
9044 static void
9045 cmd_flow_director_mask_parsed(void *parsed_result,
9046                           __attribute__((unused)) struct cmdline *cl,
9047                           __attribute__((unused)) void *data)
9048 {
9049         struct cmd_flow_director_mask_result *res = parsed_result;
9050         struct rte_eth_fdir_masks *mask;
9051         struct rte_port *port;
9052
9053         if (res->port_id > nb_ports) {
9054                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9055                 return;
9056         }
9057
9058         port = &ports[res->port_id];
9059         /** Check if the port is not started **/
9060         if (port->port_status != RTE_PORT_STOPPED) {
9061                 printf("Please stop port %d first\n", res->port_id);
9062                 return;
9063         }
9064
9065         mask = &port->dev_conf.fdir_conf.mask;
9066
9067         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9068                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9069                         printf("Please set mode to MAC-VLAN.\n");
9070                         return;
9071                 }
9072
9073                 mask->vlan_tci_mask = res->vlan_mask;
9074                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9075         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9076                 if (strcmp(res->mode_value, "Tunnel")) {
9077                         printf("Please set mode to Tunnel.\n");
9078                         return;
9079                 }
9080
9081                 mask->vlan_tci_mask = res->vlan_mask;
9082                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9083                 mask->tunnel_id_mask = res->tunnel_id_mask;
9084                 mask->tunnel_type_mask = res->tunnel_type_mask;
9085         } else {
9086                 if (strcmp(res->mode_value, "IP")) {
9087                         printf("Please set mode to IP.\n");
9088                         return;
9089                 }
9090
9091                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9092                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9093                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9094                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9095                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9096                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9097                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9098         }
9099
9100         cmd_reconfig_device_queue(res->port_id, 1, 1);
9101 }
9102
9103 cmdline_parse_token_string_t cmd_flow_director_mask =
9104         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9105                                  flow_director_mask, "flow_director_mask");
9106 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9107         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9108                               port_id, UINT8);
9109 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9110         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9111                                  vlan, "vlan");
9112 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9113         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9114                               vlan_mask, UINT16);
9115 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9116         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9117                                  src_mask, "src_mask");
9118 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9119         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9120                                  ipv4_src);
9121 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9122         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9123                                  ipv6_src);
9124 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9125         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9126                               port_src, UINT16);
9127 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9128         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9129                                  dst_mask, "dst_mask");
9130 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9131         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9132                                  ipv4_dst);
9133 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9134         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9135                                  ipv6_dst);
9136 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9137         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9138                               port_dst, UINT16);
9139
9140 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9141         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9142                                  mode, "mode");
9143 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9144         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9145                                  mode_value, "IP");
9146 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9147         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9148                                  mode_value, "MAC-VLAN");
9149 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9151                                  mode_value, "Tunnel");
9152 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9153         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9154                                  mac, "mac");
9155 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9156         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9157                               mac_addr_byte_mask, UINT8);
9158 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9159         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9160                                  tunnel_type, "tunnel-type");
9161 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9162         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9163                               tunnel_type_mask, UINT8);
9164 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9166                                  tunnel_id, "tunnel-id");
9167 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9168         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9169                               tunnel_id_mask, UINT32);
9170
9171 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9172         .f = cmd_flow_director_mask_parsed,
9173         .data = NULL,
9174         .help_str = "set IP mode flow director's mask on NIC",
9175         .tokens = {
9176                 (void *)&cmd_flow_director_mask,
9177                 (void *)&cmd_flow_director_mask_port_id,
9178                 (void *)&cmd_flow_director_mask_mode,
9179                 (void *)&cmd_flow_director_mask_mode_ip,
9180                 (void *)&cmd_flow_director_mask_vlan,
9181                 (void *)&cmd_flow_director_mask_vlan_value,
9182                 (void *)&cmd_flow_director_mask_src,
9183                 (void *)&cmd_flow_director_mask_ipv4_src,
9184                 (void *)&cmd_flow_director_mask_ipv6_src,
9185                 (void *)&cmd_flow_director_mask_port_src,
9186                 (void *)&cmd_flow_director_mask_dst,
9187                 (void *)&cmd_flow_director_mask_ipv4_dst,
9188                 (void *)&cmd_flow_director_mask_ipv6_dst,
9189                 (void *)&cmd_flow_director_mask_port_dst,
9190                 NULL,
9191         },
9192 };
9193
9194 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9195         .f = cmd_flow_director_mask_parsed,
9196         .data = NULL,
9197         .help_str = "set MAC VLAN mode flow director's mask on NIC",
9198         .tokens = {
9199                 (void *)&cmd_flow_director_mask,
9200                 (void *)&cmd_flow_director_mask_port_id,
9201                 (void *)&cmd_flow_director_mask_mode,
9202                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9203                 (void *)&cmd_flow_director_mask_vlan,
9204                 (void *)&cmd_flow_director_mask_vlan_value,
9205                 (void *)&cmd_flow_director_mask_mac,
9206                 (void *)&cmd_flow_director_mask_mac_value,
9207                 NULL,
9208         },
9209 };
9210
9211 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9212         .f = cmd_flow_director_mask_parsed,
9213         .data = NULL,
9214         .help_str = "set tunnel mode flow director's mask on NIC",
9215         .tokens = {
9216                 (void *)&cmd_flow_director_mask,
9217                 (void *)&cmd_flow_director_mask_port_id,
9218                 (void *)&cmd_flow_director_mask_mode,
9219                 (void *)&cmd_flow_director_mask_mode_tunnel,
9220                 (void *)&cmd_flow_director_mask_vlan,
9221                 (void *)&cmd_flow_director_mask_vlan_value,
9222                 (void *)&cmd_flow_director_mask_mac,
9223                 (void *)&cmd_flow_director_mask_mac_value,
9224                 (void *)&cmd_flow_director_mask_tunnel_type,
9225                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9226                 (void *)&cmd_flow_director_mask_tunnel_id,
9227                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9228                 NULL,
9229         },
9230 };
9231
9232 /* *** deal with flow director mask on flexible payload *** */
9233 struct cmd_flow_director_flex_mask_result {
9234         cmdline_fixed_string_t flow_director_flexmask;
9235         uint8_t port_id;
9236         cmdline_fixed_string_t flow;
9237         cmdline_fixed_string_t flow_type;
9238         cmdline_fixed_string_t mask;
9239 };
9240
9241 static void
9242 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9243                           __attribute__((unused)) struct cmdline *cl,
9244                           __attribute__((unused)) void *data)
9245 {
9246         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9247         struct rte_eth_fdir_info fdir_info;
9248         struct rte_eth_fdir_flex_mask flex_mask;
9249         struct rte_port *port;
9250         uint32_t flow_type_mask;
9251         uint16_t i;
9252         int ret;
9253
9254         if (res->port_id > nb_ports) {
9255                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9256                 return;
9257         }
9258
9259         port = &ports[res->port_id];
9260         /** Check if the port is not started **/
9261         if (port->port_status != RTE_PORT_STOPPED) {
9262                 printf("Please stop port %d first\n", res->port_id);
9263                 return;
9264         }
9265
9266         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9267         ret = parse_flexbytes(res->mask,
9268                         flex_mask.mask,
9269                         RTE_ETH_FDIR_MAX_FLEXLEN);
9270         if (ret < 0) {
9271                 printf("error: Cannot parse mask input.\n");
9272                 return;
9273         }
9274
9275         memset(&fdir_info, 0, sizeof(fdir_info));
9276         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9277                                 RTE_ETH_FILTER_INFO, &fdir_info);
9278         if (ret < 0) {
9279                 printf("Cannot get FDir filter info\n");
9280                 return;
9281         }
9282
9283         if (!strcmp(res->flow_type, "none")) {
9284                 /* means don't specify the flow type */
9285                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9286                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9287                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9288                                0, sizeof(struct rte_eth_fdir_flex_mask));
9289                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9290                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9291                                  &flex_mask,
9292                                  sizeof(struct rte_eth_fdir_flex_mask));
9293                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9294                 return;
9295         }
9296         flow_type_mask = fdir_info.flow_types_mask[0];
9297         if (!strcmp(res->flow_type, "all")) {
9298                 if (!flow_type_mask) {
9299                         printf("No flow type supported\n");
9300                         return;
9301                 }
9302                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9303                         if (flow_type_mask & (1 << i)) {
9304                                 flex_mask.flow_type = i;
9305                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9306                         }
9307                 }
9308                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9309                 return;
9310         }
9311         flex_mask.flow_type = str2flowtype(res->flow_type);
9312         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9313                 printf("Flow type %s not supported on port %d\n",
9314                                 res->flow_type, res->port_id);
9315                 return;
9316         }
9317         fdir_set_flex_mask(res->port_id, &flex_mask);
9318         cmd_reconfig_device_queue(res->port_id, 1, 1);
9319 }
9320
9321 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9323                                  flow_director_flexmask,
9324                                  "flow_director_flex_mask");
9325 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9326         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9327                               port_id, UINT8);
9328 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9330                                  flow, "flow");
9331 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9333                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9334                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9335 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9337                                  mask, NULL);
9338
9339 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9340         .f = cmd_flow_director_flex_mask_parsed,
9341         .data = NULL,
9342         .help_str = "set flow director's flex mask on NIC",
9343         .tokens = {
9344                 (void *)&cmd_flow_director_flexmask,
9345                 (void *)&cmd_flow_director_flexmask_port_id,
9346                 (void *)&cmd_flow_director_flexmask_flow,
9347                 (void *)&cmd_flow_director_flexmask_flow_type,
9348                 (void *)&cmd_flow_director_flexmask_mask,
9349                 NULL,
9350         },
9351 };
9352
9353 /* *** deal with flow director flexible payload configuration *** */
9354 struct cmd_flow_director_flexpayload_result {
9355         cmdline_fixed_string_t flow_director_flexpayload;
9356         uint8_t port_id;
9357         cmdline_fixed_string_t payload_layer;
9358         cmdline_fixed_string_t payload_cfg;
9359 };
9360
9361 static inline int
9362 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9363 {
9364         char s[256];
9365         const char *p, *p0 = q_arg;
9366         char *end;
9367         unsigned long int_fld;
9368         char *str_fld[max_num];
9369         int i;
9370         unsigned size;
9371         int ret = -1;
9372
9373         p = strchr(p0, '(');
9374         if (p == NULL)
9375                 return -1;
9376         ++p;
9377         p0 = strchr(p, ')');
9378         if (p0 == NULL)
9379                 return -1;
9380
9381         size = p0 - p;
9382         if (size >= sizeof(s))
9383                 return -1;
9384
9385         snprintf(s, sizeof(s), "%.*s", size, p);
9386         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9387         if (ret < 0 || ret > max_num)
9388                 return -1;
9389         for (i = 0; i < ret; i++) {
9390                 errno = 0;
9391                 int_fld = strtoul(str_fld[i], &end, 0);
9392                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9393                         return -1;
9394                 offsets[i] = (uint16_t)int_fld;
9395         }
9396         return ret;
9397 }
9398
9399 static void
9400 cmd_flow_director_flxpld_parsed(void *parsed_result,
9401                           __attribute__((unused)) struct cmdline *cl,
9402                           __attribute__((unused)) void *data)
9403 {
9404         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9405         struct rte_eth_flex_payload_cfg flex_cfg;
9406         struct rte_port *port;
9407         int ret = 0;
9408
9409         if (res->port_id > nb_ports) {
9410                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9411                 return;
9412         }
9413
9414         port = &ports[res->port_id];
9415         /** Check if the port is not started **/
9416         if (port->port_status != RTE_PORT_STOPPED) {
9417                 printf("Please stop port %d first\n", res->port_id);
9418                 return;
9419         }
9420
9421         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9422
9423         if (!strcmp(res->payload_layer, "raw"))
9424                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9425         else if (!strcmp(res->payload_layer, "l2"))
9426                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9427         else if (!strcmp(res->payload_layer, "l3"))
9428                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9429         else if (!strcmp(res->payload_layer, "l4"))
9430                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9431
9432         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9433                             RTE_ETH_FDIR_MAX_FLEXLEN);
9434         if (ret < 0) {
9435                 printf("error: Cannot parse flex payload input.\n");
9436                 return;
9437         }
9438
9439         fdir_set_flex_payload(res->port_id, &flex_cfg);
9440         cmd_reconfig_device_queue(res->port_id, 1, 1);
9441 }
9442
9443 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9444         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9445                                  flow_director_flexpayload,
9446                                  "flow_director_flex_payload");
9447 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9448         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9449                               port_id, UINT8);
9450 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9451         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9452                                  payload_layer, "raw#l2#l3#l4");
9453 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9455                                  payload_cfg, NULL);
9456
9457 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9458         .f = cmd_flow_director_flxpld_parsed,
9459         .data = NULL,
9460         .help_str = "set flow director's flex payload on NIC",
9461         .tokens = {
9462                 (void *)&cmd_flow_director_flexpayload,
9463                 (void *)&cmd_flow_director_flexpayload_port_id,
9464                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9465                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9466                 NULL,
9467         },
9468 };
9469
9470 /* *** Classification Filters Control *** */
9471 /* *** Get symmetric hash enable per port *** */
9472 struct cmd_get_sym_hash_ena_per_port_result {
9473         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9474         uint8_t port_id;
9475 };
9476
9477 static void
9478 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9479                                  __rte_unused struct cmdline *cl,
9480                                  __rte_unused void *data)
9481 {
9482         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9483         struct rte_eth_hash_filter_info info;
9484         int ret;
9485
9486         if (rte_eth_dev_filter_supported(res->port_id,
9487                                 RTE_ETH_FILTER_HASH) < 0) {
9488                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9489                                                         res->port_id);
9490                 return;
9491         }
9492
9493         memset(&info, 0, sizeof(info));
9494         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9495         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9496                                                 RTE_ETH_FILTER_GET, &info);
9497
9498         if (ret < 0) {
9499                 printf("Cannot get symmetric hash enable per port "
9500                                         "on port %u\n", res->port_id);
9501                 return;
9502         }
9503
9504         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9505                                 "enabled" : "disabled", res->port_id);
9506 }
9507
9508 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9509         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9510                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9511 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9512         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9513                 port_id, UINT8);
9514
9515 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9516         .f = cmd_get_sym_hash_per_port_parsed,
9517         .data = NULL,
9518         .help_str = "get_sym_hash_ena_per_port port_id",
9519         .tokens = {
9520                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9521                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9522                 NULL,
9523         },
9524 };
9525
9526 /* *** Set symmetric hash enable per port *** */
9527 struct cmd_set_sym_hash_ena_per_port_result {
9528         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9529         cmdline_fixed_string_t enable;
9530         uint8_t port_id;
9531 };
9532
9533 static void
9534 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9535                                  __rte_unused struct cmdline *cl,
9536                                  __rte_unused void *data)
9537 {
9538         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9539         struct rte_eth_hash_filter_info info;
9540         int ret;
9541
9542         if (rte_eth_dev_filter_supported(res->port_id,
9543                                 RTE_ETH_FILTER_HASH) < 0) {
9544                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9545                                                         res->port_id);
9546                 return;
9547         }
9548
9549         memset(&info, 0, sizeof(info));
9550         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9551         if (!strcmp(res->enable, "enable"))
9552                 info.info.enable = 1;
9553         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9554                                         RTE_ETH_FILTER_SET, &info);
9555         if (ret < 0) {
9556                 printf("Cannot set symmetric hash enable per port on "
9557                                         "port %u\n", res->port_id);
9558                 return;
9559         }
9560         printf("Symmetric hash has been set to %s on port %u\n",
9561                                         res->enable, res->port_id);
9562 }
9563
9564 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9565         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9566                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9567 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9568         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9569                 port_id, UINT8);
9570 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9571         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9572                 enable, "enable#disable");
9573
9574 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9575         .f = cmd_set_sym_hash_per_port_parsed,
9576         .data = NULL,
9577         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
9578         .tokens = {
9579                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9580                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9581                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9582                 NULL,
9583         },
9584 };
9585
9586 /* Get global config of hash function */
9587 struct cmd_get_hash_global_config_result {
9588         cmdline_fixed_string_t get_hash_global_config;
9589         uint8_t port_id;
9590 };
9591
9592 static char *
9593 flowtype_to_str(uint16_t ftype)
9594 {
9595         uint16_t i;
9596         static struct {
9597                 char str[16];
9598                 uint16_t ftype;
9599         } ftype_table[] = {
9600                 {"ipv4", RTE_ETH_FLOW_IPV4},
9601                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9602                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9603                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9604                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9605                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9606                 {"ipv6", RTE_ETH_FLOW_IPV6},
9607                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9608                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9609                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9610                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9611                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9612                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9613                 {"port", RTE_ETH_FLOW_PORT},
9614                 {"vxlan", RTE_ETH_FLOW_VXLAN},
9615                 {"geneve", RTE_ETH_FLOW_GENEVE},
9616                 {"nvgre", RTE_ETH_FLOW_NVGRE},
9617         };
9618
9619         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9620                 if (ftype_table[i].ftype == ftype)
9621                         return ftype_table[i].str;
9622         }
9623
9624         return NULL;
9625 }
9626
9627 static void
9628 cmd_get_hash_global_config_parsed(void *parsed_result,
9629                                   __rte_unused struct cmdline *cl,
9630                                   __rte_unused void *data)
9631 {
9632         struct cmd_get_hash_global_config_result *res = parsed_result;
9633         struct rte_eth_hash_filter_info info;
9634         uint32_t idx, offset;
9635         uint16_t i;
9636         char *str;
9637         int ret;
9638
9639         if (rte_eth_dev_filter_supported(res->port_id,
9640                         RTE_ETH_FILTER_HASH) < 0) {
9641                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9642                                                         res->port_id);
9643                 return;
9644         }
9645
9646         memset(&info, 0, sizeof(info));
9647         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9648         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9649                                         RTE_ETH_FILTER_GET, &info);
9650         if (ret < 0) {
9651                 printf("Cannot get hash global configurations by port %d\n",
9652                                                         res->port_id);
9653                 return;
9654         }
9655
9656         switch (info.info.global_conf.hash_func) {
9657         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9658                 printf("Hash function is Toeplitz\n");
9659                 break;
9660         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9661                 printf("Hash function is Simple XOR\n");
9662                 break;
9663         default:
9664                 printf("Unknown hash function\n");
9665                 break;
9666         }
9667
9668         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9669                 idx = i / UINT32_BIT;
9670                 offset = i % UINT32_BIT;
9671                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9672                                                 (1UL << offset)))
9673                         continue;
9674                 str = flowtype_to_str(i);
9675                 if (!str)
9676                         continue;
9677                 printf("Symmetric hash is %s globally for flow type %s "
9678                                                         "by port %d\n",
9679                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9680                         (1UL << offset)) ? "enabled" : "disabled"), str,
9681                                                         res->port_id);
9682         }
9683 }
9684
9685 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9686         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9687                 get_hash_global_config, "get_hash_global_config");
9688 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9689         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9690                 port_id, UINT8);
9691
9692 cmdline_parse_inst_t cmd_get_hash_global_config = {
9693         .f = cmd_get_hash_global_config_parsed,
9694         .data = NULL,
9695         .help_str = "get_hash_global_config port_id",
9696         .tokens = {
9697                 (void *)&cmd_get_hash_global_config_all,
9698                 (void *)&cmd_get_hash_global_config_port_id,
9699                 NULL,
9700         },
9701 };
9702
9703 /* Set global config of hash function */
9704 struct cmd_set_hash_global_config_result {
9705         cmdline_fixed_string_t set_hash_global_config;
9706         uint8_t port_id;
9707         cmdline_fixed_string_t hash_func;
9708         cmdline_fixed_string_t flow_type;
9709         cmdline_fixed_string_t enable;
9710 };
9711
9712 static void
9713 cmd_set_hash_global_config_parsed(void *parsed_result,
9714                                   __rte_unused struct cmdline *cl,
9715                                   __rte_unused void *data)
9716 {
9717         struct cmd_set_hash_global_config_result *res = parsed_result;
9718         struct rte_eth_hash_filter_info info;
9719         uint32_t ftype, idx, offset;
9720         int ret;
9721
9722         if (rte_eth_dev_filter_supported(res->port_id,
9723                                 RTE_ETH_FILTER_HASH) < 0) {
9724                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9725                                                         res->port_id);
9726                 return;
9727         }
9728         memset(&info, 0, sizeof(info));
9729         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9730         if (!strcmp(res->hash_func, "toeplitz"))
9731                 info.info.global_conf.hash_func =
9732                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9733         else if (!strcmp(res->hash_func, "simple_xor"))
9734                 info.info.global_conf.hash_func =
9735                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9736         else if (!strcmp(res->hash_func, "default"))
9737                 info.info.global_conf.hash_func =
9738                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9739
9740         ftype = str2flowtype(res->flow_type);
9741         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9742         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9743         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9744         if (!strcmp(res->enable, "enable"))
9745                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9746                                                 (1UL << offset);
9747         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9748                                         RTE_ETH_FILTER_SET, &info);
9749         if (ret < 0)
9750                 printf("Cannot set global hash configurations by port %d\n",
9751                                                         res->port_id);
9752         else
9753                 printf("Global hash configurations have been set "
9754                         "succcessfully by port %d\n", res->port_id);
9755 }
9756
9757 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9758         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9759                 set_hash_global_config, "set_hash_global_config");
9760 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9761         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9762                 port_id, UINT8);
9763 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9764         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9765                 hash_func, "toeplitz#simple_xor#default");
9766 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9767         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9768                 flow_type,
9769                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9770                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9771 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9772         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9773                 enable, "enable#disable");
9774
9775 cmdline_parse_inst_t cmd_set_hash_global_config = {
9776         .f = cmd_set_hash_global_config_parsed,
9777         .data = NULL,
9778         .help_str = "set_hash_global_config port_id "
9779                 "toeplitz|simple_xor|default "
9780                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
9781                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9782                 "enable|disable",
9783         .tokens = {
9784                 (void *)&cmd_set_hash_global_config_all,
9785                 (void *)&cmd_set_hash_global_config_port_id,
9786                 (void *)&cmd_set_hash_global_config_hash_func,
9787                 (void *)&cmd_set_hash_global_config_flow_type,
9788                 (void *)&cmd_set_hash_global_config_enable,
9789                 NULL,
9790         },
9791 };
9792
9793 /* Set hash input set */
9794 struct cmd_set_hash_input_set_result {
9795         cmdline_fixed_string_t set_hash_input_set;
9796         uint8_t port_id;
9797         cmdline_fixed_string_t flow_type;
9798         cmdline_fixed_string_t inset_field;
9799         cmdline_fixed_string_t select;
9800 };
9801
9802 static enum rte_eth_input_set_field
9803 str2inset(char *string)
9804 {
9805         uint16_t i;
9806
9807         static const struct {
9808                 char str[32];
9809                 enum rte_eth_input_set_field inset;
9810         } inset_table[] = {
9811                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
9812                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9813                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9814                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9815                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9816                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9817                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9818                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
9819                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9820                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9821                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9822                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9823                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
9824                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9825                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9826                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9827                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9828                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9829                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9830                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9831                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9832                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9833                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9834                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9835                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9836                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9837                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9838                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9839                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9840                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9841                 {"none", RTE_ETH_INPUT_SET_NONE},
9842         };
9843
9844         for (i = 0; i < RTE_DIM(inset_table); i++) {
9845                 if (!strcmp(string, inset_table[i].str))
9846                         return inset_table[i].inset;
9847         }
9848
9849         return RTE_ETH_INPUT_SET_UNKNOWN;
9850 }
9851
9852 static void
9853 cmd_set_hash_input_set_parsed(void *parsed_result,
9854                               __rte_unused struct cmdline *cl,
9855                               __rte_unused void *data)
9856 {
9857         struct cmd_set_hash_input_set_result *res = parsed_result;
9858         struct rte_eth_hash_filter_info info;
9859
9860         memset(&info, 0, sizeof(info));
9861         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
9862         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9863         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9864         info.info.input_set_conf.inset_size = 1;
9865         if (!strcmp(res->select, "select"))
9866                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9867         else if (!strcmp(res->select, "add"))
9868                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9869         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9870                                 RTE_ETH_FILTER_SET, &info);
9871 }
9872
9873 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
9874         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9875                 set_hash_input_set, "set_hash_input_set");
9876 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
9877         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
9878                 port_id, UINT8);
9879 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
9880         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9881                 flow_type,
9882                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
9883                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9884 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
9885         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9886                 inset_field,
9887                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9888                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
9889                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
9890                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
9891                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
9892                 "fld-8th#none");
9893 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
9894         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9895                 select, "select#add");
9896
9897 cmdline_parse_inst_t cmd_set_hash_input_set = {
9898         .f = cmd_set_hash_input_set_parsed,
9899         .data = NULL,
9900         .help_str = "set_hash_input_set <port_id> "
9901         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9902         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9903         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
9904         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
9905         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
9906         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9907         "fld-7th|fld-8th|none select|add",
9908         .tokens = {
9909                 (void *)&cmd_set_hash_input_set_cmd,
9910                 (void *)&cmd_set_hash_input_set_port_id,
9911                 (void *)&cmd_set_hash_input_set_flow_type,
9912                 (void *)&cmd_set_hash_input_set_field,
9913                 (void *)&cmd_set_hash_input_set_select,
9914                 NULL,
9915         },
9916 };
9917
9918 /* Set flow director input set */
9919 struct cmd_set_fdir_input_set_result {
9920         cmdline_fixed_string_t set_fdir_input_set;
9921         uint8_t port_id;
9922         cmdline_fixed_string_t flow_type;
9923         cmdline_fixed_string_t inset_field;
9924         cmdline_fixed_string_t select;
9925 };
9926
9927 static void
9928 cmd_set_fdir_input_set_parsed(void *parsed_result,
9929         __rte_unused struct cmdline *cl,
9930         __rte_unused void *data)
9931 {
9932         struct cmd_set_fdir_input_set_result *res = parsed_result;
9933         struct rte_eth_fdir_filter_info info;
9934
9935         memset(&info, 0, sizeof(info));
9936         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
9937         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9938         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9939         info.info.input_set_conf.inset_size = 1;
9940         if (!strcmp(res->select, "select"))
9941                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9942         else if (!strcmp(res->select, "add"))
9943                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9944         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9945                 RTE_ETH_FILTER_SET, &info);
9946 }
9947
9948 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
9949         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9950         set_fdir_input_set, "set_fdir_input_set");
9951 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
9952         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
9953         port_id, UINT8);
9954 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
9955         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9956         flow_type,
9957         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
9958         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9959 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
9960         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9961         inset_field,
9962         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9963         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
9964         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
9965         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
9966         "sctp-veri-tag#none");
9967 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
9968         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9969         select, "select#add");
9970
9971 cmdline_parse_inst_t cmd_set_fdir_input_set = {
9972         .f = cmd_set_fdir_input_set_parsed,
9973         .data = NULL,
9974         .help_str = "set_fdir_input_set <port_id> "
9975         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9976         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9977         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
9978         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
9979         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
9980         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
9981         "sctp-veri-tag|none select|add",
9982         .tokens = {
9983                 (void *)&cmd_set_fdir_input_set_cmd,
9984                 (void *)&cmd_set_fdir_input_set_port_id,
9985                 (void *)&cmd_set_fdir_input_set_flow_type,
9986                 (void *)&cmd_set_fdir_input_set_field,
9987                 (void *)&cmd_set_fdir_input_set_select,
9988                 NULL,
9989         },
9990 };
9991
9992 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
9993 struct cmd_mcast_addr_result {
9994         cmdline_fixed_string_t mcast_addr_cmd;
9995         cmdline_fixed_string_t what;
9996         uint8_t port_num;
9997         struct ether_addr mc_addr;
9998 };
9999
10000 static void cmd_mcast_addr_parsed(void *parsed_result,
10001                 __attribute__((unused)) struct cmdline *cl,
10002                 __attribute__((unused)) void *data)
10003 {
10004         struct cmd_mcast_addr_result *res = parsed_result;
10005
10006         if (!is_multicast_ether_addr(&res->mc_addr)) {
10007                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10008                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10009                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10010                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10011                 return;
10012         }
10013         if (strcmp(res->what, "add") == 0)
10014                 mcast_addr_add(res->port_num, &res->mc_addr);
10015         else
10016                 mcast_addr_remove(res->port_num, &res->mc_addr);
10017 }
10018
10019 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10020         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10021                                  mcast_addr_cmd, "mcast_addr");
10022 cmdline_parse_token_string_t cmd_mcast_addr_what =
10023         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10024                                  "add#remove");
10025 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10026         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10027 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10028         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10029
10030 cmdline_parse_inst_t cmd_mcast_addr = {
10031         .f = cmd_mcast_addr_parsed,
10032         .data = (void *)0,
10033         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
10034         .tokens = {
10035                 (void *)&cmd_mcast_addr_cmd,
10036                 (void *)&cmd_mcast_addr_what,
10037                 (void *)&cmd_mcast_addr_portnum,
10038                 (void *)&cmd_mcast_addr_addr,
10039                 NULL,
10040         },
10041 };
10042
10043 /* l2 tunnel config
10044  * only support E-tag now.
10045  */
10046
10047 /* Ether type config */
10048 struct cmd_config_l2_tunnel_eth_type_result {
10049         cmdline_fixed_string_t port;
10050         cmdline_fixed_string_t config;
10051         cmdline_fixed_string_t all;
10052         uint8_t id;
10053         cmdline_fixed_string_t l2_tunnel;
10054         cmdline_fixed_string_t l2_tunnel_type;
10055         cmdline_fixed_string_t eth_type;
10056         uint16_t eth_type_val;
10057 };
10058
10059 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10060         TOKEN_STRING_INITIALIZER
10061                 (struct cmd_config_l2_tunnel_eth_type_result,
10062                  port, "port");
10063 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10064         TOKEN_STRING_INITIALIZER
10065                 (struct cmd_config_l2_tunnel_eth_type_result,
10066                  config, "config");
10067 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10068         TOKEN_STRING_INITIALIZER
10069                 (struct cmd_config_l2_tunnel_eth_type_result,
10070                  all, "all");
10071 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10072         TOKEN_NUM_INITIALIZER
10073                 (struct cmd_config_l2_tunnel_eth_type_result,
10074                  id, UINT8);
10075 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10076         TOKEN_STRING_INITIALIZER
10077                 (struct cmd_config_l2_tunnel_eth_type_result,
10078                  l2_tunnel, "l2-tunnel");
10079 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10080         TOKEN_STRING_INITIALIZER
10081                 (struct cmd_config_l2_tunnel_eth_type_result,
10082                  l2_tunnel_type, "E-tag");
10083 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10084         TOKEN_STRING_INITIALIZER
10085                 (struct cmd_config_l2_tunnel_eth_type_result,
10086                  eth_type, "ether-type");
10087 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10088         TOKEN_NUM_INITIALIZER
10089                 (struct cmd_config_l2_tunnel_eth_type_result,
10090                  eth_type_val, UINT16);
10091
10092 static enum rte_eth_tunnel_type
10093 str2fdir_l2_tunnel_type(char *string)
10094 {
10095         uint32_t i = 0;
10096
10097         static const struct {
10098                 char str[32];
10099                 enum rte_eth_tunnel_type type;
10100         } l2_tunnel_type_str[] = {
10101                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10102         };
10103
10104         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10105                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10106                         return l2_tunnel_type_str[i].type;
10107         }
10108         return RTE_TUNNEL_TYPE_NONE;
10109 }
10110
10111 /* ether type config for all ports */
10112 static void
10113 cmd_config_l2_tunnel_eth_type_all_parsed
10114         (void *parsed_result,
10115          __attribute__((unused)) struct cmdline *cl,
10116          __attribute__((unused)) void *data)
10117 {
10118         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10119         struct rte_eth_l2_tunnel_conf entry;
10120         portid_t pid;
10121
10122         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10123         entry.ether_type = res->eth_type_val;
10124
10125         FOREACH_PORT(pid, ports) {
10126                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10127         }
10128 }
10129
10130 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10131         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10132         .data = NULL,
10133         .help_str = "port config all l2-tunnel ether-type",
10134         .tokens = {
10135                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10136                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10137                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10138                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10139                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10140                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10141                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10142                 NULL,
10143         },
10144 };
10145
10146 /* ether type config for a specific port */
10147 static void
10148 cmd_config_l2_tunnel_eth_type_specific_parsed(
10149         void *parsed_result,
10150         __attribute__((unused)) struct cmdline *cl,
10151         __attribute__((unused)) void *data)
10152 {
10153         struct cmd_config_l2_tunnel_eth_type_result *res =
10154                  parsed_result;
10155         struct rte_eth_l2_tunnel_conf entry;
10156
10157         if (port_id_is_invalid(res->id, ENABLED_WARN))
10158                 return;
10159
10160         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10161         entry.ether_type = res->eth_type_val;
10162
10163         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10164 }
10165
10166 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10167         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10168         .data = NULL,
10169         .help_str = "port config l2-tunnel ether-type",
10170         .tokens = {
10171                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10172                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10173                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10174                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10175                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10176                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10177                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10178                 NULL,
10179         },
10180 };
10181
10182 /* Enable/disable l2 tunnel */
10183 struct cmd_config_l2_tunnel_en_dis_result {
10184         cmdline_fixed_string_t port;
10185         cmdline_fixed_string_t config;
10186         cmdline_fixed_string_t all;
10187         uint8_t id;
10188         cmdline_fixed_string_t l2_tunnel;
10189         cmdline_fixed_string_t l2_tunnel_type;
10190         cmdline_fixed_string_t en_dis;
10191 };
10192
10193 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10194         TOKEN_STRING_INITIALIZER
10195                 (struct cmd_config_l2_tunnel_en_dis_result,
10196                  port, "port");
10197 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10198         TOKEN_STRING_INITIALIZER
10199                 (struct cmd_config_l2_tunnel_en_dis_result,
10200                  config, "config");
10201 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10202         TOKEN_STRING_INITIALIZER
10203                 (struct cmd_config_l2_tunnel_en_dis_result,
10204                  all, "all");
10205 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10206         TOKEN_NUM_INITIALIZER
10207                 (struct cmd_config_l2_tunnel_en_dis_result,
10208                  id, UINT8);
10209 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10210         TOKEN_STRING_INITIALIZER
10211                 (struct cmd_config_l2_tunnel_en_dis_result,
10212                  l2_tunnel, "l2-tunnel");
10213 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10214         TOKEN_STRING_INITIALIZER
10215                 (struct cmd_config_l2_tunnel_en_dis_result,
10216                  l2_tunnel_type, "E-tag");
10217 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10218         TOKEN_STRING_INITIALIZER
10219                 (struct cmd_config_l2_tunnel_en_dis_result,
10220                  en_dis, "enable#disable");
10221
10222 /* enable/disable l2 tunnel for all ports */
10223 static void
10224 cmd_config_l2_tunnel_en_dis_all_parsed(
10225         void *parsed_result,
10226         __attribute__((unused)) struct cmdline *cl,
10227         __attribute__((unused)) void *data)
10228 {
10229         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10230         struct rte_eth_l2_tunnel_conf entry;
10231         portid_t pid;
10232         uint8_t en;
10233
10234         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10235
10236         if (!strcmp("enable", res->en_dis))
10237                 en = 1;
10238         else
10239                 en = 0;
10240
10241         FOREACH_PORT(pid, ports) {
10242                 rte_eth_dev_l2_tunnel_offload_set(pid,
10243                                                   &entry,
10244                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10245                                                   en);
10246         }
10247 }
10248
10249 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10250         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10251         .data = NULL,
10252         .help_str = "port config all l2-tunnel enable/disable",
10253         .tokens = {
10254                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10255                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10256                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10257                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10258                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10259                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10260                 NULL,
10261         },
10262 };
10263
10264 /* enable/disable l2 tunnel for a port */
10265 static void
10266 cmd_config_l2_tunnel_en_dis_specific_parsed(
10267         void *parsed_result,
10268         __attribute__((unused)) struct cmdline *cl,
10269         __attribute__((unused)) void *data)
10270 {
10271         struct cmd_config_l2_tunnel_en_dis_result *res =
10272                 parsed_result;
10273         struct rte_eth_l2_tunnel_conf entry;
10274
10275         if (port_id_is_invalid(res->id, ENABLED_WARN))
10276                 return;
10277
10278         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10279
10280         if (!strcmp("enable", res->en_dis))
10281                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10282                                                   &entry,
10283                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10284                                                   1);
10285         else
10286                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10287                                                   &entry,
10288                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10289                                                   0);
10290 }
10291
10292 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10293         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10294         .data = NULL,
10295         .help_str = "port config l2-tunnel enable/disable",
10296         .tokens = {
10297                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10298                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10299                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10300                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10301                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10302                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10303                 NULL,
10304         },
10305 };
10306
10307 /* E-tag configuration */
10308
10309 /* Common result structure for all E-tag configuration */
10310 struct cmd_config_e_tag_result {
10311         cmdline_fixed_string_t e_tag;
10312         cmdline_fixed_string_t set;
10313         cmdline_fixed_string_t insertion;
10314         cmdline_fixed_string_t stripping;
10315         cmdline_fixed_string_t forwarding;
10316         cmdline_fixed_string_t filter;
10317         cmdline_fixed_string_t add;
10318         cmdline_fixed_string_t del;
10319         cmdline_fixed_string_t on;
10320         cmdline_fixed_string_t off;
10321         cmdline_fixed_string_t on_off;
10322         cmdline_fixed_string_t port_tag_id;
10323         uint32_t port_tag_id_val;
10324         cmdline_fixed_string_t e_tag_id;
10325         uint16_t e_tag_id_val;
10326         cmdline_fixed_string_t dst_pool;
10327         uint8_t dst_pool_val;
10328         cmdline_fixed_string_t port;
10329         uint8_t port_id;
10330         cmdline_fixed_string_t vf;
10331         uint8_t vf_id;
10332 };
10333
10334 /* Common CLI fields for all E-tag configuration */
10335 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10336         TOKEN_STRING_INITIALIZER
10337                 (struct cmd_config_e_tag_result,
10338                  e_tag, "E-tag");
10339 cmdline_parse_token_string_t cmd_config_e_tag_set =
10340         TOKEN_STRING_INITIALIZER
10341                 (struct cmd_config_e_tag_result,
10342                  set, "set");
10343 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10344         TOKEN_STRING_INITIALIZER
10345                 (struct cmd_config_e_tag_result,
10346                  insertion, "insertion");
10347 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10348         TOKEN_STRING_INITIALIZER
10349                 (struct cmd_config_e_tag_result,
10350                  stripping, "stripping");
10351 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10352         TOKEN_STRING_INITIALIZER
10353                 (struct cmd_config_e_tag_result,
10354                  forwarding, "forwarding");
10355 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10356         TOKEN_STRING_INITIALIZER
10357                 (struct cmd_config_e_tag_result,
10358                  filter, "filter");
10359 cmdline_parse_token_string_t cmd_config_e_tag_add =
10360         TOKEN_STRING_INITIALIZER
10361                 (struct cmd_config_e_tag_result,
10362                  add, "add");
10363 cmdline_parse_token_string_t cmd_config_e_tag_del =
10364         TOKEN_STRING_INITIALIZER
10365                 (struct cmd_config_e_tag_result,
10366                  del, "del");
10367 cmdline_parse_token_string_t cmd_config_e_tag_on =
10368         TOKEN_STRING_INITIALIZER
10369                 (struct cmd_config_e_tag_result,
10370                  on, "on");
10371 cmdline_parse_token_string_t cmd_config_e_tag_off =
10372         TOKEN_STRING_INITIALIZER
10373                 (struct cmd_config_e_tag_result,
10374                  off, "off");
10375 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10376         TOKEN_STRING_INITIALIZER
10377                 (struct cmd_config_e_tag_result,
10378                  on_off, "on#off");
10379 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10380         TOKEN_STRING_INITIALIZER
10381                 (struct cmd_config_e_tag_result,
10382                  port_tag_id, "port-tag-id");
10383 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10384         TOKEN_NUM_INITIALIZER
10385                 (struct cmd_config_e_tag_result,
10386                  port_tag_id_val, UINT32);
10387 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10388         TOKEN_STRING_INITIALIZER
10389                 (struct cmd_config_e_tag_result,
10390                  e_tag_id, "e-tag-id");
10391 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10392         TOKEN_NUM_INITIALIZER
10393                 (struct cmd_config_e_tag_result,
10394                  e_tag_id_val, UINT16);
10395 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10396         TOKEN_STRING_INITIALIZER
10397                 (struct cmd_config_e_tag_result,
10398                  dst_pool, "dst-pool");
10399 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10400         TOKEN_NUM_INITIALIZER
10401                 (struct cmd_config_e_tag_result,
10402                  dst_pool_val, UINT8);
10403 cmdline_parse_token_string_t cmd_config_e_tag_port =
10404         TOKEN_STRING_INITIALIZER
10405                 (struct cmd_config_e_tag_result,
10406                  port, "port");
10407 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10408         TOKEN_NUM_INITIALIZER
10409                 (struct cmd_config_e_tag_result,
10410                  port_id, UINT8);
10411 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10412         TOKEN_STRING_INITIALIZER
10413                 (struct cmd_config_e_tag_result,
10414                  vf, "vf");
10415 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10416         TOKEN_NUM_INITIALIZER
10417                 (struct cmd_config_e_tag_result,
10418                  vf_id, UINT8);
10419
10420 /* E-tag insertion configuration */
10421 static void
10422 cmd_config_e_tag_insertion_en_parsed(
10423         void *parsed_result,
10424         __attribute__((unused)) struct cmdline *cl,
10425         __attribute__((unused)) void *data)
10426 {
10427         struct cmd_config_e_tag_result *res =
10428                 parsed_result;
10429         struct rte_eth_l2_tunnel_conf entry;
10430
10431         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10432                 return;
10433
10434         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10435         entry.tunnel_id = res->port_tag_id_val;
10436         entry.vf_id = res->vf_id;
10437         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10438                                           &entry,
10439                                           ETH_L2_TUNNEL_INSERTION_MASK,
10440                                           1);
10441 }
10442
10443 static void
10444 cmd_config_e_tag_insertion_dis_parsed(
10445         void *parsed_result,
10446         __attribute__((unused)) struct cmdline *cl,
10447         __attribute__((unused)) void *data)
10448 {
10449         struct cmd_config_e_tag_result *res =
10450                 parsed_result;
10451         struct rte_eth_l2_tunnel_conf entry;
10452
10453         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10454                 return;
10455
10456         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10457         entry.vf_id = res->vf_id;
10458
10459         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10460                                           &entry,
10461                                           ETH_L2_TUNNEL_INSERTION_MASK,
10462                                           0);
10463 }
10464
10465 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10466         .f = cmd_config_e_tag_insertion_en_parsed,
10467         .data = NULL,
10468         .help_str = "E-tag insertion enable",
10469         .tokens = {
10470                 (void *)&cmd_config_e_tag_e_tag,
10471                 (void *)&cmd_config_e_tag_set,
10472                 (void *)&cmd_config_e_tag_insertion,
10473                 (void *)&cmd_config_e_tag_on,
10474                 (void *)&cmd_config_e_tag_port_tag_id,
10475                 (void *)&cmd_config_e_tag_port_tag_id_val,
10476                 (void *)&cmd_config_e_tag_port,
10477                 (void *)&cmd_config_e_tag_port_id,
10478                 (void *)&cmd_config_e_tag_vf,
10479                 (void *)&cmd_config_e_tag_vf_id,
10480                 NULL,
10481         },
10482 };
10483
10484 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10485         .f = cmd_config_e_tag_insertion_dis_parsed,
10486         .data = NULL,
10487         .help_str = "E-tag insertion disable",
10488         .tokens = {
10489                 (void *)&cmd_config_e_tag_e_tag,
10490                 (void *)&cmd_config_e_tag_set,
10491                 (void *)&cmd_config_e_tag_insertion,
10492                 (void *)&cmd_config_e_tag_off,
10493                 (void *)&cmd_config_e_tag_port,
10494                 (void *)&cmd_config_e_tag_port_id,
10495                 (void *)&cmd_config_e_tag_vf,
10496                 (void *)&cmd_config_e_tag_vf_id,
10497                 NULL,
10498         },
10499 };
10500
10501 /* E-tag stripping configuration */
10502 static void
10503 cmd_config_e_tag_stripping_parsed(
10504         void *parsed_result,
10505         __attribute__((unused)) struct cmdline *cl,
10506         __attribute__((unused)) void *data)
10507 {
10508         struct cmd_config_e_tag_result *res =
10509                 parsed_result;
10510         struct rte_eth_l2_tunnel_conf entry;
10511
10512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10513                 return;
10514
10515         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10516
10517         if (!strcmp(res->on_off, "on"))
10518                 rte_eth_dev_l2_tunnel_offload_set
10519                         (res->port_id,
10520                          &entry,
10521                          ETH_L2_TUNNEL_STRIPPING_MASK,
10522                          1);
10523         else
10524                 rte_eth_dev_l2_tunnel_offload_set
10525                         (res->port_id,
10526                          &entry,
10527                          ETH_L2_TUNNEL_STRIPPING_MASK,
10528                          0);
10529 }
10530
10531 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10532         .f = cmd_config_e_tag_stripping_parsed,
10533         .data = NULL,
10534         .help_str = "E-tag stripping enable/disable",
10535         .tokens = {
10536                 (void *)&cmd_config_e_tag_e_tag,
10537                 (void *)&cmd_config_e_tag_set,
10538                 (void *)&cmd_config_e_tag_stripping,
10539                 (void *)&cmd_config_e_tag_on_off,
10540                 (void *)&cmd_config_e_tag_port,
10541                 (void *)&cmd_config_e_tag_port_id,
10542                 NULL,
10543         },
10544 };
10545
10546 /* E-tag forwarding configuration */
10547 static void
10548 cmd_config_e_tag_forwarding_parsed(
10549         void *parsed_result,
10550         __attribute__((unused)) struct cmdline *cl,
10551         __attribute__((unused)) void *data)
10552 {
10553         struct cmd_config_e_tag_result *res = parsed_result;
10554         struct rte_eth_l2_tunnel_conf entry;
10555
10556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10557                 return;
10558
10559         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10560
10561         if (!strcmp(res->on_off, "on"))
10562                 rte_eth_dev_l2_tunnel_offload_set
10563                         (res->port_id,
10564                          &entry,
10565                          ETH_L2_TUNNEL_FORWARDING_MASK,
10566                          1);
10567         else
10568                 rte_eth_dev_l2_tunnel_offload_set
10569                         (res->port_id,
10570                          &entry,
10571                          ETH_L2_TUNNEL_FORWARDING_MASK,
10572                          0);
10573 }
10574
10575 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10576         .f = cmd_config_e_tag_forwarding_parsed,
10577         .data = NULL,
10578         .help_str = "E-tag forwarding enable/disable",
10579         .tokens = {
10580                 (void *)&cmd_config_e_tag_e_tag,
10581                 (void *)&cmd_config_e_tag_set,
10582                 (void *)&cmd_config_e_tag_forwarding,
10583                 (void *)&cmd_config_e_tag_on_off,
10584                 (void *)&cmd_config_e_tag_port,
10585                 (void *)&cmd_config_e_tag_port_id,
10586                 NULL,
10587         },
10588 };
10589
10590 /* E-tag filter configuration */
10591 static void
10592 cmd_config_e_tag_filter_add_parsed(
10593         void *parsed_result,
10594         __attribute__((unused)) struct cmdline *cl,
10595         __attribute__((unused)) void *data)
10596 {
10597         struct cmd_config_e_tag_result *res = parsed_result;
10598         struct rte_eth_l2_tunnel_conf entry;
10599         int ret = 0;
10600
10601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10602                 return;
10603
10604         if (res->e_tag_id_val > 0x3fff) {
10605                 printf("e-tag-id must be equal or less than 0x3fff.\n");
10606                 return;
10607         }
10608
10609         ret = rte_eth_dev_filter_supported(res->port_id,
10610                                            RTE_ETH_FILTER_L2_TUNNEL);
10611         if (ret < 0) {
10612                 printf("E-tag filter is not supported on port %u.\n",
10613                        res->port_id);
10614                 return;
10615         }
10616
10617         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10618         entry.tunnel_id = res->e_tag_id_val;
10619         entry.pool = res->dst_pool_val;
10620
10621         ret = rte_eth_dev_filter_ctrl(res->port_id,
10622                                       RTE_ETH_FILTER_L2_TUNNEL,
10623                                       RTE_ETH_FILTER_ADD,
10624                                       &entry);
10625         if (ret < 0)
10626                 printf("E-tag filter programming error: (%s)\n",
10627                        strerror(-ret));
10628 }
10629
10630 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10631         .f = cmd_config_e_tag_filter_add_parsed,
10632         .data = NULL,
10633         .help_str = "E-tag filter add",
10634         .tokens = {
10635                 (void *)&cmd_config_e_tag_e_tag,
10636                 (void *)&cmd_config_e_tag_set,
10637                 (void *)&cmd_config_e_tag_filter,
10638                 (void *)&cmd_config_e_tag_add,
10639                 (void *)&cmd_config_e_tag_e_tag_id,
10640                 (void *)&cmd_config_e_tag_e_tag_id_val,
10641                 (void *)&cmd_config_e_tag_dst_pool,
10642                 (void *)&cmd_config_e_tag_dst_pool_val,
10643                 (void *)&cmd_config_e_tag_port,
10644                 (void *)&cmd_config_e_tag_port_id,
10645                 NULL,
10646         },
10647 };
10648
10649 static void
10650 cmd_config_e_tag_filter_del_parsed(
10651         void *parsed_result,
10652         __attribute__((unused)) struct cmdline *cl,
10653         __attribute__((unused)) void *data)
10654 {
10655         struct cmd_config_e_tag_result *res = parsed_result;
10656         struct rte_eth_l2_tunnel_conf entry;
10657         int ret = 0;
10658
10659         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10660                 return;
10661
10662         if (res->e_tag_id_val > 0x3fff) {
10663                 printf("e-tag-id must be less than 0x3fff.\n");
10664                 return;
10665         }
10666
10667         ret = rte_eth_dev_filter_supported(res->port_id,
10668                                            RTE_ETH_FILTER_L2_TUNNEL);
10669         if (ret < 0) {
10670                 printf("E-tag filter is not supported on port %u.\n",
10671                        res->port_id);
10672                 return;
10673         }
10674
10675         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10676         entry.tunnel_id = res->e_tag_id_val;
10677
10678         ret = rte_eth_dev_filter_ctrl(res->port_id,
10679                                       RTE_ETH_FILTER_L2_TUNNEL,
10680                                       RTE_ETH_FILTER_DELETE,
10681                                       &entry);
10682         if (ret < 0)
10683                 printf("E-tag filter programming error: (%s)\n",
10684                        strerror(-ret));
10685 }
10686
10687 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10688         .f = cmd_config_e_tag_filter_del_parsed,
10689         .data = NULL,
10690         .help_str = "E-tag filter delete",
10691         .tokens = {
10692                 (void *)&cmd_config_e_tag_e_tag,
10693                 (void *)&cmd_config_e_tag_set,
10694                 (void *)&cmd_config_e_tag_filter,
10695                 (void *)&cmd_config_e_tag_del,
10696                 (void *)&cmd_config_e_tag_e_tag_id,
10697                 (void *)&cmd_config_e_tag_e_tag_id_val,
10698                 (void *)&cmd_config_e_tag_port,
10699                 (void *)&cmd_config_e_tag_port_id,
10700                 NULL,
10701         },
10702 };
10703
10704 /* ******************************************************************************** */
10705
10706 /* list of instructions */
10707 cmdline_parse_ctx_t main_ctx[] = {
10708         (cmdline_parse_inst_t *)&cmd_help_brief,
10709         (cmdline_parse_inst_t *)&cmd_help_long,
10710         (cmdline_parse_inst_t *)&cmd_quit,
10711         (cmdline_parse_inst_t *)&cmd_showport,
10712         (cmdline_parse_inst_t *)&cmd_showqueue,
10713         (cmdline_parse_inst_t *)&cmd_showportall,
10714         (cmdline_parse_inst_t *)&cmd_showcfg,
10715         (cmdline_parse_inst_t *)&cmd_start,
10716         (cmdline_parse_inst_t *)&cmd_start_tx_first,
10717         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
10718         (cmdline_parse_inst_t *)&cmd_set_link_up,
10719         (cmdline_parse_inst_t *)&cmd_set_link_down,
10720         (cmdline_parse_inst_t *)&cmd_reset,
10721         (cmdline_parse_inst_t *)&cmd_set_numbers,
10722         (cmdline_parse_inst_t *)&cmd_set_txpkts,
10723         (cmdline_parse_inst_t *)&cmd_set_txsplit,
10724         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
10725         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
10726         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
10727         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
10728         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
10729         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
10730         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
10731         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
10732         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
10733         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
10734         (cmdline_parse_inst_t *)&cmd_set_link_check,
10735 #ifdef RTE_NIC_BYPASS
10736         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
10737         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
10738         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
10739         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
10740 #endif
10741 #ifdef RTE_LIBRTE_PMD_BOND
10742         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
10743         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
10744         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
10745         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
10746         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
10747         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
10748         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
10749         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
10750         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
10751 #endif
10752         (cmdline_parse_inst_t *)&cmd_vlan_offload,
10753         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
10754         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
10755         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
10756         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
10757         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
10758         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
10759         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
10760         (cmdline_parse_inst_t *)&cmd_csum_set,
10761         (cmdline_parse_inst_t *)&cmd_csum_show,
10762         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
10763         (cmdline_parse_inst_t *)&cmd_tso_set,
10764         (cmdline_parse_inst_t *)&cmd_tso_show,
10765         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
10766         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
10767         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
10768         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
10769         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
10770         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
10771         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
10772         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
10773         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
10774         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
10775         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
10776         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
10777         (cmdline_parse_inst_t *)&cmd_config_dcb,
10778         (cmdline_parse_inst_t *)&cmd_read_reg,
10779         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
10780         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
10781         (cmdline_parse_inst_t *)&cmd_write_reg,
10782         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
10783         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
10784         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
10785         (cmdline_parse_inst_t *)&cmd_stop,
10786         (cmdline_parse_inst_t *)&cmd_mac_addr,
10787         (cmdline_parse_inst_t *)&cmd_set_qmap,
10788         (cmdline_parse_inst_t *)&cmd_operate_port,
10789         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
10790         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
10791         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
10792         (cmdline_parse_inst_t *)&cmd_config_speed_all,
10793         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
10794         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
10795         (cmdline_parse_inst_t *)&cmd_config_mtu,
10796         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
10797         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
10798         (cmdline_parse_inst_t *)&cmd_config_rss,
10799         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
10800         (cmdline_parse_inst_t *)&cmd_config_txqflags,
10801         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
10802         (cmdline_parse_inst_t *)&cmd_showport_reta,
10803         (cmdline_parse_inst_t *)&cmd_config_burst,
10804         (cmdline_parse_inst_t *)&cmd_config_thresh,
10805         (cmdline_parse_inst_t *)&cmd_config_threshold,
10806         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
10807         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
10808         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
10809         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
10810         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
10811         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
10812         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
10813         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
10814         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
10815         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
10816         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
10817         (cmdline_parse_inst_t *)&cmd_global_config,
10818         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
10819         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
10820         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
10821         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
10822         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
10823         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
10824         (cmdline_parse_inst_t *)&cmd_dump,
10825         (cmdline_parse_inst_t *)&cmd_dump_one,
10826         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
10827         (cmdline_parse_inst_t *)&cmd_syn_filter,
10828         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
10829         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
10830         (cmdline_parse_inst_t *)&cmd_flex_filter,
10831         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
10832         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
10833         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
10834         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
10835         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
10836         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
10837         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
10838         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
10839         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
10840         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
10841         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
10842         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
10843         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
10844         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
10845         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
10846         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
10847         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
10848         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
10849         (cmdline_parse_inst_t *)&cmd_mcast_addr,
10850         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
10851         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
10852         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
10853         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
10854         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
10855         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
10856         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
10857         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
10858         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
10859         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
10860         NULL,
10861 };
10862
10863 /* prompt function, called from main on MASTER lcore */
10864 void
10865 prompt(void)
10866 {
10867         /* initialize non-constant commands */
10868         cmd_set_fwd_mode_init();
10869         cmd_set_fwd_retry_mode_init();
10870
10871         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
10872         if (testpmd_cl == NULL)
10873                 return;
10874         cmdline_interact(testpmd_cl);
10875         cmdline_stdin_exit(testpmd_cl);
10876 }
10877
10878 void
10879 prompt_exit(void)
10880 {
10881         if (testpmd_cl != NULL)
10882                 cmdline_quit(testpmd_cl);
10883 }
10884
10885 static void
10886 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
10887 {
10888         if (id == (portid_t)RTE_PORT_ALL) {
10889                 portid_t pid;
10890
10891                 FOREACH_PORT(pid, ports) {
10892                         /* check if need_reconfig has been set to 1 */
10893                         if (ports[pid].need_reconfig == 0)
10894                                 ports[pid].need_reconfig = dev;
10895                         /* check if need_reconfig_queues has been set to 1 */
10896                         if (ports[pid].need_reconfig_queues == 0)
10897                                 ports[pid].need_reconfig_queues = queue;
10898                 }
10899         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
10900                 /* check if need_reconfig has been set to 1 */
10901                 if (ports[id].need_reconfig == 0)
10902                         ports[id].need_reconfig = dev;
10903                 /* check if need_reconfig_queues has been set to 1 */
10904                 if (ports[id].need_reconfig_queues == 0)
10905                         ports[id].need_reconfig_queues = queue;
10906         }
10907 }