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