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