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