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