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