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