bedf1e4501f464c1174a0d5bc31bdbd1e1060128
[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 <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.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 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
530                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
531
532                         "set port (port_id) vf (vf_id) (mac_addr)"
533                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
534                         "   Add/Remove unicast or multicast MAC addr filter"
535                         " for a VF.\n\n"
536
537                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
538                         "|MPE) (on|off)\n"
539                         "    AUPE:accepts untagged VLAN;"
540                         "ROPE:accept unicast hash\n\n"
541                         "    BAM:accepts broadcast packets;"
542                         "MPE:accepts all multicast packets\n\n"
543                         "    Enable/Disable a VF receive mode of a port\n\n"
544
545                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
546                         "    Set rate limit for a queue of a port\n\n"
547
548                         "set port (port_id) vf (vf_id) rate (rate_num) "
549                         "queue_mask (queue_mask_value)\n"
550                         "    Set rate limit for queues in VF of a port\n\n"
551
552                         "set port (port_id) mirror-rule (rule_id)"
553                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
554                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
555                         "   Set pool or vlan type mirror rule on a port.\n"
556                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
557                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
558                         " to pool 0.\n\n"
559
560                         "set port (port_id) mirror-rule (rule_id)"
561                         " (uplink-mirror|downlink-mirror) dst-pool"
562                         " (pool_id) (on|off)\n"
563                         "   Set uplink or downlink type mirror rule on a port.\n"
564                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
565                         " 0 on' enable mirror income traffic to pool 0.\n\n"
566
567                         "reset port (port_id) mirror-rule (rule_id)\n"
568                         "   Reset a mirror rule.\n\n"
569
570                         "set flush_rx (on|off)\n"
571                         "   Flush (default) or don't flush RX streams before"
572                         " forwarding. Mainly used with PCAP drivers.\n\n"
573
574                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
575                         "   Set the bypass mode for the lowest port on bypass enabled"
576                         " NIC.\n\n"
577
578                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
579                         "mode (normal|bypass|isolate) (port_id)\n"
580                         "   Set the event required to initiate specified bypass mode for"
581                         " the lowest port on a bypass enabled NIC where:\n"
582                         "       timeout   = enable bypass after watchdog timeout.\n"
583                         "       os_on     = enable bypass when OS/board is powered on.\n"
584                         "       os_off    = enable bypass when OS/board is powered off.\n"
585                         "       power_on  = enable bypass when power supply is turned on.\n"
586                         "       power_off = enable bypass when power supply is turned off."
587                         "\n\n"
588
589                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
590                         "   Set the bypass watchdog timeout to 'n' seconds"
591                         " where 0 = instant.\n\n"
592
593                         "show bypass config (port_id)\n"
594                         "   Show the bypass configuration for a bypass enabled NIC"
595                         " using the lowest port on the NIC.\n\n"
596
597 #ifdef RTE_LIBRTE_PMD_BOND
598                         "create bonded device (mode) (socket)\n"
599                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
600
601                         "add bonding slave (slave_id) (port_id)\n"
602                         "       Add a slave device to a bonded device.\n\n"
603
604                         "remove bonding slave (slave_id) (port_id)\n"
605                         "       Remove a slave device from a bonded device.\n\n"
606
607                         "set bonding mode (value) (port_id)\n"
608                         "       Set the bonding mode on a bonded device.\n\n"
609
610                         "set bonding primary (slave_id) (port_id)\n"
611                         "       Set the primary slave for a bonded device.\n\n"
612
613                         "show bonding config (port_id)\n"
614                         "       Show the bonding config for port_id.\n\n"
615
616                         "set bonding mac_addr (port_id) (address)\n"
617                         "       Set the MAC address of a bonded device.\n\n"
618
619                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
620                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
621
622                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
623                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
624
625                         "set bonding mon_period (port_id) (value)\n"
626                         "       Set the bonding link status monitoring polling period in ms.\n\n"
627
628                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
629                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
630
631 #endif
632                         "set link-up port (port_id)\n"
633                         "       Set link up for a port.\n\n"
634
635                         "set link-down port (port_id)\n"
636                         "       Set link down for a port.\n\n"
637
638                         "E-tag set insertion on port-tag-id (value)"
639                         " port (port_id) vf (vf_id)\n"
640                         "    Enable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
643                         "    Disable E-tag insertion for a VF on a port\n\n"
644
645                         "E-tag set stripping (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag stripping on a port\n\n"
647
648                         "E-tag set forwarding (on|off) port (port_id)\n"
649                         "    Enable/disable E-tag based forwarding"
650                         " on a port\n\n"
651
652                         "E-tag set filter add e-tag-id (value) dst-pool"
653                         " (pool_id) port (port_id)\n"
654                         "    Add an E-tag forwarding filter on a port\n\n"
655
656                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
657                         "    Delete an E-tag forwarding filter on a port\n\n"
658
659 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
660                         "set port tm hierarchy default (port_id)\n"
661                         "       Set default traffic Management hierarchy on a port\n\n"
662
663 #endif
664                         "ddp add (port_id) (profile_path[,output_path])\n"
665                         "    Load a profile package on a port\n\n"
666
667                         "ddp del (port_id) (profile_path)\n"
668                         "    Delete a profile package from a port\n\n"
669
670                         "ptype mapping get (port_id) (valid_only)\n"
671                         "    Get ptype mapping on a port\n\n"
672
673                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
674                         "    Replace target with the pkt_type in ptype mapping\n\n"
675
676                         "ptype mapping reset (port_id)\n"
677                         "    Reset ptype mapping on a port\n\n"
678
679                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
680                         "    Update a ptype mapping item on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "queue_start_index (value) queue_num (value)\n"
684                         "    Set a queue region on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "flowtype (value)\n"
688                         "    Set a flowtype region index on a port\n\n"
689
690                         "set port (port_id) queue-region UP (value) region_id (value)\n"
691                         "    Set the mapping of User Priority to "
692                         "queue region on a port\n\n"
693
694                         "set port (port_id) queue-region flush (on|off)\n"
695                         "    flush all queue region related configuration\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "    meter create\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
719                         "    meter update policer action\n\n"
720
721                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
722                         "    meter update stats\n\n"
723
724                         "show port (port_id) queue-region\n"
725                         "    show all queue region related configuration info\n\n"
726
727                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
728                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
729                         "       Add port tm node private shaper profile.\n\n"
730
731                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
732                         "       Delete port tm node private shaper profile.\n\n"
733
734                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
735                         " (shaper_profile_id)\n"
736                         "       Add/update port tm node shared shaper.\n\n"
737
738                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
739                         "       Delete port tm node shared shaper.\n\n"
740
741                         "set port tm node shaper profile (port_id) (node_id)"
742                         " (shaper_profile_id)\n"
743                         "       Set port tm node shaper profile.\n\n"
744
745                         "add port tm node wred profile (port_id) (wred_profile_id)"
746                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
747                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
748                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
749                         "       Add port tm node wred profile.\n\n"
750
751                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
752                         "       Delete port tm node wred profile.\n\n"
753
754                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
755                         " (priority) (weight) (level_id) (shaper_profile_id)"
756                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
757                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
758                         "       Add port tm nonleaf node.\n\n"
759
760                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
761                         " (priority) (weight) (level_id) (shaper_profile_id)"
762                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
763                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
764                         "       Add port tm leaf node.\n\n"
765
766                         "del port tm node (port_id) (node_id)\n"
767                         "       Delete port tm node.\n\n"
768
769                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
770                         " (priority) (weight)\n"
771                         "       Set port tm node parent.\n\n"
772
773                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
774                         "       Commit tm hierarchy.\n\n"
775
776                         , list_pkt_forwarding_modes()
777                 );
778         }
779
780         if (show_all || !strcmp(res->section, "ports")) {
781
782                 cmdline_printf(
783                         cl,
784                         "\n"
785                         "Port Operations:\n"
786                         "----------------\n\n"
787
788                         "port start (port_id|all)\n"
789                         "    Start all ports or port_id.\n\n"
790
791                         "port stop (port_id|all)\n"
792                         "    Stop all ports or port_id.\n\n"
793
794                         "port close (port_id|all)\n"
795                         "    Close all ports or port_id.\n\n"
796
797                         "port attach (ident)\n"
798                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
799
800                         "port detach (port_id)\n"
801                         "    Detach physical or virtual dev by port_id\n\n"
802
803                         "port config (port_id|all)"
804                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
805                         " duplex (half|full|auto)\n"
806                         "    Set speed and duplex for all ports or port_id\n\n"
807
808                         "port config all (rxq|txq|rxd|txd) (value)\n"
809                         "    Set number for rxq/txq/rxd/txd.\n\n"
810
811                         "port config all max-pkt-len (value)\n"
812                         "    Set the max packet length.\n\n"
813
814                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
815                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
816                         " (on|off)\n"
817                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
818                         " for ports.\n\n"
819
820                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
821                         "geneve|nvgre|none|<flowtype_id>)\n"
822                         "    Set the RSS mode.\n\n"
823
824                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
825                         "    Set the RSS redirection table.\n\n"
826
827                         "port config (port_id) dcb vt (on|off) (traffic_class)"
828                         " pfc (on|off)\n"
829                         "    Set the DCB mode.\n\n"
830
831                         "port config all burst (value)\n"
832                         "    Set the number of packets per burst.\n\n"
833
834                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
835                         " (value)\n"
836                         "    Set the ring prefetch/host/writeback threshold"
837                         " for tx/rx queue.\n\n"
838
839                         "port config all (txfreet|txrst|rxfreet) (value)\n"
840                         "    Set free threshold for rx/tx, or set"
841                         " tx rs bit threshold.\n\n"
842                         "port config mtu X value\n"
843                         "    Set the MTU of port X to a given value\n\n"
844
845                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
846                         "    Start/stop a rx/tx queue of port X. Only take effect"
847                         " when port X is started\n\n"
848
849                         "port config (port_id|all) l2-tunnel E-tag ether-type"
850                         " (value)\n"
851                         "    Set the value of E-tag ether-type.\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag"
854                         " (enable|disable)\n"
855                         "    Enable/disable the E-tag support.\n\n"
856
857                         "port config (port_id) pctype mapping reset\n"
858                         "    Reset flow type to pctype mapping on a port\n\n"
859
860                         "port config (port_id) pctype mapping update"
861                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
862                         "    Update a flow type to pctype mapping item on a port\n\n"
863                 );
864         }
865
866         if (show_all || !strcmp(res->section, "registers")) {
867
868                 cmdline_printf(
869                         cl,
870                         "\n"
871                         "Registers:\n"
872                         "----------\n\n"
873
874                         "read reg (port_id) (address)\n"
875                         "    Display value of a port register.\n\n"
876
877                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
878                         "    Display a port register bit field.\n\n"
879
880                         "read regbit (port_id) (address) (bit_x)\n"
881                         "    Display a single port register bit.\n\n"
882
883                         "write reg (port_id) (address) (value)\n"
884                         "    Set value of a port register.\n\n"
885
886                         "write regfield (port_id) (address) (bit_x) (bit_y)"
887                         " (value)\n"
888                         "    Set bit field of a port register.\n\n"
889
890                         "write regbit (port_id) (address) (bit_x) (value)\n"
891                         "    Set single bit value of a port register.\n\n"
892                 );
893         }
894         if (show_all || !strcmp(res->section, "filters")) {
895
896                 cmdline_printf(
897                         cl,
898                         "\n"
899                         "filters:\n"
900                         "--------\n\n"
901
902                         "ethertype_filter (port_id) (add|del)"
903                         " (mac_addr|mac_ignr) (mac_address) ethertype"
904                         " (ether_type) (drop|fwd) queue (queue_id)\n"
905                         "    Add/Del an ethertype filter.\n\n"
906
907                         "2tuple_filter (port_id) (add|del)"
908                         " dst_port (dst_port_value) protocol (protocol_value)"
909                         " mask (mask_value) tcp_flags (tcp_flags_value)"
910                         " priority (prio_value) queue (queue_id)\n"
911                         "    Add/Del a 2tuple filter.\n\n"
912
913                         "5tuple_filter (port_id) (add|del)"
914                         " dst_ip (dst_address) src_ip (src_address)"
915                         " dst_port (dst_port_value) src_port (src_port_value)"
916                         " protocol (protocol_value)"
917                         " mask (mask_value) tcp_flags (tcp_flags_value)"
918                         " priority (prio_value) queue (queue_id)\n"
919                         "    Add/Del a 5tuple filter.\n\n"
920
921                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
922                         "    Add/Del syn filter.\n\n"
923
924                         "flex_filter (port_id) (add|del) len (len_value)"
925                         " bytes (bytes_value) mask (mask_value)"
926                         " priority (prio_value) queue (queue_id)\n"
927                         "    Add/Del a flex filter.\n\n"
928
929                         "flow_director_filter (port_id) mode IP (add|del|update)"
930                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
931                         " src (src_ip_address) dst (dst_ip_address)"
932                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
933                         " vlan (vlan_value) flexbytes (flexbytes_value)"
934                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
935                         " fd_id (fd_id_value)\n"
936                         "    Add/Del an IP type flow director filter.\n\n"
937
938                         "flow_director_filter (port_id) mode IP (add|del|update)"
939                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
940                         " src (src_ip_address) (src_port)"
941                         " dst (dst_ip_address) (dst_port)"
942                         " tos (tos_value) ttl (ttl_value)"
943                         " vlan (vlan_value) flexbytes (flexbytes_value)"
944                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
945                         " fd_id (fd_id_value)\n"
946                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
947
948                         "flow_director_filter (port_id) mode IP (add|del|update)"
949                         " flow (ipv4-sctp|ipv6-sctp)"
950                         " src (src_ip_address) (src_port)"
951                         " dst (dst_ip_address) (dst_port)"
952                         " tag (verification_tag) "
953                         " tos (tos_value) ttl (ttl_value)"
954                         " vlan (vlan_value)"
955                         " flexbytes (flexbytes_value) (drop|fwd)"
956                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
957                         "    Add/Del a SCTP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow l2_payload ether (ethertype)"
961                         " flexbytes (flexbytes_value) (drop|fwd)"
962                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
963                         "    Add/Del a l2 payload type flow director filter.\n\n"
964
965                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
966                         " mac (mac_address) vlan (vlan_value)"
967                         " flexbytes (flexbytes_value) (drop|fwd)"
968                         " queue (queue_id) fd_id (fd_id_value)\n"
969                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
970
971                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
972                         " mac (mac_address) vlan (vlan_value)"
973                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
974                         " flexbytes (flexbytes_value) (drop|fwd)"
975                         " queue (queue_id) fd_id (fd_id_value)\n"
976                         "    Add/Del a Tunnel flow director filter.\n\n"
977
978                         "flush_flow_director (port_id)\n"
979                         "    Flush all flow director entries of a device.\n\n"
980
981                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
982                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
983                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
984                         "    Set flow director IP mask.\n\n"
985
986                         "flow_director_mask (port_id) mode MAC-VLAN"
987                         " vlan (vlan_value)\n"
988                         "    Set flow director MAC-VLAN mask.\n\n"
989
990                         "flow_director_mask (port_id) mode Tunnel"
991                         " vlan (vlan_value) mac (mac_value)"
992                         " tunnel-type (tunnel_type_value)"
993                         " tunnel-id (tunnel_id_value)\n"
994                         "    Set flow director Tunnel mask.\n\n"
995
996                         "flow_director_flex_mask (port_id)"
997                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
998                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
999                         " (mask)\n"
1000                         "    Configure mask of flex payload.\n\n"
1001
1002                         "flow_director_flex_payload (port_id)"
1003                         " (raw|l2|l3|l4) (config)\n"
1004                         "    Configure flex payload selection.\n\n"
1005
1006                         "get_sym_hash_ena_per_port (port_id)\n"
1007                         "    get symmetric hash enable configuration per port.\n\n"
1008
1009                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1010                         "    set symmetric hash enable configuration per port"
1011                         " to enable or disable.\n\n"
1012
1013                         "get_hash_global_config (port_id)\n"
1014                         "    Get the global configurations of hash filters.\n\n"
1015
1016                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1017                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1018                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1019                         " (enable|disable)\n"
1020                         "    Set the global configurations of hash filters.\n\n"
1021
1022                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1023                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1024                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1025                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1026                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1027                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1028                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1029                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1030                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1031                         "fld-8th|none) (select|add)\n"
1032                         "    Set the input set for hash.\n\n"
1033
1034                         "set_fdir_input_set (port_id) "
1035                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1036                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1037                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1038                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1039                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1040                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1041                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1042                         " (select|add)\n"
1043                         "    Set the input set for FDir.\n\n"
1044
1045                         "flow validate {port_id}"
1046                         " [group {group_id}] [priority {level}]"
1047                         " [ingress] [egress]"
1048                         " pattern {item} [/ {item} [...]] / end"
1049                         " actions {action} [/ {action} [...]] / end\n"
1050                         "    Check whether a flow rule can be created.\n\n"
1051
1052                         "flow create {port_id}"
1053                         " [group {group_id}] [priority {level}]"
1054                         " [ingress] [egress]"
1055                         " pattern {item} [/ {item} [...]] / end"
1056                         " actions {action} [/ {action} [...]] / end\n"
1057                         "    Create a flow rule.\n\n"
1058
1059                         "flow destroy {port_id} rule {rule_id} [...]\n"
1060                         "    Destroy specific flow rules.\n\n"
1061
1062                         "flow flush {port_id}\n"
1063                         "    Destroy all flow rules.\n\n"
1064
1065                         "flow query {port_id} {rule_id} {action}\n"
1066                         "    Query an existing flow rule.\n\n"
1067
1068                         "flow list {port_id} [group {group_id}] [...]\n"
1069                         "    List existing flow rules sorted by priority,"
1070                         " filtered by group identifiers.\n\n"
1071
1072                         "flow isolate {port_id} {boolean}\n"
1073                         "    Restrict ingress traffic to the defined"
1074                         " flow rules\n\n"
1075                 );
1076         }
1077 }
1078
1079 cmdline_parse_token_string_t cmd_help_long_help =
1080         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1081
1082 cmdline_parse_token_string_t cmd_help_long_section =
1083         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1084                         "all#control#display#config#"
1085                         "ports#registers#filters");
1086
1087 cmdline_parse_inst_t cmd_help_long = {
1088         .f = cmd_help_long_parsed,
1089         .data = NULL,
1090         .help_str = "help all|control|display|config|ports|register|filters: "
1091                 "Show help",
1092         .tokens = {
1093                 (void *)&cmd_help_long_help,
1094                 (void *)&cmd_help_long_section,
1095                 NULL,
1096         },
1097 };
1098
1099
1100 /* *** start/stop/close all ports *** */
1101 struct cmd_operate_port_result {
1102         cmdline_fixed_string_t keyword;
1103         cmdline_fixed_string_t name;
1104         cmdline_fixed_string_t value;
1105 };
1106
1107 static void cmd_operate_port_parsed(void *parsed_result,
1108                                 __attribute__((unused)) struct cmdline *cl,
1109                                 __attribute__((unused)) void *data)
1110 {
1111         struct cmd_operate_port_result *res = parsed_result;
1112
1113         if (!strcmp(res->name, "start"))
1114                 start_port(RTE_PORT_ALL);
1115         else if (!strcmp(res->name, "stop"))
1116                 stop_port(RTE_PORT_ALL);
1117         else if (!strcmp(res->name, "close"))
1118                 close_port(RTE_PORT_ALL);
1119         else if (!strcmp(res->name, "reset"))
1120                 reset_port(RTE_PORT_ALL);
1121         else
1122                 printf("Unknown parameter\n");
1123 }
1124
1125 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1126         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1127                                                                 "port");
1128 cmdline_parse_token_string_t cmd_operate_port_all_port =
1129         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1130                                                 "start#stop#close#reset");
1131 cmdline_parse_token_string_t cmd_operate_port_all_all =
1132         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1133
1134 cmdline_parse_inst_t cmd_operate_port = {
1135         .f = cmd_operate_port_parsed,
1136         .data = NULL,
1137         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1138         .tokens = {
1139                 (void *)&cmd_operate_port_all_cmd,
1140                 (void *)&cmd_operate_port_all_port,
1141                 (void *)&cmd_operate_port_all_all,
1142                 NULL,
1143         },
1144 };
1145
1146 /* *** start/stop/close specific port *** */
1147 struct cmd_operate_specific_port_result {
1148         cmdline_fixed_string_t keyword;
1149         cmdline_fixed_string_t name;
1150         uint8_t value;
1151 };
1152
1153 static void cmd_operate_specific_port_parsed(void *parsed_result,
1154                         __attribute__((unused)) struct cmdline *cl,
1155                                 __attribute__((unused)) void *data)
1156 {
1157         struct cmd_operate_specific_port_result *res = parsed_result;
1158
1159         if (!strcmp(res->name, "start"))
1160                 start_port(res->value);
1161         else if (!strcmp(res->name, "stop"))
1162                 stop_port(res->value);
1163         else if (!strcmp(res->name, "close"))
1164                 close_port(res->value);
1165         else if (!strcmp(res->name, "reset"))
1166                 reset_port(res->value);
1167         else
1168                 printf("Unknown parameter\n");
1169 }
1170
1171 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1172         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1173                                                         keyword, "port");
1174 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1175         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1176                                                 name, "start#stop#close#reset");
1177 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1178         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1179                                                         value, UINT8);
1180
1181 cmdline_parse_inst_t cmd_operate_specific_port = {
1182         .f = cmd_operate_specific_port_parsed,
1183         .data = NULL,
1184         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1185         .tokens = {
1186                 (void *)&cmd_operate_specific_port_cmd,
1187                 (void *)&cmd_operate_specific_port_port,
1188                 (void *)&cmd_operate_specific_port_id,
1189                 NULL,
1190         },
1191 };
1192
1193 /* *** attach a specified port *** */
1194 struct cmd_operate_attach_port_result {
1195         cmdline_fixed_string_t port;
1196         cmdline_fixed_string_t keyword;
1197         cmdline_fixed_string_t identifier;
1198 };
1199
1200 static void cmd_operate_attach_port_parsed(void *parsed_result,
1201                                 __attribute__((unused)) struct cmdline *cl,
1202                                 __attribute__((unused)) void *data)
1203 {
1204         struct cmd_operate_attach_port_result *res = parsed_result;
1205
1206         if (!strcmp(res->keyword, "attach"))
1207                 attach_port(res->identifier);
1208         else
1209                 printf("Unknown parameter\n");
1210 }
1211
1212 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1213         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1214                         port, "port");
1215 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1217                         keyword, "attach");
1218 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1219         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1220                         identifier, NULL);
1221
1222 cmdline_parse_inst_t cmd_operate_attach_port = {
1223         .f = cmd_operate_attach_port_parsed,
1224         .data = NULL,
1225         .help_str = "port attach <identifier>: "
1226                 "(identifier: pci address or virtual dev name)",
1227         .tokens = {
1228                 (void *)&cmd_operate_attach_port_port,
1229                 (void *)&cmd_operate_attach_port_keyword,
1230                 (void *)&cmd_operate_attach_port_identifier,
1231                 NULL,
1232         },
1233 };
1234
1235 /* *** detach a specified port *** */
1236 struct cmd_operate_detach_port_result {
1237         cmdline_fixed_string_t port;
1238         cmdline_fixed_string_t keyword;
1239         portid_t port_id;
1240 };
1241
1242 static void cmd_operate_detach_port_parsed(void *parsed_result,
1243                                 __attribute__((unused)) struct cmdline *cl,
1244                                 __attribute__((unused)) void *data)
1245 {
1246         struct cmd_operate_detach_port_result *res = parsed_result;
1247
1248         if (!strcmp(res->keyword, "detach"))
1249                 detach_port(res->port_id);
1250         else
1251                 printf("Unknown parameter\n");
1252 }
1253
1254 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1256                         port, "port");
1257 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1258         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1259                         keyword, "detach");
1260 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1261         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1262                         port_id, UINT16);
1263
1264 cmdline_parse_inst_t cmd_operate_detach_port = {
1265         .f = cmd_operate_detach_port_parsed,
1266         .data = NULL,
1267         .help_str = "port detach <port_id>",
1268         .tokens = {
1269                 (void *)&cmd_operate_detach_port_port,
1270                 (void *)&cmd_operate_detach_port_keyword,
1271                 (void *)&cmd_operate_detach_port_port_id,
1272                 NULL,
1273         },
1274 };
1275
1276 /* *** configure speed for all ports *** */
1277 struct cmd_config_speed_all {
1278         cmdline_fixed_string_t port;
1279         cmdline_fixed_string_t keyword;
1280         cmdline_fixed_string_t all;
1281         cmdline_fixed_string_t item1;
1282         cmdline_fixed_string_t item2;
1283         cmdline_fixed_string_t value1;
1284         cmdline_fixed_string_t value2;
1285 };
1286
1287 static int
1288 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1289 {
1290
1291         int duplex;
1292
1293         if (!strcmp(duplexstr, "half")) {
1294                 duplex = ETH_LINK_HALF_DUPLEX;
1295         } else if (!strcmp(duplexstr, "full")) {
1296                 duplex = ETH_LINK_FULL_DUPLEX;
1297         } else if (!strcmp(duplexstr, "auto")) {
1298                 duplex = ETH_LINK_FULL_DUPLEX;
1299         } else {
1300                 printf("Unknown duplex parameter\n");
1301                 return -1;
1302         }
1303
1304         if (!strcmp(speedstr, "10")) {
1305                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1306                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1307         } else if (!strcmp(speedstr, "100")) {
1308                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1309                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1310         } else {
1311                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1312                         printf("Invalid speed/duplex parameters\n");
1313                         return -1;
1314                 }
1315                 if (!strcmp(speedstr, "1000")) {
1316                         *speed = ETH_LINK_SPEED_1G;
1317                 } else if (!strcmp(speedstr, "10000")) {
1318                         *speed = ETH_LINK_SPEED_10G;
1319                 } else if (!strcmp(speedstr, "25000")) {
1320                         *speed = ETH_LINK_SPEED_25G;
1321                 } else if (!strcmp(speedstr, "40000")) {
1322                         *speed = ETH_LINK_SPEED_40G;
1323                 } else if (!strcmp(speedstr, "50000")) {
1324                         *speed = ETH_LINK_SPEED_50G;
1325                 } else if (!strcmp(speedstr, "100000")) {
1326                         *speed = ETH_LINK_SPEED_100G;
1327                 } else if (!strcmp(speedstr, "auto")) {
1328                         *speed = ETH_LINK_SPEED_AUTONEG;
1329                 } else {
1330                         printf("Unknown speed parameter\n");
1331                         return -1;
1332                 }
1333         }
1334
1335         return 0;
1336 }
1337
1338 static void
1339 cmd_config_speed_all_parsed(void *parsed_result,
1340                         __attribute__((unused)) struct cmdline *cl,
1341                         __attribute__((unused)) void *data)
1342 {
1343         struct cmd_config_speed_all *res = parsed_result;
1344         uint32_t link_speed;
1345         portid_t pid;
1346
1347         if (!all_ports_stopped()) {
1348                 printf("Please stop all ports first\n");
1349                 return;
1350         }
1351
1352         if (parse_and_check_speed_duplex(res->value1, res->value2,
1353                         &link_speed) < 0)
1354                 return;
1355
1356         RTE_ETH_FOREACH_DEV(pid) {
1357                 ports[pid].dev_conf.link_speeds = link_speed;
1358         }
1359
1360         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1361 }
1362
1363 cmdline_parse_token_string_t cmd_config_speed_all_port =
1364         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1365 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1366         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1367                                                         "config");
1368 cmdline_parse_token_string_t cmd_config_speed_all_all =
1369         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1370 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1371         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1372 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1373         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1374                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1375 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1376         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1377 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1378         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1379                                                 "half#full#auto");
1380
1381 cmdline_parse_inst_t cmd_config_speed_all = {
1382         .f = cmd_config_speed_all_parsed,
1383         .data = NULL,
1384         .help_str = "port config all speed "
1385                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1386                                                         "half|full|auto",
1387         .tokens = {
1388                 (void *)&cmd_config_speed_all_port,
1389                 (void *)&cmd_config_speed_all_keyword,
1390                 (void *)&cmd_config_speed_all_all,
1391                 (void *)&cmd_config_speed_all_item1,
1392                 (void *)&cmd_config_speed_all_value1,
1393                 (void *)&cmd_config_speed_all_item2,
1394                 (void *)&cmd_config_speed_all_value2,
1395                 NULL,
1396         },
1397 };
1398
1399 /* *** configure speed for specific port *** */
1400 struct cmd_config_speed_specific {
1401         cmdline_fixed_string_t port;
1402         cmdline_fixed_string_t keyword;
1403         uint8_t id;
1404         cmdline_fixed_string_t item1;
1405         cmdline_fixed_string_t item2;
1406         cmdline_fixed_string_t value1;
1407         cmdline_fixed_string_t value2;
1408 };
1409
1410 static void
1411 cmd_config_speed_specific_parsed(void *parsed_result,
1412                                 __attribute__((unused)) struct cmdline *cl,
1413                                 __attribute__((unused)) void *data)
1414 {
1415         struct cmd_config_speed_specific *res = parsed_result;
1416         uint32_t link_speed;
1417
1418         if (!all_ports_stopped()) {
1419                 printf("Please stop all ports first\n");
1420                 return;
1421         }
1422
1423         if (port_id_is_invalid(res->id, ENABLED_WARN))
1424                 return;
1425
1426         if (parse_and_check_speed_duplex(res->value1, res->value2,
1427                         &link_speed) < 0)
1428                 return;
1429
1430         ports[res->id].dev_conf.link_speeds = link_speed;
1431
1432         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1433 }
1434
1435
1436 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1437         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1438                                                                 "port");
1439 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1440         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1441                                                                 "config");
1442 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1443         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1444 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1445         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1446                                                                 "speed");
1447 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1448         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1449                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1450 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1451         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1452                                                                 "duplex");
1453 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1454         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1455                                                         "half#full#auto");
1456
1457 cmdline_parse_inst_t cmd_config_speed_specific = {
1458         .f = cmd_config_speed_specific_parsed,
1459         .data = NULL,
1460         .help_str = "port config <port_id> speed "
1461                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1462                                                         "half|full|auto",
1463         .tokens = {
1464                 (void *)&cmd_config_speed_specific_port,
1465                 (void *)&cmd_config_speed_specific_keyword,
1466                 (void *)&cmd_config_speed_specific_id,
1467                 (void *)&cmd_config_speed_specific_item1,
1468                 (void *)&cmd_config_speed_specific_value1,
1469                 (void *)&cmd_config_speed_specific_item2,
1470                 (void *)&cmd_config_speed_specific_value2,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** configure txq/rxq, txd/rxd *** */
1476 struct cmd_config_rx_tx {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         cmdline_fixed_string_t all;
1480         cmdline_fixed_string_t name;
1481         uint16_t value;
1482 };
1483
1484 static void
1485 cmd_config_rx_tx_parsed(void *parsed_result,
1486                         __attribute__((unused)) struct cmdline *cl,
1487                         __attribute__((unused)) void *data)
1488 {
1489         struct cmd_config_rx_tx *res = parsed_result;
1490
1491         if (!all_ports_stopped()) {
1492                 printf("Please stop all ports first\n");
1493                 return;
1494         }
1495         if (!strcmp(res->name, "rxq")) {
1496                 if (!res->value && !nb_txq) {
1497                         printf("Warning: Either rx or tx queues should be non zero\n");
1498                         return;
1499                 }
1500                 nb_rxq = res->value;
1501         }
1502         else if (!strcmp(res->name, "txq")) {
1503                 if (!res->value && !nb_rxq) {
1504                         printf("Warning: Either rx or tx queues should be non zero\n");
1505                         return;
1506                 }
1507                 nb_txq = res->value;
1508         }
1509         else if (!strcmp(res->name, "rxd")) {
1510                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1511                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1512                                         res->value, RTE_TEST_RX_DESC_MAX);
1513                         return;
1514                 }
1515                 nb_rxd = res->value;
1516         } else if (!strcmp(res->name, "txd")) {
1517                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1518                         printf("txd %d invalid - must be > 0 && <= %d\n",
1519                                         res->value, RTE_TEST_TX_DESC_MAX);
1520                         return;
1521                 }
1522                 nb_txd = res->value;
1523         } else {
1524                 printf("Unknown parameter\n");
1525                 return;
1526         }
1527
1528         fwd_config_setup();
1529
1530         init_port_config();
1531
1532         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1533 }
1534
1535 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1536         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1537 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1538         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1539 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1540         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1541 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1543                                                 "rxq#txq#rxd#txd");
1544 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1545         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1546
1547 cmdline_parse_inst_t cmd_config_rx_tx = {
1548         .f = cmd_config_rx_tx_parsed,
1549         .data = NULL,
1550         .help_str = "port config all rxq|txq|rxd|txd <value>",
1551         .tokens = {
1552                 (void *)&cmd_config_rx_tx_port,
1553                 (void *)&cmd_config_rx_tx_keyword,
1554                 (void *)&cmd_config_rx_tx_all,
1555                 (void *)&cmd_config_rx_tx_name,
1556                 (void *)&cmd_config_rx_tx_value,
1557                 NULL,
1558         },
1559 };
1560
1561 /* *** config max packet length *** */
1562 struct cmd_config_max_pkt_len_result {
1563         cmdline_fixed_string_t port;
1564         cmdline_fixed_string_t keyword;
1565         cmdline_fixed_string_t all;
1566         cmdline_fixed_string_t name;
1567         uint32_t value;
1568 };
1569
1570 static void
1571 cmd_config_max_pkt_len_parsed(void *parsed_result,
1572                                 __attribute__((unused)) struct cmdline *cl,
1573                                 __attribute__((unused)) void *data)
1574 {
1575         struct cmd_config_max_pkt_len_result *res = parsed_result;
1576
1577         if (!all_ports_stopped()) {
1578                 printf("Please stop all ports first\n");
1579                 return;
1580         }
1581
1582         if (!strcmp(res->name, "max-pkt-len")) {
1583                 if (res->value < ETHER_MIN_LEN) {
1584                         printf("max-pkt-len can not be less than %d\n",
1585                                                         ETHER_MIN_LEN);
1586                         return;
1587                 }
1588                 if (res->value == rx_mode.max_rx_pkt_len)
1589                         return;
1590
1591                 rx_mode.max_rx_pkt_len = res->value;
1592                 if (res->value > ETHER_MAX_LEN)
1593                         rx_mode.jumbo_frame = 1;
1594                 else
1595                         rx_mode.jumbo_frame = 0;
1596         } else {
1597                 printf("Unknown parameter\n");
1598                 return;
1599         }
1600
1601         init_port_config();
1602
1603         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1604 }
1605
1606 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1607         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1608                                                                 "port");
1609 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1610         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1611                                                                 "config");
1612 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1613         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1614                                                                 "all");
1615 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1616         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1617                                                                 "max-pkt-len");
1618 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1619         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1620                                                                 UINT32);
1621
1622 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1623         .f = cmd_config_max_pkt_len_parsed,
1624         .data = NULL,
1625         .help_str = "port config all max-pkt-len <value>",
1626         .tokens = {
1627                 (void *)&cmd_config_max_pkt_len_port,
1628                 (void *)&cmd_config_max_pkt_len_keyword,
1629                 (void *)&cmd_config_max_pkt_len_all,
1630                 (void *)&cmd_config_max_pkt_len_name,
1631                 (void *)&cmd_config_max_pkt_len_value,
1632                 NULL,
1633         },
1634 };
1635
1636 /* *** configure port MTU *** */
1637 struct cmd_config_mtu_result {
1638         cmdline_fixed_string_t port;
1639         cmdline_fixed_string_t keyword;
1640         cmdline_fixed_string_t mtu;
1641         portid_t port_id;
1642         uint16_t value;
1643 };
1644
1645 static void
1646 cmd_config_mtu_parsed(void *parsed_result,
1647                       __attribute__((unused)) struct cmdline *cl,
1648                       __attribute__((unused)) void *data)
1649 {
1650         struct cmd_config_mtu_result *res = parsed_result;
1651
1652         if (res->value < ETHER_MIN_LEN) {
1653                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1654                 return;
1655         }
1656         port_mtu_set(res->port_id, res->value);
1657 }
1658
1659 cmdline_parse_token_string_t cmd_config_mtu_port =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1661                                  "port");
1662 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1663         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1664                                  "config");
1665 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1667                                  "mtu");
1668 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1669         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1670 cmdline_parse_token_num_t cmd_config_mtu_value =
1671         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1672
1673 cmdline_parse_inst_t cmd_config_mtu = {
1674         .f = cmd_config_mtu_parsed,
1675         .data = NULL,
1676         .help_str = "port config mtu <port_id> <value>",
1677         .tokens = {
1678                 (void *)&cmd_config_mtu_port,
1679                 (void *)&cmd_config_mtu_keyword,
1680                 (void *)&cmd_config_mtu_mtu,
1681                 (void *)&cmd_config_mtu_port_id,
1682                 (void *)&cmd_config_mtu_value,
1683                 NULL,
1684         },
1685 };
1686
1687 /* *** configure rx mode *** */
1688 struct cmd_config_rx_mode_flag {
1689         cmdline_fixed_string_t port;
1690         cmdline_fixed_string_t keyword;
1691         cmdline_fixed_string_t all;
1692         cmdline_fixed_string_t name;
1693         cmdline_fixed_string_t value;
1694 };
1695
1696 static void
1697 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1698                                 __attribute__((unused)) struct cmdline *cl,
1699                                 __attribute__((unused)) void *data)
1700 {
1701         struct cmd_config_rx_mode_flag *res = parsed_result;
1702
1703         if (!all_ports_stopped()) {
1704                 printf("Please stop all ports first\n");
1705                 return;
1706         }
1707
1708         if (!strcmp(res->name, "crc-strip")) {
1709                 if (!strcmp(res->value, "on"))
1710                         rx_mode.hw_strip_crc = 1;
1711                 else if (!strcmp(res->value, "off"))
1712                         rx_mode.hw_strip_crc = 0;
1713                 else {
1714                         printf("Unknown parameter\n");
1715                         return;
1716                 }
1717         } else if (!strcmp(res->name, "scatter")) {
1718                 if (!strcmp(res->value, "on"))
1719                         rx_mode.enable_scatter = 1;
1720                 else if (!strcmp(res->value, "off"))
1721                         rx_mode.enable_scatter = 0;
1722                 else {
1723                         printf("Unknown parameter\n");
1724                         return;
1725                 }
1726         } else if (!strcmp(res->name, "rx-cksum")) {
1727                 if (!strcmp(res->value, "on"))
1728                         rx_mode.hw_ip_checksum = 1;
1729                 else if (!strcmp(res->value, "off"))
1730                         rx_mode.hw_ip_checksum = 0;
1731                 else {
1732                         printf("Unknown parameter\n");
1733                         return;
1734                 }
1735         } else if (!strcmp(res->name, "rx-timestamp")) {
1736                 if (!strcmp(res->value, "on"))
1737                         rx_mode.hw_timestamp = 1;
1738                 else if (!strcmp(res->value, "off"))
1739                         rx_mode.hw_timestamp = 0;
1740                 else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         } else if (!strcmp(res->name, "hw-vlan")) {
1745                 if (!strcmp(res->value, "on")) {
1746                         rx_mode.hw_vlan_filter = 1;
1747                         rx_mode.hw_vlan_strip  = 1;
1748                 }
1749                 else if (!strcmp(res->value, "off")) {
1750                         rx_mode.hw_vlan_filter = 0;
1751                         rx_mode.hw_vlan_strip  = 0;
1752                 }
1753                 else {
1754                         printf("Unknown parameter\n");
1755                         return;
1756                 }
1757         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1758                 if (!strcmp(res->value, "on"))
1759                         rx_mode.hw_vlan_filter = 1;
1760                 else if (!strcmp(res->value, "off"))
1761                         rx_mode.hw_vlan_filter = 0;
1762                 else {
1763                         printf("Unknown parameter\n");
1764                         return;
1765                 }
1766         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1767                 if (!strcmp(res->value, "on"))
1768                         rx_mode.hw_vlan_strip  = 1;
1769                 else if (!strcmp(res->value, "off"))
1770                         rx_mode.hw_vlan_strip  = 0;
1771                 else {
1772                         printf("Unknown parameter\n");
1773                         return;
1774                 }
1775         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1776                 if (!strcmp(res->value, "on"))
1777                         rx_mode.hw_vlan_extend = 1;
1778                 else if (!strcmp(res->value, "off"))
1779                         rx_mode.hw_vlan_extend = 0;
1780                 else {
1781                         printf("Unknown parameter\n");
1782                         return;
1783                 }
1784         } else if (!strcmp(res->name, "drop-en")) {
1785                 if (!strcmp(res->value, "on"))
1786                         rx_drop_en = 1;
1787                 else if (!strcmp(res->value, "off"))
1788                         rx_drop_en = 0;
1789                 else {
1790                         printf("Unknown parameter\n");
1791                         return;
1792                 }
1793         } else {
1794                 printf("Unknown parameter\n");
1795                 return;
1796         }
1797
1798         init_port_config();
1799
1800         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1801 }
1802
1803 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1804         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1805 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1807                                                                 "config");
1808 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1809         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1810 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1812                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1813                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1814 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1815         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1816                                                         "on#off");
1817
1818 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1819         .f = cmd_config_rx_mode_flag_parsed,
1820         .data = NULL,
1821         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1822                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1823         .tokens = {
1824                 (void *)&cmd_config_rx_mode_flag_port,
1825                 (void *)&cmd_config_rx_mode_flag_keyword,
1826                 (void *)&cmd_config_rx_mode_flag_all,
1827                 (void *)&cmd_config_rx_mode_flag_name,
1828                 (void *)&cmd_config_rx_mode_flag_value,
1829                 NULL,
1830         },
1831 };
1832
1833 /* *** configure rss *** */
1834 struct cmd_config_rss {
1835         cmdline_fixed_string_t port;
1836         cmdline_fixed_string_t keyword;
1837         cmdline_fixed_string_t all;
1838         cmdline_fixed_string_t name;
1839         cmdline_fixed_string_t value;
1840 };
1841
1842 static void
1843 cmd_config_rss_parsed(void *parsed_result,
1844                         __attribute__((unused)) struct cmdline *cl,
1845                         __attribute__((unused)) void *data)
1846 {
1847         struct cmd_config_rss *res = parsed_result;
1848         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1849         int diag;
1850         uint8_t i;
1851
1852         if (!strcmp(res->value, "all"))
1853                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1854                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1855                                         ETH_RSS_L2_PAYLOAD;
1856         else if (!strcmp(res->value, "ip"))
1857                 rss_conf.rss_hf = ETH_RSS_IP;
1858         else if (!strcmp(res->value, "udp"))
1859                 rss_conf.rss_hf = ETH_RSS_UDP;
1860         else if (!strcmp(res->value, "tcp"))
1861                 rss_conf.rss_hf = ETH_RSS_TCP;
1862         else if (!strcmp(res->value, "sctp"))
1863                 rss_conf.rss_hf = ETH_RSS_SCTP;
1864         else if (!strcmp(res->value, "ether"))
1865                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1866         else if (!strcmp(res->value, "port"))
1867                 rss_conf.rss_hf = ETH_RSS_PORT;
1868         else if (!strcmp(res->value, "vxlan"))
1869                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1870         else if (!strcmp(res->value, "geneve"))
1871                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1872         else if (!strcmp(res->value, "nvgre"))
1873                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1874         else if (!strcmp(res->value, "none"))
1875                 rss_conf.rss_hf = 0;
1876         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1877                                                 atoi(res->value) < 64)
1878                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1879         else {
1880                 printf("Unknown parameter\n");
1881                 return;
1882         }
1883         rss_conf.rss_key = NULL;
1884         for (i = 0; i < rte_eth_dev_count(); i++) {
1885                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1886                 if (diag < 0)
1887                         printf("Configuration of RSS hash at ethernet port %d "
1888                                 "failed with error (%d): %s.\n",
1889                                 i, -diag, strerror(-diag));
1890         }
1891 }
1892
1893 cmdline_parse_token_string_t cmd_config_rss_port =
1894         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1895 cmdline_parse_token_string_t cmd_config_rss_keyword =
1896         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1897 cmdline_parse_token_string_t cmd_config_rss_all =
1898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1899 cmdline_parse_token_string_t cmd_config_rss_name =
1900         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1901 cmdline_parse_token_string_t cmd_config_rss_value =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1903
1904 cmdline_parse_inst_t cmd_config_rss = {
1905         .f = cmd_config_rss_parsed,
1906         .data = NULL,
1907         .help_str = "port config all rss "
1908                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1909         .tokens = {
1910                 (void *)&cmd_config_rss_port,
1911                 (void *)&cmd_config_rss_keyword,
1912                 (void *)&cmd_config_rss_all,
1913                 (void *)&cmd_config_rss_name,
1914                 (void *)&cmd_config_rss_value,
1915                 NULL,
1916         },
1917 };
1918
1919 /* *** configure rss hash key *** */
1920 struct cmd_config_rss_hash_key {
1921         cmdline_fixed_string_t port;
1922         cmdline_fixed_string_t config;
1923         portid_t port_id;
1924         cmdline_fixed_string_t rss_hash_key;
1925         cmdline_fixed_string_t rss_type;
1926         cmdline_fixed_string_t key;
1927 };
1928
1929 static uint8_t
1930 hexa_digit_to_value(char hexa_digit)
1931 {
1932         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1933                 return (uint8_t) (hexa_digit - '0');
1934         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1935                 return (uint8_t) ((hexa_digit - 'a') + 10);
1936         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1937                 return (uint8_t) ((hexa_digit - 'A') + 10);
1938         /* Invalid hexa digit */
1939         return 0xFF;
1940 }
1941
1942 static uint8_t
1943 parse_and_check_key_hexa_digit(char *key, int idx)
1944 {
1945         uint8_t hexa_v;
1946
1947         hexa_v = hexa_digit_to_value(key[idx]);
1948         if (hexa_v == 0xFF)
1949                 printf("invalid key: character %c at position %d is not a "
1950                        "valid hexa digit\n", key[idx], idx);
1951         return hexa_v;
1952 }
1953
1954 static void
1955 cmd_config_rss_hash_key_parsed(void *parsed_result,
1956                                __attribute__((unused)) struct cmdline *cl,
1957                                __attribute__((unused)) void *data)
1958 {
1959         struct cmd_config_rss_hash_key *res = parsed_result;
1960         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1961         uint8_t xdgt0;
1962         uint8_t xdgt1;
1963         int i;
1964         struct rte_eth_dev_info dev_info;
1965         uint8_t hash_key_size;
1966         uint32_t key_len;
1967
1968         memset(&dev_info, 0, sizeof(dev_info));
1969         rte_eth_dev_info_get(res->port_id, &dev_info);
1970         if (dev_info.hash_key_size > 0 &&
1971                         dev_info.hash_key_size <= sizeof(hash_key))
1972                 hash_key_size = dev_info.hash_key_size;
1973         else {
1974                 printf("dev_info did not provide a valid hash key size\n");
1975                 return;
1976         }
1977         /* Check the length of the RSS hash key */
1978         key_len = strlen(res->key);
1979         if (key_len != (hash_key_size * 2)) {
1980                 printf("key length: %d invalid - key must be a string of %d"
1981                            " hexa-decimal numbers\n",
1982                            (int) key_len, hash_key_size * 2);
1983                 return;
1984         }
1985         /* Translate RSS hash key into binary representation */
1986         for (i = 0; i < hash_key_size; i++) {
1987                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1988                 if (xdgt0 == 0xFF)
1989                         return;
1990                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1991                 if (xdgt1 == 0xFF)
1992                         return;
1993                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1994         }
1995         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1996                         hash_key_size);
1997 }
1998
1999 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2001 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2003                                  "config");
2004 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2005         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2006 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2008                                  rss_hash_key, "rss-hash-key");
2009 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2011                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2012                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2013                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2014                                  "ipv6-tcp-ex#ipv6-udp-ex");
2015 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2016         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2017
2018 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2019         .f = cmd_config_rss_hash_key_parsed,
2020         .data = NULL,
2021         .help_str = "port config <port_id> rss-hash-key "
2022                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2023                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2024                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2025                 "<string of hex digits (variable length, NIC dependent)>",
2026         .tokens = {
2027                 (void *)&cmd_config_rss_hash_key_port,
2028                 (void *)&cmd_config_rss_hash_key_config,
2029                 (void *)&cmd_config_rss_hash_key_port_id,
2030                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2031                 (void *)&cmd_config_rss_hash_key_rss_type,
2032                 (void *)&cmd_config_rss_hash_key_value,
2033                 NULL,
2034         },
2035 };
2036
2037 /* *** configure port rxq/txq start/stop *** */
2038 struct cmd_config_rxtx_queue {
2039         cmdline_fixed_string_t port;
2040         portid_t portid;
2041         cmdline_fixed_string_t rxtxq;
2042         uint16_t qid;
2043         cmdline_fixed_string_t opname;
2044 };
2045
2046 static void
2047 cmd_config_rxtx_queue_parsed(void *parsed_result,
2048                         __attribute__((unused)) struct cmdline *cl,
2049                         __attribute__((unused)) void *data)
2050 {
2051         struct cmd_config_rxtx_queue *res = parsed_result;
2052         uint8_t isrx;
2053         uint8_t isstart;
2054         int ret = 0;
2055
2056         if (test_done == 0) {
2057                 printf("Please stop forwarding first\n");
2058                 return;
2059         }
2060
2061         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2062                 return;
2063
2064         if (port_is_started(res->portid) != 1) {
2065                 printf("Please start port %u first\n", res->portid);
2066                 return;
2067         }
2068
2069         if (!strcmp(res->rxtxq, "rxq"))
2070                 isrx = 1;
2071         else if (!strcmp(res->rxtxq, "txq"))
2072                 isrx = 0;
2073         else {
2074                 printf("Unknown parameter\n");
2075                 return;
2076         }
2077
2078         if (isrx && rx_queue_id_is_invalid(res->qid))
2079                 return;
2080         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2081                 return;
2082
2083         if (!strcmp(res->opname, "start"))
2084                 isstart = 1;
2085         else if (!strcmp(res->opname, "stop"))
2086                 isstart = 0;
2087         else {
2088                 printf("Unknown parameter\n");
2089                 return;
2090         }
2091
2092         if (isstart && isrx)
2093                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2094         else if (!isstart && isrx)
2095                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2096         else if (isstart && !isrx)
2097                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2098         else
2099                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2100
2101         if (ret == -ENOTSUP)
2102                 printf("Function not supported in PMD driver\n");
2103 }
2104
2105 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2106         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2107 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2108         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2109 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2111 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2112         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2113 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2114         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2115                                                 "start#stop");
2116
2117 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2118         .f = cmd_config_rxtx_queue_parsed,
2119         .data = NULL,
2120         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2121         .tokens = {
2122                 (void *)&cmd_config_speed_all_port,
2123                 (void *)&cmd_config_rxtx_queue_portid,
2124                 (void *)&cmd_config_rxtx_queue_rxtxq,
2125                 (void *)&cmd_config_rxtx_queue_qid,
2126                 (void *)&cmd_config_rxtx_queue_opname,
2127                 NULL,
2128         },
2129 };
2130
2131 /* *** Configure RSS RETA *** */
2132 struct cmd_config_rss_reta {
2133         cmdline_fixed_string_t port;
2134         cmdline_fixed_string_t keyword;
2135         portid_t port_id;
2136         cmdline_fixed_string_t name;
2137         cmdline_fixed_string_t list_name;
2138         cmdline_fixed_string_t list_of_items;
2139 };
2140
2141 static int
2142 parse_reta_config(const char *str,
2143                   struct rte_eth_rss_reta_entry64 *reta_conf,
2144                   uint16_t nb_entries)
2145 {
2146         int i;
2147         unsigned size;
2148         uint16_t hash_index, idx, shift;
2149         uint16_t nb_queue;
2150         char s[256];
2151         const char *p, *p0 = str;
2152         char *end;
2153         enum fieldnames {
2154                 FLD_HASH_INDEX = 0,
2155                 FLD_QUEUE,
2156                 _NUM_FLD
2157         };
2158         unsigned long int_fld[_NUM_FLD];
2159         char *str_fld[_NUM_FLD];
2160
2161         while ((p = strchr(p0,'(')) != NULL) {
2162                 ++p;
2163                 if((p0 = strchr(p,')')) == NULL)
2164                         return -1;
2165
2166                 size = p0 - p;
2167                 if(size >= sizeof(s))
2168                         return -1;
2169
2170                 snprintf(s, sizeof(s), "%.*s", size, p);
2171                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2172                         return -1;
2173                 for (i = 0; i < _NUM_FLD; i++) {
2174                         errno = 0;
2175                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2176                         if (errno != 0 || end == str_fld[i] ||
2177                                         int_fld[i] > 65535)
2178                                 return -1;
2179                 }
2180
2181                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2182                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2183
2184                 if (hash_index >= nb_entries) {
2185                         printf("Invalid RETA hash index=%d\n", hash_index);
2186                         return -1;
2187                 }
2188
2189                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2190                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2191                 reta_conf[idx].mask |= (1ULL << shift);
2192                 reta_conf[idx].reta[shift] = nb_queue;
2193         }
2194
2195         return 0;
2196 }
2197
2198 static void
2199 cmd_set_rss_reta_parsed(void *parsed_result,
2200                         __attribute__((unused)) struct cmdline *cl,
2201                         __attribute__((unused)) void *data)
2202 {
2203         int ret;
2204         struct rte_eth_dev_info dev_info;
2205         struct rte_eth_rss_reta_entry64 reta_conf[8];
2206         struct cmd_config_rss_reta *res = parsed_result;
2207
2208         memset(&dev_info, 0, sizeof(dev_info));
2209         rte_eth_dev_info_get(res->port_id, &dev_info);
2210         if (dev_info.reta_size == 0) {
2211                 printf("Redirection table size is 0 which is "
2212                                         "invalid for RSS\n");
2213                 return;
2214         } else
2215                 printf("The reta size of port %d is %u\n",
2216                         res->port_id, dev_info.reta_size);
2217         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2218                 printf("Currently do not support more than %u entries of "
2219                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2220                 return;
2221         }
2222
2223         memset(reta_conf, 0, sizeof(reta_conf));
2224         if (!strcmp(res->list_name, "reta")) {
2225                 if (parse_reta_config(res->list_of_items, reta_conf,
2226                                                 dev_info.reta_size)) {
2227                         printf("Invalid RSS Redirection Table "
2228                                         "config entered\n");
2229                         return;
2230                 }
2231                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2232                                 reta_conf, dev_info.reta_size);
2233                 if (ret != 0)
2234                         printf("Bad redirection table parameter, "
2235                                         "return code = %d \n", ret);
2236         }
2237 }
2238
2239 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2240         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2241 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2242         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2243 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2244         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2245 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2246         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2247 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2249 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2251                                  NULL);
2252 cmdline_parse_inst_t cmd_config_rss_reta = {
2253         .f = cmd_set_rss_reta_parsed,
2254         .data = NULL,
2255         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2256         .tokens = {
2257                 (void *)&cmd_config_rss_reta_port,
2258                 (void *)&cmd_config_rss_reta_keyword,
2259                 (void *)&cmd_config_rss_reta_port_id,
2260                 (void *)&cmd_config_rss_reta_name,
2261                 (void *)&cmd_config_rss_reta_list_name,
2262                 (void *)&cmd_config_rss_reta_list_of_items,
2263                 NULL,
2264         },
2265 };
2266
2267 /* *** SHOW PORT RETA INFO *** */
2268 struct cmd_showport_reta {
2269         cmdline_fixed_string_t show;
2270         cmdline_fixed_string_t port;
2271         portid_t port_id;
2272         cmdline_fixed_string_t rss;
2273         cmdline_fixed_string_t reta;
2274         uint16_t size;
2275         cmdline_fixed_string_t list_of_items;
2276 };
2277
2278 static int
2279 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2280                            uint16_t nb_entries,
2281                            char *str)
2282 {
2283         uint32_t size;
2284         const char *p, *p0 = str;
2285         char s[256];
2286         char *end;
2287         char *str_fld[8];
2288         uint16_t i;
2289         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2290                         RTE_RETA_GROUP_SIZE;
2291         int ret;
2292
2293         p = strchr(p0, '(');
2294         if (p == NULL)
2295                 return -1;
2296         p++;
2297         p0 = strchr(p, ')');
2298         if (p0 == NULL)
2299                 return -1;
2300         size = p0 - p;
2301         if (size >= sizeof(s)) {
2302                 printf("The string size exceeds the internal buffer size\n");
2303                 return -1;
2304         }
2305         snprintf(s, sizeof(s), "%.*s", size, p);
2306         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2307         if (ret <= 0 || ret != num) {
2308                 printf("The bits of masks do not match the number of "
2309                                         "reta entries: %u\n", num);
2310                 return -1;
2311         }
2312         for (i = 0; i < ret; i++)
2313                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2314
2315         return 0;
2316 }
2317
2318 static void
2319 cmd_showport_reta_parsed(void *parsed_result,
2320                          __attribute__((unused)) struct cmdline *cl,
2321                          __attribute__((unused)) void *data)
2322 {
2323         struct cmd_showport_reta *res = parsed_result;
2324         struct rte_eth_rss_reta_entry64 reta_conf[8];
2325         struct rte_eth_dev_info dev_info;
2326         uint16_t max_reta_size;
2327
2328         memset(&dev_info, 0, sizeof(dev_info));
2329         rte_eth_dev_info_get(res->port_id, &dev_info);
2330         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2331         if (res->size == 0 || res->size > max_reta_size) {
2332                 printf("Invalid redirection table size: %u (1-%u)\n",
2333                         res->size, max_reta_size);
2334                 return;
2335         }
2336
2337         memset(reta_conf, 0, sizeof(reta_conf));
2338         if (showport_parse_reta_config(reta_conf, res->size,
2339                                 res->list_of_items) < 0) {
2340                 printf("Invalid string: %s for reta masks\n",
2341                                         res->list_of_items);
2342                 return;
2343         }
2344         port_rss_reta_info(res->port_id, reta_conf, res->size);
2345 }
2346
2347 cmdline_parse_token_string_t cmd_showport_reta_show =
2348         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2349 cmdline_parse_token_string_t cmd_showport_reta_port =
2350         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2351 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2352         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2353 cmdline_parse_token_string_t cmd_showport_reta_rss =
2354         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2355 cmdline_parse_token_string_t cmd_showport_reta_reta =
2356         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2357 cmdline_parse_token_num_t cmd_showport_reta_size =
2358         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2359 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2360         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2361                                         list_of_items, NULL);
2362
2363 cmdline_parse_inst_t cmd_showport_reta = {
2364         .f = cmd_showport_reta_parsed,
2365         .data = NULL,
2366         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2367         .tokens = {
2368                 (void *)&cmd_showport_reta_show,
2369                 (void *)&cmd_showport_reta_port,
2370                 (void *)&cmd_showport_reta_port_id,
2371                 (void *)&cmd_showport_reta_rss,
2372                 (void *)&cmd_showport_reta_reta,
2373                 (void *)&cmd_showport_reta_size,
2374                 (void *)&cmd_showport_reta_list_of_items,
2375                 NULL,
2376         },
2377 };
2378
2379 /* *** Show RSS hash configuration *** */
2380 struct cmd_showport_rss_hash {
2381         cmdline_fixed_string_t show;
2382         cmdline_fixed_string_t port;
2383         portid_t port_id;
2384         cmdline_fixed_string_t rss_hash;
2385         cmdline_fixed_string_t rss_type;
2386         cmdline_fixed_string_t key; /* optional argument */
2387 };
2388
2389 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2390                                 __attribute__((unused)) struct cmdline *cl,
2391                                 void *show_rss_key)
2392 {
2393         struct cmd_showport_rss_hash *res = parsed_result;
2394
2395         port_rss_hash_conf_show(res->port_id, res->rss_type,
2396                                 show_rss_key != NULL);
2397 }
2398
2399 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2400         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2401 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2402         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2403 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2404         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2405 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2406         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2407                                  "rss-hash");
2408 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2409         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2410                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2411                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2412                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2413                                  "ipv6-tcp-ex#ipv6-udp-ex");
2414 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2415         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2416
2417 cmdline_parse_inst_t cmd_showport_rss_hash = {
2418         .f = cmd_showport_rss_hash_parsed,
2419         .data = NULL,
2420         .help_str = "show port <port_id> rss-hash "
2421                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2422                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2423                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2424         .tokens = {
2425                 (void *)&cmd_showport_rss_hash_show,
2426                 (void *)&cmd_showport_rss_hash_port,
2427                 (void *)&cmd_showport_rss_hash_port_id,
2428                 (void *)&cmd_showport_rss_hash_rss_hash,
2429                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2430                 NULL,
2431         },
2432 };
2433
2434 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2435         .f = cmd_showport_rss_hash_parsed,
2436         .data = (void *)1,
2437         .help_str = "show port <port_id> rss-hash "
2438                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2439                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2440                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2441         .tokens = {
2442                 (void *)&cmd_showport_rss_hash_show,
2443                 (void *)&cmd_showport_rss_hash_port,
2444                 (void *)&cmd_showport_rss_hash_port_id,
2445                 (void *)&cmd_showport_rss_hash_rss_hash,
2446                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2447                 (void *)&cmd_showport_rss_hash_rss_key,
2448                 NULL,
2449         },
2450 };
2451
2452 /* *** Configure DCB *** */
2453 struct cmd_config_dcb {
2454         cmdline_fixed_string_t port;
2455         cmdline_fixed_string_t config;
2456         portid_t port_id;
2457         cmdline_fixed_string_t dcb;
2458         cmdline_fixed_string_t vt;
2459         cmdline_fixed_string_t vt_en;
2460         uint8_t num_tcs;
2461         cmdline_fixed_string_t pfc;
2462         cmdline_fixed_string_t pfc_en;
2463 };
2464
2465 static void
2466 cmd_config_dcb_parsed(void *parsed_result,
2467                         __attribute__((unused)) struct cmdline *cl,
2468                         __attribute__((unused)) void *data)
2469 {
2470         struct cmd_config_dcb *res = parsed_result;
2471         portid_t port_id = res->port_id;
2472         struct rte_port *port;
2473         uint8_t pfc_en;
2474         int ret;
2475
2476         port = &ports[port_id];
2477         /** Check if the port is not started **/
2478         if (port->port_status != RTE_PORT_STOPPED) {
2479                 printf("Please stop port %d first\n", port_id);
2480                 return;
2481         }
2482
2483         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2484                 printf("The invalid number of traffic class,"
2485                         " only 4 or 8 allowed.\n");
2486                 return;
2487         }
2488
2489         if (nb_fwd_lcores < res->num_tcs) {
2490                 printf("nb_cores shouldn't be less than number of TCs.\n");
2491                 return;
2492         }
2493         if (!strncmp(res->pfc_en, "on", 2))
2494                 pfc_en = 1;
2495         else
2496                 pfc_en = 0;
2497
2498         /* DCB in VT mode */
2499         if (!strncmp(res->vt_en, "on", 2))
2500                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2501                                 (enum rte_eth_nb_tcs)res->num_tcs,
2502                                 pfc_en);
2503         else
2504                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2505                                 (enum rte_eth_nb_tcs)res->num_tcs,
2506                                 pfc_en);
2507
2508
2509         if (ret != 0) {
2510                 printf("Cannot initialize network ports.\n");
2511                 return;
2512         }
2513
2514         cmd_reconfig_device_queue(port_id, 1, 1);
2515 }
2516
2517 cmdline_parse_token_string_t cmd_config_dcb_port =
2518         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2519 cmdline_parse_token_string_t cmd_config_dcb_config =
2520         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2521 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2522         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2523 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2524         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2525 cmdline_parse_token_string_t cmd_config_dcb_vt =
2526         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2527 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2528         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2529 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2530         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2531 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2532         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2533 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2534         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2535
2536 cmdline_parse_inst_t cmd_config_dcb = {
2537         .f = cmd_config_dcb_parsed,
2538         .data = NULL,
2539         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2540         .tokens = {
2541                 (void *)&cmd_config_dcb_port,
2542                 (void *)&cmd_config_dcb_config,
2543                 (void *)&cmd_config_dcb_port_id,
2544                 (void *)&cmd_config_dcb_dcb,
2545                 (void *)&cmd_config_dcb_vt,
2546                 (void *)&cmd_config_dcb_vt_en,
2547                 (void *)&cmd_config_dcb_num_tcs,
2548                 (void *)&cmd_config_dcb_pfc,
2549                 (void *)&cmd_config_dcb_pfc_en,
2550                 NULL,
2551         },
2552 };
2553
2554 /* *** configure number of packets per burst *** */
2555 struct cmd_config_burst {
2556         cmdline_fixed_string_t port;
2557         cmdline_fixed_string_t keyword;
2558         cmdline_fixed_string_t all;
2559         cmdline_fixed_string_t name;
2560         uint16_t value;
2561 };
2562
2563 static void
2564 cmd_config_burst_parsed(void *parsed_result,
2565                         __attribute__((unused)) struct cmdline *cl,
2566                         __attribute__((unused)) void *data)
2567 {
2568         struct cmd_config_burst *res = parsed_result;
2569
2570         if (!all_ports_stopped()) {
2571                 printf("Please stop all ports first\n");
2572                 return;
2573         }
2574
2575         if (!strcmp(res->name, "burst")) {
2576                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2577                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2578                         return;
2579                 }
2580                 nb_pkt_per_burst = res->value;
2581         } else {
2582                 printf("Unknown parameter\n");
2583                 return;
2584         }
2585
2586         init_port_config();
2587
2588         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2589 }
2590
2591 cmdline_parse_token_string_t cmd_config_burst_port =
2592         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2593 cmdline_parse_token_string_t cmd_config_burst_keyword =
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2595 cmdline_parse_token_string_t cmd_config_burst_all =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2597 cmdline_parse_token_string_t cmd_config_burst_name =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2599 cmdline_parse_token_num_t cmd_config_burst_value =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2601
2602 cmdline_parse_inst_t cmd_config_burst = {
2603         .f = cmd_config_burst_parsed,
2604         .data = NULL,
2605         .help_str = "port config all burst <value>",
2606         .tokens = {
2607                 (void *)&cmd_config_burst_port,
2608                 (void *)&cmd_config_burst_keyword,
2609                 (void *)&cmd_config_burst_all,
2610                 (void *)&cmd_config_burst_name,
2611                 (void *)&cmd_config_burst_value,
2612                 NULL,
2613         },
2614 };
2615
2616 /* *** configure rx/tx queues *** */
2617 struct cmd_config_thresh {
2618         cmdline_fixed_string_t port;
2619         cmdline_fixed_string_t keyword;
2620         cmdline_fixed_string_t all;
2621         cmdline_fixed_string_t name;
2622         uint8_t value;
2623 };
2624
2625 static void
2626 cmd_config_thresh_parsed(void *parsed_result,
2627                         __attribute__((unused)) struct cmdline *cl,
2628                         __attribute__((unused)) void *data)
2629 {
2630         struct cmd_config_thresh *res = parsed_result;
2631
2632         if (!all_ports_stopped()) {
2633                 printf("Please stop all ports first\n");
2634                 return;
2635         }
2636
2637         if (!strcmp(res->name, "txpt"))
2638                 tx_pthresh = res->value;
2639         else if(!strcmp(res->name, "txht"))
2640                 tx_hthresh = res->value;
2641         else if(!strcmp(res->name, "txwt"))
2642                 tx_wthresh = res->value;
2643         else if(!strcmp(res->name, "rxpt"))
2644                 rx_pthresh = res->value;
2645         else if(!strcmp(res->name, "rxht"))
2646                 rx_hthresh = res->value;
2647         else if(!strcmp(res->name, "rxwt"))
2648                 rx_wthresh = res->value;
2649         else {
2650                 printf("Unknown parameter\n");
2651                 return;
2652         }
2653
2654         init_port_config();
2655
2656         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2657 }
2658
2659 cmdline_parse_token_string_t cmd_config_thresh_port =
2660         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2661 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2663 cmdline_parse_token_string_t cmd_config_thresh_all =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2665 cmdline_parse_token_string_t cmd_config_thresh_name =
2666         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2667                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2668 cmdline_parse_token_num_t cmd_config_thresh_value =
2669         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2670
2671 cmdline_parse_inst_t cmd_config_thresh = {
2672         .f = cmd_config_thresh_parsed,
2673         .data = NULL,
2674         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2675         .tokens = {
2676                 (void *)&cmd_config_thresh_port,
2677                 (void *)&cmd_config_thresh_keyword,
2678                 (void *)&cmd_config_thresh_all,
2679                 (void *)&cmd_config_thresh_name,
2680                 (void *)&cmd_config_thresh_value,
2681                 NULL,
2682         },
2683 };
2684
2685 /* *** configure free/rs threshold *** */
2686 struct cmd_config_threshold {
2687         cmdline_fixed_string_t port;
2688         cmdline_fixed_string_t keyword;
2689         cmdline_fixed_string_t all;
2690         cmdline_fixed_string_t name;
2691         uint16_t value;
2692 };
2693
2694 static void
2695 cmd_config_threshold_parsed(void *parsed_result,
2696                         __attribute__((unused)) struct cmdline *cl,
2697                         __attribute__((unused)) void *data)
2698 {
2699         struct cmd_config_threshold *res = parsed_result;
2700
2701         if (!all_ports_stopped()) {
2702                 printf("Please stop all ports first\n");
2703                 return;
2704         }
2705
2706         if (!strcmp(res->name, "txfreet"))
2707                 tx_free_thresh = res->value;
2708         else if (!strcmp(res->name, "txrst"))
2709                 tx_rs_thresh = res->value;
2710         else if (!strcmp(res->name, "rxfreet"))
2711                 rx_free_thresh = res->value;
2712         else {
2713                 printf("Unknown parameter\n");
2714                 return;
2715         }
2716
2717         init_port_config();
2718
2719         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2720 }
2721
2722 cmdline_parse_token_string_t cmd_config_threshold_port =
2723         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2724 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2725         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2726                                                                 "config");
2727 cmdline_parse_token_string_t cmd_config_threshold_all =
2728         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2729 cmdline_parse_token_string_t cmd_config_threshold_name =
2730         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2731                                                 "txfreet#txrst#rxfreet");
2732 cmdline_parse_token_num_t cmd_config_threshold_value =
2733         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2734
2735 cmdline_parse_inst_t cmd_config_threshold = {
2736         .f = cmd_config_threshold_parsed,
2737         .data = NULL,
2738         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2739         .tokens = {
2740                 (void *)&cmd_config_threshold_port,
2741                 (void *)&cmd_config_threshold_keyword,
2742                 (void *)&cmd_config_threshold_all,
2743                 (void *)&cmd_config_threshold_name,
2744                 (void *)&cmd_config_threshold_value,
2745                 NULL,
2746         },
2747 };
2748
2749 /* *** stop *** */
2750 struct cmd_stop_result {
2751         cmdline_fixed_string_t stop;
2752 };
2753
2754 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2755                             __attribute__((unused)) struct cmdline *cl,
2756                             __attribute__((unused)) void *data)
2757 {
2758         stop_packet_forwarding();
2759 }
2760
2761 cmdline_parse_token_string_t cmd_stop_stop =
2762         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2763
2764 cmdline_parse_inst_t cmd_stop = {
2765         .f = cmd_stop_parsed,
2766         .data = NULL,
2767         .help_str = "stop: Stop packet forwarding",
2768         .tokens = {
2769                 (void *)&cmd_stop_stop,
2770                 NULL,
2771         },
2772 };
2773
2774 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2775
2776 unsigned int
2777 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2778                 unsigned int *parsed_items, int check_unique_values)
2779 {
2780         unsigned int nb_item;
2781         unsigned int value;
2782         unsigned int i;
2783         unsigned int j;
2784         int value_ok;
2785         char c;
2786
2787         /*
2788          * First parse all items in the list and store their value.
2789          */
2790         value = 0;
2791         nb_item = 0;
2792         value_ok = 0;
2793         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2794                 c = str[i];
2795                 if ((c >= '0') && (c <= '9')) {
2796                         value = (unsigned int) (value * 10 + (c - '0'));
2797                         value_ok = 1;
2798                         continue;
2799                 }
2800                 if (c != ',') {
2801                         printf("character %c is not a decimal digit\n", c);
2802                         return 0;
2803                 }
2804                 if (! value_ok) {
2805                         printf("No valid value before comma\n");
2806                         return 0;
2807                 }
2808                 if (nb_item < max_items) {
2809                         parsed_items[nb_item] = value;
2810                         value_ok = 0;
2811                         value = 0;
2812                 }
2813                 nb_item++;
2814         }
2815         if (nb_item >= max_items) {
2816                 printf("Number of %s = %u > %u (maximum items)\n",
2817                        item_name, nb_item + 1, max_items);
2818                 return 0;
2819         }
2820         parsed_items[nb_item++] = value;
2821         if (! check_unique_values)
2822                 return nb_item;
2823
2824         /*
2825          * Then, check that all values in the list are differents.
2826          * No optimization here...
2827          */
2828         for (i = 0; i < nb_item; i++) {
2829                 for (j = i + 1; j < nb_item; j++) {
2830                         if (parsed_items[j] == parsed_items[i]) {
2831                                 printf("duplicated %s %u at index %u and %u\n",
2832                                        item_name, parsed_items[i], i, j);
2833                                 return 0;
2834                         }
2835                 }
2836         }
2837         return nb_item;
2838 }
2839
2840 struct cmd_set_list_result {
2841         cmdline_fixed_string_t cmd_keyword;
2842         cmdline_fixed_string_t list_name;
2843         cmdline_fixed_string_t list_of_items;
2844 };
2845
2846 static void cmd_set_list_parsed(void *parsed_result,
2847                                 __attribute__((unused)) struct cmdline *cl,
2848                                 __attribute__((unused)) void *data)
2849 {
2850         struct cmd_set_list_result *res;
2851         union {
2852                 unsigned int lcorelist[RTE_MAX_LCORE];
2853                 unsigned int portlist[RTE_MAX_ETHPORTS];
2854         } parsed_items;
2855         unsigned int nb_item;
2856
2857         if (test_done == 0) {
2858                 printf("Please stop forwarding first\n");
2859                 return;
2860         }
2861
2862         res = parsed_result;
2863         if (!strcmp(res->list_name, "corelist")) {
2864                 nb_item = parse_item_list(res->list_of_items, "core",
2865                                           RTE_MAX_LCORE,
2866                                           parsed_items.lcorelist, 1);
2867                 if (nb_item > 0) {
2868                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2869                         fwd_config_setup();
2870                 }
2871                 return;
2872         }
2873         if (!strcmp(res->list_name, "portlist")) {
2874                 nb_item = parse_item_list(res->list_of_items, "port",
2875                                           RTE_MAX_ETHPORTS,
2876                                           parsed_items.portlist, 1);
2877                 if (nb_item > 0) {
2878                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2879                         fwd_config_setup();
2880                 }
2881         }
2882 }
2883
2884 cmdline_parse_token_string_t cmd_set_list_keyword =
2885         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2886                                  "set");
2887 cmdline_parse_token_string_t cmd_set_list_name =
2888         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2889                                  "corelist#portlist");
2890 cmdline_parse_token_string_t cmd_set_list_of_items =
2891         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2892                                  NULL);
2893
2894 cmdline_parse_inst_t cmd_set_fwd_list = {
2895         .f = cmd_set_list_parsed,
2896         .data = NULL,
2897         .help_str = "set corelist|portlist <list0[,list1]*>",
2898         .tokens = {
2899                 (void *)&cmd_set_list_keyword,
2900                 (void *)&cmd_set_list_name,
2901                 (void *)&cmd_set_list_of_items,
2902                 NULL,
2903         },
2904 };
2905
2906 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2907
2908 struct cmd_setmask_result {
2909         cmdline_fixed_string_t set;
2910         cmdline_fixed_string_t mask;
2911         uint64_t hexavalue;
2912 };
2913
2914 static void cmd_set_mask_parsed(void *parsed_result,
2915                                 __attribute__((unused)) struct cmdline *cl,
2916                                 __attribute__((unused)) void *data)
2917 {
2918         struct cmd_setmask_result *res = parsed_result;
2919
2920         if (test_done == 0) {
2921                 printf("Please stop forwarding first\n");
2922                 return;
2923         }
2924         if (!strcmp(res->mask, "coremask")) {
2925                 set_fwd_lcores_mask(res->hexavalue);
2926                 fwd_config_setup();
2927         } else if (!strcmp(res->mask, "portmask")) {
2928                 set_fwd_ports_mask(res->hexavalue);
2929                 fwd_config_setup();
2930         }
2931 }
2932
2933 cmdline_parse_token_string_t cmd_setmask_set =
2934         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2935 cmdline_parse_token_string_t cmd_setmask_mask =
2936         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2937                                  "coremask#portmask");
2938 cmdline_parse_token_num_t cmd_setmask_value =
2939         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2940
2941 cmdline_parse_inst_t cmd_set_fwd_mask = {
2942         .f = cmd_set_mask_parsed,
2943         .data = NULL,
2944         .help_str = "set coremask|portmask <hexadecimal value>",
2945         .tokens = {
2946                 (void *)&cmd_setmask_set,
2947                 (void *)&cmd_setmask_mask,
2948                 (void *)&cmd_setmask_value,
2949                 NULL,
2950         },
2951 };
2952
2953 /*
2954  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2955  */
2956 struct cmd_set_result {
2957         cmdline_fixed_string_t set;
2958         cmdline_fixed_string_t what;
2959         uint16_t value;
2960 };
2961
2962 static void cmd_set_parsed(void *parsed_result,
2963                            __attribute__((unused)) struct cmdline *cl,
2964                            __attribute__((unused)) void *data)
2965 {
2966         struct cmd_set_result *res = parsed_result;
2967         if (!strcmp(res->what, "nbport")) {
2968                 set_fwd_ports_number(res->value);
2969                 fwd_config_setup();
2970         } else if (!strcmp(res->what, "nbcore")) {
2971                 set_fwd_lcores_number(res->value);
2972                 fwd_config_setup();
2973         } else if (!strcmp(res->what, "burst"))
2974                 set_nb_pkt_per_burst(res->value);
2975         else if (!strcmp(res->what, "verbose"))
2976                 set_verbose_level(res->value);
2977 }
2978
2979 cmdline_parse_token_string_t cmd_set_set =
2980         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2981 cmdline_parse_token_string_t cmd_set_what =
2982         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2983                                  "nbport#nbcore#burst#verbose");
2984 cmdline_parse_token_num_t cmd_set_value =
2985         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2986
2987 cmdline_parse_inst_t cmd_set_numbers = {
2988         .f = cmd_set_parsed,
2989         .data = NULL,
2990         .help_str = "set nbport|nbcore|burst|verbose <value>",
2991         .tokens = {
2992                 (void *)&cmd_set_set,
2993                 (void *)&cmd_set_what,
2994                 (void *)&cmd_set_value,
2995                 NULL,
2996         },
2997 };
2998
2999 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3000
3001 struct cmd_set_txpkts_result {
3002         cmdline_fixed_string_t cmd_keyword;
3003         cmdline_fixed_string_t txpkts;
3004         cmdline_fixed_string_t seg_lengths;
3005 };
3006
3007 static void
3008 cmd_set_txpkts_parsed(void *parsed_result,
3009                       __attribute__((unused)) struct cmdline *cl,
3010                       __attribute__((unused)) void *data)
3011 {
3012         struct cmd_set_txpkts_result *res;
3013         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3014         unsigned int nb_segs;
3015
3016         res = parsed_result;
3017         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3018                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3019         if (nb_segs > 0)
3020                 set_tx_pkt_segments(seg_lengths, nb_segs);
3021 }
3022
3023 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3024         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3025                                  cmd_keyword, "set");
3026 cmdline_parse_token_string_t cmd_set_txpkts_name =
3027         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3028                                  txpkts, "txpkts");
3029 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3030         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3031                                  seg_lengths, NULL);
3032
3033 cmdline_parse_inst_t cmd_set_txpkts = {
3034         .f = cmd_set_txpkts_parsed,
3035         .data = NULL,
3036         .help_str = "set txpkts <len0[,len1]*>",
3037         .tokens = {
3038                 (void *)&cmd_set_txpkts_keyword,
3039                 (void *)&cmd_set_txpkts_name,
3040                 (void *)&cmd_set_txpkts_lengths,
3041                 NULL,
3042         },
3043 };
3044
3045 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3046
3047 struct cmd_set_txsplit_result {
3048         cmdline_fixed_string_t cmd_keyword;
3049         cmdline_fixed_string_t txsplit;
3050         cmdline_fixed_string_t mode;
3051 };
3052
3053 static void
3054 cmd_set_txsplit_parsed(void *parsed_result,
3055                       __attribute__((unused)) struct cmdline *cl,
3056                       __attribute__((unused)) void *data)
3057 {
3058         struct cmd_set_txsplit_result *res;
3059
3060         res = parsed_result;
3061         set_tx_pkt_split(res->mode);
3062 }
3063
3064 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3065         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3066                                  cmd_keyword, "set");
3067 cmdline_parse_token_string_t cmd_set_txsplit_name =
3068         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3069                                  txsplit, "txsplit");
3070 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3071         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3072                                  mode, NULL);
3073
3074 cmdline_parse_inst_t cmd_set_txsplit = {
3075         .f = cmd_set_txsplit_parsed,
3076         .data = NULL,
3077         .help_str = "set txsplit on|off|rand",
3078         .tokens = {
3079                 (void *)&cmd_set_txsplit_keyword,
3080                 (void *)&cmd_set_txsplit_name,
3081                 (void *)&cmd_set_txsplit_mode,
3082                 NULL,
3083         },
3084 };
3085
3086 /* *** CONFIG TX QUEUE FLAGS *** */
3087
3088 struct cmd_config_txqflags_result {
3089         cmdline_fixed_string_t port;
3090         cmdline_fixed_string_t config;
3091         cmdline_fixed_string_t all;
3092         cmdline_fixed_string_t what;
3093         int32_t hexvalue;
3094 };
3095
3096 static void cmd_config_txqflags_parsed(void *parsed_result,
3097                                 __attribute__((unused)) struct cmdline *cl,
3098                                 __attribute__((unused)) void *data)
3099 {
3100         struct cmd_config_txqflags_result *res = parsed_result;
3101
3102         if (!all_ports_stopped()) {
3103                 printf("Please stop all ports first\n");
3104                 return;
3105         }
3106
3107         if (strcmp(res->what, "txqflags")) {
3108                 printf("Unknown parameter\n");
3109                 return;
3110         }
3111
3112         if (res->hexvalue >= 0) {
3113                 txq_flags = res->hexvalue;
3114         } else {
3115                 printf("txqflags must be >= 0\n");
3116                 return;
3117         }
3118
3119         init_port_config();
3120
3121         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3122 }
3123
3124 cmdline_parse_token_string_t cmd_config_txqflags_port =
3125         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3126                                  "port");
3127 cmdline_parse_token_string_t cmd_config_txqflags_config =
3128         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3129                                  "config");
3130 cmdline_parse_token_string_t cmd_config_txqflags_all =
3131         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3132                                  "all");
3133 cmdline_parse_token_string_t cmd_config_txqflags_what =
3134         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3135                                  "txqflags");
3136 cmdline_parse_token_num_t cmd_config_txqflags_value =
3137         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3138                                 hexvalue, INT32);
3139
3140 cmdline_parse_inst_t cmd_config_txqflags = {
3141         .f = cmd_config_txqflags_parsed,
3142         .data = NULL,
3143         .help_str = "port config all txqflags <value>",
3144         .tokens = {
3145                 (void *)&cmd_config_txqflags_port,
3146                 (void *)&cmd_config_txqflags_config,
3147                 (void *)&cmd_config_txqflags_all,
3148                 (void *)&cmd_config_txqflags_what,
3149                 (void *)&cmd_config_txqflags_value,
3150                 NULL,
3151         },
3152 };
3153
3154 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3155 struct cmd_rx_vlan_filter_all_result {
3156         cmdline_fixed_string_t rx_vlan;
3157         cmdline_fixed_string_t what;
3158         cmdline_fixed_string_t all;
3159         portid_t port_id;
3160 };
3161
3162 static void
3163 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3164                               __attribute__((unused)) struct cmdline *cl,
3165                               __attribute__((unused)) void *data)
3166 {
3167         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3168
3169         if (!strcmp(res->what, "add"))
3170                 rx_vlan_all_filter_set(res->port_id, 1);
3171         else
3172                 rx_vlan_all_filter_set(res->port_id, 0);
3173 }
3174
3175 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3176         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3177                                  rx_vlan, "rx_vlan");
3178 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3179         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3180                                  what, "add#rm");
3181 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3182         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3183                                  all, "all");
3184 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3185         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3186                               port_id, UINT16);
3187
3188 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3189         .f = cmd_rx_vlan_filter_all_parsed,
3190         .data = NULL,
3191         .help_str = "rx_vlan add|rm all <port_id>: "
3192                 "Add/Remove all identifiers to/from the set of VLAN "
3193                 "identifiers filtered by a port",
3194         .tokens = {
3195                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3196                 (void *)&cmd_rx_vlan_filter_all_what,
3197                 (void *)&cmd_rx_vlan_filter_all_all,
3198                 (void *)&cmd_rx_vlan_filter_all_portid,
3199                 NULL,
3200         },
3201 };
3202
3203 /* *** VLAN OFFLOAD SET ON A PORT *** */
3204 struct cmd_vlan_offload_result {
3205         cmdline_fixed_string_t vlan;
3206         cmdline_fixed_string_t set;
3207         cmdline_fixed_string_t vlan_type;
3208         cmdline_fixed_string_t what;
3209         cmdline_fixed_string_t on;
3210         cmdline_fixed_string_t port_id;
3211 };
3212
3213 static void
3214 cmd_vlan_offload_parsed(void *parsed_result,
3215                           __attribute__((unused)) struct cmdline *cl,
3216                           __attribute__((unused)) void *data)
3217 {
3218         int on;
3219         struct cmd_vlan_offload_result *res = parsed_result;
3220         char *str;
3221         int i, len = 0;
3222         portid_t port_id = 0;
3223         unsigned int tmp;
3224
3225         str = res->port_id;
3226         len = strnlen(str, STR_TOKEN_SIZE);
3227         i = 0;
3228         /* Get port_id first */
3229         while(i < len){
3230                 if(str[i] == ',')
3231                         break;
3232
3233                 i++;
3234         }
3235         str[i]='\0';
3236         tmp = strtoul(str, NULL, 0);
3237         /* If port_id greater that what portid_t can represent, return */
3238         if(tmp >= RTE_MAX_ETHPORTS)
3239                 return;
3240         port_id = (portid_t)tmp;
3241
3242         if (!strcmp(res->on, "on"))
3243                 on = 1;
3244         else
3245                 on = 0;
3246
3247         if (!strcmp(res->what, "strip"))
3248                 rx_vlan_strip_set(port_id,  on);
3249         else if(!strcmp(res->what, "stripq")){
3250                 uint16_t queue_id = 0;
3251
3252                 /* No queue_id, return */
3253                 if(i + 1 >= len) {
3254                         printf("must specify (port,queue_id)\n");
3255                         return;
3256                 }
3257                 tmp = strtoul(str + i + 1, NULL, 0);
3258                 /* If queue_id greater that what 16-bits can represent, return */
3259                 if(tmp > 0xffff)
3260                         return;
3261
3262                 queue_id = (uint16_t)tmp;
3263                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3264         }
3265         else if (!strcmp(res->what, "filter"))
3266                 rx_vlan_filter_set(port_id, on);
3267         else
3268                 vlan_extend_set(port_id, on);
3269
3270         return;
3271 }
3272
3273 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3275                                  vlan, "vlan");
3276 cmdline_parse_token_string_t cmd_vlan_offload_set =
3277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3278                                  set, "set");
3279 cmdline_parse_token_string_t cmd_vlan_offload_what =
3280         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3281                                  what, "strip#filter#qinq#stripq");
3282 cmdline_parse_token_string_t cmd_vlan_offload_on =
3283         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3284                               on, "on#off");
3285 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3286         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3287                               port_id, NULL);
3288
3289 cmdline_parse_inst_t cmd_vlan_offload = {
3290         .f = cmd_vlan_offload_parsed,
3291         .data = NULL,
3292         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3293                 "<port_id[,queue_id]>: "
3294                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3295         .tokens = {
3296                 (void *)&cmd_vlan_offload_vlan,
3297                 (void *)&cmd_vlan_offload_set,
3298                 (void *)&cmd_vlan_offload_what,
3299                 (void *)&cmd_vlan_offload_on,
3300                 (void *)&cmd_vlan_offload_portid,
3301                 NULL,
3302         },
3303 };
3304
3305 /* *** VLAN TPID SET ON A PORT *** */
3306 struct cmd_vlan_tpid_result {
3307         cmdline_fixed_string_t vlan;
3308         cmdline_fixed_string_t set;
3309         cmdline_fixed_string_t vlan_type;
3310         cmdline_fixed_string_t what;
3311         uint16_t tp_id;
3312         portid_t port_id;
3313 };
3314
3315 static void
3316 cmd_vlan_tpid_parsed(void *parsed_result,
3317                           __attribute__((unused)) struct cmdline *cl,
3318                           __attribute__((unused)) void *data)
3319 {
3320         struct cmd_vlan_tpid_result *res = parsed_result;
3321         enum rte_vlan_type vlan_type;
3322
3323         if (!strcmp(res->vlan_type, "inner"))
3324                 vlan_type = ETH_VLAN_TYPE_INNER;
3325         else if (!strcmp(res->vlan_type, "outer"))
3326                 vlan_type = ETH_VLAN_TYPE_OUTER;
3327         else {
3328                 printf("Unknown vlan type\n");
3329                 return;
3330         }
3331         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3332 }
3333
3334 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3336                                  vlan, "vlan");
3337 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3338         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3339                                  set, "set");
3340 cmdline_parse_token_string_t cmd_vlan_type =
3341         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3342                                  vlan_type, "inner#outer");
3343 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3344         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3345                                  what, "tpid");
3346 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3347         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3348                               tp_id, UINT16);
3349 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3350         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3351                               port_id, UINT8);
3352
3353 cmdline_parse_inst_t cmd_vlan_tpid = {
3354         .f = cmd_vlan_tpid_parsed,
3355         .data = NULL,
3356         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3357                 "Set the VLAN Ether type",
3358         .tokens = {
3359                 (void *)&cmd_vlan_tpid_vlan,
3360                 (void *)&cmd_vlan_tpid_set,
3361                 (void *)&cmd_vlan_type,
3362                 (void *)&cmd_vlan_tpid_what,
3363                 (void *)&cmd_vlan_tpid_tpid,
3364                 (void *)&cmd_vlan_tpid_portid,
3365                 NULL,
3366         },
3367 };
3368
3369 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3370 struct cmd_rx_vlan_filter_result {
3371         cmdline_fixed_string_t rx_vlan;
3372         cmdline_fixed_string_t what;
3373         uint16_t vlan_id;
3374         portid_t port_id;
3375 };
3376
3377 static void
3378 cmd_rx_vlan_filter_parsed(void *parsed_result,
3379                           __attribute__((unused)) struct cmdline *cl,
3380                           __attribute__((unused)) void *data)
3381 {
3382         struct cmd_rx_vlan_filter_result *res = parsed_result;
3383
3384         if (!strcmp(res->what, "add"))
3385                 rx_vft_set(res->port_id, res->vlan_id, 1);
3386         else
3387                 rx_vft_set(res->port_id, res->vlan_id, 0);
3388 }
3389
3390 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3391         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3392                                  rx_vlan, "rx_vlan");
3393 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3394         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3395                                  what, "add#rm");
3396 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3397         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3398                               vlan_id, UINT16);
3399 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3400         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3401                               port_id, UINT16);
3402
3403 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3404         .f = cmd_rx_vlan_filter_parsed,
3405         .data = NULL,
3406         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3407                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3408                 "identifiers filtered by a port",
3409         .tokens = {
3410                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3411                 (void *)&cmd_rx_vlan_filter_what,
3412                 (void *)&cmd_rx_vlan_filter_vlanid,
3413                 (void *)&cmd_rx_vlan_filter_portid,
3414                 NULL,
3415         },
3416 };
3417
3418 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3419 struct cmd_tx_vlan_set_result {
3420         cmdline_fixed_string_t tx_vlan;
3421         cmdline_fixed_string_t set;
3422         portid_t port_id;
3423         uint16_t vlan_id;
3424 };
3425
3426 static void
3427 cmd_tx_vlan_set_parsed(void *parsed_result,
3428                        __attribute__((unused)) struct cmdline *cl,
3429                        __attribute__((unused)) void *data)
3430 {
3431         struct cmd_tx_vlan_set_result *res = parsed_result;
3432
3433         tx_vlan_set(res->port_id, res->vlan_id);
3434 }
3435
3436 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3437         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3438                                  tx_vlan, "tx_vlan");
3439 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3440         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3441                                  set, "set");
3442 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3443         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3444                               port_id, UINT16);
3445 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3446         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3447                               vlan_id, UINT16);
3448
3449 cmdline_parse_inst_t cmd_tx_vlan_set = {
3450         .f = cmd_tx_vlan_set_parsed,
3451         .data = NULL,
3452         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3453                 "Enable hardware insertion of a single VLAN header "
3454                 "with a given TAG Identifier in packets sent on a port",
3455         .tokens = {
3456                 (void *)&cmd_tx_vlan_set_tx_vlan,
3457                 (void *)&cmd_tx_vlan_set_set,
3458                 (void *)&cmd_tx_vlan_set_portid,
3459                 (void *)&cmd_tx_vlan_set_vlanid,
3460                 NULL,
3461         },
3462 };
3463
3464 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3465 struct cmd_tx_vlan_set_qinq_result {
3466         cmdline_fixed_string_t tx_vlan;
3467         cmdline_fixed_string_t set;
3468         portid_t port_id;
3469         uint16_t vlan_id;
3470         uint16_t vlan_id_outer;
3471 };
3472
3473 static void
3474 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3475                             __attribute__((unused)) struct cmdline *cl,
3476                             __attribute__((unused)) void *data)
3477 {
3478         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3479
3480         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3481 }
3482
3483 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3485                 tx_vlan, "tx_vlan");
3486 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3488                 set, "set");
3489 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3490         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3491                 port_id, UINT16);
3492 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3494                 vlan_id, UINT16);
3495 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3497                 vlan_id_outer, UINT16);
3498
3499 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3500         .f = cmd_tx_vlan_set_qinq_parsed,
3501         .data = NULL,
3502         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3503                 "Enable hardware insertion of double VLAN header "
3504                 "with given TAG Identifiers in packets sent on a port",
3505         .tokens = {
3506                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3507                 (void *)&cmd_tx_vlan_set_qinq_set,
3508                 (void *)&cmd_tx_vlan_set_qinq_portid,
3509                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3510                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3511                 NULL,
3512         },
3513 };
3514
3515 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3516 struct cmd_tx_vlan_set_pvid_result {
3517         cmdline_fixed_string_t tx_vlan;
3518         cmdline_fixed_string_t set;
3519         cmdline_fixed_string_t pvid;
3520         portid_t port_id;
3521         uint16_t vlan_id;
3522         cmdline_fixed_string_t mode;
3523 };
3524
3525 static void
3526 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3527                             __attribute__((unused)) struct cmdline *cl,
3528                             __attribute__((unused)) void *data)
3529 {
3530         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3531
3532         if (strcmp(res->mode, "on") == 0)
3533                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3534         else
3535                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3536 }
3537
3538 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3539         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3540                                  tx_vlan, "tx_vlan");
3541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3543                                  set, "set");
3544 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3546                                  pvid, "pvid");
3547 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3548         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3549                              port_id, UINT16);
3550 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3551         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3552                               vlan_id, UINT16);
3553 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3554         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3555                                  mode, "on#off");
3556
3557 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3558         .f = cmd_tx_vlan_set_pvid_parsed,
3559         .data = NULL,
3560         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3561         .tokens = {
3562                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3563                 (void *)&cmd_tx_vlan_set_pvid_set,
3564                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3565                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3566                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3567                 (void *)&cmd_tx_vlan_set_pvid_mode,
3568                 NULL,
3569         },
3570 };
3571
3572 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3573 struct cmd_tx_vlan_reset_result {
3574         cmdline_fixed_string_t tx_vlan;
3575         cmdline_fixed_string_t reset;
3576         portid_t port_id;
3577 };
3578
3579 static void
3580 cmd_tx_vlan_reset_parsed(void *parsed_result,
3581                          __attribute__((unused)) struct cmdline *cl,
3582                          __attribute__((unused)) void *data)
3583 {
3584         struct cmd_tx_vlan_reset_result *res = parsed_result;
3585
3586         tx_vlan_reset(res->port_id);
3587 }
3588
3589 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3590         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3591                                  tx_vlan, "tx_vlan");
3592 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3593         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3594                                  reset, "reset");
3595 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3596         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3597                               port_id, UINT16);
3598
3599 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3600         .f = cmd_tx_vlan_reset_parsed,
3601         .data = NULL,
3602         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3603                 "VLAN header in packets sent on a port",
3604         .tokens = {
3605                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3606                 (void *)&cmd_tx_vlan_reset_reset,
3607                 (void *)&cmd_tx_vlan_reset_portid,
3608                 NULL,
3609         },
3610 };
3611
3612
3613 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3614 struct cmd_csum_result {
3615         cmdline_fixed_string_t csum;
3616         cmdline_fixed_string_t mode;
3617         cmdline_fixed_string_t proto;
3618         cmdline_fixed_string_t hwsw;
3619         portid_t port_id;
3620 };
3621
3622 static void
3623 csum_show(int port_id)
3624 {
3625         struct rte_eth_dev_info dev_info;
3626         uint16_t ol_flags;
3627
3628         ol_flags = ports[port_id].tx_ol_flags;
3629         printf("Parse tunnel is %s\n",
3630                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3631         printf("IP checksum offload is %s\n",
3632                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3633         printf("UDP checksum offload is %s\n",
3634                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3635         printf("TCP checksum offload is %s\n",
3636                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3637         printf("SCTP checksum offload is %s\n",
3638                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3639         printf("Outer-Ip checksum offload is %s\n",
3640                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3641
3642         /* display warnings if configuration is not supported by the NIC */
3643         rte_eth_dev_info_get(port_id, &dev_info);
3644         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3645                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3646                 printf("Warning: hardware IP checksum enabled but not "
3647                         "supported by port %d\n", port_id);
3648         }
3649         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3650                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3651                 printf("Warning: hardware UDP checksum enabled but not "
3652                         "supported by port %d\n", port_id);
3653         }
3654         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3655                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3656                 printf("Warning: hardware TCP checksum enabled but not "
3657                         "supported by port %d\n", port_id);
3658         }
3659         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3660                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3661                 printf("Warning: hardware SCTP checksum enabled but not "
3662                         "supported by port %d\n", port_id);
3663         }
3664         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3665                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3666                 printf("Warning: hardware outer IP checksum enabled but not "
3667                         "supported by port %d\n", port_id);
3668         }
3669 }
3670
3671 static void
3672 cmd_csum_parsed(void *parsed_result,
3673                        __attribute__((unused)) struct cmdline *cl,
3674                        __attribute__((unused)) void *data)
3675 {
3676         struct cmd_csum_result *res = parsed_result;
3677         int hw = 0;
3678         uint16_t mask = 0;
3679
3680         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3681                 printf("invalid port %d\n", res->port_id);
3682                 return;
3683         }
3684
3685         if (!strcmp(res->mode, "set")) {
3686
3687                 if (!strcmp(res->hwsw, "hw"))
3688                         hw = 1;
3689
3690                 if (!strcmp(res->proto, "ip")) {
3691                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3692                 } else if (!strcmp(res->proto, "udp")) {
3693                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3694                 } else if (!strcmp(res->proto, "tcp")) {
3695                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3696                 } else if (!strcmp(res->proto, "sctp")) {
3697                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3698                 } else if (!strcmp(res->proto, "outer-ip")) {
3699                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3700                 }
3701
3702                 if (hw)
3703                         ports[res->port_id].tx_ol_flags |= mask;
3704                 else
3705                         ports[res->port_id].tx_ol_flags &= (~mask);
3706         }
3707         csum_show(res->port_id);
3708 }
3709
3710 cmdline_parse_token_string_t cmd_csum_csum =
3711         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3712                                 csum, "csum");
3713 cmdline_parse_token_string_t cmd_csum_mode =
3714         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3715                                 mode, "set");
3716 cmdline_parse_token_string_t cmd_csum_proto =
3717         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3718                                 proto, "ip#tcp#udp#sctp#outer-ip");
3719 cmdline_parse_token_string_t cmd_csum_hwsw =
3720         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3721                                 hwsw, "hw#sw");
3722 cmdline_parse_token_num_t cmd_csum_portid =
3723         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3724                                 port_id, UINT16);
3725
3726 cmdline_parse_inst_t cmd_csum_set = {
3727         .f = cmd_csum_parsed,
3728         .data = NULL,
3729         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3730                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3731                 "using csum forward engine",
3732         .tokens = {
3733                 (void *)&cmd_csum_csum,
3734                 (void *)&cmd_csum_mode,
3735                 (void *)&cmd_csum_proto,
3736                 (void *)&cmd_csum_hwsw,
3737                 (void *)&cmd_csum_portid,
3738                 NULL,
3739         },
3740 };
3741
3742 cmdline_parse_token_string_t cmd_csum_mode_show =
3743         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3744                                 mode, "show");
3745
3746 cmdline_parse_inst_t cmd_csum_show = {
3747         .f = cmd_csum_parsed,
3748         .data = NULL,
3749         .help_str = "csum show <port_id>: Show checksum offload configuration",
3750         .tokens = {
3751                 (void *)&cmd_csum_csum,
3752                 (void *)&cmd_csum_mode_show,
3753                 (void *)&cmd_csum_portid,
3754                 NULL,
3755         },
3756 };
3757
3758 /* Enable/disable tunnel parsing */
3759 struct cmd_csum_tunnel_result {
3760         cmdline_fixed_string_t csum;
3761         cmdline_fixed_string_t parse;
3762         cmdline_fixed_string_t onoff;
3763         portid_t port_id;
3764 };
3765
3766 static void
3767 cmd_csum_tunnel_parsed(void *parsed_result,
3768                        __attribute__((unused)) struct cmdline *cl,
3769                        __attribute__((unused)) void *data)
3770 {
3771         struct cmd_csum_tunnel_result *res = parsed_result;
3772
3773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3774                 return;
3775
3776         if (!strcmp(res->onoff, "on"))
3777                 ports[res->port_id].tx_ol_flags |=
3778                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3779         else
3780                 ports[res->port_id].tx_ol_flags &=
3781                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3782
3783         csum_show(res->port_id);
3784 }
3785
3786 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3787         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3788                                 csum, "csum");
3789 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3790         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3791                                 parse, "parse_tunnel");
3792 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3793         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3794                                 onoff, "on#off");
3795 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3796         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3797                                 port_id, UINT16);
3798
3799 cmdline_parse_inst_t cmd_csum_tunnel = {
3800         .f = cmd_csum_tunnel_parsed,
3801         .data = NULL,
3802         .help_str = "csum parse_tunnel on|off <port_id>: "
3803                 "Enable/Disable parsing of tunnels for csum engine",
3804         .tokens = {
3805                 (void *)&cmd_csum_tunnel_csum,
3806                 (void *)&cmd_csum_tunnel_parse,
3807                 (void *)&cmd_csum_tunnel_onoff,
3808                 (void *)&cmd_csum_tunnel_portid,
3809                 NULL,
3810         },
3811 };
3812
3813 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3814 struct cmd_tso_set_result {
3815         cmdline_fixed_string_t tso;
3816         cmdline_fixed_string_t mode;
3817         uint16_t tso_segsz;
3818         portid_t port_id;
3819 };
3820
3821 static void
3822 cmd_tso_set_parsed(void *parsed_result,
3823                        __attribute__((unused)) struct cmdline *cl,
3824                        __attribute__((unused)) void *data)
3825 {
3826         struct cmd_tso_set_result *res = parsed_result;
3827         struct rte_eth_dev_info dev_info;
3828
3829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3830                 return;
3831
3832         if (!strcmp(res->mode, "set"))
3833                 ports[res->port_id].tso_segsz = res->tso_segsz;
3834
3835         if (ports[res->port_id].tso_segsz == 0)
3836                 printf("TSO for non-tunneled packets is disabled\n");
3837         else
3838                 printf("TSO segment size for non-tunneled packets is %d\n",
3839                         ports[res->port_id].tso_segsz);
3840
3841         /* display warnings if configuration is not supported by the NIC */
3842         rte_eth_dev_info_get(res->port_id, &dev_info);
3843         if ((ports[res->port_id].tso_segsz != 0) &&
3844                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3845                 printf("Warning: TSO enabled but not "
3846                         "supported by port %d\n", res->port_id);
3847         }
3848 }
3849
3850 cmdline_parse_token_string_t cmd_tso_set_tso =
3851         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3852                                 tso, "tso");
3853 cmdline_parse_token_string_t cmd_tso_set_mode =
3854         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3855                                 mode, "set");
3856 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3857         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3858                                 tso_segsz, UINT16);
3859 cmdline_parse_token_num_t cmd_tso_set_portid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3861                                 port_id, UINT16);
3862
3863 cmdline_parse_inst_t cmd_tso_set = {
3864         .f = cmd_tso_set_parsed,
3865         .data = NULL,
3866         .help_str = "tso set <tso_segsz> <port_id>: "
3867                 "Set TSO segment size of non-tunneled packets for csum engine "
3868                 "(0 to disable)",
3869         .tokens = {
3870                 (void *)&cmd_tso_set_tso,
3871                 (void *)&cmd_tso_set_mode,
3872                 (void *)&cmd_tso_set_tso_segsz,
3873                 (void *)&cmd_tso_set_portid,
3874                 NULL,
3875         },
3876 };
3877
3878 cmdline_parse_token_string_t cmd_tso_show_mode =
3879         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3880                                 mode, "show");
3881
3882
3883 cmdline_parse_inst_t cmd_tso_show = {
3884         .f = cmd_tso_set_parsed,
3885         .data = NULL,
3886         .help_str = "tso show <port_id>: "
3887                 "Show TSO segment size of non-tunneled packets for csum engine",
3888         .tokens = {
3889                 (void *)&cmd_tso_set_tso,
3890                 (void *)&cmd_tso_show_mode,
3891                 (void *)&cmd_tso_set_portid,
3892                 NULL,
3893         },
3894 };
3895
3896 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3897 struct cmd_tunnel_tso_set_result {
3898         cmdline_fixed_string_t tso;
3899         cmdline_fixed_string_t mode;
3900         uint16_t tso_segsz;
3901         portid_t port_id;
3902 };
3903
3904 static void
3905 check_tunnel_tso_nic_support(portid_t port_id)
3906 {
3907         struct rte_eth_dev_info dev_info;
3908
3909         rte_eth_dev_info_get(port_id, &dev_info);
3910         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3911                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3912                        "supported by port %d\n", port_id);
3913         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3914                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3915                         "supported by port %d\n", port_id);
3916         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3917                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3918                        "supported by port %d\n", port_id);
3919         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3920                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3921                        "supported by port %d\n", port_id);
3922 }
3923
3924 static void
3925 cmd_tunnel_tso_set_parsed(void *parsed_result,
3926                           __attribute__((unused)) struct cmdline *cl,
3927                           __attribute__((unused)) void *data)
3928 {
3929         struct cmd_tunnel_tso_set_result *res = parsed_result;
3930
3931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3932                 return;
3933
3934         if (!strcmp(res->mode, "set"))
3935                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3936
3937         if (ports[res->port_id].tunnel_tso_segsz == 0)
3938                 printf("TSO for tunneled packets is disabled\n");
3939         else {
3940                 printf("TSO segment size for tunneled packets is %d\n",
3941                         ports[res->port_id].tunnel_tso_segsz);
3942
3943                 /* Below conditions are needed to make it work:
3944                  * (1) tunnel TSO is supported by the NIC;
3945                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3946                  * are recognized;
3947                  * (3) for tunneled pkts with outer L3 of IPv4,
3948                  * "csum set outer-ip" must be set to hw, because after tso,
3949                  * total_len of outer IP header is changed, and the checksum
3950                  * of outer IP header calculated by sw should be wrong; that
3951                  * is not necessary for IPv6 tunneled pkts because there's no
3952                  * checksum in IP header anymore.
3953                  */
3954                 check_tunnel_tso_nic_support(res->port_id);
3955
3956                 if (!(ports[res->port_id].tx_ol_flags &
3957                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3958                         printf("Warning: csum parse_tunnel must be set "
3959                                 "so that tunneled packets are recognized\n");
3960                 if (!(ports[res->port_id].tx_ol_flags &
3961                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3962                         printf("Warning: csum set outer-ip must be set to hw "
3963                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3964         }
3965 }
3966
3967 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3968         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3969                                 tso, "tunnel_tso");
3970 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3971         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3972                                 mode, "set");
3973 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3974         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3975                                 tso_segsz, UINT16);
3976 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3977         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3978                                 port_id, UINT16);
3979
3980 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3981         .f = cmd_tunnel_tso_set_parsed,
3982         .data = NULL,
3983         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3984                 "Set TSO segment size of tunneled packets for csum engine "
3985                 "(0 to disable)",
3986         .tokens = {
3987                 (void *)&cmd_tunnel_tso_set_tso,
3988                 (void *)&cmd_tunnel_tso_set_mode,
3989                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3990                 (void *)&cmd_tunnel_tso_set_portid,
3991                 NULL,
3992         },
3993 };
3994
3995 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3996         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3997                                 mode, "show");
3998
3999
4000 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4001         .f = cmd_tunnel_tso_set_parsed,
4002         .data = NULL,
4003         .help_str = "tunnel_tso show <port_id> "
4004                 "Show TSO segment size of tunneled packets for csum engine",
4005         .tokens = {
4006                 (void *)&cmd_tunnel_tso_set_tso,
4007                 (void *)&cmd_tunnel_tso_show_mode,
4008                 (void *)&cmd_tunnel_tso_set_portid,
4009                 NULL,
4010         },
4011 };
4012
4013 /* *** SET GRO FOR A PORT *** */
4014 struct cmd_gro_enable_result {
4015         cmdline_fixed_string_t cmd_set;
4016         cmdline_fixed_string_t cmd_port;
4017         cmdline_fixed_string_t cmd_keyword;
4018         cmdline_fixed_string_t cmd_onoff;
4019         portid_t cmd_pid;
4020 };
4021
4022 static void
4023 cmd_gro_enable_parsed(void *parsed_result,
4024                 __attribute__((unused)) struct cmdline *cl,
4025                 __attribute__((unused)) void *data)
4026 {
4027         struct cmd_gro_enable_result *res;
4028
4029         res = parsed_result;
4030         if (!strcmp(res->cmd_keyword, "gro"))
4031                 setup_gro(res->cmd_onoff, res->cmd_pid);
4032 }
4033
4034 cmdline_parse_token_string_t cmd_gro_enable_set =
4035         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4036                         cmd_set, "set");
4037 cmdline_parse_token_string_t cmd_gro_enable_port =
4038         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4039                         cmd_keyword, "port");
4040 cmdline_parse_token_num_t cmd_gro_enable_pid =
4041         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4042                         cmd_pid, UINT16);
4043 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4044         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4045                         cmd_keyword, "gro");
4046 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4047         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4048                         cmd_onoff, "on#off");
4049
4050 cmdline_parse_inst_t cmd_gro_enable = {
4051         .f = cmd_gro_enable_parsed,
4052         .data = NULL,
4053         .help_str = "set port <port_id> gro on|off",
4054         .tokens = {
4055                 (void *)&cmd_gro_enable_set,
4056                 (void *)&cmd_gro_enable_port,
4057                 (void *)&cmd_gro_enable_pid,
4058                 (void *)&cmd_gro_enable_keyword,
4059                 (void *)&cmd_gro_enable_onoff,
4060                 NULL,
4061         },
4062 };
4063
4064 /* *** DISPLAY GRO CONFIGURATION *** */
4065 struct cmd_gro_show_result {
4066         cmdline_fixed_string_t cmd_show;
4067         cmdline_fixed_string_t cmd_port;
4068         cmdline_fixed_string_t cmd_keyword;
4069         portid_t cmd_pid;
4070 };
4071
4072 static void
4073 cmd_gro_show_parsed(void *parsed_result,
4074                 __attribute__((unused)) struct cmdline *cl,
4075                 __attribute__((unused)) void *data)
4076 {
4077         struct cmd_gro_show_result *res;
4078
4079         res = parsed_result;
4080         if (!strcmp(res->cmd_keyword, "gro"))
4081                 show_gro(res->cmd_pid);
4082 }
4083
4084 cmdline_parse_token_string_t cmd_gro_show_show =
4085         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4086                         cmd_show, "show");
4087 cmdline_parse_token_string_t cmd_gro_show_port =
4088         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4089                         cmd_port, "port");
4090 cmdline_parse_token_num_t cmd_gro_show_pid =
4091         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4092                         cmd_pid, UINT16);
4093 cmdline_parse_token_string_t cmd_gro_show_keyword =
4094         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4095                         cmd_keyword, "gro");
4096
4097 cmdline_parse_inst_t cmd_gro_show = {
4098         .f = cmd_gro_show_parsed,
4099         .data = NULL,
4100         .help_str = "show port <port_id> gro",
4101         .tokens = {
4102                 (void *)&cmd_gro_show_show,
4103                 (void *)&cmd_gro_show_port,
4104                 (void *)&cmd_gro_show_pid,
4105                 (void *)&cmd_gro_show_keyword,
4106                 NULL,
4107         },
4108 };
4109
4110 /* *** SET FLUSH CYCLES FOR GRO *** */
4111 struct cmd_gro_flush_result {
4112         cmdline_fixed_string_t cmd_set;
4113         cmdline_fixed_string_t cmd_keyword;
4114         cmdline_fixed_string_t cmd_flush;
4115         uint8_t cmd_cycles;
4116 };
4117
4118 static void
4119 cmd_gro_flush_parsed(void *parsed_result,
4120                 __attribute__((unused)) struct cmdline *cl,
4121                 __attribute__((unused)) void *data)
4122 {
4123         struct cmd_gro_flush_result *res;
4124
4125         res = parsed_result;
4126         if ((!strcmp(res->cmd_keyword, "gro")) &&
4127                         (!strcmp(res->cmd_flush, "flush")))
4128                 setup_gro_flush_cycles(res->cmd_cycles);
4129 }
4130
4131 cmdline_parse_token_string_t cmd_gro_flush_set =
4132         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4133                         cmd_set, "set");
4134 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4135         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4136                         cmd_keyword, "gro");
4137 cmdline_parse_token_string_t cmd_gro_flush_flush =
4138         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4139                         cmd_flush, "flush");
4140 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4141         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4142                         cmd_cycles, UINT8);
4143
4144 cmdline_parse_inst_t cmd_gro_flush = {
4145         .f = cmd_gro_flush_parsed,
4146         .data = NULL,
4147         .help_str = "set gro flush <cycles>",
4148         .tokens = {
4149                 (void *)&cmd_gro_flush_set,
4150                 (void *)&cmd_gro_flush_keyword,
4151                 (void *)&cmd_gro_flush_flush,
4152                 (void *)&cmd_gro_flush_cycles,
4153                 NULL,
4154         },
4155 };
4156
4157 /* *** ENABLE/DISABLE GSO *** */
4158 struct cmd_gso_enable_result {
4159         cmdline_fixed_string_t cmd_set;
4160         cmdline_fixed_string_t cmd_port;
4161         cmdline_fixed_string_t cmd_keyword;
4162         cmdline_fixed_string_t cmd_mode;
4163         portid_t cmd_pid;
4164 };
4165
4166 static void
4167 cmd_gso_enable_parsed(void *parsed_result,
4168                 __attribute__((unused)) struct cmdline *cl,
4169                 __attribute__((unused)) void *data)
4170 {
4171         struct cmd_gso_enable_result *res;
4172
4173         res = parsed_result;
4174         if (!strcmp(res->cmd_keyword, "gso"))
4175                 setup_gso(res->cmd_mode, res->cmd_pid);
4176 }
4177
4178 cmdline_parse_token_string_t cmd_gso_enable_set =
4179         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4180                         cmd_set, "set");
4181 cmdline_parse_token_string_t cmd_gso_enable_port =
4182         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4183                         cmd_port, "port");
4184 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4185         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4186                         cmd_keyword, "gso");
4187 cmdline_parse_token_string_t cmd_gso_enable_mode =
4188         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4189                         cmd_mode, "on#off");
4190 cmdline_parse_token_num_t cmd_gso_enable_pid =
4191         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4192                         cmd_pid, UINT16);
4193
4194 cmdline_parse_inst_t cmd_gso_enable = {
4195         .f = cmd_gso_enable_parsed,
4196         .data = NULL,
4197         .help_str = "set port <port_id> gso on|off",
4198         .tokens = {
4199                 (void *)&cmd_gso_enable_set,
4200                 (void *)&cmd_gso_enable_port,
4201                 (void *)&cmd_gso_enable_pid,
4202                 (void *)&cmd_gso_enable_keyword,
4203                 (void *)&cmd_gso_enable_mode,
4204                 NULL,
4205         },
4206 };
4207
4208 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4209 struct cmd_gso_size_result {
4210         cmdline_fixed_string_t cmd_set;
4211         cmdline_fixed_string_t cmd_keyword;
4212         cmdline_fixed_string_t cmd_segsz;
4213         uint16_t cmd_size;
4214 };
4215
4216 static void
4217 cmd_gso_size_parsed(void *parsed_result,
4218                        __attribute__((unused)) struct cmdline *cl,
4219                        __attribute__((unused)) void *data)
4220 {
4221         struct cmd_gso_size_result *res = parsed_result;
4222
4223         if (test_done == 0) {
4224                 printf("Before setting GSO segsz, please first"
4225                                 " stop fowarding\n");
4226                 return;
4227         }
4228
4229         if (!strcmp(res->cmd_keyword, "gso") &&
4230                         !strcmp(res->cmd_segsz, "segsz")) {
4231                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4232                         printf("gso_size should be larger than %zu."
4233                                         " Please input a legal value\n",
4234                                         RTE_GSO_SEG_SIZE_MIN);
4235                 else
4236                         gso_max_segment_size = res->cmd_size;
4237         }
4238 }
4239
4240 cmdline_parse_token_string_t cmd_gso_size_set =
4241         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4242                                 cmd_set, "set");
4243 cmdline_parse_token_string_t cmd_gso_size_keyword =
4244         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4245                                 cmd_keyword, "gso");
4246 cmdline_parse_token_string_t cmd_gso_size_segsz =
4247         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4248                                 cmd_segsz, "segsz");
4249 cmdline_parse_token_num_t cmd_gso_size_size =
4250         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4251                                 cmd_size, UINT16);
4252
4253 cmdline_parse_inst_t cmd_gso_size = {
4254         .f = cmd_gso_size_parsed,
4255         .data = NULL,
4256         .help_str = "set gso segsz <length>",
4257         .tokens = {
4258                 (void *)&cmd_gso_size_set,
4259                 (void *)&cmd_gso_size_keyword,
4260                 (void *)&cmd_gso_size_segsz,
4261                 (void *)&cmd_gso_size_size,
4262                 NULL,
4263         },
4264 };
4265
4266 /* *** SHOW GSO CONFIGURATION *** */
4267 struct cmd_gso_show_result {
4268         cmdline_fixed_string_t cmd_show;
4269         cmdline_fixed_string_t cmd_port;
4270         cmdline_fixed_string_t cmd_keyword;
4271         portid_t cmd_pid;
4272 };
4273
4274 static void
4275 cmd_gso_show_parsed(void *parsed_result,
4276                        __attribute__((unused)) struct cmdline *cl,
4277                        __attribute__((unused)) void *data)
4278 {
4279         struct cmd_gso_show_result *res = parsed_result;
4280
4281         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4282                 printf("invalid port id %u\n", res->cmd_pid);
4283                 return;
4284         }
4285         if (!strcmp(res->cmd_keyword, "gso")) {
4286                 if (gso_ports[res->cmd_pid].enable) {
4287                         printf("Max GSO'd packet size: %uB\n"
4288                                         "Supported GSO types: TCP/IPv4, "
4289                                         "VxLAN with inner TCP/IPv4 packet, "
4290                                         "GRE with inner TCP/IPv4  packet\n",
4291                                         gso_max_segment_size);
4292                 } else
4293                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4294         }
4295 }
4296
4297 cmdline_parse_token_string_t cmd_gso_show_show =
4298 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4299                 cmd_show, "show");
4300 cmdline_parse_token_string_t cmd_gso_show_port =
4301 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4302                 cmd_port, "port");
4303 cmdline_parse_token_string_t cmd_gso_show_keyword =
4304         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4305                                 cmd_keyword, "gso");
4306 cmdline_parse_token_num_t cmd_gso_show_pid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4308                                 cmd_pid, UINT16);
4309
4310 cmdline_parse_inst_t cmd_gso_show = {
4311         .f = cmd_gso_show_parsed,
4312         .data = NULL,
4313         .help_str = "show port <port_id> gso",
4314         .tokens = {
4315                 (void *)&cmd_gso_show_show,
4316                 (void *)&cmd_gso_show_port,
4317                 (void *)&cmd_gso_show_pid,
4318                 (void *)&cmd_gso_show_keyword,
4319                 NULL,
4320         },
4321 };
4322
4323 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4324 struct cmd_set_flush_rx {
4325         cmdline_fixed_string_t set;
4326         cmdline_fixed_string_t flush_rx;
4327         cmdline_fixed_string_t mode;
4328 };
4329
4330 static void
4331 cmd_set_flush_rx_parsed(void *parsed_result,
4332                 __attribute__((unused)) struct cmdline *cl,
4333                 __attribute__((unused)) void *data)
4334 {
4335         struct cmd_set_flush_rx *res = parsed_result;
4336         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4337 }
4338
4339 cmdline_parse_token_string_t cmd_setflushrx_set =
4340         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4341                         set, "set");
4342 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4343         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4344                         flush_rx, "flush_rx");
4345 cmdline_parse_token_string_t cmd_setflushrx_mode =
4346         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4347                         mode, "on#off");
4348
4349
4350 cmdline_parse_inst_t cmd_set_flush_rx = {
4351         .f = cmd_set_flush_rx_parsed,
4352         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4353         .data = NULL,
4354         .tokens = {
4355                 (void *)&cmd_setflushrx_set,
4356                 (void *)&cmd_setflushrx_flush_rx,
4357                 (void *)&cmd_setflushrx_mode,
4358                 NULL,
4359         },
4360 };
4361
4362 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4363 struct cmd_set_link_check {
4364         cmdline_fixed_string_t set;
4365         cmdline_fixed_string_t link_check;
4366         cmdline_fixed_string_t mode;
4367 };
4368
4369 static void
4370 cmd_set_link_check_parsed(void *parsed_result,
4371                 __attribute__((unused)) struct cmdline *cl,
4372                 __attribute__((unused)) void *data)
4373 {
4374         struct cmd_set_link_check *res = parsed_result;
4375         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4376 }
4377
4378 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4379         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4380                         set, "set");
4381 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4383                         link_check, "link_check");
4384 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4385         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4386                         mode, "on#off");
4387
4388
4389 cmdline_parse_inst_t cmd_set_link_check = {
4390         .f = cmd_set_link_check_parsed,
4391         .help_str = "set link_check on|off: Enable/Disable link status check "
4392                     "when starting/stopping a port",
4393         .data = NULL,
4394         .tokens = {
4395                 (void *)&cmd_setlinkcheck_set,
4396                 (void *)&cmd_setlinkcheck_link_check,
4397                 (void *)&cmd_setlinkcheck_mode,
4398                 NULL,
4399         },
4400 };
4401
4402 /* *** SET NIC BYPASS MODE *** */
4403 struct cmd_set_bypass_mode_result {
4404         cmdline_fixed_string_t set;
4405         cmdline_fixed_string_t bypass;
4406         cmdline_fixed_string_t mode;
4407         cmdline_fixed_string_t value;
4408         portid_t port_id;
4409 };
4410
4411 static void
4412 cmd_set_bypass_mode_parsed(void *parsed_result,
4413                 __attribute__((unused)) struct cmdline *cl,
4414                 __attribute__((unused)) void *data)
4415 {
4416         struct cmd_set_bypass_mode_result *res = parsed_result;
4417         portid_t port_id = res->port_id;
4418         int32_t rc = -EINVAL;
4419
4420 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4421         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4422
4423         if (!strcmp(res->value, "bypass"))
4424                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4425         else if (!strcmp(res->value, "isolate"))
4426                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4427         else
4428                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4429
4430         /* Set the bypass mode for the relevant port. */
4431         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4432 #endif
4433         if (rc != 0)
4434                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4435 }
4436
4437 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4438         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4439                         set, "set");
4440 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4441         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4442                         bypass, "bypass");
4443 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4444         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4445                         mode, "mode");
4446 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4447         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4448                         value, "normal#bypass#isolate");
4449 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4450         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4451                                 port_id, UINT16);
4452
4453 cmdline_parse_inst_t cmd_set_bypass_mode = {
4454         .f = cmd_set_bypass_mode_parsed,
4455         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4456                     "Set the NIC bypass mode for port_id",
4457         .data = NULL,
4458         .tokens = {
4459                 (void *)&cmd_setbypass_mode_set,
4460                 (void *)&cmd_setbypass_mode_bypass,
4461                 (void *)&cmd_setbypass_mode_mode,
4462                 (void *)&cmd_setbypass_mode_value,
4463                 (void *)&cmd_setbypass_mode_port,
4464                 NULL,
4465         },
4466 };
4467
4468 /* *** SET NIC BYPASS EVENT *** */
4469 struct cmd_set_bypass_event_result {
4470         cmdline_fixed_string_t set;
4471         cmdline_fixed_string_t bypass;
4472         cmdline_fixed_string_t event;
4473         cmdline_fixed_string_t event_value;
4474         cmdline_fixed_string_t mode;
4475         cmdline_fixed_string_t mode_value;
4476         portid_t port_id;
4477 };
4478
4479 static void
4480 cmd_set_bypass_event_parsed(void *parsed_result,
4481                 __attribute__((unused)) struct cmdline *cl,
4482                 __attribute__((unused)) void *data)
4483 {
4484         int32_t rc = -EINVAL;
4485         struct cmd_set_bypass_event_result *res = parsed_result;
4486         portid_t port_id = res->port_id;
4487
4488 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4489         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4490         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4491
4492         if (!strcmp(res->event_value, "timeout"))
4493                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4494         else if (!strcmp(res->event_value, "os_on"))
4495                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4496         else if (!strcmp(res->event_value, "os_off"))
4497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4498         else if (!strcmp(res->event_value, "power_on"))
4499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4500         else if (!strcmp(res->event_value, "power_off"))
4501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4502         else
4503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4504
4505         if (!strcmp(res->mode_value, "bypass"))
4506                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4507         else if (!strcmp(res->mode_value, "isolate"))
4508                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4509         else
4510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4511
4512         /* Set the watchdog timeout. */
4513         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4514
4515                 rc = -EINVAL;
4516                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4517                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4518                                                            bypass_timeout);
4519                 }
4520                 if (rc != 0) {
4521                         printf("Failed to set timeout value %u "
4522                         "for port %d, errto code: %d.\n",
4523                         bypass_timeout, port_id, rc);
4524                 }
4525         }
4526
4527         /* Set the bypass event to transition to bypass mode. */
4528         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4529                                               bypass_mode);
4530 #endif
4531
4532         if (rc != 0)
4533                 printf("\t Failed to set bypass event for port = %d.\n",
4534                        port_id);
4535 }
4536
4537 cmdline_parse_token_string_t cmd_setbypass_event_set =
4538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4539                         set, "set");
4540 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4542                         bypass, "bypass");
4543 cmdline_parse_token_string_t cmd_setbypass_event_event =
4544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4545                         event, "event");
4546 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4548                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4549 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4551                         mode, "mode");
4552 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4554                         mode_value, "normal#bypass#isolate");
4555 cmdline_parse_token_num_t cmd_setbypass_event_port =
4556         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4557                                 port_id, UINT16);
4558
4559 cmdline_parse_inst_t cmd_set_bypass_event = {
4560         .f = cmd_set_bypass_event_parsed,
4561         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4562                 "power_off mode normal|bypass|isolate <port_id>: "
4563                 "Set the NIC bypass event mode for port_id",
4564         .data = NULL,
4565         .tokens = {
4566                 (void *)&cmd_setbypass_event_set,
4567                 (void *)&cmd_setbypass_event_bypass,
4568                 (void *)&cmd_setbypass_event_event,
4569                 (void *)&cmd_setbypass_event_event_value,
4570                 (void *)&cmd_setbypass_event_mode,
4571                 (void *)&cmd_setbypass_event_mode_value,
4572                 (void *)&cmd_setbypass_event_port,
4573                 NULL,
4574         },
4575 };
4576
4577
4578 /* *** SET NIC BYPASS TIMEOUT *** */
4579 struct cmd_set_bypass_timeout_result {
4580         cmdline_fixed_string_t set;
4581         cmdline_fixed_string_t bypass;
4582         cmdline_fixed_string_t timeout;
4583         cmdline_fixed_string_t value;
4584 };
4585
4586 static void
4587 cmd_set_bypass_timeout_parsed(void *parsed_result,
4588                 __attribute__((unused)) struct cmdline *cl,
4589                 __attribute__((unused)) void *data)
4590 {
4591         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4592
4593 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4594         if (!strcmp(res->value, "1.5"))
4595                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4596         else if (!strcmp(res->value, "2"))
4597                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4598         else if (!strcmp(res->value, "3"))
4599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4600         else if (!strcmp(res->value, "4"))
4601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4602         else if (!strcmp(res->value, "8"))
4603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4604         else if (!strcmp(res->value, "16"))
4605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4606         else if (!strcmp(res->value, "32"))
4607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4608         else
4609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4610 #endif
4611 }
4612
4613 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4614         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4615                         set, "set");
4616 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4617         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4618                         bypass, "bypass");
4619 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4620         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4621                         timeout, "timeout");
4622 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4624                         value, "0#1.5#2#3#4#8#16#32");
4625
4626 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4627         .f = cmd_set_bypass_timeout_parsed,
4628         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4629                 "Set the NIC bypass watchdog timeout in seconds",
4630         .data = NULL,
4631         .tokens = {
4632                 (void *)&cmd_setbypass_timeout_set,
4633                 (void *)&cmd_setbypass_timeout_bypass,
4634                 (void *)&cmd_setbypass_timeout_timeout,
4635                 (void *)&cmd_setbypass_timeout_value,
4636                 NULL,
4637         },
4638 };
4639
4640 /* *** SHOW NIC BYPASS MODE *** */
4641 struct cmd_show_bypass_config_result {
4642         cmdline_fixed_string_t show;
4643         cmdline_fixed_string_t bypass;
4644         cmdline_fixed_string_t config;
4645         portid_t port_id;
4646 };
4647
4648 static void
4649 cmd_show_bypass_config_parsed(void *parsed_result,
4650                 __attribute__((unused)) struct cmdline *cl,
4651                 __attribute__((unused)) void *data)
4652 {
4653         struct cmd_show_bypass_config_result *res = parsed_result;
4654         portid_t port_id = res->port_id;
4655         int rc = -EINVAL;
4656 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4657         uint32_t event_mode;
4658         uint32_t bypass_mode;
4659         uint32_t timeout = bypass_timeout;
4660         int i;
4661
4662         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4663                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4664         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4665                 {"UNKNOWN", "normal", "bypass", "isolate"};
4666         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4667                 "NONE",
4668                 "OS/board on",
4669                 "power supply on",
4670                 "OS/board off",
4671                 "power supply off",
4672                 "timeout"};
4673         int num_events = (sizeof events) / (sizeof events[0]);
4674
4675         /* Display the bypass mode.*/
4676         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4677                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4678                 return;
4679         }
4680         else {
4681                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4682                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4683
4684                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4685         }
4686
4687         /* Display the bypass timeout.*/
4688         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4689                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4690
4691         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4692
4693         /* Display the bypass events and associated modes. */
4694         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4695
4696                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4697                         printf("\tFailed to get bypass mode for event = %s\n",
4698                                 events[i]);
4699                 } else {
4700                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4701                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4702
4703                         printf("\tbypass event: %-16s = %s\n", events[i],
4704                                 modes[event_mode]);
4705                 }
4706         }
4707 #endif
4708         if (rc != 0)
4709                 printf("\tFailed to get bypass configuration for port = %d\n",
4710                        port_id);
4711 }
4712
4713 cmdline_parse_token_string_t cmd_showbypass_config_show =
4714         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4715                         show, "show");
4716 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4717         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4718                         bypass, "bypass");
4719 cmdline_parse_token_string_t cmd_showbypass_config_config =
4720         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4721                         config, "config");
4722 cmdline_parse_token_num_t cmd_showbypass_config_port =
4723         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4724                                 port_id, UINT16);
4725
4726 cmdline_parse_inst_t cmd_show_bypass_config = {
4727         .f = cmd_show_bypass_config_parsed,
4728         .help_str = "show bypass config <port_id>: "
4729                     "Show the NIC bypass config for port_id",
4730         .data = NULL,
4731         .tokens = {
4732                 (void *)&cmd_showbypass_config_show,
4733                 (void *)&cmd_showbypass_config_bypass,
4734                 (void *)&cmd_showbypass_config_config,
4735                 (void *)&cmd_showbypass_config_port,
4736                 NULL,
4737         },
4738 };
4739
4740 #ifdef RTE_LIBRTE_PMD_BOND
4741 /* *** SET BONDING MODE *** */
4742 struct cmd_set_bonding_mode_result {
4743         cmdline_fixed_string_t set;
4744         cmdline_fixed_string_t bonding;
4745         cmdline_fixed_string_t mode;
4746         uint8_t value;
4747         portid_t port_id;
4748 };
4749
4750 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4751                 __attribute__((unused))  struct cmdline *cl,
4752                 __attribute__((unused)) void *data)
4753 {
4754         struct cmd_set_bonding_mode_result *res = parsed_result;
4755         portid_t port_id = res->port_id;
4756
4757         /* Set the bonding mode for the relevant port. */
4758         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4759                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4760 }
4761
4762 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4763 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4764                 set, "set");
4765 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4766 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4767                 bonding, "bonding");
4768 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4769 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4770                 mode, "mode");
4771 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4772 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4773                 value, UINT8);
4774 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4775 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4776                 port_id, UINT16);
4777
4778 cmdline_parse_inst_t cmd_set_bonding_mode = {
4779                 .f = cmd_set_bonding_mode_parsed,
4780                 .help_str = "set bonding mode <mode_value> <port_id>: "
4781                         "Set the bonding mode for port_id",
4782                 .data = NULL,
4783                 .tokens = {
4784                                 (void *) &cmd_setbonding_mode_set,
4785                                 (void *) &cmd_setbonding_mode_bonding,
4786                                 (void *) &cmd_setbonding_mode_mode,
4787                                 (void *) &cmd_setbonding_mode_value,
4788                                 (void *) &cmd_setbonding_mode_port,
4789                                 NULL
4790                 }
4791 };
4792
4793 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4794 struct cmd_set_bonding_lacp_dedicated_queues_result {
4795         cmdline_fixed_string_t set;
4796         cmdline_fixed_string_t bonding;
4797         cmdline_fixed_string_t lacp;
4798         cmdline_fixed_string_t dedicated_queues;
4799         portid_t port_id;
4800         cmdline_fixed_string_t mode;
4801 };
4802
4803 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4804                 __attribute__((unused))  struct cmdline *cl,
4805                 __attribute__((unused)) void *data)
4806 {
4807         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4808         portid_t port_id = res->port_id;
4809         struct rte_port *port;
4810
4811         port = &ports[port_id];
4812
4813         /** Check if the port is not started **/
4814         if (port->port_status != RTE_PORT_STOPPED) {
4815                 printf("Please stop port %d first\n", port_id);
4816                 return;
4817         }
4818
4819         if (!strcmp(res->mode, "enable")) {
4820                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4821                         printf("Dedicate queues for LACP control packets"
4822                                         " enabled\n");
4823                 else
4824                         printf("Enabling dedicate queues for LACP control "
4825                                         "packets on port %d failed\n", port_id);
4826         } else if (!strcmp(res->mode, "disable")) {
4827                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4828                         printf("Dedicated queues for LACP control packets "
4829                                         "disabled\n");
4830                 else
4831                         printf("Disabling dedicated queues for LACP control "
4832                                         "traffic on port %d failed\n", port_id);
4833         }
4834 }
4835
4836 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4837 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4838                 set, "set");
4839 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4840 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4841                 bonding, "bonding");
4842 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4843 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4844                 lacp, "lacp");
4845 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4847                 dedicated_queues, "dedicated_queues");
4848 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4849 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4850                 port_id, UINT16);
4851 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4853                 mode, "enable#disable");
4854
4855 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4856                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4857                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4858                         "enable|disable: "
4859                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4860                 .data = NULL,
4861                 .tokens = {
4862                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4863                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4864                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4865                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4866                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4867                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4868                         NULL
4869                 }
4870 };
4871
4872 /* *** SET BALANCE XMIT POLICY *** */
4873 struct cmd_set_bonding_balance_xmit_policy_result {
4874         cmdline_fixed_string_t set;
4875         cmdline_fixed_string_t bonding;
4876         cmdline_fixed_string_t balance_xmit_policy;
4877         portid_t port_id;
4878         cmdline_fixed_string_t policy;
4879 };
4880
4881 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4882                 __attribute__((unused))  struct cmdline *cl,
4883                 __attribute__((unused)) void *data)
4884 {
4885         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4886         portid_t port_id = res->port_id;
4887         uint8_t policy;
4888
4889         if (!strcmp(res->policy, "l2")) {
4890                 policy = BALANCE_XMIT_POLICY_LAYER2;
4891         } else if (!strcmp(res->policy, "l23")) {
4892                 policy = BALANCE_XMIT_POLICY_LAYER23;
4893         } else if (!strcmp(res->policy, "l34")) {
4894                 policy = BALANCE_XMIT_POLICY_LAYER34;
4895         } else {
4896                 printf("\t Invalid xmit policy selection");
4897                 return;
4898         }
4899
4900         /* Set the bonding mode for the relevant port. */
4901         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4902                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4903                                 port_id);
4904         }
4905 }
4906
4907 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4908 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4909                 set, "set");
4910 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4911 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4912                 bonding, "bonding");
4913 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4914 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4915                 balance_xmit_policy, "balance_xmit_policy");
4916 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4917 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4918                 port_id, UINT16);
4919 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4921                 policy, "l2#l23#l34");
4922
4923 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4924                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4925                 .help_str = "set bonding balance_xmit_policy <port_id> "
4926                         "l2|l23|l34: "
4927                         "Set the bonding balance_xmit_policy for port_id",
4928                 .data = NULL,
4929                 .tokens = {
4930                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4931                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4932                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4933                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4934                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4935                                 NULL
4936                 }
4937 };
4938
4939 /* *** SHOW NIC BONDING CONFIGURATION *** */
4940 struct cmd_show_bonding_config_result {
4941         cmdline_fixed_string_t show;
4942         cmdline_fixed_string_t bonding;
4943         cmdline_fixed_string_t config;
4944         portid_t port_id;
4945 };
4946
4947 static void cmd_show_bonding_config_parsed(void *parsed_result,
4948                 __attribute__((unused))  struct cmdline *cl,
4949                 __attribute__((unused)) void *data)
4950 {
4951         struct cmd_show_bonding_config_result *res = parsed_result;
4952         int bonding_mode, agg_mode;
4953         portid_t slaves[RTE_MAX_ETHPORTS];
4954         int num_slaves, num_active_slaves;
4955         int primary_id;
4956         int i;
4957         portid_t port_id = res->port_id;
4958
4959         /* Display the bonding mode.*/
4960         bonding_mode = rte_eth_bond_mode_get(port_id);
4961         if (bonding_mode < 0) {
4962                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4963                 return;
4964         } else
4965                 printf("\tBonding mode: %d\n", bonding_mode);
4966
4967         if (bonding_mode == BONDING_MODE_BALANCE) {
4968                 int balance_xmit_policy;
4969
4970                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4971                 if (balance_xmit_policy < 0) {
4972                         printf("\tFailed to get balance xmit policy for port = %d\n",
4973                                         port_id);
4974                         return;
4975                 } else {
4976                         printf("\tBalance Xmit Policy: ");
4977
4978                         switch (balance_xmit_policy) {
4979                         case BALANCE_XMIT_POLICY_LAYER2:
4980                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4981                                 break;
4982                         case BALANCE_XMIT_POLICY_LAYER23:
4983                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4984                                 break;
4985                         case BALANCE_XMIT_POLICY_LAYER34:
4986                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4987                                 break;
4988                         }
4989                         printf("\n");
4990                 }
4991         }
4992
4993         if (bonding_mode == BONDING_MODE_8023AD) {
4994                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4995                 printf("\tIEEE802.3AD Aggregator Mode: ");
4996                 switch (agg_mode) {
4997                 case AGG_BANDWIDTH:
4998                         printf("bandwidth");
4999                         break;
5000                 case AGG_STABLE:
5001                         printf("stable");
5002                         break;
5003                 case AGG_COUNT:
5004                         printf("count");
5005                         break;
5006                 }
5007                 printf("\n");
5008         }
5009
5010         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5011
5012         if (num_slaves < 0) {
5013                 printf("\tFailed to get slave list for port = %d\n", port_id);
5014                 return;
5015         }
5016         if (num_slaves > 0) {
5017                 printf("\tSlaves (%d): [", num_slaves);
5018                 for (i = 0; i < num_slaves - 1; i++)
5019                         printf("%d ", slaves[i]);
5020
5021                 printf("%d]\n", slaves[num_slaves - 1]);
5022         } else {
5023                 printf("\tSlaves: []\n");
5024
5025         }
5026
5027         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5028                         RTE_MAX_ETHPORTS);
5029
5030         if (num_active_slaves < 0) {
5031                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5032                 return;
5033         }
5034         if (num_active_slaves > 0) {
5035                 printf("\tActive Slaves (%d): [", num_active_slaves);
5036                 for (i = 0; i < num_active_slaves - 1; i++)
5037                         printf("%d ", slaves[i]);
5038
5039                 printf("%d]\n", slaves[num_active_slaves - 1]);
5040
5041         } else {
5042                 printf("\tActive Slaves: []\n");
5043
5044         }
5045
5046         primary_id = rte_eth_bond_primary_get(port_id);
5047         if (primary_id < 0) {
5048                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5049                 return;
5050         } else
5051                 printf("\tPrimary: [%d]\n", primary_id);
5052
5053 }
5054
5055 cmdline_parse_token_string_t cmd_showbonding_config_show =
5056 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5057                 show, "show");
5058 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5059 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5060                 bonding, "bonding");
5061 cmdline_parse_token_string_t cmd_showbonding_config_config =
5062 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5063                 config, "config");
5064 cmdline_parse_token_num_t cmd_showbonding_config_port =
5065 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5066                 port_id, UINT16);
5067
5068 cmdline_parse_inst_t cmd_show_bonding_config = {
5069                 .f = cmd_show_bonding_config_parsed,
5070                 .help_str = "show bonding config <port_id>: "
5071                         "Show the bonding config for port_id",
5072                 .data = NULL,
5073                 .tokens = {
5074                                 (void *)&cmd_showbonding_config_show,
5075                                 (void *)&cmd_showbonding_config_bonding,
5076                                 (void *)&cmd_showbonding_config_config,
5077                                 (void *)&cmd_showbonding_config_port,
5078                                 NULL
5079                 }
5080 };
5081
5082 /* *** SET BONDING PRIMARY *** */
5083 struct cmd_set_bonding_primary_result {
5084         cmdline_fixed_string_t set;
5085         cmdline_fixed_string_t bonding;
5086         cmdline_fixed_string_t primary;
5087         portid_t slave_id;
5088         portid_t port_id;
5089 };
5090
5091 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5092                 __attribute__((unused))  struct cmdline *cl,
5093                 __attribute__((unused)) void *data)
5094 {
5095         struct cmd_set_bonding_primary_result *res = parsed_result;
5096         portid_t master_port_id = res->port_id;
5097         portid_t slave_port_id = res->slave_id;
5098
5099         /* Set the primary slave for a bonded device. */
5100         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5101                 printf("\t Failed to set primary slave for port = %d.\n",
5102                                 master_port_id);
5103                 return;
5104         }
5105         init_port_config();
5106 }
5107
5108 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5109 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5110                 set, "set");
5111 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5112 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5113                 bonding, "bonding");
5114 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5115 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5116                 primary, "primary");
5117 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5118 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5119                 slave_id, UINT16);
5120 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5121 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5122                 port_id, UINT16);
5123
5124 cmdline_parse_inst_t cmd_set_bonding_primary = {
5125                 .f = cmd_set_bonding_primary_parsed,
5126                 .help_str = "set bonding primary <slave_id> <port_id>: "
5127                         "Set the primary slave for port_id",
5128                 .data = NULL,
5129                 .tokens = {
5130                                 (void *)&cmd_setbonding_primary_set,
5131                                 (void *)&cmd_setbonding_primary_bonding,
5132                                 (void *)&cmd_setbonding_primary_primary,
5133                                 (void *)&cmd_setbonding_primary_slave,
5134                                 (void *)&cmd_setbonding_primary_port,
5135                                 NULL
5136                 }
5137 };
5138
5139 /* *** ADD SLAVE *** */
5140 struct cmd_add_bonding_slave_result {
5141         cmdline_fixed_string_t add;
5142         cmdline_fixed_string_t bonding;
5143         cmdline_fixed_string_t slave;
5144         portid_t slave_id;
5145         portid_t port_id;
5146 };
5147
5148 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5149                 __attribute__((unused))  struct cmdline *cl,
5150                 __attribute__((unused)) void *data)
5151 {
5152         struct cmd_add_bonding_slave_result *res = parsed_result;
5153         portid_t master_port_id = res->port_id;
5154         portid_t slave_port_id = res->slave_id;
5155
5156         /* add the slave for a bonded device. */
5157         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5158                 printf("\t Failed to add slave %d to master port = %d.\n",
5159                                 slave_port_id, master_port_id);
5160                 return;
5161         }
5162         init_port_config();
5163         set_port_slave_flag(slave_port_id);
5164 }
5165
5166 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5167 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5168                 add, "add");
5169 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5170 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5171                 bonding, "bonding");
5172 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5173 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5174                 slave, "slave");
5175 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5176 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5177                 slave_id, UINT16);
5178 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5179 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5180                 port_id, UINT16);
5181
5182 cmdline_parse_inst_t cmd_add_bonding_slave = {
5183                 .f = cmd_add_bonding_slave_parsed,
5184                 .help_str = "add bonding slave <slave_id> <port_id>: "
5185                         "Add a slave device to a bonded device",
5186                 .data = NULL,
5187                 .tokens = {
5188                                 (void *)&cmd_addbonding_slave_add,
5189                                 (void *)&cmd_addbonding_slave_bonding,
5190                                 (void *)&cmd_addbonding_slave_slave,
5191                                 (void *)&cmd_addbonding_slave_slaveid,
5192                                 (void *)&cmd_addbonding_slave_port,
5193                                 NULL
5194                 }
5195 };
5196
5197 /* *** REMOVE SLAVE *** */
5198 struct cmd_remove_bonding_slave_result {
5199         cmdline_fixed_string_t remove;
5200         cmdline_fixed_string_t bonding;
5201         cmdline_fixed_string_t slave;
5202         portid_t slave_id;
5203         portid_t port_id;
5204 };
5205
5206 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5207                 __attribute__((unused))  struct cmdline *cl,
5208                 __attribute__((unused)) void *data)
5209 {
5210         struct cmd_remove_bonding_slave_result *res = parsed_result;
5211         portid_t master_port_id = res->port_id;
5212         portid_t slave_port_id = res->slave_id;
5213
5214         /* remove the slave from a bonded device. */
5215         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5216                 printf("\t Failed to remove slave %d from master port = %d.\n",
5217                                 slave_port_id, master_port_id);
5218                 return;
5219         }
5220         init_port_config();
5221         clear_port_slave_flag(slave_port_id);
5222 }
5223
5224 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5225                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5226                                 remove, "remove");
5227 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5228                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5229                                 bonding, "bonding");
5230 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5231                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5232                                 slave, "slave");
5233 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5234                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5235                                 slave_id, UINT16);
5236 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5237                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5238                                 port_id, UINT16);
5239
5240 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5241                 .f = cmd_remove_bonding_slave_parsed,
5242                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5243                         "Remove a slave device from a bonded device",
5244                 .data = NULL,
5245                 .tokens = {
5246                                 (void *)&cmd_removebonding_slave_remove,
5247                                 (void *)&cmd_removebonding_slave_bonding,
5248                                 (void *)&cmd_removebonding_slave_slave,
5249                                 (void *)&cmd_removebonding_slave_slaveid,
5250                                 (void *)&cmd_removebonding_slave_port,
5251                                 NULL
5252                 }
5253 };
5254
5255 /* *** CREATE BONDED DEVICE *** */
5256 struct cmd_create_bonded_device_result {
5257         cmdline_fixed_string_t create;
5258         cmdline_fixed_string_t bonded;
5259         cmdline_fixed_string_t device;
5260         uint8_t mode;
5261         uint8_t socket;
5262 };
5263
5264 static int bond_dev_num = 0;
5265
5266 static void cmd_create_bonded_device_parsed(void *parsed_result,
5267                 __attribute__((unused))  struct cmdline *cl,
5268                 __attribute__((unused)) void *data)
5269 {
5270         struct cmd_create_bonded_device_result *res = parsed_result;
5271         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5272         int port_id;
5273
5274         if (test_done == 0) {
5275                 printf("Please stop forwarding first\n");
5276                 return;
5277         }
5278
5279         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5280                         bond_dev_num++);
5281
5282         /* Create a new bonded device. */
5283         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5284         if (port_id < 0) {
5285                 printf("\t Failed to create bonded device.\n");
5286                 return;
5287         } else {
5288                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5289                                 port_id);
5290
5291                 /* Update number of ports */
5292                 nb_ports = rte_eth_dev_count();
5293                 reconfig(port_id, res->socket);
5294                 rte_eth_promiscuous_enable(port_id);
5295         }
5296
5297 }
5298
5299 cmdline_parse_token_string_t cmd_createbonded_device_create =
5300                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5301                                 create, "create");
5302 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5303                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5304                                 bonded, "bonded");
5305 cmdline_parse_token_string_t cmd_createbonded_device_device =
5306                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5307                                 device, "device");
5308 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5309                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5310                                 mode, UINT8);
5311 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5312                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5313                                 socket, UINT8);
5314
5315 cmdline_parse_inst_t cmd_create_bonded_device = {
5316                 .f = cmd_create_bonded_device_parsed,
5317                 .help_str = "create bonded device <mode> <socket>: "
5318                         "Create a new bonded device with specific bonding mode and socket",
5319                 .data = NULL,
5320                 .tokens = {
5321                                 (void *)&cmd_createbonded_device_create,
5322                                 (void *)&cmd_createbonded_device_bonded,
5323                                 (void *)&cmd_createbonded_device_device,
5324                                 (void *)&cmd_createbonded_device_mode,
5325                                 (void *)&cmd_createbonded_device_socket,
5326                                 NULL
5327                 }
5328 };
5329
5330 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5331 struct cmd_set_bond_mac_addr_result {
5332         cmdline_fixed_string_t set;
5333         cmdline_fixed_string_t bonding;
5334         cmdline_fixed_string_t mac_addr;
5335         uint16_t port_num;
5336         struct ether_addr address;
5337 };
5338
5339 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5340                 __attribute__((unused))  struct cmdline *cl,
5341                 __attribute__((unused)) void *data)
5342 {
5343         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5344         int ret;
5345
5346         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5347                 return;
5348
5349         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5350
5351         /* check the return value and print it if is < 0 */
5352         if (ret < 0)
5353                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5354 }
5355
5356 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5357                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5358 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5359                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5360                                 "bonding");
5361 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5362                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5363                                 "mac_addr");
5364 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5365                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5366                                 port_num, UINT16);
5367 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5368                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5369
5370 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5371                 .f = cmd_set_bond_mac_addr_parsed,
5372                 .data = (void *) 0,
5373                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5374                 .tokens = {
5375                                 (void *)&cmd_set_bond_mac_addr_set,
5376                                 (void *)&cmd_set_bond_mac_addr_bonding,
5377                                 (void *)&cmd_set_bond_mac_addr_mac,
5378                                 (void *)&cmd_set_bond_mac_addr_portnum,
5379                                 (void *)&cmd_set_bond_mac_addr_addr,
5380                                 NULL
5381                 }
5382 };
5383
5384
5385 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5386 struct cmd_set_bond_mon_period_result {
5387         cmdline_fixed_string_t set;
5388         cmdline_fixed_string_t bonding;
5389         cmdline_fixed_string_t mon_period;
5390         uint16_t port_num;
5391         uint32_t period_ms;
5392 };
5393
5394 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5395                 __attribute__((unused))  struct cmdline *cl,
5396                 __attribute__((unused)) void *data)
5397 {
5398         struct cmd_set_bond_mon_period_result *res = parsed_result;
5399         int ret;
5400
5401         if (res->port_num >= nb_ports) {
5402                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5403                 return;
5404         }
5405
5406         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5407
5408         /* check the return value and print it if is < 0 */
5409         if (ret < 0)
5410                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5411 }
5412
5413 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5414                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5415                                 set, "set");
5416 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5417                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5418                                 bonding, "bonding");
5419 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5420                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5421                                 mon_period,     "mon_period");
5422 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5423                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5424                                 port_num, UINT16);
5425 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5426                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5427                                 period_ms, UINT32);
5428
5429 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5430                 .f = cmd_set_bond_mon_period_parsed,
5431                 .data = (void *) 0,
5432                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5433                 .tokens = {
5434                                 (void *)&cmd_set_bond_mon_period_set,
5435                                 (void *)&cmd_set_bond_mon_period_bonding,
5436                                 (void *)&cmd_set_bond_mon_period_mon_period,
5437                                 (void *)&cmd_set_bond_mon_period_portnum,
5438                                 (void *)&cmd_set_bond_mon_period_period_ms,
5439                                 NULL
5440                 }
5441 };
5442
5443
5444
5445 struct cmd_set_bonding_agg_mode_policy_result {
5446         cmdline_fixed_string_t set;
5447         cmdline_fixed_string_t bonding;
5448         cmdline_fixed_string_t agg_mode;
5449         uint16_t port_num;
5450         cmdline_fixed_string_t policy;
5451 };
5452
5453
5454 static void
5455 cmd_set_bonding_agg_mode(void *parsed_result,
5456                 __attribute__((unused)) struct cmdline *cl,
5457                 __attribute__((unused)) void *data)
5458 {
5459         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5460         uint8_t policy = AGG_BANDWIDTH;
5461
5462         if (res->port_num >= nb_ports) {
5463                 printf("Port id %d must be less than %d\n",
5464                                 res->port_num, nb_ports);
5465                 return;
5466         }
5467
5468         if (!strcmp(res->policy, "bandwidth"))
5469                 policy = AGG_BANDWIDTH;
5470         else if (!strcmp(res->policy, "stable"))
5471                 policy = AGG_STABLE;
5472         else if (!strcmp(res->policy, "count"))
5473                 policy = AGG_COUNT;
5474
5475         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5476 }
5477
5478
5479 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5480         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5481                                 set, "set");
5482 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5483         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5484                                 bonding, "bonding");
5485
5486 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5488                                 agg_mode, "agg_mode");
5489
5490 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5491         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5492                                 port_num, UINT16);
5493
5494 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5495         TOKEN_STRING_INITIALIZER(
5496                         struct cmd_set_bonding_balance_xmit_policy_result,
5497                 policy, "stable#bandwidth#count");
5498
5499 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5500         .f = cmd_set_bonding_agg_mode,
5501         .data = (void *) 0,
5502         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5503         .tokens = {
5504                         (void *)&cmd_set_bonding_agg_mode_set,
5505                         (void *)&cmd_set_bonding_agg_mode_bonding,
5506                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5507                         (void *)&cmd_set_bonding_agg_mode_portnum,
5508                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5509                         NULL
5510                 }
5511 };
5512
5513
5514 #endif /* RTE_LIBRTE_PMD_BOND */
5515
5516 /* *** SET FORWARDING MODE *** */
5517 struct cmd_set_fwd_mode_result {
5518         cmdline_fixed_string_t set;
5519         cmdline_fixed_string_t fwd;
5520         cmdline_fixed_string_t mode;
5521 };
5522
5523 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5524                                     __attribute__((unused)) struct cmdline *cl,
5525                                     __attribute__((unused)) void *data)
5526 {
5527         struct cmd_set_fwd_mode_result *res = parsed_result;
5528
5529         retry_enabled = 0;
5530         set_pkt_forwarding_mode(res->mode);
5531 }
5532
5533 cmdline_parse_token_string_t cmd_setfwd_set =
5534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5535 cmdline_parse_token_string_t cmd_setfwd_fwd =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5537 cmdline_parse_token_string_t cmd_setfwd_mode =
5538         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5539                 "" /* defined at init */);
5540
5541 cmdline_parse_inst_t cmd_set_fwd_mode = {
5542         .f = cmd_set_fwd_mode_parsed,
5543         .data = NULL,
5544         .help_str = NULL, /* defined at init */
5545         .tokens = {
5546                 (void *)&cmd_setfwd_set,
5547                 (void *)&cmd_setfwd_fwd,
5548                 (void *)&cmd_setfwd_mode,
5549                 NULL,
5550         },
5551 };
5552
5553 static void cmd_set_fwd_mode_init(void)
5554 {
5555         char *modes, *c;
5556         static char token[128];
5557         static char help[256];
5558         cmdline_parse_token_string_t *token_struct;
5559
5560         modes = list_pkt_forwarding_modes();
5561         snprintf(help, sizeof(help), "set fwd %s: "
5562                 "Set packet forwarding mode", modes);
5563         cmd_set_fwd_mode.help_str = help;
5564
5565         /* string token separator is # */
5566         for (c = token; *modes != '\0'; modes++)
5567                 if (*modes == '|')
5568                         *c++ = '#';
5569                 else
5570                         *c++ = *modes;
5571         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5572         token_struct->string_data.str = token;
5573 }
5574
5575 /* *** SET RETRY FORWARDING MODE *** */
5576 struct cmd_set_fwd_retry_mode_result {
5577         cmdline_fixed_string_t set;
5578         cmdline_fixed_string_t fwd;
5579         cmdline_fixed_string_t mode;
5580         cmdline_fixed_string_t retry;
5581 };
5582
5583 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5584                             __attribute__((unused)) struct cmdline *cl,
5585                             __attribute__((unused)) void *data)
5586 {
5587         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5588
5589         retry_enabled = 1;
5590         set_pkt_forwarding_mode(res->mode);
5591 }
5592
5593 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5594         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5595                         set, "set");
5596 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5597         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5598                         fwd, "fwd");
5599 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5600         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5601                         mode,
5602                 "" /* defined at init */);
5603 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5605                         retry, "retry");
5606
5607 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5608         .f = cmd_set_fwd_retry_mode_parsed,
5609         .data = NULL,
5610         .help_str = NULL, /* defined at init */
5611         .tokens = {
5612                 (void *)&cmd_setfwd_retry_set,
5613                 (void *)&cmd_setfwd_retry_fwd,
5614                 (void *)&cmd_setfwd_retry_mode,
5615                 (void *)&cmd_setfwd_retry_retry,
5616                 NULL,
5617         },
5618 };
5619
5620 static void cmd_set_fwd_retry_mode_init(void)
5621 {
5622         char *modes, *c;
5623         static char token[128];
5624         static char help[256];
5625         cmdline_parse_token_string_t *token_struct;
5626
5627         modes = list_pkt_forwarding_retry_modes();
5628         snprintf(help, sizeof(help), "set fwd %s retry: "
5629                 "Set packet forwarding mode with retry", modes);
5630         cmd_set_fwd_retry_mode.help_str = help;
5631
5632         /* string token separator is # */
5633         for (c = token; *modes != '\0'; modes++)
5634                 if (*modes == '|')
5635                         *c++ = '#';
5636                 else
5637                         *c++ = *modes;
5638         token_struct = (cmdline_parse_token_string_t *)
5639                 cmd_set_fwd_retry_mode.tokens[2];
5640         token_struct->string_data.str = token;
5641 }
5642
5643 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5644 struct cmd_set_burst_tx_retry_result {
5645         cmdline_fixed_string_t set;
5646         cmdline_fixed_string_t burst;
5647         cmdline_fixed_string_t tx;
5648         cmdline_fixed_string_t delay;
5649         uint32_t time;
5650         cmdline_fixed_string_t retry;
5651         uint32_t retry_num;
5652 };
5653
5654 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5655                                         __attribute__((unused)) struct cmdline *cl,
5656                                         __attribute__((unused)) void *data)
5657 {
5658         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5659
5660         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5661                 && !strcmp(res->tx, "tx")) {
5662                 if (!strcmp(res->delay, "delay"))
5663                         burst_tx_delay_time = res->time;
5664                 if (!strcmp(res->retry, "retry"))
5665                         burst_tx_retry_num = res->retry_num;
5666         }
5667
5668 }
5669
5670 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5671         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5673         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5674                                  "burst");
5675 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5676         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5677 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5678         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5679 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5680         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5681 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5682         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5683 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5684         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5685
5686 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5687         .f = cmd_set_burst_tx_retry_parsed,
5688         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5689         .tokens = {
5690                 (void *)&cmd_set_burst_tx_retry_set,
5691                 (void *)&cmd_set_burst_tx_retry_burst,
5692                 (void *)&cmd_set_burst_tx_retry_tx,
5693                 (void *)&cmd_set_burst_tx_retry_delay,
5694                 (void *)&cmd_set_burst_tx_retry_time,
5695                 (void *)&cmd_set_burst_tx_retry_retry,
5696                 (void *)&cmd_set_burst_tx_retry_retry_num,
5697                 NULL,
5698         },
5699 };
5700
5701 /* *** SET PROMISC MODE *** */
5702 struct cmd_set_promisc_mode_result {
5703         cmdline_fixed_string_t set;
5704         cmdline_fixed_string_t promisc;
5705         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5706         uint16_t port_num;               /* valid if "allports" argument == 0 */
5707         cmdline_fixed_string_t mode;
5708 };
5709
5710 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5711                                         __attribute__((unused)) struct cmdline *cl,
5712                                         void *allports)
5713 {
5714         struct cmd_set_promisc_mode_result *res = parsed_result;
5715         int enable;
5716         portid_t i;
5717
5718         if (!strcmp(res->mode, "on"))
5719                 enable = 1;
5720         else
5721                 enable = 0;
5722
5723         /* all ports */
5724         if (allports) {
5725                 RTE_ETH_FOREACH_DEV(i) {
5726                         if (enable)
5727                                 rte_eth_promiscuous_enable(i);
5728                         else
5729                                 rte_eth_promiscuous_disable(i);
5730                 }
5731         }
5732         else {
5733                 if (enable)
5734                         rte_eth_promiscuous_enable(res->port_num);
5735                 else
5736                         rte_eth_promiscuous_disable(res->port_num);
5737         }
5738 }
5739
5740 cmdline_parse_token_string_t cmd_setpromisc_set =
5741         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5742 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5743         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5744                                  "promisc");
5745 cmdline_parse_token_string_t cmd_setpromisc_portall =
5746         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5747                                  "all");
5748 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5749         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5750                               UINT8);
5751 cmdline_parse_token_string_t cmd_setpromisc_mode =
5752         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5753                                  "on#off");
5754
5755 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5756         .f = cmd_set_promisc_mode_parsed,
5757         .data = (void *)1,
5758         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5759         .tokens = {
5760                 (void *)&cmd_setpromisc_set,
5761                 (void *)&cmd_setpromisc_promisc,
5762                 (void *)&cmd_setpromisc_portall,
5763                 (void *)&cmd_setpromisc_mode,
5764                 NULL,
5765         },
5766 };
5767
5768 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5769         .f = cmd_set_promisc_mode_parsed,
5770         .data = (void *)0,
5771         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5772         .tokens = {
5773                 (void *)&cmd_setpromisc_set,
5774                 (void *)&cmd_setpromisc_promisc,
5775                 (void *)&cmd_setpromisc_portnum,
5776                 (void *)&cmd_setpromisc_mode,
5777                 NULL,
5778         },
5779 };
5780
5781 /* *** SET ALLMULTI MODE *** */
5782 struct cmd_set_allmulti_mode_result {
5783         cmdline_fixed_string_t set;
5784         cmdline_fixed_string_t allmulti;
5785         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5786         uint16_t port_num;               /* valid if "allports" argument == 0 */
5787         cmdline_fixed_string_t mode;
5788 };
5789
5790 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5791                                         __attribute__((unused)) struct cmdline *cl,
5792                                         void *allports)
5793 {
5794         struct cmd_set_allmulti_mode_result *res = parsed_result;
5795         int enable;
5796         portid_t i;
5797
5798         if (!strcmp(res->mode, "on"))
5799                 enable = 1;
5800         else
5801                 enable = 0;
5802
5803         /* all ports */
5804         if (allports) {
5805                 RTE_ETH_FOREACH_DEV(i) {
5806                         if (enable)
5807                                 rte_eth_allmulticast_enable(i);
5808                         else
5809                                 rte_eth_allmulticast_disable(i);
5810                 }
5811         }
5812         else {
5813                 if (enable)
5814                         rte_eth_allmulticast_enable(res->port_num);
5815                 else
5816                         rte_eth_allmulticast_disable(res->port_num);
5817         }
5818 }
5819
5820 cmdline_parse_token_string_t cmd_setallmulti_set =
5821         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5822 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5823         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5824                                  "allmulti");
5825 cmdline_parse_token_string_t cmd_setallmulti_portall =
5826         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5827                                  "all");
5828 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5829         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5830                               UINT16);
5831 cmdline_parse_token_string_t cmd_setallmulti_mode =
5832         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5833                                  "on#off");
5834
5835 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5836         .f = cmd_set_allmulti_mode_parsed,
5837         .data = (void *)1,
5838         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5839         .tokens = {
5840                 (void *)&cmd_setallmulti_set,
5841                 (void *)&cmd_setallmulti_allmulti,
5842                 (void *)&cmd_setallmulti_portall,
5843                 (void *)&cmd_setallmulti_mode,
5844                 NULL,
5845         },
5846 };
5847
5848 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5849         .f = cmd_set_allmulti_mode_parsed,
5850         .data = (void *)0,
5851         .help_str = "set allmulti <port_id> on|off: "
5852                 "Set allmulti mode on port_id",
5853         .tokens = {
5854                 (void *)&cmd_setallmulti_set,
5855                 (void *)&cmd_setallmulti_allmulti,
5856                 (void *)&cmd_setallmulti_portnum,
5857                 (void *)&cmd_setallmulti_mode,
5858                 NULL,
5859         },
5860 };
5861
5862 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5863 struct cmd_link_flow_ctrl_set_result {
5864         cmdline_fixed_string_t set;
5865         cmdline_fixed_string_t flow_ctrl;
5866         cmdline_fixed_string_t rx;
5867         cmdline_fixed_string_t rx_lfc_mode;
5868         cmdline_fixed_string_t tx;
5869         cmdline_fixed_string_t tx_lfc_mode;
5870         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5871         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5872         cmdline_fixed_string_t autoneg_str;
5873         cmdline_fixed_string_t autoneg;
5874         cmdline_fixed_string_t hw_str;
5875         uint32_t high_water;
5876         cmdline_fixed_string_t lw_str;
5877         uint32_t low_water;
5878         cmdline_fixed_string_t pt_str;
5879         uint16_t pause_time;
5880         cmdline_fixed_string_t xon_str;
5881         uint16_t send_xon;
5882         portid_t port_id;
5883 };
5884
5885 cmdline_parse_token_string_t cmd_lfc_set_set =
5886         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5887                                 set, "set");
5888 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5889         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5890                                 flow_ctrl, "flow_ctrl");
5891 cmdline_parse_token_string_t cmd_lfc_set_rx =
5892         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5893                                 rx, "rx");
5894 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5895         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5896                                 rx_lfc_mode, "on#off");
5897 cmdline_parse_token_string_t cmd_lfc_set_tx =
5898         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5899                                 tx, "tx");
5900 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5901         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5902                                 tx_lfc_mode, "on#off");
5903 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5904         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5905                                 hw_str, "high_water");
5906 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5907         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5908                                 high_water, UINT32);
5909 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5911                                 lw_str, "low_water");
5912 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5913         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5914                                 low_water, UINT32);
5915 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5916         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5917                                 pt_str, "pause_time");
5918 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5919         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5920                                 pause_time, UINT16);
5921 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5922         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5923                                 xon_str, "send_xon");
5924 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5925         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5926                                 send_xon, UINT16);
5927 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5928         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5929                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5930 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5931         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5932                                 mac_ctrl_frame_fwd_mode, "on#off");
5933 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5934         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5935                                 autoneg_str, "autoneg");
5936 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5937         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5938                                 autoneg, "on#off");
5939 cmdline_parse_token_num_t cmd_lfc_set_portid =
5940         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5941                                 port_id, UINT16);
5942
5943 /* forward declaration */
5944 static void
5945 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5946                               void *data);
5947
5948 cmdline_parse_inst_t cmd_link_flow_control_set = {
5949         .f = cmd_link_flow_ctrl_set_parsed,
5950         .data = NULL,
5951         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5952                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5953                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5954         .tokens = {
5955                 (void *)&cmd_lfc_set_set,
5956                 (void *)&cmd_lfc_set_flow_ctrl,
5957                 (void *)&cmd_lfc_set_rx,
5958                 (void *)&cmd_lfc_set_rx_mode,
5959                 (void *)&cmd_lfc_set_tx,
5960                 (void *)&cmd_lfc_set_tx_mode,
5961                 (void *)&cmd_lfc_set_high_water,
5962                 (void *)&cmd_lfc_set_low_water,
5963                 (void *)&cmd_lfc_set_pause_time,
5964                 (void *)&cmd_lfc_set_send_xon,
5965                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5966                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5967                 (void *)&cmd_lfc_set_autoneg_str,
5968                 (void *)&cmd_lfc_set_autoneg,
5969                 (void *)&cmd_lfc_set_portid,
5970                 NULL,
5971         },
5972 };
5973
5974 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5975         .f = cmd_link_flow_ctrl_set_parsed,
5976         .data = (void *)&cmd_link_flow_control_set_rx,
5977         .help_str = "set flow_ctrl rx on|off <port_id>: "
5978                 "Change rx flow control parameter",
5979         .tokens = {
5980                 (void *)&cmd_lfc_set_set,
5981                 (void *)&cmd_lfc_set_flow_ctrl,
5982                 (void *)&cmd_lfc_set_rx,
5983                 (void *)&cmd_lfc_set_rx_mode,
5984                 (void *)&cmd_lfc_set_portid,
5985                 NULL,
5986         },
5987 };
5988
5989 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5990         .f = cmd_link_flow_ctrl_set_parsed,
5991         .data = (void *)&cmd_link_flow_control_set_tx,
5992         .help_str = "set flow_ctrl tx on|off <port_id>: "
5993                 "Change tx flow control parameter",
5994         .tokens = {
5995                 (void *)&cmd_lfc_set_set,
5996                 (void *)&cmd_lfc_set_flow_ctrl,
5997                 (void *)&cmd_lfc_set_tx,
5998                 (void *)&cmd_lfc_set_tx_mode,
5999                 (void *)&cmd_lfc_set_portid,
6000                 NULL,
6001         },
6002 };
6003
6004 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6005         .f = cmd_link_flow_ctrl_set_parsed,
6006         .data = (void *)&cmd_link_flow_control_set_hw,
6007         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6008                 "Change high water flow control parameter",
6009         .tokens = {
6010                 (void *)&cmd_lfc_set_set,
6011                 (void *)&cmd_lfc_set_flow_ctrl,
6012                 (void *)&cmd_lfc_set_high_water_str,
6013                 (void *)&cmd_lfc_set_high_water,
6014                 (void *)&cmd_lfc_set_portid,
6015                 NULL,
6016         },
6017 };
6018
6019 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6020         .f = cmd_link_flow_ctrl_set_parsed,
6021         .data = (void *)&cmd_link_flow_control_set_lw,
6022         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6023                 "Change low water flow control parameter",
6024         .tokens = {
6025                 (void *)&cmd_lfc_set_set,
6026                 (void *)&cmd_lfc_set_flow_ctrl,
6027                 (void *)&cmd_lfc_set_low_water_str,
6028                 (void *)&cmd_lfc_set_low_water,
6029                 (void *)&cmd_lfc_set_portid,
6030                 NULL,
6031         },
6032 };
6033
6034 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6035         .f = cmd_link_flow_ctrl_set_parsed,
6036         .data = (void *)&cmd_link_flow_control_set_pt,
6037         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6038                 "Change pause time flow control parameter",
6039         .tokens = {
6040                 (void *)&cmd_lfc_set_set,
6041                 (void *)&cmd_lfc_set_flow_ctrl,
6042                 (void *)&cmd_lfc_set_pause_time_str,
6043                 (void *)&cmd_lfc_set_pause_time,
6044                 (void *)&cmd_lfc_set_portid,
6045                 NULL,
6046         },
6047 };
6048
6049 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6050         .f = cmd_link_flow_ctrl_set_parsed,
6051         .data = (void *)&cmd_link_flow_control_set_xon,
6052         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6053                 "Change send_xon flow control parameter",
6054         .tokens = {
6055                 (void *)&cmd_lfc_set_set,
6056                 (void *)&cmd_lfc_set_flow_ctrl,
6057                 (void *)&cmd_lfc_set_send_xon_str,
6058                 (void *)&cmd_lfc_set_send_xon,
6059                 (void *)&cmd_lfc_set_portid,
6060                 NULL,
6061         },
6062 };
6063
6064 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6065         .f = cmd_link_flow_ctrl_set_parsed,
6066         .data = (void *)&cmd_link_flow_control_set_macfwd,
6067         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6068                 "Change mac ctrl fwd flow control parameter",
6069         .tokens = {
6070                 (void *)&cmd_lfc_set_set,
6071                 (void *)&cmd_lfc_set_flow_ctrl,
6072                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6073                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6074                 (void *)&cmd_lfc_set_portid,
6075                 NULL,
6076         },
6077 };
6078
6079 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6080         .f = cmd_link_flow_ctrl_set_parsed,
6081         .data = (void *)&cmd_link_flow_control_set_autoneg,
6082         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6083                 "Change autoneg flow control parameter",
6084         .tokens = {
6085                 (void *)&cmd_lfc_set_set,
6086                 (void *)&cmd_lfc_set_flow_ctrl,
6087                 (void *)&cmd_lfc_set_autoneg_str,
6088                 (void *)&cmd_lfc_set_autoneg,
6089                 (void *)&cmd_lfc_set_portid,
6090                 NULL,
6091         },
6092 };
6093
6094 static void
6095 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6096                               __attribute__((unused)) struct cmdline *cl,
6097                               void *data)
6098 {
6099         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6100         cmdline_parse_inst_t *cmd = data;
6101         struct rte_eth_fc_conf fc_conf;
6102         int rx_fc_en = 0;
6103         int tx_fc_en = 0;
6104         int ret;
6105
6106         /*
6107          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6108          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6109          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6110          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6111          */
6112         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6113                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6114         };
6115
6116         /* Partial command line, retrieve current configuration */
6117         if (cmd) {
6118                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6119                 if (ret != 0) {
6120                         printf("cannot get current flow ctrl parameters, return"
6121                                "code = %d\n", ret);
6122                         return;
6123                 }
6124
6125                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6126                     (fc_conf.mode == RTE_FC_FULL))
6127                         rx_fc_en = 1;
6128                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6129                     (fc_conf.mode == RTE_FC_FULL))
6130                         tx_fc_en = 1;
6131         }
6132
6133         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6134                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6135
6136         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6137                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6138
6139         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6140
6141         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6142                 fc_conf.high_water = res->high_water;
6143
6144         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6145                 fc_conf.low_water = res->low_water;
6146
6147         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6148                 fc_conf.pause_time = res->pause_time;
6149
6150         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6151                 fc_conf.send_xon = res->send_xon;
6152
6153         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6154                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6155                         fc_conf.mac_ctrl_frame_fwd = 1;
6156                 else
6157                         fc_conf.mac_ctrl_frame_fwd = 0;
6158         }
6159
6160         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6161                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6162
6163         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6164         if (ret != 0)
6165                 printf("bad flow contrl parameter, return code = %d \n", ret);
6166 }
6167
6168 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6169 struct cmd_priority_flow_ctrl_set_result {
6170         cmdline_fixed_string_t set;
6171         cmdline_fixed_string_t pfc_ctrl;
6172         cmdline_fixed_string_t rx;
6173         cmdline_fixed_string_t rx_pfc_mode;
6174         cmdline_fixed_string_t tx;
6175         cmdline_fixed_string_t tx_pfc_mode;
6176         uint32_t high_water;
6177         uint32_t low_water;
6178         uint16_t pause_time;
6179         uint8_t  priority;
6180         portid_t port_id;
6181 };
6182
6183 static void
6184 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6185                        __attribute__((unused)) struct cmdline *cl,
6186                        __attribute__((unused)) void *data)
6187 {
6188         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6189         struct rte_eth_pfc_conf pfc_conf;
6190         int rx_fc_enable, tx_fc_enable;
6191         int ret;
6192
6193         /*
6194          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6195          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6196          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6197          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6198          */
6199         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6200                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6201         };
6202
6203         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6204         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6205         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6206         pfc_conf.fc.high_water = res->high_water;
6207         pfc_conf.fc.low_water  = res->low_water;
6208         pfc_conf.fc.pause_time = res->pause_time;
6209         pfc_conf.priority      = res->priority;
6210
6211         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6212         if (ret != 0)
6213                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6214 }
6215
6216 cmdline_parse_token_string_t cmd_pfc_set_set =
6217         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6218                                 set, "set");
6219 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6220         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6221                                 pfc_ctrl, "pfc_ctrl");
6222 cmdline_parse_token_string_t cmd_pfc_set_rx =
6223         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6224                                 rx, "rx");
6225 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6226         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6227                                 rx_pfc_mode, "on#off");
6228 cmdline_parse_token_string_t cmd_pfc_set_tx =
6229         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6230                                 tx, "tx");
6231 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6232         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6233                                 tx_pfc_mode, "on#off");
6234 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6235         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6236                                 high_water, UINT32);
6237 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6238         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6239                                 low_water, UINT32);
6240 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6241         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6242                                 pause_time, UINT16);
6243 cmdline_parse_token_num_t cmd_pfc_set_priority =
6244         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6245                                 priority, UINT8);
6246 cmdline_parse_token_num_t cmd_pfc_set_portid =
6247         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6248                                 port_id, UINT16);
6249
6250 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6251         .f = cmd_priority_flow_ctrl_set_parsed,
6252         .data = NULL,
6253         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6254                 "<pause_time> <priority> <port_id>: "
6255                 "Configure the Ethernet priority flow control",
6256         .tokens = {
6257                 (void *)&cmd_pfc_set_set,
6258                 (void *)&cmd_pfc_set_flow_ctrl,
6259                 (void *)&cmd_pfc_set_rx,
6260                 (void *)&cmd_pfc_set_rx_mode,
6261                 (void *)&cmd_pfc_set_tx,
6262                 (void *)&cmd_pfc_set_tx_mode,
6263                 (void *)&cmd_pfc_set_high_water,
6264                 (void *)&cmd_pfc_set_low_water,
6265                 (void *)&cmd_pfc_set_pause_time,
6266                 (void *)&cmd_pfc_set_priority,
6267                 (void *)&cmd_pfc_set_portid,
6268                 NULL,
6269         },
6270 };
6271
6272 /* *** RESET CONFIGURATION *** */
6273 struct cmd_reset_result {
6274         cmdline_fixed_string_t reset;
6275         cmdline_fixed_string_t def;
6276 };
6277
6278 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6279                              struct cmdline *cl,
6280                              __attribute__((unused)) void *data)
6281 {
6282         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6283         set_def_fwd_config();
6284 }
6285
6286 cmdline_parse_token_string_t cmd_reset_set =
6287         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6288 cmdline_parse_token_string_t cmd_reset_def =
6289         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6290                                  "default");
6291
6292 cmdline_parse_inst_t cmd_reset = {
6293         .f = cmd_reset_parsed,
6294         .data = NULL,
6295         .help_str = "set default: Reset default forwarding configuration",
6296         .tokens = {
6297                 (void *)&cmd_reset_set,
6298                 (void *)&cmd_reset_def,
6299                 NULL,
6300         },
6301 };
6302
6303 /* *** START FORWARDING *** */
6304 struct cmd_start_result {
6305         cmdline_fixed_string_t start;
6306 };
6307
6308 cmdline_parse_token_string_t cmd_start_start =
6309         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6310
6311 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6312                              __attribute__((unused)) struct cmdline *cl,
6313                              __attribute__((unused)) void *data)
6314 {
6315         start_packet_forwarding(0);
6316 }
6317
6318 cmdline_parse_inst_t cmd_start = {
6319         .f = cmd_start_parsed,
6320         .data = NULL,
6321         .help_str = "start: Start packet forwarding",
6322         .tokens = {
6323                 (void *)&cmd_start_start,
6324                 NULL,
6325         },
6326 };
6327
6328 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6329 struct cmd_start_tx_first_result {
6330         cmdline_fixed_string_t start;
6331         cmdline_fixed_string_t tx_first;
6332 };
6333
6334 static void
6335 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6336                           __attribute__((unused)) struct cmdline *cl,
6337                           __attribute__((unused)) void *data)
6338 {
6339         start_packet_forwarding(1);
6340 }
6341
6342 cmdline_parse_token_string_t cmd_start_tx_first_start =
6343         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6344                                  "start");
6345 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6346         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6347                                  tx_first, "tx_first");
6348
6349 cmdline_parse_inst_t cmd_start_tx_first = {
6350         .f = cmd_start_tx_first_parsed,
6351         .data = NULL,
6352         .help_str = "start tx_first: Start packet forwarding, "
6353                 "after sending 1 burst of packets",
6354         .tokens = {
6355                 (void *)&cmd_start_tx_first_start,
6356                 (void *)&cmd_start_tx_first_tx_first,
6357                 NULL,
6358         },
6359 };
6360
6361 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6362 struct cmd_start_tx_first_n_result {
6363         cmdline_fixed_string_t start;
6364         cmdline_fixed_string_t tx_first;
6365         uint32_t tx_num;
6366 };
6367
6368 static void
6369 cmd_start_tx_first_n_parsed(void *parsed_result,
6370                           __attribute__((unused)) struct cmdline *cl,
6371                           __attribute__((unused)) void *data)
6372 {
6373         struct cmd_start_tx_first_n_result *res = parsed_result;
6374
6375         start_packet_forwarding(res->tx_num);
6376 }
6377
6378 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6379         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6380                         start, "start");
6381 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6382         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6383                         tx_first, "tx_first");
6384 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6385         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6386                         tx_num, UINT32);
6387
6388 cmdline_parse_inst_t cmd_start_tx_first_n = {
6389         .f = cmd_start_tx_first_n_parsed,
6390         .data = NULL,
6391         .help_str = "start tx_first <num>: "
6392                 "packet forwarding, after sending <num> bursts of packets",
6393         .tokens = {
6394                 (void *)&cmd_start_tx_first_n_start,
6395                 (void *)&cmd_start_tx_first_n_tx_first,
6396                 (void *)&cmd_start_tx_first_n_tx_num,
6397                 NULL,
6398         },
6399 };
6400
6401 /* *** SET LINK UP *** */
6402 struct cmd_set_link_up_result {
6403         cmdline_fixed_string_t set;
6404         cmdline_fixed_string_t link_up;
6405         cmdline_fixed_string_t port;
6406         portid_t port_id;
6407 };
6408
6409 cmdline_parse_token_string_t cmd_set_link_up_set =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6411 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6413                                 "link-up");
6414 cmdline_parse_token_string_t cmd_set_link_up_port =
6415         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6416 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6417         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6418
6419 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6420                              __attribute__((unused)) struct cmdline *cl,
6421                              __attribute__((unused)) void *data)
6422 {
6423         struct cmd_set_link_up_result *res = parsed_result;
6424         dev_set_link_up(res->port_id);
6425 }
6426
6427 cmdline_parse_inst_t cmd_set_link_up = {
6428         .f = cmd_set_link_up_parsed,
6429         .data = NULL,
6430         .help_str = "set link-up port <port id>",
6431         .tokens = {
6432                 (void *)&cmd_set_link_up_set,
6433                 (void *)&cmd_set_link_up_link_up,
6434                 (void *)&cmd_set_link_up_port,
6435                 (void *)&cmd_set_link_up_port_id,
6436                 NULL,
6437         },
6438 };
6439
6440 /* *** SET LINK DOWN *** */
6441 struct cmd_set_link_down_result {
6442         cmdline_fixed_string_t set;
6443         cmdline_fixed_string_t link_down;
6444         cmdline_fixed_string_t port;
6445         portid_t port_id;
6446 };
6447
6448 cmdline_parse_token_string_t cmd_set_link_down_set =
6449         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6450 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6452                                 "link-down");
6453 cmdline_parse_token_string_t cmd_set_link_down_port =
6454         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6455 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6456         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6457
6458 static void cmd_set_link_down_parsed(
6459                                 __attribute__((unused)) void *parsed_result,
6460                                 __attribute__((unused)) struct cmdline *cl,
6461                                 __attribute__((unused)) void *data)
6462 {
6463         struct cmd_set_link_down_result *res = parsed_result;
6464         dev_set_link_down(res->port_id);
6465 }
6466
6467 cmdline_parse_inst_t cmd_set_link_down = {
6468         .f = cmd_set_link_down_parsed,
6469         .data = NULL,
6470         .help_str = "set link-down port <port id>",
6471         .tokens = {
6472                 (void *)&cmd_set_link_down_set,
6473                 (void *)&cmd_set_link_down_link_down,
6474                 (void *)&cmd_set_link_down_port,
6475                 (void *)&cmd_set_link_down_port_id,
6476                 NULL,
6477         },
6478 };
6479
6480 /* *** SHOW CFG *** */
6481 struct cmd_showcfg_result {
6482         cmdline_fixed_string_t show;
6483         cmdline_fixed_string_t cfg;
6484         cmdline_fixed_string_t what;
6485 };
6486
6487 static void cmd_showcfg_parsed(void *parsed_result,
6488                                __attribute__((unused)) struct cmdline *cl,
6489                                __attribute__((unused)) void *data)
6490 {
6491         struct cmd_showcfg_result *res = parsed_result;
6492         if (!strcmp(res->what, "rxtx"))
6493                 rxtx_config_display();
6494         else if (!strcmp(res->what, "cores"))
6495                 fwd_lcores_config_display();
6496         else if (!strcmp(res->what, "fwd"))
6497                 pkt_fwd_config_display(&cur_fwd_config);
6498         else if (!strcmp(res->what, "txpkts"))
6499                 show_tx_pkt_segments();
6500 }
6501
6502 cmdline_parse_token_string_t cmd_showcfg_show =
6503         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6504 cmdline_parse_token_string_t cmd_showcfg_port =
6505         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6506 cmdline_parse_token_string_t cmd_showcfg_what =
6507         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6508                                  "rxtx#cores#fwd#txpkts");
6509
6510 cmdline_parse_inst_t cmd_showcfg = {
6511         .f = cmd_showcfg_parsed,
6512         .data = NULL,
6513         .help_str = "show config rxtx|cores|fwd|txpkts",
6514         .tokens = {
6515                 (void *)&cmd_showcfg_show,
6516                 (void *)&cmd_showcfg_port,
6517                 (void *)&cmd_showcfg_what,
6518                 NULL,
6519         },
6520 };
6521
6522 /* *** SHOW ALL PORT INFO *** */
6523 struct cmd_showportall_result {
6524         cmdline_fixed_string_t show;
6525         cmdline_fixed_string_t port;
6526         cmdline_fixed_string_t what;
6527         cmdline_fixed_string_t all;
6528 };
6529
6530 static void cmd_showportall_parsed(void *parsed_result,
6531                                 __attribute__((unused)) struct cmdline *cl,
6532                                 __attribute__((unused)) void *data)
6533 {
6534         portid_t i;
6535
6536         struct cmd_showportall_result *res = parsed_result;
6537         if (!strcmp(res->show, "clear")) {
6538                 if (!strcmp(res->what, "stats"))
6539                         RTE_ETH_FOREACH_DEV(i)
6540                                 nic_stats_clear(i);
6541                 else if (!strcmp(res->what, "xstats"))
6542                         RTE_ETH_FOREACH_DEV(i)
6543                                 nic_xstats_clear(i);
6544         } else if (!strcmp(res->what, "info"))
6545                 RTE_ETH_FOREACH_DEV(i)
6546                         port_infos_display(i);
6547         else if (!strcmp(res->what, "stats"))
6548                 RTE_ETH_FOREACH_DEV(i)
6549                         nic_stats_display(i);
6550         else if (!strcmp(res->what, "xstats"))
6551                 RTE_ETH_FOREACH_DEV(i)
6552                         nic_xstats_display(i);
6553         else if (!strcmp(res->what, "fdir"))
6554                 RTE_ETH_FOREACH_DEV(i)
6555                         fdir_get_infos(i);
6556         else if (!strcmp(res->what, "stat_qmap"))
6557                 RTE_ETH_FOREACH_DEV(i)
6558                         nic_stats_mapping_display(i);
6559         else if (!strcmp(res->what, "dcb_tc"))
6560                 RTE_ETH_FOREACH_DEV(i)
6561                         port_dcb_info_display(i);
6562         else if (!strcmp(res->what, "cap"))
6563                 RTE_ETH_FOREACH_DEV(i)
6564                         port_offload_cap_display(i);
6565 }
6566
6567 cmdline_parse_token_string_t cmd_showportall_show =
6568         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6569                                  "show#clear");
6570 cmdline_parse_token_string_t cmd_showportall_port =
6571         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6572 cmdline_parse_token_string_t cmd_showportall_what =
6573         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6574                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6575 cmdline_parse_token_string_t cmd_showportall_all =
6576         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6577 cmdline_parse_inst_t cmd_showportall = {
6578         .f = cmd_showportall_parsed,
6579         .data = NULL,
6580         .help_str = "show|clear port "
6581                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6582         .tokens = {
6583                 (void *)&cmd_showportall_show,
6584                 (void *)&cmd_showportall_port,
6585                 (void *)&cmd_showportall_what,
6586                 (void *)&cmd_showportall_all,
6587                 NULL,
6588         },
6589 };
6590
6591 /* *** SHOW PORT INFO *** */
6592 struct cmd_showport_result {
6593         cmdline_fixed_string_t show;
6594         cmdline_fixed_string_t port;
6595         cmdline_fixed_string_t what;
6596         uint16_t portnum;
6597 };
6598
6599 static void cmd_showport_parsed(void *parsed_result,
6600                                 __attribute__((unused)) struct cmdline *cl,
6601                                 __attribute__((unused)) void *data)
6602 {
6603         struct cmd_showport_result *res = parsed_result;
6604         if (!strcmp(res->show, "clear")) {
6605                 if (!strcmp(res->what, "stats"))
6606                         nic_stats_clear(res->portnum);
6607                 else if (!strcmp(res->what, "xstats"))
6608                         nic_xstats_clear(res->portnum);
6609         } else if (!strcmp(res->what, "info"))
6610                 port_infos_display(res->portnum);
6611         else if (!strcmp(res->what, "stats"))
6612                 nic_stats_display(res->portnum);
6613         else if (!strcmp(res->what, "xstats"))
6614                 nic_xstats_display(res->portnum);
6615         else if (!strcmp(res->what, "fdir"))
6616                  fdir_get_infos(res->portnum);
6617         else if (!strcmp(res->what, "stat_qmap"))
6618                 nic_stats_mapping_display(res->portnum);
6619         else if (!strcmp(res->what, "dcb_tc"))
6620                 port_dcb_info_display(res->portnum);
6621         else if (!strcmp(res->what, "cap"))
6622                 port_offload_cap_display(res->portnum);
6623 }
6624
6625 cmdline_parse_token_string_t cmd_showport_show =
6626         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6627                                  "show#clear");
6628 cmdline_parse_token_string_t cmd_showport_port =
6629         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6630 cmdline_parse_token_string_t cmd_showport_what =
6631         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6632                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6633 cmdline_parse_token_num_t cmd_showport_portnum =
6634         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6635
6636 cmdline_parse_inst_t cmd_showport = {
6637         .f = cmd_showport_parsed,
6638         .data = NULL,
6639         .help_str = "show|clear port "
6640                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6641                 "<port_id>",
6642         .tokens = {
6643                 (void *)&cmd_showport_show,
6644                 (void *)&cmd_showport_port,
6645                 (void *)&cmd_showport_what,
6646                 (void *)&cmd_showport_portnum,
6647                 NULL,
6648         },
6649 };
6650
6651 /* *** SHOW QUEUE INFO *** */
6652 struct cmd_showqueue_result {
6653         cmdline_fixed_string_t show;
6654         cmdline_fixed_string_t type;
6655         cmdline_fixed_string_t what;
6656         uint16_t portnum;
6657         uint16_t queuenum;
6658 };
6659
6660 static void
6661 cmd_showqueue_parsed(void *parsed_result,
6662         __attribute__((unused)) struct cmdline *cl,
6663         __attribute__((unused)) void *data)
6664 {
6665         struct cmd_showqueue_result *res = parsed_result;
6666
6667         if (!strcmp(res->type, "rxq"))
6668                 rx_queue_infos_display(res->portnum, res->queuenum);
6669         else if (!strcmp(res->type, "txq"))
6670                 tx_queue_infos_display(res->portnum, res->queuenum);
6671 }
6672
6673 cmdline_parse_token_string_t cmd_showqueue_show =
6674         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6675 cmdline_parse_token_string_t cmd_showqueue_type =
6676         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6677 cmdline_parse_token_string_t cmd_showqueue_what =
6678         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6679 cmdline_parse_token_num_t cmd_showqueue_portnum =
6680         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6681 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6682         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6683
6684 cmdline_parse_inst_t cmd_showqueue = {
6685         .f = cmd_showqueue_parsed,
6686         .data = NULL,
6687         .help_str = "show rxq|txq info <port_id> <queue_id>",
6688         .tokens = {
6689                 (void *)&cmd_showqueue_show,
6690                 (void *)&cmd_showqueue_type,
6691                 (void *)&cmd_showqueue_what,
6692                 (void *)&cmd_showqueue_portnum,
6693                 (void *)&cmd_showqueue_queuenum,
6694                 NULL,
6695         },
6696 };
6697
6698 /* *** READ PORT REGISTER *** */
6699 struct cmd_read_reg_result {
6700         cmdline_fixed_string_t read;
6701         cmdline_fixed_string_t reg;
6702         portid_t port_id;
6703         uint32_t reg_off;
6704 };
6705
6706 static void
6707 cmd_read_reg_parsed(void *parsed_result,
6708                     __attribute__((unused)) struct cmdline *cl,
6709                     __attribute__((unused)) void *data)
6710 {
6711         struct cmd_read_reg_result *res = parsed_result;
6712         port_reg_display(res->port_id, res->reg_off);
6713 }
6714
6715 cmdline_parse_token_string_t cmd_read_reg_read =
6716         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6717 cmdline_parse_token_string_t cmd_read_reg_reg =
6718         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6719 cmdline_parse_token_num_t cmd_read_reg_port_id =
6720         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6721 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6722         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6723
6724 cmdline_parse_inst_t cmd_read_reg = {
6725         .f = cmd_read_reg_parsed,
6726         .data = NULL,
6727         .help_str = "read reg <port_id> <reg_off>",
6728         .tokens = {
6729                 (void *)&cmd_read_reg_read,
6730                 (void *)&cmd_read_reg_reg,
6731                 (void *)&cmd_read_reg_port_id,
6732                 (void *)&cmd_read_reg_reg_off,
6733                 NULL,
6734         },
6735 };
6736
6737 /* *** READ PORT REGISTER BIT FIELD *** */
6738 struct cmd_read_reg_bit_field_result {
6739         cmdline_fixed_string_t read;
6740         cmdline_fixed_string_t regfield;
6741         portid_t port_id;
6742         uint32_t reg_off;
6743         uint8_t bit1_pos;
6744         uint8_t bit2_pos;
6745 };
6746
6747 static void
6748 cmd_read_reg_bit_field_parsed(void *parsed_result,
6749                               __attribute__((unused)) struct cmdline *cl,
6750                               __attribute__((unused)) void *data)
6751 {
6752         struct cmd_read_reg_bit_field_result *res = parsed_result;
6753         port_reg_bit_field_display(res->port_id, res->reg_off,
6754                                    res->bit1_pos, res->bit2_pos);
6755 }
6756
6757 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6758         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6759                                  "read");
6760 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6761         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6762                                  regfield, "regfield");
6763 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6764         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6765                               UINT16);
6766 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6767         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6768                               UINT32);
6769 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6770         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6771                               UINT8);
6772 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6773         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6774                               UINT8);
6775
6776 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6777         .f = cmd_read_reg_bit_field_parsed,
6778         .data = NULL,
6779         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6780         "Read register bit field between bit_x and bit_y included",
6781         .tokens = {
6782                 (void *)&cmd_read_reg_bit_field_read,
6783                 (void *)&cmd_read_reg_bit_field_regfield,
6784                 (void *)&cmd_read_reg_bit_field_port_id,
6785                 (void *)&cmd_read_reg_bit_field_reg_off,
6786                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6787                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6788                 NULL,
6789         },
6790 };
6791
6792 /* *** READ PORT REGISTER BIT *** */
6793 struct cmd_read_reg_bit_result {
6794         cmdline_fixed_string_t read;
6795         cmdline_fixed_string_t regbit;
6796         portid_t port_id;
6797         uint32_t reg_off;
6798         uint8_t bit_pos;
6799 };
6800
6801 static void
6802 cmd_read_reg_bit_parsed(void *parsed_result,
6803                         __attribute__((unused)) struct cmdline *cl,
6804                         __attribute__((unused)) void *data)
6805 {
6806         struct cmd_read_reg_bit_result *res = parsed_result;
6807         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6808 }
6809
6810 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6811         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6812 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6813         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6814                                  regbit, "regbit");
6815 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6816         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6817 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6818         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6819 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6820         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6821
6822 cmdline_parse_inst_t cmd_read_reg_bit = {
6823         .f = cmd_read_reg_bit_parsed,
6824         .data = NULL,
6825         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6826         .tokens = {
6827                 (void *)&cmd_read_reg_bit_read,
6828                 (void *)&cmd_read_reg_bit_regbit,
6829                 (void *)&cmd_read_reg_bit_port_id,
6830                 (void *)&cmd_read_reg_bit_reg_off,
6831                 (void *)&cmd_read_reg_bit_bit_pos,
6832                 NULL,
6833         },
6834 };
6835
6836 /* *** WRITE PORT REGISTER *** */
6837 struct cmd_write_reg_result {
6838         cmdline_fixed_string_t write;
6839         cmdline_fixed_string_t reg;
6840         portid_t port_id;
6841         uint32_t reg_off;
6842         uint32_t value;
6843 };
6844
6845 static void
6846 cmd_write_reg_parsed(void *parsed_result,
6847                      __attribute__((unused)) struct cmdline *cl,
6848                      __attribute__((unused)) void *data)
6849 {
6850         struct cmd_write_reg_result *res = parsed_result;
6851         port_reg_set(res->port_id, res->reg_off, res->value);
6852 }
6853
6854 cmdline_parse_token_string_t cmd_write_reg_write =
6855         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6856 cmdline_parse_token_string_t cmd_write_reg_reg =
6857         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6858 cmdline_parse_token_num_t cmd_write_reg_port_id =
6859         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6860 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6861         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6862 cmdline_parse_token_num_t cmd_write_reg_value =
6863         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6864
6865 cmdline_parse_inst_t cmd_write_reg = {
6866         .f = cmd_write_reg_parsed,
6867         .data = NULL,
6868         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6869         .tokens = {
6870                 (void *)&cmd_write_reg_write,
6871                 (void *)&cmd_write_reg_reg,
6872                 (void *)&cmd_write_reg_port_id,
6873                 (void *)&cmd_write_reg_reg_off,
6874                 (void *)&cmd_write_reg_value,
6875                 NULL,
6876         },
6877 };
6878
6879 /* *** WRITE PORT REGISTER BIT FIELD *** */
6880 struct cmd_write_reg_bit_field_result {
6881         cmdline_fixed_string_t write;
6882         cmdline_fixed_string_t regfield;
6883         portid_t port_id;
6884         uint32_t reg_off;
6885         uint8_t bit1_pos;
6886         uint8_t bit2_pos;
6887         uint32_t value;
6888 };
6889
6890 static void
6891 cmd_write_reg_bit_field_parsed(void *parsed_result,
6892                                __attribute__((unused)) struct cmdline *cl,
6893                                __attribute__((unused)) void *data)
6894 {
6895         struct cmd_write_reg_bit_field_result *res = parsed_result;
6896         port_reg_bit_field_set(res->port_id, res->reg_off,
6897                           res->bit1_pos, res->bit2_pos, res->value);
6898 }
6899
6900 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6901         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6902                                  "write");
6903 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6904         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6905                                  regfield, "regfield");
6906 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6907         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6908                               UINT16);
6909 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6910         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6911                               UINT32);
6912 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6913         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6914                               UINT8);
6915 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6916         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6917                               UINT8);
6918 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6919         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6920                               UINT32);
6921
6922 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6923         .f = cmd_write_reg_bit_field_parsed,
6924         .data = NULL,
6925         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6926                 "<reg_value>: "
6927                 "Set register bit field between bit_x and bit_y included",
6928         .tokens = {
6929                 (void *)&cmd_write_reg_bit_field_write,
6930                 (void *)&cmd_write_reg_bit_field_regfield,
6931                 (void *)&cmd_write_reg_bit_field_port_id,
6932                 (void *)&cmd_write_reg_bit_field_reg_off,
6933                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6934                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6935                 (void *)&cmd_write_reg_bit_field_value,
6936                 NULL,
6937         },
6938 };
6939
6940 /* *** WRITE PORT REGISTER BIT *** */
6941 struct cmd_write_reg_bit_result {
6942         cmdline_fixed_string_t write;
6943         cmdline_fixed_string_t regbit;
6944         portid_t port_id;
6945         uint32_t reg_off;
6946         uint8_t bit_pos;
6947         uint8_t value;
6948 };
6949
6950 static void
6951 cmd_write_reg_bit_parsed(void *parsed_result,
6952                          __attribute__((unused)) struct cmdline *cl,
6953                          __attribute__((unused)) void *data)
6954 {
6955         struct cmd_write_reg_bit_result *res = parsed_result;
6956         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6957 }
6958
6959 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6960         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6961                                  "write");
6962 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6963         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6964                                  regbit, "regbit");
6965 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6966         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6967 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6968         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6969 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6970         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6971 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6972         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6973
6974 cmdline_parse_inst_t cmd_write_reg_bit = {
6975         .f = cmd_write_reg_bit_parsed,
6976         .data = NULL,
6977         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6978                 "0 <= bit_x <= 31",
6979         .tokens = {
6980                 (void *)&cmd_write_reg_bit_write,
6981                 (void *)&cmd_write_reg_bit_regbit,
6982                 (void *)&cmd_write_reg_bit_port_id,
6983                 (void *)&cmd_write_reg_bit_reg_off,
6984                 (void *)&cmd_write_reg_bit_bit_pos,
6985                 (void *)&cmd_write_reg_bit_value,
6986                 NULL,
6987         },
6988 };
6989
6990 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6991 struct cmd_read_rxd_txd_result {
6992         cmdline_fixed_string_t read;
6993         cmdline_fixed_string_t rxd_txd;
6994         portid_t port_id;
6995         uint16_t queue_id;
6996         uint16_t desc_id;
6997 };
6998
6999 static void
7000 cmd_read_rxd_txd_parsed(void *parsed_result,
7001                         __attribute__((unused)) struct cmdline *cl,
7002                         __attribute__((unused)) void *data)
7003 {
7004         struct cmd_read_rxd_txd_result *res = parsed_result;
7005
7006         if (!strcmp(res->rxd_txd, "rxd"))
7007                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7008         else if (!strcmp(res->rxd_txd, "txd"))
7009                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7010 }
7011
7012 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7013         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7014 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7015         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7016                                  "rxd#txd");
7017 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7018         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7019 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7020         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7021 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7022         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7023
7024 cmdline_parse_inst_t cmd_read_rxd_txd = {
7025         .f = cmd_read_rxd_txd_parsed,
7026         .data = NULL,
7027         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7028         .tokens = {
7029                 (void *)&cmd_read_rxd_txd_read,
7030                 (void *)&cmd_read_rxd_txd_rxd_txd,
7031                 (void *)&cmd_read_rxd_txd_port_id,
7032                 (void *)&cmd_read_rxd_txd_queue_id,
7033                 (void *)&cmd_read_rxd_txd_desc_id,
7034                 NULL,
7035         },
7036 };
7037
7038 /* *** QUIT *** */
7039 struct cmd_quit_result {
7040         cmdline_fixed_string_t quit;
7041 };
7042
7043 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7044                             struct cmdline *cl,
7045                             __attribute__((unused)) void *data)
7046 {
7047         pmd_test_exit();
7048         cmdline_quit(cl);
7049 }
7050
7051 cmdline_parse_token_string_t cmd_quit_quit =
7052         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7053
7054 cmdline_parse_inst_t cmd_quit = {
7055         .f = cmd_quit_parsed,
7056         .data = NULL,
7057         .help_str = "quit: Exit application",
7058         .tokens = {
7059                 (void *)&cmd_quit_quit,
7060                 NULL,
7061         },
7062 };
7063
7064 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7065 struct cmd_mac_addr_result {
7066         cmdline_fixed_string_t mac_addr_cmd;
7067         cmdline_fixed_string_t what;
7068         uint16_t port_num;
7069         struct ether_addr address;
7070 };
7071
7072 static void cmd_mac_addr_parsed(void *parsed_result,
7073                 __attribute__((unused)) struct cmdline *cl,
7074                 __attribute__((unused)) void *data)
7075 {
7076         struct cmd_mac_addr_result *res = parsed_result;
7077         int ret;
7078
7079         if (strcmp(res->what, "add") == 0)
7080                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7081         else if (strcmp(res->what, "set") == 0)
7082                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7083                                                        &res->address);
7084         else
7085                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7086
7087         /* check the return value and print it if is < 0 */
7088         if(ret < 0)
7089                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7090
7091 }
7092
7093 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7094         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7095                                 "mac_addr");
7096 cmdline_parse_token_string_t cmd_mac_addr_what =
7097         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7098                                 "add#remove#set");
7099 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7100                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7101                                         UINT16);
7102 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7103                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7104
7105 cmdline_parse_inst_t cmd_mac_addr = {
7106         .f = cmd_mac_addr_parsed,
7107         .data = (void *)0,
7108         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7109                         "Add/Remove/Set MAC address on port_id",
7110         .tokens = {
7111                 (void *)&cmd_mac_addr_cmd,
7112                 (void *)&cmd_mac_addr_what,
7113                 (void *)&cmd_mac_addr_portnum,
7114                 (void *)&cmd_mac_addr_addr,
7115                 NULL,
7116         },
7117 };
7118
7119
7120 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7121 struct cmd_set_qmap_result {
7122         cmdline_fixed_string_t set;
7123         cmdline_fixed_string_t qmap;
7124         cmdline_fixed_string_t what;
7125         portid_t port_id;
7126         uint16_t queue_id;
7127         uint8_t map_value;
7128 };
7129
7130 static void
7131 cmd_set_qmap_parsed(void *parsed_result,
7132                        __attribute__((unused)) struct cmdline *cl,
7133                        __attribute__((unused)) void *data)
7134 {
7135         struct cmd_set_qmap_result *res = parsed_result;
7136         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7137
7138         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7139 }
7140
7141 cmdline_parse_token_string_t cmd_setqmap_set =
7142         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7143                                  set, "set");
7144 cmdline_parse_token_string_t cmd_setqmap_qmap =
7145         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7146                                  qmap, "stat_qmap");
7147 cmdline_parse_token_string_t cmd_setqmap_what =
7148         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7149                                  what, "tx#rx");
7150 cmdline_parse_token_num_t cmd_setqmap_portid =
7151         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7152                               port_id, UINT16);
7153 cmdline_parse_token_num_t cmd_setqmap_queueid =
7154         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7155                               queue_id, UINT16);
7156 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7157         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7158                               map_value, UINT8);
7159
7160 cmdline_parse_inst_t cmd_set_qmap = {
7161         .f = cmd_set_qmap_parsed,
7162         .data = NULL,
7163         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7164                 "Set statistics mapping value on tx|rx queue_id of port_id",
7165         .tokens = {
7166                 (void *)&cmd_setqmap_set,
7167                 (void *)&cmd_setqmap_qmap,
7168                 (void *)&cmd_setqmap_what,
7169                 (void *)&cmd_setqmap_portid,
7170                 (void *)&cmd_setqmap_queueid,
7171                 (void *)&cmd_setqmap_mapvalue,
7172                 NULL,
7173         },
7174 };
7175
7176 /* *** CONFIGURE UNICAST HASH TABLE *** */
7177 struct cmd_set_uc_hash_table {
7178         cmdline_fixed_string_t set;
7179         cmdline_fixed_string_t port;
7180         portid_t port_id;
7181         cmdline_fixed_string_t what;
7182         struct ether_addr address;
7183         cmdline_fixed_string_t mode;
7184 };
7185
7186 static void
7187 cmd_set_uc_hash_parsed(void *parsed_result,
7188                        __attribute__((unused)) struct cmdline *cl,
7189                        __attribute__((unused)) void *data)
7190 {
7191         int ret=0;
7192         struct cmd_set_uc_hash_table *res = parsed_result;
7193
7194         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7195
7196         if (strcmp(res->what, "uta") == 0)
7197                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7198                                                 &res->address,(uint8_t)is_on);
7199         if (ret < 0)
7200                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7201
7202 }
7203
7204 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7205         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7206                                  set, "set");
7207 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7209                                  port, "port");
7210 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7211         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7212                               port_id, UINT16);
7213 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7215                                  what, "uta");
7216 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7217         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7218                                 address);
7219 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7221                                  mode, "on#off");
7222
7223 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7224         .f = cmd_set_uc_hash_parsed,
7225         .data = NULL,
7226         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7227         .tokens = {
7228                 (void *)&cmd_set_uc_hash_set,
7229                 (void *)&cmd_set_uc_hash_port,
7230                 (void *)&cmd_set_uc_hash_portid,
7231                 (void *)&cmd_set_uc_hash_what,
7232                 (void *)&cmd_set_uc_hash_mac,
7233                 (void *)&cmd_set_uc_hash_mode,
7234                 NULL,
7235         },
7236 };
7237
7238 struct cmd_set_uc_all_hash_table {
7239         cmdline_fixed_string_t set;
7240         cmdline_fixed_string_t port;
7241         portid_t port_id;
7242         cmdline_fixed_string_t what;
7243         cmdline_fixed_string_t value;
7244         cmdline_fixed_string_t mode;
7245 };
7246
7247 static void
7248 cmd_set_uc_all_hash_parsed(void *parsed_result,
7249                        __attribute__((unused)) struct cmdline *cl,
7250                        __attribute__((unused)) void *data)
7251 {
7252         int ret=0;
7253         struct cmd_set_uc_all_hash_table *res = parsed_result;
7254
7255         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7256
7257         if ((strcmp(res->what, "uta") == 0) &&
7258                 (strcmp(res->value, "all") == 0))
7259                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7260         if (ret < 0)
7261                 printf("bad unicast hash table parameter,"
7262                         "return code = %d \n", ret);
7263 }
7264
7265 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7266         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7267                                  set, "set");
7268 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7269         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7270                                  port, "port");
7271 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7272         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7273                               port_id, UINT16);
7274 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7275         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7276                                  what, "uta");
7277 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7278         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7279                                 value,"all");
7280 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7281         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7282                                  mode, "on#off");
7283
7284 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7285         .f = cmd_set_uc_all_hash_parsed,
7286         .data = NULL,
7287         .help_str = "set port <port_id> uta all on|off",
7288         .tokens = {
7289                 (void *)&cmd_set_uc_all_hash_set,
7290                 (void *)&cmd_set_uc_all_hash_port,
7291                 (void *)&cmd_set_uc_all_hash_portid,
7292                 (void *)&cmd_set_uc_all_hash_what,
7293                 (void *)&cmd_set_uc_all_hash_value,
7294                 (void *)&cmd_set_uc_all_hash_mode,
7295                 NULL,
7296         },
7297 };
7298
7299 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7300 struct cmd_set_vf_macvlan_filter {
7301         cmdline_fixed_string_t set;
7302         cmdline_fixed_string_t port;
7303         portid_t port_id;
7304         cmdline_fixed_string_t vf;
7305         uint8_t vf_id;
7306         struct ether_addr address;
7307         cmdline_fixed_string_t filter_type;
7308         cmdline_fixed_string_t mode;
7309 };
7310
7311 static void
7312 cmd_set_vf_macvlan_parsed(void *parsed_result,
7313                        __attribute__((unused)) struct cmdline *cl,
7314                        __attribute__((unused)) void *data)
7315 {
7316         int is_on, ret = 0;
7317         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7318         struct rte_eth_mac_filter filter;
7319
7320         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7321
7322         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7323
7324         /* set VF MAC filter */
7325         filter.is_vf = 1;
7326
7327         /* set VF ID */
7328         filter.dst_id = res->vf_id;
7329
7330         if (!strcmp(res->filter_type, "exact-mac"))
7331                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7332         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7333                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7334         else if (!strcmp(res->filter_type, "hashmac"))
7335                 filter.filter_type = RTE_MAC_HASH_MATCH;
7336         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7337                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7338
7339         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7340
7341         if (is_on)
7342                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7343                                         RTE_ETH_FILTER_MACVLAN,
7344                                         RTE_ETH_FILTER_ADD,
7345                                          &filter);
7346         else
7347                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7348                                         RTE_ETH_FILTER_MACVLAN,
7349                                         RTE_ETH_FILTER_DELETE,
7350                                         &filter);
7351
7352         if (ret < 0)
7353                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7354
7355 }
7356
7357 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7358         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7359                                  set, "set");
7360 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7361         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7362                                  port, "port");
7363 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7364         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7365                               port_id, UINT16);
7366 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7367         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7368                                  vf, "vf");
7369 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7370         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7371                                 vf_id, UINT8);
7372 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7373         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7374                                 address);
7375 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7376         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7377                                 filter_type, "exact-mac#exact-mac-vlan"
7378                                 "#hashmac#hashmac-vlan");
7379 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7380         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7381                                  mode, "on#off");
7382
7383 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7384         .f = cmd_set_vf_macvlan_parsed,
7385         .data = NULL,
7386         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7387                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7388                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7389                 "hash match rule: hash match of MAC and exact match of VLAN",
7390         .tokens = {
7391                 (void *)&cmd_set_vf_macvlan_set,
7392                 (void *)&cmd_set_vf_macvlan_port,
7393                 (void *)&cmd_set_vf_macvlan_portid,
7394                 (void *)&cmd_set_vf_macvlan_vf,
7395                 (void *)&cmd_set_vf_macvlan_vf_id,
7396                 (void *)&cmd_set_vf_macvlan_mac,
7397                 (void *)&cmd_set_vf_macvlan_filter_type,
7398                 (void *)&cmd_set_vf_macvlan_mode,
7399                 NULL,
7400         },
7401 };
7402
7403 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7404 struct cmd_set_vf_traffic {
7405         cmdline_fixed_string_t set;
7406         cmdline_fixed_string_t port;
7407         portid_t port_id;
7408         cmdline_fixed_string_t vf;
7409         uint8_t vf_id;
7410         cmdline_fixed_string_t what;
7411         cmdline_fixed_string_t mode;
7412 };
7413
7414 static void
7415 cmd_set_vf_traffic_parsed(void *parsed_result,
7416                        __attribute__((unused)) struct cmdline *cl,
7417                        __attribute__((unused)) void *data)
7418 {
7419         struct cmd_set_vf_traffic *res = parsed_result;
7420         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7421         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7422
7423         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7424 }
7425
7426 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7427         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7428                                  set, "set");
7429 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7431                                  port, "port");
7432 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7433         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7434                               port_id, UINT16);
7435 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7437                                  vf, "vf");
7438 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7439         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7440                               vf_id, UINT8);
7441 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7443                                  what, "tx#rx");
7444 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7445         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7446                                  mode, "on#off");
7447
7448 cmdline_parse_inst_t cmd_set_vf_traffic = {
7449         .f = cmd_set_vf_traffic_parsed,
7450         .data = NULL,
7451         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7452         .tokens = {
7453                 (void *)&cmd_setvf_traffic_set,
7454                 (void *)&cmd_setvf_traffic_port,
7455                 (void *)&cmd_setvf_traffic_portid,
7456                 (void *)&cmd_setvf_traffic_vf,
7457                 (void *)&cmd_setvf_traffic_vfid,
7458                 (void *)&cmd_setvf_traffic_what,
7459                 (void *)&cmd_setvf_traffic_mode,
7460                 NULL,
7461         },
7462 };
7463
7464 /* *** CONFIGURE VF RECEIVE MODE *** */
7465 struct cmd_set_vf_rxmode {
7466         cmdline_fixed_string_t set;
7467         cmdline_fixed_string_t port;
7468         portid_t port_id;
7469         cmdline_fixed_string_t vf;
7470         uint8_t vf_id;
7471         cmdline_fixed_string_t what;
7472         cmdline_fixed_string_t mode;
7473         cmdline_fixed_string_t on;
7474 };
7475
7476 static void
7477 cmd_set_vf_rxmode_parsed(void *parsed_result,
7478                        __attribute__((unused)) struct cmdline *cl,
7479                        __attribute__((unused)) void *data)
7480 {
7481         int ret = -ENOTSUP;
7482         uint16_t rx_mode = 0;
7483         struct cmd_set_vf_rxmode *res = parsed_result;
7484
7485         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7486         if (!strcmp(res->what,"rxmode")) {
7487                 if (!strcmp(res->mode, "AUPE"))
7488                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7489                 else if (!strcmp(res->mode, "ROPE"))
7490                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7491                 else if (!strcmp(res->mode, "BAM"))
7492                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7493                 else if (!strncmp(res->mode, "MPE",3))
7494                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7495         }
7496
7497 #ifdef RTE_LIBRTE_IXGBE_PMD
7498         if (ret == -ENOTSUP)
7499                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7500                                                   rx_mode, (uint8_t)is_on);
7501 #endif
7502 #ifdef RTE_LIBRTE_BNXT_PMD
7503         if (ret == -ENOTSUP)
7504                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7505                                                  rx_mode, (uint8_t)is_on);
7506 #endif
7507         if (ret < 0)
7508                 printf("bad VF receive mode parameter, return code = %d \n",
7509                 ret);
7510 }
7511
7512 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7513         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7514                                  set, "set");
7515 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7516         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7517                                  port, "port");
7518 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7519         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7520                               port_id, UINT16);
7521 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7522         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7523                                  vf, "vf");
7524 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7525         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7526                               vf_id, UINT8);
7527 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7528         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7529                                  what, "rxmode");
7530 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7531         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7532                                  mode, "AUPE#ROPE#BAM#MPE");
7533 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7534         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7535                                  on, "on#off");
7536
7537 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7538         .f = cmd_set_vf_rxmode_parsed,
7539         .data = NULL,
7540         .help_str = "set port <port_id> vf <vf_id> rxmode "
7541                 "AUPE|ROPE|BAM|MPE on|off",
7542         .tokens = {
7543                 (void *)&cmd_set_vf_rxmode_set,
7544                 (void *)&cmd_set_vf_rxmode_port,
7545                 (void *)&cmd_set_vf_rxmode_portid,
7546                 (void *)&cmd_set_vf_rxmode_vf,
7547                 (void *)&cmd_set_vf_rxmode_vfid,
7548                 (void *)&cmd_set_vf_rxmode_what,
7549                 (void *)&cmd_set_vf_rxmode_mode,
7550                 (void *)&cmd_set_vf_rxmode_on,
7551                 NULL,
7552         },
7553 };
7554
7555 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7556 struct cmd_vf_mac_addr_result {
7557         cmdline_fixed_string_t mac_addr_cmd;
7558         cmdline_fixed_string_t what;
7559         cmdline_fixed_string_t port;
7560         uint16_t port_num;
7561         cmdline_fixed_string_t vf;
7562         uint8_t vf_num;
7563         struct ether_addr address;
7564 };
7565
7566 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7567                 __attribute__((unused)) struct cmdline *cl,
7568                 __attribute__((unused)) void *data)
7569 {
7570         struct cmd_vf_mac_addr_result *res = parsed_result;
7571         int ret = -ENOTSUP;
7572
7573         if (strcmp(res->what, "add") != 0)
7574                 return;
7575
7576 #ifdef RTE_LIBRTE_I40E_PMD
7577         if (ret == -ENOTSUP)
7578                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7579                                                    &res->address);
7580 #endif
7581 #ifdef RTE_LIBRTE_BNXT_PMD
7582         if (ret == -ENOTSUP)
7583                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7584                                                 res->vf_num);
7585 #endif
7586
7587         if(ret < 0)
7588                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7589
7590 }
7591
7592 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7593         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7594                                 mac_addr_cmd,"mac_addr");
7595 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7596         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7597                                 what,"add");
7598 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7599         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7600                                 port,"port");
7601 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7602         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7603                                 port_num, UINT16);
7604 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7605         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7606                                 vf,"vf");
7607 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7608         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7609                                 vf_num, UINT8);
7610 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7611         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7612                                 address);
7613
7614 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7615         .f = cmd_vf_mac_addr_parsed,
7616         .data = (void *)0,
7617         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7618                 "Add MAC address filtering for a VF on port_id",
7619         .tokens = {
7620                 (void *)&cmd_vf_mac_addr_cmd,
7621                 (void *)&cmd_vf_mac_addr_what,
7622                 (void *)&cmd_vf_mac_addr_port,
7623                 (void *)&cmd_vf_mac_addr_portnum,
7624                 (void *)&cmd_vf_mac_addr_vf,
7625                 (void *)&cmd_vf_mac_addr_vfnum,
7626                 (void *)&cmd_vf_mac_addr_addr,
7627                 NULL,
7628         },
7629 };
7630
7631 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7632 struct cmd_vf_rx_vlan_filter {
7633         cmdline_fixed_string_t rx_vlan;
7634         cmdline_fixed_string_t what;
7635         uint16_t vlan_id;
7636         cmdline_fixed_string_t port;
7637         portid_t port_id;
7638         cmdline_fixed_string_t vf;
7639         uint64_t vf_mask;
7640 };
7641
7642 static void
7643 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7644                           __attribute__((unused)) struct cmdline *cl,
7645                           __attribute__((unused)) void *data)
7646 {
7647         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7648         int ret = -ENOTSUP;
7649
7650         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7651
7652 #ifdef RTE_LIBRTE_IXGBE_PMD
7653         if (ret == -ENOTSUP)
7654                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7655                                 res->vlan_id, res->vf_mask, is_add);
7656 #endif
7657 #ifdef RTE_LIBRTE_I40E_PMD
7658         if (ret == -ENOTSUP)
7659                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7660                                 res->vlan_id, res->vf_mask, is_add);
7661 #endif
7662 #ifdef RTE_LIBRTE_BNXT_PMD
7663         if (ret == -ENOTSUP)
7664                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7665                                 res->vlan_id, res->vf_mask, is_add);
7666 #endif
7667
7668         switch (ret) {
7669         case 0:
7670                 break;
7671         case -EINVAL:
7672                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7673                                 res->vlan_id, res->vf_mask);
7674                 break;
7675         case -ENODEV:
7676                 printf("invalid port_id %d\n", res->port_id);
7677                 break;
7678         case -ENOTSUP:
7679                 printf("function not implemented or supported\n");
7680                 break;
7681         default:
7682                 printf("programming error: (%s)\n", strerror(-ret));
7683         }
7684 }
7685
7686 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7687         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7688                                  rx_vlan, "rx_vlan");
7689 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7690         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7691                                  what, "add#rm");
7692 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7693         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7694                               vlan_id, UINT16);
7695 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7696         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7697                                  port, "port");
7698 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7699         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7700                               port_id, UINT16);
7701 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7702         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7703                                  vf, "vf");
7704 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7705         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7706                               vf_mask, UINT64);
7707
7708 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7709         .f = cmd_vf_rx_vlan_filter_parsed,
7710         .data = NULL,
7711         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7712                 "(vf_mask = hexadecimal VF mask)",
7713         .tokens = {
7714                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7715                 (void *)&cmd_vf_rx_vlan_filter_what,
7716                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7717                 (void *)&cmd_vf_rx_vlan_filter_port,
7718                 (void *)&cmd_vf_rx_vlan_filter_portid,
7719                 (void *)&cmd_vf_rx_vlan_filter_vf,
7720                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7721                 NULL,
7722         },
7723 };
7724
7725 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7726 struct cmd_queue_rate_limit_result {
7727         cmdline_fixed_string_t set;
7728         cmdline_fixed_string_t port;
7729         uint16_t port_num;
7730         cmdline_fixed_string_t queue;
7731         uint8_t queue_num;
7732         cmdline_fixed_string_t rate;
7733         uint16_t rate_num;
7734 };
7735
7736 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7737                 __attribute__((unused)) struct cmdline *cl,
7738                 __attribute__((unused)) void *data)
7739 {
7740         struct cmd_queue_rate_limit_result *res = parsed_result;
7741         int ret = 0;
7742
7743         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7744                 && (strcmp(res->queue, "queue") == 0)
7745                 && (strcmp(res->rate, "rate") == 0))
7746                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7747                                         res->rate_num);
7748         if (ret < 0)
7749                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7750
7751 }
7752
7753 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7754         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7755                                 set, "set");
7756 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7757         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7758                                 port, "port");
7759 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7760         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7761                                 port_num, UINT16);
7762 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7763         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7764                                 queue, "queue");
7765 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7766         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7767                                 queue_num, UINT8);
7768 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7769         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7770                                 rate, "rate");
7771 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7772         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7773                                 rate_num, UINT16);
7774
7775 cmdline_parse_inst_t cmd_queue_rate_limit = {
7776         .f = cmd_queue_rate_limit_parsed,
7777         .data = (void *)0,
7778         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7779                 "Set rate limit for a queue on port_id",
7780         .tokens = {
7781                 (void *)&cmd_queue_rate_limit_set,
7782                 (void *)&cmd_queue_rate_limit_port,
7783                 (void *)&cmd_queue_rate_limit_portnum,
7784                 (void *)&cmd_queue_rate_limit_queue,
7785                 (void *)&cmd_queue_rate_limit_queuenum,
7786                 (void *)&cmd_queue_rate_limit_rate,
7787                 (void *)&cmd_queue_rate_limit_ratenum,
7788                 NULL,
7789         },
7790 };
7791
7792 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7793 struct cmd_vf_rate_limit_result {
7794         cmdline_fixed_string_t set;
7795         cmdline_fixed_string_t port;
7796         uint16_t port_num;
7797         cmdline_fixed_string_t vf;
7798         uint8_t vf_num;
7799         cmdline_fixed_string_t rate;
7800         uint16_t rate_num;
7801         cmdline_fixed_string_t q_msk;
7802         uint64_t q_msk_val;
7803 };
7804
7805 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7806                 __attribute__((unused)) struct cmdline *cl,
7807                 __attribute__((unused)) void *data)
7808 {
7809         struct cmd_vf_rate_limit_result *res = parsed_result;
7810         int ret = 0;
7811
7812         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7813                 && (strcmp(res->vf, "vf") == 0)
7814                 && (strcmp(res->rate, "rate") == 0)
7815                 && (strcmp(res->q_msk, "queue_mask") == 0))
7816                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7817                                         res->rate_num, res->q_msk_val);
7818         if (ret < 0)
7819                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7820
7821 }
7822
7823 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7824         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7825                                 set, "set");
7826 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7827         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7828                                 port, "port");
7829 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7830         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7831                                 port_num, UINT16);
7832 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7833         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7834                                 vf, "vf");
7835 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7836         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7837                                 vf_num, UINT8);
7838 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7839         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7840                                 rate, "rate");
7841 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7842         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7843                                 rate_num, UINT16);
7844 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7845         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7846                                 q_msk, "queue_mask");
7847 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7848         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7849                                 q_msk_val, UINT64);
7850
7851 cmdline_parse_inst_t cmd_vf_rate_limit = {
7852         .f = cmd_vf_rate_limit_parsed,
7853         .data = (void *)0,
7854         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7855                 "queue_mask <queue_mask_value>: "
7856                 "Set rate limit for queues of VF on port_id",
7857         .tokens = {
7858                 (void *)&cmd_vf_rate_limit_set,
7859                 (void *)&cmd_vf_rate_limit_port,
7860                 (void *)&cmd_vf_rate_limit_portnum,
7861                 (void *)&cmd_vf_rate_limit_vf,
7862                 (void *)&cmd_vf_rate_limit_vfnum,
7863                 (void *)&cmd_vf_rate_limit_rate,
7864                 (void *)&cmd_vf_rate_limit_ratenum,
7865                 (void *)&cmd_vf_rate_limit_q_msk,
7866                 (void *)&cmd_vf_rate_limit_q_msk_val,
7867                 NULL,
7868         },
7869 };
7870
7871 /* *** ADD TUNNEL FILTER OF A PORT *** */
7872 struct cmd_tunnel_filter_result {
7873         cmdline_fixed_string_t cmd;
7874         cmdline_fixed_string_t what;
7875         portid_t port_id;
7876         struct ether_addr outer_mac;
7877         struct ether_addr inner_mac;
7878         cmdline_ipaddr_t ip_value;
7879         uint16_t inner_vlan;
7880         cmdline_fixed_string_t tunnel_type;
7881         cmdline_fixed_string_t filter_type;
7882         uint32_t tenant_id;
7883         uint16_t queue_num;
7884 };
7885
7886 static void
7887 cmd_tunnel_filter_parsed(void *parsed_result,
7888                           __attribute__((unused)) struct cmdline *cl,
7889                           __attribute__((unused)) void *data)
7890 {
7891         struct cmd_tunnel_filter_result *res = parsed_result;
7892         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7893         int ret = 0;
7894
7895         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7896
7897         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7898         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7899         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7900
7901         if (res->ip_value.family == AF_INET) {
7902                 tunnel_filter_conf.ip_addr.ipv4_addr =
7903                         res->ip_value.addr.ipv4.s_addr;
7904                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7905         } else {
7906                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7907                         &(res->ip_value.addr.ipv6),
7908                         sizeof(struct in6_addr));
7909                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7910         }
7911
7912         if (!strcmp(res->filter_type, "imac-ivlan"))
7913                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7914         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7915                 tunnel_filter_conf.filter_type =
7916                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7917         else if (!strcmp(res->filter_type, "imac-tenid"))
7918                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7919         else if (!strcmp(res->filter_type, "imac"))
7920                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7921         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7922                 tunnel_filter_conf.filter_type =
7923                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7924         else if (!strcmp(res->filter_type, "oip"))
7925                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7926         else if (!strcmp(res->filter_type, "iip"))
7927                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7928         else {
7929                 printf("The filter type is not supported");
7930                 return;
7931         }
7932
7933         if (!strcmp(res->tunnel_type, "vxlan"))
7934                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7935         else if (!strcmp(res->tunnel_type, "nvgre"))
7936                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7937         else if (!strcmp(res->tunnel_type, "ipingre"))
7938                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7939         else {
7940                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7941                 return;
7942         }
7943
7944         tunnel_filter_conf.tenant_id = res->tenant_id;
7945         tunnel_filter_conf.queue_id = res->queue_num;
7946         if (!strcmp(res->what, "add"))
7947                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7948                                         RTE_ETH_FILTER_TUNNEL,
7949                                         RTE_ETH_FILTER_ADD,
7950                                         &tunnel_filter_conf);
7951         else
7952                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7953                                         RTE_ETH_FILTER_TUNNEL,
7954                                         RTE_ETH_FILTER_DELETE,
7955                                         &tunnel_filter_conf);
7956         if (ret < 0)
7957                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7958                                 strerror(-ret));
7959
7960 }
7961 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7962         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7963         cmd, "tunnel_filter");
7964 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7965         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7966         what, "add#rm");
7967 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7968         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7969         port_id, UINT16);
7970 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7971         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7972         outer_mac);
7973 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7974         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7975         inner_mac);
7976 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7977         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7978         inner_vlan, UINT16);
7979 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7980         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7981         ip_value);
7982 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7983         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7984         tunnel_type, "vxlan#nvgre#ipingre");
7985
7986 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7987         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7988         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7989                 "imac#omac-imac-tenid");
7990 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7991         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7992         tenant_id, UINT32);
7993 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7994         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7995         queue_num, UINT16);
7996
7997 cmdline_parse_inst_t cmd_tunnel_filter = {
7998         .f = cmd_tunnel_filter_parsed,
7999         .data = (void *)0,
8000         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8001                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8002                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8003                 "<queue_id>: Add/Rm tunnel filter of a port",
8004         .tokens = {
8005                 (void *)&cmd_tunnel_filter_cmd,
8006                 (void *)&cmd_tunnel_filter_what,
8007                 (void *)&cmd_tunnel_filter_port_id,
8008                 (void *)&cmd_tunnel_filter_outer_mac,
8009                 (void *)&cmd_tunnel_filter_inner_mac,
8010                 (void *)&cmd_tunnel_filter_ip_value,
8011                 (void *)&cmd_tunnel_filter_innner_vlan,
8012                 (void *)&cmd_tunnel_filter_tunnel_type,
8013                 (void *)&cmd_tunnel_filter_filter_type,
8014                 (void *)&cmd_tunnel_filter_tenant_id,
8015                 (void *)&cmd_tunnel_filter_queue_num,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** CONFIGURE TUNNEL UDP PORT *** */
8021 struct cmd_tunnel_udp_config {
8022         cmdline_fixed_string_t cmd;
8023         cmdline_fixed_string_t what;
8024         uint16_t udp_port;
8025         portid_t port_id;
8026 };
8027
8028 static void
8029 cmd_tunnel_udp_config_parsed(void *parsed_result,
8030                           __attribute__((unused)) struct cmdline *cl,
8031                           __attribute__((unused)) void *data)
8032 {
8033         struct cmd_tunnel_udp_config *res = parsed_result;
8034         struct rte_eth_udp_tunnel tunnel_udp;
8035         int ret;
8036
8037         tunnel_udp.udp_port = res->udp_port;
8038
8039         if (!strcmp(res->cmd, "rx_vxlan_port"))
8040                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8041
8042         if (!strcmp(res->what, "add"))
8043                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8044                                                       &tunnel_udp);
8045         else
8046                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8047                                                          &tunnel_udp);
8048
8049         if (ret < 0)
8050                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8051 }
8052
8053 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8054         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8055                                 cmd, "rx_vxlan_port");
8056 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8057         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8058                                 what, "add#rm");
8059 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8060         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8061                                 udp_port, UINT16);
8062 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8063         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8064                                 port_id, UINT16);
8065
8066 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8067         .f = cmd_tunnel_udp_config_parsed,
8068         .data = (void *)0,
8069         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8070                 "Add/Remove a tunneling UDP port filter",
8071         .tokens = {
8072                 (void *)&cmd_tunnel_udp_config_cmd,
8073                 (void *)&cmd_tunnel_udp_config_what,
8074                 (void *)&cmd_tunnel_udp_config_udp_port,
8075                 (void *)&cmd_tunnel_udp_config_port_id,
8076                 NULL,
8077         },
8078 };
8079
8080 /* *** GLOBAL CONFIG *** */
8081 struct cmd_global_config_result {
8082         cmdline_fixed_string_t cmd;
8083         portid_t port_id;
8084         cmdline_fixed_string_t cfg_type;
8085         uint8_t len;
8086 };
8087
8088 static void
8089 cmd_global_config_parsed(void *parsed_result,
8090                          __attribute__((unused)) struct cmdline *cl,
8091                          __attribute__((unused)) void *data)
8092 {
8093         struct cmd_global_config_result *res = parsed_result;
8094         struct rte_eth_global_cfg conf;
8095         int ret;
8096
8097         memset(&conf, 0, sizeof(conf));
8098         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8099         conf.cfg.gre_key_len = res->len;
8100         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8101                                       RTE_ETH_FILTER_SET, &conf);
8102         if (ret != 0)
8103                 printf("Global config error\n");
8104 }
8105
8106 cmdline_parse_token_string_t cmd_global_config_cmd =
8107         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8108                 "global_config");
8109 cmdline_parse_token_num_t cmd_global_config_port_id =
8110         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8111                                UINT16);
8112 cmdline_parse_token_string_t cmd_global_config_type =
8113         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8114                 cfg_type, "gre-key-len");
8115 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8116         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8117                 len, UINT8);
8118
8119 cmdline_parse_inst_t cmd_global_config = {
8120         .f = cmd_global_config_parsed,
8121         .data = (void *)NULL,
8122         .help_str = "global_config <port_id> gre-key-len <key_len>",
8123         .tokens = {
8124                 (void *)&cmd_global_config_cmd,
8125                 (void *)&cmd_global_config_port_id,
8126                 (void *)&cmd_global_config_type,
8127                 (void *)&cmd_global_config_gre_key_len,
8128                 NULL,
8129         },
8130 };
8131
8132 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8133 struct cmd_set_mirror_mask_result {
8134         cmdline_fixed_string_t set;
8135         cmdline_fixed_string_t port;
8136         portid_t port_id;
8137         cmdline_fixed_string_t mirror;
8138         uint8_t rule_id;
8139         cmdline_fixed_string_t what;
8140         cmdline_fixed_string_t value;
8141         cmdline_fixed_string_t dstpool;
8142         uint8_t dstpool_id;
8143         cmdline_fixed_string_t on;
8144 };
8145
8146 cmdline_parse_token_string_t cmd_mirror_mask_set =
8147         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8148                                 set, "set");
8149 cmdline_parse_token_string_t cmd_mirror_mask_port =
8150         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8151                                 port, "port");
8152 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8153         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8154                                 port_id, UINT16);
8155 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8156         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8157                                 mirror, "mirror-rule");
8158 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8159         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8160                                 rule_id, UINT8);
8161 cmdline_parse_token_string_t cmd_mirror_mask_what =
8162         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8163                                 what, "pool-mirror-up#pool-mirror-down"
8164                                       "#vlan-mirror");
8165 cmdline_parse_token_string_t cmd_mirror_mask_value =
8166         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8167                                 value, NULL);
8168 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8169         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8170                                 dstpool, "dst-pool");
8171 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8172         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8173                                 dstpool_id, UINT8);
8174 cmdline_parse_token_string_t cmd_mirror_mask_on =
8175         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8176                                 on, "on#off");
8177
8178 static void
8179 cmd_set_mirror_mask_parsed(void *parsed_result,
8180                        __attribute__((unused)) struct cmdline *cl,
8181                        __attribute__((unused)) void *data)
8182 {
8183         int ret,nb_item,i;
8184         struct cmd_set_mirror_mask_result *res = parsed_result;
8185         struct rte_eth_mirror_conf mr_conf;
8186
8187         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8188
8189         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8190
8191         mr_conf.dst_pool = res->dstpool_id;
8192
8193         if (!strcmp(res->what, "pool-mirror-up")) {
8194                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8195                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8196         } else if (!strcmp(res->what, "pool-mirror-down")) {
8197                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8198                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8199         } else if (!strcmp(res->what, "vlan-mirror")) {
8200                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8201                 nb_item = parse_item_list(res->value, "vlan",
8202                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8203                 if (nb_item <= 0)
8204                         return;
8205
8206                 for (i = 0; i < nb_item; i++) {
8207                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8208                                 printf("Invalid vlan_id: must be < 4096\n");
8209                                 return;
8210                         }
8211
8212                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8213                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8214                 }
8215         }
8216
8217         if (!strcmp(res->on, "on"))
8218                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8219                                                 res->rule_id, 1);
8220         else
8221                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8222                                                 res->rule_id, 0);
8223         if (ret < 0)
8224                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8225 }
8226
8227 cmdline_parse_inst_t cmd_set_mirror_mask = {
8228                 .f = cmd_set_mirror_mask_parsed,
8229                 .data = NULL,
8230                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8231                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8232                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8233                 .tokens = {
8234                         (void *)&cmd_mirror_mask_set,
8235                         (void *)&cmd_mirror_mask_port,
8236                         (void *)&cmd_mirror_mask_portid,
8237                         (void *)&cmd_mirror_mask_mirror,
8238                         (void *)&cmd_mirror_mask_ruleid,
8239                         (void *)&cmd_mirror_mask_what,
8240                         (void *)&cmd_mirror_mask_value,
8241                         (void *)&cmd_mirror_mask_dstpool,
8242                         (void *)&cmd_mirror_mask_poolid,
8243                         (void *)&cmd_mirror_mask_on,
8244                         NULL,
8245                 },
8246 };
8247
8248 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8249 struct cmd_set_mirror_link_result {
8250         cmdline_fixed_string_t set;
8251         cmdline_fixed_string_t port;
8252         portid_t port_id;
8253         cmdline_fixed_string_t mirror;
8254         uint8_t rule_id;
8255         cmdline_fixed_string_t what;
8256         cmdline_fixed_string_t dstpool;
8257         uint8_t dstpool_id;
8258         cmdline_fixed_string_t on;
8259 };
8260
8261 cmdline_parse_token_string_t cmd_mirror_link_set =
8262         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8263                                  set, "set");
8264 cmdline_parse_token_string_t cmd_mirror_link_port =
8265         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8266                                 port, "port");
8267 cmdline_parse_token_num_t cmd_mirror_link_portid =
8268         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8269                                 port_id, UINT16);
8270 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8271         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8272                                 mirror, "mirror-rule");
8273 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8274         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8275                             rule_id, UINT8);
8276 cmdline_parse_token_string_t cmd_mirror_link_what =
8277         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8278                                 what, "uplink-mirror#downlink-mirror");
8279 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8280         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8281                                 dstpool, "dst-pool");
8282 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8283         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8284                                 dstpool_id, UINT8);
8285 cmdline_parse_token_string_t cmd_mirror_link_on =
8286         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8287                                 on, "on#off");
8288
8289 static void
8290 cmd_set_mirror_link_parsed(void *parsed_result,
8291                        __attribute__((unused)) struct cmdline *cl,
8292                        __attribute__((unused)) void *data)
8293 {
8294         int ret;
8295         struct cmd_set_mirror_link_result *res = parsed_result;
8296         struct rte_eth_mirror_conf mr_conf;
8297
8298         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8299         if (!strcmp(res->what, "uplink-mirror"))
8300                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8301         else
8302                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8303
8304         mr_conf.dst_pool = res->dstpool_id;
8305
8306         if (!strcmp(res->on, "on"))
8307                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8308                                                 res->rule_id, 1);
8309         else
8310                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8311                                                 res->rule_id, 0);
8312
8313         /* check the return value and print it if is < 0 */
8314         if (ret < 0)
8315                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8316
8317 }
8318
8319 cmdline_parse_inst_t cmd_set_mirror_link = {
8320                 .f = cmd_set_mirror_link_parsed,
8321                 .data = NULL,
8322                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8323                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8324                 .tokens = {
8325                         (void *)&cmd_mirror_link_set,
8326                         (void *)&cmd_mirror_link_port,
8327                         (void *)&cmd_mirror_link_portid,
8328                         (void *)&cmd_mirror_link_mirror,
8329                         (void *)&cmd_mirror_link_ruleid,
8330                         (void *)&cmd_mirror_link_what,
8331                         (void *)&cmd_mirror_link_dstpool,
8332                         (void *)&cmd_mirror_link_poolid,
8333                         (void *)&cmd_mirror_link_on,
8334                         NULL,
8335                 },
8336 };
8337
8338 /* *** RESET VM MIRROR RULE *** */
8339 struct cmd_rm_mirror_rule_result {
8340         cmdline_fixed_string_t reset;
8341         cmdline_fixed_string_t port;
8342         portid_t port_id;
8343         cmdline_fixed_string_t mirror;
8344         uint8_t rule_id;
8345 };
8346
8347 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8348         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8349                                  reset, "reset");
8350 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8351         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8352                                 port, "port");
8353 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8354         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8355                                 port_id, UINT16);
8356 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8357         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8358                                 mirror, "mirror-rule");
8359 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8360         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8361                                 rule_id, UINT8);
8362
8363 static void
8364 cmd_reset_mirror_rule_parsed(void *parsed_result,
8365                        __attribute__((unused)) struct cmdline *cl,
8366                        __attribute__((unused)) void *data)
8367 {
8368         int ret;
8369         struct cmd_set_mirror_link_result *res = parsed_result;
8370         /* check rule_id */
8371         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8372         if(ret < 0)
8373                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8374 }
8375
8376 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8377                 .f = cmd_reset_mirror_rule_parsed,
8378                 .data = NULL,
8379                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8380                 .tokens = {
8381                         (void *)&cmd_rm_mirror_rule_reset,
8382                         (void *)&cmd_rm_mirror_rule_port,
8383                         (void *)&cmd_rm_mirror_rule_portid,
8384                         (void *)&cmd_rm_mirror_rule_mirror,
8385                         (void *)&cmd_rm_mirror_rule_ruleid,
8386                         NULL,
8387                 },
8388 };
8389
8390 /* ******************************************************************************** */
8391
8392 struct cmd_dump_result {
8393         cmdline_fixed_string_t dump;
8394 };
8395
8396 static void
8397 dump_struct_sizes(void)
8398 {
8399 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8400         DUMP_SIZE(struct rte_mbuf);
8401         DUMP_SIZE(struct rte_mempool);
8402         DUMP_SIZE(struct rte_ring);
8403 #undef DUMP_SIZE
8404 }
8405
8406 static void cmd_dump_parsed(void *parsed_result,
8407                             __attribute__((unused)) struct cmdline *cl,
8408                             __attribute__((unused)) void *data)
8409 {
8410         struct cmd_dump_result *res = parsed_result;
8411
8412         if (!strcmp(res->dump, "dump_physmem"))
8413                 rte_dump_physmem_layout(stdout);
8414         else if (!strcmp(res->dump, "dump_memzone"))
8415                 rte_memzone_dump(stdout);
8416         else if (!strcmp(res->dump, "dump_struct_sizes"))
8417                 dump_struct_sizes();
8418         else if (!strcmp(res->dump, "dump_ring"))
8419                 rte_ring_list_dump(stdout);
8420         else if (!strcmp(res->dump, "dump_mempool"))
8421                 rte_mempool_list_dump(stdout);
8422         else if (!strcmp(res->dump, "dump_devargs"))
8423                 rte_eal_devargs_dump(stdout);
8424         else if (!strcmp(res->dump, "dump_log_types"))
8425                 rte_log_dump(stdout);
8426 }
8427
8428 cmdline_parse_token_string_t cmd_dump_dump =
8429         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8430                 "dump_physmem#"
8431                 "dump_memzone#"
8432                 "dump_struct_sizes#"
8433                 "dump_ring#"
8434                 "dump_mempool#"
8435                 "dump_devargs#"
8436                 "dump_log_types");
8437
8438 cmdline_parse_inst_t cmd_dump = {
8439         .f = cmd_dump_parsed,  /* function to call */
8440         .data = NULL,      /* 2nd arg of func */
8441         .help_str = "Dump status",
8442         .tokens = {        /* token list, NULL terminated */
8443                 (void *)&cmd_dump_dump,
8444                 NULL,
8445         },
8446 };
8447
8448 /* ******************************************************************************** */
8449
8450 struct cmd_dump_one_result {
8451         cmdline_fixed_string_t dump;
8452         cmdline_fixed_string_t name;
8453 };
8454
8455 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8456                                 __attribute__((unused)) void *data)
8457 {
8458         struct cmd_dump_one_result *res = parsed_result;
8459
8460         if (!strcmp(res->dump, "dump_ring")) {
8461                 struct rte_ring *r;
8462                 r = rte_ring_lookup(res->name);
8463                 if (r == NULL) {
8464                         cmdline_printf(cl, "Cannot find ring\n");
8465                         return;
8466                 }
8467                 rte_ring_dump(stdout, r);
8468         } else if (!strcmp(res->dump, "dump_mempool")) {
8469                 struct rte_mempool *mp;
8470                 mp = rte_mempool_lookup(res->name);
8471                 if (mp == NULL) {
8472                         cmdline_printf(cl, "Cannot find mempool\n");
8473                         return;
8474                 }
8475                 rte_mempool_dump(stdout, mp);
8476         }
8477 }
8478
8479 cmdline_parse_token_string_t cmd_dump_one_dump =
8480         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8481                                  "dump_ring#dump_mempool");
8482
8483 cmdline_parse_token_string_t cmd_dump_one_name =
8484         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8485
8486 cmdline_parse_inst_t cmd_dump_one = {
8487         .f = cmd_dump_one_parsed,  /* function to call */
8488         .data = NULL,      /* 2nd arg of func */
8489         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8490         .tokens = {        /* token list, NULL terminated */
8491                 (void *)&cmd_dump_one_dump,
8492                 (void *)&cmd_dump_one_name,
8493                 NULL,
8494         },
8495 };
8496
8497 /* *** Add/Del syn filter *** */
8498 struct cmd_syn_filter_result {
8499         cmdline_fixed_string_t filter;
8500         portid_t port_id;
8501         cmdline_fixed_string_t ops;
8502         cmdline_fixed_string_t priority;
8503         cmdline_fixed_string_t high;
8504         cmdline_fixed_string_t queue;
8505         uint16_t queue_id;
8506 };
8507
8508 static void
8509 cmd_syn_filter_parsed(void *parsed_result,
8510                         __attribute__((unused)) struct cmdline *cl,
8511                         __attribute__((unused)) void *data)
8512 {
8513         struct cmd_syn_filter_result *res = parsed_result;
8514         struct rte_eth_syn_filter syn_filter;
8515         int ret = 0;
8516
8517         ret = rte_eth_dev_filter_supported(res->port_id,
8518                                         RTE_ETH_FILTER_SYN);
8519         if (ret < 0) {
8520                 printf("syn filter is not supported on port %u.\n",
8521                                 res->port_id);
8522                 return;
8523         }
8524
8525         memset(&syn_filter, 0, sizeof(syn_filter));
8526
8527         if (!strcmp(res->ops, "add")) {
8528                 if (!strcmp(res->high, "high"))
8529                         syn_filter.hig_pri = 1;
8530                 else
8531                         syn_filter.hig_pri = 0;
8532
8533                 syn_filter.queue = res->queue_id;
8534                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8535                                                 RTE_ETH_FILTER_SYN,
8536                                                 RTE_ETH_FILTER_ADD,
8537                                                 &syn_filter);
8538         } else
8539                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8540                                                 RTE_ETH_FILTER_SYN,
8541                                                 RTE_ETH_FILTER_DELETE,
8542                                                 &syn_filter);
8543
8544         if (ret < 0)
8545                 printf("syn filter programming error: (%s)\n",
8546                                 strerror(-ret));
8547 }
8548
8549 cmdline_parse_token_string_t cmd_syn_filter_filter =
8550         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8551         filter, "syn_filter");
8552 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8553         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8554         port_id, UINT16);
8555 cmdline_parse_token_string_t cmd_syn_filter_ops =
8556         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8557         ops, "add#del");
8558 cmdline_parse_token_string_t cmd_syn_filter_priority =
8559         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8560                                 priority, "priority");
8561 cmdline_parse_token_string_t cmd_syn_filter_high =
8562         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8563                                 high, "high#low");
8564 cmdline_parse_token_string_t cmd_syn_filter_queue =
8565         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8566                                 queue, "queue");
8567 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8568         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8569                                 queue_id, UINT16);
8570
8571 cmdline_parse_inst_t cmd_syn_filter = {
8572         .f = cmd_syn_filter_parsed,
8573         .data = NULL,
8574         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8575                 "<queue_id>: Add/Delete syn filter",
8576         .tokens = {
8577                 (void *)&cmd_syn_filter_filter,
8578                 (void *)&cmd_syn_filter_port_id,
8579                 (void *)&cmd_syn_filter_ops,
8580                 (void *)&cmd_syn_filter_priority,
8581                 (void *)&cmd_syn_filter_high,
8582                 (void *)&cmd_syn_filter_queue,
8583                 (void *)&cmd_syn_filter_queue_id,
8584                 NULL,
8585         },
8586 };
8587
8588 /* *** queue region set *** */
8589 struct cmd_queue_region_result {
8590         cmdline_fixed_string_t set;
8591         cmdline_fixed_string_t port;
8592         portid_t port_id;
8593         cmdline_fixed_string_t cmd;
8594         cmdline_fixed_string_t region;
8595         uint8_t  region_id;
8596         cmdline_fixed_string_t queue_start_index;
8597         uint8_t  queue_id;
8598         cmdline_fixed_string_t queue_num;
8599         uint8_t  queue_num_value;
8600 };
8601
8602 static void
8603 cmd_queue_region_parsed(void *parsed_result,
8604                         __attribute__((unused)) struct cmdline *cl,
8605                         __attribute__((unused)) void *data)
8606 {
8607         struct cmd_queue_region_result *res = parsed_result;
8608         int ret = -ENOTSUP;
8609 #ifdef RTE_LIBRTE_I40E_PMD
8610         struct rte_pmd_i40e_queue_region_conf region_conf;
8611         enum rte_pmd_i40e_queue_region_op op_type;
8612 #endif
8613
8614         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8615                 return;
8616
8617 #ifdef RTE_LIBRTE_I40E_PMD
8618         memset(&region_conf, 0, sizeof(region_conf));
8619         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8620         region_conf.region_id = res->region_id;
8621         region_conf.queue_num = res->queue_num_value;
8622         region_conf.queue_start_index = res->queue_id;
8623
8624         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8625                                 op_type, &region_conf);
8626 #endif
8627
8628         switch (ret) {
8629         case 0:
8630                 break;
8631         case -ENOTSUP:
8632                 printf("function not implemented or supported\n");
8633                 break;
8634         default:
8635                 printf("queue region config error: (%s)\n", strerror(-ret));
8636         }
8637 }
8638
8639 cmdline_parse_token_string_t cmd_queue_region_set =
8640 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8641                 set, "set");
8642 cmdline_parse_token_string_t cmd_queue_region_port =
8643         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8644 cmdline_parse_token_num_t cmd_queue_region_port_id =
8645         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8646                                 port_id, UINT16);
8647 cmdline_parse_token_string_t cmd_queue_region_cmd =
8648         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8649                                  cmd, "queue-region");
8650 cmdline_parse_token_string_t cmd_queue_region_id =
8651         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8652                                 region, "region_id");
8653 cmdline_parse_token_num_t cmd_queue_region_index =
8654         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8655                                 region_id, UINT8);
8656 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8657         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8658                                 queue_start_index, "queue_start_index");
8659 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8660         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8661                                 queue_id, UINT8);
8662 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8663         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8664                                 queue_num, "queue_num");
8665 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8666         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8667                                 queue_num_value, UINT8);
8668
8669 cmdline_parse_inst_t cmd_queue_region = {
8670         .f = cmd_queue_region_parsed,
8671         .data = NULL,
8672         .help_str = "set port <port_id> queue-region region_id <value> "
8673                 "queue_start_index <value> queue_num <value>: Set a queue region",
8674         .tokens = {
8675                 (void *)&cmd_queue_region_set,
8676                 (void *)&cmd_queue_region_port,
8677                 (void *)&cmd_queue_region_port_id,
8678                 (void *)&cmd_queue_region_cmd,
8679                 (void *)&cmd_queue_region_id,
8680                 (void *)&cmd_queue_region_index,
8681                 (void *)&cmd_queue_region_queue_start_index,
8682                 (void *)&cmd_queue_region_queue_id,
8683                 (void *)&cmd_queue_region_queue_num,
8684                 (void *)&cmd_queue_region_queue_num_value,
8685                 NULL,
8686         },
8687 };
8688
8689 /* *** queue region and flowtype set *** */
8690 struct cmd_region_flowtype_result {
8691         cmdline_fixed_string_t set;
8692         cmdline_fixed_string_t port;
8693         portid_t port_id;
8694         cmdline_fixed_string_t cmd;
8695         cmdline_fixed_string_t region;
8696         uint8_t  region_id;
8697         cmdline_fixed_string_t flowtype;
8698         uint8_t  flowtype_id;
8699 };
8700
8701 static void
8702 cmd_region_flowtype_parsed(void *parsed_result,
8703                         __attribute__((unused)) struct cmdline *cl,
8704                         __attribute__((unused)) void *data)
8705 {
8706         struct cmd_region_flowtype_result *res = parsed_result;
8707         int ret = -ENOTSUP;
8708 #ifdef RTE_LIBRTE_I40E_PMD
8709         struct rte_pmd_i40e_queue_region_conf region_conf;
8710         enum rte_pmd_i40e_queue_region_op op_type;
8711 #endif
8712
8713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8714                 return;
8715
8716 #ifdef RTE_LIBRTE_I40E_PMD
8717         memset(&region_conf, 0, sizeof(region_conf));
8718
8719         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8720         region_conf.region_id = res->region_id;
8721         region_conf.hw_flowtype = res->flowtype_id;
8722
8723         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8724                         op_type, &region_conf);
8725 #endif
8726
8727         switch (ret) {
8728         case 0:
8729                 break;
8730         case -ENOTSUP:
8731                 printf("function not implemented or supported\n");
8732                 break;
8733         default:
8734                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8735         }
8736 }
8737
8738 cmdline_parse_token_string_t cmd_region_flowtype_set =
8739 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8740                                 set, "set");
8741 cmdline_parse_token_string_t cmd_region_flowtype_port =
8742         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8743                                 port, "port");
8744 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8745         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8746                                 port_id, UINT16);
8747 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8748         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8749                                 cmd, "queue-region");
8750 cmdline_parse_token_string_t cmd_region_flowtype_index =
8751         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8752                                 region, "region_id");
8753 cmdline_parse_token_num_t cmd_region_flowtype_id =
8754         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8755                                 region_id, UINT8);
8756 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8757         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8758                                 flowtype, "flowtype");
8759 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8760         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8761                                 flowtype_id, UINT8);
8762 cmdline_parse_inst_t cmd_region_flowtype = {
8763         .f = cmd_region_flowtype_parsed,
8764         .data = NULL,
8765         .help_str = "set port <port_id> queue-region region_id <value> "
8766                 "flowtype <value>: Set a flowtype region index",
8767         .tokens = {
8768                 (void *)&cmd_region_flowtype_set,
8769                 (void *)&cmd_region_flowtype_port,
8770                 (void *)&cmd_region_flowtype_port_index,
8771                 (void *)&cmd_region_flowtype_cmd,
8772                 (void *)&cmd_region_flowtype_index,
8773                 (void *)&cmd_region_flowtype_id,
8774                 (void *)&cmd_region_flowtype_flow_index,
8775                 (void *)&cmd_region_flowtype_flow_id,
8776                 NULL,
8777         },
8778 };
8779
8780 /* *** User Priority (UP) to queue region (region_id) set *** */
8781 struct cmd_user_priority_region_result {
8782         cmdline_fixed_string_t set;
8783         cmdline_fixed_string_t port;
8784         portid_t port_id;
8785         cmdline_fixed_string_t cmd;
8786         cmdline_fixed_string_t user_priority;
8787         uint8_t  user_priority_id;
8788         cmdline_fixed_string_t region;
8789         uint8_t  region_id;
8790 };
8791
8792 static void
8793 cmd_user_priority_region_parsed(void *parsed_result,
8794                         __attribute__((unused)) struct cmdline *cl,
8795                         __attribute__((unused)) void *data)
8796 {
8797         struct cmd_user_priority_region_result *res = parsed_result;
8798         int ret = -ENOTSUP;
8799 #ifdef RTE_LIBRTE_I40E_PMD
8800         struct rte_pmd_i40e_queue_region_conf region_conf;
8801         enum rte_pmd_i40e_queue_region_op op_type;
8802 #endif
8803
8804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8805                 return;
8806
8807 #ifdef RTE_LIBRTE_I40E_PMD
8808         memset(&region_conf, 0, sizeof(region_conf));
8809         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8810         region_conf.user_priority = res->user_priority_id;
8811         region_conf.region_id = res->region_id;
8812
8813         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8814                                 op_type, &region_conf);
8815 #endif
8816
8817         switch (ret) {
8818         case 0:
8819                 break;
8820         case -ENOTSUP:
8821                 printf("function not implemented or supported\n");
8822                 break;
8823         default:
8824                 printf("user_priority region config error: (%s)\n",
8825                                 strerror(-ret));
8826         }
8827 }
8828
8829 cmdline_parse_token_string_t cmd_user_priority_region_set =
8830         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8831                                 set, "set");
8832 cmdline_parse_token_string_t cmd_user_priority_region_port =
8833         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8834                                 port, "port");
8835 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8836         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8837                                 port_id, UINT16);
8838 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8839         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8840                                 cmd, "queue-region");
8841 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8842         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8843                                 user_priority, "UP");
8844 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8845         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8846                                 user_priority_id, UINT8);
8847 cmdline_parse_token_string_t cmd_user_priority_region_region =
8848         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8849                                 region, "region_id");
8850 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8851         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8852                                 region_id, UINT8);
8853
8854 cmdline_parse_inst_t cmd_user_priority_region = {
8855         .f = cmd_user_priority_region_parsed,
8856         .data = NULL,
8857         .help_str = "set port <port_id> queue-region UP <value> "
8858                 "region_id <value>: Set the mapping of User Priority (UP) "
8859                 "to queue region (region_id) ",
8860         .tokens = {
8861                 (void *)&cmd_user_priority_region_set,
8862                 (void *)&cmd_user_priority_region_port,
8863                 (void *)&cmd_user_priority_region_port_index,
8864                 (void *)&cmd_user_priority_region_cmd,
8865                 (void *)&cmd_user_priority_region_UP,
8866                 (void *)&cmd_user_priority_region_UP_id,
8867                 (void *)&cmd_user_priority_region_region,
8868                 (void *)&cmd_user_priority_region_region_id,
8869                 NULL,
8870         },
8871 };
8872
8873 /* *** flush all queue region related configuration *** */
8874 struct cmd_flush_queue_region_result {
8875         cmdline_fixed_string_t set;
8876         cmdline_fixed_string_t port;
8877         portid_t port_id;
8878         cmdline_fixed_string_t cmd;
8879         cmdline_fixed_string_t flush;
8880         cmdline_fixed_string_t what;
8881 };
8882
8883 static void
8884 cmd_flush_queue_region_parsed(void *parsed_result,
8885                         __attribute__((unused)) struct cmdline *cl,
8886                         __attribute__((unused)) void *data)
8887 {
8888         struct cmd_flush_queue_region_result *res = parsed_result;
8889         int ret = -ENOTSUP;
8890 #ifdef RTE_LIBRTE_I40E_PMD
8891         struct rte_pmd_i40e_queue_region_conf region_conf;
8892         enum rte_pmd_i40e_queue_region_op op_type;
8893 #endif
8894
8895         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8896                 return;
8897
8898 #ifdef RTE_LIBRTE_I40E_PMD
8899         memset(&region_conf, 0, sizeof(region_conf));
8900
8901         if (strcmp(res->what, "on") == 0)
8902                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8903         else
8904                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8905
8906         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8907                                 op_type, &region_conf);
8908 #endif
8909
8910         switch (ret) {
8911         case 0:
8912                 break;
8913         case -ENOTSUP:
8914                 printf("function not implemented or supported\n");
8915                 break;
8916         default:
8917                 printf("queue region config flush error: (%s)\n",
8918                                 strerror(-ret));
8919         }
8920 }
8921
8922 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8923         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8924                                 set, "set");
8925 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8926         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8927                                 port, "port");
8928 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8929         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8930                                 port_id, UINT16);
8931 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8932         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8933                                 cmd, "queue-region");
8934 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8935         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8936                                 flush, "flush");
8937 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8938         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8939                                 what, "on#off");
8940
8941 cmdline_parse_inst_t cmd_flush_queue_region = {
8942         .f = cmd_flush_queue_region_parsed,
8943         .data = NULL,
8944         .help_str = "set port <port_id> queue-region flush on|off"
8945                 ": flush all queue region related configuration",
8946         .tokens = {
8947                 (void *)&cmd_flush_queue_region_set,
8948                 (void *)&cmd_flush_queue_region_port,
8949                 (void *)&cmd_flush_queue_region_port_index,
8950                 (void *)&cmd_flush_queue_region_cmd,
8951                 (void *)&cmd_flush_queue_region_flush,
8952                 (void *)&cmd_flush_queue_region_what,
8953                 NULL,
8954         },
8955 };
8956
8957 /* *** get all queue region related configuration info *** */
8958 struct cmd_show_queue_region_info {
8959         cmdline_fixed_string_t show;
8960         cmdline_fixed_string_t port;
8961         portid_t port_id;
8962         cmdline_fixed_string_t cmd;
8963 };
8964
8965 static void
8966 cmd_show_queue_region_info_parsed(void *parsed_result,
8967                         __attribute__((unused)) struct cmdline *cl,
8968                         __attribute__((unused)) void *data)
8969 {
8970         struct cmd_show_queue_region_info *res = parsed_result;
8971         int ret = -ENOTSUP;
8972 #ifdef RTE_LIBRTE_I40E_PMD
8973         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
8974         enum rte_pmd_i40e_queue_region_op op_type;
8975 #endif
8976
8977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8978                 return;
8979
8980 #ifdef RTE_LIBRTE_I40E_PMD
8981         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
8982
8983         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
8984
8985         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8986                                         op_type, &rte_pmd_regions);
8987
8988         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
8989 #endif
8990
8991         switch (ret) {
8992         case 0:
8993                 break;
8994         case -ENOTSUP:
8995                 printf("function not implemented or supported\n");
8996                 break;
8997         default:
8998                 printf("queue region config info show error: (%s)\n",
8999                                 strerror(-ret));
9000         }
9001 }
9002
9003 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9004 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9005                                 show, "show");
9006 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9007         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9008                                 port, "port");
9009 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9010         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9011                                 port_id, UINT16);
9012 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9013         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9014                                 cmd, "queue-region");
9015
9016 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9017         .f = cmd_show_queue_region_info_parsed,
9018         .data = NULL,
9019         .help_str = "show port <port_id> queue-region"
9020                 ": show all queue region related configuration info",
9021         .tokens = {
9022                 (void *)&cmd_show_queue_region_info_get,
9023                 (void *)&cmd_show_queue_region_info_port,
9024                 (void *)&cmd_show_queue_region_info_port_index,
9025                 (void *)&cmd_show_queue_region_info_cmd,
9026                 NULL,
9027         },
9028 };
9029
9030 /* *** ADD/REMOVE A 2tuple FILTER *** */
9031 struct cmd_2tuple_filter_result {
9032         cmdline_fixed_string_t filter;
9033         portid_t port_id;
9034         cmdline_fixed_string_t ops;
9035         cmdline_fixed_string_t dst_port;
9036         uint16_t dst_port_value;
9037         cmdline_fixed_string_t protocol;
9038         uint8_t protocol_value;
9039         cmdline_fixed_string_t mask;
9040         uint8_t  mask_value;
9041         cmdline_fixed_string_t tcp_flags;
9042         uint8_t tcp_flags_value;
9043         cmdline_fixed_string_t priority;
9044         uint8_t  priority_value;
9045         cmdline_fixed_string_t queue;
9046         uint16_t  queue_id;
9047 };
9048
9049 static void
9050 cmd_2tuple_filter_parsed(void *parsed_result,
9051                         __attribute__((unused)) struct cmdline *cl,
9052                         __attribute__((unused)) void *data)
9053 {
9054         struct rte_eth_ntuple_filter filter;
9055         struct cmd_2tuple_filter_result *res = parsed_result;
9056         int ret = 0;
9057
9058         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9059         if (ret < 0) {
9060                 printf("ntuple filter is not supported on port %u.\n",
9061                         res->port_id);
9062                 return;
9063         }
9064
9065         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9066
9067         filter.flags = RTE_2TUPLE_FLAGS;
9068         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9069         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9070         filter.proto = res->protocol_value;
9071         filter.priority = res->priority_value;
9072         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9073                 printf("nonzero tcp_flags is only meaningful"
9074                         " when protocol is TCP.\n");
9075                 return;
9076         }
9077         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9078                 printf("invalid TCP flags.\n");
9079                 return;
9080         }
9081
9082         if (res->tcp_flags_value != 0) {
9083                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9084                 filter.tcp_flags = res->tcp_flags_value;
9085         }
9086
9087         /* need convert to big endian. */
9088         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9089         filter.queue = res->queue_id;
9090
9091         if (!strcmp(res->ops, "add"))
9092                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9093                                 RTE_ETH_FILTER_NTUPLE,
9094                                 RTE_ETH_FILTER_ADD,
9095                                 &filter);
9096         else
9097                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9098                                 RTE_ETH_FILTER_NTUPLE,
9099                                 RTE_ETH_FILTER_DELETE,
9100                                 &filter);
9101         if (ret < 0)
9102                 printf("2tuple filter programming error: (%s)\n",
9103                         strerror(-ret));
9104
9105 }
9106
9107 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9108         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9109                                  filter, "2tuple_filter");
9110 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9111         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9112                                 port_id, UINT16);
9113 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9114         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9115                                  ops, "add#del");
9116 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9117         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9118                                 dst_port, "dst_port");
9119 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9120         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9121                                 dst_port_value, UINT16);
9122 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9123         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9124                                 protocol, "protocol");
9125 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9126         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9127                                 protocol_value, UINT8);
9128 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9129         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9130                                 mask, "mask");
9131 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9132         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9133                                 mask_value, INT8);
9134 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9135         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9136                                 tcp_flags, "tcp_flags");
9137 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9138         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9139                                 tcp_flags_value, UINT8);
9140 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9141         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9142                                 priority, "priority");
9143 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9144         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9145                                 priority_value, UINT8);
9146 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9147         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9148                                 queue, "queue");
9149 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9150         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9151                                 queue_id, UINT16);
9152
9153 cmdline_parse_inst_t cmd_2tuple_filter = {
9154         .f = cmd_2tuple_filter_parsed,
9155         .data = NULL,
9156         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9157                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9158                 "<queue_id>: Add a 2tuple filter",
9159         .tokens = {
9160                 (void *)&cmd_2tuple_filter_filter,
9161                 (void *)&cmd_2tuple_filter_port_id,
9162                 (void *)&cmd_2tuple_filter_ops,
9163                 (void *)&cmd_2tuple_filter_dst_port,
9164                 (void *)&cmd_2tuple_filter_dst_port_value,
9165                 (void *)&cmd_2tuple_filter_protocol,
9166                 (void *)&cmd_2tuple_filter_protocol_value,
9167                 (void *)&cmd_2tuple_filter_mask,
9168                 (void *)&cmd_2tuple_filter_mask_value,
9169                 (void *)&cmd_2tuple_filter_tcp_flags,
9170                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9171                 (void *)&cmd_2tuple_filter_priority,
9172                 (void *)&cmd_2tuple_filter_priority_value,
9173                 (void *)&cmd_2tuple_filter_queue,
9174                 (void *)&cmd_2tuple_filter_queue_id,
9175                 NULL,
9176         },
9177 };
9178
9179 /* *** ADD/REMOVE A 5tuple FILTER *** */
9180 struct cmd_5tuple_filter_result {
9181         cmdline_fixed_string_t filter;
9182         portid_t port_id;
9183         cmdline_fixed_string_t ops;
9184         cmdline_fixed_string_t dst_ip;
9185         cmdline_ipaddr_t dst_ip_value;
9186         cmdline_fixed_string_t src_ip;
9187         cmdline_ipaddr_t src_ip_value;
9188         cmdline_fixed_string_t dst_port;
9189         uint16_t dst_port_value;
9190         cmdline_fixed_string_t src_port;
9191         uint16_t src_port_value;
9192         cmdline_fixed_string_t protocol;
9193         uint8_t protocol_value;
9194         cmdline_fixed_string_t mask;
9195         uint8_t  mask_value;
9196         cmdline_fixed_string_t tcp_flags;
9197         uint8_t tcp_flags_value;
9198         cmdline_fixed_string_t priority;
9199         uint8_t  priority_value;
9200         cmdline_fixed_string_t queue;
9201         uint16_t  queue_id;
9202 };
9203
9204 static void
9205 cmd_5tuple_filter_parsed(void *parsed_result,
9206                         __attribute__((unused)) struct cmdline *cl,
9207                         __attribute__((unused)) void *data)
9208 {
9209         struct rte_eth_ntuple_filter filter;
9210         struct cmd_5tuple_filter_result *res = parsed_result;
9211         int ret = 0;
9212
9213         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9214         if (ret < 0) {
9215                 printf("ntuple filter is not supported on port %u.\n",
9216                         res->port_id);
9217                 return;
9218         }
9219
9220         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9221
9222         filter.flags = RTE_5TUPLE_FLAGS;
9223         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9224         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9225         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9226         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9227         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9228         filter.proto = res->protocol_value;
9229         filter.priority = res->priority_value;
9230         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9231                 printf("nonzero tcp_flags is only meaningful"
9232                         " when protocol is TCP.\n");
9233                 return;
9234         }
9235         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9236                 printf("invalid TCP flags.\n");
9237                 return;
9238         }
9239
9240         if (res->tcp_flags_value != 0) {
9241                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9242                 filter.tcp_flags = res->tcp_flags_value;
9243         }
9244
9245         if (res->dst_ip_value.family == AF_INET)
9246                 /* no need to convert, already big endian. */
9247                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9248         else {
9249                 if (filter.dst_ip_mask == 0) {
9250                         printf("can not support ipv6 involved compare.\n");
9251                         return;
9252                 }
9253                 filter.dst_ip = 0;
9254         }
9255
9256         if (res->src_ip_value.family == AF_INET)
9257                 /* no need to convert, already big endian. */
9258                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9259         else {
9260                 if (filter.src_ip_mask == 0) {
9261                         printf("can not support ipv6 involved compare.\n");
9262                         return;
9263                 }
9264                 filter.src_ip = 0;
9265         }
9266         /* need convert to big endian. */
9267         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9268         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9269         filter.queue = res->queue_id;
9270
9271         if (!strcmp(res->ops, "add"))
9272                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9273                                 RTE_ETH_FILTER_NTUPLE,
9274                                 RTE_ETH_FILTER_ADD,
9275                                 &filter);
9276         else
9277                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9278                                 RTE_ETH_FILTER_NTUPLE,
9279                                 RTE_ETH_FILTER_DELETE,
9280                                 &filter);
9281         if (ret < 0)
9282                 printf("5tuple filter programming error: (%s)\n",
9283                         strerror(-ret));
9284 }
9285
9286 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9287         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9288                                  filter, "5tuple_filter");
9289 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9290         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9291                                 port_id, UINT16);
9292 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9293         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9294                                  ops, "add#del");
9295 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9296         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9297                                 dst_ip, "dst_ip");
9298 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9299         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9300                                 dst_ip_value);
9301 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9302         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9303                                 src_ip, "src_ip");
9304 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9305         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9306                                 src_ip_value);
9307 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9308         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9309                                 dst_port, "dst_port");
9310 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9311         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9312                                 dst_port_value, UINT16);
9313 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9314         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9315                                 src_port, "src_port");
9316 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9317         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9318                                 src_port_value, UINT16);
9319 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9320         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9321                                 protocol, "protocol");
9322 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9323         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9324                                 protocol_value, UINT8);
9325 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9326         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9327                                 mask, "mask");
9328 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9329         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9330                                 mask_value, INT8);
9331 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9332         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9333                                 tcp_flags, "tcp_flags");
9334 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9335         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9336                                 tcp_flags_value, UINT8);
9337 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9338         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9339                                 priority, "priority");
9340 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9341         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9342                                 priority_value, UINT8);
9343 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9344         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9345                                 queue, "queue");
9346 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9347         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9348                                 queue_id, UINT16);
9349
9350 cmdline_parse_inst_t cmd_5tuple_filter = {
9351         .f = cmd_5tuple_filter_parsed,
9352         .data = NULL,
9353         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9354                 "src_ip <value> dst_port <value> src_port <value> "
9355                 "protocol <value>  mask <value> tcp_flags <value> "
9356                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9357         .tokens = {
9358                 (void *)&cmd_5tuple_filter_filter,
9359                 (void *)&cmd_5tuple_filter_port_id,
9360                 (void *)&cmd_5tuple_filter_ops,
9361                 (void *)&cmd_5tuple_filter_dst_ip,
9362                 (void *)&cmd_5tuple_filter_dst_ip_value,
9363                 (void *)&cmd_5tuple_filter_src_ip,
9364                 (void *)&cmd_5tuple_filter_src_ip_value,
9365                 (void *)&cmd_5tuple_filter_dst_port,
9366                 (void *)&cmd_5tuple_filter_dst_port_value,
9367                 (void *)&cmd_5tuple_filter_src_port,
9368                 (void *)&cmd_5tuple_filter_src_port_value,
9369                 (void *)&cmd_5tuple_filter_protocol,
9370                 (void *)&cmd_5tuple_filter_protocol_value,
9371                 (void *)&cmd_5tuple_filter_mask,
9372                 (void *)&cmd_5tuple_filter_mask_value,
9373                 (void *)&cmd_5tuple_filter_tcp_flags,
9374                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9375                 (void *)&cmd_5tuple_filter_priority,
9376                 (void *)&cmd_5tuple_filter_priority_value,
9377                 (void *)&cmd_5tuple_filter_queue,
9378                 (void *)&cmd_5tuple_filter_queue_id,
9379                 NULL,
9380         },
9381 };
9382
9383 /* *** ADD/REMOVE A flex FILTER *** */
9384 struct cmd_flex_filter_result {
9385         cmdline_fixed_string_t filter;
9386         cmdline_fixed_string_t ops;
9387         portid_t port_id;
9388         cmdline_fixed_string_t len;
9389         uint8_t len_value;
9390         cmdline_fixed_string_t bytes;
9391         cmdline_fixed_string_t bytes_value;
9392         cmdline_fixed_string_t mask;
9393         cmdline_fixed_string_t mask_value;
9394         cmdline_fixed_string_t priority;
9395         uint8_t priority_value;
9396         cmdline_fixed_string_t queue;
9397         uint16_t queue_id;
9398 };
9399
9400 static int xdigit2val(unsigned char c)
9401 {
9402         int val;
9403         if (isdigit(c))
9404                 val = c - '0';
9405         else if (isupper(c))
9406                 val = c - 'A' + 10;
9407         else
9408                 val = c - 'a' + 10;
9409         return val;
9410 }
9411
9412 static void
9413 cmd_flex_filter_parsed(void *parsed_result,
9414                           __attribute__((unused)) struct cmdline *cl,
9415                           __attribute__((unused)) void *data)
9416 {
9417         int ret = 0;
9418         struct rte_eth_flex_filter filter;
9419         struct cmd_flex_filter_result *res = parsed_result;
9420         char *bytes_ptr, *mask_ptr;
9421         uint16_t len, i, j = 0;
9422         char c;
9423         int val;
9424         uint8_t byte = 0;
9425
9426         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9427                 printf("the len exceed the max length 128\n");
9428                 return;
9429         }
9430         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9431         filter.len = res->len_value;
9432         filter.priority = res->priority_value;
9433         filter.queue = res->queue_id;
9434         bytes_ptr = res->bytes_value;
9435         mask_ptr = res->mask_value;
9436
9437          /* translate bytes string to array. */
9438         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9439                 (bytes_ptr[1] == 'X')))
9440                 bytes_ptr += 2;
9441         len = strnlen(bytes_ptr, res->len_value * 2);
9442         if (len == 0 || (len % 8 != 0)) {
9443                 printf("please check len and bytes input\n");
9444                 return;
9445         }
9446         for (i = 0; i < len; i++) {
9447                 c = bytes_ptr[i];
9448                 if (isxdigit(c) == 0) {
9449                         /* invalid characters. */
9450                         printf("invalid input\n");
9451                         return;
9452                 }
9453                 val = xdigit2val(c);
9454                 if (i % 2) {
9455                         byte |= val;
9456                         filter.bytes[j] = byte;
9457                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9458                         j++;
9459                         byte = 0;
9460                 } else
9461                         byte |= val << 4;
9462         }
9463         printf("\n");
9464          /* translate mask string to uint8_t array. */
9465         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9466                 (mask_ptr[1] == 'X')))
9467                 mask_ptr += 2;
9468         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9469         if (len == 0) {
9470                 printf("invalid input\n");
9471                 return;
9472         }
9473         j = 0;
9474         byte = 0;
9475         for (i = 0; i < len; i++) {
9476                 c = mask_ptr[i];
9477                 if (isxdigit(c) == 0) {
9478                         /* invalid characters. */
9479                         printf("invalid input\n");
9480                         return;
9481                 }
9482                 val = xdigit2val(c);
9483                 if (i % 2) {
9484                         byte |= val;
9485                         filter.mask[j] = byte;
9486                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9487                         j++;
9488                         byte = 0;
9489                 } else
9490                         byte |= val << 4;
9491         }
9492         printf("\n");
9493
9494         if (!strcmp(res->ops, "add"))
9495                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9496                                 RTE_ETH_FILTER_FLEXIBLE,
9497                                 RTE_ETH_FILTER_ADD,
9498                                 &filter);
9499         else
9500                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9501                                 RTE_ETH_FILTER_FLEXIBLE,
9502                                 RTE_ETH_FILTER_DELETE,
9503                                 &filter);
9504
9505         if (ret < 0)
9506                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9507 }
9508
9509 cmdline_parse_token_string_t cmd_flex_filter_filter =
9510         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9511                                 filter, "flex_filter");
9512 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9513         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9514                                 port_id, UINT16);
9515 cmdline_parse_token_string_t cmd_flex_filter_ops =
9516         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9517                                 ops, "add#del");
9518 cmdline_parse_token_string_t cmd_flex_filter_len =
9519         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9520                                 len, "len");
9521 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9522         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9523                                 len_value, UINT8);
9524 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9525         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9526                                 bytes, "bytes");
9527 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9528         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9529                                 bytes_value, NULL);
9530 cmdline_parse_token_string_t cmd_flex_filter_mask =
9531         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9532                                 mask, "mask");
9533 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9534         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9535                                 mask_value, NULL);
9536 cmdline_parse_token_string_t cmd_flex_filter_priority =
9537         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9538                                 priority, "priority");
9539 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9540         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9541                                 priority_value, UINT8);
9542 cmdline_parse_token_string_t cmd_flex_filter_queue =
9543         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9544                                 queue, "queue");
9545 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9546         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9547                                 queue_id, UINT16);
9548 cmdline_parse_inst_t cmd_flex_filter = {
9549         .f = cmd_flex_filter_parsed,
9550         .data = NULL,
9551         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9552                 "<value> mask <value> priority <value> queue <queue_id>: "
9553                 "Add/Del a flex filter",
9554         .tokens = {
9555                 (void *)&cmd_flex_filter_filter,
9556                 (void *)&cmd_flex_filter_port_id,
9557                 (void *)&cmd_flex_filter_ops,
9558                 (void *)&cmd_flex_filter_len,
9559                 (void *)&cmd_flex_filter_len_value,
9560                 (void *)&cmd_flex_filter_bytes,
9561                 (void *)&cmd_flex_filter_bytes_value,
9562                 (void *)&cmd_flex_filter_mask,
9563                 (void *)&cmd_flex_filter_mask_value,
9564                 (void *)&cmd_flex_filter_priority,
9565                 (void *)&cmd_flex_filter_priority_value,
9566                 (void *)&cmd_flex_filter_queue,
9567                 (void *)&cmd_flex_filter_queue_id,
9568                 NULL,
9569         },
9570 };
9571
9572 /* *** Filters Control *** */
9573
9574 /* *** deal with ethertype filter *** */
9575 struct cmd_ethertype_filter_result {
9576         cmdline_fixed_string_t filter;
9577         portid_t port_id;
9578         cmdline_fixed_string_t ops;
9579         cmdline_fixed_string_t mac;
9580         struct ether_addr mac_addr;
9581         cmdline_fixed_string_t ethertype;
9582         uint16_t ethertype_value;
9583         cmdline_fixed_string_t drop;
9584         cmdline_fixed_string_t queue;
9585         uint16_t  queue_id;
9586 };
9587
9588 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9589         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9590                                  filter, "ethertype_filter");
9591 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9592         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9593                               port_id, UINT16);
9594 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9595         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9596                                  ops, "add#del");
9597 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9598         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9599                                  mac, "mac_addr#mac_ignr");
9600 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9601         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9602                                      mac_addr);
9603 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9604         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9605                                  ethertype, "ethertype");
9606 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9607         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9608                               ethertype_value, UINT16);
9609 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9610         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9611                                  drop, "drop#fwd");
9612 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9613         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9614                                  queue, "queue");
9615 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9616         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9617                               queue_id, UINT16);
9618
9619 static void
9620 cmd_ethertype_filter_parsed(void *parsed_result,
9621                           __attribute__((unused)) struct cmdline *cl,
9622                           __attribute__((unused)) void *data)
9623 {
9624         struct cmd_ethertype_filter_result *res = parsed_result;
9625         struct rte_eth_ethertype_filter filter;
9626         int ret = 0;
9627
9628         ret = rte_eth_dev_filter_supported(res->port_id,
9629                         RTE_ETH_FILTER_ETHERTYPE);
9630         if (ret < 0) {
9631                 printf("ethertype filter is not supported on port %u.\n",
9632                         res->port_id);
9633                 return;
9634         }
9635
9636         memset(&filter, 0, sizeof(filter));
9637         if (!strcmp(res->mac, "mac_addr")) {
9638                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9639                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9640                         sizeof(struct ether_addr));
9641         }
9642         if (!strcmp(res->drop, "drop"))
9643                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9644         filter.ether_type = res->ethertype_value;
9645         filter.queue = res->queue_id;
9646
9647         if (!strcmp(res->ops, "add"))
9648                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9649                                 RTE_ETH_FILTER_ETHERTYPE,
9650                                 RTE_ETH_FILTER_ADD,
9651                                 &filter);
9652         else
9653                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9654                                 RTE_ETH_FILTER_ETHERTYPE,
9655                                 RTE_ETH_FILTER_DELETE,
9656                                 &filter);
9657         if (ret < 0)
9658                 printf("ethertype filter programming error: (%s)\n",
9659                         strerror(-ret));
9660 }
9661
9662 cmdline_parse_inst_t cmd_ethertype_filter = {
9663         .f = cmd_ethertype_filter_parsed,
9664         .data = NULL,
9665         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9666                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9667                 "Add or delete an ethertype filter entry",
9668         .tokens = {
9669                 (void *)&cmd_ethertype_filter_filter,
9670                 (void *)&cmd_ethertype_filter_port_id,
9671                 (void *)&cmd_ethertype_filter_ops,
9672                 (void *)&cmd_ethertype_filter_mac,
9673                 (void *)&cmd_ethertype_filter_mac_addr,
9674                 (void *)&cmd_ethertype_filter_ethertype,
9675                 (void *)&cmd_ethertype_filter_ethertype_value,
9676                 (void *)&cmd_ethertype_filter_drop,
9677                 (void *)&cmd_ethertype_filter_queue,
9678                 (void *)&cmd_ethertype_filter_queue_id,
9679                 NULL,
9680         },
9681 };
9682
9683 /* *** deal with flow director filter *** */
9684 struct cmd_flow_director_result {
9685         cmdline_fixed_string_t flow_director_filter;
9686         portid_t port_id;
9687         cmdline_fixed_string_t mode;
9688         cmdline_fixed_string_t mode_value;
9689         cmdline_fixed_string_t ops;
9690         cmdline_fixed_string_t flow;
9691         cmdline_fixed_string_t flow_type;
9692         cmdline_fixed_string_t ether;
9693         uint16_t ether_type;
9694         cmdline_fixed_string_t src;
9695         cmdline_ipaddr_t ip_src;
9696         uint16_t port_src;
9697         cmdline_fixed_string_t dst;
9698         cmdline_ipaddr_t ip_dst;
9699         uint16_t port_dst;
9700         cmdline_fixed_string_t verify_tag;
9701         uint32_t verify_tag_value;
9702         cmdline_ipaddr_t tos;
9703         uint8_t tos_value;
9704         cmdline_ipaddr_t proto;
9705         uint8_t proto_value;
9706         cmdline_ipaddr_t ttl;
9707         uint8_t ttl_value;
9708         cmdline_fixed_string_t vlan;
9709         uint16_t vlan_value;
9710         cmdline_fixed_string_t flexbytes;
9711         cmdline_fixed_string_t flexbytes_value;
9712         cmdline_fixed_string_t pf_vf;
9713         cmdline_fixed_string_t drop;
9714         cmdline_fixed_string_t queue;
9715         uint16_t  queue_id;
9716         cmdline_fixed_string_t fd_id;
9717         uint32_t  fd_id_value;
9718         cmdline_fixed_string_t mac;
9719         struct ether_addr mac_addr;
9720         cmdline_fixed_string_t tunnel;
9721         cmdline_fixed_string_t tunnel_type;
9722         cmdline_fixed_string_t tunnel_id;
9723         uint32_t tunnel_id_value;
9724 };
9725
9726 static inline int
9727 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9728 {
9729         char s[256];
9730         const char *p, *p0 = q_arg;
9731         char *end;
9732         unsigned long int_fld;
9733         char *str_fld[max_num];
9734         int i;
9735         unsigned size;
9736         int ret = -1;
9737
9738         p = strchr(p0, '(');
9739         if (p == NULL)
9740                 return -1;
9741         ++p;
9742         p0 = strchr(p, ')');
9743         if (p0 == NULL)
9744                 return -1;
9745
9746         size = p0 - p;
9747         if (size >= sizeof(s))
9748                 return -1;
9749
9750         snprintf(s, sizeof(s), "%.*s", size, p);
9751         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9752         if (ret < 0 || ret > max_num)
9753                 return -1;
9754         for (i = 0; i < ret; i++) {
9755                 errno = 0;
9756                 int_fld = strtoul(str_fld[i], &end, 0);
9757                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9758                         return -1;
9759                 flexbytes[i] = (uint8_t)int_fld;
9760         }
9761         return ret;
9762 }
9763
9764 static uint16_t
9765 str2flowtype(char *string)
9766 {
9767         uint8_t i = 0;
9768         static const struct {
9769                 char str[32];
9770                 uint16_t type;
9771         } flowtype_str[] = {
9772                 {"raw", RTE_ETH_FLOW_RAW},
9773                 {"ipv4", RTE_ETH_FLOW_IPV4},
9774                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9775                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9776                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9777                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9778                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9779                 {"ipv6", RTE_ETH_FLOW_IPV6},
9780                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9781                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9782                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9783                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9784                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9785                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9786         };
9787
9788         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9789                 if (!strcmp(flowtype_str[i].str, string))
9790                         return flowtype_str[i].type;
9791         }
9792
9793         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9794                 return (uint16_t)atoi(string);
9795
9796         return RTE_ETH_FLOW_UNKNOWN;
9797 }
9798
9799 static enum rte_eth_fdir_tunnel_type
9800 str2fdir_tunneltype(char *string)
9801 {
9802         uint8_t i = 0;
9803
9804         static const struct {
9805                 char str[32];
9806                 enum rte_eth_fdir_tunnel_type type;
9807         } tunneltype_str[] = {
9808                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9809                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9810         };
9811
9812         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9813                 if (!strcmp(tunneltype_str[i].str, string))
9814                         return tunneltype_str[i].type;
9815         }
9816         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9817 }
9818
9819 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9820 do { \
9821         if ((ip_addr).family == AF_INET) \
9822                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9823         else { \
9824                 printf("invalid parameter.\n"); \
9825                 return; \
9826         } \
9827 } while (0)
9828
9829 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9830 do { \
9831         if ((ip_addr).family == AF_INET6) \
9832                 rte_memcpy(&(ip), \
9833                                  &((ip_addr).addr.ipv6), \
9834                                  sizeof(struct in6_addr)); \
9835         else { \
9836                 printf("invalid parameter.\n"); \
9837                 return; \
9838         } \
9839 } while (0)
9840
9841 static void
9842 cmd_flow_director_filter_parsed(void *parsed_result,
9843                           __attribute__((unused)) struct cmdline *cl,
9844                           __attribute__((unused)) void *data)
9845 {
9846         struct cmd_flow_director_result *res = parsed_result;
9847         struct rte_eth_fdir_filter entry;
9848         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9849         char *end;
9850         unsigned long vf_id;
9851         int ret = 0;
9852
9853         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9854         if (ret < 0) {
9855                 printf("flow director is not supported on port %u.\n",
9856                         res->port_id);
9857                 return;
9858         }
9859         memset(flexbytes, 0, sizeof(flexbytes));
9860         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9861
9862         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9863                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9864                         printf("Please set mode to MAC-VLAN.\n");
9865                         return;
9866                 }
9867         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9868                 if (strcmp(res->mode_value, "Tunnel")) {
9869                         printf("Please set mode to Tunnel.\n");
9870                         return;
9871                 }
9872         } else {
9873                 if (strcmp(res->mode_value, "IP")) {
9874                         printf("Please set mode to IP.\n");
9875                         return;
9876                 }
9877                 entry.input.flow_type = str2flowtype(res->flow_type);
9878         }
9879
9880         ret = parse_flexbytes(res->flexbytes_value,
9881                                         flexbytes,
9882                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9883         if (ret < 0) {
9884                 printf("error: Cannot parse flexbytes input.\n");
9885                 return;
9886         }
9887
9888         switch (entry.input.flow_type) {
9889         case RTE_ETH_FLOW_FRAG_IPV4:
9890         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9891                 entry.input.flow.ip4_flow.proto = res->proto_value;
9892                 /* fall-through */
9893         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9894         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9895                 IPV4_ADDR_TO_UINT(res->ip_dst,
9896                         entry.input.flow.ip4_flow.dst_ip);
9897                 IPV4_ADDR_TO_UINT(res->ip_src,
9898                         entry.input.flow.ip4_flow.src_ip);
9899                 entry.input.flow.ip4_flow.tos = res->tos_value;
9900                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9901                 /* need convert to big endian. */
9902                 entry.input.flow.udp4_flow.dst_port =
9903                                 rte_cpu_to_be_16(res->port_dst);
9904                 entry.input.flow.udp4_flow.src_port =
9905                                 rte_cpu_to_be_16(res->port_src);
9906                 break;
9907         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9908                 IPV4_ADDR_TO_UINT(res->ip_dst,
9909                         entry.input.flow.sctp4_flow.ip.dst_ip);
9910                 IPV4_ADDR_TO_UINT(res->ip_src,
9911                         entry.input.flow.sctp4_flow.ip.src_ip);
9912                 entry.input.flow.ip4_flow.tos = res->tos_value;
9913                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9914                 /* need convert to big endian. */
9915                 entry.input.flow.sctp4_flow.dst_port =
9916                                 rte_cpu_to_be_16(res->port_dst);
9917                 entry.input.flow.sctp4_flow.src_port =
9918                                 rte_cpu_to_be_16(res->port_src);
9919                 entry.input.flow.sctp4_flow.verify_tag =
9920                                 rte_cpu_to_be_32(res->verify_tag_value);
9921                 break;
9922         case RTE_ETH_FLOW_FRAG_IPV6:
9923         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9924                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9925                 /* fall-through */
9926         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9927         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9928                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9929                         entry.input.flow.ipv6_flow.dst_ip);
9930                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9931                         entry.input.flow.ipv6_flow.src_ip);
9932                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9933                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9934                 /* need convert to big endian. */
9935                 entry.input.flow.udp6_flow.dst_port =
9936                                 rte_cpu_to_be_16(res->port_dst);
9937                 entry.input.flow.udp6_flow.src_port =
9938                                 rte_cpu_to_be_16(res->port_src);
9939                 break;
9940         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9941                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9942                         entry.input.flow.sctp6_flow.ip.dst_ip);
9943                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9944                         entry.input.flow.sctp6_flow.ip.src_ip);
9945                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9946                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9947                 /* need convert to big endian. */
9948                 entry.input.flow.sctp6_flow.dst_port =
9949                                 rte_cpu_to_be_16(res->port_dst);
9950                 entry.input.flow.sctp6_flow.src_port =
9951                                 rte_cpu_to_be_16(res->port_src);
9952                 entry.input.flow.sctp6_flow.verify_tag =
9953                                 rte_cpu_to_be_32(res->verify_tag_value);
9954                 break;
9955         case RTE_ETH_FLOW_L2_PAYLOAD:
9956                 entry.input.flow.l2_flow.ether_type =
9957                         rte_cpu_to_be_16(res->ether_type);
9958                 break;
9959         default:
9960                 break;
9961         }
9962
9963         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9964                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9965                                  &res->mac_addr,
9966                                  sizeof(struct ether_addr));
9967
9968         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9969                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9970                                  &res->mac_addr,
9971                                  sizeof(struct ether_addr));
9972                 entry.input.flow.tunnel_flow.tunnel_type =
9973                         str2fdir_tunneltype(res->tunnel_type);
9974                 entry.input.flow.tunnel_flow.tunnel_id =
9975                         rte_cpu_to_be_32(res->tunnel_id_value);
9976         }
9977
9978         rte_memcpy(entry.input.flow_ext.flexbytes,
9979                    flexbytes,
9980                    RTE_ETH_FDIR_MAX_FLEXLEN);
9981
9982         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9983
9984         entry.action.flex_off = 0;  /*use 0 by default */
9985         if (!strcmp(res->drop, "drop"))
9986                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9987         else
9988                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9989
9990         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9991             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9992                 if (!strcmp(res->pf_vf, "pf"))
9993                         entry.input.flow_ext.is_vf = 0;
9994                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9995                         struct rte_eth_dev_info dev_info;
9996
9997                         memset(&dev_info, 0, sizeof(dev_info));
9998                         rte_eth_dev_info_get(res->port_id, &dev_info);
9999                         errno = 0;
10000                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10001                         if (errno != 0 || *end != '\0' ||
10002                             vf_id >= dev_info.max_vfs) {
10003                                 printf("invalid parameter %s.\n", res->pf_vf);
10004                                 return;
10005                         }
10006                         entry.input.flow_ext.is_vf = 1;
10007                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10008                 } else {
10009                         printf("invalid parameter %s.\n", res->pf_vf);
10010                         return;
10011                 }
10012         }
10013
10014         /* set to report FD ID by default */
10015         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10016         entry.action.rx_queue = res->queue_id;
10017         entry.soft_id = res->fd_id_value;
10018         if (!strcmp(res->ops, "add"))
10019                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10020                                              RTE_ETH_FILTER_ADD, &entry);
10021         else if (!strcmp(res->ops, "del"))
10022                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10023                                              RTE_ETH_FILTER_DELETE, &entry);
10024         else
10025                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10026                                              RTE_ETH_FILTER_UPDATE, &entry);
10027         if (ret < 0)
10028                 printf("flow director programming error: (%s)\n",
10029                         strerror(-ret));
10030 }
10031
10032 cmdline_parse_token_string_t cmd_flow_director_filter =
10033         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10034                                  flow_director_filter, "flow_director_filter");
10035 cmdline_parse_token_num_t cmd_flow_director_port_id =
10036         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10037                               port_id, UINT16);
10038 cmdline_parse_token_string_t cmd_flow_director_ops =
10039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10040                                  ops, "add#del#update");
10041 cmdline_parse_token_string_t cmd_flow_director_flow =
10042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10043                                  flow, "flow");
10044 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10046                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10047                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10048 cmdline_parse_token_string_t cmd_flow_director_ether =
10049         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10050                                  ether, "ether");
10051 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10052         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10053                               ether_type, UINT16);
10054 cmdline_parse_token_string_t cmd_flow_director_src =
10055         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10056                                  src, "src");
10057 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10058         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10059                                  ip_src);
10060 cmdline_parse_token_num_t cmd_flow_director_port_src =
10061         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10062                               port_src, UINT16);
10063 cmdline_parse_token_string_t cmd_flow_director_dst =
10064         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10065                                  dst, "dst");
10066 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10067         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10068                                  ip_dst);
10069 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10070         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10071                               port_dst, UINT16);
10072 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10073         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10074                                   verify_tag, "verify_tag");
10075 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10076         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10077                               verify_tag_value, UINT32);
10078 cmdline_parse_token_string_t cmd_flow_director_tos =
10079         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10080                                  tos, "tos");
10081 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10082         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10083                               tos_value, UINT8);
10084 cmdline_parse_token_string_t cmd_flow_director_proto =
10085         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10086                                  proto, "proto");
10087 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10088         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10089                               proto_value, UINT8);
10090 cmdline_parse_token_string_t cmd_flow_director_ttl =
10091         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10092                                  ttl, "ttl");
10093 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10094         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10095                               ttl_value, UINT8);
10096 cmdline_parse_token_string_t cmd_flow_director_vlan =
10097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10098                                  vlan, "vlan");
10099 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10100         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10101                               vlan_value, UINT16);
10102 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10103         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10104                                  flexbytes, "flexbytes");
10105 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10106         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10107                               flexbytes_value, NULL);
10108 cmdline_parse_token_string_t cmd_flow_director_drop =
10109         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10110                                  drop, "drop#fwd");
10111 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10112         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10113                               pf_vf, NULL);
10114 cmdline_parse_token_string_t cmd_flow_director_queue =
10115         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10116                                  queue, "queue");
10117 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10118         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10119                               queue_id, UINT16);
10120 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10121         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10122                                  fd_id, "fd_id");
10123 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10124         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10125                               fd_id_value, UINT32);
10126
10127 cmdline_parse_token_string_t cmd_flow_director_mode =
10128         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10129                                  mode, "mode");
10130 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10131         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10132                                  mode_value, "IP");
10133 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10135                                  mode_value, "MAC-VLAN");
10136 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10137         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10138                                  mode_value, "Tunnel");
10139 cmdline_parse_token_string_t cmd_flow_director_mac =
10140         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10141                                  mac, "mac");
10142 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10143         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10144                                     mac_addr);
10145 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10146         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10147                                  tunnel, "tunnel");
10148 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10150                                  tunnel_type, "NVGRE#VxLAN");
10151 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10153                                  tunnel_id, "tunnel-id");
10154 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10155         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10156                               tunnel_id_value, UINT32);
10157
10158 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10159         .f = cmd_flow_director_filter_parsed,
10160         .data = NULL,
10161         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10162                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10163                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10164                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10165                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10166                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
10167                 "fd_id <fd_id_value>: "
10168                 "Add or delete an ip flow director entry on NIC",
10169         .tokens = {
10170                 (void *)&cmd_flow_director_filter,
10171                 (void *)&cmd_flow_director_port_id,
10172                 (void *)&cmd_flow_director_mode,
10173                 (void *)&cmd_flow_director_mode_ip,
10174                 (void *)&cmd_flow_director_ops,
10175                 (void *)&cmd_flow_director_flow,
10176                 (void *)&cmd_flow_director_flow_type,
10177                 (void *)&cmd_flow_director_src,
10178                 (void *)&cmd_flow_director_ip_src,
10179                 (void *)&cmd_flow_director_dst,
10180                 (void *)&cmd_flow_director_ip_dst,
10181                 (void *)&cmd_flow_director_tos,
10182                 (void *)&cmd_flow_director_tos_value,
10183                 (void *)&cmd_flow_director_proto,
10184                 (void *)&cmd_flow_director_proto_value,
10185                 (void *)&cmd_flow_director_ttl,
10186                 (void *)&cmd_flow_director_ttl_value,
10187                 (void *)&cmd_flow_director_vlan,
10188                 (void *)&cmd_flow_director_vlan_value,
10189                 (void *)&cmd_flow_director_flexbytes,
10190                 (void *)&cmd_flow_director_flexbytes_value,
10191                 (void *)&cmd_flow_director_drop,
10192                 (void *)&cmd_flow_director_pf_vf,
10193                 (void *)&cmd_flow_director_queue,
10194                 (void *)&cmd_flow_director_queue_id,
10195                 (void *)&cmd_flow_director_fd_id,
10196                 (void *)&cmd_flow_director_fd_id_value,
10197                 NULL,
10198         },
10199 };
10200
10201 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10202         .f = cmd_flow_director_filter_parsed,
10203         .data = NULL,
10204         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10205                 "director entry on NIC",
10206         .tokens = {
10207                 (void *)&cmd_flow_director_filter,
10208                 (void *)&cmd_flow_director_port_id,
10209                 (void *)&cmd_flow_director_mode,
10210                 (void *)&cmd_flow_director_mode_ip,
10211                 (void *)&cmd_flow_director_ops,
10212                 (void *)&cmd_flow_director_flow,
10213                 (void *)&cmd_flow_director_flow_type,
10214                 (void *)&cmd_flow_director_src,
10215                 (void *)&cmd_flow_director_ip_src,
10216                 (void *)&cmd_flow_director_port_src,
10217                 (void *)&cmd_flow_director_dst,
10218                 (void *)&cmd_flow_director_ip_dst,
10219                 (void *)&cmd_flow_director_port_dst,
10220                 (void *)&cmd_flow_director_tos,
10221                 (void *)&cmd_flow_director_tos_value,
10222                 (void *)&cmd_flow_director_ttl,
10223                 (void *)&cmd_flow_director_ttl_value,
10224                 (void *)&cmd_flow_director_vlan,
10225                 (void *)&cmd_flow_director_vlan_value,
10226                 (void *)&cmd_flow_director_flexbytes,
10227                 (void *)&cmd_flow_director_flexbytes_value,
10228                 (void *)&cmd_flow_director_drop,
10229                 (void *)&cmd_flow_director_pf_vf,
10230                 (void *)&cmd_flow_director_queue,
10231                 (void *)&cmd_flow_director_queue_id,
10232                 (void *)&cmd_flow_director_fd_id,
10233                 (void *)&cmd_flow_director_fd_id_value,
10234                 NULL,
10235         },
10236 };
10237
10238 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10239         .f = cmd_flow_director_filter_parsed,
10240         .data = NULL,
10241         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10242                 "director entry on NIC",
10243         .tokens = {
10244                 (void *)&cmd_flow_director_filter,
10245                 (void *)&cmd_flow_director_port_id,
10246                 (void *)&cmd_flow_director_mode,
10247                 (void *)&cmd_flow_director_mode_ip,
10248                 (void *)&cmd_flow_director_ops,
10249                 (void *)&cmd_flow_director_flow,
10250                 (void *)&cmd_flow_director_flow_type,
10251                 (void *)&cmd_flow_director_src,
10252                 (void *)&cmd_flow_director_ip_src,
10253                 (void *)&cmd_flow_director_port_dst,
10254                 (void *)&cmd_flow_director_dst,
10255                 (void *)&cmd_flow_director_ip_dst,
10256                 (void *)&cmd_flow_director_port_dst,
10257                 (void *)&cmd_flow_director_verify_tag,
10258                 (void *)&cmd_flow_director_verify_tag_value,
10259                 (void *)&cmd_flow_director_tos,
10260                 (void *)&cmd_flow_director_tos_value,
10261                 (void *)&cmd_flow_director_ttl,
10262                 (void *)&cmd_flow_director_ttl_value,
10263                 (void *)&cmd_flow_director_vlan,
10264                 (void *)&cmd_flow_director_vlan_value,
10265                 (void *)&cmd_flow_director_flexbytes,
10266                 (void *)&cmd_flow_director_flexbytes_value,
10267                 (void *)&cmd_flow_director_drop,
10268                 (void *)&cmd_flow_director_pf_vf,
10269                 (void *)&cmd_flow_director_queue,
10270                 (void *)&cmd_flow_director_queue_id,
10271                 (void *)&cmd_flow_director_fd_id,
10272                 (void *)&cmd_flow_director_fd_id_value,
10273                 NULL,
10274         },
10275 };
10276
10277 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10278         .f = cmd_flow_director_filter_parsed,
10279         .data = NULL,
10280         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10281                 "director entry on NIC",
10282         .tokens = {
10283                 (void *)&cmd_flow_director_filter,
10284                 (void *)&cmd_flow_director_port_id,
10285                 (void *)&cmd_flow_director_mode,
10286                 (void *)&cmd_flow_director_mode_ip,
10287                 (void *)&cmd_flow_director_ops,
10288                 (void *)&cmd_flow_director_flow,
10289                 (void *)&cmd_flow_director_flow_type,
10290                 (void *)&cmd_flow_director_ether,
10291                 (void *)&cmd_flow_director_ether_type,
10292                 (void *)&cmd_flow_director_flexbytes,
10293                 (void *)&cmd_flow_director_flexbytes_value,
10294                 (void *)&cmd_flow_director_drop,
10295                 (void *)&cmd_flow_director_pf_vf,
10296                 (void *)&cmd_flow_director_queue,
10297                 (void *)&cmd_flow_director_queue_id,
10298                 (void *)&cmd_flow_director_fd_id,
10299                 (void *)&cmd_flow_director_fd_id_value,
10300                 NULL,
10301         },
10302 };
10303
10304 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10305         .f = cmd_flow_director_filter_parsed,
10306         .data = NULL,
10307         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10308                 "director entry on NIC",
10309         .tokens = {
10310                 (void *)&cmd_flow_director_filter,
10311                 (void *)&cmd_flow_director_port_id,
10312                 (void *)&cmd_flow_director_mode,
10313                 (void *)&cmd_flow_director_mode_mac_vlan,
10314                 (void *)&cmd_flow_director_ops,
10315                 (void *)&cmd_flow_director_mac,
10316                 (void *)&cmd_flow_director_mac_addr,
10317                 (void *)&cmd_flow_director_vlan,
10318                 (void *)&cmd_flow_director_vlan_value,
10319                 (void *)&cmd_flow_director_flexbytes,
10320                 (void *)&cmd_flow_director_flexbytes_value,
10321                 (void *)&cmd_flow_director_drop,
10322                 (void *)&cmd_flow_director_queue,
10323                 (void *)&cmd_flow_director_queue_id,
10324                 (void *)&cmd_flow_director_fd_id,
10325                 (void *)&cmd_flow_director_fd_id_value,
10326                 NULL,
10327         },
10328 };
10329
10330 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10331         .f = cmd_flow_director_filter_parsed,
10332         .data = NULL,
10333         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10334                 "director entry on NIC",
10335         .tokens = {
10336                 (void *)&cmd_flow_director_filter,
10337                 (void *)&cmd_flow_director_port_id,
10338                 (void *)&cmd_flow_director_mode,
10339                 (void *)&cmd_flow_director_mode_tunnel,
10340                 (void *)&cmd_flow_director_ops,
10341                 (void *)&cmd_flow_director_mac,
10342                 (void *)&cmd_flow_director_mac_addr,
10343                 (void *)&cmd_flow_director_vlan,
10344                 (void *)&cmd_flow_director_vlan_value,
10345                 (void *)&cmd_flow_director_tunnel,
10346                 (void *)&cmd_flow_director_tunnel_type,
10347                 (void *)&cmd_flow_director_tunnel_id,
10348                 (void *)&cmd_flow_director_tunnel_id_value,
10349                 (void *)&cmd_flow_director_flexbytes,
10350                 (void *)&cmd_flow_director_flexbytes_value,
10351                 (void *)&cmd_flow_director_drop,
10352                 (void *)&cmd_flow_director_queue,
10353                 (void *)&cmd_flow_director_queue_id,
10354                 (void *)&cmd_flow_director_fd_id,
10355                 (void *)&cmd_flow_director_fd_id_value,
10356                 NULL,
10357         },
10358 };
10359
10360 struct cmd_flush_flow_director_result {
10361         cmdline_fixed_string_t flush_flow_director;
10362         portid_t port_id;
10363 };
10364
10365 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10366         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10367                                  flush_flow_director, "flush_flow_director");
10368 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10369         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10370                               port_id, UINT16);
10371
10372 static void
10373 cmd_flush_flow_director_parsed(void *parsed_result,
10374                           __attribute__((unused)) struct cmdline *cl,
10375                           __attribute__((unused)) void *data)
10376 {
10377         struct cmd_flow_director_result *res = parsed_result;
10378         int ret = 0;
10379
10380         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10381         if (ret < 0) {
10382                 printf("flow director is not supported on port %u.\n",
10383                         res->port_id);
10384                 return;
10385         }
10386
10387         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10388                         RTE_ETH_FILTER_FLUSH, NULL);
10389         if (ret < 0)
10390                 printf("flow director table flushing error: (%s)\n",
10391                         strerror(-ret));
10392 }
10393
10394 cmdline_parse_inst_t cmd_flush_flow_director = {
10395         .f = cmd_flush_flow_director_parsed,
10396         .data = NULL,
10397         .help_str = "flush_flow_director <port_id>: "
10398                 "Flush all flow director entries of a device on NIC",
10399         .tokens = {
10400                 (void *)&cmd_flush_flow_director_flush,
10401                 (void *)&cmd_flush_flow_director_port_id,
10402                 NULL,
10403         },
10404 };
10405
10406 /* *** deal with flow director mask *** */
10407 struct cmd_flow_director_mask_result {
10408         cmdline_fixed_string_t flow_director_mask;
10409         portid_t port_id;
10410         cmdline_fixed_string_t mode;
10411         cmdline_fixed_string_t mode_value;
10412         cmdline_fixed_string_t vlan;
10413         uint16_t vlan_mask;
10414         cmdline_fixed_string_t src_mask;
10415         cmdline_ipaddr_t ipv4_src;
10416         cmdline_ipaddr_t ipv6_src;
10417         uint16_t port_src;
10418         cmdline_fixed_string_t dst_mask;
10419         cmdline_ipaddr_t ipv4_dst;
10420         cmdline_ipaddr_t ipv6_dst;
10421         uint16_t port_dst;
10422         cmdline_fixed_string_t mac;
10423         uint8_t mac_addr_byte_mask;
10424         cmdline_fixed_string_t tunnel_id;
10425         uint32_t tunnel_id_mask;
10426         cmdline_fixed_string_t tunnel_type;
10427         uint8_t tunnel_type_mask;
10428 };
10429
10430 static void
10431 cmd_flow_director_mask_parsed(void *parsed_result,
10432                           __attribute__((unused)) struct cmdline *cl,
10433                           __attribute__((unused)) void *data)
10434 {
10435         struct cmd_flow_director_mask_result *res = parsed_result;
10436         struct rte_eth_fdir_masks *mask;
10437         struct rte_port *port;
10438
10439         if (res->port_id > nb_ports) {
10440                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10441                 return;
10442         }
10443
10444         port = &ports[res->port_id];
10445         /** Check if the port is not started **/
10446         if (port->port_status != RTE_PORT_STOPPED) {
10447                 printf("Please stop port %d first\n", res->port_id);
10448                 return;
10449         }
10450
10451         mask = &port->dev_conf.fdir_conf.mask;
10452
10453         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10454                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10455                         printf("Please set mode to MAC-VLAN.\n");
10456                         return;
10457                 }
10458
10459                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10460         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10461                 if (strcmp(res->mode_value, "Tunnel")) {
10462                         printf("Please set mode to Tunnel.\n");
10463                         return;
10464                 }
10465
10466                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10467                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10468                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10469                 mask->tunnel_type_mask = res->tunnel_type_mask;
10470         } else {
10471                 if (strcmp(res->mode_value, "IP")) {
10472                         printf("Please set mode to IP.\n");
10473                         return;
10474                 }
10475
10476                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10477                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10478                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10479                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10480                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10481                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10482                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10483         }
10484
10485         cmd_reconfig_device_queue(res->port_id, 1, 1);
10486 }
10487
10488 cmdline_parse_token_string_t cmd_flow_director_mask =
10489         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10490                                  flow_director_mask, "flow_director_mask");
10491 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10492         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10493                               port_id, UINT16);
10494 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10495         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10496                                  vlan, "vlan");
10497 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10498         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10499                               vlan_mask, UINT16);
10500 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10501         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10502                                  src_mask, "src_mask");
10503 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10504         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10505                                  ipv4_src);
10506 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10507         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10508                                  ipv6_src);
10509 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10510         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10511                               port_src, UINT16);
10512 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10513         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10514                                  dst_mask, "dst_mask");
10515 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10516         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10517                                  ipv4_dst);
10518 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10519         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10520                                  ipv6_dst);
10521 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10522         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10523                               port_dst, UINT16);
10524
10525 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10526         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10527                                  mode, "mode");
10528 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10529         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10530                                  mode_value, "IP");
10531 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10532         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10533                                  mode_value, "MAC-VLAN");
10534 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10535         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10536                                  mode_value, "Tunnel");
10537 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10538         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10539                                  mac, "mac");
10540 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10541         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10542                               mac_addr_byte_mask, UINT8);
10543 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10544         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10545                                  tunnel_type, "tunnel-type");
10546 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10547         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10548                               tunnel_type_mask, UINT8);
10549 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10550         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10551                                  tunnel_id, "tunnel-id");
10552 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10553         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10554                               tunnel_id_mask, UINT32);
10555
10556 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10557         .f = cmd_flow_director_mask_parsed,
10558         .data = NULL,
10559         .help_str = "flow_director_mask ... : "
10560                 "Set IP mode flow director's mask on NIC",
10561         .tokens = {
10562                 (void *)&cmd_flow_director_mask,
10563                 (void *)&cmd_flow_director_mask_port_id,
10564                 (void *)&cmd_flow_director_mask_mode,
10565                 (void *)&cmd_flow_director_mask_mode_ip,
10566                 (void *)&cmd_flow_director_mask_vlan,
10567                 (void *)&cmd_flow_director_mask_vlan_value,
10568                 (void *)&cmd_flow_director_mask_src,
10569                 (void *)&cmd_flow_director_mask_ipv4_src,
10570                 (void *)&cmd_flow_director_mask_ipv6_src,
10571                 (void *)&cmd_flow_director_mask_port_src,
10572                 (void *)&cmd_flow_director_mask_dst,
10573                 (void *)&cmd_flow_director_mask_ipv4_dst,
10574                 (void *)&cmd_flow_director_mask_ipv6_dst,
10575                 (void *)&cmd_flow_director_mask_port_dst,
10576                 NULL,
10577         },
10578 };
10579
10580 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10581         .f = cmd_flow_director_mask_parsed,
10582         .data = NULL,
10583         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10584                 "flow director's mask on NIC",
10585         .tokens = {
10586                 (void *)&cmd_flow_director_mask,
10587                 (void *)&cmd_flow_director_mask_port_id,
10588                 (void *)&cmd_flow_director_mask_mode,
10589                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10590                 (void *)&cmd_flow_director_mask_vlan,
10591                 (void *)&cmd_flow_director_mask_vlan_value,
10592                 NULL,
10593         },
10594 };
10595
10596 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10597         .f = cmd_flow_director_mask_parsed,
10598         .data = NULL,
10599         .help_str = "flow_director_mask ... : Set tunnel mode "
10600                 "flow director's mask on NIC",
10601         .tokens = {
10602                 (void *)&cmd_flow_director_mask,
10603                 (void *)&cmd_flow_director_mask_port_id,
10604                 (void *)&cmd_flow_director_mask_mode,
10605                 (void *)&cmd_flow_director_mask_mode_tunnel,
10606                 (void *)&cmd_flow_director_mask_vlan,
10607                 (void *)&cmd_flow_director_mask_vlan_value,
10608                 (void *)&cmd_flow_director_mask_mac,
10609                 (void *)&cmd_flow_director_mask_mac_value,
10610                 (void *)&cmd_flow_director_mask_tunnel_type,
10611                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10612                 (void *)&cmd_flow_director_mask_tunnel_id,
10613                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10614                 NULL,
10615         },
10616 };
10617
10618 /* *** deal with flow director mask on flexible payload *** */
10619 struct cmd_flow_director_flex_mask_result {
10620         cmdline_fixed_string_t flow_director_flexmask;
10621         portid_t port_id;
10622         cmdline_fixed_string_t flow;
10623         cmdline_fixed_string_t flow_type;
10624         cmdline_fixed_string_t mask;
10625 };
10626
10627 static void
10628 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10629                           __attribute__((unused)) struct cmdline *cl,
10630                           __attribute__((unused)) void *data)
10631 {
10632         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10633         struct rte_eth_fdir_info fdir_info;
10634         struct rte_eth_fdir_flex_mask flex_mask;
10635         struct rte_port *port;
10636         uint32_t flow_type_mask;
10637         uint16_t i;
10638         int ret;
10639
10640         if (res->port_id > nb_ports) {
10641                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10642                 return;
10643         }
10644
10645         port = &ports[res->port_id];
10646         /** Check if the port is not started **/
10647         if (port->port_status != RTE_PORT_STOPPED) {
10648                 printf("Please stop port %d first\n", res->port_id);
10649                 return;
10650         }
10651
10652         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10653         ret = parse_flexbytes(res->mask,
10654                         flex_mask.mask,
10655                         RTE_ETH_FDIR_MAX_FLEXLEN);
10656         if (ret < 0) {
10657                 printf("error: Cannot parse mask input.\n");
10658                 return;
10659         }
10660
10661         memset(&fdir_info, 0, sizeof(fdir_info));
10662         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10663                                 RTE_ETH_FILTER_INFO, &fdir_info);
10664         if (ret < 0) {
10665                 printf("Cannot get FDir filter info\n");
10666                 return;
10667         }
10668
10669         if (!strcmp(res->flow_type, "none")) {
10670                 /* means don't specify the flow type */
10671                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10672                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10673                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10674                                0, sizeof(struct rte_eth_fdir_flex_mask));
10675                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10676                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10677                                  &flex_mask,
10678                                  sizeof(struct rte_eth_fdir_flex_mask));
10679                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10680                 return;
10681         }
10682         flow_type_mask = fdir_info.flow_types_mask[0];
10683         if (!strcmp(res->flow_type, "all")) {
10684                 if (!flow_type_mask) {
10685                         printf("No flow type supported\n");
10686                         return;
10687                 }
10688                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10689                         if (flow_type_mask & (1 << i)) {
10690                                 flex_mask.flow_type = i;
10691                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10692                         }
10693                 }
10694                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10695                 return;
10696         }
10697         flex_mask.flow_type = str2flowtype(res->flow_type);
10698         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10699                 printf("Flow type %s not supported on port %d\n",
10700                                 res->flow_type, res->port_id);
10701                 return;
10702         }
10703         fdir_set_flex_mask(res->port_id, &flex_mask);
10704         cmd_reconfig_device_queue(res->port_id, 1, 1);
10705 }
10706
10707 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10709                                  flow_director_flexmask,
10710                                  "flow_director_flex_mask");
10711 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10712         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10713                               port_id, UINT16);
10714 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10715         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10716                                  flow, "flow");
10717 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10718         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10719                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10720                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10721 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10722         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10723                                  mask, NULL);
10724
10725 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10726         .f = cmd_flow_director_flex_mask_parsed,
10727         .data = NULL,
10728         .help_str = "flow_director_flex_mask ... : "
10729                 "Set flow director's flex mask on NIC",
10730         .tokens = {
10731                 (void *)&cmd_flow_director_flexmask,
10732                 (void *)&cmd_flow_director_flexmask_port_id,
10733                 (void *)&cmd_flow_director_flexmask_flow,
10734                 (void *)&cmd_flow_director_flexmask_flow_type,
10735                 (void *)&cmd_flow_director_flexmask_mask,
10736                 NULL,
10737         },
10738 };
10739
10740 /* *** deal with flow director flexible payload configuration *** */
10741 struct cmd_flow_director_flexpayload_result {
10742         cmdline_fixed_string_t flow_director_flexpayload;
10743         portid_t port_id;
10744         cmdline_fixed_string_t payload_layer;
10745         cmdline_fixed_string_t payload_cfg;
10746 };
10747
10748 static inline int
10749 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10750 {
10751         char s[256];
10752         const char *p, *p0 = q_arg;
10753         char *end;
10754         unsigned long int_fld;
10755         char *str_fld[max_num];
10756         int i;
10757         unsigned size;
10758         int ret = -1;
10759
10760         p = strchr(p0, '(');
10761         if (p == NULL)
10762                 return -1;
10763         ++p;
10764         p0 = strchr(p, ')');
10765         if (p0 == NULL)
10766                 return -1;
10767
10768         size = p0 - p;
10769         if (size >= sizeof(s))
10770                 return -1;
10771
10772         snprintf(s, sizeof(s), "%.*s", size, p);
10773         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10774         if (ret < 0 || ret > max_num)
10775                 return -1;
10776         for (i = 0; i < ret; i++) {
10777                 errno = 0;
10778                 int_fld = strtoul(str_fld[i], &end, 0);
10779                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10780                         return -1;
10781                 offsets[i] = (uint16_t)int_fld;
10782         }
10783         return ret;
10784 }
10785
10786 static void
10787 cmd_flow_director_flxpld_parsed(void *parsed_result,
10788                           __attribute__((unused)) struct cmdline *cl,
10789                           __attribute__((unused)) void *data)
10790 {
10791         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10792         struct rte_eth_flex_payload_cfg flex_cfg;
10793         struct rte_port *port;
10794         int ret = 0;
10795
10796         if (res->port_id > nb_ports) {
10797                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10798                 return;
10799         }
10800
10801         port = &ports[res->port_id];
10802         /** Check if the port is not started **/
10803         if (port->port_status != RTE_PORT_STOPPED) {
10804                 printf("Please stop port %d first\n", res->port_id);
10805                 return;
10806         }
10807
10808         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10809
10810         if (!strcmp(res->payload_layer, "raw"))
10811                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10812         else if (!strcmp(res->payload_layer, "l2"))
10813                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10814         else if (!strcmp(res->payload_layer, "l3"))
10815                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10816         else if (!strcmp(res->payload_layer, "l4"))
10817                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10818
10819         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10820                             RTE_ETH_FDIR_MAX_FLEXLEN);
10821         if (ret < 0) {
10822                 printf("error: Cannot parse flex payload input.\n");
10823                 return;
10824         }
10825
10826         fdir_set_flex_payload(res->port_id, &flex_cfg);
10827         cmd_reconfig_device_queue(res->port_id, 1, 1);
10828 }
10829
10830 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10831         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10832                                  flow_director_flexpayload,
10833                                  "flow_director_flex_payload");
10834 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10836                               port_id, UINT16);
10837 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10839                                  payload_layer, "raw#l2#l3#l4");
10840 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10841         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10842                                  payload_cfg, NULL);
10843
10844 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10845         .f = cmd_flow_director_flxpld_parsed,
10846         .data = NULL,
10847         .help_str = "flow_director_flexpayload ... : "
10848                 "Set flow director's flex payload on NIC",
10849         .tokens = {
10850                 (void *)&cmd_flow_director_flexpayload,
10851                 (void *)&cmd_flow_director_flexpayload_port_id,
10852                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10853                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10854                 NULL,
10855         },
10856 };
10857
10858 /* Generic flow interface command. */
10859 extern cmdline_parse_inst_t cmd_flow;
10860
10861 /* *** Classification Filters Control *** */
10862 /* *** Get symmetric hash enable per port *** */
10863 struct cmd_get_sym_hash_ena_per_port_result {
10864         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10865         portid_t port_id;
10866 };
10867
10868 static void
10869 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10870                                  __rte_unused struct cmdline *cl,
10871                                  __rte_unused void *data)
10872 {
10873         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10874         struct rte_eth_hash_filter_info info;
10875         int ret;
10876
10877         if (rte_eth_dev_filter_supported(res->port_id,
10878                                 RTE_ETH_FILTER_HASH) < 0) {
10879                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10880                                                         res->port_id);
10881                 return;
10882         }
10883
10884         memset(&info, 0, sizeof(info));
10885         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10886         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10887                                                 RTE_ETH_FILTER_GET, &info);
10888
10889         if (ret < 0) {
10890                 printf("Cannot get symmetric hash enable per port "
10891                                         "on port %u\n", res->port_id);
10892                 return;
10893         }
10894
10895         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10896                                 "enabled" : "disabled", res->port_id);
10897 }
10898
10899 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10900         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10901                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10902 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10903         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10904                 port_id, UINT16);
10905
10906 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10907         .f = cmd_get_sym_hash_per_port_parsed,
10908         .data = NULL,
10909         .help_str = "get_sym_hash_ena_per_port <port_id>",
10910         .tokens = {
10911                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10912                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10913                 NULL,
10914         },
10915 };
10916
10917 /* *** Set symmetric hash enable per port *** */
10918 struct cmd_set_sym_hash_ena_per_port_result {
10919         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10920         cmdline_fixed_string_t enable;
10921         portid_t port_id;
10922 };
10923
10924 static void
10925 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10926                                  __rte_unused struct cmdline *cl,
10927                                  __rte_unused void *data)
10928 {
10929         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10930         struct rte_eth_hash_filter_info info;
10931         int ret;
10932
10933         if (rte_eth_dev_filter_supported(res->port_id,
10934                                 RTE_ETH_FILTER_HASH) < 0) {
10935                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10936                                                         res->port_id);
10937                 return;
10938         }
10939
10940         memset(&info, 0, sizeof(info));
10941         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10942         if (!strcmp(res->enable, "enable"))
10943                 info.info.enable = 1;
10944         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10945                                         RTE_ETH_FILTER_SET, &info);
10946         if (ret < 0) {
10947                 printf("Cannot set symmetric hash enable per port on "
10948                                         "port %u\n", res->port_id);
10949                 return;
10950         }
10951         printf("Symmetric hash has been set to %s on port %u\n",
10952                                         res->enable, res->port_id);
10953 }
10954
10955 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10956         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10957                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10958 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10959         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10960                 port_id, UINT16);
10961 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10962         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10963                 enable, "enable#disable");
10964
10965 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10966         .f = cmd_set_sym_hash_per_port_parsed,
10967         .data = NULL,
10968         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10969         .tokens = {
10970                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10971                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10972                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10973                 NULL,
10974         },
10975 };
10976
10977 /* Get global config of hash function */
10978 struct cmd_get_hash_global_config_result {
10979         cmdline_fixed_string_t get_hash_global_config;
10980         portid_t port_id;
10981 };
10982
10983 static char *
10984 flowtype_to_str(uint16_t ftype)
10985 {
10986         uint16_t i;
10987         static struct {
10988                 char str[16];
10989                 uint16_t ftype;
10990         } ftype_table[] = {
10991                 {"ipv4", RTE_ETH_FLOW_IPV4},
10992                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10993                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10994                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10995                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10996                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10997                 {"ipv6", RTE_ETH_FLOW_IPV6},
10998                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10999                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11000                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11001                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11002                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11003                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11004                 {"port", RTE_ETH_FLOW_PORT},
11005                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11006                 {"geneve", RTE_ETH_FLOW_GENEVE},
11007                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11008         };
11009
11010         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11011                 if (ftype_table[i].ftype == ftype)
11012                         return ftype_table[i].str;
11013         }
11014
11015         return NULL;
11016 }
11017
11018 static void
11019 cmd_get_hash_global_config_parsed(void *parsed_result,
11020                                   __rte_unused struct cmdline *cl,
11021                                   __rte_unused void *data)
11022 {
11023         struct cmd_get_hash_global_config_result *res = parsed_result;
11024         struct rte_eth_hash_filter_info info;
11025         uint32_t idx, offset;
11026         uint16_t i;
11027         char *str;
11028         int ret;
11029
11030         if (rte_eth_dev_filter_supported(res->port_id,
11031                         RTE_ETH_FILTER_HASH) < 0) {
11032                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11033                                                         res->port_id);
11034                 return;
11035         }
11036
11037         memset(&info, 0, sizeof(info));
11038         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11039         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11040                                         RTE_ETH_FILTER_GET, &info);
11041         if (ret < 0) {
11042                 printf("Cannot get hash global configurations by port %d\n",
11043                                                         res->port_id);
11044                 return;
11045         }
11046
11047         switch (info.info.global_conf.hash_func) {
11048         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11049                 printf("Hash function is Toeplitz\n");
11050                 break;
11051         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11052                 printf("Hash function is Simple XOR\n");
11053                 break;
11054         default:
11055                 printf("Unknown hash function\n");
11056                 break;
11057         }
11058
11059         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11060                 idx = i / UINT32_BIT;
11061                 offset = i % UINT32_BIT;
11062                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11063                                                 (1UL << offset)))
11064                         continue;
11065                 str = flowtype_to_str(i);
11066                 if (!str)
11067                         continue;
11068                 printf("Symmetric hash is %s globally for flow type %s "
11069                                                         "by port %d\n",
11070                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11071                         (1UL << offset)) ? "enabled" : "disabled"), str,
11072                                                         res->port_id);
11073         }
11074 }
11075
11076 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11077         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11078                 get_hash_global_config, "get_hash_global_config");
11079 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11080         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11081                 port_id, UINT16);
11082
11083 cmdline_parse_inst_t cmd_get_hash_global_config = {
11084         .f = cmd_get_hash_global_config_parsed,
11085         .data = NULL,
11086         .help_str = "get_hash_global_config <port_id>",
11087         .tokens = {
11088                 (void *)&cmd_get_hash_global_config_all,
11089                 (void *)&cmd_get_hash_global_config_port_id,
11090                 NULL,
11091         },
11092 };
11093
11094 /* Set global config of hash function */
11095 struct cmd_set_hash_global_config_result {
11096         cmdline_fixed_string_t set_hash_global_config;
11097         portid_t port_id;
11098         cmdline_fixed_string_t hash_func;
11099         cmdline_fixed_string_t flow_type;
11100         cmdline_fixed_string_t enable;
11101 };
11102
11103 static void
11104 cmd_set_hash_global_config_parsed(void *parsed_result,
11105                                   __rte_unused struct cmdline *cl,
11106                                   __rte_unused void *data)
11107 {
11108         struct cmd_set_hash_global_config_result *res = parsed_result;
11109         struct rte_eth_hash_filter_info info;
11110         uint32_t ftype, idx, offset;
11111         int ret;
11112
11113         if (rte_eth_dev_filter_supported(res->port_id,
11114                                 RTE_ETH_FILTER_HASH) < 0) {
11115                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11116                                                         res->port_id);
11117                 return;
11118         }
11119         memset(&info, 0, sizeof(info));
11120         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11121         if (!strcmp(res->hash_func, "toeplitz"))
11122                 info.info.global_conf.hash_func =
11123                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11124         else if (!strcmp(res->hash_func, "simple_xor"))
11125                 info.info.global_conf.hash_func =
11126                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11127         else if (!strcmp(res->hash_func, "default"))
11128                 info.info.global_conf.hash_func =
11129                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11130
11131         ftype = str2flowtype(res->flow_type);
11132         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11133         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11134         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11135         if (!strcmp(res->enable, "enable"))
11136                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11137                                                 (1UL << offset);
11138         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11139                                         RTE_ETH_FILTER_SET, &info);
11140         if (ret < 0)
11141                 printf("Cannot set global hash configurations by port %d\n",
11142                                                         res->port_id);
11143         else
11144                 printf("Global hash configurations have been set "
11145                         "succcessfully by port %d\n", res->port_id);
11146 }
11147
11148 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11149         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11150                 set_hash_global_config, "set_hash_global_config");
11151 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11152         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11153                 port_id, UINT16);
11154 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11155         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11156                 hash_func, "toeplitz#simple_xor#default");
11157 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11158         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11159                 flow_type,
11160                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11161                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11162 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11163         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11164                 enable, "enable#disable");
11165
11166 cmdline_parse_inst_t cmd_set_hash_global_config = {
11167         .f = cmd_set_hash_global_config_parsed,
11168         .data = NULL,
11169         .help_str = "set_hash_global_config <port_id> "
11170                 "toeplitz|simple_xor|default "
11171                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11172                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11173                 "l2_payload enable|disable",
11174         .tokens = {
11175                 (void *)&cmd_set_hash_global_config_all,
11176                 (void *)&cmd_set_hash_global_config_port_id,
11177                 (void *)&cmd_set_hash_global_config_hash_func,
11178                 (void *)&cmd_set_hash_global_config_flow_type,
11179                 (void *)&cmd_set_hash_global_config_enable,
11180                 NULL,
11181         },
11182 };
11183
11184 /* Set hash input set */
11185 struct cmd_set_hash_input_set_result {
11186         cmdline_fixed_string_t set_hash_input_set;
11187         portid_t port_id;
11188         cmdline_fixed_string_t flow_type;
11189         cmdline_fixed_string_t inset_field;
11190         cmdline_fixed_string_t select;
11191 };
11192
11193 static enum rte_eth_input_set_field
11194 str2inset(char *string)
11195 {
11196         uint16_t i;
11197
11198         static const struct {
11199                 char str[32];
11200                 enum rte_eth_input_set_field inset;
11201         } inset_table[] = {
11202                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11203                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11204                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11205                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11206                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11207                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11208                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11209                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11210                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11211                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11212                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11213                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11214                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11215                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11216                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11217                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11218                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11219                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11220                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11221                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11222                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11223                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11224                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11225                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11226                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11227                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11228                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11229                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11230                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11231                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11232                 {"none", RTE_ETH_INPUT_SET_NONE},
11233         };
11234
11235         for (i = 0; i < RTE_DIM(inset_table); i++) {
11236                 if (!strcmp(string, inset_table[i].str))
11237                         return inset_table[i].inset;
11238         }
11239
11240         return RTE_ETH_INPUT_SET_UNKNOWN;
11241 }
11242
11243 static void
11244 cmd_set_hash_input_set_parsed(void *parsed_result,
11245                               __rte_unused struct cmdline *cl,
11246                               __rte_unused void *data)
11247 {
11248         struct cmd_set_hash_input_set_result *res = parsed_result;
11249         struct rte_eth_hash_filter_info info;
11250
11251         memset(&info, 0, sizeof(info));
11252         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11253         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11254         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11255         info.info.input_set_conf.inset_size = 1;
11256         if (!strcmp(res->select, "select"))
11257                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11258         else if (!strcmp(res->select, "add"))
11259                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11260         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11261                                 RTE_ETH_FILTER_SET, &info);
11262 }
11263
11264 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11265         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11266                 set_hash_input_set, "set_hash_input_set");
11267 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11268         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11269                 port_id, UINT16);
11270 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11271         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11272                 flow_type, NULL);
11273 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11274         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11275                 inset_field,
11276                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11277                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11278                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11279                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11280                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11281                 "fld-8th#none");
11282 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11283         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11284                 select, "select#add");
11285
11286 cmdline_parse_inst_t cmd_set_hash_input_set = {
11287         .f = cmd_set_hash_input_set_parsed,
11288         .data = NULL,
11289         .help_str = "set_hash_input_set <port_id> "
11290         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11291         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11292         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11293         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11294         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11295         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11296         "fld-7th|fld-8th|none select|add",
11297         .tokens = {
11298                 (void *)&cmd_set_hash_input_set_cmd,
11299                 (void *)&cmd_set_hash_input_set_port_id,
11300                 (void *)&cmd_set_hash_input_set_flow_type,
11301                 (void *)&cmd_set_hash_input_set_field,
11302                 (void *)&cmd_set_hash_input_set_select,
11303                 NULL,
11304         },
11305 };
11306
11307 /* Set flow director input set */
11308 struct cmd_set_fdir_input_set_result {
11309         cmdline_fixed_string_t set_fdir_input_set;
11310         portid_t port_id;
11311         cmdline_fixed_string_t flow_type;
11312         cmdline_fixed_string_t inset_field;
11313         cmdline_fixed_string_t select;
11314 };
11315
11316 static void
11317 cmd_set_fdir_input_set_parsed(void *parsed_result,
11318         __rte_unused struct cmdline *cl,
11319         __rte_unused void *data)
11320 {
11321         struct cmd_set_fdir_input_set_result *res = parsed_result;
11322         struct rte_eth_fdir_filter_info info;
11323
11324         memset(&info, 0, sizeof(info));
11325         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11326         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11327         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11328         info.info.input_set_conf.inset_size = 1;
11329         if (!strcmp(res->select, "select"))
11330                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11331         else if (!strcmp(res->select, "add"))
11332                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11333         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11334                 RTE_ETH_FILTER_SET, &info);
11335 }
11336
11337 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11338         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11339         set_fdir_input_set, "set_fdir_input_set");
11340 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11341         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11342         port_id, UINT16);
11343 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11344         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11345         flow_type,
11346         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11347         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11348 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11349         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11350         inset_field,
11351         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11352         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11353         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11354         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11355         "sctp-veri-tag#none");
11356 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11357         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11358         select, "select#add");
11359
11360 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11361         .f = cmd_set_fdir_input_set_parsed,
11362         .data = NULL,
11363         .help_str = "set_fdir_input_set <port_id> "
11364         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11365         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11366         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11367         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11368         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11369         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11370         "sctp-veri-tag|none select|add",
11371         .tokens = {
11372                 (void *)&cmd_set_fdir_input_set_cmd,
11373                 (void *)&cmd_set_fdir_input_set_port_id,
11374                 (void *)&cmd_set_fdir_input_set_flow_type,
11375                 (void *)&cmd_set_fdir_input_set_field,
11376                 (void *)&cmd_set_fdir_input_set_select,
11377                 NULL,
11378         },
11379 };
11380
11381 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11382 struct cmd_mcast_addr_result {
11383         cmdline_fixed_string_t mcast_addr_cmd;
11384         cmdline_fixed_string_t what;
11385         uint16_t port_num;
11386         struct ether_addr mc_addr;
11387 };
11388
11389 static void cmd_mcast_addr_parsed(void *parsed_result,
11390                 __attribute__((unused)) struct cmdline *cl,
11391                 __attribute__((unused)) void *data)
11392 {
11393         struct cmd_mcast_addr_result *res = parsed_result;
11394
11395         if (!is_multicast_ether_addr(&res->mc_addr)) {
11396                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11397                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11398                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11399                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11400                 return;
11401         }
11402         if (strcmp(res->what, "add") == 0)
11403                 mcast_addr_add(res->port_num, &res->mc_addr);
11404         else
11405                 mcast_addr_remove(res->port_num, &res->mc_addr);
11406 }
11407
11408 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11409         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11410                                  mcast_addr_cmd, "mcast_addr");
11411 cmdline_parse_token_string_t cmd_mcast_addr_what =
11412         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11413                                  "add#remove");
11414 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11415         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11416 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11417         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11418
11419 cmdline_parse_inst_t cmd_mcast_addr = {
11420         .f = cmd_mcast_addr_parsed,
11421         .data = (void *)0,
11422         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11423                 "Add/Remove multicast MAC address on port_id",
11424         .tokens = {
11425                 (void *)&cmd_mcast_addr_cmd,
11426                 (void *)&cmd_mcast_addr_what,
11427                 (void *)&cmd_mcast_addr_portnum,
11428                 (void *)&cmd_mcast_addr_addr,
11429                 NULL,
11430         },
11431 };
11432
11433 /* l2 tunnel config
11434  * only support E-tag now.
11435  */
11436
11437 /* Ether type config */
11438 struct cmd_config_l2_tunnel_eth_type_result {
11439         cmdline_fixed_string_t port;
11440         cmdline_fixed_string_t config;
11441         cmdline_fixed_string_t all;
11442         uint8_t id;
11443         cmdline_fixed_string_t l2_tunnel;
11444         cmdline_fixed_string_t l2_tunnel_type;
11445         cmdline_fixed_string_t eth_type;
11446         uint16_t eth_type_val;
11447 };
11448
11449 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11450         TOKEN_STRING_INITIALIZER
11451                 (struct cmd_config_l2_tunnel_eth_type_result,
11452                  port, "port");
11453 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11454         TOKEN_STRING_INITIALIZER
11455                 (struct cmd_config_l2_tunnel_eth_type_result,
11456                  config, "config");
11457 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11458         TOKEN_STRING_INITIALIZER
11459                 (struct cmd_config_l2_tunnel_eth_type_result,
11460                  all, "all");
11461 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11462         TOKEN_NUM_INITIALIZER
11463                 (struct cmd_config_l2_tunnel_eth_type_result,
11464                  id, UINT8);
11465 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11466         TOKEN_STRING_INITIALIZER
11467                 (struct cmd_config_l2_tunnel_eth_type_result,
11468                  l2_tunnel, "l2-tunnel");
11469 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11470         TOKEN_STRING_INITIALIZER
11471                 (struct cmd_config_l2_tunnel_eth_type_result,
11472                  l2_tunnel_type, "E-tag");
11473 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11474         TOKEN_STRING_INITIALIZER
11475                 (struct cmd_config_l2_tunnel_eth_type_result,
11476                  eth_type, "ether-type");
11477 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11478         TOKEN_NUM_INITIALIZER
11479                 (struct cmd_config_l2_tunnel_eth_type_result,
11480                  eth_type_val, UINT16);
11481
11482 static enum rte_eth_tunnel_type
11483 str2fdir_l2_tunnel_type(char *string)
11484 {
11485         uint32_t i = 0;
11486
11487         static const struct {
11488                 char str[32];
11489                 enum rte_eth_tunnel_type type;
11490         } l2_tunnel_type_str[] = {
11491                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11492         };
11493
11494         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11495                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11496                         return l2_tunnel_type_str[i].type;
11497         }
11498         return RTE_TUNNEL_TYPE_NONE;
11499 }
11500
11501 /* ether type config for all ports */
11502 static void
11503 cmd_config_l2_tunnel_eth_type_all_parsed
11504         (void *parsed_result,
11505          __attribute__((unused)) struct cmdline *cl,
11506          __attribute__((unused)) void *data)
11507 {
11508         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11509         struct rte_eth_l2_tunnel_conf entry;
11510         portid_t pid;
11511
11512         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11513         entry.ether_type = res->eth_type_val;
11514
11515         RTE_ETH_FOREACH_DEV(pid) {
11516                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11517         }
11518 }
11519
11520 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11521         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11522         .data = NULL,
11523         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11524         .tokens = {
11525                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11526                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11527                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11528                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11529                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11530                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11531                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11532                 NULL,
11533         },
11534 };
11535
11536 /* ether type config for a specific port */
11537 static void
11538 cmd_config_l2_tunnel_eth_type_specific_parsed(
11539         void *parsed_result,
11540         __attribute__((unused)) struct cmdline *cl,
11541         __attribute__((unused)) void *data)
11542 {
11543         struct cmd_config_l2_tunnel_eth_type_result *res =
11544                  parsed_result;
11545         struct rte_eth_l2_tunnel_conf entry;
11546
11547         if (port_id_is_invalid(res->id, ENABLED_WARN))
11548                 return;
11549
11550         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11551         entry.ether_type = res->eth_type_val;
11552
11553         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11554 }
11555
11556 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11557         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11558         .data = NULL,
11559         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11560         .tokens = {
11561                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11562                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11563                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11564                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11565                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11566                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11567                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11568                 NULL,
11569         },
11570 };
11571
11572 /* Enable/disable l2 tunnel */
11573 struct cmd_config_l2_tunnel_en_dis_result {
11574         cmdline_fixed_string_t port;
11575         cmdline_fixed_string_t config;
11576         cmdline_fixed_string_t all;
11577         uint8_t id;
11578         cmdline_fixed_string_t l2_tunnel;
11579         cmdline_fixed_string_t l2_tunnel_type;
11580         cmdline_fixed_string_t en_dis;
11581 };
11582
11583 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11584         TOKEN_STRING_INITIALIZER
11585                 (struct cmd_config_l2_tunnel_en_dis_result,
11586                  port, "port");
11587 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11588         TOKEN_STRING_INITIALIZER
11589                 (struct cmd_config_l2_tunnel_en_dis_result,
11590                  config, "config");
11591 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11592         TOKEN_STRING_INITIALIZER
11593                 (struct cmd_config_l2_tunnel_en_dis_result,
11594                  all, "all");
11595 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11596         TOKEN_NUM_INITIALIZER
11597                 (struct cmd_config_l2_tunnel_en_dis_result,
11598                  id, UINT8);
11599 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11600         TOKEN_STRING_INITIALIZER
11601                 (struct cmd_config_l2_tunnel_en_dis_result,
11602                  l2_tunnel, "l2-tunnel");
11603 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11604         TOKEN_STRING_INITIALIZER
11605                 (struct cmd_config_l2_tunnel_en_dis_result,
11606                  l2_tunnel_type, "E-tag");
11607 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11608         TOKEN_STRING_INITIALIZER
11609                 (struct cmd_config_l2_tunnel_en_dis_result,
11610                  en_dis, "enable#disable");
11611
11612 /* enable/disable l2 tunnel for all ports */
11613 static void
11614 cmd_config_l2_tunnel_en_dis_all_parsed(
11615         void *parsed_result,
11616         __attribute__((unused)) struct cmdline *cl,
11617         __attribute__((unused)) void *data)
11618 {
11619         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11620         struct rte_eth_l2_tunnel_conf entry;
11621         portid_t pid;
11622         uint8_t en;
11623
11624         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11625
11626         if (!strcmp("enable", res->en_dis))
11627                 en = 1;
11628         else
11629                 en = 0;
11630
11631         RTE_ETH_FOREACH_DEV(pid) {
11632                 rte_eth_dev_l2_tunnel_offload_set(pid,
11633                                                   &entry,
11634                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11635                                                   en);
11636         }
11637 }
11638
11639 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11640         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11641         .data = NULL,
11642         .help_str = "port config all l2-tunnel E-tag enable|disable",
11643         .tokens = {
11644                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11645                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11646                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11647                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11648                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11649                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11650                 NULL,
11651         },
11652 };
11653
11654 /* enable/disable l2 tunnel for a port */
11655 static void
11656 cmd_config_l2_tunnel_en_dis_specific_parsed(
11657         void *parsed_result,
11658         __attribute__((unused)) struct cmdline *cl,
11659         __attribute__((unused)) void *data)
11660 {
11661         struct cmd_config_l2_tunnel_en_dis_result *res =
11662                 parsed_result;
11663         struct rte_eth_l2_tunnel_conf entry;
11664
11665         if (port_id_is_invalid(res->id, ENABLED_WARN))
11666                 return;
11667
11668         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11669
11670         if (!strcmp("enable", res->en_dis))
11671                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11672                                                   &entry,
11673                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11674                                                   1);
11675         else
11676                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11677                                                   &entry,
11678                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11679                                                   0);
11680 }
11681
11682 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11683         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11684         .data = NULL,
11685         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11686         .tokens = {
11687                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11688                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11689                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11690                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11691                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11692                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11693                 NULL,
11694         },
11695 };
11696
11697 /* E-tag configuration */
11698
11699 /* Common result structure for all E-tag configuration */
11700 struct cmd_config_e_tag_result {
11701         cmdline_fixed_string_t e_tag;
11702         cmdline_fixed_string_t set;
11703         cmdline_fixed_string_t insertion;
11704         cmdline_fixed_string_t stripping;
11705         cmdline_fixed_string_t forwarding;
11706         cmdline_fixed_string_t filter;
11707         cmdline_fixed_string_t add;
11708         cmdline_fixed_string_t del;
11709         cmdline_fixed_string_t on;
11710         cmdline_fixed_string_t off;
11711         cmdline_fixed_string_t on_off;
11712         cmdline_fixed_string_t port_tag_id;
11713         uint32_t port_tag_id_val;
11714         cmdline_fixed_string_t e_tag_id;
11715         uint16_t e_tag_id_val;
11716         cmdline_fixed_string_t dst_pool;
11717         uint8_t dst_pool_val;
11718         cmdline_fixed_string_t port;
11719         portid_t port_id;
11720         cmdline_fixed_string_t vf;
11721         uint8_t vf_id;
11722 };
11723
11724 /* Common CLI fields for all E-tag configuration */
11725 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11726         TOKEN_STRING_INITIALIZER
11727                 (struct cmd_config_e_tag_result,
11728                  e_tag, "E-tag");
11729 cmdline_parse_token_string_t cmd_config_e_tag_set =
11730         TOKEN_STRING_INITIALIZER
11731                 (struct cmd_config_e_tag_result,
11732                  set, "set");
11733 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11734         TOKEN_STRING_INITIALIZER
11735                 (struct cmd_config_e_tag_result,
11736                  insertion, "insertion");
11737 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11738         TOKEN_STRING_INITIALIZER
11739                 (struct cmd_config_e_tag_result,
11740                  stripping, "stripping");
11741 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11742         TOKEN_STRING_INITIALIZER
11743                 (struct cmd_config_e_tag_result,
11744                  forwarding, "forwarding");
11745 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11746         TOKEN_STRING_INITIALIZER
11747                 (struct cmd_config_e_tag_result,
11748                  filter, "filter");
11749 cmdline_parse_token_string_t cmd_config_e_tag_add =
11750         TOKEN_STRING_INITIALIZER
11751                 (struct cmd_config_e_tag_result,
11752                  add, "add");
11753 cmdline_parse_token_string_t cmd_config_e_tag_del =
11754         TOKEN_STRING_INITIALIZER
11755                 (struct cmd_config_e_tag_result,
11756                  del, "del");
11757 cmdline_parse_token_string_t cmd_config_e_tag_on =
11758         TOKEN_STRING_INITIALIZER
11759                 (struct cmd_config_e_tag_result,
11760                  on, "on");
11761 cmdline_parse_token_string_t cmd_config_e_tag_off =
11762         TOKEN_STRING_INITIALIZER
11763                 (struct cmd_config_e_tag_result,
11764                  off, "off");
11765 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11766         TOKEN_STRING_INITIALIZER
11767                 (struct cmd_config_e_tag_result,
11768                  on_off, "on#off");
11769 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11770         TOKEN_STRING_INITIALIZER
11771                 (struct cmd_config_e_tag_result,
11772                  port_tag_id, "port-tag-id");
11773 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11774         TOKEN_NUM_INITIALIZER
11775                 (struct cmd_config_e_tag_result,
11776                  port_tag_id_val, UINT32);
11777 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11778         TOKEN_STRING_INITIALIZER
11779                 (struct cmd_config_e_tag_result,
11780                  e_tag_id, "e-tag-id");
11781 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11782         TOKEN_NUM_INITIALIZER
11783                 (struct cmd_config_e_tag_result,
11784                  e_tag_id_val, UINT16);
11785 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_config_e_tag_result,
11788                  dst_pool, "dst-pool");
11789 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11790         TOKEN_NUM_INITIALIZER
11791                 (struct cmd_config_e_tag_result,
11792                  dst_pool_val, UINT8);
11793 cmdline_parse_token_string_t cmd_config_e_tag_port =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_config_e_tag_result,
11796                  port, "port");
11797 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11798         TOKEN_NUM_INITIALIZER
11799                 (struct cmd_config_e_tag_result,
11800                  port_id, UINT16);
11801 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_config_e_tag_result,
11804                  vf, "vf");
11805 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11806         TOKEN_NUM_INITIALIZER
11807                 (struct cmd_config_e_tag_result,
11808                  vf_id, UINT8);
11809
11810 /* E-tag insertion configuration */
11811 static void
11812 cmd_config_e_tag_insertion_en_parsed(
11813         void *parsed_result,
11814         __attribute__((unused)) struct cmdline *cl,
11815         __attribute__((unused)) void *data)
11816 {
11817         struct cmd_config_e_tag_result *res =
11818                 parsed_result;
11819         struct rte_eth_l2_tunnel_conf entry;
11820
11821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11822                 return;
11823
11824         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11825         entry.tunnel_id = res->port_tag_id_val;
11826         entry.vf_id = res->vf_id;
11827         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11828                                           &entry,
11829                                           ETH_L2_TUNNEL_INSERTION_MASK,
11830                                           1);
11831 }
11832
11833 static void
11834 cmd_config_e_tag_insertion_dis_parsed(
11835         void *parsed_result,
11836         __attribute__((unused)) struct cmdline *cl,
11837         __attribute__((unused)) void *data)
11838 {
11839         struct cmd_config_e_tag_result *res =
11840                 parsed_result;
11841         struct rte_eth_l2_tunnel_conf entry;
11842
11843         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11844                 return;
11845
11846         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11847         entry.vf_id = res->vf_id;
11848
11849         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11850                                           &entry,
11851                                           ETH_L2_TUNNEL_INSERTION_MASK,
11852                                           0);
11853 }
11854
11855 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11856         .f = cmd_config_e_tag_insertion_en_parsed,
11857         .data = NULL,
11858         .help_str = "E-tag ... : E-tag insertion enable",
11859         .tokens = {
11860                 (void *)&cmd_config_e_tag_e_tag,
11861                 (void *)&cmd_config_e_tag_set,
11862                 (void *)&cmd_config_e_tag_insertion,
11863                 (void *)&cmd_config_e_tag_on,
11864                 (void *)&cmd_config_e_tag_port_tag_id,
11865                 (void *)&cmd_config_e_tag_port_tag_id_val,
11866                 (void *)&cmd_config_e_tag_port,
11867                 (void *)&cmd_config_e_tag_port_id,
11868                 (void *)&cmd_config_e_tag_vf,
11869                 (void *)&cmd_config_e_tag_vf_id,
11870                 NULL,
11871         },
11872 };
11873
11874 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11875         .f = cmd_config_e_tag_insertion_dis_parsed,
11876         .data = NULL,
11877         .help_str = "E-tag ... : E-tag insertion disable",
11878         .tokens = {
11879                 (void *)&cmd_config_e_tag_e_tag,
11880                 (void *)&cmd_config_e_tag_set,
11881                 (void *)&cmd_config_e_tag_insertion,
11882                 (void *)&cmd_config_e_tag_off,
11883                 (void *)&cmd_config_e_tag_port,
11884                 (void *)&cmd_config_e_tag_port_id,
11885                 (void *)&cmd_config_e_tag_vf,
11886                 (void *)&cmd_config_e_tag_vf_id,
11887                 NULL,
11888         },
11889 };
11890
11891 /* E-tag stripping configuration */
11892 static void
11893 cmd_config_e_tag_stripping_parsed(
11894         void *parsed_result,
11895         __attribute__((unused)) struct cmdline *cl,
11896         __attribute__((unused)) void *data)
11897 {
11898         struct cmd_config_e_tag_result *res =
11899                 parsed_result;
11900         struct rte_eth_l2_tunnel_conf entry;
11901
11902         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11903                 return;
11904
11905         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11906
11907         if (!strcmp(res->on_off, "on"))
11908                 rte_eth_dev_l2_tunnel_offload_set
11909                         (res->port_id,
11910                          &entry,
11911                          ETH_L2_TUNNEL_STRIPPING_MASK,
11912                          1);
11913         else
11914                 rte_eth_dev_l2_tunnel_offload_set
11915                         (res->port_id,
11916                          &entry,
11917                          ETH_L2_TUNNEL_STRIPPING_MASK,
11918                          0);
11919 }
11920
11921 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11922         .f = cmd_config_e_tag_stripping_parsed,
11923         .data = NULL,
11924         .help_str = "E-tag ... : E-tag stripping enable/disable",
11925         .tokens = {
11926                 (void *)&cmd_config_e_tag_e_tag,
11927                 (void *)&cmd_config_e_tag_set,
11928                 (void *)&cmd_config_e_tag_stripping,
11929                 (void *)&cmd_config_e_tag_on_off,
11930                 (void *)&cmd_config_e_tag_port,
11931                 (void *)&cmd_config_e_tag_port_id,
11932                 NULL,
11933         },
11934 };
11935
11936 /* E-tag forwarding configuration */
11937 static void
11938 cmd_config_e_tag_forwarding_parsed(
11939         void *parsed_result,
11940         __attribute__((unused)) struct cmdline *cl,
11941         __attribute__((unused)) void *data)
11942 {
11943         struct cmd_config_e_tag_result *res = parsed_result;
11944         struct rte_eth_l2_tunnel_conf entry;
11945
11946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11947                 return;
11948
11949         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11950
11951         if (!strcmp(res->on_off, "on"))
11952                 rte_eth_dev_l2_tunnel_offload_set
11953                         (res->port_id,
11954                          &entry,
11955                          ETH_L2_TUNNEL_FORWARDING_MASK,
11956                          1);
11957         else
11958                 rte_eth_dev_l2_tunnel_offload_set
11959                         (res->port_id,
11960                          &entry,
11961                          ETH_L2_TUNNEL_FORWARDING_MASK,
11962                          0);
11963 }
11964
11965 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11966         .f = cmd_config_e_tag_forwarding_parsed,
11967         .data = NULL,
11968         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11969         .tokens = {
11970                 (void *)&cmd_config_e_tag_e_tag,
11971                 (void *)&cmd_config_e_tag_set,
11972                 (void *)&cmd_config_e_tag_forwarding,
11973                 (void *)&cmd_config_e_tag_on_off,
11974                 (void *)&cmd_config_e_tag_port,
11975                 (void *)&cmd_config_e_tag_port_id,
11976                 NULL,
11977         },
11978 };
11979
11980 /* E-tag filter configuration */
11981 static void
11982 cmd_config_e_tag_filter_add_parsed(
11983         void *parsed_result,
11984         __attribute__((unused)) struct cmdline *cl,
11985         __attribute__((unused)) void *data)
11986 {
11987         struct cmd_config_e_tag_result *res = parsed_result;
11988         struct rte_eth_l2_tunnel_conf entry;
11989         int ret = 0;
11990
11991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11992                 return;
11993
11994         if (res->e_tag_id_val > 0x3fff) {
11995                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11996                 return;
11997         }
11998
11999         ret = rte_eth_dev_filter_supported(res->port_id,
12000                                            RTE_ETH_FILTER_L2_TUNNEL);
12001         if (ret < 0) {
12002                 printf("E-tag filter is not supported on port %u.\n",
12003                        res->port_id);
12004                 return;
12005         }
12006
12007         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12008         entry.tunnel_id = res->e_tag_id_val;
12009         entry.pool = res->dst_pool_val;
12010
12011         ret = rte_eth_dev_filter_ctrl(res->port_id,
12012                                       RTE_ETH_FILTER_L2_TUNNEL,
12013                                       RTE_ETH_FILTER_ADD,
12014                                       &entry);
12015         if (ret < 0)
12016                 printf("E-tag filter programming error: (%s)\n",
12017                        strerror(-ret));
12018 }
12019
12020 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12021         .f = cmd_config_e_tag_filter_add_parsed,
12022         .data = NULL,
12023         .help_str = "E-tag ... : E-tag filter add",
12024         .tokens = {
12025                 (void *)&cmd_config_e_tag_e_tag,
12026                 (void *)&cmd_config_e_tag_set,
12027                 (void *)&cmd_config_e_tag_filter,
12028                 (void *)&cmd_config_e_tag_add,
12029                 (void *)&cmd_config_e_tag_e_tag_id,
12030                 (void *)&cmd_config_e_tag_e_tag_id_val,
12031                 (void *)&cmd_config_e_tag_dst_pool,
12032                 (void *)&cmd_config_e_tag_dst_pool_val,
12033                 (void *)&cmd_config_e_tag_port,
12034                 (void *)&cmd_config_e_tag_port_id,
12035                 NULL,
12036         },
12037 };
12038
12039 static void
12040 cmd_config_e_tag_filter_del_parsed(
12041         void *parsed_result,
12042         __attribute__((unused)) struct cmdline *cl,
12043         __attribute__((unused)) void *data)
12044 {
12045         struct cmd_config_e_tag_result *res = parsed_result;
12046         struct rte_eth_l2_tunnel_conf entry;
12047         int ret = 0;
12048
12049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12050                 return;
12051
12052         if (res->e_tag_id_val > 0x3fff) {
12053                 printf("e-tag-id must be less than 0x3fff.\n");
12054                 return;
12055         }
12056
12057         ret = rte_eth_dev_filter_supported(res->port_id,
12058                                            RTE_ETH_FILTER_L2_TUNNEL);
12059         if (ret < 0) {
12060                 printf("E-tag filter is not supported on port %u.\n",
12061                        res->port_id);
12062                 return;
12063         }
12064
12065         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12066         entry.tunnel_id = res->e_tag_id_val;
12067
12068         ret = rte_eth_dev_filter_ctrl(res->port_id,
12069                                       RTE_ETH_FILTER_L2_TUNNEL,
12070                                       RTE_ETH_FILTER_DELETE,
12071                                       &entry);
12072         if (ret < 0)
12073                 printf("E-tag filter programming error: (%s)\n",
12074                        strerror(-ret));
12075 }
12076
12077 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12078         .f = cmd_config_e_tag_filter_del_parsed,
12079         .data = NULL,
12080         .help_str = "E-tag ... : E-tag filter delete",
12081         .tokens = {
12082                 (void *)&cmd_config_e_tag_e_tag,
12083                 (void *)&cmd_config_e_tag_set,
12084                 (void *)&cmd_config_e_tag_filter,
12085                 (void *)&cmd_config_e_tag_del,
12086                 (void *)&cmd_config_e_tag_e_tag_id,
12087                 (void *)&cmd_config_e_tag_e_tag_id_val,
12088                 (void *)&cmd_config_e_tag_port,
12089                 (void *)&cmd_config_e_tag_port_id,
12090                 NULL,
12091         },
12092 };
12093
12094 /* vf vlan anti spoof configuration */
12095
12096 /* Common result structure for vf vlan anti spoof */
12097 struct cmd_vf_vlan_anti_spoof_result {
12098         cmdline_fixed_string_t set;
12099         cmdline_fixed_string_t vf;
12100         cmdline_fixed_string_t vlan;
12101         cmdline_fixed_string_t antispoof;
12102         portid_t port_id;
12103         uint32_t vf_id;
12104         cmdline_fixed_string_t on_off;
12105 };
12106
12107 /* Common CLI fields for vf vlan anti spoof enable disable */
12108 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12109         TOKEN_STRING_INITIALIZER
12110                 (struct cmd_vf_vlan_anti_spoof_result,
12111                  set, "set");
12112 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12113         TOKEN_STRING_INITIALIZER
12114                 (struct cmd_vf_vlan_anti_spoof_result,
12115                  vf, "vf");
12116 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12117         TOKEN_STRING_INITIALIZER
12118                 (struct cmd_vf_vlan_anti_spoof_result,
12119                  vlan, "vlan");
12120 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12121         TOKEN_STRING_INITIALIZER
12122                 (struct cmd_vf_vlan_anti_spoof_result,
12123                  antispoof, "antispoof");
12124 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12125         TOKEN_NUM_INITIALIZER
12126                 (struct cmd_vf_vlan_anti_spoof_result,
12127                  port_id, UINT16);
12128 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12129         TOKEN_NUM_INITIALIZER
12130                 (struct cmd_vf_vlan_anti_spoof_result,
12131                  vf_id, UINT32);
12132 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12133         TOKEN_STRING_INITIALIZER
12134                 (struct cmd_vf_vlan_anti_spoof_result,
12135                  on_off, "on#off");
12136
12137 static void
12138 cmd_set_vf_vlan_anti_spoof_parsed(
12139         void *parsed_result,
12140         __attribute__((unused)) struct cmdline *cl,
12141         __attribute__((unused)) void *data)
12142 {
12143         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12144         int ret = -ENOTSUP;
12145
12146         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12147
12148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12149                 return;
12150
12151 #ifdef RTE_LIBRTE_IXGBE_PMD
12152         if (ret == -ENOTSUP)
12153                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12154                                 res->vf_id, is_on);
12155 #endif
12156 #ifdef RTE_LIBRTE_I40E_PMD
12157         if (ret == -ENOTSUP)
12158                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12159                                 res->vf_id, is_on);
12160 #endif
12161 #ifdef RTE_LIBRTE_BNXT_PMD
12162         if (ret == -ENOTSUP)
12163                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12164                                 res->vf_id, is_on);
12165 #endif
12166
12167         switch (ret) {
12168         case 0:
12169                 break;
12170         case -EINVAL:
12171                 printf("invalid vf_id %d\n", res->vf_id);
12172                 break;
12173         case -ENODEV:
12174                 printf("invalid port_id %d\n", res->port_id);
12175                 break;
12176         case -ENOTSUP:
12177                 printf("function not implemented\n");
12178                 break;
12179         default:
12180                 printf("programming error: (%s)\n", strerror(-ret));
12181         }
12182 }
12183
12184 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12185         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12186         .data = NULL,
12187         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12188         .tokens = {
12189                 (void *)&cmd_vf_vlan_anti_spoof_set,
12190                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12191                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12192                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12193                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12194                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12195                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12196                 NULL,
12197         },
12198 };
12199
12200 /* vf mac anti spoof configuration */
12201
12202 /* Common result structure for vf mac anti spoof */
12203 struct cmd_vf_mac_anti_spoof_result {
12204         cmdline_fixed_string_t set;
12205         cmdline_fixed_string_t vf;
12206         cmdline_fixed_string_t mac;
12207         cmdline_fixed_string_t antispoof;
12208         portid_t port_id;
12209         uint32_t vf_id;
12210         cmdline_fixed_string_t on_off;
12211 };
12212
12213 /* Common CLI fields for vf mac anti spoof enable disable */
12214 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12215         TOKEN_STRING_INITIALIZER
12216                 (struct cmd_vf_mac_anti_spoof_result,
12217                  set, "set");
12218 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_vf_mac_anti_spoof_result,
12221                  vf, "vf");
12222 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_vf_mac_anti_spoof_result,
12225                  mac, "mac");
12226 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12227         TOKEN_STRING_INITIALIZER
12228                 (struct cmd_vf_mac_anti_spoof_result,
12229                  antispoof, "antispoof");
12230 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12231         TOKEN_NUM_INITIALIZER
12232                 (struct cmd_vf_mac_anti_spoof_result,
12233                  port_id, UINT16);
12234 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12235         TOKEN_NUM_INITIALIZER
12236                 (struct cmd_vf_mac_anti_spoof_result,
12237                  vf_id, UINT32);
12238 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12239         TOKEN_STRING_INITIALIZER
12240                 (struct cmd_vf_mac_anti_spoof_result,
12241                  on_off, "on#off");
12242
12243 static void
12244 cmd_set_vf_mac_anti_spoof_parsed(
12245         void *parsed_result,
12246         __attribute__((unused)) struct cmdline *cl,
12247         __attribute__((unused)) void *data)
12248 {
12249         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12250         int ret = -ENOTSUP;
12251
12252         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12253
12254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12255                 return;
12256
12257 #ifdef RTE_LIBRTE_IXGBE_PMD
12258         if (ret == -ENOTSUP)
12259                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12260                         res->vf_id, is_on);
12261 #endif
12262 #ifdef RTE_LIBRTE_I40E_PMD
12263         if (ret == -ENOTSUP)
12264                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12265                         res->vf_id, is_on);
12266 #endif
12267 #ifdef RTE_LIBRTE_BNXT_PMD
12268         if (ret == -ENOTSUP)
12269                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12270                         res->vf_id, is_on);
12271 #endif
12272
12273         switch (ret) {
12274         case 0:
12275                 break;
12276         case -EINVAL:
12277                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12278                 break;
12279         case -ENODEV:
12280                 printf("invalid port_id %d\n", res->port_id);
12281                 break;
12282         case -ENOTSUP:
12283                 printf("function not implemented\n");
12284                 break;
12285         default:
12286                 printf("programming error: (%s)\n", strerror(-ret));
12287         }
12288 }
12289
12290 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12291         .f = cmd_set_vf_mac_anti_spoof_parsed,
12292         .data = NULL,
12293         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12294         .tokens = {
12295                 (void *)&cmd_vf_mac_anti_spoof_set,
12296                 (void *)&cmd_vf_mac_anti_spoof_vf,
12297                 (void *)&cmd_vf_mac_anti_spoof_mac,
12298                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12299                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12300                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12301                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12302                 NULL,
12303         },
12304 };
12305
12306 /* vf vlan strip queue configuration */
12307
12308 /* Common result structure for vf mac anti spoof */
12309 struct cmd_vf_vlan_stripq_result {
12310         cmdline_fixed_string_t set;
12311         cmdline_fixed_string_t vf;
12312         cmdline_fixed_string_t vlan;
12313         cmdline_fixed_string_t stripq;
12314         portid_t port_id;
12315         uint16_t vf_id;
12316         cmdline_fixed_string_t on_off;
12317 };
12318
12319 /* Common CLI fields for vf vlan strip enable disable */
12320 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12321         TOKEN_STRING_INITIALIZER
12322                 (struct cmd_vf_vlan_stripq_result,
12323                  set, "set");
12324 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12325         TOKEN_STRING_INITIALIZER
12326                 (struct cmd_vf_vlan_stripq_result,
12327                  vf, "vf");
12328 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12329         TOKEN_STRING_INITIALIZER
12330                 (struct cmd_vf_vlan_stripq_result,
12331                  vlan, "vlan");
12332 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12333         TOKEN_STRING_INITIALIZER
12334                 (struct cmd_vf_vlan_stripq_result,
12335                  stripq, "stripq");
12336 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12337         TOKEN_NUM_INITIALIZER
12338                 (struct cmd_vf_vlan_stripq_result,
12339                  port_id, UINT16);
12340 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12341         TOKEN_NUM_INITIALIZER
12342                 (struct cmd_vf_vlan_stripq_result,
12343                  vf_id, UINT16);
12344 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12345         TOKEN_STRING_INITIALIZER
12346                 (struct cmd_vf_vlan_stripq_result,
12347                  on_off, "on#off");
12348
12349 static void
12350 cmd_set_vf_vlan_stripq_parsed(
12351         void *parsed_result,
12352         __attribute__((unused)) struct cmdline *cl,
12353         __attribute__((unused)) void *data)
12354 {
12355         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12356         int ret = -ENOTSUP;
12357
12358         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12359
12360         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12361                 return;
12362
12363 #ifdef RTE_LIBRTE_IXGBE_PMD
12364         if (ret == -ENOTSUP)
12365                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12366                         res->vf_id, is_on);
12367 #endif
12368 #ifdef RTE_LIBRTE_I40E_PMD
12369         if (ret == -ENOTSUP)
12370                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12371                         res->vf_id, is_on);
12372 #endif
12373 #ifdef RTE_LIBRTE_BNXT_PMD
12374         if (ret == -ENOTSUP)
12375                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12376                         res->vf_id, is_on);
12377 #endif
12378
12379         switch (ret) {
12380         case 0:
12381                 break;
12382         case -EINVAL:
12383                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12384                 break;
12385         case -ENODEV:
12386                 printf("invalid port_id %d\n", res->port_id);
12387                 break;
12388         case -ENOTSUP:
12389                 printf("function not implemented\n");
12390                 break;
12391         default:
12392                 printf("programming error: (%s)\n", strerror(-ret));
12393         }
12394 }
12395
12396 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12397         .f = cmd_set_vf_vlan_stripq_parsed,
12398         .data = NULL,
12399         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12400         .tokens = {
12401                 (void *)&cmd_vf_vlan_stripq_set,
12402                 (void *)&cmd_vf_vlan_stripq_vf,
12403                 (void *)&cmd_vf_vlan_stripq_vlan,
12404                 (void *)&cmd_vf_vlan_stripq_stripq,
12405                 (void *)&cmd_vf_vlan_stripq_port_id,
12406                 (void *)&cmd_vf_vlan_stripq_vf_id,
12407                 (void *)&cmd_vf_vlan_stripq_on_off,
12408                 NULL,
12409         },
12410 };
12411
12412 /* vf vlan insert configuration */
12413
12414 /* Common result structure for vf vlan insert */
12415 struct cmd_vf_vlan_insert_result {
12416         cmdline_fixed_string_t set;
12417         cmdline_fixed_string_t vf;
12418         cmdline_fixed_string_t vlan;
12419         cmdline_fixed_string_t insert;
12420         portid_t port_id;
12421         uint16_t vf_id;
12422         uint16_t vlan_id;
12423 };
12424
12425 /* Common CLI fields for vf vlan insert enable disable */
12426 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12427         TOKEN_STRING_INITIALIZER
12428                 (struct cmd_vf_vlan_insert_result,
12429                  set, "set");
12430 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12431         TOKEN_STRING_INITIALIZER
12432                 (struct cmd_vf_vlan_insert_result,
12433                  vf, "vf");
12434 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12435         TOKEN_STRING_INITIALIZER
12436                 (struct cmd_vf_vlan_insert_result,
12437                  vlan, "vlan");
12438 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12439         TOKEN_STRING_INITIALIZER
12440                 (struct cmd_vf_vlan_insert_result,
12441                  insert, "insert");
12442 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12443         TOKEN_NUM_INITIALIZER
12444                 (struct cmd_vf_vlan_insert_result,
12445                  port_id, UINT16);
12446 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12447         TOKEN_NUM_INITIALIZER
12448                 (struct cmd_vf_vlan_insert_result,
12449                  vf_id, UINT16);
12450 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12451         TOKEN_NUM_INITIALIZER
12452                 (struct cmd_vf_vlan_insert_result,
12453                  vlan_id, UINT16);
12454
12455 static void
12456 cmd_set_vf_vlan_insert_parsed(
12457         void *parsed_result,
12458         __attribute__((unused)) struct cmdline *cl,
12459         __attribute__((unused)) void *data)
12460 {
12461         struct cmd_vf_vlan_insert_result *res = parsed_result;
12462         int ret = -ENOTSUP;
12463
12464         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12465                 return;
12466
12467 #ifdef RTE_LIBRTE_IXGBE_PMD
12468         if (ret == -ENOTSUP)
12469                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12470                         res->vlan_id);
12471 #endif
12472 #ifdef RTE_LIBRTE_I40E_PMD
12473         if (ret == -ENOTSUP)
12474                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12475                         res->vlan_id);
12476 #endif
12477 #ifdef RTE_LIBRTE_BNXT_PMD
12478         if (ret == -ENOTSUP)
12479                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12480                         res->vlan_id);
12481 #endif
12482
12483         switch (ret) {
12484         case 0:
12485                 break;
12486         case -EINVAL:
12487                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12488                 break;
12489         case -ENODEV:
12490                 printf("invalid port_id %d\n", res->port_id);
12491                 break;
12492         case -ENOTSUP:
12493                 printf("function not implemented\n");
12494                 break;
12495         default:
12496                 printf("programming error: (%s)\n", strerror(-ret));
12497         }
12498 }
12499
12500 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12501         .f = cmd_set_vf_vlan_insert_parsed,
12502         .data = NULL,
12503         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12504         .tokens = {
12505                 (void *)&cmd_vf_vlan_insert_set,
12506                 (void *)&cmd_vf_vlan_insert_vf,
12507                 (void *)&cmd_vf_vlan_insert_vlan,
12508                 (void *)&cmd_vf_vlan_insert_insert,
12509                 (void *)&cmd_vf_vlan_insert_port_id,
12510                 (void *)&cmd_vf_vlan_insert_vf_id,
12511                 (void *)&cmd_vf_vlan_insert_vlan_id,
12512                 NULL,
12513         },
12514 };
12515
12516 /* tx loopback configuration */
12517
12518 /* Common result structure for tx loopback */
12519 struct cmd_tx_loopback_result {
12520         cmdline_fixed_string_t set;
12521         cmdline_fixed_string_t tx;
12522         cmdline_fixed_string_t loopback;
12523         portid_t port_id;
12524         cmdline_fixed_string_t on_off;
12525 };
12526
12527 /* Common CLI fields for tx loopback enable disable */
12528 cmdline_parse_token_string_t cmd_tx_loopback_set =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_tx_loopback_result,
12531                  set, "set");
12532 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_tx_loopback_result,
12535                  tx, "tx");
12536 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_tx_loopback_result,
12539                  loopback, "loopback");
12540 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12541         TOKEN_NUM_INITIALIZER
12542                 (struct cmd_tx_loopback_result,
12543                  port_id, UINT16);
12544 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12545         TOKEN_STRING_INITIALIZER
12546                 (struct cmd_tx_loopback_result,
12547                  on_off, "on#off");
12548
12549 static void
12550 cmd_set_tx_loopback_parsed(
12551         void *parsed_result,
12552         __attribute__((unused)) struct cmdline *cl,
12553         __attribute__((unused)) void *data)
12554 {
12555         struct cmd_tx_loopback_result *res = parsed_result;
12556         int ret = -ENOTSUP;
12557
12558         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12559
12560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12561                 return;
12562
12563 #ifdef RTE_LIBRTE_IXGBE_PMD
12564         if (ret == -ENOTSUP)
12565                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12566 #endif
12567 #ifdef RTE_LIBRTE_I40E_PMD
12568         if (ret == -ENOTSUP)
12569                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12570 #endif
12571 #ifdef RTE_LIBRTE_BNXT_PMD
12572         if (ret == -ENOTSUP)
12573                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12574 #endif
12575
12576         switch (ret) {
12577         case 0:
12578                 break;
12579         case -EINVAL:
12580                 printf("invalid is_on %d\n", is_on);
12581                 break;
12582         case -ENODEV:
12583                 printf("invalid port_id %d\n", res->port_id);
12584                 break;
12585         case -ENOTSUP:
12586                 printf("function not implemented\n");
12587                 break;
12588         default:
12589                 printf("programming error: (%s)\n", strerror(-ret));
12590         }
12591 }
12592
12593 cmdline_parse_inst_t cmd_set_tx_loopback = {
12594         .f = cmd_set_tx_loopback_parsed,
12595         .data = NULL,
12596         .help_str = "set tx loopback <port_id> on|off",
12597         .tokens = {
12598                 (void *)&cmd_tx_loopback_set,
12599                 (void *)&cmd_tx_loopback_tx,
12600                 (void *)&cmd_tx_loopback_loopback,
12601                 (void *)&cmd_tx_loopback_port_id,
12602                 (void *)&cmd_tx_loopback_on_off,
12603                 NULL,
12604         },
12605 };
12606
12607 /* all queues drop enable configuration */
12608
12609 /* Common result structure for all queues drop enable */
12610 struct cmd_all_queues_drop_en_result {
12611         cmdline_fixed_string_t set;
12612         cmdline_fixed_string_t all;
12613         cmdline_fixed_string_t queues;
12614         cmdline_fixed_string_t drop;
12615         portid_t port_id;
12616         cmdline_fixed_string_t on_off;
12617 };
12618
12619 /* Common CLI fields for tx loopback enable disable */
12620 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12621         TOKEN_STRING_INITIALIZER
12622                 (struct cmd_all_queues_drop_en_result,
12623                  set, "set");
12624 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12625         TOKEN_STRING_INITIALIZER
12626                 (struct cmd_all_queues_drop_en_result,
12627                  all, "all");
12628 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12629         TOKEN_STRING_INITIALIZER
12630                 (struct cmd_all_queues_drop_en_result,
12631                  queues, "queues");
12632 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12633         TOKEN_STRING_INITIALIZER
12634                 (struct cmd_all_queues_drop_en_result,
12635                  drop, "drop");
12636 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12637         TOKEN_NUM_INITIALIZER
12638                 (struct cmd_all_queues_drop_en_result,
12639                  port_id, UINT16);
12640 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12641         TOKEN_STRING_INITIALIZER
12642                 (struct cmd_all_queues_drop_en_result,
12643                  on_off, "on#off");
12644
12645 static void
12646 cmd_set_all_queues_drop_en_parsed(
12647         void *parsed_result,
12648         __attribute__((unused)) struct cmdline *cl,
12649         __attribute__((unused)) void *data)
12650 {
12651         struct cmd_all_queues_drop_en_result *res = parsed_result;
12652         int ret = -ENOTSUP;
12653         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12654
12655         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12656                 return;
12657
12658 #ifdef RTE_LIBRTE_IXGBE_PMD
12659         if (ret == -ENOTSUP)
12660                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12661 #endif
12662 #ifdef RTE_LIBRTE_BNXT_PMD
12663         if (ret == -ENOTSUP)
12664                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12665 #endif
12666         switch (ret) {
12667         case 0:
12668                 break;
12669         case -EINVAL:
12670                 printf("invalid is_on %d\n", is_on);
12671                 break;
12672         case -ENODEV:
12673                 printf("invalid port_id %d\n", res->port_id);
12674                 break;
12675         case -ENOTSUP:
12676                 printf("function not implemented\n");
12677                 break;
12678         default:
12679                 printf("programming error: (%s)\n", strerror(-ret));
12680         }
12681 }
12682
12683 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12684         .f = cmd_set_all_queues_drop_en_parsed,
12685         .data = NULL,
12686         .help_str = "set all queues drop <port_id> on|off",
12687         .tokens = {
12688                 (void *)&cmd_all_queues_drop_en_set,
12689                 (void *)&cmd_all_queues_drop_en_all,
12690                 (void *)&cmd_all_queues_drop_en_queues,
12691                 (void *)&cmd_all_queues_drop_en_drop,
12692                 (void *)&cmd_all_queues_drop_en_port_id,
12693                 (void *)&cmd_all_queues_drop_en_on_off,
12694                 NULL,
12695         },
12696 };
12697
12698 /* vf split drop enable configuration */
12699
12700 /* Common result structure for vf split drop enable */
12701 struct cmd_vf_split_drop_en_result {
12702         cmdline_fixed_string_t set;
12703         cmdline_fixed_string_t vf;
12704         cmdline_fixed_string_t split;
12705         cmdline_fixed_string_t drop;
12706         portid_t port_id;
12707         uint16_t vf_id;
12708         cmdline_fixed_string_t on_off;
12709 };
12710
12711 /* Common CLI fields for vf split drop enable disable */
12712 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12713         TOKEN_STRING_INITIALIZER
12714                 (struct cmd_vf_split_drop_en_result,
12715                  set, "set");
12716 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12717         TOKEN_STRING_INITIALIZER
12718                 (struct cmd_vf_split_drop_en_result,
12719                  vf, "vf");
12720 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12721         TOKEN_STRING_INITIALIZER
12722                 (struct cmd_vf_split_drop_en_result,
12723                  split, "split");
12724 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12725         TOKEN_STRING_INITIALIZER
12726                 (struct cmd_vf_split_drop_en_result,
12727                  drop, "drop");
12728 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12729         TOKEN_NUM_INITIALIZER
12730                 (struct cmd_vf_split_drop_en_result,
12731                  port_id, UINT16);
12732 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12733         TOKEN_NUM_INITIALIZER
12734                 (struct cmd_vf_split_drop_en_result,
12735                  vf_id, UINT16);
12736 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_vf_split_drop_en_result,
12739                  on_off, "on#off");
12740
12741 static void
12742 cmd_set_vf_split_drop_en_parsed(
12743         void *parsed_result,
12744         __attribute__((unused)) struct cmdline *cl,
12745         __attribute__((unused)) void *data)
12746 {
12747         struct cmd_vf_split_drop_en_result *res = parsed_result;
12748         int ret = -ENOTSUP;
12749         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12750
12751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12752                 return;
12753
12754 #ifdef RTE_LIBRTE_IXGBE_PMD
12755         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12756                         is_on);
12757 #endif
12758         switch (ret) {
12759         case 0:
12760                 break;
12761         case -EINVAL:
12762                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12763                 break;
12764         case -ENODEV:
12765                 printf("invalid port_id %d\n", res->port_id);
12766                 break;
12767         case -ENOTSUP:
12768                 printf("not supported on port %d\n", res->port_id);
12769                 break;
12770         default:
12771                 printf("programming error: (%s)\n", strerror(-ret));
12772         }
12773 }
12774
12775 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12776         .f = cmd_set_vf_split_drop_en_parsed,
12777         .data = NULL,
12778         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12779         .tokens = {
12780                 (void *)&cmd_vf_split_drop_en_set,
12781                 (void *)&cmd_vf_split_drop_en_vf,
12782                 (void *)&cmd_vf_split_drop_en_split,
12783                 (void *)&cmd_vf_split_drop_en_drop,
12784                 (void *)&cmd_vf_split_drop_en_port_id,
12785                 (void *)&cmd_vf_split_drop_en_vf_id,
12786                 (void *)&cmd_vf_split_drop_en_on_off,
12787                 NULL,
12788         },
12789 };
12790
12791 /* vf mac address configuration */
12792
12793 /* Common result structure for vf mac address */
12794 struct cmd_set_vf_mac_addr_result {
12795         cmdline_fixed_string_t set;
12796         cmdline_fixed_string_t vf;
12797         cmdline_fixed_string_t mac;
12798         cmdline_fixed_string_t addr;
12799         portid_t port_id;
12800         uint16_t vf_id;
12801         struct ether_addr mac_addr;
12802
12803 };
12804
12805 /* Common CLI fields for vf split drop enable disable */
12806 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12807         TOKEN_STRING_INITIALIZER
12808                 (struct cmd_set_vf_mac_addr_result,
12809                  set, "set");
12810 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12811         TOKEN_STRING_INITIALIZER
12812                 (struct cmd_set_vf_mac_addr_result,
12813                  vf, "vf");
12814 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12815         TOKEN_STRING_INITIALIZER
12816                 (struct cmd_set_vf_mac_addr_result,
12817                  mac, "mac");
12818 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12819         TOKEN_STRING_INITIALIZER
12820                 (struct cmd_set_vf_mac_addr_result,
12821                  addr, "addr");
12822 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12823         TOKEN_NUM_INITIALIZER
12824                 (struct cmd_set_vf_mac_addr_result,
12825                  port_id, UINT16);
12826 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12827         TOKEN_NUM_INITIALIZER
12828                 (struct cmd_set_vf_mac_addr_result,
12829                  vf_id, UINT16);
12830 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12831         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12832                  mac_addr);
12833
12834 static void
12835 cmd_set_vf_mac_addr_parsed(
12836         void *parsed_result,
12837         __attribute__((unused)) struct cmdline *cl,
12838         __attribute__((unused)) void *data)
12839 {
12840         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12841         int ret = -ENOTSUP;
12842
12843         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12844                 return;
12845
12846 #ifdef RTE_LIBRTE_IXGBE_PMD
12847         if (ret == -ENOTSUP)
12848                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12849                                 &res->mac_addr);
12850 #endif
12851 #ifdef RTE_LIBRTE_I40E_PMD
12852         if (ret == -ENOTSUP)
12853                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12854                                 &res->mac_addr);
12855 #endif
12856 #ifdef RTE_LIBRTE_BNXT_PMD
12857         if (ret == -ENOTSUP)
12858                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12859                                 &res->mac_addr);
12860 #endif
12861
12862         switch (ret) {
12863         case 0:
12864                 break;
12865         case -EINVAL:
12866                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12867                 break;
12868         case -ENODEV:
12869                 printf("invalid port_id %d\n", res->port_id);
12870                 break;
12871         case -ENOTSUP:
12872                 printf("function not implemented\n");
12873                 break;
12874         default:
12875                 printf("programming error: (%s)\n", strerror(-ret));
12876         }
12877 }
12878
12879 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12880         .f = cmd_set_vf_mac_addr_parsed,
12881         .data = NULL,
12882         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12883         .tokens = {
12884                 (void *)&cmd_set_vf_mac_addr_set,
12885                 (void *)&cmd_set_vf_mac_addr_vf,
12886                 (void *)&cmd_set_vf_mac_addr_mac,
12887                 (void *)&cmd_set_vf_mac_addr_addr,
12888                 (void *)&cmd_set_vf_mac_addr_port_id,
12889                 (void *)&cmd_set_vf_mac_addr_vf_id,
12890                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12891                 NULL,
12892         },
12893 };
12894
12895 /* MACsec configuration */
12896
12897 /* Common result structure for MACsec offload enable */
12898 struct cmd_macsec_offload_on_result {
12899         cmdline_fixed_string_t set;
12900         cmdline_fixed_string_t macsec;
12901         cmdline_fixed_string_t offload;
12902         portid_t port_id;
12903         cmdline_fixed_string_t on;
12904         cmdline_fixed_string_t encrypt;
12905         cmdline_fixed_string_t en_on_off;
12906         cmdline_fixed_string_t replay_protect;
12907         cmdline_fixed_string_t rp_on_off;
12908 };
12909
12910 /* Common CLI fields for MACsec offload disable */
12911 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_macsec_offload_on_result,
12914                  set, "set");
12915 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_macsec_offload_on_result,
12918                  macsec, "macsec");
12919 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_macsec_offload_on_result,
12922                  offload, "offload");
12923 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12924         TOKEN_NUM_INITIALIZER
12925                 (struct cmd_macsec_offload_on_result,
12926                  port_id, UINT16);
12927 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12928         TOKEN_STRING_INITIALIZER
12929                 (struct cmd_macsec_offload_on_result,
12930                  on, "on");
12931 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_macsec_offload_on_result,
12934                  encrypt, "encrypt");
12935 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12936         TOKEN_STRING_INITIALIZER
12937                 (struct cmd_macsec_offload_on_result,
12938                  en_on_off, "on#off");
12939 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12940         TOKEN_STRING_INITIALIZER
12941                 (struct cmd_macsec_offload_on_result,
12942                  replay_protect, "replay-protect");
12943 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12944         TOKEN_STRING_INITIALIZER
12945                 (struct cmd_macsec_offload_on_result,
12946                  rp_on_off, "on#off");
12947
12948 static void
12949 cmd_set_macsec_offload_on_parsed(
12950         void *parsed_result,
12951         __attribute__((unused)) struct cmdline *cl,
12952         __attribute__((unused)) void *data)
12953 {
12954         struct cmd_macsec_offload_on_result *res = parsed_result;
12955         int ret = -ENOTSUP;
12956         portid_t port_id = res->port_id;
12957         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12958         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12959
12960         if (port_id_is_invalid(port_id, ENABLED_WARN))
12961                 return;
12962
12963         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12964 #ifdef RTE_LIBRTE_IXGBE_PMD
12965         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12966 #endif
12967         RTE_SET_USED(en);
12968         RTE_SET_USED(rp);
12969
12970         switch (ret) {
12971         case 0:
12972                 break;
12973         case -ENODEV:
12974                 printf("invalid port_id %d\n", port_id);
12975                 break;
12976         case -ENOTSUP:
12977                 printf("not supported on port %d\n", port_id);
12978                 break;
12979         default:
12980                 printf("programming error: (%s)\n", strerror(-ret));
12981         }
12982 }
12983
12984 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12985         .f = cmd_set_macsec_offload_on_parsed,
12986         .data = NULL,
12987         .help_str = "set macsec offload <port_id> on "
12988                 "encrypt on|off replay-protect on|off",
12989         .tokens = {
12990                 (void *)&cmd_macsec_offload_on_set,
12991                 (void *)&cmd_macsec_offload_on_macsec,
12992                 (void *)&cmd_macsec_offload_on_offload,
12993                 (void *)&cmd_macsec_offload_on_port_id,
12994                 (void *)&cmd_macsec_offload_on_on,
12995                 (void *)&cmd_macsec_offload_on_encrypt,
12996                 (void *)&cmd_macsec_offload_on_en_on_off,
12997                 (void *)&cmd_macsec_offload_on_replay_protect,
12998                 (void *)&cmd_macsec_offload_on_rp_on_off,
12999                 NULL,
13000         },
13001 };
13002
13003 /* Common result structure for MACsec offload disable */
13004 struct cmd_macsec_offload_off_result {
13005         cmdline_fixed_string_t set;
13006         cmdline_fixed_string_t macsec;
13007         cmdline_fixed_string_t offload;
13008         portid_t port_id;
13009         cmdline_fixed_string_t off;
13010 };
13011
13012 /* Common CLI fields for MACsec offload disable */
13013 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13014         TOKEN_STRING_INITIALIZER
13015                 (struct cmd_macsec_offload_off_result,
13016                  set, "set");
13017 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13018         TOKEN_STRING_INITIALIZER
13019                 (struct cmd_macsec_offload_off_result,
13020                  macsec, "macsec");
13021 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13022         TOKEN_STRING_INITIALIZER
13023                 (struct cmd_macsec_offload_off_result,
13024                  offload, "offload");
13025 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13026         TOKEN_NUM_INITIALIZER
13027                 (struct cmd_macsec_offload_off_result,
13028                  port_id, UINT16);
13029 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13030         TOKEN_STRING_INITIALIZER
13031                 (struct cmd_macsec_offload_off_result,
13032                  off, "off");
13033
13034 static void
13035 cmd_set_macsec_offload_off_parsed(
13036         void *parsed_result,
13037         __attribute__((unused)) struct cmdline *cl,
13038         __attribute__((unused)) void *data)
13039 {
13040         struct cmd_macsec_offload_off_result *res = parsed_result;
13041         int ret = -ENOTSUP;
13042         portid_t port_id = res->port_id;
13043
13044         if (port_id_is_invalid(port_id, ENABLED_WARN))
13045                 return;
13046
13047         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13048 #ifdef RTE_LIBRTE_IXGBE_PMD
13049         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13050 #endif
13051
13052         switch (ret) {
13053         case 0:
13054                 break;
13055         case -ENODEV:
13056                 printf("invalid port_id %d\n", port_id);
13057                 break;
13058         case -ENOTSUP:
13059                 printf("not supported on port %d\n", port_id);
13060                 break;
13061         default:
13062                 printf("programming error: (%s)\n", strerror(-ret));
13063         }
13064 }
13065
13066 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13067         .f = cmd_set_macsec_offload_off_parsed,
13068         .data = NULL,
13069         .help_str = "set macsec offload <port_id> off",
13070         .tokens = {
13071                 (void *)&cmd_macsec_offload_off_set,
13072                 (void *)&cmd_macsec_offload_off_macsec,
13073                 (void *)&cmd_macsec_offload_off_offload,
13074                 (void *)&cmd_macsec_offload_off_port_id,
13075                 (void *)&cmd_macsec_offload_off_off,
13076                 NULL,
13077         },
13078 };
13079
13080 /* Common result structure for MACsec secure connection configure */
13081 struct cmd_macsec_sc_result {
13082         cmdline_fixed_string_t set;
13083         cmdline_fixed_string_t macsec;
13084         cmdline_fixed_string_t sc;
13085         cmdline_fixed_string_t tx_rx;
13086         portid_t port_id;
13087         struct ether_addr mac;
13088         uint16_t pi;
13089 };
13090
13091 /* Common CLI fields for MACsec secure connection configure */
13092 cmdline_parse_token_string_t cmd_macsec_sc_set =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_macsec_sc_result,
13095                  set, "set");
13096 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13097         TOKEN_STRING_INITIALIZER
13098                 (struct cmd_macsec_sc_result,
13099                  macsec, "macsec");
13100 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13101         TOKEN_STRING_INITIALIZER
13102                 (struct cmd_macsec_sc_result,
13103                  sc, "sc");
13104 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13105         TOKEN_STRING_INITIALIZER
13106                 (struct cmd_macsec_sc_result,
13107                  tx_rx, "tx#rx");
13108 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13109         TOKEN_NUM_INITIALIZER
13110                 (struct cmd_macsec_sc_result,
13111                  port_id, UINT16);
13112 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13113         TOKEN_ETHERADDR_INITIALIZER
13114                 (struct cmd_macsec_sc_result,
13115                  mac);
13116 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13117         TOKEN_NUM_INITIALIZER
13118                 (struct cmd_macsec_sc_result,
13119                  pi, UINT16);
13120
13121 static void
13122 cmd_set_macsec_sc_parsed(
13123         void *parsed_result,
13124         __attribute__((unused)) struct cmdline *cl,
13125         __attribute__((unused)) void *data)
13126 {
13127         struct cmd_macsec_sc_result *res = parsed_result;
13128         int ret = -ENOTSUP;
13129         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13130
13131 #ifdef RTE_LIBRTE_IXGBE_PMD
13132         ret = is_tx ?
13133                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13134                                 res->mac.addr_bytes) :
13135                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13136                                 res->mac.addr_bytes, res->pi);
13137 #endif
13138         RTE_SET_USED(is_tx);
13139
13140         switch (ret) {
13141         case 0:
13142                 break;
13143         case -ENODEV:
13144                 printf("invalid port_id %d\n", res->port_id);
13145                 break;
13146         case -ENOTSUP:
13147                 printf("not supported on port %d\n", res->port_id);
13148                 break;
13149         default:
13150                 printf("programming error: (%s)\n", strerror(-ret));
13151         }
13152 }
13153
13154 cmdline_parse_inst_t cmd_set_macsec_sc = {
13155         .f = cmd_set_macsec_sc_parsed,
13156         .data = NULL,
13157         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13158         .tokens = {
13159                 (void *)&cmd_macsec_sc_set,
13160                 (void *)&cmd_macsec_sc_macsec,
13161                 (void *)&cmd_macsec_sc_sc,
13162                 (void *)&cmd_macsec_sc_tx_rx,
13163                 (void *)&cmd_macsec_sc_port_id,
13164                 (void *)&cmd_macsec_sc_mac,
13165                 (void *)&cmd_macsec_sc_pi,
13166                 NULL,
13167         },
13168 };
13169
13170 /* Common result structure for MACsec secure connection configure */
13171 struct cmd_macsec_sa_result {
13172         cmdline_fixed_string_t set;
13173         cmdline_fixed_string_t macsec;
13174         cmdline_fixed_string_t sa;
13175         cmdline_fixed_string_t tx_rx;
13176         portid_t port_id;
13177         uint8_t idx;
13178         uint8_t an;
13179         uint32_t pn;
13180         cmdline_fixed_string_t key;
13181 };
13182
13183 /* Common CLI fields for MACsec secure connection configure */
13184 cmdline_parse_token_string_t cmd_macsec_sa_set =
13185         TOKEN_STRING_INITIALIZER
13186                 (struct cmd_macsec_sa_result,
13187                  set, "set");
13188 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_macsec_sa_result,
13191                  macsec, "macsec");
13192 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13193         TOKEN_STRING_INITIALIZER
13194                 (struct cmd_macsec_sa_result,
13195                  sa, "sa");
13196 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13197         TOKEN_STRING_INITIALIZER
13198                 (struct cmd_macsec_sa_result,
13199                  tx_rx, "tx#rx");
13200 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13201         TOKEN_NUM_INITIALIZER
13202                 (struct cmd_macsec_sa_result,
13203                  port_id, UINT16);
13204 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13205         TOKEN_NUM_INITIALIZER
13206                 (struct cmd_macsec_sa_result,
13207                  idx, UINT8);
13208 cmdline_parse_token_num_t cmd_macsec_sa_an =
13209         TOKEN_NUM_INITIALIZER
13210                 (struct cmd_macsec_sa_result,
13211                  an, UINT8);
13212 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13213         TOKEN_NUM_INITIALIZER
13214                 (struct cmd_macsec_sa_result,
13215                  pn, UINT32);
13216 cmdline_parse_token_string_t cmd_macsec_sa_key =
13217         TOKEN_STRING_INITIALIZER
13218                 (struct cmd_macsec_sa_result,
13219                  key, NULL);
13220
13221 static void
13222 cmd_set_macsec_sa_parsed(
13223         void *parsed_result,
13224         __attribute__((unused)) struct cmdline *cl,
13225         __attribute__((unused)) void *data)
13226 {
13227         struct cmd_macsec_sa_result *res = parsed_result;
13228         int ret = -ENOTSUP;
13229         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13230         uint8_t key[16] = { 0 };
13231         uint8_t xdgt0;
13232         uint8_t xdgt1;
13233         int key_len;
13234         int i;
13235
13236         key_len = strlen(res->key) / 2;
13237         if (key_len > 16)
13238                 key_len = 16;
13239
13240         for (i = 0; i < key_len; i++) {
13241                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13242                 if (xdgt0 == 0xFF)
13243                         return;
13244                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13245                 if (xdgt1 == 0xFF)
13246                         return;
13247                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13248         }
13249
13250 #ifdef RTE_LIBRTE_IXGBE_PMD
13251         ret = is_tx ?
13252                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13253                         res->idx, res->an, res->pn, key) :
13254                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13255                         res->idx, res->an, res->pn, key);
13256 #endif
13257         RTE_SET_USED(is_tx);
13258         RTE_SET_USED(key);
13259
13260         switch (ret) {
13261         case 0:
13262                 break;
13263         case -EINVAL:
13264                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13265                 break;
13266         case -ENODEV:
13267                 printf("invalid port_id %d\n", res->port_id);
13268                 break;
13269         case -ENOTSUP:
13270                 printf("not supported on port %d\n", res->port_id);
13271                 break;
13272         default:
13273                 printf("programming error: (%s)\n", strerror(-ret));
13274         }
13275 }
13276
13277 cmdline_parse_inst_t cmd_set_macsec_sa = {
13278         .f = cmd_set_macsec_sa_parsed,
13279         .data = NULL,
13280         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13281         .tokens = {
13282                 (void *)&cmd_macsec_sa_set,
13283                 (void *)&cmd_macsec_sa_macsec,
13284                 (void *)&cmd_macsec_sa_sa,
13285                 (void *)&cmd_macsec_sa_tx_rx,
13286                 (void *)&cmd_macsec_sa_port_id,
13287                 (void *)&cmd_macsec_sa_idx,
13288                 (void *)&cmd_macsec_sa_an,
13289                 (void *)&cmd_macsec_sa_pn,
13290                 (void *)&cmd_macsec_sa_key,
13291                 NULL,
13292         },
13293 };
13294
13295 /* VF unicast promiscuous mode configuration */
13296
13297 /* Common result structure for VF unicast promiscuous mode */
13298 struct cmd_vf_promisc_result {
13299         cmdline_fixed_string_t set;
13300         cmdline_fixed_string_t vf;
13301         cmdline_fixed_string_t promisc;
13302         portid_t port_id;
13303         uint32_t vf_id;
13304         cmdline_fixed_string_t on_off;
13305 };
13306
13307 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13308 cmdline_parse_token_string_t cmd_vf_promisc_set =
13309         TOKEN_STRING_INITIALIZER
13310                 (struct cmd_vf_promisc_result,
13311                  set, "set");
13312 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13313         TOKEN_STRING_INITIALIZER
13314                 (struct cmd_vf_promisc_result,
13315                  vf, "vf");
13316 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13317         TOKEN_STRING_INITIALIZER
13318                 (struct cmd_vf_promisc_result,
13319                  promisc, "promisc");
13320 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13321         TOKEN_NUM_INITIALIZER
13322                 (struct cmd_vf_promisc_result,
13323                  port_id, UINT16);
13324 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13325         TOKEN_NUM_INITIALIZER
13326                 (struct cmd_vf_promisc_result,
13327                  vf_id, UINT32);
13328 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13329         TOKEN_STRING_INITIALIZER
13330                 (struct cmd_vf_promisc_result,
13331                  on_off, "on#off");
13332
13333 static void
13334 cmd_set_vf_promisc_parsed(
13335         void *parsed_result,
13336         __attribute__((unused)) struct cmdline *cl,
13337         __attribute__((unused)) void *data)
13338 {
13339         struct cmd_vf_promisc_result *res = parsed_result;
13340         int ret = -ENOTSUP;
13341
13342         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13343
13344         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13345                 return;
13346
13347 #ifdef RTE_LIBRTE_I40E_PMD
13348         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13349                                                   res->vf_id, is_on);
13350 #endif
13351
13352         switch (ret) {
13353         case 0:
13354                 break;
13355         case -EINVAL:
13356                 printf("invalid vf_id %d\n", res->vf_id);
13357                 break;
13358         case -ENODEV:
13359                 printf("invalid port_id %d\n", res->port_id);
13360                 break;
13361         case -ENOTSUP:
13362                 printf("function not implemented\n");
13363                 break;
13364         default:
13365                 printf("programming error: (%s)\n", strerror(-ret));
13366         }
13367 }
13368
13369 cmdline_parse_inst_t cmd_set_vf_promisc = {
13370         .f = cmd_set_vf_promisc_parsed,
13371         .data = NULL,
13372         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13373                 "Set unicast promiscuous mode for a VF from the PF",
13374         .tokens = {
13375                 (void *)&cmd_vf_promisc_set,
13376                 (void *)&cmd_vf_promisc_vf,
13377                 (void *)&cmd_vf_promisc_promisc,
13378                 (void *)&cmd_vf_promisc_port_id,
13379                 (void *)&cmd_vf_promisc_vf_id,
13380                 (void *)&cmd_vf_promisc_on_off,
13381                 NULL,
13382         },
13383 };
13384
13385 /* VF multicast promiscuous mode configuration */
13386
13387 /* Common result structure for VF multicast promiscuous mode */
13388 struct cmd_vf_allmulti_result {
13389         cmdline_fixed_string_t set;
13390         cmdline_fixed_string_t vf;
13391         cmdline_fixed_string_t allmulti;
13392         portid_t port_id;
13393         uint32_t vf_id;
13394         cmdline_fixed_string_t on_off;
13395 };
13396
13397 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13398 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13399         TOKEN_STRING_INITIALIZER
13400                 (struct cmd_vf_allmulti_result,
13401                  set, "set");
13402 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13403         TOKEN_STRING_INITIALIZER
13404                 (struct cmd_vf_allmulti_result,
13405                  vf, "vf");
13406 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13407         TOKEN_STRING_INITIALIZER
13408                 (struct cmd_vf_allmulti_result,
13409                  allmulti, "allmulti");
13410 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13411         TOKEN_NUM_INITIALIZER
13412                 (struct cmd_vf_allmulti_result,
13413                  port_id, UINT16);
13414 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13415         TOKEN_NUM_INITIALIZER
13416                 (struct cmd_vf_allmulti_result,
13417                  vf_id, UINT32);
13418 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13419         TOKEN_STRING_INITIALIZER
13420                 (struct cmd_vf_allmulti_result,
13421                  on_off, "on#off");
13422
13423 static void
13424 cmd_set_vf_allmulti_parsed(
13425         void *parsed_result,
13426         __attribute__((unused)) struct cmdline *cl,
13427         __attribute__((unused)) void *data)
13428 {
13429         struct cmd_vf_allmulti_result *res = parsed_result;
13430         int ret = -ENOTSUP;
13431
13432         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13433
13434         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13435                 return;
13436
13437 #ifdef RTE_LIBRTE_I40E_PMD
13438         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13439                                                     res->vf_id, is_on);
13440 #endif
13441
13442         switch (ret) {
13443         case 0:
13444                 break;
13445         case -EINVAL:
13446                 printf("invalid vf_id %d\n", res->vf_id);
13447                 break;
13448         case -ENODEV:
13449                 printf("invalid port_id %d\n", res->port_id);
13450                 break;
13451         case -ENOTSUP:
13452                 printf("function not implemented\n");
13453                 break;
13454         default:
13455                 printf("programming error: (%s)\n", strerror(-ret));
13456         }
13457 }
13458
13459 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13460         .f = cmd_set_vf_allmulti_parsed,
13461         .data = NULL,
13462         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13463                 "Set multicast promiscuous mode for a VF from the PF",
13464         .tokens = {
13465                 (void *)&cmd_vf_allmulti_set,
13466                 (void *)&cmd_vf_allmulti_vf,
13467                 (void *)&cmd_vf_allmulti_allmulti,
13468                 (void *)&cmd_vf_allmulti_port_id,
13469                 (void *)&cmd_vf_allmulti_vf_id,
13470                 (void *)&cmd_vf_allmulti_on_off,
13471                 NULL,
13472         },
13473 };
13474
13475 /* vf broadcast mode configuration */
13476
13477 /* Common result structure for vf broadcast */
13478 struct cmd_set_vf_broadcast_result {
13479         cmdline_fixed_string_t set;
13480         cmdline_fixed_string_t vf;
13481         cmdline_fixed_string_t broadcast;
13482         portid_t port_id;
13483         uint16_t vf_id;
13484         cmdline_fixed_string_t on_off;
13485 };
13486
13487 /* Common CLI fields for vf broadcast enable disable */
13488 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13489         TOKEN_STRING_INITIALIZER
13490                 (struct cmd_set_vf_broadcast_result,
13491                  set, "set");
13492 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_set_vf_broadcast_result,
13495                  vf, "vf");
13496 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13497         TOKEN_STRING_INITIALIZER
13498                 (struct cmd_set_vf_broadcast_result,
13499                  broadcast, "broadcast");
13500 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13501         TOKEN_NUM_INITIALIZER
13502                 (struct cmd_set_vf_broadcast_result,
13503                  port_id, UINT16);
13504 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13505         TOKEN_NUM_INITIALIZER
13506                 (struct cmd_set_vf_broadcast_result,
13507                  vf_id, UINT16);
13508 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13509         TOKEN_STRING_INITIALIZER
13510                 (struct cmd_set_vf_broadcast_result,
13511                  on_off, "on#off");
13512
13513 static void
13514 cmd_set_vf_broadcast_parsed(
13515         void *parsed_result,
13516         __attribute__((unused)) struct cmdline *cl,
13517         __attribute__((unused)) void *data)
13518 {
13519         struct cmd_set_vf_broadcast_result *res = parsed_result;
13520         int ret = -ENOTSUP;
13521
13522         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13523
13524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13525                 return;
13526
13527 #ifdef RTE_LIBRTE_I40E_PMD
13528         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13529                                             res->vf_id, is_on);
13530 #endif
13531
13532         switch (ret) {
13533         case 0:
13534                 break;
13535         case -EINVAL:
13536                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13537                 break;
13538         case -ENODEV:
13539                 printf("invalid port_id %d\n", res->port_id);
13540                 break;
13541         case -ENOTSUP:
13542                 printf("function not implemented\n");
13543                 break;
13544         default:
13545                 printf("programming error: (%s)\n", strerror(-ret));
13546         }
13547 }
13548
13549 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13550         .f = cmd_set_vf_broadcast_parsed,
13551         .data = NULL,
13552         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13553         .tokens = {
13554                 (void *)&cmd_set_vf_broadcast_set,
13555                 (void *)&cmd_set_vf_broadcast_vf,
13556                 (void *)&cmd_set_vf_broadcast_broadcast,
13557                 (void *)&cmd_set_vf_broadcast_port_id,
13558                 (void *)&cmd_set_vf_broadcast_vf_id,
13559                 (void *)&cmd_set_vf_broadcast_on_off,
13560                 NULL,
13561         },
13562 };
13563
13564 /* vf vlan tag configuration */
13565
13566 /* Common result structure for vf vlan tag */
13567 struct cmd_set_vf_vlan_tag_result {
13568         cmdline_fixed_string_t set;
13569         cmdline_fixed_string_t vf;
13570         cmdline_fixed_string_t vlan;
13571         cmdline_fixed_string_t tag;
13572         portid_t port_id;
13573         uint16_t vf_id;
13574         cmdline_fixed_string_t on_off;
13575 };
13576
13577 /* Common CLI fields for vf vlan tag enable disable */
13578 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_set_vf_vlan_tag_result,
13581                  set, "set");
13582 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_set_vf_vlan_tag_result,
13585                  vf, "vf");
13586 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_set_vf_vlan_tag_result,
13589                  vlan, "vlan");
13590 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13591         TOKEN_STRING_INITIALIZER
13592                 (struct cmd_set_vf_vlan_tag_result,
13593                  tag, "tag");
13594 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13595         TOKEN_NUM_INITIALIZER
13596                 (struct cmd_set_vf_vlan_tag_result,
13597                  port_id, UINT16);
13598 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13599         TOKEN_NUM_INITIALIZER
13600                 (struct cmd_set_vf_vlan_tag_result,
13601                  vf_id, UINT16);
13602 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13603         TOKEN_STRING_INITIALIZER
13604                 (struct cmd_set_vf_vlan_tag_result,
13605                  on_off, "on#off");
13606
13607 static void
13608 cmd_set_vf_vlan_tag_parsed(
13609         void *parsed_result,
13610         __attribute__((unused)) struct cmdline *cl,
13611         __attribute__((unused)) void *data)
13612 {
13613         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13614         int ret = -ENOTSUP;
13615
13616         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13617
13618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13619                 return;
13620
13621 #ifdef RTE_LIBRTE_I40E_PMD
13622         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13623                                            res->vf_id, is_on);
13624 #endif
13625
13626         switch (ret) {
13627         case 0:
13628                 break;
13629         case -EINVAL:
13630                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13631                 break;
13632         case -ENODEV:
13633                 printf("invalid port_id %d\n", res->port_id);
13634                 break;
13635         case -ENOTSUP:
13636                 printf("function not implemented\n");
13637                 break;
13638         default:
13639                 printf("programming error: (%s)\n", strerror(-ret));
13640         }
13641 }
13642
13643 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13644         .f = cmd_set_vf_vlan_tag_parsed,
13645         .data = NULL,
13646         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13647         .tokens = {
13648                 (void *)&cmd_set_vf_vlan_tag_set,
13649                 (void *)&cmd_set_vf_vlan_tag_vf,
13650                 (void *)&cmd_set_vf_vlan_tag_vlan,
13651                 (void *)&cmd_set_vf_vlan_tag_tag,
13652                 (void *)&cmd_set_vf_vlan_tag_port_id,
13653                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13654                 (void *)&cmd_set_vf_vlan_tag_on_off,
13655                 NULL,
13656         },
13657 };
13658
13659 /* Common definition of VF and TC TX bandwidth configuration */
13660 struct cmd_vf_tc_bw_result {
13661         cmdline_fixed_string_t set;
13662         cmdline_fixed_string_t vf;
13663         cmdline_fixed_string_t tc;
13664         cmdline_fixed_string_t tx;
13665         cmdline_fixed_string_t min_bw;
13666         cmdline_fixed_string_t max_bw;
13667         cmdline_fixed_string_t strict_link_prio;
13668         portid_t port_id;
13669         uint16_t vf_id;
13670         uint8_t tc_no;
13671         uint32_t bw;
13672         cmdline_fixed_string_t bw_list;
13673         uint8_t tc_map;
13674 };
13675
13676 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_vf_tc_bw_result,
13679                  set, "set");
13680 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13681         TOKEN_STRING_INITIALIZER
13682                 (struct cmd_vf_tc_bw_result,
13683                  vf, "vf");
13684 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_vf_tc_bw_result,
13687                  tc, "tc");
13688 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_vf_tc_bw_result,
13691                  tx, "tx");
13692 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_vf_tc_bw_result,
13695                  strict_link_prio, "strict-link-priority");
13696 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13697         TOKEN_STRING_INITIALIZER
13698                 (struct cmd_vf_tc_bw_result,
13699                  min_bw, "min-bandwidth");
13700 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13701         TOKEN_STRING_INITIALIZER
13702                 (struct cmd_vf_tc_bw_result,
13703                  max_bw, "max-bandwidth");
13704 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13705         TOKEN_NUM_INITIALIZER
13706                 (struct cmd_vf_tc_bw_result,
13707                  port_id, UINT16);
13708 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13709         TOKEN_NUM_INITIALIZER
13710                 (struct cmd_vf_tc_bw_result,
13711                  vf_id, UINT16);
13712 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13713         TOKEN_NUM_INITIALIZER
13714                 (struct cmd_vf_tc_bw_result,
13715                  tc_no, UINT8);
13716 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13717         TOKEN_NUM_INITIALIZER
13718                 (struct cmd_vf_tc_bw_result,
13719                  bw, UINT32);
13720 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13721         TOKEN_STRING_INITIALIZER
13722                 (struct cmd_vf_tc_bw_result,
13723                  bw_list, NULL);
13724 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13725         TOKEN_NUM_INITIALIZER
13726                 (struct cmd_vf_tc_bw_result,
13727                  tc_map, UINT8);
13728
13729 /* VF max bandwidth setting */
13730 static void
13731 cmd_vf_max_bw_parsed(
13732         void *parsed_result,
13733         __attribute__((unused)) struct cmdline *cl,
13734         __attribute__((unused)) void *data)
13735 {
13736         struct cmd_vf_tc_bw_result *res = parsed_result;
13737         int ret = -ENOTSUP;
13738
13739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13740                 return;
13741
13742 #ifdef RTE_LIBRTE_I40E_PMD
13743         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13744                                          res->vf_id, res->bw);
13745 #endif
13746
13747         switch (ret) {
13748         case 0:
13749                 break;
13750         case -EINVAL:
13751                 printf("invalid vf_id %d or bandwidth %d\n",
13752                        res->vf_id, res->bw);
13753                 break;
13754         case -ENODEV:
13755                 printf("invalid port_id %d\n", res->port_id);
13756                 break;
13757         case -ENOTSUP:
13758                 printf("function not implemented\n");
13759                 break;
13760         default:
13761                 printf("programming error: (%s)\n", strerror(-ret));
13762         }
13763 }
13764
13765 cmdline_parse_inst_t cmd_vf_max_bw = {
13766         .f = cmd_vf_max_bw_parsed,
13767         .data = NULL,
13768         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13769         .tokens = {
13770                 (void *)&cmd_vf_tc_bw_set,
13771                 (void *)&cmd_vf_tc_bw_vf,
13772                 (void *)&cmd_vf_tc_bw_tx,
13773                 (void *)&cmd_vf_tc_bw_max_bw,
13774                 (void *)&cmd_vf_tc_bw_port_id,
13775                 (void *)&cmd_vf_tc_bw_vf_id,
13776                 (void *)&cmd_vf_tc_bw_bw,
13777                 NULL,
13778         },
13779 };
13780
13781 static int
13782 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13783                            uint8_t *tc_num,
13784                            char *str)
13785 {
13786         uint32_t size;
13787         const char *p, *p0 = str;
13788         char s[256];
13789         char *end;
13790         char *str_fld[16];
13791         uint16_t i;
13792         int ret;
13793
13794         p = strchr(p0, '(');
13795         if (p == NULL) {
13796                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13797                 return -1;
13798         }
13799         p++;
13800         p0 = strchr(p, ')');
13801         if (p0 == NULL) {
13802                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13803                 return -1;
13804         }
13805         size = p0 - p;
13806         if (size >= sizeof(s)) {
13807                 printf("The string size exceeds the internal buffer size\n");
13808                 return -1;
13809         }
13810         snprintf(s, sizeof(s), "%.*s", size, p);
13811         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13812         if (ret <= 0) {
13813                 printf("Failed to get the bandwidth list. ");
13814                 return -1;
13815         }
13816         *tc_num = ret;
13817         for (i = 0; i < ret; i++)
13818                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13819
13820         return 0;
13821 }
13822
13823 /* TC min bandwidth setting */
13824 static void
13825 cmd_vf_tc_min_bw_parsed(
13826         void *parsed_result,
13827         __attribute__((unused)) struct cmdline *cl,
13828         __attribute__((unused)) void *data)
13829 {
13830         struct cmd_vf_tc_bw_result *res = parsed_result;
13831         uint8_t tc_num;
13832         uint8_t bw[16];
13833         int ret = -ENOTSUP;
13834
13835         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13836                 return;
13837
13838         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13839         if (ret)
13840                 return;
13841
13842 #ifdef RTE_LIBRTE_I40E_PMD
13843         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13844                                               tc_num, bw);
13845 #endif
13846
13847         switch (ret) {
13848         case 0:
13849                 break;
13850         case -EINVAL:
13851                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13852                 break;
13853         case -ENODEV:
13854                 printf("invalid port_id %d\n", res->port_id);
13855                 break;
13856         case -ENOTSUP:
13857                 printf("function not implemented\n");
13858                 break;
13859         default:
13860                 printf("programming error: (%s)\n", strerror(-ret));
13861         }
13862 }
13863
13864 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13865         .f = cmd_vf_tc_min_bw_parsed,
13866         .data = NULL,
13867         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13868                     " <bw1, bw2, ...>",
13869         .tokens = {
13870                 (void *)&cmd_vf_tc_bw_set,
13871                 (void *)&cmd_vf_tc_bw_vf,
13872                 (void *)&cmd_vf_tc_bw_tc,
13873                 (void *)&cmd_vf_tc_bw_tx,
13874                 (void *)&cmd_vf_tc_bw_min_bw,
13875                 (void *)&cmd_vf_tc_bw_port_id,
13876                 (void *)&cmd_vf_tc_bw_vf_id,
13877                 (void *)&cmd_vf_tc_bw_bw_list,
13878                 NULL,
13879         },
13880 };
13881
13882 static void
13883 cmd_tc_min_bw_parsed(
13884         void *parsed_result,
13885         __attribute__((unused)) struct cmdline *cl,
13886         __attribute__((unused)) void *data)
13887 {
13888         struct cmd_vf_tc_bw_result *res = parsed_result;
13889         struct rte_port *port;
13890         uint8_t tc_num;
13891         uint8_t bw[16];
13892         int ret = -ENOTSUP;
13893
13894         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13895                 return;
13896
13897         port = &ports[res->port_id];
13898         /** Check if the port is not started **/
13899         if (port->port_status != RTE_PORT_STOPPED) {
13900                 printf("Please stop port %d first\n", res->port_id);
13901                 return;
13902         }
13903
13904         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13905         if (ret)
13906                 return;
13907
13908 #ifdef RTE_LIBRTE_IXGBE_PMD
13909         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13910 #endif
13911
13912         switch (ret) {
13913         case 0:
13914                 break;
13915         case -EINVAL:
13916                 printf("invalid bandwidth\n");
13917                 break;
13918         case -ENODEV:
13919                 printf("invalid port_id %d\n", res->port_id);
13920                 break;
13921         case -ENOTSUP:
13922                 printf("function not implemented\n");
13923                 break;
13924         default:
13925                 printf("programming error: (%s)\n", strerror(-ret));
13926         }
13927 }
13928
13929 cmdline_parse_inst_t cmd_tc_min_bw = {
13930         .f = cmd_tc_min_bw_parsed,
13931         .data = NULL,
13932         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13933         .tokens = {
13934                 (void *)&cmd_vf_tc_bw_set,
13935                 (void *)&cmd_vf_tc_bw_tc,
13936                 (void *)&cmd_vf_tc_bw_tx,
13937                 (void *)&cmd_vf_tc_bw_min_bw,
13938                 (void *)&cmd_vf_tc_bw_port_id,
13939                 (void *)&cmd_vf_tc_bw_bw_list,
13940                 NULL,
13941         },
13942 };
13943
13944 /* TC max bandwidth setting */
13945 static void
13946 cmd_vf_tc_max_bw_parsed(
13947         void *parsed_result,
13948         __attribute__((unused)) struct cmdline *cl,
13949         __attribute__((unused)) void *data)
13950 {
13951         struct cmd_vf_tc_bw_result *res = parsed_result;
13952         int ret = -ENOTSUP;
13953
13954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13955                 return;
13956
13957 #ifdef RTE_LIBRTE_I40E_PMD
13958         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13959                                             res->tc_no, res->bw);
13960 #endif
13961
13962         switch (ret) {
13963         case 0:
13964                 break;
13965         case -EINVAL:
13966                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13967                        res->vf_id, res->tc_no, res->bw);
13968                 break;
13969         case -ENODEV:
13970                 printf("invalid port_id %d\n", res->port_id);
13971                 break;
13972         case -ENOTSUP:
13973                 printf("function not implemented\n");
13974                 break;
13975         default:
13976                 printf("programming error: (%s)\n", strerror(-ret));
13977         }
13978 }
13979
13980 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13981         .f = cmd_vf_tc_max_bw_parsed,
13982         .data = NULL,
13983         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13984                     " <bandwidth>",
13985         .tokens = {
13986                 (void *)&cmd_vf_tc_bw_set,
13987                 (void *)&cmd_vf_tc_bw_vf,
13988                 (void *)&cmd_vf_tc_bw_tc,
13989                 (void *)&cmd_vf_tc_bw_tx,
13990                 (void *)&cmd_vf_tc_bw_max_bw,
13991                 (void *)&cmd_vf_tc_bw_port_id,
13992                 (void *)&cmd_vf_tc_bw_vf_id,
13993                 (void *)&cmd_vf_tc_bw_tc_no,
13994                 (void *)&cmd_vf_tc_bw_bw,
13995                 NULL,
13996         },
13997 };
13998
13999
14000 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14001
14002 /* *** Set Port default Traffic Management Hierarchy *** */
14003 struct cmd_set_port_tm_hierarchy_default_result {
14004         cmdline_fixed_string_t set;
14005         cmdline_fixed_string_t port;
14006         cmdline_fixed_string_t tm;
14007         cmdline_fixed_string_t hierarchy;
14008         cmdline_fixed_string_t def;
14009         portid_t port_id;
14010 };
14011
14012 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14013         TOKEN_STRING_INITIALIZER(
14014                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14015 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14016         TOKEN_STRING_INITIALIZER(
14017                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14018 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14019         TOKEN_STRING_INITIALIZER(
14020                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14021 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14022         TOKEN_STRING_INITIALIZER(
14023                 struct cmd_set_port_tm_hierarchy_default_result,
14024                         hierarchy, "hierarchy");
14025 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14026         TOKEN_STRING_INITIALIZER(
14027                 struct cmd_set_port_tm_hierarchy_default_result,
14028                         def, "default");
14029 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14030         TOKEN_NUM_INITIALIZER(
14031                 struct cmd_set_port_tm_hierarchy_default_result,
14032                         port_id, UINT16);
14033
14034 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14035         __attribute__((unused)) struct cmdline *cl,
14036         __attribute__((unused)) void *data)
14037 {
14038         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14039         struct rte_port *p;
14040         portid_t port_id = res->port_id;
14041
14042         if (port_id_is_invalid(port_id, ENABLED_WARN))
14043                 return;
14044
14045         p = &ports[port_id];
14046
14047         /* Port tm flag */
14048         if (p->softport.tm_flag == 0) {
14049                 printf("  tm not enabled on port %u (error)\n", port_id);
14050                 return;
14051         }
14052
14053         /* Forward mode: tm */
14054         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14055                 printf("  tm mode not enabled(error)\n");
14056                 return;
14057         }
14058
14059         /* Set the default tm hierarchy */
14060         p->softport.tm.default_hierarchy_enable = 1;
14061 }
14062
14063 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14064         .f = cmd_set_port_tm_hierarchy_default_parsed,
14065         .data = NULL,
14066         .help_str = "set port tm hierarchy default <port_id>",
14067         .tokens = {
14068                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14069                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14070                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14071                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14072                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14073                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14074                 NULL,
14075         },
14076 };
14077 #endif
14078
14079 /* Strict link priority scheduling mode setting */
14080 static void
14081 cmd_strict_link_prio_parsed(
14082         void *parsed_result,
14083         __attribute__((unused)) struct cmdline *cl,
14084         __attribute__((unused)) void *data)
14085 {
14086         struct cmd_vf_tc_bw_result *res = parsed_result;
14087         int ret = -ENOTSUP;
14088
14089         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14090                 return;
14091
14092 #ifdef RTE_LIBRTE_I40E_PMD
14093         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14094 #endif
14095
14096         switch (ret) {
14097         case 0:
14098                 break;
14099         case -EINVAL:
14100                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14101                 break;
14102         case -ENODEV:
14103                 printf("invalid port_id %d\n", res->port_id);
14104                 break;
14105         case -ENOTSUP:
14106                 printf("function not implemented\n");
14107                 break;
14108         default:
14109                 printf("programming error: (%s)\n", strerror(-ret));
14110         }
14111 }
14112
14113 cmdline_parse_inst_t cmd_strict_link_prio = {
14114         .f = cmd_strict_link_prio_parsed,
14115         .data = NULL,
14116         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14117         .tokens = {
14118                 (void *)&cmd_vf_tc_bw_set,
14119                 (void *)&cmd_vf_tc_bw_tx,
14120                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14121                 (void *)&cmd_vf_tc_bw_port_id,
14122                 (void *)&cmd_vf_tc_bw_tc_map,
14123                 NULL,
14124         },
14125 };
14126
14127 /* Load dynamic device personalization*/
14128 struct cmd_ddp_add_result {
14129         cmdline_fixed_string_t ddp;
14130         cmdline_fixed_string_t add;
14131         portid_t port_id;
14132         char filepath[];
14133 };
14134
14135 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14136         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14137 cmdline_parse_token_string_t cmd_ddp_add_add =
14138         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14139 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14140         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14141 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14142         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14143
14144 static void
14145 cmd_ddp_add_parsed(
14146         void *parsed_result,
14147         __attribute__((unused)) struct cmdline *cl,
14148         __attribute__((unused)) void *data)
14149 {
14150         struct cmd_ddp_add_result *res = parsed_result;
14151         uint8_t *buff;
14152         uint32_t size;
14153         char *filepath;
14154         char *file_fld[2];
14155         int file_num;
14156         int ret = -ENOTSUP;
14157
14158         if (res->port_id > nb_ports) {
14159                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14160                 return;
14161         }
14162
14163         if (!all_ports_stopped()) {
14164                 printf("Please stop all ports first\n");
14165                 return;
14166         }
14167
14168         filepath = strdup(res->filepath);
14169         if (filepath == NULL) {
14170                 printf("Failed to allocate memory\n");
14171                 return;
14172         }
14173         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14174
14175         buff = open_ddp_package_file(file_fld[0], &size);
14176         if (!buff) {
14177                 free((void *)filepath);
14178                 return;
14179         }
14180
14181 #ifdef RTE_LIBRTE_I40E_PMD
14182         if (ret == -ENOTSUP)
14183                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14184                                                buff, size,
14185                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14186 #endif
14187
14188         if (ret == -EEXIST)
14189                 printf("Profile has already existed.\n");
14190         else if (ret < 0)
14191                 printf("Failed to load profile.\n");
14192         else if (file_num == 2)
14193                 save_ddp_package_file(file_fld[1], buff, size);
14194
14195         close_ddp_package_file(buff);
14196         free((void *)filepath);
14197 }
14198
14199 cmdline_parse_inst_t cmd_ddp_add = {
14200         .f = cmd_ddp_add_parsed,
14201         .data = NULL,
14202         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14203         .tokens = {
14204                 (void *)&cmd_ddp_add_ddp,
14205                 (void *)&cmd_ddp_add_add,
14206                 (void *)&cmd_ddp_add_port_id,
14207                 (void *)&cmd_ddp_add_filepath,
14208                 NULL,
14209         },
14210 };
14211
14212 /* Delete dynamic device personalization*/
14213 struct cmd_ddp_del_result {
14214         cmdline_fixed_string_t ddp;
14215         cmdline_fixed_string_t del;
14216         portid_t port_id;
14217         char filepath[];
14218 };
14219
14220 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14221         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14222 cmdline_parse_token_string_t cmd_ddp_del_del =
14223         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14224 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14225         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14226 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14227         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14228
14229 static void
14230 cmd_ddp_del_parsed(
14231         void *parsed_result,
14232         __attribute__((unused)) struct cmdline *cl,
14233         __attribute__((unused)) void *data)
14234 {
14235         struct cmd_ddp_del_result *res = parsed_result;
14236         uint8_t *buff;
14237         uint32_t size;
14238         int ret = -ENOTSUP;
14239
14240         if (res->port_id > nb_ports) {
14241                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14242                 return;
14243         }
14244
14245         if (!all_ports_stopped()) {
14246                 printf("Please stop all ports first\n");
14247                 return;
14248         }
14249
14250         buff = open_ddp_package_file(res->filepath, &size);
14251         if (!buff)
14252                 return;
14253
14254 #ifdef RTE_LIBRTE_I40E_PMD
14255         if (ret == -ENOTSUP)
14256                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14257                                                buff, size,
14258                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14259 #endif
14260
14261         if (ret == -EACCES)
14262                 printf("Profile does not exist.\n");
14263         else if (ret < 0)
14264                 printf("Failed to delete profile.\n");
14265
14266         close_ddp_package_file(buff);
14267 }
14268
14269 cmdline_parse_inst_t cmd_ddp_del = {
14270         .f = cmd_ddp_del_parsed,
14271         .data = NULL,
14272         .help_str = "ddp del <port_id> <profile_path>",
14273         .tokens = {
14274                 (void *)&cmd_ddp_del_ddp,
14275                 (void *)&cmd_ddp_del_del,
14276                 (void *)&cmd_ddp_del_port_id,
14277                 (void *)&cmd_ddp_del_filepath,
14278                 NULL,
14279         },
14280 };
14281
14282 /* Get dynamic device personalization profile info */
14283 struct cmd_ddp_info_result {
14284         cmdline_fixed_string_t ddp;
14285         cmdline_fixed_string_t get;
14286         cmdline_fixed_string_t info;
14287         char filepath[];
14288 };
14289
14290 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14291         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14292 cmdline_parse_token_string_t cmd_ddp_info_get =
14293         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14294 cmdline_parse_token_string_t cmd_ddp_info_info =
14295         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14296 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14297         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14298
14299 static void
14300 cmd_ddp_info_parsed(
14301         void *parsed_result,
14302         __attribute__((unused)) struct cmdline *cl,
14303         __attribute__((unused)) void *data)
14304 {
14305         struct cmd_ddp_info_result *res = parsed_result;
14306         uint8_t *pkg;
14307         uint32_t pkg_size;
14308         int ret = -ENOTSUP;
14309 #ifdef RTE_LIBRTE_I40E_PMD
14310         uint32_t i, j, n;
14311         uint8_t *buff;
14312         uint32_t buff_size = 0;
14313         struct rte_pmd_i40e_profile_info info;
14314         uint32_t dev_num = 0;
14315         struct rte_pmd_i40e_ddp_device_id *devs;
14316         uint32_t proto_num = 0;
14317         struct rte_pmd_i40e_proto_info *proto;
14318         uint32_t pctype_num = 0;
14319         struct rte_pmd_i40e_ptype_info *pctype;
14320         uint32_t ptype_num = 0;
14321         struct rte_pmd_i40e_ptype_info *ptype;
14322         uint8_t proto_id;
14323
14324 #endif
14325
14326         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14327         if (!pkg)
14328                 return;
14329
14330 #ifdef RTE_LIBRTE_I40E_PMD
14331         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14332                                 (uint8_t *)&info, sizeof(info),
14333                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14334         if (!ret) {
14335                 printf("Global Track id:       0x%x\n", info.track_id);
14336                 printf("Global Version:        %d.%d.%d.%d\n",
14337                         info.version.major,
14338                         info.version.minor,
14339                         info.version.update,
14340                         info.version.draft);
14341                 printf("Global Package name:   %s\n\n", info.name);
14342         }
14343
14344         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14345                                 (uint8_t *)&info, sizeof(info),
14346                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14347         if (!ret) {
14348                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14349                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14350                         info.version.major,
14351                         info.version.minor,
14352                         info.version.update,
14353                         info.version.draft);
14354                 printf("i40e Profile name:     %s\n\n", info.name);
14355         }
14356
14357         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14358                                 (uint8_t *)&buff_size, sizeof(buff_size),
14359                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14360         if (!ret && buff_size) {
14361                 buff = (uint8_t *)malloc(buff_size);
14362                 if (buff) {
14363                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14364                                                 buff, buff_size,
14365                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14366                         if (!ret)
14367                                 printf("Package Notes:\n%s\n\n", buff);
14368                         free(buff);
14369                 }
14370         }
14371
14372         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14373                                 (uint8_t *)&dev_num, sizeof(dev_num),
14374                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14375         if (!ret && dev_num) {
14376                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14377                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14378                 if (devs) {
14379                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14380                                                 (uint8_t *)devs, buff_size,
14381                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14382                         if (!ret) {
14383                                 printf("List of supported devices:\n");
14384                                 for (i = 0; i < dev_num; i++) {
14385                                         printf("  %04X:%04X %04X:%04X\n",
14386                                                 devs[i].vendor_dev_id >> 16,
14387                                                 devs[i].vendor_dev_id & 0xFFFF,
14388                                                 devs[i].sub_vendor_dev_id >> 16,
14389                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14390                                 }
14391                                 printf("\n");
14392                         }
14393                         free(devs);
14394                 }
14395         }
14396
14397         /* get information about protocols and packet types */
14398         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14399                 (uint8_t *)&proto_num, sizeof(proto_num),
14400                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14401         if (ret || !proto_num)
14402                 goto no_print_return;
14403
14404         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14405         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14406         if (!proto)
14407                 goto no_print_return;
14408
14409         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14410                                         buff_size,
14411                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14412         if (!ret) {
14413                 printf("List of used protocols:\n");
14414                 for (i = 0; i < proto_num; i++)
14415                         printf("  %2u: %s\n", proto[i].proto_id,
14416                                proto[i].name);
14417                 printf("\n");
14418         }
14419         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14420                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14421                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14422         if (ret || !pctype_num)
14423                 goto no_print_pctypes;
14424
14425         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14426         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14427         if (!pctype)
14428                 goto no_print_pctypes;
14429
14430         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14431                                         buff_size,
14432                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14433         if (ret) {
14434                 free(pctype);
14435                 goto no_print_pctypes;
14436         }
14437
14438         printf("List of defined packet classification types:\n");
14439         for (i = 0; i < pctype_num; i++) {
14440                 printf("  %2u:", pctype[i].ptype_id);
14441                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14442                         proto_id = pctype[i].protocols[j];
14443                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14444                                 for (n = 0; n < proto_num; n++) {
14445                                         if (proto[n].proto_id == proto_id) {
14446                                                 printf(" %s", proto[n].name);
14447                                                 break;
14448                                         }
14449                                 }
14450                         }
14451                 }
14452                 printf("\n");
14453         }
14454         printf("\n");
14455         free(pctype);
14456
14457 no_print_pctypes:
14458
14459         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14460                                         sizeof(ptype_num),
14461                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14462         if (ret || !ptype_num)
14463                 goto no_print_return;
14464
14465         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14466         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14467         if (!ptype)
14468                 goto no_print_return;
14469
14470         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14471                                         buff_size,
14472                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14473         if (ret) {
14474                 free(ptype);
14475                 goto no_print_return;
14476         }
14477         printf("List of defined packet types:\n");
14478         for (i = 0; i < ptype_num; i++) {
14479                 printf("  %2u:", ptype[i].ptype_id);
14480                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14481                         proto_id = ptype[i].protocols[j];
14482                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14483                                 for (n = 0; n < proto_num; n++) {
14484                                         if (proto[n].proto_id == proto_id) {
14485                                                 printf(" %s", proto[n].name);
14486                                                 break;
14487                                         }
14488                                 }
14489                         }
14490                 }
14491                 printf("\n");
14492         }
14493         free(ptype);
14494         printf("\n");
14495
14496         free(proto);
14497         ret = 0;
14498 no_print_return:
14499 #endif
14500         if (ret == -ENOTSUP)
14501                 printf("Function not supported in PMD driver\n");
14502         close_ddp_package_file(pkg);
14503 }
14504
14505 cmdline_parse_inst_t cmd_ddp_get_info = {
14506         .f = cmd_ddp_info_parsed,
14507         .data = NULL,
14508         .help_str = "ddp get info <profile_path>",
14509         .tokens = {
14510                 (void *)&cmd_ddp_info_ddp,
14511                 (void *)&cmd_ddp_info_get,
14512                 (void *)&cmd_ddp_info_info,
14513                 (void *)&cmd_ddp_info_filepath,
14514                 NULL,
14515         },
14516 };
14517
14518 /* Get dynamic device personalization profile info list*/
14519 #define PROFILE_INFO_SIZE 48
14520 #define MAX_PROFILE_NUM 16
14521
14522 struct cmd_ddp_get_list_result {
14523         cmdline_fixed_string_t ddp;
14524         cmdline_fixed_string_t get;
14525         cmdline_fixed_string_t list;
14526         portid_t port_id;
14527 };
14528
14529 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14530         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14531 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14532         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14533 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14534         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14535 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14536         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14537
14538 static void
14539 cmd_ddp_get_list_parsed(
14540         void *parsed_result,
14541         __attribute__((unused)) struct cmdline *cl,
14542         __attribute__((unused)) void *data)
14543 {
14544         struct cmd_ddp_get_list_result *res = parsed_result;
14545 #ifdef RTE_LIBRTE_I40E_PMD
14546         struct rte_pmd_i40e_profile_list *p_list;
14547         struct rte_pmd_i40e_profile_info *p_info;
14548         uint32_t p_num;
14549         uint32_t size;
14550         uint32_t i;
14551 #endif
14552         int ret = -ENOTSUP;
14553
14554         if (res->port_id > nb_ports) {
14555                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14556                 return;
14557         }
14558
14559 #ifdef RTE_LIBRTE_I40E_PMD
14560         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14561         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14562         if (!p_list)
14563                 printf("%s: Failed to malloc buffer\n", __func__);
14564
14565         if (ret == -ENOTSUP)
14566                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14567                                                 (uint8_t *)p_list, size);
14568
14569         if (!ret) {
14570                 p_num = p_list->p_count;
14571                 printf("Profile number is: %d\n\n", p_num);
14572
14573                 for (i = 0; i < p_num; i++) {
14574                         p_info = &p_list->p_info[i];
14575                         printf("Profile %d:\n", i);
14576                         printf("Track id:     0x%x\n", p_info->track_id);
14577                         printf("Version:      %d.%d.%d.%d\n",
14578                                p_info->version.major,
14579                                p_info->version.minor,
14580                                p_info->version.update,
14581                                p_info->version.draft);
14582                         printf("Profile name: %s\n\n", p_info->name);
14583                 }
14584         }
14585
14586         free(p_list);
14587 #endif
14588
14589         if (ret < 0)
14590                 printf("Failed to get ddp list\n");
14591 }
14592
14593 cmdline_parse_inst_t cmd_ddp_get_list = {
14594         .f = cmd_ddp_get_list_parsed,
14595         .data = NULL,
14596         .help_str = "ddp get list <port_id>",
14597         .tokens = {
14598                 (void *)&cmd_ddp_get_list_ddp,
14599                 (void *)&cmd_ddp_get_list_get,
14600                 (void *)&cmd_ddp_get_list_list,
14601                 (void *)&cmd_ddp_get_list_port_id,
14602                 NULL,
14603         },
14604 };
14605
14606 /* show vf stats */
14607
14608 /* Common result structure for show vf stats */
14609 struct cmd_show_vf_stats_result {
14610         cmdline_fixed_string_t show;
14611         cmdline_fixed_string_t vf;
14612         cmdline_fixed_string_t stats;
14613         portid_t port_id;
14614         uint16_t vf_id;
14615 };
14616
14617 /* Common CLI fields show vf stats*/
14618 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14619         TOKEN_STRING_INITIALIZER
14620                 (struct cmd_show_vf_stats_result,
14621                  show, "show");
14622 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14623         TOKEN_STRING_INITIALIZER
14624                 (struct cmd_show_vf_stats_result,
14625                  vf, "vf");
14626 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14627         TOKEN_STRING_INITIALIZER
14628                 (struct cmd_show_vf_stats_result,
14629                  stats, "stats");
14630 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14631         TOKEN_NUM_INITIALIZER
14632                 (struct cmd_show_vf_stats_result,
14633                  port_id, UINT16);
14634 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14635         TOKEN_NUM_INITIALIZER
14636                 (struct cmd_show_vf_stats_result,
14637                  vf_id, UINT16);
14638
14639 static void
14640 cmd_show_vf_stats_parsed(
14641         void *parsed_result,
14642         __attribute__((unused)) struct cmdline *cl,
14643         __attribute__((unused)) void *data)
14644 {
14645         struct cmd_show_vf_stats_result *res = parsed_result;
14646         struct rte_eth_stats stats;
14647         int ret = -ENOTSUP;
14648         static const char *nic_stats_border = "########################";
14649
14650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14651                 return;
14652
14653         memset(&stats, 0, sizeof(stats));
14654
14655 #ifdef RTE_LIBRTE_I40E_PMD
14656         if (ret == -ENOTSUP)
14657                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14658                                                 res->vf_id,
14659                                                 &stats);
14660 #endif
14661 #ifdef RTE_LIBRTE_BNXT_PMD
14662         if (ret == -ENOTSUP)
14663                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14664                                                 res->vf_id,
14665                                                 &stats);
14666 #endif
14667
14668         switch (ret) {
14669         case 0:
14670                 break;
14671         case -EINVAL:
14672                 printf("invalid vf_id %d\n", res->vf_id);
14673                 break;
14674         case -ENODEV:
14675                 printf("invalid port_id %d\n", res->port_id);
14676                 break;
14677         case -ENOTSUP:
14678                 printf("function not implemented\n");
14679                 break;
14680         default:
14681                 printf("programming error: (%s)\n", strerror(-ret));
14682         }
14683
14684         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14685                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14686
14687         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14688                "%-"PRIu64"\n",
14689                stats.ipackets, stats.imissed, stats.ibytes);
14690         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14691         printf("  RX-nombuf:  %-10"PRIu64"\n",
14692                stats.rx_nombuf);
14693         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14694                "%-"PRIu64"\n",
14695                stats.opackets, stats.oerrors, stats.obytes);
14696
14697         printf("  %s############################%s\n",
14698                                nic_stats_border, nic_stats_border);
14699 }
14700
14701 cmdline_parse_inst_t cmd_show_vf_stats = {
14702         .f = cmd_show_vf_stats_parsed,
14703         .data = NULL,
14704         .help_str = "show vf stats <port_id> <vf_id>",
14705         .tokens = {
14706                 (void *)&cmd_show_vf_stats_show,
14707                 (void *)&cmd_show_vf_stats_vf,
14708                 (void *)&cmd_show_vf_stats_stats,
14709                 (void *)&cmd_show_vf_stats_port_id,
14710                 (void *)&cmd_show_vf_stats_vf_id,
14711                 NULL,
14712         },
14713 };
14714
14715 /* clear vf stats */
14716
14717 /* Common result structure for clear vf stats */
14718 struct cmd_clear_vf_stats_result {
14719         cmdline_fixed_string_t clear;
14720         cmdline_fixed_string_t vf;
14721         cmdline_fixed_string_t stats;
14722         portid_t port_id;
14723         uint16_t vf_id;
14724 };
14725
14726 /* Common CLI fields clear vf stats*/
14727 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14728         TOKEN_STRING_INITIALIZER
14729                 (struct cmd_clear_vf_stats_result,
14730                  clear, "clear");
14731 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14732         TOKEN_STRING_INITIALIZER
14733                 (struct cmd_clear_vf_stats_result,
14734                  vf, "vf");
14735 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14736         TOKEN_STRING_INITIALIZER
14737                 (struct cmd_clear_vf_stats_result,
14738                  stats, "stats");
14739 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14740         TOKEN_NUM_INITIALIZER
14741                 (struct cmd_clear_vf_stats_result,
14742                  port_id, UINT16);
14743 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14744         TOKEN_NUM_INITIALIZER
14745                 (struct cmd_clear_vf_stats_result,
14746                  vf_id, UINT16);
14747
14748 static void
14749 cmd_clear_vf_stats_parsed(
14750         void *parsed_result,
14751         __attribute__((unused)) struct cmdline *cl,
14752         __attribute__((unused)) void *data)
14753 {
14754         struct cmd_clear_vf_stats_result *res = parsed_result;
14755         int ret = -ENOTSUP;
14756
14757         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14758                 return;
14759
14760 #ifdef RTE_LIBRTE_I40E_PMD
14761         if (ret == -ENOTSUP)
14762                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14763                                                   res->vf_id);
14764 #endif
14765 #ifdef RTE_LIBRTE_BNXT_PMD
14766         if (ret == -ENOTSUP)
14767                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14768                                                   res->vf_id);
14769 #endif
14770
14771         switch (ret) {
14772         case 0:
14773                 break;
14774         case -EINVAL:
14775                 printf("invalid vf_id %d\n", res->vf_id);
14776                 break;
14777         case -ENODEV:
14778                 printf("invalid port_id %d\n", res->port_id);
14779                 break;
14780         case -ENOTSUP:
14781                 printf("function not implemented\n");
14782                 break;
14783         default:
14784                 printf("programming error: (%s)\n", strerror(-ret));
14785         }
14786 }
14787
14788 cmdline_parse_inst_t cmd_clear_vf_stats = {
14789         .f = cmd_clear_vf_stats_parsed,
14790         .data = NULL,
14791         .help_str = "clear vf stats <port_id> <vf_id>",
14792         .tokens = {
14793                 (void *)&cmd_clear_vf_stats_clear,
14794                 (void *)&cmd_clear_vf_stats_vf,
14795                 (void *)&cmd_clear_vf_stats_stats,
14796                 (void *)&cmd_clear_vf_stats_port_id,
14797                 (void *)&cmd_clear_vf_stats_vf_id,
14798                 NULL,
14799         },
14800 };
14801
14802 /* port config pctype mapping reset */
14803
14804 /* Common result structure for port config pctype mapping reset */
14805 struct cmd_pctype_mapping_reset_result {
14806         cmdline_fixed_string_t port;
14807         cmdline_fixed_string_t config;
14808         portid_t port_id;
14809         cmdline_fixed_string_t pctype;
14810         cmdline_fixed_string_t mapping;
14811         cmdline_fixed_string_t reset;
14812 };
14813
14814 /* Common CLI fields for port config pctype mapping reset*/
14815 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14816         TOKEN_STRING_INITIALIZER
14817                 (struct cmd_pctype_mapping_reset_result,
14818                  port, "port");
14819 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14820         TOKEN_STRING_INITIALIZER
14821                 (struct cmd_pctype_mapping_reset_result,
14822                  config, "config");
14823 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14824         TOKEN_NUM_INITIALIZER
14825                 (struct cmd_pctype_mapping_reset_result,
14826                  port_id, UINT16);
14827 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14828         TOKEN_STRING_INITIALIZER
14829                 (struct cmd_pctype_mapping_reset_result,
14830                  pctype, "pctype");
14831 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14832         TOKEN_STRING_INITIALIZER
14833                 (struct cmd_pctype_mapping_reset_result,
14834                  mapping, "mapping");
14835 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14836         TOKEN_STRING_INITIALIZER
14837                 (struct cmd_pctype_mapping_reset_result,
14838                  reset, "reset");
14839
14840 static void
14841 cmd_pctype_mapping_reset_parsed(
14842         void *parsed_result,
14843         __attribute__((unused)) struct cmdline *cl,
14844         __attribute__((unused)) void *data)
14845 {
14846         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14847         int ret = -ENOTSUP;
14848
14849         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14850                 return;
14851
14852 #ifdef RTE_LIBRTE_I40E_PMD
14853         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14854 #endif
14855
14856         switch (ret) {
14857         case 0:
14858                 break;
14859         case -ENODEV:
14860                 printf("invalid port_id %d\n", res->port_id);
14861                 break;
14862         case -ENOTSUP:
14863                 printf("function not implemented\n");
14864                 break;
14865         default:
14866                 printf("programming error: (%s)\n", strerror(-ret));
14867         }
14868 }
14869
14870 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14871         .f = cmd_pctype_mapping_reset_parsed,
14872         .data = NULL,
14873         .help_str = "port config <port_id> pctype mapping reset",
14874         .tokens = {
14875                 (void *)&cmd_pctype_mapping_reset_port,
14876                 (void *)&cmd_pctype_mapping_reset_config,
14877                 (void *)&cmd_pctype_mapping_reset_port_id,
14878                 (void *)&cmd_pctype_mapping_reset_pctype,
14879                 (void *)&cmd_pctype_mapping_reset_mapping,
14880                 (void *)&cmd_pctype_mapping_reset_reset,
14881                 NULL,
14882         },
14883 };
14884
14885 /* show port pctype mapping */
14886
14887 /* Common result structure for show port pctype mapping */
14888 struct cmd_pctype_mapping_get_result {
14889         cmdline_fixed_string_t show;
14890         cmdline_fixed_string_t port;
14891         portid_t port_id;
14892         cmdline_fixed_string_t pctype;
14893         cmdline_fixed_string_t mapping;
14894 };
14895
14896 /* Common CLI fields for pctype mapping get */
14897 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14898         TOKEN_STRING_INITIALIZER
14899                 (struct cmd_pctype_mapping_get_result,
14900                  show, "show");
14901 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14902         TOKEN_STRING_INITIALIZER
14903                 (struct cmd_pctype_mapping_get_result,
14904                  port, "port");
14905 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14906         TOKEN_NUM_INITIALIZER
14907                 (struct cmd_pctype_mapping_get_result,
14908                  port_id, UINT16);
14909 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14910         TOKEN_STRING_INITIALIZER
14911                 (struct cmd_pctype_mapping_get_result,
14912                  pctype, "pctype");
14913 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14914         TOKEN_STRING_INITIALIZER
14915                 (struct cmd_pctype_mapping_get_result,
14916                  mapping, "mapping");
14917
14918 static void
14919 cmd_pctype_mapping_get_parsed(
14920         void *parsed_result,
14921         __attribute__((unused)) struct cmdline *cl,
14922         __attribute__((unused)) void *data)
14923 {
14924         struct cmd_pctype_mapping_get_result *res = parsed_result;
14925         int ret = -ENOTSUP;
14926 #ifdef RTE_LIBRTE_I40E_PMD
14927         struct rte_pmd_i40e_flow_type_mapping
14928                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14929         int i, j, first_pctype;
14930 #endif
14931
14932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14933                 return;
14934
14935 #ifdef RTE_LIBRTE_I40E_PMD
14936         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14937 #endif
14938
14939         switch (ret) {
14940         case 0:
14941                 break;
14942         case -ENODEV:
14943                 printf("invalid port_id %d\n", res->port_id);
14944                 return;
14945         case -ENOTSUP:
14946                 printf("function not implemented\n");
14947                 return;
14948         default:
14949                 printf("programming error: (%s)\n", strerror(-ret));
14950                 return;
14951         }
14952
14953 #ifdef RTE_LIBRTE_I40E_PMD
14954         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14955                 if (mapping[i].pctype != 0ULL) {
14956                         first_pctype = 1;
14957
14958                         printf("pctype: ");
14959                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14960                                 if (mapping[i].pctype & (1ULL << j)) {
14961                                         printf(first_pctype ?
14962                                                "%02d" : ",%02d", j);
14963                                         first_pctype = 0;
14964                                 }
14965                         }
14966                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14967                 }
14968         }
14969 #endif
14970 }
14971
14972 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14973         .f = cmd_pctype_mapping_get_parsed,
14974         .data = NULL,
14975         .help_str = "show port <port_id> pctype mapping",
14976         .tokens = {
14977                 (void *)&cmd_pctype_mapping_get_show,
14978                 (void *)&cmd_pctype_mapping_get_port,
14979                 (void *)&cmd_pctype_mapping_get_port_id,
14980                 (void *)&cmd_pctype_mapping_get_pctype,
14981                 (void *)&cmd_pctype_mapping_get_mapping,
14982                 NULL,
14983         },
14984 };
14985
14986 /* port config pctype mapping update */
14987
14988 /* Common result structure for port config pctype mapping update */
14989 struct cmd_pctype_mapping_update_result {
14990         cmdline_fixed_string_t port;
14991         cmdline_fixed_string_t config;
14992         portid_t port_id;
14993         cmdline_fixed_string_t pctype;
14994         cmdline_fixed_string_t mapping;
14995         cmdline_fixed_string_t update;
14996         cmdline_fixed_string_t pctype_list;
14997         uint16_t flow_type;
14998 };
14999
15000 /* Common CLI fields for pctype mapping update*/
15001 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15002         TOKEN_STRING_INITIALIZER
15003                 (struct cmd_pctype_mapping_update_result,
15004                  port, "port");
15005 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15006         TOKEN_STRING_INITIALIZER
15007                 (struct cmd_pctype_mapping_update_result,
15008                  config, "config");
15009 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15010         TOKEN_NUM_INITIALIZER
15011                 (struct cmd_pctype_mapping_update_result,
15012                  port_id, UINT16);
15013 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15014         TOKEN_STRING_INITIALIZER
15015                 (struct cmd_pctype_mapping_update_result,
15016                  pctype, "pctype");
15017 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15018         TOKEN_STRING_INITIALIZER
15019                 (struct cmd_pctype_mapping_update_result,
15020                  mapping, "mapping");
15021 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15022         TOKEN_STRING_INITIALIZER
15023                 (struct cmd_pctype_mapping_update_result,
15024                  update, "update");
15025 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15026         TOKEN_STRING_INITIALIZER
15027                 (struct cmd_pctype_mapping_update_result,
15028                  pctype_list, NULL);
15029 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15030         TOKEN_NUM_INITIALIZER
15031                 (struct cmd_pctype_mapping_update_result,
15032                  flow_type, UINT16);
15033
15034 static void
15035 cmd_pctype_mapping_update_parsed(
15036         void *parsed_result,
15037         __attribute__((unused)) struct cmdline *cl,
15038         __attribute__((unused)) void *data)
15039 {
15040         struct cmd_pctype_mapping_update_result *res = parsed_result;
15041         int ret = -ENOTSUP;
15042 #ifdef RTE_LIBRTE_I40E_PMD
15043         struct rte_pmd_i40e_flow_type_mapping mapping;
15044         unsigned int i;
15045         unsigned int nb_item;
15046         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15047 #endif
15048
15049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15050                 return;
15051
15052 #ifdef RTE_LIBRTE_I40E_PMD
15053         nb_item = parse_item_list(res->pctype_list, "pctypes",
15054                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15055         mapping.flow_type = res->flow_type;
15056         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15057                 mapping.pctype |= (1ULL << pctype_list[i]);
15058         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15059                                                 &mapping,
15060                                                 1,
15061                                                 0);
15062 #endif
15063
15064         switch (ret) {
15065         case 0:
15066                 break;
15067         case -EINVAL:
15068                 printf("invalid pctype or flow type\n");
15069                 break;
15070         case -ENODEV:
15071                 printf("invalid port_id %d\n", res->port_id);
15072                 break;
15073         case -ENOTSUP:
15074                 printf("function not implemented\n");
15075                 break;
15076         default:
15077                 printf("programming error: (%s)\n", strerror(-ret));
15078         }
15079 }
15080
15081 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15082         .f = cmd_pctype_mapping_update_parsed,
15083         .data = NULL,
15084         .help_str = "port config <port_id> pctype mapping update"
15085         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15086         .tokens = {
15087                 (void *)&cmd_pctype_mapping_update_port,
15088                 (void *)&cmd_pctype_mapping_update_config,
15089                 (void *)&cmd_pctype_mapping_update_port_id,
15090                 (void *)&cmd_pctype_mapping_update_pctype,
15091                 (void *)&cmd_pctype_mapping_update_mapping,
15092                 (void *)&cmd_pctype_mapping_update_update,
15093                 (void *)&cmd_pctype_mapping_update_pc_type,
15094                 (void *)&cmd_pctype_mapping_update_flow_type,
15095                 NULL,
15096         },
15097 };
15098
15099 /* ptype mapping get */
15100
15101 /* Common result structure for ptype mapping get */
15102 struct cmd_ptype_mapping_get_result {
15103         cmdline_fixed_string_t ptype;
15104         cmdline_fixed_string_t mapping;
15105         cmdline_fixed_string_t get;
15106         portid_t port_id;
15107         uint8_t valid_only;
15108 };
15109
15110 /* Common CLI fields for ptype mapping get */
15111 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15112         TOKEN_STRING_INITIALIZER
15113                 (struct cmd_ptype_mapping_get_result,
15114                  ptype, "ptype");
15115 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15116         TOKEN_STRING_INITIALIZER
15117                 (struct cmd_ptype_mapping_get_result,
15118                  mapping, "mapping");
15119 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15120         TOKEN_STRING_INITIALIZER
15121                 (struct cmd_ptype_mapping_get_result,
15122                  get, "get");
15123 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15124         TOKEN_NUM_INITIALIZER
15125                 (struct cmd_ptype_mapping_get_result,
15126                  port_id, UINT16);
15127 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15128         TOKEN_NUM_INITIALIZER
15129                 (struct cmd_ptype_mapping_get_result,
15130                  valid_only, UINT8);
15131
15132 static void
15133 cmd_ptype_mapping_get_parsed(
15134         void *parsed_result,
15135         __attribute__((unused)) struct cmdline *cl,
15136         __attribute__((unused)) void *data)
15137 {
15138         struct cmd_ptype_mapping_get_result *res = parsed_result;
15139         int ret = -ENOTSUP;
15140 #ifdef RTE_LIBRTE_I40E_PMD
15141         int max_ptype_num = 256;
15142         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15143         uint16_t count;
15144         int i;
15145 #endif
15146
15147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15148                 return;
15149
15150 #ifdef RTE_LIBRTE_I40E_PMD
15151         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15152                                         mapping,
15153                                         max_ptype_num,
15154                                         &count,
15155                                         res->valid_only);
15156 #endif
15157
15158         switch (ret) {
15159         case 0:
15160                 break;
15161         case -ENODEV:
15162                 printf("invalid port_id %d\n", res->port_id);
15163                 break;
15164         case -ENOTSUP:
15165                 printf("function not implemented\n");
15166                 break;
15167         default:
15168                 printf("programming error: (%s)\n", strerror(-ret));
15169         }
15170
15171 #ifdef RTE_LIBRTE_I40E_PMD
15172         if (!ret) {
15173                 for (i = 0; i < count; i++)
15174                         printf("%3d\t0x%08x\n",
15175                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15176         }
15177 #endif
15178 }
15179
15180 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15181         .f = cmd_ptype_mapping_get_parsed,
15182         .data = NULL,
15183         .help_str = "ptype mapping get <port_id> <valid_only>",
15184         .tokens = {
15185                 (void *)&cmd_ptype_mapping_get_ptype,
15186                 (void *)&cmd_ptype_mapping_get_mapping,
15187                 (void *)&cmd_ptype_mapping_get_get,
15188                 (void *)&cmd_ptype_mapping_get_port_id,
15189                 (void *)&cmd_ptype_mapping_get_valid_only,
15190                 NULL,
15191         },
15192 };
15193
15194 /* ptype mapping replace */
15195
15196 /* Common result structure for ptype mapping replace */
15197 struct cmd_ptype_mapping_replace_result {
15198         cmdline_fixed_string_t ptype;
15199         cmdline_fixed_string_t mapping;
15200         cmdline_fixed_string_t replace;
15201         portid_t port_id;
15202         uint32_t target;
15203         uint8_t mask;
15204         uint32_t pkt_type;
15205 };
15206
15207 /* Common CLI fields for ptype mapping replace */
15208 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15209         TOKEN_STRING_INITIALIZER
15210                 (struct cmd_ptype_mapping_replace_result,
15211                  ptype, "ptype");
15212 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15213         TOKEN_STRING_INITIALIZER
15214                 (struct cmd_ptype_mapping_replace_result,
15215                  mapping, "mapping");
15216 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15217         TOKEN_STRING_INITIALIZER
15218                 (struct cmd_ptype_mapping_replace_result,
15219                  replace, "replace");
15220 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15221         TOKEN_NUM_INITIALIZER
15222                 (struct cmd_ptype_mapping_replace_result,
15223                  port_id, UINT16);
15224 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15225         TOKEN_NUM_INITIALIZER
15226                 (struct cmd_ptype_mapping_replace_result,
15227                  target, UINT32);
15228 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15229         TOKEN_NUM_INITIALIZER
15230                 (struct cmd_ptype_mapping_replace_result,
15231                  mask, UINT8);
15232 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15233         TOKEN_NUM_INITIALIZER
15234                 (struct cmd_ptype_mapping_replace_result,
15235                  pkt_type, UINT32);
15236
15237 static void
15238 cmd_ptype_mapping_replace_parsed(
15239         void *parsed_result,
15240         __attribute__((unused)) struct cmdline *cl,
15241         __attribute__((unused)) void *data)
15242 {
15243         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15244         int ret = -ENOTSUP;
15245
15246         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15247                 return;
15248
15249 #ifdef RTE_LIBRTE_I40E_PMD
15250         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15251                                         res->target,
15252                                         res->mask,
15253                                         res->pkt_type);
15254 #endif
15255
15256         switch (ret) {
15257         case 0:
15258                 break;
15259         case -EINVAL:
15260                 printf("invalid ptype 0x%8x or 0x%8x\n",
15261                                 res->target, res->pkt_type);
15262                 break;
15263         case -ENODEV:
15264                 printf("invalid port_id %d\n", res->port_id);
15265                 break;
15266         case -ENOTSUP:
15267                 printf("function not implemented\n");
15268                 break;
15269         default:
15270                 printf("programming error: (%s)\n", strerror(-ret));
15271         }
15272 }
15273
15274 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15275         .f = cmd_ptype_mapping_replace_parsed,
15276         .data = NULL,
15277         .help_str =
15278                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15279         .tokens = {
15280                 (void *)&cmd_ptype_mapping_replace_ptype,
15281                 (void *)&cmd_ptype_mapping_replace_mapping,
15282                 (void *)&cmd_ptype_mapping_replace_replace,
15283                 (void *)&cmd_ptype_mapping_replace_port_id,
15284                 (void *)&cmd_ptype_mapping_replace_target,
15285                 (void *)&cmd_ptype_mapping_replace_mask,
15286                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15287                 NULL,
15288         },
15289 };
15290
15291 /* ptype mapping reset */
15292
15293 /* Common result structure for ptype mapping reset */
15294 struct cmd_ptype_mapping_reset_result {
15295         cmdline_fixed_string_t ptype;
15296         cmdline_fixed_string_t mapping;
15297         cmdline_fixed_string_t reset;
15298         portid_t port_id;
15299 };
15300
15301 /* Common CLI fields for ptype mapping reset*/
15302 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15303         TOKEN_STRING_INITIALIZER
15304                 (struct cmd_ptype_mapping_reset_result,
15305                  ptype, "ptype");
15306 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15307         TOKEN_STRING_INITIALIZER
15308                 (struct cmd_ptype_mapping_reset_result,
15309                  mapping, "mapping");
15310 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15311         TOKEN_STRING_INITIALIZER
15312                 (struct cmd_ptype_mapping_reset_result,
15313                  reset, "reset");
15314 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15315         TOKEN_NUM_INITIALIZER
15316                 (struct cmd_ptype_mapping_reset_result,
15317                  port_id, UINT16);
15318
15319 static void
15320 cmd_ptype_mapping_reset_parsed(
15321         void *parsed_result,
15322         __attribute__((unused)) struct cmdline *cl,
15323         __attribute__((unused)) void *data)
15324 {
15325         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15326         int ret = -ENOTSUP;
15327
15328         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15329                 return;
15330
15331 #ifdef RTE_LIBRTE_I40E_PMD
15332         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15333 #endif
15334
15335         switch (ret) {
15336         case 0:
15337                 break;
15338         case -ENODEV:
15339                 printf("invalid port_id %d\n", res->port_id);
15340                 break;
15341         case -ENOTSUP:
15342                 printf("function not implemented\n");
15343                 break;
15344         default:
15345                 printf("programming error: (%s)\n", strerror(-ret));
15346         }
15347 }
15348
15349 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15350         .f = cmd_ptype_mapping_reset_parsed,
15351         .data = NULL,
15352         .help_str = "ptype mapping reset <port_id>",
15353         .tokens = {
15354                 (void *)&cmd_ptype_mapping_reset_ptype,
15355                 (void *)&cmd_ptype_mapping_reset_mapping,
15356                 (void *)&cmd_ptype_mapping_reset_reset,
15357                 (void *)&cmd_ptype_mapping_reset_port_id,
15358                 NULL,
15359         },
15360 };
15361
15362 /* ptype mapping update */
15363
15364 /* Common result structure for ptype mapping update */
15365 struct cmd_ptype_mapping_update_result {
15366         cmdline_fixed_string_t ptype;
15367         cmdline_fixed_string_t mapping;
15368         cmdline_fixed_string_t reset;
15369         portid_t port_id;
15370         uint8_t hw_ptype;
15371         uint32_t sw_ptype;
15372 };
15373
15374 /* Common CLI fields for ptype mapping update*/
15375 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15376         TOKEN_STRING_INITIALIZER
15377                 (struct cmd_ptype_mapping_update_result,
15378                  ptype, "ptype");
15379 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15380         TOKEN_STRING_INITIALIZER
15381                 (struct cmd_ptype_mapping_update_result,
15382                  mapping, "mapping");
15383 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15384         TOKEN_STRING_INITIALIZER
15385                 (struct cmd_ptype_mapping_update_result,
15386                  reset, "update");
15387 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15388         TOKEN_NUM_INITIALIZER
15389                 (struct cmd_ptype_mapping_update_result,
15390                  port_id, UINT16);
15391 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15392         TOKEN_NUM_INITIALIZER
15393                 (struct cmd_ptype_mapping_update_result,
15394                  hw_ptype, UINT8);
15395 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15396         TOKEN_NUM_INITIALIZER
15397                 (struct cmd_ptype_mapping_update_result,
15398                  sw_ptype, UINT32);
15399
15400 static void
15401 cmd_ptype_mapping_update_parsed(
15402         void *parsed_result,
15403         __attribute__((unused)) struct cmdline *cl,
15404         __attribute__((unused)) void *data)
15405 {
15406         struct cmd_ptype_mapping_update_result *res = parsed_result;
15407         int ret = -ENOTSUP;
15408 #ifdef RTE_LIBRTE_I40E_PMD
15409         struct rte_pmd_i40e_ptype_mapping mapping;
15410 #endif
15411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15412                 return;
15413
15414 #ifdef RTE_LIBRTE_I40E_PMD
15415         mapping.hw_ptype = res->hw_ptype;
15416         mapping.sw_ptype = res->sw_ptype;
15417         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15418                                                 &mapping,
15419                                                 1,
15420                                                 0);
15421 #endif
15422
15423         switch (ret) {
15424         case 0:
15425                 break;
15426         case -EINVAL:
15427                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15428                 break;
15429         case -ENODEV:
15430                 printf("invalid port_id %d\n", res->port_id);
15431                 break;
15432         case -ENOTSUP:
15433                 printf("function not implemented\n");
15434                 break;
15435         default:
15436                 printf("programming error: (%s)\n", strerror(-ret));
15437         }
15438 }
15439
15440 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15441         .f = cmd_ptype_mapping_update_parsed,
15442         .data = NULL,
15443         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15444         .tokens = {
15445                 (void *)&cmd_ptype_mapping_update_ptype,
15446                 (void *)&cmd_ptype_mapping_update_mapping,
15447                 (void *)&cmd_ptype_mapping_update_update,
15448                 (void *)&cmd_ptype_mapping_update_port_id,
15449                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15450                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15451                 NULL,
15452         },
15453 };
15454
15455 /* Common result structure for file commands */
15456 struct cmd_cmdfile_result {
15457         cmdline_fixed_string_t load;
15458         cmdline_fixed_string_t filename;
15459 };
15460
15461 /* Common CLI fields for file commands */
15462 cmdline_parse_token_string_t cmd_load_cmdfile =
15463         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15464 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15465         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15466
15467 static void
15468 cmd_load_from_file_parsed(
15469         void *parsed_result,
15470         __attribute__((unused)) struct cmdline *cl,
15471         __attribute__((unused)) void *data)
15472 {
15473         struct cmd_cmdfile_result *res = parsed_result;
15474
15475         cmdline_read_from_file(res->filename);
15476 }
15477
15478 cmdline_parse_inst_t cmd_load_from_file = {
15479         .f = cmd_load_from_file_parsed,
15480         .data = NULL,
15481         .help_str = "load <filename>",
15482         .tokens = {
15483                 (void *)&cmd_load_cmdfile,
15484                 (void *)&cmd_load_cmdfile_filename,
15485                 NULL,
15486         },
15487 };
15488
15489 /* ******************************************************************************** */
15490
15491 /* list of instructions */
15492 cmdline_parse_ctx_t main_ctx[] = {
15493         (cmdline_parse_inst_t *)&cmd_help_brief,
15494         (cmdline_parse_inst_t *)&cmd_help_long,
15495         (cmdline_parse_inst_t *)&cmd_quit,
15496         (cmdline_parse_inst_t *)&cmd_load_from_file,
15497         (cmdline_parse_inst_t *)&cmd_showport,
15498         (cmdline_parse_inst_t *)&cmd_showqueue,
15499         (cmdline_parse_inst_t *)&cmd_showportall,
15500         (cmdline_parse_inst_t *)&cmd_showcfg,
15501         (cmdline_parse_inst_t *)&cmd_start,
15502         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15503         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15504         (cmdline_parse_inst_t *)&cmd_set_link_up,
15505         (cmdline_parse_inst_t *)&cmd_set_link_down,
15506         (cmdline_parse_inst_t *)&cmd_reset,
15507         (cmdline_parse_inst_t *)&cmd_set_numbers,
15508         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15509         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15510         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15511         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15512         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15513         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15514         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15515         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15516         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15517         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15518         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15519         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15520         (cmdline_parse_inst_t *)&cmd_set_link_check,
15521         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15522         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15523         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15524         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15525 #ifdef RTE_LIBRTE_PMD_BOND
15526         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15527         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15528         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15529         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15530         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15531         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15532         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15533         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15534         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15535         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15536         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15537 #endif
15538         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15539         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15540         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15541         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15542         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15543         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15544         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15545         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15546         (cmdline_parse_inst_t *)&cmd_csum_set,
15547         (cmdline_parse_inst_t *)&cmd_csum_show,
15548         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15549         (cmdline_parse_inst_t *)&cmd_tso_set,
15550         (cmdline_parse_inst_t *)&cmd_tso_show,
15551         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15552         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15553         (cmdline_parse_inst_t *)&cmd_gro_enable,
15554         (cmdline_parse_inst_t *)&cmd_gro_flush,
15555         (cmdline_parse_inst_t *)&cmd_gro_show,
15556         (cmdline_parse_inst_t *)&cmd_gso_enable,
15557         (cmdline_parse_inst_t *)&cmd_gso_size,
15558         (cmdline_parse_inst_t *)&cmd_gso_show,
15559         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15560         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15561         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15568         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15569         (cmdline_parse_inst_t *)&cmd_config_dcb,
15570         (cmdline_parse_inst_t *)&cmd_read_reg,
15571         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15572         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15573         (cmdline_parse_inst_t *)&cmd_write_reg,
15574         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15575         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15576         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15577         (cmdline_parse_inst_t *)&cmd_stop,
15578         (cmdline_parse_inst_t *)&cmd_mac_addr,
15579         (cmdline_parse_inst_t *)&cmd_set_qmap,
15580         (cmdline_parse_inst_t *)&cmd_operate_port,
15581         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15582         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15583         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15584         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15585         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15586         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15587         (cmdline_parse_inst_t *)&cmd_config_mtu,
15588         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15589         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15590         (cmdline_parse_inst_t *)&cmd_config_rss,
15591         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15592         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15593         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15594         (cmdline_parse_inst_t *)&cmd_showport_reta,
15595         (cmdline_parse_inst_t *)&cmd_config_burst,
15596         (cmdline_parse_inst_t *)&cmd_config_thresh,
15597         (cmdline_parse_inst_t *)&cmd_config_threshold,
15598         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15599         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15600         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15601         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15602         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15603         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15604         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15605         (cmdline_parse_inst_t *)&cmd_global_config,
15606         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15607         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15608         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15609         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15610         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15611         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15612         (cmdline_parse_inst_t *)&cmd_dump,
15613         (cmdline_parse_inst_t *)&cmd_dump_one,
15614         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15615         (cmdline_parse_inst_t *)&cmd_syn_filter,
15616         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15617         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15618         (cmdline_parse_inst_t *)&cmd_flex_filter,
15619         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15620         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15621         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15622         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15623         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15624         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15625         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15626         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15627         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15628         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15629         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15630         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15631         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15632         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15633         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15634         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15635         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15636         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15637         (cmdline_parse_inst_t *)&cmd_flow,
15638         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15639         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15640         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15641         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15642         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15643         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15644         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15645         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15646         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15647         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15648         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15649         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15650         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15651         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15652         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15653         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15654         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15655         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15656         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15657         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15658         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15659         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15660         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15661         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15662         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15663         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15664         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15665         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15666         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15667         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15668         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15669         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15670         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15671         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15672         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15673         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15674         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15675         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15676         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15677         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15678         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15679         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15680         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15681         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15682         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15683 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15684         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15685 #endif
15686         (cmdline_parse_inst_t *)&cmd_ddp_add,
15687         (cmdline_parse_inst_t *)&cmd_ddp_del,
15688         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15689         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15690         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15691         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15692         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15693         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15694         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15695         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15696
15697         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15698         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15699         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15700         (cmdline_parse_inst_t *)&cmd_queue_region,
15701         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15702         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15703         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15704         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15705         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15706         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15707         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15708         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15709         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15710         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15711         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15712         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15713         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15714         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15715         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15716         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15717         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15718         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15719         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15720         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15721         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15722         NULL,
15723 };
15724
15725 /* read cmdline commands from file */
15726 void
15727 cmdline_read_from_file(const char *filename)
15728 {
15729         struct cmdline *cl;
15730
15731         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15732         if (cl == NULL) {
15733                 printf("Failed to create file based cmdline context: %s\n",
15734                        filename);
15735                 return;
15736         }
15737
15738         cmdline_interact(cl);
15739         cmdline_quit(cl);
15740
15741         cmdline_free(cl);
15742
15743         printf("Read CLI commands from %s\n", filename);
15744 }
15745
15746 /* prompt function, called from main on MASTER lcore */
15747 void
15748 prompt(void)
15749 {
15750         /* initialize non-constant commands */
15751         cmd_set_fwd_mode_init();
15752         cmd_set_fwd_retry_mode_init();
15753
15754         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15755         if (testpmd_cl == NULL)
15756                 return;
15757         cmdline_interact(testpmd_cl);
15758         cmdline_stdin_exit(testpmd_cl);
15759 }
15760
15761 void
15762 prompt_exit(void)
15763 {
15764         if (testpmd_cl != NULL)
15765                 cmdline_quit(testpmd_cl);
15766 }
15767
15768 static void
15769 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15770 {
15771         if (id == (portid_t)RTE_PORT_ALL) {
15772                 portid_t pid;
15773
15774                 RTE_ETH_FOREACH_DEV(pid) {
15775                         /* check if need_reconfig has been set to 1 */
15776                         if (ports[pid].need_reconfig == 0)
15777                                 ports[pid].need_reconfig = dev;
15778                         /* check if need_reconfig_queues has been set to 1 */
15779                         if (ports[pid].need_reconfig_queues == 0)
15780                                 ports[pid].need_reconfig_queues = queue;
15781                 }
15782         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15783                 /* check if need_reconfig has been set to 1 */
15784                 if (ports[id].need_reconfig == 0)
15785                         ports[id].need_reconfig = dev;
15786                 /* check if need_reconfig_queues has been set to 1 */
15787                 if (ports[id].need_reconfig_queues == 0)
15788                         ports[id].need_reconfig_queues = queue;
15789         }
15790 }