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