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