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