app/testpmd: fix shaper profile parameters
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78 #include "bpf_cmd.h"
79
80 static struct cmdline *testpmd_cl;
81
82 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
83
84 /* *** Help command with introduction. *** */
85 struct cmd_help_brief_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
90                                   struct cmdline *cl,
91                                   __attribute__((unused)) void *data)
92 {
93         cmdline_printf(
94                 cl,
95                 "\n"
96                 "Help is available for the following sections:\n\n"
97                 "    help control    : Start and stop forwarding.\n"
98                 "    help display    : Displaying port, stats and config "
99                 "information.\n"
100                 "    help config     : Configuration information.\n"
101                 "    help ports      : Configuring ports.\n"
102                 "    help registers  : Reading and setting port registers.\n"
103                 "    help filters    : Filters configuration help.\n"
104                 "    help all        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213                         "show port tm cap (port_id)\n"
214                         "       Display the port TM capability.\n\n"
215
216                         "show port tm level cap (port_id) (level_id)\n"
217                         "       Display the port TM hierarchical level capability.\n\n"
218
219                         "show port tm node cap (port_id) (node_id)\n"
220                         "       Display the port TM node capability.\n\n"
221
222                         "show port tm node type (port_id) (node_id)\n"
223                         "       Display the port TM node type.\n\n"
224
225                         "show port tm node stats (port_id) (node_id) (clear)\n"
226                         "       Display the port TM node stats.\n\n"
227
228                 );
229         }
230
231         if (show_all || !strcmp(res->section, "config")) {
232                 cmdline_printf(
233                         cl,
234                         "\n"
235                         "Configuration:\n"
236                         "--------------\n"
237                         "Configuration changes only become active when"
238                         " forwarding is started/restarted.\n\n"
239
240                         "set default\n"
241                         "    Reset forwarding to the default configuration.\n\n"
242
243                         "set verbose (level)\n"
244                         "    Set the debug verbosity level X.\n\n"
245
246                         "set log global|(type) (level)\n"
247                         "    Set the log level.\n\n"
248
249                         "set nbport (num)\n"
250                         "    Set number of ports.\n\n"
251
252                         "set nbcore (num)\n"
253                         "    Set number of cores.\n\n"
254
255                         "set coremask (mask)\n"
256                         "    Set the forwarding cores hexadecimal mask.\n\n"
257
258                         "set portmask (mask)\n"
259                         "    Set the forwarding ports hexadecimal mask.\n\n"
260
261                         "set burst (num)\n"
262                         "    Set number of packets per burst.\n\n"
263
264                         "set burst tx delay (microseconds) retry (num)\n"
265                         "    Set the transmit delay time and number of retries,"
266                         " effective when retry is enabled.\n\n"
267
268                         "set txpkts (x[,y]*)\n"
269                         "    Set the length of each segment of TXONLY"
270                         " and optionally CSUM packets.\n\n"
271
272                         "set txsplit (off|on|rand)\n"
273                         "    Set the split policy for the TX packets."
274                         " Right now only applicable for CSUM and TXONLY"
275                         " modes\n\n"
276
277                         "set corelist (x[,y]*)\n"
278                         "    Set the list of forwarding cores.\n\n"
279
280                         "set portlist (x[,y]*)\n"
281                         "    Set the list of forwarding ports.\n\n"
282
283                         "set port setup on (iterator|event)\n"
284                         "    Select how attached port is retrieved for setup.\n\n"
285
286                         "set tx loopback (port_id) (on|off)\n"
287                         "    Enable or disable tx loopback.\n\n"
288
289                         "set all queues drop (port_id) (on|off)\n"
290                         "    Set drop enable bit for all queues.\n\n"
291
292                         "set vf split drop (port_id) (vf_id) (on|off)\n"
293                         "    Set split drop enable bit for a VF from the PF.\n\n"
294
295                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
296                         "    Set MAC antispoof for a VF from the PF.\n\n"
297
298                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
299                         "    Enable MACsec offload.\n\n"
300
301                         "set macsec offload (port_id) off\n"
302                         "    Disable MACsec offload.\n\n"
303
304                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
305                         "    Configure MACsec secure connection (SC).\n\n"
306
307                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
308                         "    Configure MACsec secure association (SA).\n\n"
309
310                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
311                         "    Set VF broadcast for a VF from the PF.\n\n"
312
313                         "vlan set strip (on|off) (port_id)\n"
314                         "    Set the VLAN strip on a port.\n\n"
315
316                         "vlan set stripq (on|off) (port_id,queue_id)\n"
317                         "    Set the VLAN strip for a queue on a port.\n\n"
318
319                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
320                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
321
322                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
323                         "    Set VLAN insert for a VF from the PF.\n\n"
324
325                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN antispoof for a VF from the PF.\n\n"
327
328                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN tag for a VF from the PF.\n\n"
330
331                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
332                         "    Set a VF's max bandwidth(Mbps).\n\n"
333
334                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
335                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
336
337                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
338                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
339
340                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
341                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
342
343                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
344                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
345
346                         "vlan set filter (on|off) (port_id)\n"
347                         "    Set the VLAN filter on a port.\n\n"
348
349                         "vlan set qinq (on|off) (port_id)\n"
350                         "    Set the VLAN QinQ (extended queue in queue)"
351                         " on a port.\n\n"
352
353                         "vlan set (inner|outer) tpid (value) (port_id)\n"
354                         "    Set the VLAN TPID for Packet Filtering on"
355                         " a port\n\n"
356
357                         "rx_vlan add (vlan_id|all) (port_id)\n"
358                         "    Add a vlan_id, or all identifiers, to the set"
359                         " of VLAN identifiers filtered by port_id.\n\n"
360
361                         "rx_vlan rm (vlan_id|all) (port_id)\n"
362                         "    Remove a vlan_id, or all identifiers, from the set"
363                         " of VLAN identifiers filtered by port_id.\n\n"
364
365                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
366                         "    Add a vlan_id, to the set of VLAN identifiers"
367                         "filtered for VF(s) from port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
370                         "    Remove a vlan_id, to the set of VLAN identifiers"
371                         "filtered for VF(s) from port_id.\n\n"
372
373                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
374                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
375                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
376                         "   add a tunnel filter of a port.\n\n"
377
378                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   remove a tunnel filter of a port.\n\n"
382
383                         "rx_vxlan_port add (udp_port) (port_id)\n"
384                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "rx_vxlan_port rm (udp_port) (port_id)\n"
387                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
390                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
391                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
392
393                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
394                         "    Set port based TX VLAN insertion.\n\n"
395
396                         "tx_vlan reset (port_id)\n"
397                         "    Disable hardware insertion of a VLAN header in"
398                         " packets sent on a port.\n\n"
399
400                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
401                         "    Select hardware or software calculation of the"
402                         " checksum when transmitting a packet using the"
403                         " csum forward engine.\n"
404                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
405                         "    outer-ip concerns the outer IP layer in"
406                         "    outer-udp concerns the outer UDP layer in"
407                         " case the packet is recognized as a tunnel packet by"
408                         " the forward engine (vxlan, gre and ipip are supported)\n"
409                         "    Please check the NIC datasheet for HW limits.\n\n"
410
411                         "csum parse-tunnel (on|off) (tx_port_id)\n"
412                         "    If disabled, treat tunnel packets as non-tunneled"
413                         " packets (treat inner headers as payload). The port\n"
414                         "    argument is the port used for TX in csum forward"
415                         " engine.\n\n"
416
417                         "csum show (port_id)\n"
418                         "    Display tx checksum offload configuration\n\n"
419
420                         "tso set (segsize) (portid)\n"
421                         "    Enable TCP Segmentation Offload in csum forward"
422                         " engine.\n"
423                         "    Please check the NIC datasheet for HW limits.\n\n"
424
425                         "tso show (portid)"
426                         "    Display the status of TCP Segmentation Offload.\n\n"
427
428                         "set port (port_id) gro on|off\n"
429                         "    Enable or disable Generic Receive Offload in"
430                         " csum forwarding engine.\n\n"
431
432                         "show port (port_id) gro\n"
433                         "    Display GRO configuration.\n\n"
434
435                         "set gro flush (cycles)\n"
436                         "    Set the cycle to flush GROed packets from"
437                         " reassembly tables.\n\n"
438
439                         "set port (port_id) gso (on|off)"
440                         "    Enable or disable Generic Segmentation Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "set gso segsz (length)\n"
444                         "    Set max packet length for output GSO segments,"
445                         " including packet header and payload.\n\n"
446
447                         "show port (port_id) gso\n"
448                         "    Show GSO configuration.\n\n"
449
450                         "set fwd (%s)\n"
451                         "    Set packet forwarding mode.\n\n"
452
453                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
454                         "    Add a MAC address on port_id.\n\n"
455
456                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
457                         "    Remove a MAC address from port_id.\n\n"
458
459                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
460                         "    Set the default MAC address for port_id.\n\n"
461
462                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
463                         "    Add a MAC address for a VF on the port.\n\n"
464
465                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
466                         "    Set the MAC address for a VF from the PF.\n\n"
467
468                         "set eth-peer (port_id) (peer_addr)\n"
469                         "    set the peer address for certain port.\n\n"
470
471                         "set port (port_id) uta (mac_address|all) (on|off)\n"
472                         "    Add/Remove a or all unicast hash filter(s)"
473                         "from port X.\n\n"
474
475                         "set promisc (port_id|all) (on|off)\n"
476                         "    Set the promiscuous mode on port_id, or all.\n\n"
477
478                         "set allmulti (port_id|all) (on|off)\n"
479                         "    Set the allmulti mode on port_id, or all.\n\n"
480
481                         "set vf promisc (port_id) (vf_id) (on|off)\n"
482                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
483
484                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
485                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
486
487                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
488                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
489                         " (on|off) autoneg (on|off) (port_id)\n"
490                         "set flow_ctrl rx (on|off) (portid)\n"
491                         "set flow_ctrl tx (on|off) (portid)\n"
492                         "set flow_ctrl high_water (high_water) (portid)\n"
493                         "set flow_ctrl low_water (low_water) (portid)\n"
494                         "set flow_ctrl pause_time (pause_time) (portid)\n"
495                         "set flow_ctrl send_xon (send_xon) (portid)\n"
496                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
497                         "set flow_ctrl autoneg (on|off) (port_id)\n"
498                         "    Set the link flow control parameter on a port.\n\n"
499
500                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (priority) (port_id)\n"
502                         "    Set the priority flow control parameter on a"
503                         " port.\n\n"
504
505                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
506                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
507                         " queue on port.\n"
508                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
509                         " on port 0 to mapping 5.\n\n"
510
511                         "set xstats-hide-zero on|off\n"
512                         "    Set the option to hide the zero values"
513                         " for xstats display.\n"
514
515                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
516                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
517
518                         "set port (port_id) vf (vf_id) (mac_addr)"
519                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
520                         "   Add/Remove unicast or multicast MAC addr filter"
521                         " for a VF.\n\n"
522
523                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
524                         "|MPE) (on|off)\n"
525                         "    AUPE:accepts untagged VLAN;"
526                         "ROPE:accept unicast hash\n\n"
527                         "    BAM:accepts broadcast packets;"
528                         "MPE:accepts all multicast packets\n\n"
529                         "    Enable/Disable a VF receive mode of a port\n\n"
530
531                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
532                         "    Set rate limit for a queue of a port\n\n"
533
534                         "set port (port_id) vf (vf_id) rate (rate_num) "
535                         "queue_mask (queue_mask_value)\n"
536                         "    Set rate limit for queues in VF of a port\n\n"
537
538                         "set port (port_id) mirror-rule (rule_id)"
539                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
540                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
541                         "   Set pool or vlan type mirror rule on a port.\n"
542                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
543                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
544                         " to pool 0.\n\n"
545
546                         "set port (port_id) mirror-rule (rule_id)"
547                         " (uplink-mirror|downlink-mirror) dst-pool"
548                         " (pool_id) (on|off)\n"
549                         "   Set uplink or downlink type mirror rule on a port.\n"
550                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
551                         " 0 on' enable mirror income traffic to pool 0.\n\n"
552
553                         "reset port (port_id) mirror-rule (rule_id)\n"
554                         "   Reset a mirror rule.\n\n"
555
556                         "set flush_rx (on|off)\n"
557                         "   Flush (default) or don't flush RX streams before"
558                         " forwarding. Mainly used with PCAP drivers.\n\n"
559
560                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
561                         "   Set the bypass mode for the lowest port on bypass enabled"
562                         " NIC.\n\n"
563
564                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
565                         "mode (normal|bypass|isolate) (port_id)\n"
566                         "   Set the event required to initiate specified bypass mode for"
567                         " the lowest port on a bypass enabled NIC where:\n"
568                         "       timeout   = enable bypass after watchdog timeout.\n"
569                         "       os_on     = enable bypass when OS/board is powered on.\n"
570                         "       os_off    = enable bypass when OS/board is powered off.\n"
571                         "       power_on  = enable bypass when power supply is turned on.\n"
572                         "       power_off = enable bypass when power supply is turned off."
573                         "\n\n"
574
575                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
576                         "   Set the bypass watchdog timeout to 'n' seconds"
577                         " where 0 = instant.\n\n"
578
579                         "show bypass config (port_id)\n"
580                         "   Show the bypass configuration for a bypass enabled NIC"
581                         " using the lowest port on the NIC.\n\n"
582
583 #ifdef RTE_LIBRTE_PMD_BOND
584                         "create bonded device (mode) (socket)\n"
585                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
586
587                         "add bonding slave (slave_id) (port_id)\n"
588                         "       Add a slave device to a bonded device.\n\n"
589
590                         "remove bonding slave (slave_id) (port_id)\n"
591                         "       Remove a slave device from a bonded device.\n\n"
592
593                         "set bonding mode (value) (port_id)\n"
594                         "       Set the bonding mode on a bonded device.\n\n"
595
596                         "set bonding primary (slave_id) (port_id)\n"
597                         "       Set the primary slave for a bonded device.\n\n"
598
599                         "show bonding config (port_id)\n"
600                         "       Show the bonding config for port_id.\n\n"
601
602                         "set bonding mac_addr (port_id) (address)\n"
603                         "       Set the MAC address of a bonded device.\n\n"
604
605                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
606                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
607
608                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
609                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
610
611                         "set bonding mon_period (port_id) (value)\n"
612                         "       Set the bonding link status monitoring polling period in ms.\n\n"
613
614                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
615                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
616
617 #endif
618                         "set link-up port (port_id)\n"
619                         "       Set link up for a port.\n\n"
620
621                         "set link-down port (port_id)\n"
622                         "       Set link down for a port.\n\n"
623
624                         "E-tag set insertion on port-tag-id (value)"
625                         " port (port_id) vf (vf_id)\n"
626                         "    Enable E-tag insertion for a VF on a port\n\n"
627
628                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
629                         "    Disable E-tag insertion for a VF on a port\n\n"
630
631                         "E-tag set stripping (on|off) port (port_id)\n"
632                         "    Enable/disable E-tag stripping on a port\n\n"
633
634                         "E-tag set forwarding (on|off) port (port_id)\n"
635                         "    Enable/disable E-tag based forwarding"
636                         " on a port\n\n"
637
638                         "E-tag set filter add e-tag-id (value) dst-pool"
639                         " (pool_id) port (port_id)\n"
640                         "    Add an E-tag forwarding filter on a port\n\n"
641
642                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
643                         "    Delete an E-tag forwarding filter on a port\n\n"
644
645 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
646                         "set port tm hierarchy default (port_id)\n"
647                         "       Set default traffic Management hierarchy on a port\n\n"
648
649 #endif
650                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
651                         "    Load a profile package on a port\n\n"
652
653                         "ddp del (port_id) (backup_profile_path)\n"
654                         "    Delete a profile package from a port\n\n"
655
656                         "ptype mapping get (port_id) (valid_only)\n"
657                         "    Get ptype mapping on a port\n\n"
658
659                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
660                         "    Replace target with the pkt_type in ptype mapping\n\n"
661
662                         "ptype mapping reset (port_id)\n"
663                         "    Reset ptype mapping on a port\n\n"
664
665                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
666                         "    Update a ptype mapping item on a port\n\n"
667
668                         "set port (port_id) queue-region region_id (value) "
669                         "queue_start_index (value) queue_num (value)\n"
670                         "    Set a queue region on a port\n\n"
671
672                         "set port (port_id) queue-region region_id (value) "
673                         "flowtype (value)\n"
674                         "    Set a flowtype region index on a port\n\n"
675
676                         "set port (port_id) queue-region UP (value) region_id (value)\n"
677                         "    Set the mapping of User Priority to "
678                         "queue region on a port\n\n"
679
680                         "set port (port_id) queue-region flush (on|off)\n"
681                         "    flush all queue region related configuration\n\n"
682
683                         "show port meter cap (port_id)\n"
684                         "    Show port meter capability information\n\n"
685
686                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
687                         "    meter profile add - srtcm rfc 2697\n\n"
688
689                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
690                         "    meter profile add - trtcm rfc 2698\n\n"
691
692                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
693                         "    meter profile add - trtcm rfc 4115\n\n"
694
695                         "del port meter profile (port_id) (profile_id)\n"
696                         "    meter profile delete\n\n"
697
698                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
699                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
700                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
701                         "(dscp_tbl_entry63)]\n"
702                         "    meter create\n\n"
703
704                         "enable port meter (port_id) (mtr_id)\n"
705                         "    meter enable\n\n"
706
707                         "disable port meter (port_id) (mtr_id)\n"
708                         "    meter disable\n\n"
709
710                         "del port meter (port_id) (mtr_id)\n"
711                         "    meter delete\n\n"
712
713                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
714                         "    meter update meter profile\n\n"
715
716                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
717                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
718                         "    update meter dscp table entries\n\n"
719
720                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
721                         "(action0) [(action1) (action2)]\n"
722                         "    meter update policer action\n\n"
723
724                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
725                         "    meter update stats\n\n"
726
727                         "show port (port_id) queue-region\n"
728                         "    show all queue region related configuration info\n\n"
729
730                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
731                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
732                         " (packet_length_adjust)\n"
733                         "       Add port tm node private shaper profile.\n\n"
734
735                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
736                         "       Delete port tm node private shaper profile.\n\n"
737
738                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
739                         " (shaper_profile_id)\n"
740                         "       Add/update port tm node shared shaper.\n\n"
741
742                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
743                         "       Delete port tm node shared shaper.\n\n"
744
745                         "set port tm node shaper profile (port_id) (node_id)"
746                         " (shaper_profile_id)\n"
747                         "       Set port tm node shaper profile.\n\n"
748
749                         "add port tm node wred profile (port_id) (wred_profile_id)"
750                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
751                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
752                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
753                         "       Add port tm node wred profile.\n\n"
754
755                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
756                         "       Delete port tm node wred profile.\n\n"
757
758                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
759                         " (priority) (weight) (level_id) (shaper_profile_id)"
760                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
761                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
762                         "       Add port tm nonleaf node.\n\n"
763
764                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
765                         " (priority) (weight) (level_id) (shaper_profile_id)"
766                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
767                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
768                         "       Add port tm leaf node.\n\n"
769
770                         "del port tm node (port_id) (node_id)\n"
771                         "       Delete port tm node.\n\n"
772
773                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
774                         " (priority) (weight)\n"
775                         "       Set port tm node parent.\n\n"
776
777                         "suspend port tm node (port_id) (node_id)"
778                         "       Suspend tm node.\n\n"
779
780                         "resume port tm node (port_id) (node_id)"
781                         "       Resume tm node.\n\n"
782
783                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
784                         "       Commit tm hierarchy.\n\n"
785
786                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
787                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
788                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
789                         "       Configure the VXLAN encapsulation for flows.\n\n"
790
791                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
792                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
793                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
794                         " eth-dst (eth-dst)\n"
795                         "       Configure the VXLAN encapsulation for flows.\n\n"
796
797                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
798                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
799                         " (eth-dst)\n"
800                         "       Configure the NVGRE encapsulation for flows.\n\n"
801
802                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
803                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
804                         " eth-src (eth-src) eth-dst (eth-dst)\n"
805                         "       Configure the NVGRE encapsulation for flows.\n\n"
806
807                         , list_pkt_forwarding_modes()
808                 );
809         }
810
811         if (show_all || !strcmp(res->section, "ports")) {
812
813                 cmdline_printf(
814                         cl,
815                         "\n"
816                         "Port Operations:\n"
817                         "----------------\n\n"
818
819                         "port start (port_id|all)\n"
820                         "    Start all ports or port_id.\n\n"
821
822                         "port stop (port_id|all)\n"
823                         "    Stop all ports or port_id.\n\n"
824
825                         "port close (port_id|all)\n"
826                         "    Close all ports or port_id.\n\n"
827
828                         "port attach (ident)\n"
829                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
830
831                         "port detach (port_id)\n"
832                         "    Detach physical or virtual dev by port_id\n\n"
833
834                         "port config (port_id|all)"
835                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
836                         " duplex (half|full|auto)\n"
837                         "    Set speed and duplex for all ports or port_id\n\n"
838
839                         "port config (port_id|all) loopback (mode)\n"
840                         "    Set loopback mode for all ports or port_id\n\n"
841
842                         "port config all (rxq|txq|rxd|txd) (value)\n"
843                         "    Set number for rxq/txq/rxd/txd.\n\n"
844
845                         "port config all max-pkt-len (value)\n"
846                         "    Set the max packet length.\n\n"
847
848                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
849                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
850                         " (on|off)\n"
851                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
852                         " for ports.\n\n"
853
854                         "port config all rss (all|default|ip|tcp|udp|sctp|"
855                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
856                         "    Set the RSS mode.\n\n"
857
858                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
859                         "    Set the RSS redirection table.\n\n"
860
861                         "port config (port_id) dcb vt (on|off) (traffic_class)"
862                         " pfc (on|off)\n"
863                         "    Set the DCB mode.\n\n"
864
865                         "port config all burst (value)\n"
866                         "    Set the number of packets per burst.\n\n"
867
868                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
869                         " (value)\n"
870                         "    Set the ring prefetch/host/writeback threshold"
871                         " for tx/rx queue.\n\n"
872
873                         "port config all (txfreet|txrst|rxfreet) (value)\n"
874                         "    Set free threshold for rx/tx, or set"
875                         " tx rs bit threshold.\n\n"
876                         "port config mtu X value\n"
877                         "    Set the MTU of port X to a given value\n\n"
878
879                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
880                         "    Set a rx/tx queue's ring size configuration, the new"
881                         " value will take effect after command that (re-)start the port"
882                         " or command that setup the specific queue\n\n"
883
884                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
885                         "    Start/stop a rx/tx queue of port X. Only take effect"
886                         " when port X is started\n\n"
887
888                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
889                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
890                         " take effect when port X is stopped.\n\n"
891
892                         "port (port_id) (rxq|txq) (queue_id) setup\n"
893                         "    Setup a rx/tx queue of port X.\n\n"
894
895                         "port config (port_id|all) l2-tunnel E-tag ether-type"
896                         " (value)\n"
897                         "    Set the value of E-tag ether-type.\n\n"
898
899                         "port config (port_id|all) l2-tunnel E-tag"
900                         " (enable|disable)\n"
901                         "    Enable/disable the E-tag support.\n\n"
902
903                         "port config (port_id) pctype mapping reset\n"
904                         "    Reset flow type to pctype mapping on a port\n\n"
905
906                         "port config (port_id) pctype mapping update"
907                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
908                         "    Update a flow type to pctype mapping item on a port\n\n"
909
910                         "port config (port_id) pctype (pctype_id) hash_inset|"
911                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
912                         " (field_idx)\n"
913                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
914
915                         "port config (port_id) pctype (pctype_id) hash_inset|"
916                         "fdir_inset|fdir_flx_inset clear all"
917                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
918
919                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
920                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
921                 );
922         }
923
924         if (show_all || !strcmp(res->section, "registers")) {
925
926                 cmdline_printf(
927                         cl,
928                         "\n"
929                         "Registers:\n"
930                         "----------\n\n"
931
932                         "read reg (port_id) (address)\n"
933                         "    Display value of a port register.\n\n"
934
935                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
936                         "    Display a port register bit field.\n\n"
937
938                         "read regbit (port_id) (address) (bit_x)\n"
939                         "    Display a single port register bit.\n\n"
940
941                         "write reg (port_id) (address) (value)\n"
942                         "    Set value of a port register.\n\n"
943
944                         "write regfield (port_id) (address) (bit_x) (bit_y)"
945                         " (value)\n"
946                         "    Set bit field of a port register.\n\n"
947
948                         "write regbit (port_id) (address) (bit_x) (value)\n"
949                         "    Set single bit value of a port register.\n\n"
950                 );
951         }
952         if (show_all || !strcmp(res->section, "filters")) {
953
954                 cmdline_printf(
955                         cl,
956                         "\n"
957                         "filters:\n"
958                         "--------\n\n"
959
960                         "ethertype_filter (port_id) (add|del)"
961                         " (mac_addr|mac_ignr) (mac_address) ethertype"
962                         " (ether_type) (drop|fwd) queue (queue_id)\n"
963                         "    Add/Del an ethertype filter.\n\n"
964
965                         "2tuple_filter (port_id) (add|del)"
966                         " dst_port (dst_port_value) protocol (protocol_value)"
967                         " mask (mask_value) tcp_flags (tcp_flags_value)"
968                         " priority (prio_value) queue (queue_id)\n"
969                         "    Add/Del a 2tuple filter.\n\n"
970
971                         "5tuple_filter (port_id) (add|del)"
972                         " dst_ip (dst_address) src_ip (src_address)"
973                         " dst_port (dst_port_value) src_port (src_port_value)"
974                         " protocol (protocol_value)"
975                         " mask (mask_value) tcp_flags (tcp_flags_value)"
976                         " priority (prio_value) queue (queue_id)\n"
977                         "    Add/Del a 5tuple filter.\n\n"
978
979                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
980                         "    Add/Del syn filter.\n\n"
981
982                         "flex_filter (port_id) (add|del) len (len_value)"
983                         " bytes (bytes_value) mask (mask_value)"
984                         " priority (prio_value) queue (queue_id)\n"
985                         "    Add/Del a flex filter.\n\n"
986
987                         "flow_director_filter (port_id) mode IP (add|del|update)"
988                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
989                         " src (src_ip_address) dst (dst_ip_address)"
990                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
991                         " vlan (vlan_value) flexbytes (flexbytes_value)"
992                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
993                         " fd_id (fd_id_value)\n"
994                         "    Add/Del an IP type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode IP (add|del|update)"
997                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
998                         " src (src_ip_address) (src_port)"
999                         " dst (dst_ip_address) (dst_port)"
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1002                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1003                         " fd_id (fd_id_value)\n"
1004                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow (ipv4-sctp|ipv6-sctp)"
1008                         " src (src_ip_address) (src_port)"
1009                         " dst (dst_ip_address) (dst_port)"
1010                         " tag (verification_tag) "
1011                         " tos (tos_value) ttl (ttl_value)"
1012                         " vlan (vlan_value)"
1013                         " flexbytes (flexbytes_value) (drop|fwd)"
1014                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1015                         "    Add/Del a SCTP type flow director filter.\n\n"
1016
1017                         "flow_director_filter (port_id) mode IP (add|del|update)"
1018                         " flow l2_payload ether (ethertype)"
1019                         " flexbytes (flexbytes_value) (drop|fwd)"
1020                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1021                         "    Add/Del a l2 payload type flow director filter.\n\n"
1022
1023                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1024                         " mac (mac_address) vlan (vlan_value)"
1025                         " flexbytes (flexbytes_value) (drop|fwd)"
1026                         " queue (queue_id) fd_id (fd_id_value)\n"
1027                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1028
1029                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1030                         " mac (mac_address) vlan (vlan_value)"
1031                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1032                         " flexbytes (flexbytes_value) (drop|fwd)"
1033                         " queue (queue_id) fd_id (fd_id_value)\n"
1034                         "    Add/Del a Tunnel flow director filter.\n\n"
1035
1036                         "flow_director_filter (port_id) mode raw (add|del|update)"
1037                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1038                         " fd_id (fd_id_value) packet (packet file name)\n"
1039                         "    Add/Del a raw type flow director filter.\n\n"
1040
1041                         "flush_flow_director (port_id)\n"
1042                         "    Flush all flow director entries of a device.\n\n"
1043
1044                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1045                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1046                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1047                         "    Set flow director IP mask.\n\n"
1048
1049                         "flow_director_mask (port_id) mode MAC-VLAN"
1050                         " vlan (vlan_value)\n"
1051                         "    Set flow director MAC-VLAN mask.\n\n"
1052
1053                         "flow_director_mask (port_id) mode Tunnel"
1054                         " vlan (vlan_value) mac (mac_value)"
1055                         " tunnel-type (tunnel_type_value)"
1056                         " tunnel-id (tunnel_id_value)\n"
1057                         "    Set flow director Tunnel mask.\n\n"
1058
1059                         "flow_director_flex_mask (port_id)"
1060                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1061                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1062                         " (mask)\n"
1063                         "    Configure mask of flex payload.\n\n"
1064
1065                         "flow_director_flex_payload (port_id)"
1066                         " (raw|l2|l3|l4) (config)\n"
1067                         "    Configure flex payload selection.\n\n"
1068
1069                         "get_sym_hash_ena_per_port (port_id)\n"
1070                         "    get symmetric hash enable configuration per port.\n\n"
1071
1072                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1073                         "    set symmetric hash enable configuration per port"
1074                         " to enable or disable.\n\n"
1075
1076                         "get_hash_global_config (port_id)\n"
1077                         "    Get the global configurations of hash filters.\n\n"
1078
1079                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1080                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1081                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1082                         " (enable|disable)\n"
1083                         "    Set the global configurations of hash filters.\n\n"
1084
1085                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1086                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1087                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1088                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1089                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1090                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1091                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1092                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1093                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1094                         "fld-8th|none) (select|add)\n"
1095                         "    Set the input set for hash.\n\n"
1096
1097                         "set_fdir_input_set (port_id) "
1098                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1099                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1100                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1101                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1102                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1103                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1104                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1105                         " (select|add)\n"
1106                         "    Set the input set for FDir.\n\n"
1107
1108                         "flow validate {port_id}"
1109                         " [group {group_id}] [priority {level}]"
1110                         " [ingress] [egress]"
1111                         " pattern {item} [/ {item} [...]] / end"
1112                         " actions {action} [/ {action} [...]] / end\n"
1113                         "    Check whether a flow rule can be created.\n\n"
1114
1115                         "flow create {port_id}"
1116                         " [group {group_id}] [priority {level}]"
1117                         " [ingress] [egress]"
1118                         " pattern {item} [/ {item} [...]] / end"
1119                         " actions {action} [/ {action} [...]] / end\n"
1120                         "    Create a flow rule.\n\n"
1121
1122                         "flow destroy {port_id} rule {rule_id} [...]\n"
1123                         "    Destroy specific flow rules.\n\n"
1124
1125                         "flow flush {port_id}\n"
1126                         "    Destroy all flow rules.\n\n"
1127
1128                         "flow query {port_id} {rule_id} {action}\n"
1129                         "    Query an existing flow rule.\n\n"
1130
1131                         "flow list {port_id} [group {group_id}] [...]\n"
1132                         "    List existing flow rules sorted by priority,"
1133                         " filtered by group identifiers.\n\n"
1134
1135                         "flow isolate {port_id} {boolean}\n"
1136                         "    Restrict ingress traffic to the defined"
1137                         " flow rules\n\n"
1138                 );
1139         }
1140 }
1141
1142 cmdline_parse_token_string_t cmd_help_long_help =
1143         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1144
1145 cmdline_parse_token_string_t cmd_help_long_section =
1146         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1147                         "all#control#display#config#"
1148                         "ports#registers#filters");
1149
1150 cmdline_parse_inst_t cmd_help_long = {
1151         .f = cmd_help_long_parsed,
1152         .data = NULL,
1153         .help_str = "help all|control|display|config|ports|register|filters: "
1154                 "Show help",
1155         .tokens = {
1156                 (void *)&cmd_help_long_help,
1157                 (void *)&cmd_help_long_section,
1158                 NULL,
1159         },
1160 };
1161
1162
1163 /* *** start/stop/close all ports *** */
1164 struct cmd_operate_port_result {
1165         cmdline_fixed_string_t keyword;
1166         cmdline_fixed_string_t name;
1167         cmdline_fixed_string_t value;
1168 };
1169
1170 static void cmd_operate_port_parsed(void *parsed_result,
1171                                 __attribute__((unused)) struct cmdline *cl,
1172                                 __attribute__((unused)) void *data)
1173 {
1174         struct cmd_operate_port_result *res = parsed_result;
1175
1176         if (!strcmp(res->name, "start"))
1177                 start_port(RTE_PORT_ALL);
1178         else if (!strcmp(res->name, "stop"))
1179                 stop_port(RTE_PORT_ALL);
1180         else if (!strcmp(res->name, "close"))
1181                 close_port(RTE_PORT_ALL);
1182         else if (!strcmp(res->name, "reset"))
1183                 reset_port(RTE_PORT_ALL);
1184         else
1185                 printf("Unknown parameter\n");
1186 }
1187
1188 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1189         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1190                                                                 "port");
1191 cmdline_parse_token_string_t cmd_operate_port_all_port =
1192         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1193                                                 "start#stop#close#reset");
1194 cmdline_parse_token_string_t cmd_operate_port_all_all =
1195         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1196
1197 cmdline_parse_inst_t cmd_operate_port = {
1198         .f = cmd_operate_port_parsed,
1199         .data = NULL,
1200         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1201         .tokens = {
1202                 (void *)&cmd_operate_port_all_cmd,
1203                 (void *)&cmd_operate_port_all_port,
1204                 (void *)&cmd_operate_port_all_all,
1205                 NULL,
1206         },
1207 };
1208
1209 /* *** start/stop/close specific port *** */
1210 struct cmd_operate_specific_port_result {
1211         cmdline_fixed_string_t keyword;
1212         cmdline_fixed_string_t name;
1213         uint8_t value;
1214 };
1215
1216 static void cmd_operate_specific_port_parsed(void *parsed_result,
1217                         __attribute__((unused)) struct cmdline *cl,
1218                                 __attribute__((unused)) void *data)
1219 {
1220         struct cmd_operate_specific_port_result *res = parsed_result;
1221
1222         if (!strcmp(res->name, "start"))
1223                 start_port(res->value);
1224         else if (!strcmp(res->name, "stop"))
1225                 stop_port(res->value);
1226         else if (!strcmp(res->name, "close"))
1227                 close_port(res->value);
1228         else if (!strcmp(res->name, "reset"))
1229                 reset_port(res->value);
1230         else
1231                 printf("Unknown parameter\n");
1232 }
1233
1234 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1235         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1236                                                         keyword, "port");
1237 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1238         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1239                                                 name, "start#stop#close#reset");
1240 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1241         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1242                                                         value, UINT8);
1243
1244 cmdline_parse_inst_t cmd_operate_specific_port = {
1245         .f = cmd_operate_specific_port_parsed,
1246         .data = NULL,
1247         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1248         .tokens = {
1249                 (void *)&cmd_operate_specific_port_cmd,
1250                 (void *)&cmd_operate_specific_port_port,
1251                 (void *)&cmd_operate_specific_port_id,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** enable port setup (after attach) via iterator or event *** */
1257 struct cmd_set_port_setup_on_result {
1258         cmdline_fixed_string_t set;
1259         cmdline_fixed_string_t port;
1260         cmdline_fixed_string_t setup;
1261         cmdline_fixed_string_t on;
1262         cmdline_fixed_string_t mode;
1263 };
1264
1265 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1266                                 __attribute__((unused)) struct cmdline *cl,
1267                                 __attribute__((unused)) void *data)
1268 {
1269         struct cmd_set_port_setup_on_result *res = parsed_result;
1270
1271         if (strcmp(res->mode, "event") == 0)
1272                 setup_on_probe_event = true;
1273         else if (strcmp(res->mode, "iterator") == 0)
1274                 setup_on_probe_event = false;
1275         else
1276                 printf("Unknown mode\n");
1277 }
1278
1279 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1280         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1281                         set, "set");
1282 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1283         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1284                         port, "port");
1285 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1286         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1287                         setup, "setup");
1288 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1289         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1290                         on, "on");
1291 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1292         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1293                         mode, "iterator#event");
1294
1295 cmdline_parse_inst_t cmd_set_port_setup_on = {
1296         .f = cmd_set_port_setup_on_parsed,
1297         .data = NULL,
1298         .help_str = "set port setup on iterator|event",
1299         .tokens = {
1300                 (void *)&cmd_set_port_setup_on_set,
1301                 (void *)&cmd_set_port_setup_on_port,
1302                 (void *)&cmd_set_port_setup_on_setup,
1303                 (void *)&cmd_set_port_setup_on_on,
1304                 (void *)&cmd_set_port_setup_on_mode,
1305                 NULL,
1306         },
1307 };
1308
1309 /* *** attach a specified port *** */
1310 struct cmd_operate_attach_port_result {
1311         cmdline_fixed_string_t port;
1312         cmdline_fixed_string_t keyword;
1313         cmdline_fixed_string_t identifier;
1314 };
1315
1316 static void cmd_operate_attach_port_parsed(void *parsed_result,
1317                                 __attribute__((unused)) struct cmdline *cl,
1318                                 __attribute__((unused)) void *data)
1319 {
1320         struct cmd_operate_attach_port_result *res = parsed_result;
1321
1322         if (!strcmp(res->keyword, "attach"))
1323                 attach_port(res->identifier);
1324         else
1325                 printf("Unknown parameter\n");
1326 }
1327
1328 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1329         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1330                         port, "port");
1331 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1332         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1333                         keyword, "attach");
1334 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1335         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1336                         identifier, NULL);
1337
1338 cmdline_parse_inst_t cmd_operate_attach_port = {
1339         .f = cmd_operate_attach_port_parsed,
1340         .data = NULL,
1341         .help_str = "port attach <identifier>: "
1342                 "(identifier: pci address or virtual dev name)",
1343         .tokens = {
1344                 (void *)&cmd_operate_attach_port_port,
1345                 (void *)&cmd_operate_attach_port_keyword,
1346                 (void *)&cmd_operate_attach_port_identifier,
1347                 NULL,
1348         },
1349 };
1350
1351 /* *** detach a specified port *** */
1352 struct cmd_operate_detach_port_result {
1353         cmdline_fixed_string_t port;
1354         cmdline_fixed_string_t keyword;
1355         portid_t port_id;
1356 };
1357
1358 static void cmd_operate_detach_port_parsed(void *parsed_result,
1359                                 __attribute__((unused)) struct cmdline *cl,
1360                                 __attribute__((unused)) void *data)
1361 {
1362         struct cmd_operate_detach_port_result *res = parsed_result;
1363
1364         if (!strcmp(res->keyword, "detach"))
1365                 detach_port_device(res->port_id);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1372                         port, "port");
1373 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1375                         keyword, "detach");
1376 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1377         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1378                         port_id, UINT16);
1379
1380 cmdline_parse_inst_t cmd_operate_detach_port = {
1381         .f = cmd_operate_detach_port_parsed,
1382         .data = NULL,
1383         .help_str = "port detach <port_id>",
1384         .tokens = {
1385                 (void *)&cmd_operate_detach_port_port,
1386                 (void *)&cmd_operate_detach_port_keyword,
1387                 (void *)&cmd_operate_detach_port_port_id,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** configure speed for all ports *** */
1393 struct cmd_config_speed_all {
1394         cmdline_fixed_string_t port;
1395         cmdline_fixed_string_t keyword;
1396         cmdline_fixed_string_t all;
1397         cmdline_fixed_string_t item1;
1398         cmdline_fixed_string_t item2;
1399         cmdline_fixed_string_t value1;
1400         cmdline_fixed_string_t value2;
1401 };
1402
1403 static int
1404 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1405 {
1406
1407         int duplex;
1408
1409         if (!strcmp(duplexstr, "half")) {
1410                 duplex = ETH_LINK_HALF_DUPLEX;
1411         } else if (!strcmp(duplexstr, "full")) {
1412                 duplex = ETH_LINK_FULL_DUPLEX;
1413         } else if (!strcmp(duplexstr, "auto")) {
1414                 duplex = ETH_LINK_FULL_DUPLEX;
1415         } else {
1416                 printf("Unknown duplex parameter\n");
1417                 return -1;
1418         }
1419
1420         if (!strcmp(speedstr, "10")) {
1421                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1422                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1423         } else if (!strcmp(speedstr, "100")) {
1424                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1425                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1426         } else {
1427                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1428                         printf("Invalid speed/duplex parameters\n");
1429                         return -1;
1430                 }
1431                 if (!strcmp(speedstr, "1000")) {
1432                         *speed = ETH_LINK_SPEED_1G;
1433                 } else if (!strcmp(speedstr, "10000")) {
1434                         *speed = ETH_LINK_SPEED_10G;
1435                 } else if (!strcmp(speedstr, "25000")) {
1436                         *speed = ETH_LINK_SPEED_25G;
1437                 } else if (!strcmp(speedstr, "40000")) {
1438                         *speed = ETH_LINK_SPEED_40G;
1439                 } else if (!strcmp(speedstr, "50000")) {
1440                         *speed = ETH_LINK_SPEED_50G;
1441                 } else if (!strcmp(speedstr, "100000")) {
1442                         *speed = ETH_LINK_SPEED_100G;
1443                 } else if (!strcmp(speedstr, "auto")) {
1444                         *speed = ETH_LINK_SPEED_AUTONEG;
1445                 } else {
1446                         printf("Unknown speed parameter\n");
1447                         return -1;
1448                 }
1449         }
1450
1451         return 0;
1452 }
1453
1454 static void
1455 cmd_config_speed_all_parsed(void *parsed_result,
1456                         __attribute__((unused)) struct cmdline *cl,
1457                         __attribute__((unused)) void *data)
1458 {
1459         struct cmd_config_speed_all *res = parsed_result;
1460         uint32_t link_speed;
1461         portid_t pid;
1462
1463         if (!all_ports_stopped()) {
1464                 printf("Please stop all ports first\n");
1465                 return;
1466         }
1467
1468         if (parse_and_check_speed_duplex(res->value1, res->value2,
1469                         &link_speed) < 0)
1470                 return;
1471
1472         RTE_ETH_FOREACH_DEV(pid) {
1473                 ports[pid].dev_conf.link_speeds = link_speed;
1474         }
1475
1476         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1477 }
1478
1479 cmdline_parse_token_string_t cmd_config_speed_all_port =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1481 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1482         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1483                                                         "config");
1484 cmdline_parse_token_string_t cmd_config_speed_all_all =
1485         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1486 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1488 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1490                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1491 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1493 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1494         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1495                                                 "half#full#auto");
1496
1497 cmdline_parse_inst_t cmd_config_speed_all = {
1498         .f = cmd_config_speed_all_parsed,
1499         .data = NULL,
1500         .help_str = "port config all speed "
1501                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1502                                                         "half|full|auto",
1503         .tokens = {
1504                 (void *)&cmd_config_speed_all_port,
1505                 (void *)&cmd_config_speed_all_keyword,
1506                 (void *)&cmd_config_speed_all_all,
1507                 (void *)&cmd_config_speed_all_item1,
1508                 (void *)&cmd_config_speed_all_value1,
1509                 (void *)&cmd_config_speed_all_item2,
1510                 (void *)&cmd_config_speed_all_value2,
1511                 NULL,
1512         },
1513 };
1514
1515 /* *** configure speed for specific port *** */
1516 struct cmd_config_speed_specific {
1517         cmdline_fixed_string_t port;
1518         cmdline_fixed_string_t keyword;
1519         portid_t id;
1520         cmdline_fixed_string_t item1;
1521         cmdline_fixed_string_t item2;
1522         cmdline_fixed_string_t value1;
1523         cmdline_fixed_string_t value2;
1524 };
1525
1526 static void
1527 cmd_config_speed_specific_parsed(void *parsed_result,
1528                                 __attribute__((unused)) struct cmdline *cl,
1529                                 __attribute__((unused)) void *data)
1530 {
1531         struct cmd_config_speed_specific *res = parsed_result;
1532         uint32_t link_speed;
1533
1534         if (!all_ports_stopped()) {
1535                 printf("Please stop all ports first\n");
1536                 return;
1537         }
1538
1539         if (port_id_is_invalid(res->id, ENABLED_WARN))
1540                 return;
1541
1542         if (parse_and_check_speed_duplex(res->value1, res->value2,
1543                         &link_speed) < 0)
1544                 return;
1545
1546         ports[res->id].dev_conf.link_speeds = link_speed;
1547
1548         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1549 }
1550
1551
1552 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1554                                                                 "port");
1555 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1556         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1557                                                                 "config");
1558 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1559         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1560 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1562                                                                 "speed");
1563 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1565                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1566 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1568                                                                 "duplex");
1569 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1571                                                         "half#full#auto");
1572
1573 cmdline_parse_inst_t cmd_config_speed_specific = {
1574         .f = cmd_config_speed_specific_parsed,
1575         .data = NULL,
1576         .help_str = "port config <port_id> speed "
1577                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1578                                                         "half|full|auto",
1579         .tokens = {
1580                 (void *)&cmd_config_speed_specific_port,
1581                 (void *)&cmd_config_speed_specific_keyword,
1582                 (void *)&cmd_config_speed_specific_id,
1583                 (void *)&cmd_config_speed_specific_item1,
1584                 (void *)&cmd_config_speed_specific_value1,
1585                 (void *)&cmd_config_speed_specific_item2,
1586                 (void *)&cmd_config_speed_specific_value2,
1587                 NULL,
1588         },
1589 };
1590
1591 /* *** configure loopback for all ports *** */
1592 struct cmd_config_loopback_all {
1593         cmdline_fixed_string_t port;
1594         cmdline_fixed_string_t keyword;
1595         cmdline_fixed_string_t all;
1596         cmdline_fixed_string_t item;
1597         uint32_t mode;
1598 };
1599
1600 static void
1601 cmd_config_loopback_all_parsed(void *parsed_result,
1602                         __attribute__((unused)) struct cmdline *cl,
1603                         __attribute__((unused)) void *data)
1604 {
1605         struct cmd_config_loopback_all *res = parsed_result;
1606         portid_t pid;
1607
1608         if (!all_ports_stopped()) {
1609                 printf("Please stop all ports first\n");
1610                 return;
1611         }
1612
1613         RTE_ETH_FOREACH_DEV(pid) {
1614                 ports[pid].dev_conf.lpbk_mode = res->mode;
1615         }
1616
1617         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1618 }
1619
1620 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1621         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1622 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1623         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1624                                                         "config");
1625 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1627 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1628         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1629                                                         "loopback");
1630 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1631         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1632
1633 cmdline_parse_inst_t cmd_config_loopback_all = {
1634         .f = cmd_config_loopback_all_parsed,
1635         .data = NULL,
1636         .help_str = "port config all loopback <mode>",
1637         .tokens = {
1638                 (void *)&cmd_config_loopback_all_port,
1639                 (void *)&cmd_config_loopback_all_keyword,
1640                 (void *)&cmd_config_loopback_all_all,
1641                 (void *)&cmd_config_loopback_all_item,
1642                 (void *)&cmd_config_loopback_all_mode,
1643                 NULL,
1644         },
1645 };
1646
1647 /* *** configure loopback for specific port *** */
1648 struct cmd_config_loopback_specific {
1649         cmdline_fixed_string_t port;
1650         cmdline_fixed_string_t keyword;
1651         uint16_t port_id;
1652         cmdline_fixed_string_t item;
1653         uint32_t mode;
1654 };
1655
1656 static void
1657 cmd_config_loopback_specific_parsed(void *parsed_result,
1658                                 __attribute__((unused)) struct cmdline *cl,
1659                                 __attribute__((unused)) void *data)
1660 {
1661         struct cmd_config_loopback_specific *res = parsed_result;
1662
1663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1664                 return;
1665
1666         if (!port_is_stopped(res->port_id)) {
1667                 printf("Please stop port %u first\n", res->port_id);
1668                 return;
1669         }
1670
1671         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1672
1673         cmd_reconfig_device_queue(res->port_id, 1, 1);
1674 }
1675
1676
1677 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1679                                                                 "port");
1680 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1682                                                                 "config");
1683 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1684         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1685                                                                 UINT16);
1686 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1688                                                                 "loopback");
1689 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1690         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1691                               UINT32);
1692
1693 cmdline_parse_inst_t cmd_config_loopback_specific = {
1694         .f = cmd_config_loopback_specific_parsed,
1695         .data = NULL,
1696         .help_str = "port config <port_id> loopback <mode>",
1697         .tokens = {
1698                 (void *)&cmd_config_loopback_specific_port,
1699                 (void *)&cmd_config_loopback_specific_keyword,
1700                 (void *)&cmd_config_loopback_specific_id,
1701                 (void *)&cmd_config_loopback_specific_item,
1702                 (void *)&cmd_config_loopback_specific_mode,
1703                 NULL,
1704         },
1705 };
1706
1707 /* *** configure txq/rxq, txd/rxd *** */
1708 struct cmd_config_rx_tx {
1709         cmdline_fixed_string_t port;
1710         cmdline_fixed_string_t keyword;
1711         cmdline_fixed_string_t all;
1712         cmdline_fixed_string_t name;
1713         uint16_t value;
1714 };
1715
1716 static void
1717 cmd_config_rx_tx_parsed(void *parsed_result,
1718                         __attribute__((unused)) struct cmdline *cl,
1719                         __attribute__((unused)) void *data)
1720 {
1721         struct cmd_config_rx_tx *res = parsed_result;
1722
1723         if (!all_ports_stopped()) {
1724                 printf("Please stop all ports first\n");
1725                 return;
1726         }
1727         if (!strcmp(res->name, "rxq")) {
1728                 if (!res->value && !nb_txq) {
1729                         printf("Warning: Either rx or tx queues should be non zero\n");
1730                         return;
1731                 }
1732                 if (check_nb_rxq(res->value) != 0)
1733                         return;
1734                 nb_rxq = res->value;
1735         }
1736         else if (!strcmp(res->name, "txq")) {
1737                 if (!res->value && !nb_rxq) {
1738                         printf("Warning: Either rx or tx queues should be non zero\n");
1739                         return;
1740                 }
1741                 if (check_nb_txq(res->value) != 0)
1742                         return;
1743                 nb_txq = res->value;
1744         }
1745         else if (!strcmp(res->name, "rxd")) {
1746                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1747                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1748                                         res->value, RTE_TEST_RX_DESC_MAX);
1749                         return;
1750                 }
1751                 nb_rxd = res->value;
1752         } else if (!strcmp(res->name, "txd")) {
1753                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1754                         printf("txd %d invalid - must be > 0 && <= %d\n",
1755                                         res->value, RTE_TEST_TX_DESC_MAX);
1756                         return;
1757                 }
1758                 nb_txd = res->value;
1759         } else {
1760                 printf("Unknown parameter\n");
1761                 return;
1762         }
1763
1764         fwd_config_setup();
1765
1766         init_port_config();
1767
1768         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1769 }
1770
1771 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1773 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1774         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1775 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1777 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1778         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1779                                                 "rxq#txq#rxd#txd");
1780 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1781         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1782
1783 cmdline_parse_inst_t cmd_config_rx_tx = {
1784         .f = cmd_config_rx_tx_parsed,
1785         .data = NULL,
1786         .help_str = "port config all rxq|txq|rxd|txd <value>",
1787         .tokens = {
1788                 (void *)&cmd_config_rx_tx_port,
1789                 (void *)&cmd_config_rx_tx_keyword,
1790                 (void *)&cmd_config_rx_tx_all,
1791                 (void *)&cmd_config_rx_tx_name,
1792                 (void *)&cmd_config_rx_tx_value,
1793                 NULL,
1794         },
1795 };
1796
1797 /* *** config max packet length *** */
1798 struct cmd_config_max_pkt_len_result {
1799         cmdline_fixed_string_t port;
1800         cmdline_fixed_string_t keyword;
1801         cmdline_fixed_string_t all;
1802         cmdline_fixed_string_t name;
1803         uint32_t value;
1804 };
1805
1806 static void
1807 cmd_config_max_pkt_len_parsed(void *parsed_result,
1808                                 __attribute__((unused)) struct cmdline *cl,
1809                                 __attribute__((unused)) void *data)
1810 {
1811         struct cmd_config_max_pkt_len_result *res = parsed_result;
1812         portid_t pid;
1813
1814         if (!all_ports_stopped()) {
1815                 printf("Please stop all ports first\n");
1816                 return;
1817         }
1818
1819         RTE_ETH_FOREACH_DEV(pid) {
1820                 struct rte_port *port = &ports[pid];
1821                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1822
1823                 if (!strcmp(res->name, "max-pkt-len")) {
1824                         if (res->value < ETHER_MIN_LEN) {
1825                                 printf("max-pkt-len can not be less than %d\n",
1826                                                 ETHER_MIN_LEN);
1827                                 return;
1828                         }
1829                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1830                                 return;
1831
1832                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1833                         if (res->value > ETHER_MAX_LEN)
1834                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1835                         else
1836                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1837                         port->dev_conf.rxmode.offloads = rx_offloads;
1838                 } else {
1839                         printf("Unknown parameter\n");
1840                         return;
1841                 }
1842         }
1843
1844         init_port_config();
1845
1846         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1847 }
1848
1849 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1851                                                                 "port");
1852 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1854                                                                 "config");
1855 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1856         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1857                                                                 "all");
1858 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1860                                                                 "max-pkt-len");
1861 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1862         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1863                                                                 UINT32);
1864
1865 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1866         .f = cmd_config_max_pkt_len_parsed,
1867         .data = NULL,
1868         .help_str = "port config all max-pkt-len <value>",
1869         .tokens = {
1870                 (void *)&cmd_config_max_pkt_len_port,
1871                 (void *)&cmd_config_max_pkt_len_keyword,
1872                 (void *)&cmd_config_max_pkt_len_all,
1873                 (void *)&cmd_config_max_pkt_len_name,
1874                 (void *)&cmd_config_max_pkt_len_value,
1875                 NULL,
1876         },
1877 };
1878
1879 /* *** configure port MTU *** */
1880 struct cmd_config_mtu_result {
1881         cmdline_fixed_string_t port;
1882         cmdline_fixed_string_t keyword;
1883         cmdline_fixed_string_t mtu;
1884         portid_t port_id;
1885         uint16_t value;
1886 };
1887
1888 static void
1889 cmd_config_mtu_parsed(void *parsed_result,
1890                       __attribute__((unused)) struct cmdline *cl,
1891                       __attribute__((unused)) void *data)
1892 {
1893         struct cmd_config_mtu_result *res = parsed_result;
1894
1895         if (res->value < ETHER_MIN_LEN) {
1896                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1897                 return;
1898         }
1899         port_mtu_set(res->port_id, res->value);
1900 }
1901
1902 cmdline_parse_token_string_t cmd_config_mtu_port =
1903         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1904                                  "port");
1905 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1906         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1907                                  "config");
1908 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1909         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1910                                  "mtu");
1911 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1912         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1913 cmdline_parse_token_num_t cmd_config_mtu_value =
1914         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1915
1916 cmdline_parse_inst_t cmd_config_mtu = {
1917         .f = cmd_config_mtu_parsed,
1918         .data = NULL,
1919         .help_str = "port config mtu <port_id> <value>",
1920         .tokens = {
1921                 (void *)&cmd_config_mtu_port,
1922                 (void *)&cmd_config_mtu_keyword,
1923                 (void *)&cmd_config_mtu_mtu,
1924                 (void *)&cmd_config_mtu_port_id,
1925                 (void *)&cmd_config_mtu_value,
1926                 NULL,
1927         },
1928 };
1929
1930 /* *** configure rx mode *** */
1931 struct cmd_config_rx_mode_flag {
1932         cmdline_fixed_string_t port;
1933         cmdline_fixed_string_t keyword;
1934         cmdline_fixed_string_t all;
1935         cmdline_fixed_string_t name;
1936         cmdline_fixed_string_t value;
1937 };
1938
1939 static void
1940 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1941                                 __attribute__((unused)) struct cmdline *cl,
1942                                 __attribute__((unused)) void *data)
1943 {
1944         struct cmd_config_rx_mode_flag *res = parsed_result;
1945         portid_t pid;
1946
1947         if (!all_ports_stopped()) {
1948                 printf("Please stop all ports first\n");
1949                 return;
1950         }
1951
1952         RTE_ETH_FOREACH_DEV(pid) {
1953                 struct rte_port *port;
1954                 uint64_t rx_offloads;
1955
1956                 port = &ports[pid];
1957                 rx_offloads = port->dev_conf.rxmode.offloads;
1958                 if (!strcmp(res->name, "crc-strip")) {
1959                         if (!strcmp(res->value, "on")) {
1960                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1961                         } else if (!strcmp(res->value, "off")) {
1962                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1963                         } else {
1964                                 printf("Unknown parameter\n");
1965                                 return;
1966                         }
1967                 } else if (!strcmp(res->name, "scatter")) {
1968                         if (!strcmp(res->value, "on")) {
1969                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1970                         } else if (!strcmp(res->value, "off")) {
1971                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1972                         } else {
1973                                 printf("Unknown parameter\n");
1974                                 return;
1975                         }
1976                 } else if (!strcmp(res->name, "rx-cksum")) {
1977                         if (!strcmp(res->value, "on"))
1978                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1979                         else if (!strcmp(res->value, "off"))
1980                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1981                         else {
1982                                 printf("Unknown parameter\n");
1983                                 return;
1984                         }
1985                 } else if (!strcmp(res->name, "rx-timestamp")) {
1986                         if (!strcmp(res->value, "on"))
1987                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1988                         else if (!strcmp(res->value, "off"))
1989                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1990                         else {
1991                                 printf("Unknown parameter\n");
1992                                 return;
1993                         }
1994                 } else if (!strcmp(res->name, "hw-vlan")) {
1995                         if (!strcmp(res->value, "on")) {
1996                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1997                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1998                         } else if (!strcmp(res->value, "off")) {
1999                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2000                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2001                         } else {
2002                                 printf("Unknown parameter\n");
2003                                 return;
2004                         }
2005                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2006                         if (!strcmp(res->value, "on"))
2007                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2008                         else if (!strcmp(res->value, "off"))
2009                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2010                         else {
2011                                 printf("Unknown parameter\n");
2012                                 return;
2013                         }
2014                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2015                         if (!strcmp(res->value, "on"))
2016                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2017                         else if (!strcmp(res->value, "off"))
2018                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2019                         else {
2020                                 printf("Unknown parameter\n");
2021                                 return;
2022                         }
2023                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2024                         if (!strcmp(res->value, "on"))
2025                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2026                         else if (!strcmp(res->value, "off"))
2027                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2028                         else {
2029                                 printf("Unknown parameter\n");
2030                                 return;
2031                         }
2032                 } else if (!strcmp(res->name, "drop-en")) {
2033                         if (!strcmp(res->value, "on"))
2034                                 rx_drop_en = 1;
2035                         else if (!strcmp(res->value, "off"))
2036                                 rx_drop_en = 0;
2037                         else {
2038                                 printf("Unknown parameter\n");
2039                                 return;
2040                         }
2041                 } else {
2042                         printf("Unknown parameter\n");
2043                         return;
2044                 }
2045                 port->dev_conf.rxmode.offloads = rx_offloads;
2046         }
2047
2048         init_port_config();
2049
2050         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2051 }
2052
2053 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2055 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2057                                                                 "config");
2058 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2060 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2062                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2063                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2064 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2066                                                         "on#off");
2067
2068 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2069         .f = cmd_config_rx_mode_flag_parsed,
2070         .data = NULL,
2071         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2072                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2073         .tokens = {
2074                 (void *)&cmd_config_rx_mode_flag_port,
2075                 (void *)&cmd_config_rx_mode_flag_keyword,
2076                 (void *)&cmd_config_rx_mode_flag_all,
2077                 (void *)&cmd_config_rx_mode_flag_name,
2078                 (void *)&cmd_config_rx_mode_flag_value,
2079                 NULL,
2080         },
2081 };
2082
2083 /* *** configure rss *** */
2084 struct cmd_config_rss {
2085         cmdline_fixed_string_t port;
2086         cmdline_fixed_string_t keyword;
2087         cmdline_fixed_string_t all;
2088         cmdline_fixed_string_t name;
2089         cmdline_fixed_string_t value;
2090 };
2091
2092 static void
2093 cmd_config_rss_parsed(void *parsed_result,
2094                         __attribute__((unused)) struct cmdline *cl,
2095                         __attribute__((unused)) void *data)
2096 {
2097         struct cmd_config_rss *res = parsed_result;
2098         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2099         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2100         int use_default = 0;
2101         int all_updated = 1;
2102         int diag;
2103         uint16_t i;
2104
2105         if (!strcmp(res->value, "all"))
2106                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2107                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2108                                         ETH_RSS_L2_PAYLOAD;
2109         else if (!strcmp(res->value, "ip"))
2110                 rss_conf.rss_hf = ETH_RSS_IP;
2111         else if (!strcmp(res->value, "udp"))
2112                 rss_conf.rss_hf = ETH_RSS_UDP;
2113         else if (!strcmp(res->value, "tcp"))
2114                 rss_conf.rss_hf = ETH_RSS_TCP;
2115         else if (!strcmp(res->value, "sctp"))
2116                 rss_conf.rss_hf = ETH_RSS_SCTP;
2117         else if (!strcmp(res->value, "ether"))
2118                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2119         else if (!strcmp(res->value, "port"))
2120                 rss_conf.rss_hf = ETH_RSS_PORT;
2121         else if (!strcmp(res->value, "vxlan"))
2122                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2123         else if (!strcmp(res->value, "geneve"))
2124                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2125         else if (!strcmp(res->value, "nvgre"))
2126                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2127         else if (!strcmp(res->value, "none"))
2128                 rss_conf.rss_hf = 0;
2129         else if (!strcmp(res->value, "default"))
2130                 use_default = 1;
2131         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2132                                                 atoi(res->value) < 64)
2133                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2134         else {
2135                 printf("Unknown parameter\n");
2136                 return;
2137         }
2138         rss_conf.rss_key = NULL;
2139         /* Update global configuration for RSS types. */
2140         RTE_ETH_FOREACH_DEV(i) {
2141                 struct rte_eth_rss_conf local_rss_conf;
2142
2143                 rte_eth_dev_info_get(i, &dev_info);
2144                 if (use_default)
2145                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2146
2147                 local_rss_conf = rss_conf;
2148                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2149                         dev_info.flow_type_rss_offloads;
2150                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2151                         printf("Port %u modified RSS hash function based on hardware support,"
2152                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2153                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2154                 }
2155                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2156                 if (diag < 0) {
2157                         all_updated = 0;
2158                         printf("Configuration of RSS hash at ethernet port %d "
2159                                 "failed with error (%d): %s.\n",
2160                                 i, -diag, strerror(-diag));
2161                 }
2162         }
2163         if (all_updated && !use_default)
2164                 rss_hf = rss_conf.rss_hf;
2165 }
2166
2167 cmdline_parse_token_string_t cmd_config_rss_port =
2168         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2169 cmdline_parse_token_string_t cmd_config_rss_keyword =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2171 cmdline_parse_token_string_t cmd_config_rss_all =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2173 cmdline_parse_token_string_t cmd_config_rss_name =
2174         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2175 cmdline_parse_token_string_t cmd_config_rss_value =
2176         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2177
2178 cmdline_parse_inst_t cmd_config_rss = {
2179         .f = cmd_config_rss_parsed,
2180         .data = NULL,
2181         .help_str = "port config all rss "
2182                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2183         .tokens = {
2184                 (void *)&cmd_config_rss_port,
2185                 (void *)&cmd_config_rss_keyword,
2186                 (void *)&cmd_config_rss_all,
2187                 (void *)&cmd_config_rss_name,
2188                 (void *)&cmd_config_rss_value,
2189                 NULL,
2190         },
2191 };
2192
2193 /* *** configure rss hash key *** */
2194 struct cmd_config_rss_hash_key {
2195         cmdline_fixed_string_t port;
2196         cmdline_fixed_string_t config;
2197         portid_t port_id;
2198         cmdline_fixed_string_t rss_hash_key;
2199         cmdline_fixed_string_t rss_type;
2200         cmdline_fixed_string_t key;
2201 };
2202
2203 static uint8_t
2204 hexa_digit_to_value(char hexa_digit)
2205 {
2206         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2207                 return (uint8_t) (hexa_digit - '0');
2208         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2209                 return (uint8_t) ((hexa_digit - 'a') + 10);
2210         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2211                 return (uint8_t) ((hexa_digit - 'A') + 10);
2212         /* Invalid hexa digit */
2213         return 0xFF;
2214 }
2215
2216 static uint8_t
2217 parse_and_check_key_hexa_digit(char *key, int idx)
2218 {
2219         uint8_t hexa_v;
2220
2221         hexa_v = hexa_digit_to_value(key[idx]);
2222         if (hexa_v == 0xFF)
2223                 printf("invalid key: character %c at position %d is not a "
2224                        "valid hexa digit\n", key[idx], idx);
2225         return hexa_v;
2226 }
2227
2228 static void
2229 cmd_config_rss_hash_key_parsed(void *parsed_result,
2230                                __attribute__((unused)) struct cmdline *cl,
2231                                __attribute__((unused)) void *data)
2232 {
2233         struct cmd_config_rss_hash_key *res = parsed_result;
2234         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2235         uint8_t xdgt0;
2236         uint8_t xdgt1;
2237         int i;
2238         struct rte_eth_dev_info dev_info;
2239         uint8_t hash_key_size;
2240         uint32_t key_len;
2241
2242         memset(&dev_info, 0, sizeof(dev_info));
2243         rte_eth_dev_info_get(res->port_id, &dev_info);
2244         if (dev_info.hash_key_size > 0 &&
2245                         dev_info.hash_key_size <= sizeof(hash_key))
2246                 hash_key_size = dev_info.hash_key_size;
2247         else {
2248                 printf("dev_info did not provide a valid hash key size\n");
2249                 return;
2250         }
2251         /* Check the length of the RSS hash key */
2252         key_len = strlen(res->key);
2253         if (key_len != (hash_key_size * 2)) {
2254                 printf("key length: %d invalid - key must be a string of %d"
2255                            " hexa-decimal numbers\n",
2256                            (int) key_len, hash_key_size * 2);
2257                 return;
2258         }
2259         /* Translate RSS hash key into binary representation */
2260         for (i = 0; i < hash_key_size; i++) {
2261                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2262                 if (xdgt0 == 0xFF)
2263                         return;
2264                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2265                 if (xdgt1 == 0xFF)
2266                         return;
2267                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2268         }
2269         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2270                         hash_key_size);
2271 }
2272
2273 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2275 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2277                                  "config");
2278 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2279         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2280 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2282                                  rss_hash_key, "rss-hash-key");
2283 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2285                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2286                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2287                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2288                                  "ipv6-tcp-ex#ipv6-udp-ex");
2289 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2291
2292 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2293         .f = cmd_config_rss_hash_key_parsed,
2294         .data = NULL,
2295         .help_str = "port config <port_id> rss-hash-key "
2296                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2297                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2298                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2299                 "<string of hex digits (variable length, NIC dependent)>",
2300         .tokens = {
2301                 (void *)&cmd_config_rss_hash_key_port,
2302                 (void *)&cmd_config_rss_hash_key_config,
2303                 (void *)&cmd_config_rss_hash_key_port_id,
2304                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2305                 (void *)&cmd_config_rss_hash_key_rss_type,
2306                 (void *)&cmd_config_rss_hash_key_value,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** configure port rxq/txq ring size *** */
2312 struct cmd_config_rxtx_ring_size {
2313         cmdline_fixed_string_t port;
2314         cmdline_fixed_string_t config;
2315         portid_t portid;
2316         cmdline_fixed_string_t rxtxq;
2317         uint16_t qid;
2318         cmdline_fixed_string_t rsize;
2319         uint16_t size;
2320 };
2321
2322 static void
2323 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2324                                  __attribute__((unused)) struct cmdline *cl,
2325                                  __attribute__((unused)) void *data)
2326 {
2327         struct cmd_config_rxtx_ring_size *res = parsed_result;
2328         struct rte_port *port;
2329         uint8_t isrx;
2330
2331         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2332                 return;
2333
2334         if (res->portid == (portid_t)RTE_PORT_ALL) {
2335                 printf("Invalid port id\n");
2336                 return;
2337         }
2338
2339         port = &ports[res->portid];
2340
2341         if (!strcmp(res->rxtxq, "rxq"))
2342                 isrx = 1;
2343         else if (!strcmp(res->rxtxq, "txq"))
2344                 isrx = 0;
2345         else {
2346                 printf("Unknown parameter\n");
2347                 return;
2348         }
2349
2350         if (isrx && rx_queue_id_is_invalid(res->qid))
2351                 return;
2352         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2353                 return;
2354
2355         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2356                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2357                        rx_free_thresh);
2358                 return;
2359         }
2360
2361         if (isrx)
2362                 port->nb_rx_desc[res->qid] = res->size;
2363         else
2364                 port->nb_tx_desc[res->qid] = res->size;
2365
2366         cmd_reconfig_device_queue(res->portid, 0, 1);
2367 }
2368
2369 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2371                                  port, "port");
2372 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2374                                  config, "config");
2375 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2376         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2377                                  portid, UINT16);
2378 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2379         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2380                                  rxtxq, "rxq#txq");
2381 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2382         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2383                               qid, UINT16);
2384 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2386                                  rsize, "ring_size");
2387 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2388         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2389                               size, UINT16);
2390
2391 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2392         .f = cmd_config_rxtx_ring_size_parsed,
2393         .data = NULL,
2394         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2395         .tokens = {
2396                 (void *)&cmd_config_rxtx_ring_size_port,
2397                 (void *)&cmd_config_rxtx_ring_size_config,
2398                 (void *)&cmd_config_rxtx_ring_size_portid,
2399                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2400                 (void *)&cmd_config_rxtx_ring_size_qid,
2401                 (void *)&cmd_config_rxtx_ring_size_rsize,
2402                 (void *)&cmd_config_rxtx_ring_size_size,
2403                 NULL,
2404         },
2405 };
2406
2407 /* *** configure port rxq/txq start/stop *** */
2408 struct cmd_config_rxtx_queue {
2409         cmdline_fixed_string_t port;
2410         portid_t portid;
2411         cmdline_fixed_string_t rxtxq;
2412         uint16_t qid;
2413         cmdline_fixed_string_t opname;
2414 };
2415
2416 static void
2417 cmd_config_rxtx_queue_parsed(void *parsed_result,
2418                         __attribute__((unused)) struct cmdline *cl,
2419                         __attribute__((unused)) void *data)
2420 {
2421         struct cmd_config_rxtx_queue *res = parsed_result;
2422         uint8_t isrx;
2423         uint8_t isstart;
2424         int ret = 0;
2425
2426         if (test_done == 0) {
2427                 printf("Please stop forwarding first\n");
2428                 return;
2429         }
2430
2431         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2432                 return;
2433
2434         if (port_is_started(res->portid) != 1) {
2435                 printf("Please start port %u first\n", res->portid);
2436                 return;
2437         }
2438
2439         if (!strcmp(res->rxtxq, "rxq"))
2440                 isrx = 1;
2441         else if (!strcmp(res->rxtxq, "txq"))
2442                 isrx = 0;
2443         else {
2444                 printf("Unknown parameter\n");
2445                 return;
2446         }
2447
2448         if (isrx && rx_queue_id_is_invalid(res->qid))
2449                 return;
2450         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2451                 return;
2452
2453         if (!strcmp(res->opname, "start"))
2454                 isstart = 1;
2455         else if (!strcmp(res->opname, "stop"))
2456                 isstart = 0;
2457         else {
2458                 printf("Unknown parameter\n");
2459                 return;
2460         }
2461
2462         if (isstart && isrx)
2463                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2464         else if (!isstart && isrx)
2465                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2466         else if (isstart && !isrx)
2467                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2468         else
2469                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2470
2471         if (ret == -ENOTSUP)
2472                 printf("Function not supported in PMD driver\n");
2473 }
2474
2475 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2476         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2477 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2478         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2479 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2481 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2482         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2483 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2484         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2485                                                 "start#stop");
2486
2487 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2488         .f = cmd_config_rxtx_queue_parsed,
2489         .data = NULL,
2490         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2491         .tokens = {
2492                 (void *)&cmd_config_rxtx_queue_port,
2493                 (void *)&cmd_config_rxtx_queue_portid,
2494                 (void *)&cmd_config_rxtx_queue_rxtxq,
2495                 (void *)&cmd_config_rxtx_queue_qid,
2496                 (void *)&cmd_config_rxtx_queue_opname,
2497                 NULL,
2498         },
2499 };
2500
2501 /* *** configure port rxq/txq deferred start on/off *** */
2502 struct cmd_config_deferred_start_rxtx_queue {
2503         cmdline_fixed_string_t port;
2504         portid_t port_id;
2505         cmdline_fixed_string_t rxtxq;
2506         uint16_t qid;
2507         cmdline_fixed_string_t opname;
2508         cmdline_fixed_string_t state;
2509 };
2510
2511 static void
2512 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2513                         __attribute__((unused)) struct cmdline *cl,
2514                         __attribute__((unused)) void *data)
2515 {
2516         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2517         struct rte_port *port;
2518         uint8_t isrx;
2519         uint8_t ison;
2520         uint8_t needreconfig = 0;
2521
2522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2523                 return;
2524
2525         if (port_is_started(res->port_id) != 0) {
2526                 printf("Please stop port %u first\n", res->port_id);
2527                 return;
2528         }
2529
2530         port = &ports[res->port_id];
2531
2532         isrx = !strcmp(res->rxtxq, "rxq");
2533
2534         if (isrx && rx_queue_id_is_invalid(res->qid))
2535                 return;
2536         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2537                 return;
2538
2539         ison = !strcmp(res->state, "on");
2540
2541         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2542                 port->rx_conf[res->qid].rx_deferred_start = ison;
2543                 needreconfig = 1;
2544         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2545                 port->tx_conf[res->qid].tx_deferred_start = ison;
2546                 needreconfig = 1;
2547         }
2548
2549         if (needreconfig)
2550                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2551 }
2552
2553 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2555                                                 port, "port");
2556 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2557         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2558                                                 port_id, UINT16);
2559 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2561                                                 rxtxq, "rxq#txq");
2562 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2563         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2564                                                 qid, UINT16);
2565 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2567                                                 opname, "deferred_start");
2568 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2570                                                 state, "on#off");
2571
2572 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2573         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2574         .data = NULL,
2575         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2576         .tokens = {
2577                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2578                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2579                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2580                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2581                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2582                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2583                 NULL,
2584         },
2585 };
2586
2587 /* *** configure port rxq/txq setup *** */
2588 struct cmd_setup_rxtx_queue {
2589         cmdline_fixed_string_t port;
2590         portid_t portid;
2591         cmdline_fixed_string_t rxtxq;
2592         uint16_t qid;
2593         cmdline_fixed_string_t setup;
2594 };
2595
2596 /* Common CLI fields for queue setup */
2597 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2598         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2599 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2601 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2602         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2603 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2604         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2605 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2606         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2607
2608 static void
2609 cmd_setup_rxtx_queue_parsed(
2610         void *parsed_result,
2611         __attribute__((unused)) struct cmdline *cl,
2612         __attribute__((unused)) void *data)
2613 {
2614         struct cmd_setup_rxtx_queue *res = parsed_result;
2615         struct rte_port *port;
2616         struct rte_mempool *mp;
2617         unsigned int socket_id;
2618         uint8_t isrx = 0;
2619         int ret;
2620
2621         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2622                 return;
2623
2624         if (res->portid == (portid_t)RTE_PORT_ALL) {
2625                 printf("Invalid port id\n");
2626                 return;
2627         }
2628
2629         if (!strcmp(res->rxtxq, "rxq"))
2630                 isrx = 1;
2631         else if (!strcmp(res->rxtxq, "txq"))
2632                 isrx = 0;
2633         else {
2634                 printf("Unknown parameter\n");
2635                 return;
2636         }
2637
2638         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2639                 printf("Invalid rx queue\n");
2640                 return;
2641         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2642                 printf("Invalid tx queue\n");
2643                 return;
2644         }
2645
2646         port = &ports[res->portid];
2647         if (isrx) {
2648                 socket_id = rxring_numa[res->portid];
2649                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2650                         socket_id = port->socket_id;
2651
2652                 mp = mbuf_pool_find(socket_id);
2653                 if (mp == NULL) {
2654                         printf("Failed to setup RX queue: "
2655                                 "No mempool allocation"
2656                                 " on the socket %d\n",
2657                                 rxring_numa[res->portid]);
2658                         return;
2659                 }
2660                 ret = rte_eth_rx_queue_setup(res->portid,
2661                                              res->qid,
2662                                              port->nb_rx_desc[res->qid],
2663                                              socket_id,
2664                                              &port->rx_conf[res->qid],
2665                                              mp);
2666                 if (ret)
2667                         printf("Failed to setup RX queue\n");
2668         } else {
2669                 socket_id = txring_numa[res->portid];
2670                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2671                         socket_id = port->socket_id;
2672
2673                 ret = rte_eth_tx_queue_setup(res->portid,
2674                                              res->qid,
2675                                              port->nb_tx_desc[res->qid],
2676                                              socket_id,
2677                                              &port->tx_conf[res->qid]);
2678                 if (ret)
2679                         printf("Failed to setup TX queue\n");
2680         }
2681 }
2682
2683 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2684         .f = cmd_setup_rxtx_queue_parsed,
2685         .data = NULL,
2686         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2687         .tokens = {
2688                 (void *)&cmd_setup_rxtx_queue_port,
2689                 (void *)&cmd_setup_rxtx_queue_portid,
2690                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2691                 (void *)&cmd_setup_rxtx_queue_qid,
2692                 (void *)&cmd_setup_rxtx_queue_setup,
2693                 NULL,
2694         },
2695 };
2696
2697
2698 /* *** Configure RSS RETA *** */
2699 struct cmd_config_rss_reta {
2700         cmdline_fixed_string_t port;
2701         cmdline_fixed_string_t keyword;
2702         portid_t port_id;
2703         cmdline_fixed_string_t name;
2704         cmdline_fixed_string_t list_name;
2705         cmdline_fixed_string_t list_of_items;
2706 };
2707
2708 static int
2709 parse_reta_config(const char *str,
2710                   struct rte_eth_rss_reta_entry64 *reta_conf,
2711                   uint16_t nb_entries)
2712 {
2713         int i;
2714         unsigned size;
2715         uint16_t hash_index, idx, shift;
2716         uint16_t nb_queue;
2717         char s[256];
2718         const char *p, *p0 = str;
2719         char *end;
2720         enum fieldnames {
2721                 FLD_HASH_INDEX = 0,
2722                 FLD_QUEUE,
2723                 _NUM_FLD
2724         };
2725         unsigned long int_fld[_NUM_FLD];
2726         char *str_fld[_NUM_FLD];
2727
2728         while ((p = strchr(p0,'(')) != NULL) {
2729                 ++p;
2730                 if((p0 = strchr(p,')')) == NULL)
2731                         return -1;
2732
2733                 size = p0 - p;
2734                 if(size >= sizeof(s))
2735                         return -1;
2736
2737                 snprintf(s, sizeof(s), "%.*s", size, p);
2738                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2739                         return -1;
2740                 for (i = 0; i < _NUM_FLD; i++) {
2741                         errno = 0;
2742                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2743                         if (errno != 0 || end == str_fld[i] ||
2744                                         int_fld[i] > 65535)
2745                                 return -1;
2746                 }
2747
2748                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2749                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2750
2751                 if (hash_index >= nb_entries) {
2752                         printf("Invalid RETA hash index=%d\n", hash_index);
2753                         return -1;
2754                 }
2755
2756                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2757                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2758                 reta_conf[idx].mask |= (1ULL << shift);
2759                 reta_conf[idx].reta[shift] = nb_queue;
2760         }
2761
2762         return 0;
2763 }
2764
2765 static void
2766 cmd_set_rss_reta_parsed(void *parsed_result,
2767                         __attribute__((unused)) struct cmdline *cl,
2768                         __attribute__((unused)) void *data)
2769 {
2770         int ret;
2771         struct rte_eth_dev_info dev_info;
2772         struct rte_eth_rss_reta_entry64 reta_conf[8];
2773         struct cmd_config_rss_reta *res = parsed_result;
2774
2775         memset(&dev_info, 0, sizeof(dev_info));
2776         rte_eth_dev_info_get(res->port_id, &dev_info);
2777         if (dev_info.reta_size == 0) {
2778                 printf("Redirection table size is 0 which is "
2779                                         "invalid for RSS\n");
2780                 return;
2781         } else
2782                 printf("The reta size of port %d is %u\n",
2783                         res->port_id, dev_info.reta_size);
2784         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2785                 printf("Currently do not support more than %u entries of "
2786                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2787                 return;
2788         }
2789
2790         memset(reta_conf, 0, sizeof(reta_conf));
2791         if (!strcmp(res->list_name, "reta")) {
2792                 if (parse_reta_config(res->list_of_items, reta_conf,
2793                                                 dev_info.reta_size)) {
2794                         printf("Invalid RSS Redirection Table "
2795                                         "config entered\n");
2796                         return;
2797                 }
2798                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2799                                 reta_conf, dev_info.reta_size);
2800                 if (ret != 0)
2801                         printf("Bad redirection table parameter, "
2802                                         "return code = %d \n", ret);
2803         }
2804 }
2805
2806 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2807         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2808 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2809         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2810 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2811         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2812 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2813         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2814 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2815         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2816 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2817         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2818                                  NULL);
2819 cmdline_parse_inst_t cmd_config_rss_reta = {
2820         .f = cmd_set_rss_reta_parsed,
2821         .data = NULL,
2822         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2823         .tokens = {
2824                 (void *)&cmd_config_rss_reta_port,
2825                 (void *)&cmd_config_rss_reta_keyword,
2826                 (void *)&cmd_config_rss_reta_port_id,
2827                 (void *)&cmd_config_rss_reta_name,
2828                 (void *)&cmd_config_rss_reta_list_name,
2829                 (void *)&cmd_config_rss_reta_list_of_items,
2830                 NULL,
2831         },
2832 };
2833
2834 /* *** SHOW PORT RETA INFO *** */
2835 struct cmd_showport_reta {
2836         cmdline_fixed_string_t show;
2837         cmdline_fixed_string_t port;
2838         portid_t port_id;
2839         cmdline_fixed_string_t rss;
2840         cmdline_fixed_string_t reta;
2841         uint16_t size;
2842         cmdline_fixed_string_t list_of_items;
2843 };
2844
2845 static int
2846 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2847                            uint16_t nb_entries,
2848                            char *str)
2849 {
2850         uint32_t size;
2851         const char *p, *p0 = str;
2852         char s[256];
2853         char *end;
2854         char *str_fld[8];
2855         uint16_t i;
2856         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2857                         RTE_RETA_GROUP_SIZE;
2858         int ret;
2859
2860         p = strchr(p0, '(');
2861         if (p == NULL)
2862                 return -1;
2863         p++;
2864         p0 = strchr(p, ')');
2865         if (p0 == NULL)
2866                 return -1;
2867         size = p0 - p;
2868         if (size >= sizeof(s)) {
2869                 printf("The string size exceeds the internal buffer size\n");
2870                 return -1;
2871         }
2872         snprintf(s, sizeof(s), "%.*s", size, p);
2873         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2874         if (ret <= 0 || ret != num) {
2875                 printf("The bits of masks do not match the number of "
2876                                         "reta entries: %u\n", num);
2877                 return -1;
2878         }
2879         for (i = 0; i < ret; i++)
2880                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2881
2882         return 0;
2883 }
2884
2885 static void
2886 cmd_showport_reta_parsed(void *parsed_result,
2887                          __attribute__((unused)) struct cmdline *cl,
2888                          __attribute__((unused)) void *data)
2889 {
2890         struct cmd_showport_reta *res = parsed_result;
2891         struct rte_eth_rss_reta_entry64 reta_conf[8];
2892         struct rte_eth_dev_info dev_info;
2893         uint16_t max_reta_size;
2894
2895         memset(&dev_info, 0, sizeof(dev_info));
2896         rte_eth_dev_info_get(res->port_id, &dev_info);
2897         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2898         if (res->size == 0 || res->size > max_reta_size) {
2899                 printf("Invalid redirection table size: %u (1-%u)\n",
2900                         res->size, max_reta_size);
2901                 return;
2902         }
2903
2904         memset(reta_conf, 0, sizeof(reta_conf));
2905         if (showport_parse_reta_config(reta_conf, res->size,
2906                                 res->list_of_items) < 0) {
2907                 printf("Invalid string: %s for reta masks\n",
2908                                         res->list_of_items);
2909                 return;
2910         }
2911         port_rss_reta_info(res->port_id, reta_conf, res->size);
2912 }
2913
2914 cmdline_parse_token_string_t cmd_showport_reta_show =
2915         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2916 cmdline_parse_token_string_t cmd_showport_reta_port =
2917         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2918 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2919         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2920 cmdline_parse_token_string_t cmd_showport_reta_rss =
2921         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2922 cmdline_parse_token_string_t cmd_showport_reta_reta =
2923         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2924 cmdline_parse_token_num_t cmd_showport_reta_size =
2925         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2926 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2927         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2928                                         list_of_items, NULL);
2929
2930 cmdline_parse_inst_t cmd_showport_reta = {
2931         .f = cmd_showport_reta_parsed,
2932         .data = NULL,
2933         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2934         .tokens = {
2935                 (void *)&cmd_showport_reta_show,
2936                 (void *)&cmd_showport_reta_port,
2937                 (void *)&cmd_showport_reta_port_id,
2938                 (void *)&cmd_showport_reta_rss,
2939                 (void *)&cmd_showport_reta_reta,
2940                 (void *)&cmd_showport_reta_size,
2941                 (void *)&cmd_showport_reta_list_of_items,
2942                 NULL,
2943         },
2944 };
2945
2946 /* *** Show RSS hash configuration *** */
2947 struct cmd_showport_rss_hash {
2948         cmdline_fixed_string_t show;
2949         cmdline_fixed_string_t port;
2950         portid_t port_id;
2951         cmdline_fixed_string_t rss_hash;
2952         cmdline_fixed_string_t rss_type;
2953         cmdline_fixed_string_t key; /* optional argument */
2954 };
2955
2956 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2957                                 __attribute__((unused)) struct cmdline *cl,
2958                                 void *show_rss_key)
2959 {
2960         struct cmd_showport_rss_hash *res = parsed_result;
2961
2962         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2963 }
2964
2965 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2966         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2967 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2968         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2969 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2970         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2971 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2972         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2973                                  "rss-hash");
2974 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2975         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2976
2977 cmdline_parse_inst_t cmd_showport_rss_hash = {
2978         .f = cmd_showport_rss_hash_parsed,
2979         .data = NULL,
2980         .help_str = "show port <port_id> rss-hash",
2981         .tokens = {
2982                 (void *)&cmd_showport_rss_hash_show,
2983                 (void *)&cmd_showport_rss_hash_port,
2984                 (void *)&cmd_showport_rss_hash_port_id,
2985                 (void *)&cmd_showport_rss_hash_rss_hash,
2986                 NULL,
2987         },
2988 };
2989
2990 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2991         .f = cmd_showport_rss_hash_parsed,
2992         .data = (void *)1,
2993         .help_str = "show port <port_id> rss-hash key",
2994         .tokens = {
2995                 (void *)&cmd_showport_rss_hash_show,
2996                 (void *)&cmd_showport_rss_hash_port,
2997                 (void *)&cmd_showport_rss_hash_port_id,
2998                 (void *)&cmd_showport_rss_hash_rss_hash,
2999                 (void *)&cmd_showport_rss_hash_rss_key,
3000                 NULL,
3001         },
3002 };
3003
3004 /* *** Configure DCB *** */
3005 struct cmd_config_dcb {
3006         cmdline_fixed_string_t port;
3007         cmdline_fixed_string_t config;
3008         portid_t port_id;
3009         cmdline_fixed_string_t dcb;
3010         cmdline_fixed_string_t vt;
3011         cmdline_fixed_string_t vt_en;
3012         uint8_t num_tcs;
3013         cmdline_fixed_string_t pfc;
3014         cmdline_fixed_string_t pfc_en;
3015 };
3016
3017 static void
3018 cmd_config_dcb_parsed(void *parsed_result,
3019                         __attribute__((unused)) struct cmdline *cl,
3020                         __attribute__((unused)) void *data)
3021 {
3022         struct cmd_config_dcb *res = parsed_result;
3023         portid_t port_id = res->port_id;
3024         struct rte_port *port;
3025         uint8_t pfc_en;
3026         int ret;
3027
3028         port = &ports[port_id];
3029         /** Check if the port is not started **/
3030         if (port->port_status != RTE_PORT_STOPPED) {
3031                 printf("Please stop port %d first\n", port_id);
3032                 return;
3033         }
3034
3035         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3036                 printf("The invalid number of traffic class,"
3037                         " only 4 or 8 allowed.\n");
3038                 return;
3039         }
3040
3041         if (nb_fwd_lcores < res->num_tcs) {
3042                 printf("nb_cores shouldn't be less than number of TCs.\n");
3043                 return;
3044         }
3045         if (!strncmp(res->pfc_en, "on", 2))
3046                 pfc_en = 1;
3047         else
3048                 pfc_en = 0;
3049
3050         /* DCB in VT mode */
3051         if (!strncmp(res->vt_en, "on", 2))
3052                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3053                                 (enum rte_eth_nb_tcs)res->num_tcs,
3054                                 pfc_en);
3055         else
3056                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3057                                 (enum rte_eth_nb_tcs)res->num_tcs,
3058                                 pfc_en);
3059
3060
3061         if (ret != 0) {
3062                 printf("Cannot initialize network ports.\n");
3063                 return;
3064         }
3065
3066         cmd_reconfig_device_queue(port_id, 1, 1);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_config_dcb_port =
3070         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3071 cmdline_parse_token_string_t cmd_config_dcb_config =
3072         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3073 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3075 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3076         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3077 cmdline_parse_token_string_t cmd_config_dcb_vt =
3078         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3079 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3080         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3081 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3082         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3083 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3084         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3085 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3086         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3087
3088 cmdline_parse_inst_t cmd_config_dcb = {
3089         .f = cmd_config_dcb_parsed,
3090         .data = NULL,
3091         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3092         .tokens = {
3093                 (void *)&cmd_config_dcb_port,
3094                 (void *)&cmd_config_dcb_config,
3095                 (void *)&cmd_config_dcb_port_id,
3096                 (void *)&cmd_config_dcb_dcb,
3097                 (void *)&cmd_config_dcb_vt,
3098                 (void *)&cmd_config_dcb_vt_en,
3099                 (void *)&cmd_config_dcb_num_tcs,
3100                 (void *)&cmd_config_dcb_pfc,
3101                 (void *)&cmd_config_dcb_pfc_en,
3102                 NULL,
3103         },
3104 };
3105
3106 /* *** configure number of packets per burst *** */
3107 struct cmd_config_burst {
3108         cmdline_fixed_string_t port;
3109         cmdline_fixed_string_t keyword;
3110         cmdline_fixed_string_t all;
3111         cmdline_fixed_string_t name;
3112         uint16_t value;
3113 };
3114
3115 static void
3116 cmd_config_burst_parsed(void *parsed_result,
3117                         __attribute__((unused)) struct cmdline *cl,
3118                         __attribute__((unused)) void *data)
3119 {
3120         struct cmd_config_burst *res = parsed_result;
3121         struct rte_eth_dev_info dev_info;
3122         uint16_t rec_nb_pkts;
3123
3124         if (!all_ports_stopped()) {
3125                 printf("Please stop all ports first\n");
3126                 return;
3127         }
3128
3129         if (!strcmp(res->name, "burst")) {
3130                 if (res->value == 0) {
3131                         /* If user gives a value of zero, query the PMD for
3132                          * its recommended Rx burst size. Testpmd uses a single
3133                          * size for all ports, so assume all ports are the same
3134                          * NIC model and use the values from Port 0.
3135                          */
3136                         rte_eth_dev_info_get(0, &dev_info);
3137                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3138
3139                         if (rec_nb_pkts == 0) {
3140                                 printf("PMD does not recommend a burst size.\n"
3141                                         "User provided value must be between"
3142                                         " 1 and %d\n", MAX_PKT_BURST);
3143                                 return;
3144                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3145                                 printf("PMD recommended burst size of %d"
3146                                         " exceeds maximum value of %d\n",
3147                                         rec_nb_pkts, MAX_PKT_BURST);
3148                                 return;
3149                         }
3150                         printf("Using PMD-provided burst value of %d\n",
3151                                 rec_nb_pkts);
3152                         nb_pkt_per_burst = rec_nb_pkts;
3153                 } else if (res->value > MAX_PKT_BURST) {
3154                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3155                         return;
3156                 } else
3157                         nb_pkt_per_burst = res->value;
3158         } else {
3159                 printf("Unknown parameter\n");
3160                 return;
3161         }
3162
3163         init_port_config();
3164
3165         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3166 }
3167
3168 cmdline_parse_token_string_t cmd_config_burst_port =
3169         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3170 cmdline_parse_token_string_t cmd_config_burst_keyword =
3171         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3172 cmdline_parse_token_string_t cmd_config_burst_all =
3173         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3174 cmdline_parse_token_string_t cmd_config_burst_name =
3175         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3176 cmdline_parse_token_num_t cmd_config_burst_value =
3177         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3178
3179 cmdline_parse_inst_t cmd_config_burst = {
3180         .f = cmd_config_burst_parsed,
3181         .data = NULL,
3182         .help_str = "port config all burst <value>",
3183         .tokens = {
3184                 (void *)&cmd_config_burst_port,
3185                 (void *)&cmd_config_burst_keyword,
3186                 (void *)&cmd_config_burst_all,
3187                 (void *)&cmd_config_burst_name,
3188                 (void *)&cmd_config_burst_value,
3189                 NULL,
3190         },
3191 };
3192
3193 /* *** configure rx/tx queues *** */
3194 struct cmd_config_thresh {
3195         cmdline_fixed_string_t port;
3196         cmdline_fixed_string_t keyword;
3197         cmdline_fixed_string_t all;
3198         cmdline_fixed_string_t name;
3199         uint8_t value;
3200 };
3201
3202 static void
3203 cmd_config_thresh_parsed(void *parsed_result,
3204                         __attribute__((unused)) struct cmdline *cl,
3205                         __attribute__((unused)) void *data)
3206 {
3207         struct cmd_config_thresh *res = parsed_result;
3208
3209         if (!all_ports_stopped()) {
3210                 printf("Please stop all ports first\n");
3211                 return;
3212         }
3213
3214         if (!strcmp(res->name, "txpt"))
3215                 tx_pthresh = res->value;
3216         else if(!strcmp(res->name, "txht"))
3217                 tx_hthresh = res->value;
3218         else if(!strcmp(res->name, "txwt"))
3219                 tx_wthresh = res->value;
3220         else if(!strcmp(res->name, "rxpt"))
3221                 rx_pthresh = res->value;
3222         else if(!strcmp(res->name, "rxht"))
3223                 rx_hthresh = res->value;
3224         else if(!strcmp(res->name, "rxwt"))
3225                 rx_wthresh = res->value;
3226         else {
3227                 printf("Unknown parameter\n");
3228                 return;
3229         }
3230
3231         init_port_config();
3232
3233         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3234 }
3235
3236 cmdline_parse_token_string_t cmd_config_thresh_port =
3237         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3238 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3239         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3240 cmdline_parse_token_string_t cmd_config_thresh_all =
3241         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3242 cmdline_parse_token_string_t cmd_config_thresh_name =
3243         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3244                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3245 cmdline_parse_token_num_t cmd_config_thresh_value =
3246         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3247
3248 cmdline_parse_inst_t cmd_config_thresh = {
3249         .f = cmd_config_thresh_parsed,
3250         .data = NULL,
3251         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3252         .tokens = {
3253                 (void *)&cmd_config_thresh_port,
3254                 (void *)&cmd_config_thresh_keyword,
3255                 (void *)&cmd_config_thresh_all,
3256                 (void *)&cmd_config_thresh_name,
3257                 (void *)&cmd_config_thresh_value,
3258                 NULL,
3259         },
3260 };
3261
3262 /* *** configure free/rs threshold *** */
3263 struct cmd_config_threshold {
3264         cmdline_fixed_string_t port;
3265         cmdline_fixed_string_t keyword;
3266         cmdline_fixed_string_t all;
3267         cmdline_fixed_string_t name;
3268         uint16_t value;
3269 };
3270
3271 static void
3272 cmd_config_threshold_parsed(void *parsed_result,
3273                         __attribute__((unused)) struct cmdline *cl,
3274                         __attribute__((unused)) void *data)
3275 {
3276         struct cmd_config_threshold *res = parsed_result;
3277
3278         if (!all_ports_stopped()) {
3279                 printf("Please stop all ports first\n");
3280                 return;
3281         }
3282
3283         if (!strcmp(res->name, "txfreet"))
3284                 tx_free_thresh = res->value;
3285         else if (!strcmp(res->name, "txrst"))
3286                 tx_rs_thresh = res->value;
3287         else if (!strcmp(res->name, "rxfreet"))
3288                 rx_free_thresh = res->value;
3289         else {
3290                 printf("Unknown parameter\n");
3291                 return;
3292         }
3293
3294         init_port_config();
3295
3296         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3297 }
3298
3299 cmdline_parse_token_string_t cmd_config_threshold_port =
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3301 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3302         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3303                                                                 "config");
3304 cmdline_parse_token_string_t cmd_config_threshold_all =
3305         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3306 cmdline_parse_token_string_t cmd_config_threshold_name =
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3308                                                 "txfreet#txrst#rxfreet");
3309 cmdline_parse_token_num_t cmd_config_threshold_value =
3310         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3311
3312 cmdline_parse_inst_t cmd_config_threshold = {
3313         .f = cmd_config_threshold_parsed,
3314         .data = NULL,
3315         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3316         .tokens = {
3317                 (void *)&cmd_config_threshold_port,
3318                 (void *)&cmd_config_threshold_keyword,
3319                 (void *)&cmd_config_threshold_all,
3320                 (void *)&cmd_config_threshold_name,
3321                 (void *)&cmd_config_threshold_value,
3322                 NULL,
3323         },
3324 };
3325
3326 /* *** stop *** */
3327 struct cmd_stop_result {
3328         cmdline_fixed_string_t stop;
3329 };
3330
3331 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3332                             __attribute__((unused)) struct cmdline *cl,
3333                             __attribute__((unused)) void *data)
3334 {
3335         stop_packet_forwarding();
3336 }
3337
3338 cmdline_parse_token_string_t cmd_stop_stop =
3339         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3340
3341 cmdline_parse_inst_t cmd_stop = {
3342         .f = cmd_stop_parsed,
3343         .data = NULL,
3344         .help_str = "stop: Stop packet forwarding",
3345         .tokens = {
3346                 (void *)&cmd_stop_stop,
3347                 NULL,
3348         },
3349 };
3350
3351 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3352
3353 unsigned int
3354 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3355                 unsigned int *parsed_items, int check_unique_values)
3356 {
3357         unsigned int nb_item;
3358         unsigned int value;
3359         unsigned int i;
3360         unsigned int j;
3361         int value_ok;
3362         char c;
3363
3364         /*
3365          * First parse all items in the list and store their value.
3366          */
3367         value = 0;
3368         nb_item = 0;
3369         value_ok = 0;
3370         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3371                 c = str[i];
3372                 if ((c >= '0') && (c <= '9')) {
3373                         value = (unsigned int) (value * 10 + (c - '0'));
3374                         value_ok = 1;
3375                         continue;
3376                 }
3377                 if (c != ',') {
3378                         printf("character %c is not a decimal digit\n", c);
3379                         return 0;
3380                 }
3381                 if (! value_ok) {
3382                         printf("No valid value before comma\n");
3383                         return 0;
3384                 }
3385                 if (nb_item < max_items) {
3386                         parsed_items[nb_item] = value;
3387                         value_ok = 0;
3388                         value = 0;
3389                 }
3390                 nb_item++;
3391         }
3392         if (nb_item >= max_items) {
3393                 printf("Number of %s = %u > %u (maximum items)\n",
3394                        item_name, nb_item + 1, max_items);
3395                 return 0;
3396         }
3397         parsed_items[nb_item++] = value;
3398         if (! check_unique_values)
3399                 return nb_item;
3400
3401         /*
3402          * Then, check that all values in the list are differents.
3403          * No optimization here...
3404          */
3405         for (i = 0; i < nb_item; i++) {
3406                 for (j = i + 1; j < nb_item; j++) {
3407                         if (parsed_items[j] == parsed_items[i]) {
3408                                 printf("duplicated %s %u at index %u and %u\n",
3409                                        item_name, parsed_items[i], i, j);
3410                                 return 0;
3411                         }
3412                 }
3413         }
3414         return nb_item;
3415 }
3416
3417 struct cmd_set_list_result {
3418         cmdline_fixed_string_t cmd_keyword;
3419         cmdline_fixed_string_t list_name;
3420         cmdline_fixed_string_t list_of_items;
3421 };
3422
3423 static void cmd_set_list_parsed(void *parsed_result,
3424                                 __attribute__((unused)) struct cmdline *cl,
3425                                 __attribute__((unused)) void *data)
3426 {
3427         struct cmd_set_list_result *res;
3428         union {
3429                 unsigned int lcorelist[RTE_MAX_LCORE];
3430                 unsigned int portlist[RTE_MAX_ETHPORTS];
3431         } parsed_items;
3432         unsigned int nb_item;
3433
3434         if (test_done == 0) {
3435                 printf("Please stop forwarding first\n");
3436                 return;
3437         }
3438
3439         res = parsed_result;
3440         if (!strcmp(res->list_name, "corelist")) {
3441                 nb_item = parse_item_list(res->list_of_items, "core",
3442                                           RTE_MAX_LCORE,
3443                                           parsed_items.lcorelist, 1);
3444                 if (nb_item > 0) {
3445                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3446                         fwd_config_setup();
3447                 }
3448                 return;
3449         }
3450         if (!strcmp(res->list_name, "portlist")) {
3451                 nb_item = parse_item_list(res->list_of_items, "port",
3452                                           RTE_MAX_ETHPORTS,
3453                                           parsed_items.portlist, 1);
3454                 if (nb_item > 0) {
3455                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3456                         fwd_config_setup();
3457                 }
3458         }
3459 }
3460
3461 cmdline_parse_token_string_t cmd_set_list_keyword =
3462         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3463                                  "set");
3464 cmdline_parse_token_string_t cmd_set_list_name =
3465         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3466                                  "corelist#portlist");
3467 cmdline_parse_token_string_t cmd_set_list_of_items =
3468         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3469                                  NULL);
3470
3471 cmdline_parse_inst_t cmd_set_fwd_list = {
3472         .f = cmd_set_list_parsed,
3473         .data = NULL,
3474         .help_str = "set corelist|portlist <list0[,list1]*>",
3475         .tokens = {
3476                 (void *)&cmd_set_list_keyword,
3477                 (void *)&cmd_set_list_name,
3478                 (void *)&cmd_set_list_of_items,
3479                 NULL,
3480         },
3481 };
3482
3483 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3484
3485 struct cmd_setmask_result {
3486         cmdline_fixed_string_t set;
3487         cmdline_fixed_string_t mask;
3488         uint64_t hexavalue;
3489 };
3490
3491 static void cmd_set_mask_parsed(void *parsed_result,
3492                                 __attribute__((unused)) struct cmdline *cl,
3493                                 __attribute__((unused)) void *data)
3494 {
3495         struct cmd_setmask_result *res = parsed_result;
3496
3497         if (test_done == 0) {
3498                 printf("Please stop forwarding first\n");
3499                 return;
3500         }
3501         if (!strcmp(res->mask, "coremask")) {
3502                 set_fwd_lcores_mask(res->hexavalue);
3503                 fwd_config_setup();
3504         } else if (!strcmp(res->mask, "portmask")) {
3505                 set_fwd_ports_mask(res->hexavalue);
3506                 fwd_config_setup();
3507         }
3508 }
3509
3510 cmdline_parse_token_string_t cmd_setmask_set =
3511         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3512 cmdline_parse_token_string_t cmd_setmask_mask =
3513         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3514                                  "coremask#portmask");
3515 cmdline_parse_token_num_t cmd_setmask_value =
3516         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3517
3518 cmdline_parse_inst_t cmd_set_fwd_mask = {
3519         .f = cmd_set_mask_parsed,
3520         .data = NULL,
3521         .help_str = "set coremask|portmask <hexadecimal value>",
3522         .tokens = {
3523                 (void *)&cmd_setmask_set,
3524                 (void *)&cmd_setmask_mask,
3525                 (void *)&cmd_setmask_value,
3526                 NULL,
3527         },
3528 };
3529
3530 /*
3531  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3532  */
3533 struct cmd_set_result {
3534         cmdline_fixed_string_t set;
3535         cmdline_fixed_string_t what;
3536         uint16_t value;
3537 };
3538
3539 static void cmd_set_parsed(void *parsed_result,
3540                            __attribute__((unused)) struct cmdline *cl,
3541                            __attribute__((unused)) void *data)
3542 {
3543         struct cmd_set_result *res = parsed_result;
3544         if (!strcmp(res->what, "nbport")) {
3545                 set_fwd_ports_number(res->value);
3546                 fwd_config_setup();
3547         } else if (!strcmp(res->what, "nbcore")) {
3548                 set_fwd_lcores_number(res->value);
3549                 fwd_config_setup();
3550         } else if (!strcmp(res->what, "burst"))
3551                 set_nb_pkt_per_burst(res->value);
3552         else if (!strcmp(res->what, "verbose"))
3553                 set_verbose_level(res->value);
3554 }
3555
3556 cmdline_parse_token_string_t cmd_set_set =
3557         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3558 cmdline_parse_token_string_t cmd_set_what =
3559         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3560                                  "nbport#nbcore#burst#verbose");
3561 cmdline_parse_token_num_t cmd_set_value =
3562         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3563
3564 cmdline_parse_inst_t cmd_set_numbers = {
3565         .f = cmd_set_parsed,
3566         .data = NULL,
3567         .help_str = "set nbport|nbcore|burst|verbose <value>",
3568         .tokens = {
3569                 (void *)&cmd_set_set,
3570                 (void *)&cmd_set_what,
3571                 (void *)&cmd_set_value,
3572                 NULL,
3573         },
3574 };
3575
3576 /* *** SET LOG LEVEL CONFIGURATION *** */
3577
3578 struct cmd_set_log_result {
3579         cmdline_fixed_string_t set;
3580         cmdline_fixed_string_t log;
3581         cmdline_fixed_string_t type;
3582         uint32_t level;
3583 };
3584
3585 static void
3586 cmd_set_log_parsed(void *parsed_result,
3587                    __attribute__((unused)) struct cmdline *cl,
3588                    __attribute__((unused)) void *data)
3589 {
3590         struct cmd_set_log_result *res;
3591         int ret;
3592
3593         res = parsed_result;
3594         if (!strcmp(res->type, "global"))
3595                 rte_log_set_global_level(res->level);
3596         else {
3597                 ret = rte_log_set_level_regexp(res->type, res->level);
3598                 if (ret < 0)
3599                         printf("Unable to set log level\n");
3600         }
3601 }
3602
3603 cmdline_parse_token_string_t cmd_set_log_set =
3604         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3605 cmdline_parse_token_string_t cmd_set_log_log =
3606         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3607 cmdline_parse_token_string_t cmd_set_log_type =
3608         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3609 cmdline_parse_token_num_t cmd_set_log_level =
3610         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3611
3612 cmdline_parse_inst_t cmd_set_log = {
3613         .f = cmd_set_log_parsed,
3614         .data = NULL,
3615         .help_str = "set log global|<type> <level>",
3616         .tokens = {
3617                 (void *)&cmd_set_log_set,
3618                 (void *)&cmd_set_log_log,
3619                 (void *)&cmd_set_log_type,
3620                 (void *)&cmd_set_log_level,
3621                 NULL,
3622         },
3623 };
3624
3625 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3626
3627 struct cmd_set_txpkts_result {
3628         cmdline_fixed_string_t cmd_keyword;
3629         cmdline_fixed_string_t txpkts;
3630         cmdline_fixed_string_t seg_lengths;
3631 };
3632
3633 static void
3634 cmd_set_txpkts_parsed(void *parsed_result,
3635                       __attribute__((unused)) struct cmdline *cl,
3636                       __attribute__((unused)) void *data)
3637 {
3638         struct cmd_set_txpkts_result *res;
3639         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3640         unsigned int nb_segs;
3641
3642         res = parsed_result;
3643         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3644                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3645         if (nb_segs > 0)
3646                 set_tx_pkt_segments(seg_lengths, nb_segs);
3647 }
3648
3649 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3650         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3651                                  cmd_keyword, "set");
3652 cmdline_parse_token_string_t cmd_set_txpkts_name =
3653         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3654                                  txpkts, "txpkts");
3655 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3656         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3657                                  seg_lengths, NULL);
3658
3659 cmdline_parse_inst_t cmd_set_txpkts = {
3660         .f = cmd_set_txpkts_parsed,
3661         .data = NULL,
3662         .help_str = "set txpkts <len0[,len1]*>",
3663         .tokens = {
3664                 (void *)&cmd_set_txpkts_keyword,
3665                 (void *)&cmd_set_txpkts_name,
3666                 (void *)&cmd_set_txpkts_lengths,
3667                 NULL,
3668         },
3669 };
3670
3671 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3672
3673 struct cmd_set_txsplit_result {
3674         cmdline_fixed_string_t cmd_keyword;
3675         cmdline_fixed_string_t txsplit;
3676         cmdline_fixed_string_t mode;
3677 };
3678
3679 static void
3680 cmd_set_txsplit_parsed(void *parsed_result,
3681                       __attribute__((unused)) struct cmdline *cl,
3682                       __attribute__((unused)) void *data)
3683 {
3684         struct cmd_set_txsplit_result *res;
3685
3686         res = parsed_result;
3687         set_tx_pkt_split(res->mode);
3688 }
3689
3690 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3691         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3692                                  cmd_keyword, "set");
3693 cmdline_parse_token_string_t cmd_set_txsplit_name =
3694         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3695                                  txsplit, "txsplit");
3696 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3697         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3698                                  mode, NULL);
3699
3700 cmdline_parse_inst_t cmd_set_txsplit = {
3701         .f = cmd_set_txsplit_parsed,
3702         .data = NULL,
3703         .help_str = "set txsplit on|off|rand",
3704         .tokens = {
3705                 (void *)&cmd_set_txsplit_keyword,
3706                 (void *)&cmd_set_txsplit_name,
3707                 (void *)&cmd_set_txsplit_mode,
3708                 NULL,
3709         },
3710 };
3711
3712 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3713 struct cmd_rx_vlan_filter_all_result {
3714         cmdline_fixed_string_t rx_vlan;
3715         cmdline_fixed_string_t what;
3716         cmdline_fixed_string_t all;
3717         portid_t port_id;
3718 };
3719
3720 static void
3721 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3722                               __attribute__((unused)) struct cmdline *cl,
3723                               __attribute__((unused)) void *data)
3724 {
3725         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3726
3727         if (!strcmp(res->what, "add"))
3728                 rx_vlan_all_filter_set(res->port_id, 1);
3729         else
3730                 rx_vlan_all_filter_set(res->port_id, 0);
3731 }
3732
3733 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3734         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3735                                  rx_vlan, "rx_vlan");
3736 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3737         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3738                                  what, "add#rm");
3739 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3740         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3741                                  all, "all");
3742 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3743         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3744                               port_id, UINT16);
3745
3746 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3747         .f = cmd_rx_vlan_filter_all_parsed,
3748         .data = NULL,
3749         .help_str = "rx_vlan add|rm all <port_id>: "
3750                 "Add/Remove all identifiers to/from the set of VLAN "
3751                 "identifiers filtered by a port",
3752         .tokens = {
3753                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3754                 (void *)&cmd_rx_vlan_filter_all_what,
3755                 (void *)&cmd_rx_vlan_filter_all_all,
3756                 (void *)&cmd_rx_vlan_filter_all_portid,
3757                 NULL,
3758         },
3759 };
3760
3761 /* *** VLAN OFFLOAD SET ON A PORT *** */
3762 struct cmd_vlan_offload_result {
3763         cmdline_fixed_string_t vlan;
3764         cmdline_fixed_string_t set;
3765         cmdline_fixed_string_t vlan_type;
3766         cmdline_fixed_string_t what;
3767         cmdline_fixed_string_t on;
3768         cmdline_fixed_string_t port_id;
3769 };
3770
3771 static void
3772 cmd_vlan_offload_parsed(void *parsed_result,
3773                           __attribute__((unused)) struct cmdline *cl,
3774                           __attribute__((unused)) void *data)
3775 {
3776         int on;
3777         struct cmd_vlan_offload_result *res = parsed_result;
3778         char *str;
3779         int i, len = 0;
3780         portid_t port_id = 0;
3781         unsigned int tmp;
3782
3783         str = res->port_id;
3784         len = strnlen(str, STR_TOKEN_SIZE);
3785         i = 0;
3786         /* Get port_id first */
3787         while(i < len){
3788                 if(str[i] == ',')
3789                         break;
3790
3791                 i++;
3792         }
3793         str[i]='\0';
3794         tmp = strtoul(str, NULL, 0);
3795         /* If port_id greater that what portid_t can represent, return */
3796         if(tmp >= RTE_MAX_ETHPORTS)
3797                 return;
3798         port_id = (portid_t)tmp;
3799
3800         if (!strcmp(res->on, "on"))
3801                 on = 1;
3802         else
3803                 on = 0;
3804
3805         if (!strcmp(res->what, "strip"))
3806                 rx_vlan_strip_set(port_id,  on);
3807         else if(!strcmp(res->what, "stripq")){
3808                 uint16_t queue_id = 0;
3809
3810                 /* No queue_id, return */
3811                 if(i + 1 >= len) {
3812                         printf("must specify (port,queue_id)\n");
3813                         return;
3814                 }
3815                 tmp = strtoul(str + i + 1, NULL, 0);
3816                 /* If queue_id greater that what 16-bits can represent, return */
3817                 if(tmp > 0xffff)
3818                         return;
3819
3820                 queue_id = (uint16_t)tmp;
3821                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3822         }
3823         else if (!strcmp(res->what, "filter"))
3824                 rx_vlan_filter_set(port_id, on);
3825         else
3826                 vlan_extend_set(port_id, on);
3827
3828         return;
3829 }
3830
3831 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3832         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3833                                  vlan, "vlan");
3834 cmdline_parse_token_string_t cmd_vlan_offload_set =
3835         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3836                                  set, "set");
3837 cmdline_parse_token_string_t cmd_vlan_offload_what =
3838         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3839                                  what, "strip#filter#qinq#stripq");
3840 cmdline_parse_token_string_t cmd_vlan_offload_on =
3841         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3842                               on, "on#off");
3843 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3844         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3845                               port_id, NULL);
3846
3847 cmdline_parse_inst_t cmd_vlan_offload = {
3848         .f = cmd_vlan_offload_parsed,
3849         .data = NULL,
3850         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3851                 "<port_id[,queue_id]>: "
3852                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3853         .tokens = {
3854                 (void *)&cmd_vlan_offload_vlan,
3855                 (void *)&cmd_vlan_offload_set,
3856                 (void *)&cmd_vlan_offload_what,
3857                 (void *)&cmd_vlan_offload_on,
3858                 (void *)&cmd_vlan_offload_portid,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** VLAN TPID SET ON A PORT *** */
3864 struct cmd_vlan_tpid_result {
3865         cmdline_fixed_string_t vlan;
3866         cmdline_fixed_string_t set;
3867         cmdline_fixed_string_t vlan_type;
3868         cmdline_fixed_string_t what;
3869         uint16_t tp_id;
3870         portid_t port_id;
3871 };
3872
3873 static void
3874 cmd_vlan_tpid_parsed(void *parsed_result,
3875                           __attribute__((unused)) struct cmdline *cl,
3876                           __attribute__((unused)) void *data)
3877 {
3878         struct cmd_vlan_tpid_result *res = parsed_result;
3879         enum rte_vlan_type vlan_type;
3880
3881         if (!strcmp(res->vlan_type, "inner"))
3882                 vlan_type = ETH_VLAN_TYPE_INNER;
3883         else if (!strcmp(res->vlan_type, "outer"))
3884                 vlan_type = ETH_VLAN_TYPE_OUTER;
3885         else {
3886                 printf("Unknown vlan type\n");
3887                 return;
3888         }
3889         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3890 }
3891
3892 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3893         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3894                                  vlan, "vlan");
3895 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3896         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3897                                  set, "set");
3898 cmdline_parse_token_string_t cmd_vlan_type =
3899         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3900                                  vlan_type, "inner#outer");
3901 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3902         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3903                                  what, "tpid");
3904 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3905         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3906                               tp_id, UINT16);
3907 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3908         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3909                               port_id, UINT16);
3910
3911 cmdline_parse_inst_t cmd_vlan_tpid = {
3912         .f = cmd_vlan_tpid_parsed,
3913         .data = NULL,
3914         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3915                 "Set the VLAN Ether type",
3916         .tokens = {
3917                 (void *)&cmd_vlan_tpid_vlan,
3918                 (void *)&cmd_vlan_tpid_set,
3919                 (void *)&cmd_vlan_type,
3920                 (void *)&cmd_vlan_tpid_what,
3921                 (void *)&cmd_vlan_tpid_tpid,
3922                 (void *)&cmd_vlan_tpid_portid,
3923                 NULL,
3924         },
3925 };
3926
3927 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3928 struct cmd_rx_vlan_filter_result {
3929         cmdline_fixed_string_t rx_vlan;
3930         cmdline_fixed_string_t what;
3931         uint16_t vlan_id;
3932         portid_t port_id;
3933 };
3934
3935 static void
3936 cmd_rx_vlan_filter_parsed(void *parsed_result,
3937                           __attribute__((unused)) struct cmdline *cl,
3938                           __attribute__((unused)) void *data)
3939 {
3940         struct cmd_rx_vlan_filter_result *res = parsed_result;
3941
3942         if (!strcmp(res->what, "add"))
3943                 rx_vft_set(res->port_id, res->vlan_id, 1);
3944         else
3945                 rx_vft_set(res->port_id, res->vlan_id, 0);
3946 }
3947
3948 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3949         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3950                                  rx_vlan, "rx_vlan");
3951 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3952         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3953                                  what, "add#rm");
3954 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3955         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3956                               vlan_id, UINT16);
3957 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3958         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3959                               port_id, UINT16);
3960
3961 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3962         .f = cmd_rx_vlan_filter_parsed,
3963         .data = NULL,
3964         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3965                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3966                 "identifiers filtered by a port",
3967         .tokens = {
3968                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3969                 (void *)&cmd_rx_vlan_filter_what,
3970                 (void *)&cmd_rx_vlan_filter_vlanid,
3971                 (void *)&cmd_rx_vlan_filter_portid,
3972                 NULL,
3973         },
3974 };
3975
3976 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3977 struct cmd_tx_vlan_set_result {
3978         cmdline_fixed_string_t tx_vlan;
3979         cmdline_fixed_string_t set;
3980         portid_t port_id;
3981         uint16_t vlan_id;
3982 };
3983
3984 static void
3985 cmd_tx_vlan_set_parsed(void *parsed_result,
3986                        __attribute__((unused)) struct cmdline *cl,
3987                        __attribute__((unused)) void *data)
3988 {
3989         struct cmd_tx_vlan_set_result *res = parsed_result;
3990
3991         if (!port_is_stopped(res->port_id)) {
3992                 printf("Please stop port %d first\n", res->port_id);
3993                 return;
3994         }
3995
3996         tx_vlan_set(res->port_id, res->vlan_id);
3997
3998         cmd_reconfig_device_queue(res->port_id, 1, 1);
3999 }
4000
4001 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4002         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4003                                  tx_vlan, "tx_vlan");
4004 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4005         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4006                                  set, "set");
4007 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4008         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4009                               port_id, UINT16);
4010 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4011         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4012                               vlan_id, UINT16);
4013
4014 cmdline_parse_inst_t cmd_tx_vlan_set = {
4015         .f = cmd_tx_vlan_set_parsed,
4016         .data = NULL,
4017         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4018                 "Enable hardware insertion of a single VLAN header "
4019                 "with a given TAG Identifier in packets sent on a port",
4020         .tokens = {
4021                 (void *)&cmd_tx_vlan_set_tx_vlan,
4022                 (void *)&cmd_tx_vlan_set_set,
4023                 (void *)&cmd_tx_vlan_set_portid,
4024                 (void *)&cmd_tx_vlan_set_vlanid,
4025                 NULL,
4026         },
4027 };
4028
4029 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4030 struct cmd_tx_vlan_set_qinq_result {
4031         cmdline_fixed_string_t tx_vlan;
4032         cmdline_fixed_string_t set;
4033         portid_t port_id;
4034         uint16_t vlan_id;
4035         uint16_t vlan_id_outer;
4036 };
4037
4038 static void
4039 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4040                             __attribute__((unused)) struct cmdline *cl,
4041                             __attribute__((unused)) void *data)
4042 {
4043         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4044
4045         if (!port_is_stopped(res->port_id)) {
4046                 printf("Please stop port %d first\n", res->port_id);
4047                 return;
4048         }
4049
4050         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4051
4052         cmd_reconfig_device_queue(res->port_id, 1, 1);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4056         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4057                 tx_vlan, "tx_vlan");
4058 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4059         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4060                 set, "set");
4061 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4063                 port_id, UINT16);
4064 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4066                 vlan_id, UINT16);
4067 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4068         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4069                 vlan_id_outer, UINT16);
4070
4071 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4072         .f = cmd_tx_vlan_set_qinq_parsed,
4073         .data = NULL,
4074         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4075                 "Enable hardware insertion of double VLAN header "
4076                 "with given TAG Identifiers in packets sent on a port",
4077         .tokens = {
4078                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4079                 (void *)&cmd_tx_vlan_set_qinq_set,
4080                 (void *)&cmd_tx_vlan_set_qinq_portid,
4081                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4082                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4083                 NULL,
4084         },
4085 };
4086
4087 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4088 struct cmd_tx_vlan_set_pvid_result {
4089         cmdline_fixed_string_t tx_vlan;
4090         cmdline_fixed_string_t set;
4091         cmdline_fixed_string_t pvid;
4092         portid_t port_id;
4093         uint16_t vlan_id;
4094         cmdline_fixed_string_t mode;
4095 };
4096
4097 static void
4098 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4099                             __attribute__((unused)) struct cmdline *cl,
4100                             __attribute__((unused)) void *data)
4101 {
4102         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4103
4104         if (strcmp(res->mode, "on") == 0)
4105                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4106         else
4107                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4111         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4112                                  tx_vlan, "tx_vlan");
4113 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4115                                  set, "set");
4116 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4117         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4118                                  pvid, "pvid");
4119 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4120         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4121                              port_id, UINT16);
4122 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4123         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4124                               vlan_id, UINT16);
4125 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4126         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4127                                  mode, "on#off");
4128
4129 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4130         .f = cmd_tx_vlan_set_pvid_parsed,
4131         .data = NULL,
4132         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4133         .tokens = {
4134                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4135                 (void *)&cmd_tx_vlan_set_pvid_set,
4136                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4137                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4138                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4139                 (void *)&cmd_tx_vlan_set_pvid_mode,
4140                 NULL,
4141         },
4142 };
4143
4144 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4145 struct cmd_tx_vlan_reset_result {
4146         cmdline_fixed_string_t tx_vlan;
4147         cmdline_fixed_string_t reset;
4148         portid_t port_id;
4149 };
4150
4151 static void
4152 cmd_tx_vlan_reset_parsed(void *parsed_result,
4153                          __attribute__((unused)) struct cmdline *cl,
4154                          __attribute__((unused)) void *data)
4155 {
4156         struct cmd_tx_vlan_reset_result *res = parsed_result;
4157
4158         if (!port_is_stopped(res->port_id)) {
4159                 printf("Please stop port %d first\n", res->port_id);
4160                 return;
4161         }
4162
4163         tx_vlan_reset(res->port_id);
4164
4165         cmd_reconfig_device_queue(res->port_id, 1, 1);
4166 }
4167
4168 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4169         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4170                                  tx_vlan, "tx_vlan");
4171 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4172         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4173                                  reset, "reset");
4174 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4175         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4176                               port_id, UINT16);
4177
4178 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4179         .f = cmd_tx_vlan_reset_parsed,
4180         .data = NULL,
4181         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4182                 "VLAN header in packets sent on a port",
4183         .tokens = {
4184                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4185                 (void *)&cmd_tx_vlan_reset_reset,
4186                 (void *)&cmd_tx_vlan_reset_portid,
4187                 NULL,
4188         },
4189 };
4190
4191
4192 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4193 struct cmd_csum_result {
4194         cmdline_fixed_string_t csum;
4195         cmdline_fixed_string_t mode;
4196         cmdline_fixed_string_t proto;
4197         cmdline_fixed_string_t hwsw;
4198         portid_t port_id;
4199 };
4200
4201 static void
4202 csum_show(int port_id)
4203 {
4204         struct rte_eth_dev_info dev_info;
4205         uint64_t tx_offloads;
4206
4207         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4208         printf("Parse tunnel is %s\n",
4209                 (ports[port_id].parse_tunnel) ? "on" : "off");
4210         printf("IP checksum offload is %s\n",
4211                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4212         printf("UDP checksum offload is %s\n",
4213                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4214         printf("TCP checksum offload is %s\n",
4215                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4216         printf("SCTP checksum offload is %s\n",
4217                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4218         printf("Outer-Ip checksum offload is %s\n",
4219                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4220         printf("Outer-Udp checksum offload is %s\n",
4221                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4222
4223         /* display warnings if configuration is not supported by the NIC */
4224         rte_eth_dev_info_get(port_id, &dev_info);
4225         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4226                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4227                 printf("Warning: hardware IP checksum enabled but not "
4228                         "supported by port %d\n", port_id);
4229         }
4230         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4231                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4232                 printf("Warning: hardware UDP checksum enabled but not "
4233                         "supported by port %d\n", port_id);
4234         }
4235         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4236                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4237                 printf("Warning: hardware TCP checksum enabled but not "
4238                         "supported by port %d\n", port_id);
4239         }
4240         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4241                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4242                 printf("Warning: hardware SCTP checksum enabled but not "
4243                         "supported by port %d\n", port_id);
4244         }
4245         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4246                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4247                 printf("Warning: hardware outer IP checksum enabled but not "
4248                         "supported by port %d\n", port_id);
4249         }
4250         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4251                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4252                         == 0) {
4253                 printf("Warning: hardware outer UDP checksum enabled but not "
4254                         "supported by port %d\n", port_id);
4255         }
4256 }
4257
4258 static void
4259 cmd_csum_parsed(void *parsed_result,
4260                        __attribute__((unused)) struct cmdline *cl,
4261                        __attribute__((unused)) void *data)
4262 {
4263         struct cmd_csum_result *res = parsed_result;
4264         int hw = 0;
4265         uint64_t csum_offloads = 0;
4266         struct rte_eth_dev_info dev_info;
4267
4268         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4269                 printf("invalid port %d\n", res->port_id);
4270                 return;
4271         }
4272         if (!port_is_stopped(res->port_id)) {
4273                 printf("Please stop port %d first\n", res->port_id);
4274                 return;
4275         }
4276
4277         rte_eth_dev_info_get(res->port_id, &dev_info);
4278         if (!strcmp(res->mode, "set")) {
4279
4280                 if (!strcmp(res->hwsw, "hw"))
4281                         hw = 1;
4282
4283                 if (!strcmp(res->proto, "ip")) {
4284                         if (hw == 0 || (dev_info.tx_offload_capa &
4285                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4286                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4287                         } else {
4288                                 printf("IP checksum offload is not supported "
4289                                        "by port %u\n", res->port_id);
4290                         }
4291                 } else if (!strcmp(res->proto, "udp")) {
4292                         if (hw == 0 || (dev_info.tx_offload_capa &
4293                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4294                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4295                         } else {
4296                                 printf("UDP checksum offload is not supported "
4297                                        "by port %u\n", res->port_id);
4298                         }
4299                 } else if (!strcmp(res->proto, "tcp")) {
4300                         if (hw == 0 || (dev_info.tx_offload_capa &
4301                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4302                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4303                         } else {
4304                                 printf("TCP checksum offload is not supported "
4305                                        "by port %u\n", res->port_id);
4306                         }
4307                 } else if (!strcmp(res->proto, "sctp")) {
4308                         if (hw == 0 || (dev_info.tx_offload_capa &
4309                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4310                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4311                         } else {
4312                                 printf("SCTP checksum offload is not supported "
4313                                        "by port %u\n", res->port_id);
4314                         }
4315                 } else if (!strcmp(res->proto, "outer-ip")) {
4316                         if (hw == 0 || (dev_info.tx_offload_capa &
4317                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4318                                 csum_offloads |=
4319                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4320                         } else {
4321                                 printf("Outer IP checksum offload is not "
4322                                        "supported by port %u\n", res->port_id);
4323                         }
4324                 } else if (!strcmp(res->proto, "outer-udp")) {
4325                         if (hw == 0 || (dev_info.tx_offload_capa &
4326                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4327                                 csum_offloads |=
4328                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4329                         } else {
4330                                 printf("Outer UDP checksum offload is not "
4331                                        "supported by port %u\n", res->port_id);
4332                         }
4333                 }
4334
4335                 if (hw) {
4336                         ports[res->port_id].dev_conf.txmode.offloads |=
4337                                                         csum_offloads;
4338                 } else {
4339                         ports[res->port_id].dev_conf.txmode.offloads &=
4340                                                         (~csum_offloads);
4341                 }
4342         }
4343         csum_show(res->port_id);
4344
4345         cmd_reconfig_device_queue(res->port_id, 1, 1);
4346 }
4347
4348 cmdline_parse_token_string_t cmd_csum_csum =
4349         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4350                                 csum, "csum");
4351 cmdline_parse_token_string_t cmd_csum_mode =
4352         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4353                                 mode, "set");
4354 cmdline_parse_token_string_t cmd_csum_proto =
4355         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4356                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4357 cmdline_parse_token_string_t cmd_csum_hwsw =
4358         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4359                                 hwsw, "hw#sw");
4360 cmdline_parse_token_num_t cmd_csum_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4362                                 port_id, UINT16);
4363
4364 cmdline_parse_inst_t cmd_csum_set = {
4365         .f = cmd_csum_parsed,
4366         .data = NULL,
4367         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4368                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4369                 "using csum forward engine",
4370         .tokens = {
4371                 (void *)&cmd_csum_csum,
4372                 (void *)&cmd_csum_mode,
4373                 (void *)&cmd_csum_proto,
4374                 (void *)&cmd_csum_hwsw,
4375                 (void *)&cmd_csum_portid,
4376                 NULL,
4377         },
4378 };
4379
4380 cmdline_parse_token_string_t cmd_csum_mode_show =
4381         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4382                                 mode, "show");
4383
4384 cmdline_parse_inst_t cmd_csum_show = {
4385         .f = cmd_csum_parsed,
4386         .data = NULL,
4387         .help_str = "csum show <port_id>: Show checksum offload configuration",
4388         .tokens = {
4389                 (void *)&cmd_csum_csum,
4390                 (void *)&cmd_csum_mode_show,
4391                 (void *)&cmd_csum_portid,
4392                 NULL,
4393         },
4394 };
4395
4396 /* Enable/disable tunnel parsing */
4397 struct cmd_csum_tunnel_result {
4398         cmdline_fixed_string_t csum;
4399         cmdline_fixed_string_t parse;
4400         cmdline_fixed_string_t onoff;
4401         portid_t port_id;
4402 };
4403
4404 static void
4405 cmd_csum_tunnel_parsed(void *parsed_result,
4406                        __attribute__((unused)) struct cmdline *cl,
4407                        __attribute__((unused)) void *data)
4408 {
4409         struct cmd_csum_tunnel_result *res = parsed_result;
4410
4411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4412                 return;
4413
4414         if (!strcmp(res->onoff, "on"))
4415                 ports[res->port_id].parse_tunnel = 1;
4416         else
4417                 ports[res->port_id].parse_tunnel = 0;
4418
4419         csum_show(res->port_id);
4420 }
4421
4422 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4423         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4424                                 csum, "csum");
4425 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4426         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4427                                 parse, "parse-tunnel");
4428 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4429         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4430                                 onoff, "on#off");
4431 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4432         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4433                                 port_id, UINT16);
4434
4435 cmdline_parse_inst_t cmd_csum_tunnel = {
4436         .f = cmd_csum_tunnel_parsed,
4437         .data = NULL,
4438         .help_str = "csum parse-tunnel on|off <port_id>: "
4439                 "Enable/Disable parsing of tunnels for csum engine",
4440         .tokens = {
4441                 (void *)&cmd_csum_tunnel_csum,
4442                 (void *)&cmd_csum_tunnel_parse,
4443                 (void *)&cmd_csum_tunnel_onoff,
4444                 (void *)&cmd_csum_tunnel_portid,
4445                 NULL,
4446         },
4447 };
4448
4449 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4450 struct cmd_tso_set_result {
4451         cmdline_fixed_string_t tso;
4452         cmdline_fixed_string_t mode;
4453         uint16_t tso_segsz;
4454         portid_t port_id;
4455 };
4456
4457 static void
4458 cmd_tso_set_parsed(void *parsed_result,
4459                        __attribute__((unused)) struct cmdline *cl,
4460                        __attribute__((unused)) void *data)
4461 {
4462         struct cmd_tso_set_result *res = parsed_result;
4463         struct rte_eth_dev_info dev_info;
4464
4465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4466                 return;
4467         if (!port_is_stopped(res->port_id)) {
4468                 printf("Please stop port %d first\n", res->port_id);
4469                 return;
4470         }
4471
4472         if (!strcmp(res->mode, "set"))
4473                 ports[res->port_id].tso_segsz = res->tso_segsz;
4474
4475         rte_eth_dev_info_get(res->port_id, &dev_info);
4476         if ((ports[res->port_id].tso_segsz != 0) &&
4477                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4478                 printf("Error: TSO is not supported by port %d\n",
4479                        res->port_id);
4480                 return;
4481         }
4482
4483         if (ports[res->port_id].tso_segsz == 0) {
4484                 ports[res->port_id].dev_conf.txmode.offloads &=
4485                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4486                 printf("TSO for non-tunneled packets is disabled\n");
4487         } else {
4488                 ports[res->port_id].dev_conf.txmode.offloads |=
4489                                                 DEV_TX_OFFLOAD_TCP_TSO;
4490                 printf("TSO segment size for non-tunneled packets is %d\n",
4491                         ports[res->port_id].tso_segsz);
4492         }
4493
4494         /* display warnings if configuration is not supported by the NIC */
4495         rte_eth_dev_info_get(res->port_id, &dev_info);
4496         if ((ports[res->port_id].tso_segsz != 0) &&
4497                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4498                 printf("Warning: TSO enabled but not "
4499                         "supported by port %d\n", res->port_id);
4500         }
4501
4502         cmd_reconfig_device_queue(res->port_id, 1, 1);
4503 }
4504
4505 cmdline_parse_token_string_t cmd_tso_set_tso =
4506         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4507                                 tso, "tso");
4508 cmdline_parse_token_string_t cmd_tso_set_mode =
4509         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4510                                 mode, "set");
4511 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4512         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4513                                 tso_segsz, UINT16);
4514 cmdline_parse_token_num_t cmd_tso_set_portid =
4515         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4516                                 port_id, UINT16);
4517
4518 cmdline_parse_inst_t cmd_tso_set = {
4519         .f = cmd_tso_set_parsed,
4520         .data = NULL,
4521         .help_str = "tso set <tso_segsz> <port_id>: "
4522                 "Set TSO segment size of non-tunneled packets for csum engine "
4523                 "(0 to disable)",
4524         .tokens = {
4525                 (void *)&cmd_tso_set_tso,
4526                 (void *)&cmd_tso_set_mode,
4527                 (void *)&cmd_tso_set_tso_segsz,
4528                 (void *)&cmd_tso_set_portid,
4529                 NULL,
4530         },
4531 };
4532
4533 cmdline_parse_token_string_t cmd_tso_show_mode =
4534         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4535                                 mode, "show");
4536
4537
4538 cmdline_parse_inst_t cmd_tso_show = {
4539         .f = cmd_tso_set_parsed,
4540         .data = NULL,
4541         .help_str = "tso show <port_id>: "
4542                 "Show TSO segment size of non-tunneled packets for csum engine",
4543         .tokens = {
4544                 (void *)&cmd_tso_set_tso,
4545                 (void *)&cmd_tso_show_mode,
4546                 (void *)&cmd_tso_set_portid,
4547                 NULL,
4548         },
4549 };
4550
4551 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4552 struct cmd_tunnel_tso_set_result {
4553         cmdline_fixed_string_t tso;
4554         cmdline_fixed_string_t mode;
4555         uint16_t tso_segsz;
4556         portid_t port_id;
4557 };
4558
4559 static struct rte_eth_dev_info
4560 check_tunnel_tso_nic_support(portid_t port_id)
4561 {
4562         struct rte_eth_dev_info dev_info;
4563
4564         rte_eth_dev_info_get(port_id, &dev_info);
4565         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4566                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4567                        "not enabled for port %d\n", port_id);
4568         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4569                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4570                        "not enabled for port %d\n", port_id);
4571         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4572                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4573                        "not enabled for port %d\n", port_id);
4574         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4575                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4576                        "not enabled for port %d\n", port_id);
4577         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4578                 printf("Warning: IP TUNNEL TSO not supported therefore "
4579                        "not enabled for port %d\n", port_id);
4580         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4581                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4582                        "not enabled for port %d\n", port_id);
4583         return dev_info;
4584 }
4585
4586 static void
4587 cmd_tunnel_tso_set_parsed(void *parsed_result,
4588                           __attribute__((unused)) struct cmdline *cl,
4589                           __attribute__((unused)) void *data)
4590 {
4591         struct cmd_tunnel_tso_set_result *res = parsed_result;
4592         struct rte_eth_dev_info dev_info;
4593
4594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4595                 return;
4596         if (!port_is_stopped(res->port_id)) {
4597                 printf("Please stop port %d first\n", res->port_id);
4598                 return;
4599         }
4600
4601         if (!strcmp(res->mode, "set"))
4602                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4603
4604         dev_info = check_tunnel_tso_nic_support(res->port_id);
4605         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4606                 ports[res->port_id].dev_conf.txmode.offloads &=
4607                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4608                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4609                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4610                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4611                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4612                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4613                 printf("TSO for tunneled packets is disabled\n");
4614         } else {
4615                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4616                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4617                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4618                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4619                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4620                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4621
4622                 ports[res->port_id].dev_conf.txmode.offloads |=
4623                         (tso_offloads & dev_info.tx_offload_capa);
4624                 printf("TSO segment size for tunneled packets is %d\n",
4625                         ports[res->port_id].tunnel_tso_segsz);
4626
4627                 /* Below conditions are needed to make it work:
4628                  * (1) tunnel TSO is supported by the NIC;
4629                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4630                  * are recognized;
4631                  * (3) for tunneled pkts with outer L3 of IPv4,
4632                  * "csum set outer-ip" must be set to hw, because after tso,
4633                  * total_len of outer IP header is changed, and the checksum
4634                  * of outer IP header calculated by sw should be wrong; that
4635                  * is not necessary for IPv6 tunneled pkts because there's no
4636                  * checksum in IP header anymore.
4637                  */
4638
4639                 if (!ports[res->port_id].parse_tunnel)
4640                         printf("Warning: csum parse_tunnel must be set "
4641                                 "so that tunneled packets are recognized\n");
4642                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4643                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4644                         printf("Warning: csum set outer-ip must be set to hw "
4645                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4646         }
4647
4648         cmd_reconfig_device_queue(res->port_id, 1, 1);
4649 }
4650
4651 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4652         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4653                                 tso, "tunnel_tso");
4654 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4655         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4656                                 mode, "set");
4657 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4658         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4659                                 tso_segsz, UINT16);
4660 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4661         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4662                                 port_id, UINT16);
4663
4664 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4665         .f = cmd_tunnel_tso_set_parsed,
4666         .data = NULL,
4667         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4668                 "Set TSO segment size of tunneled packets for csum engine "
4669                 "(0 to disable)",
4670         .tokens = {
4671                 (void *)&cmd_tunnel_tso_set_tso,
4672                 (void *)&cmd_tunnel_tso_set_mode,
4673                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4674                 (void *)&cmd_tunnel_tso_set_portid,
4675                 NULL,
4676         },
4677 };
4678
4679 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4680         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4681                                 mode, "show");
4682
4683
4684 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4685         .f = cmd_tunnel_tso_set_parsed,
4686         .data = NULL,
4687         .help_str = "tunnel_tso show <port_id> "
4688                 "Show TSO segment size of tunneled packets for csum engine",
4689         .tokens = {
4690                 (void *)&cmd_tunnel_tso_set_tso,
4691                 (void *)&cmd_tunnel_tso_show_mode,
4692                 (void *)&cmd_tunnel_tso_set_portid,
4693                 NULL,
4694         },
4695 };
4696
4697 /* *** SET GRO FOR A PORT *** */
4698 struct cmd_gro_enable_result {
4699         cmdline_fixed_string_t cmd_set;
4700         cmdline_fixed_string_t cmd_port;
4701         cmdline_fixed_string_t cmd_keyword;
4702         cmdline_fixed_string_t cmd_onoff;
4703         portid_t cmd_pid;
4704 };
4705
4706 static void
4707 cmd_gro_enable_parsed(void *parsed_result,
4708                 __attribute__((unused)) struct cmdline *cl,
4709                 __attribute__((unused)) void *data)
4710 {
4711         struct cmd_gro_enable_result *res;
4712
4713         res = parsed_result;
4714         if (!strcmp(res->cmd_keyword, "gro"))
4715                 setup_gro(res->cmd_onoff, res->cmd_pid);
4716 }
4717
4718 cmdline_parse_token_string_t cmd_gro_enable_set =
4719         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4720                         cmd_set, "set");
4721 cmdline_parse_token_string_t cmd_gro_enable_port =
4722         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4723                         cmd_keyword, "port");
4724 cmdline_parse_token_num_t cmd_gro_enable_pid =
4725         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4726                         cmd_pid, UINT16);
4727 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4728         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4729                         cmd_keyword, "gro");
4730 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4731         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4732                         cmd_onoff, "on#off");
4733
4734 cmdline_parse_inst_t cmd_gro_enable = {
4735         .f = cmd_gro_enable_parsed,
4736         .data = NULL,
4737         .help_str = "set port <port_id> gro on|off",
4738         .tokens = {
4739                 (void *)&cmd_gro_enable_set,
4740                 (void *)&cmd_gro_enable_port,
4741                 (void *)&cmd_gro_enable_pid,
4742                 (void *)&cmd_gro_enable_keyword,
4743                 (void *)&cmd_gro_enable_onoff,
4744                 NULL,
4745         },
4746 };
4747
4748 /* *** DISPLAY GRO CONFIGURATION *** */
4749 struct cmd_gro_show_result {
4750         cmdline_fixed_string_t cmd_show;
4751         cmdline_fixed_string_t cmd_port;
4752         cmdline_fixed_string_t cmd_keyword;
4753         portid_t cmd_pid;
4754 };
4755
4756 static void
4757 cmd_gro_show_parsed(void *parsed_result,
4758                 __attribute__((unused)) struct cmdline *cl,
4759                 __attribute__((unused)) void *data)
4760 {
4761         struct cmd_gro_show_result *res;
4762
4763         res = parsed_result;
4764         if (!strcmp(res->cmd_keyword, "gro"))
4765                 show_gro(res->cmd_pid);
4766 }
4767
4768 cmdline_parse_token_string_t cmd_gro_show_show =
4769         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4770                         cmd_show, "show");
4771 cmdline_parse_token_string_t cmd_gro_show_port =
4772         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4773                         cmd_port, "port");
4774 cmdline_parse_token_num_t cmd_gro_show_pid =
4775         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4776                         cmd_pid, UINT16);
4777 cmdline_parse_token_string_t cmd_gro_show_keyword =
4778         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4779                         cmd_keyword, "gro");
4780
4781 cmdline_parse_inst_t cmd_gro_show = {
4782         .f = cmd_gro_show_parsed,
4783         .data = NULL,
4784         .help_str = "show port <port_id> gro",
4785         .tokens = {
4786                 (void *)&cmd_gro_show_show,
4787                 (void *)&cmd_gro_show_port,
4788                 (void *)&cmd_gro_show_pid,
4789                 (void *)&cmd_gro_show_keyword,
4790                 NULL,
4791         },
4792 };
4793
4794 /* *** SET FLUSH CYCLES FOR GRO *** */
4795 struct cmd_gro_flush_result {
4796         cmdline_fixed_string_t cmd_set;
4797         cmdline_fixed_string_t cmd_keyword;
4798         cmdline_fixed_string_t cmd_flush;
4799         uint8_t cmd_cycles;
4800 };
4801
4802 static void
4803 cmd_gro_flush_parsed(void *parsed_result,
4804                 __attribute__((unused)) struct cmdline *cl,
4805                 __attribute__((unused)) void *data)
4806 {
4807         struct cmd_gro_flush_result *res;
4808
4809         res = parsed_result;
4810         if ((!strcmp(res->cmd_keyword, "gro")) &&
4811                         (!strcmp(res->cmd_flush, "flush")))
4812                 setup_gro_flush_cycles(res->cmd_cycles);
4813 }
4814
4815 cmdline_parse_token_string_t cmd_gro_flush_set =
4816         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4817                         cmd_set, "set");
4818 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4819         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4820                         cmd_keyword, "gro");
4821 cmdline_parse_token_string_t cmd_gro_flush_flush =
4822         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4823                         cmd_flush, "flush");
4824 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4825         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4826                         cmd_cycles, UINT8);
4827
4828 cmdline_parse_inst_t cmd_gro_flush = {
4829         .f = cmd_gro_flush_parsed,
4830         .data = NULL,
4831         .help_str = "set gro flush <cycles>",
4832         .tokens = {
4833                 (void *)&cmd_gro_flush_set,
4834                 (void *)&cmd_gro_flush_keyword,
4835                 (void *)&cmd_gro_flush_flush,
4836                 (void *)&cmd_gro_flush_cycles,
4837                 NULL,
4838         },
4839 };
4840
4841 /* *** ENABLE/DISABLE GSO *** */
4842 struct cmd_gso_enable_result {
4843         cmdline_fixed_string_t cmd_set;
4844         cmdline_fixed_string_t cmd_port;
4845         cmdline_fixed_string_t cmd_keyword;
4846         cmdline_fixed_string_t cmd_mode;
4847         portid_t cmd_pid;
4848 };
4849
4850 static void
4851 cmd_gso_enable_parsed(void *parsed_result,
4852                 __attribute__((unused)) struct cmdline *cl,
4853                 __attribute__((unused)) void *data)
4854 {
4855         struct cmd_gso_enable_result *res;
4856
4857         res = parsed_result;
4858         if (!strcmp(res->cmd_keyword, "gso"))
4859                 setup_gso(res->cmd_mode, res->cmd_pid);
4860 }
4861
4862 cmdline_parse_token_string_t cmd_gso_enable_set =
4863         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4864                         cmd_set, "set");
4865 cmdline_parse_token_string_t cmd_gso_enable_port =
4866         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4867                         cmd_port, "port");
4868 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4869         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4870                         cmd_keyword, "gso");
4871 cmdline_parse_token_string_t cmd_gso_enable_mode =
4872         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4873                         cmd_mode, "on#off");
4874 cmdline_parse_token_num_t cmd_gso_enable_pid =
4875         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4876                         cmd_pid, UINT16);
4877
4878 cmdline_parse_inst_t cmd_gso_enable = {
4879         .f = cmd_gso_enable_parsed,
4880         .data = NULL,
4881         .help_str = "set port <port_id> gso on|off",
4882         .tokens = {
4883                 (void *)&cmd_gso_enable_set,
4884                 (void *)&cmd_gso_enable_port,
4885                 (void *)&cmd_gso_enable_pid,
4886                 (void *)&cmd_gso_enable_keyword,
4887                 (void *)&cmd_gso_enable_mode,
4888                 NULL,
4889         },
4890 };
4891
4892 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4893 struct cmd_gso_size_result {
4894         cmdline_fixed_string_t cmd_set;
4895         cmdline_fixed_string_t cmd_keyword;
4896         cmdline_fixed_string_t cmd_segsz;
4897         uint16_t cmd_size;
4898 };
4899
4900 static void
4901 cmd_gso_size_parsed(void *parsed_result,
4902                        __attribute__((unused)) struct cmdline *cl,
4903                        __attribute__((unused)) void *data)
4904 {
4905         struct cmd_gso_size_result *res = parsed_result;
4906
4907         if (test_done == 0) {
4908                 printf("Before setting GSO segsz, please first"
4909                                 " stop fowarding\n");
4910                 return;
4911         }
4912
4913         if (!strcmp(res->cmd_keyword, "gso") &&
4914                         !strcmp(res->cmd_segsz, "segsz")) {
4915                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4916                         printf("gso_size should be larger than %zu."
4917                                         " Please input a legal value\n",
4918                                         RTE_GSO_SEG_SIZE_MIN);
4919                 else
4920                         gso_max_segment_size = res->cmd_size;
4921         }
4922 }
4923
4924 cmdline_parse_token_string_t cmd_gso_size_set =
4925         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4926                                 cmd_set, "set");
4927 cmdline_parse_token_string_t cmd_gso_size_keyword =
4928         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4929                                 cmd_keyword, "gso");
4930 cmdline_parse_token_string_t cmd_gso_size_segsz =
4931         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4932                                 cmd_segsz, "segsz");
4933 cmdline_parse_token_num_t cmd_gso_size_size =
4934         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4935                                 cmd_size, UINT16);
4936
4937 cmdline_parse_inst_t cmd_gso_size = {
4938         .f = cmd_gso_size_parsed,
4939         .data = NULL,
4940         .help_str = "set gso segsz <length>",
4941         .tokens = {
4942                 (void *)&cmd_gso_size_set,
4943                 (void *)&cmd_gso_size_keyword,
4944                 (void *)&cmd_gso_size_segsz,
4945                 (void *)&cmd_gso_size_size,
4946                 NULL,
4947         },
4948 };
4949
4950 /* *** SHOW GSO CONFIGURATION *** */
4951 struct cmd_gso_show_result {
4952         cmdline_fixed_string_t cmd_show;
4953         cmdline_fixed_string_t cmd_port;
4954         cmdline_fixed_string_t cmd_keyword;
4955         portid_t cmd_pid;
4956 };
4957
4958 static void
4959 cmd_gso_show_parsed(void *parsed_result,
4960                        __attribute__((unused)) struct cmdline *cl,
4961                        __attribute__((unused)) void *data)
4962 {
4963         struct cmd_gso_show_result *res = parsed_result;
4964
4965         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4966                 printf("invalid port id %u\n", res->cmd_pid);
4967                 return;
4968         }
4969         if (!strcmp(res->cmd_keyword, "gso")) {
4970                 if (gso_ports[res->cmd_pid].enable) {
4971                         printf("Max GSO'd packet size: %uB\n"
4972                                         "Supported GSO types: TCP/IPv4, "
4973                                         "UDP/IPv4, VxLAN with inner "
4974                                         "TCP/IPv4 packet, GRE with inner "
4975                                         "TCP/IPv4 packet\n",
4976                                         gso_max_segment_size);
4977                 } else
4978                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4979         }
4980 }
4981
4982 cmdline_parse_token_string_t cmd_gso_show_show =
4983 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4984                 cmd_show, "show");
4985 cmdline_parse_token_string_t cmd_gso_show_port =
4986 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4987                 cmd_port, "port");
4988 cmdline_parse_token_string_t cmd_gso_show_keyword =
4989         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4990                                 cmd_keyword, "gso");
4991 cmdline_parse_token_num_t cmd_gso_show_pid =
4992         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4993                                 cmd_pid, UINT16);
4994
4995 cmdline_parse_inst_t cmd_gso_show = {
4996         .f = cmd_gso_show_parsed,
4997         .data = NULL,
4998         .help_str = "show port <port_id> gso",
4999         .tokens = {
5000                 (void *)&cmd_gso_show_show,
5001                 (void *)&cmd_gso_show_port,
5002                 (void *)&cmd_gso_show_pid,
5003                 (void *)&cmd_gso_show_keyword,
5004                 NULL,
5005         },
5006 };
5007
5008 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5009 struct cmd_set_flush_rx {
5010         cmdline_fixed_string_t set;
5011         cmdline_fixed_string_t flush_rx;
5012         cmdline_fixed_string_t mode;
5013 };
5014
5015 static void
5016 cmd_set_flush_rx_parsed(void *parsed_result,
5017                 __attribute__((unused)) struct cmdline *cl,
5018                 __attribute__((unused)) void *data)
5019 {
5020         struct cmd_set_flush_rx *res = parsed_result;
5021         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5022 }
5023
5024 cmdline_parse_token_string_t cmd_setflushrx_set =
5025         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5026                         set, "set");
5027 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5028         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5029                         flush_rx, "flush_rx");
5030 cmdline_parse_token_string_t cmd_setflushrx_mode =
5031         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5032                         mode, "on#off");
5033
5034
5035 cmdline_parse_inst_t cmd_set_flush_rx = {
5036         .f = cmd_set_flush_rx_parsed,
5037         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5038         .data = NULL,
5039         .tokens = {
5040                 (void *)&cmd_setflushrx_set,
5041                 (void *)&cmd_setflushrx_flush_rx,
5042                 (void *)&cmd_setflushrx_mode,
5043                 NULL,
5044         },
5045 };
5046
5047 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5048 struct cmd_set_link_check {
5049         cmdline_fixed_string_t set;
5050         cmdline_fixed_string_t link_check;
5051         cmdline_fixed_string_t mode;
5052 };
5053
5054 static void
5055 cmd_set_link_check_parsed(void *parsed_result,
5056                 __attribute__((unused)) struct cmdline *cl,
5057                 __attribute__((unused)) void *data)
5058 {
5059         struct cmd_set_link_check *res = parsed_result;
5060         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5061 }
5062
5063 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5064         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5065                         set, "set");
5066 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5067         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5068                         link_check, "link_check");
5069 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5070         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5071                         mode, "on#off");
5072
5073
5074 cmdline_parse_inst_t cmd_set_link_check = {
5075         .f = cmd_set_link_check_parsed,
5076         .help_str = "set link_check on|off: Enable/Disable link status check "
5077                     "when starting/stopping a port",
5078         .data = NULL,
5079         .tokens = {
5080                 (void *)&cmd_setlinkcheck_set,
5081                 (void *)&cmd_setlinkcheck_link_check,
5082                 (void *)&cmd_setlinkcheck_mode,
5083                 NULL,
5084         },
5085 };
5086
5087 /* *** SET NIC BYPASS MODE *** */
5088 struct cmd_set_bypass_mode_result {
5089         cmdline_fixed_string_t set;
5090         cmdline_fixed_string_t bypass;
5091         cmdline_fixed_string_t mode;
5092         cmdline_fixed_string_t value;
5093         portid_t port_id;
5094 };
5095
5096 static void
5097 cmd_set_bypass_mode_parsed(void *parsed_result,
5098                 __attribute__((unused)) struct cmdline *cl,
5099                 __attribute__((unused)) void *data)
5100 {
5101         struct cmd_set_bypass_mode_result *res = parsed_result;
5102         portid_t port_id = res->port_id;
5103         int32_t rc = -EINVAL;
5104
5105 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5106         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5107
5108         if (!strcmp(res->value, "bypass"))
5109                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5110         else if (!strcmp(res->value, "isolate"))
5111                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5112         else
5113                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5114
5115         /* Set the bypass mode for the relevant port. */
5116         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5117 #endif
5118         if (rc != 0)
5119                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5120 }
5121
5122 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5123         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5124                         set, "set");
5125 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5126         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5127                         bypass, "bypass");
5128 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5130                         mode, "mode");
5131 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5132         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5133                         value, "normal#bypass#isolate");
5134 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5135         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5136                                 port_id, UINT16);
5137
5138 cmdline_parse_inst_t cmd_set_bypass_mode = {
5139         .f = cmd_set_bypass_mode_parsed,
5140         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5141                     "Set the NIC bypass mode for port_id",
5142         .data = NULL,
5143         .tokens = {
5144                 (void *)&cmd_setbypass_mode_set,
5145                 (void *)&cmd_setbypass_mode_bypass,
5146                 (void *)&cmd_setbypass_mode_mode,
5147                 (void *)&cmd_setbypass_mode_value,
5148                 (void *)&cmd_setbypass_mode_port,
5149                 NULL,
5150         },
5151 };
5152
5153 /* *** SET NIC BYPASS EVENT *** */
5154 struct cmd_set_bypass_event_result {
5155         cmdline_fixed_string_t set;
5156         cmdline_fixed_string_t bypass;
5157         cmdline_fixed_string_t event;
5158         cmdline_fixed_string_t event_value;
5159         cmdline_fixed_string_t mode;
5160         cmdline_fixed_string_t mode_value;
5161         portid_t port_id;
5162 };
5163
5164 static void
5165 cmd_set_bypass_event_parsed(void *parsed_result,
5166                 __attribute__((unused)) struct cmdline *cl,
5167                 __attribute__((unused)) void *data)
5168 {
5169         int32_t rc = -EINVAL;
5170         struct cmd_set_bypass_event_result *res = parsed_result;
5171         portid_t port_id = res->port_id;
5172
5173 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5174         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5175         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5176
5177         if (!strcmp(res->event_value, "timeout"))
5178                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5179         else if (!strcmp(res->event_value, "os_on"))
5180                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5181         else if (!strcmp(res->event_value, "os_off"))
5182                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5183         else if (!strcmp(res->event_value, "power_on"))
5184                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5185         else if (!strcmp(res->event_value, "power_off"))
5186                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5187         else
5188                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5189
5190         if (!strcmp(res->mode_value, "bypass"))
5191                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5192         else if (!strcmp(res->mode_value, "isolate"))
5193                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5194         else
5195                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5196
5197         /* Set the watchdog timeout. */
5198         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5199
5200                 rc = -EINVAL;
5201                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5202                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5203                                                            bypass_timeout);
5204                 }
5205                 if (rc != 0) {
5206                         printf("Failed to set timeout value %u "
5207                         "for port %d, errto code: %d.\n",
5208                         bypass_timeout, port_id, rc);
5209                 }
5210         }
5211
5212         /* Set the bypass event to transition to bypass mode. */
5213         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5214                                               bypass_mode);
5215 #endif
5216
5217         if (rc != 0)
5218                 printf("\t Failed to set bypass event for port = %d.\n",
5219                        port_id);
5220 }
5221
5222 cmdline_parse_token_string_t cmd_setbypass_event_set =
5223         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5224                         set, "set");
5225 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5226         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5227                         bypass, "bypass");
5228 cmdline_parse_token_string_t cmd_setbypass_event_event =
5229         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5230                         event, "event");
5231 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5232         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5233                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5234 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5235         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5236                         mode, "mode");
5237 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5238         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5239                         mode_value, "normal#bypass#isolate");
5240 cmdline_parse_token_num_t cmd_setbypass_event_port =
5241         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5242                                 port_id, UINT16);
5243
5244 cmdline_parse_inst_t cmd_set_bypass_event = {
5245         .f = cmd_set_bypass_event_parsed,
5246         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5247                 "power_off mode normal|bypass|isolate <port_id>: "
5248                 "Set the NIC bypass event mode for port_id",
5249         .data = NULL,
5250         .tokens = {
5251                 (void *)&cmd_setbypass_event_set,
5252                 (void *)&cmd_setbypass_event_bypass,
5253                 (void *)&cmd_setbypass_event_event,
5254                 (void *)&cmd_setbypass_event_event_value,
5255                 (void *)&cmd_setbypass_event_mode,
5256                 (void *)&cmd_setbypass_event_mode_value,
5257                 (void *)&cmd_setbypass_event_port,
5258                 NULL,
5259         },
5260 };
5261
5262
5263 /* *** SET NIC BYPASS TIMEOUT *** */
5264 struct cmd_set_bypass_timeout_result {
5265         cmdline_fixed_string_t set;
5266         cmdline_fixed_string_t bypass;
5267         cmdline_fixed_string_t timeout;
5268         cmdline_fixed_string_t value;
5269 };
5270
5271 static void
5272 cmd_set_bypass_timeout_parsed(void *parsed_result,
5273                 __attribute__((unused)) struct cmdline *cl,
5274                 __attribute__((unused)) void *data)
5275 {
5276         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5277
5278 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5279         if (!strcmp(res->value, "1.5"))
5280                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5281         else if (!strcmp(res->value, "2"))
5282                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5283         else if (!strcmp(res->value, "3"))
5284                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5285         else if (!strcmp(res->value, "4"))
5286                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5287         else if (!strcmp(res->value, "8"))
5288                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5289         else if (!strcmp(res->value, "16"))
5290                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5291         else if (!strcmp(res->value, "32"))
5292                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5293         else
5294                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5295 #endif
5296 }
5297
5298 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5299         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5300                         set, "set");
5301 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5302         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5303                         bypass, "bypass");
5304 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5305         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5306                         timeout, "timeout");
5307 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5308         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5309                         value, "0#1.5#2#3#4#8#16#32");
5310
5311 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5312         .f = cmd_set_bypass_timeout_parsed,
5313         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5314                 "Set the NIC bypass watchdog timeout in seconds",
5315         .data = NULL,
5316         .tokens = {
5317                 (void *)&cmd_setbypass_timeout_set,
5318                 (void *)&cmd_setbypass_timeout_bypass,
5319                 (void *)&cmd_setbypass_timeout_timeout,
5320                 (void *)&cmd_setbypass_timeout_value,
5321                 NULL,
5322         },
5323 };
5324
5325 /* *** SHOW NIC BYPASS MODE *** */
5326 struct cmd_show_bypass_config_result {
5327         cmdline_fixed_string_t show;
5328         cmdline_fixed_string_t bypass;
5329         cmdline_fixed_string_t config;
5330         portid_t port_id;
5331 };
5332
5333 static void
5334 cmd_show_bypass_config_parsed(void *parsed_result,
5335                 __attribute__((unused)) struct cmdline *cl,
5336                 __attribute__((unused)) void *data)
5337 {
5338         struct cmd_show_bypass_config_result *res = parsed_result;
5339         portid_t port_id = res->port_id;
5340         int rc = -EINVAL;
5341 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5342         uint32_t event_mode;
5343         uint32_t bypass_mode;
5344         uint32_t timeout = bypass_timeout;
5345         int i;
5346
5347         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5348                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5349         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5350                 {"UNKNOWN", "normal", "bypass", "isolate"};
5351         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5352                 "NONE",
5353                 "OS/board on",
5354                 "power supply on",
5355                 "OS/board off",
5356                 "power supply off",
5357                 "timeout"};
5358         int num_events = (sizeof events) / (sizeof events[0]);
5359
5360         /* Display the bypass mode.*/
5361         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5362                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5363                 return;
5364         }
5365         else {
5366                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5367                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5368
5369                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5370         }
5371
5372         /* Display the bypass timeout.*/
5373         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5374                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5375
5376         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5377
5378         /* Display the bypass events and associated modes. */
5379         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5380
5381                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5382                         printf("\tFailed to get bypass mode for event = %s\n",
5383                                 events[i]);
5384                 } else {
5385                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5386                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5387
5388                         printf("\tbypass event: %-16s = %s\n", events[i],
5389                                 modes[event_mode]);
5390                 }
5391         }
5392 #endif
5393         if (rc != 0)
5394                 printf("\tFailed to get bypass configuration for port = %d\n",
5395                        port_id);
5396 }
5397
5398 cmdline_parse_token_string_t cmd_showbypass_config_show =
5399         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5400                         show, "show");
5401 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5402         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5403                         bypass, "bypass");
5404 cmdline_parse_token_string_t cmd_showbypass_config_config =
5405         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5406                         config, "config");
5407 cmdline_parse_token_num_t cmd_showbypass_config_port =
5408         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5409                                 port_id, UINT16);
5410
5411 cmdline_parse_inst_t cmd_show_bypass_config = {
5412         .f = cmd_show_bypass_config_parsed,
5413         .help_str = "show bypass config <port_id>: "
5414                     "Show the NIC bypass config for port_id",
5415         .data = NULL,
5416         .tokens = {
5417                 (void *)&cmd_showbypass_config_show,
5418                 (void *)&cmd_showbypass_config_bypass,
5419                 (void *)&cmd_showbypass_config_config,
5420                 (void *)&cmd_showbypass_config_port,
5421                 NULL,
5422         },
5423 };
5424
5425 #ifdef RTE_LIBRTE_PMD_BOND
5426 /* *** SET BONDING MODE *** */
5427 struct cmd_set_bonding_mode_result {
5428         cmdline_fixed_string_t set;
5429         cmdline_fixed_string_t bonding;
5430         cmdline_fixed_string_t mode;
5431         uint8_t value;
5432         portid_t port_id;
5433 };
5434
5435 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5436                 __attribute__((unused))  struct cmdline *cl,
5437                 __attribute__((unused)) void *data)
5438 {
5439         struct cmd_set_bonding_mode_result *res = parsed_result;
5440         portid_t port_id = res->port_id;
5441
5442         /* Set the bonding mode for the relevant port. */
5443         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5444                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5445 }
5446
5447 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5448 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5449                 set, "set");
5450 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5451 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5452                 bonding, "bonding");
5453 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5454 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5455                 mode, "mode");
5456 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5457 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5458                 value, UINT8);
5459 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5460 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5461                 port_id, UINT16);
5462
5463 cmdline_parse_inst_t cmd_set_bonding_mode = {
5464                 .f = cmd_set_bonding_mode_parsed,
5465                 .help_str = "set bonding mode <mode_value> <port_id>: "
5466                         "Set the bonding mode for port_id",
5467                 .data = NULL,
5468                 .tokens = {
5469                                 (void *) &cmd_setbonding_mode_set,
5470                                 (void *) &cmd_setbonding_mode_bonding,
5471                                 (void *) &cmd_setbonding_mode_mode,
5472                                 (void *) &cmd_setbonding_mode_value,
5473                                 (void *) &cmd_setbonding_mode_port,
5474                                 NULL
5475                 }
5476 };
5477
5478 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5479 struct cmd_set_bonding_lacp_dedicated_queues_result {
5480         cmdline_fixed_string_t set;
5481         cmdline_fixed_string_t bonding;
5482         cmdline_fixed_string_t lacp;
5483         cmdline_fixed_string_t dedicated_queues;
5484         portid_t port_id;
5485         cmdline_fixed_string_t mode;
5486 };
5487
5488 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5489                 __attribute__((unused))  struct cmdline *cl,
5490                 __attribute__((unused)) void *data)
5491 {
5492         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5493         portid_t port_id = res->port_id;
5494         struct rte_port *port;
5495
5496         port = &ports[port_id];
5497
5498         /** Check if the port is not started **/
5499         if (port->port_status != RTE_PORT_STOPPED) {
5500                 printf("Please stop port %d first\n", port_id);
5501                 return;
5502         }
5503
5504         if (!strcmp(res->mode, "enable")) {
5505                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5506                         printf("Dedicate queues for LACP control packets"
5507                                         " enabled\n");
5508                 else
5509                         printf("Enabling dedicate queues for LACP control "
5510                                         "packets on port %d failed\n", port_id);
5511         } else if (!strcmp(res->mode, "disable")) {
5512                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5513                         printf("Dedicated queues for LACP control packets "
5514                                         "disabled\n");
5515                 else
5516                         printf("Disabling dedicated queues for LACP control "
5517                                         "traffic on port %d failed\n", port_id);
5518         }
5519 }
5520
5521 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5522 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5523                 set, "set");
5524 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5525 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5526                 bonding, "bonding");
5527 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5528 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5529                 lacp, "lacp");
5530 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5531 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5532                 dedicated_queues, "dedicated_queues");
5533 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5534 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5535                 port_id, UINT16);
5536 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5537 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5538                 mode, "enable#disable");
5539
5540 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5541                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5542                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5543                         "enable|disable: "
5544                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5545                 .data = NULL,
5546                 .tokens = {
5547                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5548                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5549                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5550                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5551                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5552                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5553                         NULL
5554                 }
5555 };
5556
5557 /* *** SET BALANCE XMIT POLICY *** */
5558 struct cmd_set_bonding_balance_xmit_policy_result {
5559         cmdline_fixed_string_t set;
5560         cmdline_fixed_string_t bonding;
5561         cmdline_fixed_string_t balance_xmit_policy;
5562         portid_t port_id;
5563         cmdline_fixed_string_t policy;
5564 };
5565
5566 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5567                 __attribute__((unused))  struct cmdline *cl,
5568                 __attribute__((unused)) void *data)
5569 {
5570         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5571         portid_t port_id = res->port_id;
5572         uint8_t policy;
5573
5574         if (!strcmp(res->policy, "l2")) {
5575                 policy = BALANCE_XMIT_POLICY_LAYER2;
5576         } else if (!strcmp(res->policy, "l23")) {
5577                 policy = BALANCE_XMIT_POLICY_LAYER23;
5578         } else if (!strcmp(res->policy, "l34")) {
5579                 policy = BALANCE_XMIT_POLICY_LAYER34;
5580         } else {
5581                 printf("\t Invalid xmit policy selection");
5582                 return;
5583         }
5584
5585         /* Set the bonding mode for the relevant port. */
5586         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5587                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5588                                 port_id);
5589         }
5590 }
5591
5592 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5593 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5594                 set, "set");
5595 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5596 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5597                 bonding, "bonding");
5598 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5599 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5600                 balance_xmit_policy, "balance_xmit_policy");
5601 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5602 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5603                 port_id, UINT16);
5604 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5605 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5606                 policy, "l2#l23#l34");
5607
5608 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5609                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5610                 .help_str = "set bonding balance_xmit_policy <port_id> "
5611                         "l2|l23|l34: "
5612                         "Set the bonding balance_xmit_policy for port_id",
5613                 .data = NULL,
5614                 .tokens = {
5615                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5616                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5617                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5618                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5619                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5620                                 NULL
5621                 }
5622 };
5623
5624 /* *** SHOW NIC BONDING CONFIGURATION *** */
5625 struct cmd_show_bonding_config_result {
5626         cmdline_fixed_string_t show;
5627         cmdline_fixed_string_t bonding;
5628         cmdline_fixed_string_t config;
5629         portid_t port_id;
5630 };
5631
5632 static void cmd_show_bonding_config_parsed(void *parsed_result,
5633                 __attribute__((unused))  struct cmdline *cl,
5634                 __attribute__((unused)) void *data)
5635 {
5636         struct cmd_show_bonding_config_result *res = parsed_result;
5637         int bonding_mode, agg_mode;
5638         portid_t slaves[RTE_MAX_ETHPORTS];
5639         int num_slaves, num_active_slaves;
5640         int primary_id;
5641         int i;
5642         portid_t port_id = res->port_id;
5643
5644         /* Display the bonding mode.*/
5645         bonding_mode = rte_eth_bond_mode_get(port_id);
5646         if (bonding_mode < 0) {
5647                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5648                 return;
5649         } else
5650                 printf("\tBonding mode: %d\n", bonding_mode);
5651
5652         if (bonding_mode == BONDING_MODE_BALANCE) {
5653                 int balance_xmit_policy;
5654
5655                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5656                 if (balance_xmit_policy < 0) {
5657                         printf("\tFailed to get balance xmit policy for port = %d\n",
5658                                         port_id);
5659                         return;
5660                 } else {
5661                         printf("\tBalance Xmit Policy: ");
5662
5663                         switch (balance_xmit_policy) {
5664                         case BALANCE_XMIT_POLICY_LAYER2:
5665                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5666                                 break;
5667                         case BALANCE_XMIT_POLICY_LAYER23:
5668                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5669                                 break;
5670                         case BALANCE_XMIT_POLICY_LAYER34:
5671                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5672                                 break;
5673                         }
5674                         printf("\n");
5675                 }
5676         }
5677
5678         if (bonding_mode == BONDING_MODE_8023AD) {
5679                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5680                 printf("\tIEEE802.3AD Aggregator Mode: ");
5681                 switch (agg_mode) {
5682                 case AGG_BANDWIDTH:
5683                         printf("bandwidth");
5684                         break;
5685                 case AGG_STABLE:
5686                         printf("stable");
5687                         break;
5688                 case AGG_COUNT:
5689                         printf("count");
5690                         break;
5691                 }
5692                 printf("\n");
5693         }
5694
5695         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5696
5697         if (num_slaves < 0) {
5698                 printf("\tFailed to get slave list for port = %d\n", port_id);
5699                 return;
5700         }
5701         if (num_slaves > 0) {
5702                 printf("\tSlaves (%d): [", num_slaves);
5703                 for (i = 0; i < num_slaves - 1; i++)
5704                         printf("%d ", slaves[i]);
5705
5706                 printf("%d]\n", slaves[num_slaves - 1]);
5707         } else {
5708                 printf("\tSlaves: []\n");
5709
5710         }
5711
5712         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5713                         RTE_MAX_ETHPORTS);
5714
5715         if (num_active_slaves < 0) {
5716                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5717                 return;
5718         }
5719         if (num_active_slaves > 0) {
5720                 printf("\tActive Slaves (%d): [", num_active_slaves);
5721                 for (i = 0; i < num_active_slaves - 1; i++)
5722                         printf("%d ", slaves[i]);
5723
5724                 printf("%d]\n", slaves[num_active_slaves - 1]);
5725
5726         } else {
5727                 printf("\tActive Slaves: []\n");
5728
5729         }
5730
5731         primary_id = rte_eth_bond_primary_get(port_id);
5732         if (primary_id < 0) {
5733                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5734                 return;
5735         } else
5736                 printf("\tPrimary: [%d]\n", primary_id);
5737
5738 }
5739
5740 cmdline_parse_token_string_t cmd_showbonding_config_show =
5741 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5742                 show, "show");
5743 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5744 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5745                 bonding, "bonding");
5746 cmdline_parse_token_string_t cmd_showbonding_config_config =
5747 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5748                 config, "config");
5749 cmdline_parse_token_num_t cmd_showbonding_config_port =
5750 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5751                 port_id, UINT16);
5752
5753 cmdline_parse_inst_t cmd_show_bonding_config = {
5754                 .f = cmd_show_bonding_config_parsed,
5755                 .help_str = "show bonding config <port_id>: "
5756                         "Show the bonding config for port_id",
5757                 .data = NULL,
5758                 .tokens = {
5759                                 (void *)&cmd_showbonding_config_show,
5760                                 (void *)&cmd_showbonding_config_bonding,
5761                                 (void *)&cmd_showbonding_config_config,
5762                                 (void *)&cmd_showbonding_config_port,
5763                                 NULL
5764                 }
5765 };
5766
5767 /* *** SET BONDING PRIMARY *** */
5768 struct cmd_set_bonding_primary_result {
5769         cmdline_fixed_string_t set;
5770         cmdline_fixed_string_t bonding;
5771         cmdline_fixed_string_t primary;
5772         portid_t slave_id;
5773         portid_t port_id;
5774 };
5775
5776 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5777                 __attribute__((unused))  struct cmdline *cl,
5778                 __attribute__((unused)) void *data)
5779 {
5780         struct cmd_set_bonding_primary_result *res = parsed_result;
5781         portid_t master_port_id = res->port_id;
5782         portid_t slave_port_id = res->slave_id;
5783
5784         /* Set the primary slave for a bonded device. */
5785         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5786                 printf("\t Failed to set primary slave for port = %d.\n",
5787                                 master_port_id);
5788                 return;
5789         }
5790         init_port_config();
5791 }
5792
5793 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5794 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5795                 set, "set");
5796 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5797 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5798                 bonding, "bonding");
5799 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5800 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5801                 primary, "primary");
5802 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5803 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5804                 slave_id, UINT16);
5805 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5806 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5807                 port_id, UINT16);
5808
5809 cmdline_parse_inst_t cmd_set_bonding_primary = {
5810                 .f = cmd_set_bonding_primary_parsed,
5811                 .help_str = "set bonding primary <slave_id> <port_id>: "
5812                         "Set the primary slave for port_id",
5813                 .data = NULL,
5814                 .tokens = {
5815                                 (void *)&cmd_setbonding_primary_set,
5816                                 (void *)&cmd_setbonding_primary_bonding,
5817                                 (void *)&cmd_setbonding_primary_primary,
5818                                 (void *)&cmd_setbonding_primary_slave,
5819                                 (void *)&cmd_setbonding_primary_port,
5820                                 NULL
5821                 }
5822 };
5823
5824 /* *** ADD SLAVE *** */
5825 struct cmd_add_bonding_slave_result {
5826         cmdline_fixed_string_t add;
5827         cmdline_fixed_string_t bonding;
5828         cmdline_fixed_string_t slave;
5829         portid_t slave_id;
5830         portid_t port_id;
5831 };
5832
5833 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5834                 __attribute__((unused))  struct cmdline *cl,
5835                 __attribute__((unused)) void *data)
5836 {
5837         struct cmd_add_bonding_slave_result *res = parsed_result;
5838         portid_t master_port_id = res->port_id;
5839         portid_t slave_port_id = res->slave_id;
5840
5841         /* add the slave for a bonded device. */
5842         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5843                 printf("\t Failed to add slave %d to master port = %d.\n",
5844                                 slave_port_id, master_port_id);
5845                 return;
5846         }
5847         init_port_config();
5848         set_port_slave_flag(slave_port_id);
5849 }
5850
5851 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5852 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5853                 add, "add");
5854 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5855 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5856                 bonding, "bonding");
5857 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5858 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5859                 slave, "slave");
5860 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5861 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5862                 slave_id, UINT16);
5863 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5864 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5865                 port_id, UINT16);
5866
5867 cmdline_parse_inst_t cmd_add_bonding_slave = {
5868                 .f = cmd_add_bonding_slave_parsed,
5869                 .help_str = "add bonding slave <slave_id> <port_id>: "
5870                         "Add a slave device to a bonded device",
5871                 .data = NULL,
5872                 .tokens = {
5873                                 (void *)&cmd_addbonding_slave_add,
5874                                 (void *)&cmd_addbonding_slave_bonding,
5875                                 (void *)&cmd_addbonding_slave_slave,
5876                                 (void *)&cmd_addbonding_slave_slaveid,
5877                                 (void *)&cmd_addbonding_slave_port,
5878                                 NULL
5879                 }
5880 };
5881
5882 /* *** REMOVE SLAVE *** */
5883 struct cmd_remove_bonding_slave_result {
5884         cmdline_fixed_string_t remove;
5885         cmdline_fixed_string_t bonding;
5886         cmdline_fixed_string_t slave;
5887         portid_t slave_id;
5888         portid_t port_id;
5889 };
5890
5891 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5892                 __attribute__((unused))  struct cmdline *cl,
5893                 __attribute__((unused)) void *data)
5894 {
5895         struct cmd_remove_bonding_slave_result *res = parsed_result;
5896         portid_t master_port_id = res->port_id;
5897         portid_t slave_port_id = res->slave_id;
5898
5899         /* remove the slave from a bonded device. */
5900         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5901                 printf("\t Failed to remove slave %d from master port = %d.\n",
5902                                 slave_port_id, master_port_id);
5903                 return;
5904         }
5905         init_port_config();
5906         clear_port_slave_flag(slave_port_id);
5907 }
5908
5909 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5910                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5911                                 remove, "remove");
5912 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5913                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5914                                 bonding, "bonding");
5915 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5916                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5917                                 slave, "slave");
5918 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5919                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5920                                 slave_id, UINT16);
5921 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5922                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5923                                 port_id, UINT16);
5924
5925 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5926                 .f = cmd_remove_bonding_slave_parsed,
5927                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5928                         "Remove a slave device from a bonded device",
5929                 .data = NULL,
5930                 .tokens = {
5931                                 (void *)&cmd_removebonding_slave_remove,
5932                                 (void *)&cmd_removebonding_slave_bonding,
5933                                 (void *)&cmd_removebonding_slave_slave,
5934                                 (void *)&cmd_removebonding_slave_slaveid,
5935                                 (void *)&cmd_removebonding_slave_port,
5936                                 NULL
5937                 }
5938 };
5939
5940 /* *** CREATE BONDED DEVICE *** */
5941 struct cmd_create_bonded_device_result {
5942         cmdline_fixed_string_t create;
5943         cmdline_fixed_string_t bonded;
5944         cmdline_fixed_string_t device;
5945         uint8_t mode;
5946         uint8_t socket;
5947 };
5948
5949 static int bond_dev_num = 0;
5950
5951 static void cmd_create_bonded_device_parsed(void *parsed_result,
5952                 __attribute__((unused))  struct cmdline *cl,
5953                 __attribute__((unused)) void *data)
5954 {
5955         struct cmd_create_bonded_device_result *res = parsed_result;
5956         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5957         int port_id;
5958
5959         if (test_done == 0) {
5960                 printf("Please stop forwarding first\n");
5961                 return;
5962         }
5963
5964         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5965                         bond_dev_num++);
5966
5967         /* Create a new bonded device. */
5968         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5969         if (port_id < 0) {
5970                 printf("\t Failed to create bonded device.\n");
5971                 return;
5972         } else {
5973                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5974                                 port_id);
5975
5976                 /* Update number of ports */
5977                 nb_ports = rte_eth_dev_count_avail();
5978                 reconfig(port_id, res->socket);
5979                 rte_eth_promiscuous_enable(port_id);
5980         }
5981
5982 }
5983
5984 cmdline_parse_token_string_t cmd_createbonded_device_create =
5985                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5986                                 create, "create");
5987 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5988                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5989                                 bonded, "bonded");
5990 cmdline_parse_token_string_t cmd_createbonded_device_device =
5991                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5992                                 device, "device");
5993 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5994                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5995                                 mode, UINT8);
5996 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5997                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5998                                 socket, UINT8);
5999
6000 cmdline_parse_inst_t cmd_create_bonded_device = {
6001                 .f = cmd_create_bonded_device_parsed,
6002                 .help_str = "create bonded device <mode> <socket>: "
6003                         "Create a new bonded device with specific bonding mode and socket",
6004                 .data = NULL,
6005                 .tokens = {
6006                                 (void *)&cmd_createbonded_device_create,
6007                                 (void *)&cmd_createbonded_device_bonded,
6008                                 (void *)&cmd_createbonded_device_device,
6009                                 (void *)&cmd_createbonded_device_mode,
6010                                 (void *)&cmd_createbonded_device_socket,
6011                                 NULL
6012                 }
6013 };
6014
6015 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6016 struct cmd_set_bond_mac_addr_result {
6017         cmdline_fixed_string_t set;
6018         cmdline_fixed_string_t bonding;
6019         cmdline_fixed_string_t mac_addr;
6020         uint16_t port_num;
6021         struct ether_addr address;
6022 };
6023
6024 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6025                 __attribute__((unused))  struct cmdline *cl,
6026                 __attribute__((unused)) void *data)
6027 {
6028         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6029         int ret;
6030
6031         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6032                 return;
6033
6034         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6035
6036         /* check the return value and print it if is < 0 */
6037         if (ret < 0)
6038                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6039 }
6040
6041 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6042                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6043 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6044                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6045                                 "bonding");
6046 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6047                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6048                                 "mac_addr");
6049 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6050                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6051                                 port_num, UINT16);
6052 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6053                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6054
6055 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6056                 .f = cmd_set_bond_mac_addr_parsed,
6057                 .data = (void *) 0,
6058                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6059                 .tokens = {
6060                                 (void *)&cmd_set_bond_mac_addr_set,
6061                                 (void *)&cmd_set_bond_mac_addr_bonding,
6062                                 (void *)&cmd_set_bond_mac_addr_mac,
6063                                 (void *)&cmd_set_bond_mac_addr_portnum,
6064                                 (void *)&cmd_set_bond_mac_addr_addr,
6065                                 NULL
6066                 }
6067 };
6068
6069
6070 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6071 struct cmd_set_bond_mon_period_result {
6072         cmdline_fixed_string_t set;
6073         cmdline_fixed_string_t bonding;
6074         cmdline_fixed_string_t mon_period;
6075         uint16_t port_num;
6076         uint32_t period_ms;
6077 };
6078
6079 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6080                 __attribute__((unused))  struct cmdline *cl,
6081                 __attribute__((unused)) void *data)
6082 {
6083         struct cmd_set_bond_mon_period_result *res = parsed_result;
6084         int ret;
6085
6086         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6087
6088         /* check the return value and print it if is < 0 */
6089         if (ret < 0)
6090                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6091 }
6092
6093 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6094                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6095                                 set, "set");
6096 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6097                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6098                                 bonding, "bonding");
6099 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6100                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6101                                 mon_period,     "mon_period");
6102 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6103                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6104                                 port_num, UINT16);
6105 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6106                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6107                                 period_ms, UINT32);
6108
6109 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6110                 .f = cmd_set_bond_mon_period_parsed,
6111                 .data = (void *) 0,
6112                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6113                 .tokens = {
6114                                 (void *)&cmd_set_bond_mon_period_set,
6115                                 (void *)&cmd_set_bond_mon_period_bonding,
6116                                 (void *)&cmd_set_bond_mon_period_mon_period,
6117                                 (void *)&cmd_set_bond_mon_period_portnum,
6118                                 (void *)&cmd_set_bond_mon_period_period_ms,
6119                                 NULL
6120                 }
6121 };
6122
6123
6124
6125 struct cmd_set_bonding_agg_mode_policy_result {
6126         cmdline_fixed_string_t set;
6127         cmdline_fixed_string_t bonding;
6128         cmdline_fixed_string_t agg_mode;
6129         uint16_t port_num;
6130         cmdline_fixed_string_t policy;
6131 };
6132
6133
6134 static void
6135 cmd_set_bonding_agg_mode(void *parsed_result,
6136                 __attribute__((unused)) struct cmdline *cl,
6137                 __attribute__((unused)) void *data)
6138 {
6139         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6140         uint8_t policy = AGG_BANDWIDTH;
6141
6142         if (!strcmp(res->policy, "bandwidth"))
6143                 policy = AGG_BANDWIDTH;
6144         else if (!strcmp(res->policy, "stable"))
6145                 policy = AGG_STABLE;
6146         else if (!strcmp(res->policy, "count"))
6147                 policy = AGG_COUNT;
6148
6149         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6150 }
6151
6152
6153 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6154         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6155                                 set, "set");
6156 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6157         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6158                                 bonding, "bonding");
6159
6160 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6161         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6162                                 agg_mode, "agg_mode");
6163
6164 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6165         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6166                                 port_num, UINT16);
6167
6168 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6169         TOKEN_STRING_INITIALIZER(
6170                         struct cmd_set_bonding_balance_xmit_policy_result,
6171                 policy, "stable#bandwidth#count");
6172
6173 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6174         .f = cmd_set_bonding_agg_mode,
6175         .data = (void *) 0,
6176         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6177         .tokens = {
6178                         (void *)&cmd_set_bonding_agg_mode_set,
6179                         (void *)&cmd_set_bonding_agg_mode_bonding,
6180                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6181                         (void *)&cmd_set_bonding_agg_mode_portnum,
6182                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6183                         NULL
6184                 }
6185 };
6186
6187
6188 #endif /* RTE_LIBRTE_PMD_BOND */
6189
6190 /* *** SET FORWARDING MODE *** */
6191 struct cmd_set_fwd_mode_result {
6192         cmdline_fixed_string_t set;
6193         cmdline_fixed_string_t fwd;
6194         cmdline_fixed_string_t mode;
6195 };
6196
6197 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6198                                     __attribute__((unused)) struct cmdline *cl,
6199                                     __attribute__((unused)) void *data)
6200 {
6201         struct cmd_set_fwd_mode_result *res = parsed_result;
6202
6203         retry_enabled = 0;
6204         set_pkt_forwarding_mode(res->mode);
6205 }
6206
6207 cmdline_parse_token_string_t cmd_setfwd_set =
6208         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6209 cmdline_parse_token_string_t cmd_setfwd_fwd =
6210         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6211 cmdline_parse_token_string_t cmd_setfwd_mode =
6212         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6213                 "" /* defined at init */);
6214
6215 cmdline_parse_inst_t cmd_set_fwd_mode = {
6216         .f = cmd_set_fwd_mode_parsed,
6217         .data = NULL,
6218         .help_str = NULL, /* defined at init */
6219         .tokens = {
6220                 (void *)&cmd_setfwd_set,
6221                 (void *)&cmd_setfwd_fwd,
6222                 (void *)&cmd_setfwd_mode,
6223                 NULL,
6224         },
6225 };
6226
6227 static void cmd_set_fwd_mode_init(void)
6228 {
6229         char *modes, *c;
6230         static char token[128];
6231         static char help[256];
6232         cmdline_parse_token_string_t *token_struct;
6233
6234         modes = list_pkt_forwarding_modes();
6235         snprintf(help, sizeof(help), "set fwd %s: "
6236                 "Set packet forwarding mode", modes);
6237         cmd_set_fwd_mode.help_str = help;
6238
6239         /* string token separator is # */
6240         for (c = token; *modes != '\0'; modes++)
6241                 if (*modes == '|')
6242                         *c++ = '#';
6243                 else
6244                         *c++ = *modes;
6245         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6246         token_struct->string_data.str = token;
6247 }
6248
6249 /* *** SET RETRY FORWARDING MODE *** */
6250 struct cmd_set_fwd_retry_mode_result {
6251         cmdline_fixed_string_t set;
6252         cmdline_fixed_string_t fwd;
6253         cmdline_fixed_string_t mode;
6254         cmdline_fixed_string_t retry;
6255 };
6256
6257 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6258                             __attribute__((unused)) struct cmdline *cl,
6259                             __attribute__((unused)) void *data)
6260 {
6261         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6262
6263         retry_enabled = 1;
6264         set_pkt_forwarding_mode(res->mode);
6265 }
6266
6267 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6268         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6269                         set, "set");
6270 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6271         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6272                         fwd, "fwd");
6273 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6274         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6275                         mode,
6276                 "" /* defined at init */);
6277 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6278         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6279                         retry, "retry");
6280
6281 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6282         .f = cmd_set_fwd_retry_mode_parsed,
6283         .data = NULL,
6284         .help_str = NULL, /* defined at init */
6285         .tokens = {
6286                 (void *)&cmd_setfwd_retry_set,
6287                 (void *)&cmd_setfwd_retry_fwd,
6288                 (void *)&cmd_setfwd_retry_mode,
6289                 (void *)&cmd_setfwd_retry_retry,
6290                 NULL,
6291         },
6292 };
6293
6294 static void cmd_set_fwd_retry_mode_init(void)
6295 {
6296         char *modes, *c;
6297         static char token[128];
6298         static char help[256];
6299         cmdline_parse_token_string_t *token_struct;
6300
6301         modes = list_pkt_forwarding_retry_modes();
6302         snprintf(help, sizeof(help), "set fwd %s retry: "
6303                 "Set packet forwarding mode with retry", modes);
6304         cmd_set_fwd_retry_mode.help_str = help;
6305
6306         /* string token separator is # */
6307         for (c = token; *modes != '\0'; modes++)
6308                 if (*modes == '|')
6309                         *c++ = '#';
6310                 else
6311                         *c++ = *modes;
6312         token_struct = (cmdline_parse_token_string_t *)
6313                 cmd_set_fwd_retry_mode.tokens[2];
6314         token_struct->string_data.str = token;
6315 }
6316
6317 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6318 struct cmd_set_burst_tx_retry_result {
6319         cmdline_fixed_string_t set;
6320         cmdline_fixed_string_t burst;
6321         cmdline_fixed_string_t tx;
6322         cmdline_fixed_string_t delay;
6323         uint32_t time;
6324         cmdline_fixed_string_t retry;
6325         uint32_t retry_num;
6326 };
6327
6328 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6329                                         __attribute__((unused)) struct cmdline *cl,
6330                                         __attribute__((unused)) void *data)
6331 {
6332         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6333
6334         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6335                 && !strcmp(res->tx, "tx")) {
6336                 if (!strcmp(res->delay, "delay"))
6337                         burst_tx_delay_time = res->time;
6338                 if (!strcmp(res->retry, "retry"))
6339                         burst_tx_retry_num = res->retry_num;
6340         }
6341
6342 }
6343
6344 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6345         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6346 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6347         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6348                                  "burst");
6349 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6350         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6351 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6352         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6353 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6354         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6355 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6356         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6357 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6358         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6359
6360 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6361         .f = cmd_set_burst_tx_retry_parsed,
6362         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6363         .tokens = {
6364                 (void *)&cmd_set_burst_tx_retry_set,
6365                 (void *)&cmd_set_burst_tx_retry_burst,
6366                 (void *)&cmd_set_burst_tx_retry_tx,
6367                 (void *)&cmd_set_burst_tx_retry_delay,
6368                 (void *)&cmd_set_burst_tx_retry_time,
6369                 (void *)&cmd_set_burst_tx_retry_retry,
6370                 (void *)&cmd_set_burst_tx_retry_retry_num,
6371                 NULL,
6372         },
6373 };
6374
6375 /* *** SET PROMISC MODE *** */
6376 struct cmd_set_promisc_mode_result {
6377         cmdline_fixed_string_t set;
6378         cmdline_fixed_string_t promisc;
6379         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6380         uint16_t port_num;               /* valid if "allports" argument == 0 */
6381         cmdline_fixed_string_t mode;
6382 };
6383
6384 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6385                                         __attribute__((unused)) struct cmdline *cl,
6386                                         void *allports)
6387 {
6388         struct cmd_set_promisc_mode_result *res = parsed_result;
6389         int enable;
6390         portid_t i;
6391
6392         if (!strcmp(res->mode, "on"))
6393                 enable = 1;
6394         else
6395                 enable = 0;
6396
6397         /* all ports */
6398         if (allports) {
6399                 RTE_ETH_FOREACH_DEV(i) {
6400                         if (enable)
6401                                 rte_eth_promiscuous_enable(i);
6402                         else
6403                                 rte_eth_promiscuous_disable(i);
6404                 }
6405         }
6406         else {
6407                 if (enable)
6408                         rte_eth_promiscuous_enable(res->port_num);
6409                 else
6410                         rte_eth_promiscuous_disable(res->port_num);
6411         }
6412 }
6413
6414 cmdline_parse_token_string_t cmd_setpromisc_set =
6415         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6416 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6417         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6418                                  "promisc");
6419 cmdline_parse_token_string_t cmd_setpromisc_portall =
6420         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6421                                  "all");
6422 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6423         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6424                               UINT16);
6425 cmdline_parse_token_string_t cmd_setpromisc_mode =
6426         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6427                                  "on#off");
6428
6429 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6430         .f = cmd_set_promisc_mode_parsed,
6431         .data = (void *)1,
6432         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6433         .tokens = {
6434                 (void *)&cmd_setpromisc_set,
6435                 (void *)&cmd_setpromisc_promisc,
6436                 (void *)&cmd_setpromisc_portall,
6437                 (void *)&cmd_setpromisc_mode,
6438                 NULL,
6439         },
6440 };
6441
6442 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6443         .f = cmd_set_promisc_mode_parsed,
6444         .data = (void *)0,
6445         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6446         .tokens = {
6447                 (void *)&cmd_setpromisc_set,
6448                 (void *)&cmd_setpromisc_promisc,
6449                 (void *)&cmd_setpromisc_portnum,
6450                 (void *)&cmd_setpromisc_mode,
6451                 NULL,
6452         },
6453 };
6454
6455 /* *** SET ALLMULTI MODE *** */
6456 struct cmd_set_allmulti_mode_result {
6457         cmdline_fixed_string_t set;
6458         cmdline_fixed_string_t allmulti;
6459         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6460         uint16_t port_num;               /* valid if "allports" argument == 0 */
6461         cmdline_fixed_string_t mode;
6462 };
6463
6464 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6465                                         __attribute__((unused)) struct cmdline *cl,
6466                                         void *allports)
6467 {
6468         struct cmd_set_allmulti_mode_result *res = parsed_result;
6469         int enable;
6470         portid_t i;
6471
6472         if (!strcmp(res->mode, "on"))
6473                 enable = 1;
6474         else
6475                 enable = 0;
6476
6477         /* all ports */
6478         if (allports) {
6479                 RTE_ETH_FOREACH_DEV(i) {
6480                         if (enable)
6481                                 rte_eth_allmulticast_enable(i);
6482                         else
6483                                 rte_eth_allmulticast_disable(i);
6484                 }
6485         }
6486         else {
6487                 if (enable)
6488                         rte_eth_allmulticast_enable(res->port_num);
6489                 else
6490                         rte_eth_allmulticast_disable(res->port_num);
6491         }
6492 }
6493
6494 cmdline_parse_token_string_t cmd_setallmulti_set =
6495         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6496 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6497         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6498                                  "allmulti");
6499 cmdline_parse_token_string_t cmd_setallmulti_portall =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6501                                  "all");
6502 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6503         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6504                               UINT16);
6505 cmdline_parse_token_string_t cmd_setallmulti_mode =
6506         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6507                                  "on#off");
6508
6509 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6510         .f = cmd_set_allmulti_mode_parsed,
6511         .data = (void *)1,
6512         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6513         .tokens = {
6514                 (void *)&cmd_setallmulti_set,
6515                 (void *)&cmd_setallmulti_allmulti,
6516                 (void *)&cmd_setallmulti_portall,
6517                 (void *)&cmd_setallmulti_mode,
6518                 NULL,
6519         },
6520 };
6521
6522 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6523         .f = cmd_set_allmulti_mode_parsed,
6524         .data = (void *)0,
6525         .help_str = "set allmulti <port_id> on|off: "
6526                 "Set allmulti mode on port_id",
6527         .tokens = {
6528                 (void *)&cmd_setallmulti_set,
6529                 (void *)&cmd_setallmulti_allmulti,
6530                 (void *)&cmd_setallmulti_portnum,
6531                 (void *)&cmd_setallmulti_mode,
6532                 NULL,
6533         },
6534 };
6535
6536 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6537 struct cmd_link_flow_ctrl_set_result {
6538         cmdline_fixed_string_t set;
6539         cmdline_fixed_string_t flow_ctrl;
6540         cmdline_fixed_string_t rx;
6541         cmdline_fixed_string_t rx_lfc_mode;
6542         cmdline_fixed_string_t tx;
6543         cmdline_fixed_string_t tx_lfc_mode;
6544         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6545         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6546         cmdline_fixed_string_t autoneg_str;
6547         cmdline_fixed_string_t autoneg;
6548         cmdline_fixed_string_t hw_str;
6549         uint32_t high_water;
6550         cmdline_fixed_string_t lw_str;
6551         uint32_t low_water;
6552         cmdline_fixed_string_t pt_str;
6553         uint16_t pause_time;
6554         cmdline_fixed_string_t xon_str;
6555         uint16_t send_xon;
6556         portid_t port_id;
6557 };
6558
6559 cmdline_parse_token_string_t cmd_lfc_set_set =
6560         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6561                                 set, "set");
6562 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6563         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6564                                 flow_ctrl, "flow_ctrl");
6565 cmdline_parse_token_string_t cmd_lfc_set_rx =
6566         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6567                                 rx, "rx");
6568 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6569         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6570                                 rx_lfc_mode, "on#off");
6571 cmdline_parse_token_string_t cmd_lfc_set_tx =
6572         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6573                                 tx, "tx");
6574 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6575         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6576                                 tx_lfc_mode, "on#off");
6577 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6578         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6579                                 hw_str, "high_water");
6580 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6581         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6582                                 high_water, UINT32);
6583 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6584         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6585                                 lw_str, "low_water");
6586 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6587         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6588                                 low_water, UINT32);
6589 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6590         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6591                                 pt_str, "pause_time");
6592 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6593         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6594                                 pause_time, UINT16);
6595 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6596         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6597                                 xon_str, "send_xon");
6598 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6599         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6600                                 send_xon, UINT16);
6601 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6602         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6603                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6604 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6605         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6606                                 mac_ctrl_frame_fwd_mode, "on#off");
6607 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6608         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6609                                 autoneg_str, "autoneg");
6610 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6611         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6612                                 autoneg, "on#off");
6613 cmdline_parse_token_num_t cmd_lfc_set_portid =
6614         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6615                                 port_id, UINT16);
6616
6617 /* forward declaration */
6618 static void
6619 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6620                               void *data);
6621
6622 cmdline_parse_inst_t cmd_link_flow_control_set = {
6623         .f = cmd_link_flow_ctrl_set_parsed,
6624         .data = NULL,
6625         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6626                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6627                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6628         .tokens = {
6629                 (void *)&cmd_lfc_set_set,
6630                 (void *)&cmd_lfc_set_flow_ctrl,
6631                 (void *)&cmd_lfc_set_rx,
6632                 (void *)&cmd_lfc_set_rx_mode,
6633                 (void *)&cmd_lfc_set_tx,
6634                 (void *)&cmd_lfc_set_tx_mode,
6635                 (void *)&cmd_lfc_set_high_water,
6636                 (void *)&cmd_lfc_set_low_water,
6637                 (void *)&cmd_lfc_set_pause_time,
6638                 (void *)&cmd_lfc_set_send_xon,
6639                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6640                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6641                 (void *)&cmd_lfc_set_autoneg_str,
6642                 (void *)&cmd_lfc_set_autoneg,
6643                 (void *)&cmd_lfc_set_portid,
6644                 NULL,
6645         },
6646 };
6647
6648 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6649         .f = cmd_link_flow_ctrl_set_parsed,
6650         .data = (void *)&cmd_link_flow_control_set_rx,
6651         .help_str = "set flow_ctrl rx on|off <port_id>: "
6652                 "Change rx flow control parameter",
6653         .tokens = {
6654                 (void *)&cmd_lfc_set_set,
6655                 (void *)&cmd_lfc_set_flow_ctrl,
6656                 (void *)&cmd_lfc_set_rx,
6657                 (void *)&cmd_lfc_set_rx_mode,
6658                 (void *)&cmd_lfc_set_portid,
6659                 NULL,
6660         },
6661 };
6662
6663 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6664         .f = cmd_link_flow_ctrl_set_parsed,
6665         .data = (void *)&cmd_link_flow_control_set_tx,
6666         .help_str = "set flow_ctrl tx on|off <port_id>: "
6667                 "Change tx flow control parameter",
6668         .tokens = {
6669                 (void *)&cmd_lfc_set_set,
6670                 (void *)&cmd_lfc_set_flow_ctrl,
6671                 (void *)&cmd_lfc_set_tx,
6672                 (void *)&cmd_lfc_set_tx_mode,
6673                 (void *)&cmd_lfc_set_portid,
6674                 NULL,
6675         },
6676 };
6677
6678 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6679         .f = cmd_link_flow_ctrl_set_parsed,
6680         .data = (void *)&cmd_link_flow_control_set_hw,
6681         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6682                 "Change high water flow control parameter",
6683         .tokens = {
6684                 (void *)&cmd_lfc_set_set,
6685                 (void *)&cmd_lfc_set_flow_ctrl,
6686                 (void *)&cmd_lfc_set_high_water_str,
6687                 (void *)&cmd_lfc_set_high_water,
6688                 (void *)&cmd_lfc_set_portid,
6689                 NULL,
6690         },
6691 };
6692
6693 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6694         .f = cmd_link_flow_ctrl_set_parsed,
6695         .data = (void *)&cmd_link_flow_control_set_lw,
6696         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6697                 "Change low water flow control parameter",
6698         .tokens = {
6699                 (void *)&cmd_lfc_set_set,
6700                 (void *)&cmd_lfc_set_flow_ctrl,
6701                 (void *)&cmd_lfc_set_low_water_str,
6702                 (void *)&cmd_lfc_set_low_water,
6703                 (void *)&cmd_lfc_set_portid,
6704                 NULL,
6705         },
6706 };
6707
6708 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6709         .f = cmd_link_flow_ctrl_set_parsed,
6710         .data = (void *)&cmd_link_flow_control_set_pt,
6711         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6712                 "Change pause time flow control parameter",
6713         .tokens = {
6714                 (void *)&cmd_lfc_set_set,
6715                 (void *)&cmd_lfc_set_flow_ctrl,
6716                 (void *)&cmd_lfc_set_pause_time_str,
6717                 (void *)&cmd_lfc_set_pause_time,
6718                 (void *)&cmd_lfc_set_portid,
6719                 NULL,
6720         },
6721 };
6722
6723 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6724         .f = cmd_link_flow_ctrl_set_parsed,
6725         .data = (void *)&cmd_link_flow_control_set_xon,
6726         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6727                 "Change send_xon flow control parameter",
6728         .tokens = {
6729                 (void *)&cmd_lfc_set_set,
6730                 (void *)&cmd_lfc_set_flow_ctrl,
6731                 (void *)&cmd_lfc_set_send_xon_str,
6732                 (void *)&cmd_lfc_set_send_xon,
6733                 (void *)&cmd_lfc_set_portid,
6734                 NULL,
6735         },
6736 };
6737
6738 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6739         .f = cmd_link_flow_ctrl_set_parsed,
6740         .data = (void *)&cmd_link_flow_control_set_macfwd,
6741         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6742                 "Change mac ctrl fwd flow control parameter",
6743         .tokens = {
6744                 (void *)&cmd_lfc_set_set,
6745                 (void *)&cmd_lfc_set_flow_ctrl,
6746                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6747                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6748                 (void *)&cmd_lfc_set_portid,
6749                 NULL,
6750         },
6751 };
6752
6753 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6754         .f = cmd_link_flow_ctrl_set_parsed,
6755         .data = (void *)&cmd_link_flow_control_set_autoneg,
6756         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6757                 "Change autoneg flow control parameter",
6758         .tokens = {
6759                 (void *)&cmd_lfc_set_set,
6760                 (void *)&cmd_lfc_set_flow_ctrl,
6761                 (void *)&cmd_lfc_set_autoneg_str,
6762                 (void *)&cmd_lfc_set_autoneg,
6763                 (void *)&cmd_lfc_set_portid,
6764                 NULL,
6765         },
6766 };
6767
6768 static void
6769 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6770                               __attribute__((unused)) struct cmdline *cl,
6771                               void *data)
6772 {
6773         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6774         cmdline_parse_inst_t *cmd = data;
6775         struct rte_eth_fc_conf fc_conf;
6776         int rx_fc_en = 0;
6777         int tx_fc_en = 0;
6778         int ret;
6779
6780         /*
6781          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6782          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6783          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6784          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6785          */
6786         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6787                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6788         };
6789
6790         /* Partial command line, retrieve current configuration */
6791         if (cmd) {
6792                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6793                 if (ret != 0) {
6794                         printf("cannot get current flow ctrl parameters, return"
6795                                "code = %d\n", ret);
6796                         return;
6797                 }
6798
6799                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6800                     (fc_conf.mode == RTE_FC_FULL))
6801                         rx_fc_en = 1;
6802                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6803                     (fc_conf.mode == RTE_FC_FULL))
6804                         tx_fc_en = 1;
6805         }
6806
6807         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6808                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6809
6810         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6811                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6812
6813         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6814
6815         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6816                 fc_conf.high_water = res->high_water;
6817
6818         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6819                 fc_conf.low_water = res->low_water;
6820
6821         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6822                 fc_conf.pause_time = res->pause_time;
6823
6824         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6825                 fc_conf.send_xon = res->send_xon;
6826
6827         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6828                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6829                         fc_conf.mac_ctrl_frame_fwd = 1;
6830                 else
6831                         fc_conf.mac_ctrl_frame_fwd = 0;
6832         }
6833
6834         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6835                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6836
6837         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6838         if (ret != 0)
6839                 printf("bad flow contrl parameter, return code = %d \n", ret);
6840 }
6841
6842 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6843 struct cmd_priority_flow_ctrl_set_result {
6844         cmdline_fixed_string_t set;
6845         cmdline_fixed_string_t pfc_ctrl;
6846         cmdline_fixed_string_t rx;
6847         cmdline_fixed_string_t rx_pfc_mode;
6848         cmdline_fixed_string_t tx;
6849         cmdline_fixed_string_t tx_pfc_mode;
6850         uint32_t high_water;
6851         uint32_t low_water;
6852         uint16_t pause_time;
6853         uint8_t  priority;
6854         portid_t port_id;
6855 };
6856
6857 static void
6858 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6859                        __attribute__((unused)) struct cmdline *cl,
6860                        __attribute__((unused)) void *data)
6861 {
6862         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6863         struct rte_eth_pfc_conf pfc_conf;
6864         int rx_fc_enable, tx_fc_enable;
6865         int ret;
6866
6867         /*
6868          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6869          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6870          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6871          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6872          */
6873         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6874                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6875         };
6876
6877         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6878         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6879         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6880         pfc_conf.fc.high_water = res->high_water;
6881         pfc_conf.fc.low_water  = res->low_water;
6882         pfc_conf.fc.pause_time = res->pause_time;
6883         pfc_conf.priority      = res->priority;
6884
6885         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6886         if (ret != 0)
6887                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6888 }
6889
6890 cmdline_parse_token_string_t cmd_pfc_set_set =
6891         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6892                                 set, "set");
6893 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6894         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6895                                 pfc_ctrl, "pfc_ctrl");
6896 cmdline_parse_token_string_t cmd_pfc_set_rx =
6897         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6898                                 rx, "rx");
6899 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6900         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6901                                 rx_pfc_mode, "on#off");
6902 cmdline_parse_token_string_t cmd_pfc_set_tx =
6903         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6904                                 tx, "tx");
6905 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6906         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6907                                 tx_pfc_mode, "on#off");
6908 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6909         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6910                                 high_water, UINT32);
6911 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6912         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6913                                 low_water, UINT32);
6914 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6915         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6916                                 pause_time, UINT16);
6917 cmdline_parse_token_num_t cmd_pfc_set_priority =
6918         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6919                                 priority, UINT8);
6920 cmdline_parse_token_num_t cmd_pfc_set_portid =
6921         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6922                                 port_id, UINT16);
6923
6924 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6925         .f = cmd_priority_flow_ctrl_set_parsed,
6926         .data = NULL,
6927         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6928                 "<pause_time> <priority> <port_id>: "
6929                 "Configure the Ethernet priority flow control",
6930         .tokens = {
6931                 (void *)&cmd_pfc_set_set,
6932                 (void *)&cmd_pfc_set_flow_ctrl,
6933                 (void *)&cmd_pfc_set_rx,
6934                 (void *)&cmd_pfc_set_rx_mode,
6935                 (void *)&cmd_pfc_set_tx,
6936                 (void *)&cmd_pfc_set_tx_mode,
6937                 (void *)&cmd_pfc_set_high_water,
6938                 (void *)&cmd_pfc_set_low_water,
6939                 (void *)&cmd_pfc_set_pause_time,
6940                 (void *)&cmd_pfc_set_priority,
6941                 (void *)&cmd_pfc_set_portid,
6942                 NULL,
6943         },
6944 };
6945
6946 /* *** RESET CONFIGURATION *** */
6947 struct cmd_reset_result {
6948         cmdline_fixed_string_t reset;
6949         cmdline_fixed_string_t def;
6950 };
6951
6952 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6953                              struct cmdline *cl,
6954                              __attribute__((unused)) void *data)
6955 {
6956         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6957         set_def_fwd_config();
6958 }
6959
6960 cmdline_parse_token_string_t cmd_reset_set =
6961         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6962 cmdline_parse_token_string_t cmd_reset_def =
6963         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6964                                  "default");
6965
6966 cmdline_parse_inst_t cmd_reset = {
6967         .f = cmd_reset_parsed,
6968         .data = NULL,
6969         .help_str = "set default: Reset default forwarding configuration",
6970         .tokens = {
6971                 (void *)&cmd_reset_set,
6972                 (void *)&cmd_reset_def,
6973                 NULL,
6974         },
6975 };
6976
6977 /* *** START FORWARDING *** */
6978 struct cmd_start_result {
6979         cmdline_fixed_string_t start;
6980 };
6981
6982 cmdline_parse_token_string_t cmd_start_start =
6983         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6984
6985 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6986                              __attribute__((unused)) struct cmdline *cl,
6987                              __attribute__((unused)) void *data)
6988 {
6989         start_packet_forwarding(0);
6990 }
6991
6992 cmdline_parse_inst_t cmd_start = {
6993         .f = cmd_start_parsed,
6994         .data = NULL,
6995         .help_str = "start: Start packet forwarding",
6996         .tokens = {
6997                 (void *)&cmd_start_start,
6998                 NULL,
6999         },
7000 };
7001
7002 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7003 struct cmd_start_tx_first_result {
7004         cmdline_fixed_string_t start;
7005         cmdline_fixed_string_t tx_first;
7006 };
7007
7008 static void
7009 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7010                           __attribute__((unused)) struct cmdline *cl,
7011                           __attribute__((unused)) void *data)
7012 {
7013         start_packet_forwarding(1);
7014 }
7015
7016 cmdline_parse_token_string_t cmd_start_tx_first_start =
7017         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7018                                  "start");
7019 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7020         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7021                                  tx_first, "tx_first");
7022
7023 cmdline_parse_inst_t cmd_start_tx_first = {
7024         .f = cmd_start_tx_first_parsed,
7025         .data = NULL,
7026         .help_str = "start tx_first: Start packet forwarding, "
7027                 "after sending 1 burst of packets",
7028         .tokens = {
7029                 (void *)&cmd_start_tx_first_start,
7030                 (void *)&cmd_start_tx_first_tx_first,
7031                 NULL,
7032         },
7033 };
7034
7035 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7036 struct cmd_start_tx_first_n_result {
7037         cmdline_fixed_string_t start;
7038         cmdline_fixed_string_t tx_first;
7039         uint32_t tx_num;
7040 };
7041
7042 static void
7043 cmd_start_tx_first_n_parsed(void *parsed_result,
7044                           __attribute__((unused)) struct cmdline *cl,
7045                           __attribute__((unused)) void *data)
7046 {
7047         struct cmd_start_tx_first_n_result *res = parsed_result;
7048
7049         start_packet_forwarding(res->tx_num);
7050 }
7051
7052 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7053         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7054                         start, "start");
7055 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7056         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7057                         tx_first, "tx_first");
7058 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7059         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7060                         tx_num, UINT32);
7061
7062 cmdline_parse_inst_t cmd_start_tx_first_n = {
7063         .f = cmd_start_tx_first_n_parsed,
7064         .data = NULL,
7065         .help_str = "start tx_first <num>: "
7066                 "packet forwarding, after sending <num> bursts of packets",
7067         .tokens = {
7068                 (void *)&cmd_start_tx_first_n_start,
7069                 (void *)&cmd_start_tx_first_n_tx_first,
7070                 (void *)&cmd_start_tx_first_n_tx_num,
7071                 NULL,
7072         },
7073 };
7074
7075 /* *** SET LINK UP *** */
7076 struct cmd_set_link_up_result {
7077         cmdline_fixed_string_t set;
7078         cmdline_fixed_string_t link_up;
7079         cmdline_fixed_string_t port;
7080         portid_t port_id;
7081 };
7082
7083 cmdline_parse_token_string_t cmd_set_link_up_set =
7084         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7085 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7086         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7087                                 "link-up");
7088 cmdline_parse_token_string_t cmd_set_link_up_port =
7089         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7090 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7091         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7092
7093 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7094                              __attribute__((unused)) struct cmdline *cl,
7095                              __attribute__((unused)) void *data)
7096 {
7097         struct cmd_set_link_up_result *res = parsed_result;
7098         dev_set_link_up(res->port_id);
7099 }
7100
7101 cmdline_parse_inst_t cmd_set_link_up = {
7102         .f = cmd_set_link_up_parsed,
7103         .data = NULL,
7104         .help_str = "set link-up port <port id>",
7105         .tokens = {
7106                 (void *)&cmd_set_link_up_set,
7107                 (void *)&cmd_set_link_up_link_up,
7108                 (void *)&cmd_set_link_up_port,
7109                 (void *)&cmd_set_link_up_port_id,
7110                 NULL,
7111         },
7112 };
7113
7114 /* *** SET LINK DOWN *** */
7115 struct cmd_set_link_down_result {
7116         cmdline_fixed_string_t set;
7117         cmdline_fixed_string_t link_down;
7118         cmdline_fixed_string_t port;
7119         portid_t port_id;
7120 };
7121
7122 cmdline_parse_token_string_t cmd_set_link_down_set =
7123         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7124 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7125         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7126                                 "link-down");
7127 cmdline_parse_token_string_t cmd_set_link_down_port =
7128         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7129 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7130         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7131
7132 static void cmd_set_link_down_parsed(
7133                                 __attribute__((unused)) void *parsed_result,
7134                                 __attribute__((unused)) struct cmdline *cl,
7135                                 __attribute__((unused)) void *data)
7136 {
7137         struct cmd_set_link_down_result *res = parsed_result;
7138         dev_set_link_down(res->port_id);
7139 }
7140
7141 cmdline_parse_inst_t cmd_set_link_down = {
7142         .f = cmd_set_link_down_parsed,
7143         .data = NULL,
7144         .help_str = "set link-down port <port id>",
7145         .tokens = {
7146                 (void *)&cmd_set_link_down_set,
7147                 (void *)&cmd_set_link_down_link_down,
7148                 (void *)&cmd_set_link_down_port,
7149                 (void *)&cmd_set_link_down_port_id,
7150                 NULL,
7151         },
7152 };
7153
7154 /* *** SHOW CFG *** */
7155 struct cmd_showcfg_result {
7156         cmdline_fixed_string_t show;
7157         cmdline_fixed_string_t cfg;
7158         cmdline_fixed_string_t what;
7159 };
7160
7161 static void cmd_showcfg_parsed(void *parsed_result,
7162                                __attribute__((unused)) struct cmdline *cl,
7163                                __attribute__((unused)) void *data)
7164 {
7165         struct cmd_showcfg_result *res = parsed_result;
7166         if (!strcmp(res->what, "rxtx"))
7167                 rxtx_config_display();
7168         else if (!strcmp(res->what, "cores"))
7169                 fwd_lcores_config_display();
7170         else if (!strcmp(res->what, "fwd"))
7171                 pkt_fwd_config_display(&cur_fwd_config);
7172         else if (!strcmp(res->what, "txpkts"))
7173                 show_tx_pkt_segments();
7174 }
7175
7176 cmdline_parse_token_string_t cmd_showcfg_show =
7177         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7178 cmdline_parse_token_string_t cmd_showcfg_port =
7179         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7180 cmdline_parse_token_string_t cmd_showcfg_what =
7181         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7182                                  "rxtx#cores#fwd#txpkts");
7183
7184 cmdline_parse_inst_t cmd_showcfg = {
7185         .f = cmd_showcfg_parsed,
7186         .data = NULL,
7187         .help_str = "show config rxtx|cores|fwd|txpkts",
7188         .tokens = {
7189                 (void *)&cmd_showcfg_show,
7190                 (void *)&cmd_showcfg_port,
7191                 (void *)&cmd_showcfg_what,
7192                 NULL,
7193         },
7194 };
7195
7196 /* *** SHOW ALL PORT INFO *** */
7197 struct cmd_showportall_result {
7198         cmdline_fixed_string_t show;
7199         cmdline_fixed_string_t port;
7200         cmdline_fixed_string_t what;
7201         cmdline_fixed_string_t all;
7202 };
7203
7204 static void cmd_showportall_parsed(void *parsed_result,
7205                                 __attribute__((unused)) struct cmdline *cl,
7206                                 __attribute__((unused)) void *data)
7207 {
7208         portid_t i;
7209
7210         struct cmd_showportall_result *res = parsed_result;
7211         if (!strcmp(res->show, "clear")) {
7212                 if (!strcmp(res->what, "stats"))
7213                         RTE_ETH_FOREACH_DEV(i)
7214                                 nic_stats_clear(i);
7215                 else if (!strcmp(res->what, "xstats"))
7216                         RTE_ETH_FOREACH_DEV(i)
7217                                 nic_xstats_clear(i);
7218         } else if (!strcmp(res->what, "info"))
7219                 RTE_ETH_FOREACH_DEV(i)
7220                         port_infos_display(i);
7221         else if (!strcmp(res->what, "summary")) {
7222                 port_summary_header_display();
7223                 RTE_ETH_FOREACH_DEV(i)
7224                         port_summary_display(i);
7225         }
7226         else if (!strcmp(res->what, "stats"))
7227                 RTE_ETH_FOREACH_DEV(i)
7228                         nic_stats_display(i);
7229         else if (!strcmp(res->what, "xstats"))
7230                 RTE_ETH_FOREACH_DEV(i)
7231                         nic_xstats_display(i);
7232         else if (!strcmp(res->what, "fdir"))
7233                 RTE_ETH_FOREACH_DEV(i)
7234                         fdir_get_infos(i);
7235         else if (!strcmp(res->what, "stat_qmap"))
7236                 RTE_ETH_FOREACH_DEV(i)
7237                         nic_stats_mapping_display(i);
7238         else if (!strcmp(res->what, "dcb_tc"))
7239                 RTE_ETH_FOREACH_DEV(i)
7240                         port_dcb_info_display(i);
7241         else if (!strcmp(res->what, "cap"))
7242                 RTE_ETH_FOREACH_DEV(i)
7243                         port_offload_cap_display(i);
7244 }
7245
7246 cmdline_parse_token_string_t cmd_showportall_show =
7247         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7248                                  "show#clear");
7249 cmdline_parse_token_string_t cmd_showportall_port =
7250         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7251 cmdline_parse_token_string_t cmd_showportall_what =
7252         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7253                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7254 cmdline_parse_token_string_t cmd_showportall_all =
7255         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7256 cmdline_parse_inst_t cmd_showportall = {
7257         .f = cmd_showportall_parsed,
7258         .data = NULL,
7259         .help_str = "show|clear port "
7260                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7261         .tokens = {
7262                 (void *)&cmd_showportall_show,
7263                 (void *)&cmd_showportall_port,
7264                 (void *)&cmd_showportall_what,
7265                 (void *)&cmd_showportall_all,
7266                 NULL,
7267         },
7268 };
7269
7270 /* *** SHOW PORT INFO *** */
7271 struct cmd_showport_result {
7272         cmdline_fixed_string_t show;
7273         cmdline_fixed_string_t port;
7274         cmdline_fixed_string_t what;
7275         uint16_t portnum;
7276 };
7277
7278 static void cmd_showport_parsed(void *parsed_result,
7279                                 __attribute__((unused)) struct cmdline *cl,
7280                                 __attribute__((unused)) void *data)
7281 {
7282         struct cmd_showport_result *res = parsed_result;
7283         if (!strcmp(res->show, "clear")) {
7284                 if (!strcmp(res->what, "stats"))
7285                         nic_stats_clear(res->portnum);
7286                 else if (!strcmp(res->what, "xstats"))
7287                         nic_xstats_clear(res->portnum);
7288         } else if (!strcmp(res->what, "info"))
7289                 port_infos_display(res->portnum);
7290         else if (!strcmp(res->what, "summary")) {
7291                 port_summary_header_display();
7292                 port_summary_display(res->portnum);
7293         }
7294         else if (!strcmp(res->what, "stats"))
7295                 nic_stats_display(res->portnum);
7296         else if (!strcmp(res->what, "xstats"))
7297                 nic_xstats_display(res->portnum);
7298         else if (!strcmp(res->what, "fdir"))
7299                  fdir_get_infos(res->portnum);
7300         else if (!strcmp(res->what, "stat_qmap"))
7301                 nic_stats_mapping_display(res->portnum);
7302         else if (!strcmp(res->what, "dcb_tc"))
7303                 port_dcb_info_display(res->portnum);
7304         else if (!strcmp(res->what, "cap"))
7305                 port_offload_cap_display(res->portnum);
7306 }
7307
7308 cmdline_parse_token_string_t cmd_showport_show =
7309         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7310                                  "show#clear");
7311 cmdline_parse_token_string_t cmd_showport_port =
7312         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7313 cmdline_parse_token_string_t cmd_showport_what =
7314         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7315                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7316 cmdline_parse_token_num_t cmd_showport_portnum =
7317         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7318
7319 cmdline_parse_inst_t cmd_showport = {
7320         .f = cmd_showport_parsed,
7321         .data = NULL,
7322         .help_str = "show|clear port "
7323                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7324                 "<port_id>",
7325         .tokens = {
7326                 (void *)&cmd_showport_show,
7327                 (void *)&cmd_showport_port,
7328                 (void *)&cmd_showport_what,
7329                 (void *)&cmd_showport_portnum,
7330                 NULL,
7331         },
7332 };
7333
7334 /* *** SHOW QUEUE INFO *** */
7335 struct cmd_showqueue_result {
7336         cmdline_fixed_string_t show;
7337         cmdline_fixed_string_t type;
7338         cmdline_fixed_string_t what;
7339         uint16_t portnum;
7340         uint16_t queuenum;
7341 };
7342
7343 static void
7344 cmd_showqueue_parsed(void *parsed_result,
7345         __attribute__((unused)) struct cmdline *cl,
7346         __attribute__((unused)) void *data)
7347 {
7348         struct cmd_showqueue_result *res = parsed_result;
7349
7350         if (!strcmp(res->type, "rxq"))
7351                 rx_queue_infos_display(res->portnum, res->queuenum);
7352         else if (!strcmp(res->type, "txq"))
7353                 tx_queue_infos_display(res->portnum, res->queuenum);
7354 }
7355
7356 cmdline_parse_token_string_t cmd_showqueue_show =
7357         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7358 cmdline_parse_token_string_t cmd_showqueue_type =
7359         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7360 cmdline_parse_token_string_t cmd_showqueue_what =
7361         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7362 cmdline_parse_token_num_t cmd_showqueue_portnum =
7363         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7364 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7365         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7366
7367 cmdline_parse_inst_t cmd_showqueue = {
7368         .f = cmd_showqueue_parsed,
7369         .data = NULL,
7370         .help_str = "show rxq|txq info <port_id> <queue_id>",
7371         .tokens = {
7372                 (void *)&cmd_showqueue_show,
7373                 (void *)&cmd_showqueue_type,
7374                 (void *)&cmd_showqueue_what,
7375                 (void *)&cmd_showqueue_portnum,
7376                 (void *)&cmd_showqueue_queuenum,
7377                 NULL,
7378         },
7379 };
7380
7381 /* *** READ PORT REGISTER *** */
7382 struct cmd_read_reg_result {
7383         cmdline_fixed_string_t read;
7384         cmdline_fixed_string_t reg;
7385         portid_t port_id;
7386         uint32_t reg_off;
7387 };
7388
7389 static void
7390 cmd_read_reg_parsed(void *parsed_result,
7391                     __attribute__((unused)) struct cmdline *cl,
7392                     __attribute__((unused)) void *data)
7393 {
7394         struct cmd_read_reg_result *res = parsed_result;
7395         port_reg_display(res->port_id, res->reg_off);
7396 }
7397
7398 cmdline_parse_token_string_t cmd_read_reg_read =
7399         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7400 cmdline_parse_token_string_t cmd_read_reg_reg =
7401         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7402 cmdline_parse_token_num_t cmd_read_reg_port_id =
7403         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7404 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7405         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7406
7407 cmdline_parse_inst_t cmd_read_reg = {
7408         .f = cmd_read_reg_parsed,
7409         .data = NULL,
7410         .help_str = "read reg <port_id> <reg_off>",
7411         .tokens = {
7412                 (void *)&cmd_read_reg_read,
7413                 (void *)&cmd_read_reg_reg,
7414                 (void *)&cmd_read_reg_port_id,
7415                 (void *)&cmd_read_reg_reg_off,
7416                 NULL,
7417         },
7418 };
7419
7420 /* *** READ PORT REGISTER BIT FIELD *** */
7421 struct cmd_read_reg_bit_field_result {
7422         cmdline_fixed_string_t read;
7423         cmdline_fixed_string_t regfield;
7424         portid_t port_id;
7425         uint32_t reg_off;
7426         uint8_t bit1_pos;
7427         uint8_t bit2_pos;
7428 };
7429
7430 static void
7431 cmd_read_reg_bit_field_parsed(void *parsed_result,
7432                               __attribute__((unused)) struct cmdline *cl,
7433                               __attribute__((unused)) void *data)
7434 {
7435         struct cmd_read_reg_bit_field_result *res = parsed_result;
7436         port_reg_bit_field_display(res->port_id, res->reg_off,
7437                                    res->bit1_pos, res->bit2_pos);
7438 }
7439
7440 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7441         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7442                                  "read");
7443 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7444         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7445                                  regfield, "regfield");
7446 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7447         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7448                               UINT16);
7449 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7450         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7451                               UINT32);
7452 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7453         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7454                               UINT8);
7455 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7456         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7457                               UINT8);
7458
7459 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7460         .f = cmd_read_reg_bit_field_parsed,
7461         .data = NULL,
7462         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7463         "Read register bit field between bit_x and bit_y included",
7464         .tokens = {
7465                 (void *)&cmd_read_reg_bit_field_read,
7466                 (void *)&cmd_read_reg_bit_field_regfield,
7467                 (void *)&cmd_read_reg_bit_field_port_id,
7468                 (void *)&cmd_read_reg_bit_field_reg_off,
7469                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7470                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7471                 NULL,
7472         },
7473 };
7474
7475 /* *** READ PORT REGISTER BIT *** */
7476 struct cmd_read_reg_bit_result {
7477         cmdline_fixed_string_t read;
7478         cmdline_fixed_string_t regbit;
7479         portid_t port_id;
7480         uint32_t reg_off;
7481         uint8_t bit_pos;
7482 };
7483
7484 static void
7485 cmd_read_reg_bit_parsed(void *parsed_result,
7486                         __attribute__((unused)) struct cmdline *cl,
7487                         __attribute__((unused)) void *data)
7488 {
7489         struct cmd_read_reg_bit_result *res = parsed_result;
7490         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7491 }
7492
7493 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7494         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7495 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7496         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7497                                  regbit, "regbit");
7498 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7499         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7500 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7501         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7502 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7503         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7504
7505 cmdline_parse_inst_t cmd_read_reg_bit = {
7506         .f = cmd_read_reg_bit_parsed,
7507         .data = NULL,
7508         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7509         .tokens = {
7510                 (void *)&cmd_read_reg_bit_read,
7511                 (void *)&cmd_read_reg_bit_regbit,
7512                 (void *)&cmd_read_reg_bit_port_id,
7513                 (void *)&cmd_read_reg_bit_reg_off,
7514                 (void *)&cmd_read_reg_bit_bit_pos,
7515                 NULL,
7516         },
7517 };
7518
7519 /* *** WRITE PORT REGISTER *** */
7520 struct cmd_write_reg_result {
7521         cmdline_fixed_string_t write;
7522         cmdline_fixed_string_t reg;
7523         portid_t port_id;
7524         uint32_t reg_off;
7525         uint32_t value;
7526 };
7527
7528 static void
7529 cmd_write_reg_parsed(void *parsed_result,
7530                      __attribute__((unused)) struct cmdline *cl,
7531                      __attribute__((unused)) void *data)
7532 {
7533         struct cmd_write_reg_result *res = parsed_result;
7534         port_reg_set(res->port_id, res->reg_off, res->value);
7535 }
7536
7537 cmdline_parse_token_string_t cmd_write_reg_write =
7538         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7539 cmdline_parse_token_string_t cmd_write_reg_reg =
7540         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7541 cmdline_parse_token_num_t cmd_write_reg_port_id =
7542         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7543 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7544         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7545 cmdline_parse_token_num_t cmd_write_reg_value =
7546         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7547
7548 cmdline_parse_inst_t cmd_write_reg = {
7549         .f = cmd_write_reg_parsed,
7550         .data = NULL,
7551         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7552         .tokens = {
7553                 (void *)&cmd_write_reg_write,
7554                 (void *)&cmd_write_reg_reg,
7555                 (void *)&cmd_write_reg_port_id,
7556                 (void *)&cmd_write_reg_reg_off,
7557                 (void *)&cmd_write_reg_value,
7558                 NULL,
7559         },
7560 };
7561
7562 /* *** WRITE PORT REGISTER BIT FIELD *** */
7563 struct cmd_write_reg_bit_field_result {
7564         cmdline_fixed_string_t write;
7565         cmdline_fixed_string_t regfield;
7566         portid_t port_id;
7567         uint32_t reg_off;
7568         uint8_t bit1_pos;
7569         uint8_t bit2_pos;
7570         uint32_t value;
7571 };
7572
7573 static void
7574 cmd_write_reg_bit_field_parsed(void *parsed_result,
7575                                __attribute__((unused)) struct cmdline *cl,
7576                                __attribute__((unused)) void *data)
7577 {
7578         struct cmd_write_reg_bit_field_result *res = parsed_result;
7579         port_reg_bit_field_set(res->port_id, res->reg_off,
7580                           res->bit1_pos, res->bit2_pos, res->value);
7581 }
7582
7583 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7584         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7585                                  "write");
7586 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7587         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7588                                  regfield, "regfield");
7589 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7590         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7591                               UINT16);
7592 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7593         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7594                               UINT32);
7595 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7596         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7597                               UINT8);
7598 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7599         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7600                               UINT8);
7601 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7602         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7603                               UINT32);
7604
7605 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7606         .f = cmd_write_reg_bit_field_parsed,
7607         .data = NULL,
7608         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7609                 "<reg_value>: "
7610                 "Set register bit field between bit_x and bit_y included",
7611         .tokens = {
7612                 (void *)&cmd_write_reg_bit_field_write,
7613                 (void *)&cmd_write_reg_bit_field_regfield,
7614                 (void *)&cmd_write_reg_bit_field_port_id,
7615                 (void *)&cmd_write_reg_bit_field_reg_off,
7616                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7617                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7618                 (void *)&cmd_write_reg_bit_field_value,
7619                 NULL,
7620         },
7621 };
7622
7623 /* *** WRITE PORT REGISTER BIT *** */
7624 struct cmd_write_reg_bit_result {
7625         cmdline_fixed_string_t write;
7626         cmdline_fixed_string_t regbit;
7627         portid_t port_id;
7628         uint32_t reg_off;
7629         uint8_t bit_pos;
7630         uint8_t value;
7631 };
7632
7633 static void
7634 cmd_write_reg_bit_parsed(void *parsed_result,
7635                          __attribute__((unused)) struct cmdline *cl,
7636                          __attribute__((unused)) void *data)
7637 {
7638         struct cmd_write_reg_bit_result *res = parsed_result;
7639         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7640 }
7641
7642 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7643         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7644                                  "write");
7645 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7646         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7647                                  regbit, "regbit");
7648 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7649         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7650 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7651         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7652 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7653         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7654 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7655         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7656
7657 cmdline_parse_inst_t cmd_write_reg_bit = {
7658         .f = cmd_write_reg_bit_parsed,
7659         .data = NULL,
7660         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7661                 "0 <= bit_x <= 31",
7662         .tokens = {
7663                 (void *)&cmd_write_reg_bit_write,
7664                 (void *)&cmd_write_reg_bit_regbit,
7665                 (void *)&cmd_write_reg_bit_port_id,
7666                 (void *)&cmd_write_reg_bit_reg_off,
7667                 (void *)&cmd_write_reg_bit_bit_pos,
7668                 (void *)&cmd_write_reg_bit_value,
7669                 NULL,
7670         },
7671 };
7672
7673 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7674 struct cmd_read_rxd_txd_result {
7675         cmdline_fixed_string_t read;
7676         cmdline_fixed_string_t rxd_txd;
7677         portid_t port_id;
7678         uint16_t queue_id;
7679         uint16_t desc_id;
7680 };
7681
7682 static void
7683 cmd_read_rxd_txd_parsed(void *parsed_result,
7684                         __attribute__((unused)) struct cmdline *cl,
7685                         __attribute__((unused)) void *data)
7686 {
7687         struct cmd_read_rxd_txd_result *res = parsed_result;
7688
7689         if (!strcmp(res->rxd_txd, "rxd"))
7690                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7691         else if (!strcmp(res->rxd_txd, "txd"))
7692                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7693 }
7694
7695 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7696         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7697 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7698         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7699                                  "rxd#txd");
7700 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7701         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7702 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7703         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7704 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7705         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7706
7707 cmdline_parse_inst_t cmd_read_rxd_txd = {
7708         .f = cmd_read_rxd_txd_parsed,
7709         .data = NULL,
7710         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7711         .tokens = {
7712                 (void *)&cmd_read_rxd_txd_read,
7713                 (void *)&cmd_read_rxd_txd_rxd_txd,
7714                 (void *)&cmd_read_rxd_txd_port_id,
7715                 (void *)&cmd_read_rxd_txd_queue_id,
7716                 (void *)&cmd_read_rxd_txd_desc_id,
7717                 NULL,
7718         },
7719 };
7720
7721 /* *** QUIT *** */
7722 struct cmd_quit_result {
7723         cmdline_fixed_string_t quit;
7724 };
7725
7726 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7727                             struct cmdline *cl,
7728                             __attribute__((unused)) void *data)
7729 {
7730         cmdline_quit(cl);
7731 }
7732
7733 cmdline_parse_token_string_t cmd_quit_quit =
7734         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7735
7736 cmdline_parse_inst_t cmd_quit = {
7737         .f = cmd_quit_parsed,
7738         .data = NULL,
7739         .help_str = "quit: Exit application",
7740         .tokens = {
7741                 (void *)&cmd_quit_quit,
7742                 NULL,
7743         },
7744 };
7745
7746 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7747 struct cmd_mac_addr_result {
7748         cmdline_fixed_string_t mac_addr_cmd;
7749         cmdline_fixed_string_t what;
7750         uint16_t port_num;
7751         struct ether_addr address;
7752 };
7753
7754 static void cmd_mac_addr_parsed(void *parsed_result,
7755                 __attribute__((unused)) struct cmdline *cl,
7756                 __attribute__((unused)) void *data)
7757 {
7758         struct cmd_mac_addr_result *res = parsed_result;
7759         int ret;
7760
7761         if (strcmp(res->what, "add") == 0)
7762                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7763         else if (strcmp(res->what, "set") == 0)
7764                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7765                                                        &res->address);
7766         else
7767                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7768
7769         /* check the return value and print it if is < 0 */
7770         if(ret < 0)
7771                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7772
7773 }
7774
7775 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7776         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7777                                 "mac_addr");
7778 cmdline_parse_token_string_t cmd_mac_addr_what =
7779         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7780                                 "add#remove#set");
7781 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7782                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7783                                         UINT16);
7784 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7785                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7786
7787 cmdline_parse_inst_t cmd_mac_addr = {
7788         .f = cmd_mac_addr_parsed,
7789         .data = (void *)0,
7790         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7791                         "Add/Remove/Set MAC address on port_id",
7792         .tokens = {
7793                 (void *)&cmd_mac_addr_cmd,
7794                 (void *)&cmd_mac_addr_what,
7795                 (void *)&cmd_mac_addr_portnum,
7796                 (void *)&cmd_mac_addr_addr,
7797                 NULL,
7798         },
7799 };
7800
7801 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7802 struct cmd_eth_peer_result {
7803         cmdline_fixed_string_t set;
7804         cmdline_fixed_string_t eth_peer;
7805         portid_t port_id;
7806         cmdline_fixed_string_t peer_addr;
7807 };
7808
7809 static void cmd_set_eth_peer_parsed(void *parsed_result,
7810                         __attribute__((unused)) struct cmdline *cl,
7811                         __attribute__((unused)) void *data)
7812 {
7813                 struct cmd_eth_peer_result *res = parsed_result;
7814
7815                 if (test_done == 0) {
7816                         printf("Please stop forwarding first\n");
7817                         return;
7818                 }
7819                 if (!strcmp(res->eth_peer, "eth-peer")) {
7820                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7821                         fwd_config_setup();
7822                 }
7823 }
7824 cmdline_parse_token_string_t cmd_eth_peer_set =
7825         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7826 cmdline_parse_token_string_t cmd_eth_peer =
7827         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7828 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7829         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7830 cmdline_parse_token_string_t cmd_eth_peer_addr =
7831         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7832
7833 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7834         .f = cmd_set_eth_peer_parsed,
7835         .data = NULL,
7836         .help_str = "set eth-peer <port_id> <peer_mac>",
7837         .tokens = {
7838                 (void *)&cmd_eth_peer_set,
7839                 (void *)&cmd_eth_peer,
7840                 (void *)&cmd_eth_peer_port_id,
7841                 (void *)&cmd_eth_peer_addr,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7847 struct cmd_set_qmap_result {
7848         cmdline_fixed_string_t set;
7849         cmdline_fixed_string_t qmap;
7850         cmdline_fixed_string_t what;
7851         portid_t port_id;
7852         uint16_t queue_id;
7853         uint8_t map_value;
7854 };
7855
7856 static void
7857 cmd_set_qmap_parsed(void *parsed_result,
7858                        __attribute__((unused)) struct cmdline *cl,
7859                        __attribute__((unused)) void *data)
7860 {
7861         struct cmd_set_qmap_result *res = parsed_result;
7862         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7863
7864         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7865 }
7866
7867 cmdline_parse_token_string_t cmd_setqmap_set =
7868         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7869                                  set, "set");
7870 cmdline_parse_token_string_t cmd_setqmap_qmap =
7871         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7872                                  qmap, "stat_qmap");
7873 cmdline_parse_token_string_t cmd_setqmap_what =
7874         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7875                                  what, "tx#rx");
7876 cmdline_parse_token_num_t cmd_setqmap_portid =
7877         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7878                               port_id, UINT16);
7879 cmdline_parse_token_num_t cmd_setqmap_queueid =
7880         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7881                               queue_id, UINT16);
7882 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7883         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7884                               map_value, UINT8);
7885
7886 cmdline_parse_inst_t cmd_set_qmap = {
7887         .f = cmd_set_qmap_parsed,
7888         .data = NULL,
7889         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7890                 "Set statistics mapping value on tx|rx queue_id of port_id",
7891         .tokens = {
7892                 (void *)&cmd_setqmap_set,
7893                 (void *)&cmd_setqmap_qmap,
7894                 (void *)&cmd_setqmap_what,
7895                 (void *)&cmd_setqmap_portid,
7896                 (void *)&cmd_setqmap_queueid,
7897                 (void *)&cmd_setqmap_mapvalue,
7898                 NULL,
7899         },
7900 };
7901
7902 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7903 struct cmd_set_xstats_hide_zero_result {
7904         cmdline_fixed_string_t keyword;
7905         cmdline_fixed_string_t name;
7906         cmdline_fixed_string_t on_off;
7907 };
7908
7909 static void
7910 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7911                         __attribute__((unused)) struct cmdline *cl,
7912                         __attribute__((unused)) void *data)
7913 {
7914         struct cmd_set_xstats_hide_zero_result *res;
7915         uint16_t on_off = 0;
7916
7917         res = parsed_result;
7918         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7919         set_xstats_hide_zero(on_off);
7920 }
7921
7922 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7923         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7924                                  keyword, "set");
7925 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7926         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7927                                  name, "xstats-hide-zero");
7928 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7929         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7930                                  on_off, "on#off");
7931
7932 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7933         .f = cmd_set_xstats_hide_zero_parsed,
7934         .data = NULL,
7935         .help_str = "set xstats-hide-zero on|off",
7936         .tokens = {
7937                 (void *)&cmd_set_xstats_hide_zero_keyword,
7938                 (void *)&cmd_set_xstats_hide_zero_name,
7939                 (void *)&cmd_set_xstats_hide_zero_on_off,
7940                 NULL,
7941         },
7942 };
7943
7944 /* *** CONFIGURE UNICAST HASH TABLE *** */
7945 struct cmd_set_uc_hash_table {
7946         cmdline_fixed_string_t set;
7947         cmdline_fixed_string_t port;
7948         portid_t port_id;
7949         cmdline_fixed_string_t what;
7950         struct ether_addr address;
7951         cmdline_fixed_string_t mode;
7952 };
7953
7954 static void
7955 cmd_set_uc_hash_parsed(void *parsed_result,
7956                        __attribute__((unused)) struct cmdline *cl,
7957                        __attribute__((unused)) void *data)
7958 {
7959         int ret=0;
7960         struct cmd_set_uc_hash_table *res = parsed_result;
7961
7962         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7963
7964         if (strcmp(res->what, "uta") == 0)
7965                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7966                                                 &res->address,(uint8_t)is_on);
7967         if (ret < 0)
7968                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7969
7970 }
7971
7972 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7973         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7974                                  set, "set");
7975 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7976         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7977                                  port, "port");
7978 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7979         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7980                               port_id, UINT16);
7981 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7982         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7983                                  what, "uta");
7984 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7985         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7986                                 address);
7987 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7988         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7989                                  mode, "on#off");
7990
7991 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7992         .f = cmd_set_uc_hash_parsed,
7993         .data = NULL,
7994         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7995         .tokens = {
7996                 (void *)&cmd_set_uc_hash_set,
7997                 (void *)&cmd_set_uc_hash_port,
7998                 (void *)&cmd_set_uc_hash_portid,
7999                 (void *)&cmd_set_uc_hash_what,
8000                 (void *)&cmd_set_uc_hash_mac,
8001                 (void *)&cmd_set_uc_hash_mode,
8002                 NULL,
8003         },
8004 };
8005
8006 struct cmd_set_uc_all_hash_table {
8007         cmdline_fixed_string_t set;
8008         cmdline_fixed_string_t port;
8009         portid_t port_id;
8010         cmdline_fixed_string_t what;
8011         cmdline_fixed_string_t value;
8012         cmdline_fixed_string_t mode;
8013 };
8014
8015 static void
8016 cmd_set_uc_all_hash_parsed(void *parsed_result,
8017                        __attribute__((unused)) struct cmdline *cl,
8018                        __attribute__((unused)) void *data)
8019 {
8020         int ret=0;
8021         struct cmd_set_uc_all_hash_table *res = parsed_result;
8022
8023         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8024
8025         if ((strcmp(res->what, "uta") == 0) &&
8026                 (strcmp(res->value, "all") == 0))
8027                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8028         if (ret < 0)
8029                 printf("bad unicast hash table parameter,"
8030                         "return code = %d \n", ret);
8031 }
8032
8033 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8034         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8035                                  set, "set");
8036 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8038                                  port, "port");
8039 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8040         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8041                               port_id, UINT16);
8042 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8043         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8044                                  what, "uta");
8045 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8046         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8047                                 value,"all");
8048 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8049         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8050                                  mode, "on#off");
8051
8052 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8053         .f = cmd_set_uc_all_hash_parsed,
8054         .data = NULL,
8055         .help_str = "set port <port_id> uta all on|off",
8056         .tokens = {
8057                 (void *)&cmd_set_uc_all_hash_set,
8058                 (void *)&cmd_set_uc_all_hash_port,
8059                 (void *)&cmd_set_uc_all_hash_portid,
8060                 (void *)&cmd_set_uc_all_hash_what,
8061                 (void *)&cmd_set_uc_all_hash_value,
8062                 (void *)&cmd_set_uc_all_hash_mode,
8063                 NULL,
8064         },
8065 };
8066
8067 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8068 struct cmd_set_vf_macvlan_filter {
8069         cmdline_fixed_string_t set;
8070         cmdline_fixed_string_t port;
8071         portid_t port_id;
8072         cmdline_fixed_string_t vf;
8073         uint8_t vf_id;
8074         struct ether_addr address;
8075         cmdline_fixed_string_t filter_type;
8076         cmdline_fixed_string_t mode;
8077 };
8078
8079 static void
8080 cmd_set_vf_macvlan_parsed(void *parsed_result,
8081                        __attribute__((unused)) struct cmdline *cl,
8082                        __attribute__((unused)) void *data)
8083 {
8084         int is_on, ret = 0;
8085         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8086         struct rte_eth_mac_filter filter;
8087
8088         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8089
8090         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8091
8092         /* set VF MAC filter */
8093         filter.is_vf = 1;
8094
8095         /* set VF ID */
8096         filter.dst_id = res->vf_id;
8097
8098         if (!strcmp(res->filter_type, "exact-mac"))
8099                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8100         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8101                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8102         else if (!strcmp(res->filter_type, "hashmac"))
8103                 filter.filter_type = RTE_MAC_HASH_MATCH;
8104         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8105                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8106
8107         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8108
8109         if (is_on)
8110                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8111                                         RTE_ETH_FILTER_MACVLAN,
8112                                         RTE_ETH_FILTER_ADD,
8113                                          &filter);
8114         else
8115                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8116                                         RTE_ETH_FILTER_MACVLAN,
8117                                         RTE_ETH_FILTER_DELETE,
8118                                         &filter);
8119
8120         if (ret < 0)
8121                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8122
8123 }
8124
8125 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8126         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8127                                  set, "set");
8128 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8129         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8130                                  port, "port");
8131 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8132         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8133                               port_id, UINT16);
8134 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8135         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8136                                  vf, "vf");
8137 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8138         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8139                                 vf_id, UINT8);
8140 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8141         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8142                                 address);
8143 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8144         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8145                                 filter_type, "exact-mac#exact-mac-vlan"
8146                                 "#hashmac#hashmac-vlan");
8147 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8148         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8149                                  mode, "on#off");
8150
8151 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8152         .f = cmd_set_vf_macvlan_parsed,
8153         .data = NULL,
8154         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8155                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8156                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8157                 "hash match rule: hash match of MAC and exact match of VLAN",
8158         .tokens = {
8159                 (void *)&cmd_set_vf_macvlan_set,
8160                 (void *)&cmd_set_vf_macvlan_port,
8161                 (void *)&cmd_set_vf_macvlan_portid,
8162                 (void *)&cmd_set_vf_macvlan_vf,
8163                 (void *)&cmd_set_vf_macvlan_vf_id,
8164                 (void *)&cmd_set_vf_macvlan_mac,
8165                 (void *)&cmd_set_vf_macvlan_filter_type,
8166                 (void *)&cmd_set_vf_macvlan_mode,
8167                 NULL,
8168         },
8169 };
8170
8171 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8172 struct cmd_set_vf_traffic {
8173         cmdline_fixed_string_t set;
8174         cmdline_fixed_string_t port;
8175         portid_t port_id;
8176         cmdline_fixed_string_t vf;
8177         uint8_t vf_id;
8178         cmdline_fixed_string_t what;
8179         cmdline_fixed_string_t mode;
8180 };
8181
8182 static void
8183 cmd_set_vf_traffic_parsed(void *parsed_result,
8184                        __attribute__((unused)) struct cmdline *cl,
8185                        __attribute__((unused)) void *data)
8186 {
8187         struct cmd_set_vf_traffic *res = parsed_result;
8188         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8189         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8190
8191         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8192 }
8193
8194 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8195         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8196                                  set, "set");
8197 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8199                                  port, "port");
8200 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8201         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8202                               port_id, UINT16);
8203 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8205                                  vf, "vf");
8206 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8207         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8208                               vf_id, UINT8);
8209 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8210         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8211                                  what, "tx#rx");
8212 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8213         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8214                                  mode, "on#off");
8215
8216 cmdline_parse_inst_t cmd_set_vf_traffic = {
8217         .f = cmd_set_vf_traffic_parsed,
8218         .data = NULL,
8219         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8220         .tokens = {
8221                 (void *)&cmd_setvf_traffic_set,
8222                 (void *)&cmd_setvf_traffic_port,
8223                 (void *)&cmd_setvf_traffic_portid,
8224                 (void *)&cmd_setvf_traffic_vf,
8225                 (void *)&cmd_setvf_traffic_vfid,
8226                 (void *)&cmd_setvf_traffic_what,
8227                 (void *)&cmd_setvf_traffic_mode,
8228                 NULL,
8229         },
8230 };
8231
8232 /* *** CONFIGURE VF RECEIVE MODE *** */
8233 struct cmd_set_vf_rxmode {
8234         cmdline_fixed_string_t set;
8235         cmdline_fixed_string_t port;
8236         portid_t port_id;
8237         cmdline_fixed_string_t vf;
8238         uint8_t vf_id;
8239         cmdline_fixed_string_t what;
8240         cmdline_fixed_string_t mode;
8241         cmdline_fixed_string_t on;
8242 };
8243
8244 static void
8245 cmd_set_vf_rxmode_parsed(void *parsed_result,
8246                        __attribute__((unused)) struct cmdline *cl,
8247                        __attribute__((unused)) void *data)
8248 {
8249         int ret = -ENOTSUP;
8250         uint16_t rx_mode = 0;
8251         struct cmd_set_vf_rxmode *res = parsed_result;
8252
8253         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8254         if (!strcmp(res->what,"rxmode")) {
8255                 if (!strcmp(res->mode, "AUPE"))
8256                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8257                 else if (!strcmp(res->mode, "ROPE"))
8258                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8259                 else if (!strcmp(res->mode, "BAM"))
8260                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8261                 else if (!strncmp(res->mode, "MPE",3))
8262                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8263         }
8264
8265         RTE_SET_USED(is_on);
8266
8267 #ifdef RTE_LIBRTE_IXGBE_PMD
8268         if (ret == -ENOTSUP)
8269                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8270                                                   rx_mode, (uint8_t)is_on);
8271 #endif
8272 #ifdef RTE_LIBRTE_BNXT_PMD
8273         if (ret == -ENOTSUP)
8274                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8275                                                  rx_mode, (uint8_t)is_on);
8276 #endif
8277         if (ret < 0)
8278                 printf("bad VF receive mode parameter, return code = %d \n",
8279                 ret);
8280 }
8281
8282 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8283         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8284                                  set, "set");
8285 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8286         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8287                                  port, "port");
8288 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8289         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8290                               port_id, UINT16);
8291 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8292         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8293                                  vf, "vf");
8294 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8295         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8296                               vf_id, UINT8);
8297 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8298         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8299                                  what, "rxmode");
8300 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8301         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8302                                  mode, "AUPE#ROPE#BAM#MPE");
8303 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8305                                  on, "on#off");
8306
8307 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8308         .f = cmd_set_vf_rxmode_parsed,
8309         .data = NULL,
8310         .help_str = "set port <port_id> vf <vf_id> rxmode "
8311                 "AUPE|ROPE|BAM|MPE on|off",
8312         .tokens = {
8313                 (void *)&cmd_set_vf_rxmode_set,
8314                 (void *)&cmd_set_vf_rxmode_port,
8315                 (void *)&cmd_set_vf_rxmode_portid,
8316                 (void *)&cmd_set_vf_rxmode_vf,
8317                 (void *)&cmd_set_vf_rxmode_vfid,
8318                 (void *)&cmd_set_vf_rxmode_what,
8319                 (void *)&cmd_set_vf_rxmode_mode,
8320                 (void *)&cmd_set_vf_rxmode_on,
8321                 NULL,
8322         },
8323 };
8324
8325 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8326 struct cmd_vf_mac_addr_result {
8327         cmdline_fixed_string_t mac_addr_cmd;
8328         cmdline_fixed_string_t what;
8329         cmdline_fixed_string_t port;
8330         uint16_t port_num;
8331         cmdline_fixed_string_t vf;
8332         uint8_t vf_num;
8333         struct ether_addr address;
8334 };
8335
8336 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8337                 __attribute__((unused)) struct cmdline *cl,
8338                 __attribute__((unused)) void *data)
8339 {
8340         struct cmd_vf_mac_addr_result *res = parsed_result;
8341         int ret = -ENOTSUP;
8342
8343         if (strcmp(res->what, "add") != 0)
8344                 return;
8345
8346 #ifdef RTE_LIBRTE_I40E_PMD
8347         if (ret == -ENOTSUP)
8348                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8349                                                    &res->address);
8350 #endif
8351 #ifdef RTE_LIBRTE_BNXT_PMD
8352         if (ret == -ENOTSUP)
8353                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8354                                                 res->vf_num);
8355 #endif
8356
8357         if(ret < 0)
8358                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8359
8360 }
8361
8362 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8363         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8364                                 mac_addr_cmd,"mac_addr");
8365 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8366         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8367                                 what,"add");
8368 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8369         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8370                                 port,"port");
8371 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8372         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8373                                 port_num, UINT16);
8374 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8375         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8376                                 vf,"vf");
8377 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8378         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8379                                 vf_num, UINT8);
8380 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8381         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8382                                 address);
8383
8384 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8385         .f = cmd_vf_mac_addr_parsed,
8386         .data = (void *)0,
8387         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8388                 "Add MAC address filtering for a VF on port_id",
8389         .tokens = {
8390                 (void *)&cmd_vf_mac_addr_cmd,
8391                 (void *)&cmd_vf_mac_addr_what,
8392                 (void *)&cmd_vf_mac_addr_port,
8393                 (void *)&cmd_vf_mac_addr_portnum,
8394                 (void *)&cmd_vf_mac_addr_vf,
8395                 (void *)&cmd_vf_mac_addr_vfnum,
8396                 (void *)&cmd_vf_mac_addr_addr,
8397                 NULL,
8398         },
8399 };
8400
8401 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8402 struct cmd_vf_rx_vlan_filter {
8403         cmdline_fixed_string_t rx_vlan;
8404         cmdline_fixed_string_t what;
8405         uint16_t vlan_id;
8406         cmdline_fixed_string_t port;
8407         portid_t port_id;
8408         cmdline_fixed_string_t vf;
8409         uint64_t vf_mask;
8410 };
8411
8412 static void
8413 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8414                           __attribute__((unused)) struct cmdline *cl,
8415                           __attribute__((unused)) void *data)
8416 {
8417         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8418         int ret = -ENOTSUP;
8419
8420         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8421
8422 #ifdef RTE_LIBRTE_IXGBE_PMD
8423         if (ret == -ENOTSUP)
8424                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8425                                 res->vlan_id, res->vf_mask, is_add);
8426 #endif
8427 #ifdef RTE_LIBRTE_I40E_PMD
8428         if (ret == -ENOTSUP)
8429                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8430                                 res->vlan_id, res->vf_mask, is_add);
8431 #endif
8432 #ifdef RTE_LIBRTE_BNXT_PMD
8433         if (ret == -ENOTSUP)
8434                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8435                                 res->vlan_id, res->vf_mask, is_add);
8436 #endif
8437
8438         switch (ret) {
8439         case 0:
8440                 break;
8441         case -EINVAL:
8442                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8443                                 res->vlan_id, res->vf_mask);
8444                 break;
8445         case -ENODEV:
8446                 printf("invalid port_id %d\n", res->port_id);
8447                 break;
8448         case -ENOTSUP:
8449                 printf("function not implemented or supported\n");
8450                 break;
8451         default:
8452                 printf("programming error: (%s)\n", strerror(-ret));
8453         }
8454 }
8455
8456 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8457         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8458                                  rx_vlan, "rx_vlan");
8459 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8460         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8461                                  what, "add#rm");
8462 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8463         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8464                               vlan_id, UINT16);
8465 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8466         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8467                                  port, "port");
8468 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8469         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8470                               port_id, UINT16);
8471 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8472         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8473                                  vf, "vf");
8474 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8475         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8476                               vf_mask, UINT64);
8477
8478 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8479         .f = cmd_vf_rx_vlan_filter_parsed,
8480         .data = NULL,
8481         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8482                 "(vf_mask = hexadecimal VF mask)",
8483         .tokens = {
8484                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8485                 (void *)&cmd_vf_rx_vlan_filter_what,
8486                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8487                 (void *)&cmd_vf_rx_vlan_filter_port,
8488                 (void *)&cmd_vf_rx_vlan_filter_portid,
8489                 (void *)&cmd_vf_rx_vlan_filter_vf,
8490                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8491                 NULL,
8492         },
8493 };
8494
8495 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8496 struct cmd_queue_rate_limit_result {
8497         cmdline_fixed_string_t set;
8498         cmdline_fixed_string_t port;
8499         uint16_t port_num;
8500         cmdline_fixed_string_t queue;
8501         uint8_t queue_num;
8502         cmdline_fixed_string_t rate;
8503         uint16_t rate_num;
8504 };
8505
8506 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8507                 __attribute__((unused)) struct cmdline *cl,
8508                 __attribute__((unused)) void *data)
8509 {
8510         struct cmd_queue_rate_limit_result *res = parsed_result;
8511         int ret = 0;
8512
8513         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8514                 && (strcmp(res->queue, "queue") == 0)
8515                 && (strcmp(res->rate, "rate") == 0))
8516                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8517                                         res->rate_num);
8518         if (ret < 0)
8519                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8520
8521 }
8522
8523 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8524         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8525                                 set, "set");
8526 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8527         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8528                                 port, "port");
8529 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8530         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8531                                 port_num, UINT16);
8532 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8533         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8534                                 queue, "queue");
8535 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8536         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8537                                 queue_num, UINT8);
8538 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8539         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8540                                 rate, "rate");
8541 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8542         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8543                                 rate_num, UINT16);
8544
8545 cmdline_parse_inst_t cmd_queue_rate_limit = {
8546         .f = cmd_queue_rate_limit_parsed,
8547         .data = (void *)0,
8548         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8549                 "Set rate limit for a queue on port_id",
8550         .tokens = {
8551                 (void *)&cmd_queue_rate_limit_set,
8552                 (void *)&cmd_queue_rate_limit_port,
8553                 (void *)&cmd_queue_rate_limit_portnum,
8554                 (void *)&cmd_queue_rate_limit_queue,
8555                 (void *)&cmd_queue_rate_limit_queuenum,
8556                 (void *)&cmd_queue_rate_limit_rate,
8557                 (void *)&cmd_queue_rate_limit_ratenum,
8558                 NULL,
8559         },
8560 };
8561
8562 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8563 struct cmd_vf_rate_limit_result {
8564         cmdline_fixed_string_t set;
8565         cmdline_fixed_string_t port;
8566         uint16_t port_num;
8567         cmdline_fixed_string_t vf;
8568         uint8_t vf_num;
8569         cmdline_fixed_string_t rate;
8570         uint16_t rate_num;
8571         cmdline_fixed_string_t q_msk;
8572         uint64_t q_msk_val;
8573 };
8574
8575 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8576                 __attribute__((unused)) struct cmdline *cl,
8577                 __attribute__((unused)) void *data)
8578 {
8579         struct cmd_vf_rate_limit_result *res = parsed_result;
8580         int ret = 0;
8581
8582         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8583                 && (strcmp(res->vf, "vf") == 0)
8584                 && (strcmp(res->rate, "rate") == 0)
8585                 && (strcmp(res->q_msk, "queue_mask") == 0))
8586                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8587                                         res->rate_num, res->q_msk_val);
8588         if (ret < 0)
8589                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8590
8591 }
8592
8593 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8594         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8595                                 set, "set");
8596 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8597         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8598                                 port, "port");
8599 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8600         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8601                                 port_num, UINT16);
8602 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8603         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8604                                 vf, "vf");
8605 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8606         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8607                                 vf_num, UINT8);
8608 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8609         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8610                                 rate, "rate");
8611 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8612         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8613                                 rate_num, UINT16);
8614 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8615         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8616                                 q_msk, "queue_mask");
8617 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8618         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8619                                 q_msk_val, UINT64);
8620
8621 cmdline_parse_inst_t cmd_vf_rate_limit = {
8622         .f = cmd_vf_rate_limit_parsed,
8623         .data = (void *)0,
8624         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8625                 "queue_mask <queue_mask_value>: "
8626                 "Set rate limit for queues of VF on port_id",
8627         .tokens = {
8628                 (void *)&cmd_vf_rate_limit_set,
8629                 (void *)&cmd_vf_rate_limit_port,
8630                 (void *)&cmd_vf_rate_limit_portnum,
8631                 (void *)&cmd_vf_rate_limit_vf,
8632                 (void *)&cmd_vf_rate_limit_vfnum,
8633                 (void *)&cmd_vf_rate_limit_rate,
8634                 (void *)&cmd_vf_rate_limit_ratenum,
8635                 (void *)&cmd_vf_rate_limit_q_msk,
8636                 (void *)&cmd_vf_rate_limit_q_msk_val,
8637                 NULL,
8638         },
8639 };
8640
8641 /* *** ADD TUNNEL FILTER OF A PORT *** */
8642 struct cmd_tunnel_filter_result {
8643         cmdline_fixed_string_t cmd;
8644         cmdline_fixed_string_t what;
8645         portid_t port_id;
8646         struct ether_addr outer_mac;
8647         struct ether_addr inner_mac;
8648         cmdline_ipaddr_t ip_value;
8649         uint16_t inner_vlan;
8650         cmdline_fixed_string_t tunnel_type;
8651         cmdline_fixed_string_t filter_type;
8652         uint32_t tenant_id;
8653         uint16_t queue_num;
8654 };
8655
8656 static void
8657 cmd_tunnel_filter_parsed(void *parsed_result,
8658                           __attribute__((unused)) struct cmdline *cl,
8659                           __attribute__((unused)) void *data)
8660 {
8661         struct cmd_tunnel_filter_result *res = parsed_result;
8662         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8663         int ret = 0;
8664
8665         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8666
8667         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8668         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8669         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8670
8671         if (res->ip_value.family == AF_INET) {
8672                 tunnel_filter_conf.ip_addr.ipv4_addr =
8673                         res->ip_value.addr.ipv4.s_addr;
8674                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8675         } else {
8676                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8677                         &(res->ip_value.addr.ipv6),
8678                         sizeof(struct in6_addr));
8679                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8680         }
8681
8682         if (!strcmp(res->filter_type, "imac-ivlan"))
8683                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8684         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8685                 tunnel_filter_conf.filter_type =
8686                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8687         else if (!strcmp(res->filter_type, "imac-tenid"))
8688                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8689         else if (!strcmp(res->filter_type, "imac"))
8690                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8691         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8692                 tunnel_filter_conf.filter_type =
8693                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8694         else if (!strcmp(res->filter_type, "oip"))
8695                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8696         else if (!strcmp(res->filter_type, "iip"))
8697                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8698         else {
8699                 printf("The filter type is not supported");
8700                 return;
8701         }
8702
8703         if (!strcmp(res->tunnel_type, "vxlan"))
8704                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8705         else if (!strcmp(res->tunnel_type, "nvgre"))
8706                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8707         else if (!strcmp(res->tunnel_type, "ipingre"))
8708                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8709         else {
8710                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8711                 return;
8712         }
8713
8714         tunnel_filter_conf.tenant_id = res->tenant_id;
8715         tunnel_filter_conf.queue_id = res->queue_num;
8716         if (!strcmp(res->what, "add"))
8717                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8718                                         RTE_ETH_FILTER_TUNNEL,
8719                                         RTE_ETH_FILTER_ADD,
8720                                         &tunnel_filter_conf);
8721         else
8722                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8723                                         RTE_ETH_FILTER_TUNNEL,
8724                                         RTE_ETH_FILTER_DELETE,
8725                                         &tunnel_filter_conf);
8726         if (ret < 0)
8727                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8728                                 strerror(-ret));
8729
8730 }
8731 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8732         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8733         cmd, "tunnel_filter");
8734 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8735         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8736         what, "add#rm");
8737 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8738         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8739         port_id, UINT16);
8740 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8741         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8742         outer_mac);
8743 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8744         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8745         inner_mac);
8746 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8747         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8748         inner_vlan, UINT16);
8749 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8750         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8751         ip_value);
8752 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8753         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8754         tunnel_type, "vxlan#nvgre#ipingre");
8755
8756 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8757         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8758         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8759                 "imac#omac-imac-tenid");
8760 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8761         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8762         tenant_id, UINT32);
8763 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8764         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8765         queue_num, UINT16);
8766
8767 cmdline_parse_inst_t cmd_tunnel_filter = {
8768         .f = cmd_tunnel_filter_parsed,
8769         .data = (void *)0,
8770         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8771                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8772                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8773                 "<queue_id>: Add/Rm tunnel filter of a port",
8774         .tokens = {
8775                 (void *)&cmd_tunnel_filter_cmd,
8776                 (void *)&cmd_tunnel_filter_what,
8777                 (void *)&cmd_tunnel_filter_port_id,
8778                 (void *)&cmd_tunnel_filter_outer_mac,
8779                 (void *)&cmd_tunnel_filter_inner_mac,
8780                 (void *)&cmd_tunnel_filter_ip_value,
8781                 (void *)&cmd_tunnel_filter_innner_vlan,
8782                 (void *)&cmd_tunnel_filter_tunnel_type,
8783                 (void *)&cmd_tunnel_filter_filter_type,
8784                 (void *)&cmd_tunnel_filter_tenant_id,
8785                 (void *)&cmd_tunnel_filter_queue_num,
8786                 NULL,
8787         },
8788 };
8789
8790 /* *** CONFIGURE TUNNEL UDP PORT *** */
8791 struct cmd_tunnel_udp_config {
8792         cmdline_fixed_string_t cmd;
8793         cmdline_fixed_string_t what;
8794         uint16_t udp_port;
8795         portid_t port_id;
8796 };
8797
8798 static void
8799 cmd_tunnel_udp_config_parsed(void *parsed_result,
8800                           __attribute__((unused)) struct cmdline *cl,
8801                           __attribute__((unused)) void *data)
8802 {
8803         struct cmd_tunnel_udp_config *res = parsed_result;
8804         struct rte_eth_udp_tunnel tunnel_udp;
8805         int ret;
8806
8807         tunnel_udp.udp_port = res->udp_port;
8808
8809         if (!strcmp(res->cmd, "rx_vxlan_port"))
8810                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8811
8812         if (!strcmp(res->what, "add"))
8813                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8814                                                       &tunnel_udp);
8815         else
8816                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8817                                                          &tunnel_udp);
8818
8819         if (ret < 0)
8820                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8821 }
8822
8823 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8824         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8825                                 cmd, "rx_vxlan_port");
8826 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8827         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8828                                 what, "add#rm");
8829 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8830         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8831                                 udp_port, UINT16);
8832 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8833         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8834                                 port_id, UINT16);
8835
8836 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8837         .f = cmd_tunnel_udp_config_parsed,
8838         .data = (void *)0,
8839         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8840                 "Add/Remove a tunneling UDP port filter",
8841         .tokens = {
8842                 (void *)&cmd_tunnel_udp_config_cmd,
8843                 (void *)&cmd_tunnel_udp_config_what,
8844                 (void *)&cmd_tunnel_udp_config_udp_port,
8845                 (void *)&cmd_tunnel_udp_config_port_id,
8846                 NULL,
8847         },
8848 };
8849
8850 struct cmd_config_tunnel_udp_port {
8851         cmdline_fixed_string_t port;
8852         cmdline_fixed_string_t config;
8853         portid_t port_id;
8854         cmdline_fixed_string_t udp_tunnel_port;
8855         cmdline_fixed_string_t action;
8856         cmdline_fixed_string_t tunnel_type;
8857         uint16_t udp_port;
8858 };
8859
8860 static void
8861 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8862                                __attribute__((unused)) struct cmdline *cl,
8863                                __attribute__((unused)) void *data)
8864 {
8865         struct cmd_config_tunnel_udp_port *res = parsed_result;
8866         struct rte_eth_udp_tunnel tunnel_udp;
8867         int ret = 0;
8868
8869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8870                 return;
8871
8872         tunnel_udp.udp_port = res->udp_port;
8873
8874         if (!strcmp(res->tunnel_type, "vxlan")) {
8875                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8876         } else if (!strcmp(res->tunnel_type, "geneve")) {
8877                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8878         } else {
8879                 printf("Invalid tunnel type\n");
8880                 return;
8881         }
8882
8883         if (!strcmp(res->action, "add"))
8884                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8885                                                       &tunnel_udp);
8886         else
8887                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8888                                                          &tunnel_udp);
8889
8890         if (ret < 0)
8891                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8892 }
8893
8894 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8895         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8896                                  "port");
8897 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8898         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8899                                  "config");
8900 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8901         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8902                               UINT16);
8903 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8904         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8905                                  udp_tunnel_port,
8906                                  "udp_tunnel_port");
8907 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8908         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8909                                  "add#rm");
8910 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8911         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8912                                  "vxlan#geneve");
8913 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8914         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8915                               UINT16);
8916
8917 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8918         .f = cmd_cfg_tunnel_udp_port_parsed,
8919         .data = NULL,
8920         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8921         .tokens = {
8922                 (void *)&cmd_config_tunnel_udp_port_port,
8923                 (void *)&cmd_config_tunnel_udp_port_config,
8924                 (void *)&cmd_config_tunnel_udp_port_port_id,
8925                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8926                 (void *)&cmd_config_tunnel_udp_port_action,
8927                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8928                 (void *)&cmd_config_tunnel_udp_port_value,
8929                 NULL,
8930         },
8931 };
8932
8933 /* *** GLOBAL CONFIG *** */
8934 struct cmd_global_config_result {
8935         cmdline_fixed_string_t cmd;
8936         portid_t port_id;
8937         cmdline_fixed_string_t cfg_type;
8938         uint8_t len;
8939 };
8940
8941 static void
8942 cmd_global_config_parsed(void *parsed_result,
8943                          __attribute__((unused)) struct cmdline *cl,
8944                          __attribute__((unused)) void *data)
8945 {
8946         struct cmd_global_config_result *res = parsed_result;
8947         struct rte_eth_global_cfg conf;
8948         int ret;
8949
8950         memset(&conf, 0, sizeof(conf));
8951         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8952         conf.cfg.gre_key_len = res->len;
8953         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8954                                       RTE_ETH_FILTER_SET, &conf);
8955         if (ret != 0)
8956                 printf("Global config error\n");
8957 }
8958
8959 cmdline_parse_token_string_t cmd_global_config_cmd =
8960         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8961                 "global_config");
8962 cmdline_parse_token_num_t cmd_global_config_port_id =
8963         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8964                                UINT16);
8965 cmdline_parse_token_string_t cmd_global_config_type =
8966         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8967                 cfg_type, "gre-key-len");
8968 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8969         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8970                 len, UINT8);
8971
8972 cmdline_parse_inst_t cmd_global_config = {
8973         .f = cmd_global_config_parsed,
8974         .data = (void *)NULL,
8975         .help_str = "global_config <port_id> gre-key-len <key_len>",
8976         .tokens = {
8977                 (void *)&cmd_global_config_cmd,
8978                 (void *)&cmd_global_config_port_id,
8979                 (void *)&cmd_global_config_type,
8980                 (void *)&cmd_global_config_gre_key_len,
8981                 NULL,
8982         },
8983 };
8984
8985 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8986 struct cmd_set_mirror_mask_result {
8987         cmdline_fixed_string_t set;
8988         cmdline_fixed_string_t port;
8989         portid_t port_id;
8990         cmdline_fixed_string_t mirror;
8991         uint8_t rule_id;
8992         cmdline_fixed_string_t what;
8993         cmdline_fixed_string_t value;
8994         cmdline_fixed_string_t dstpool;
8995         uint8_t dstpool_id;
8996         cmdline_fixed_string_t on;
8997 };
8998
8999 cmdline_parse_token_string_t cmd_mirror_mask_set =
9000         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9001                                 set, "set");
9002 cmdline_parse_token_string_t cmd_mirror_mask_port =
9003         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9004                                 port, "port");
9005 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9006         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9007                                 port_id, UINT16);
9008 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9009         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9010                                 mirror, "mirror-rule");
9011 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9012         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9013                                 rule_id, UINT8);
9014 cmdline_parse_token_string_t cmd_mirror_mask_what =
9015         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9016                                 what, "pool-mirror-up#pool-mirror-down"
9017                                       "#vlan-mirror");
9018 cmdline_parse_token_string_t cmd_mirror_mask_value =
9019         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9020                                 value, NULL);
9021 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9022         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9023                                 dstpool, "dst-pool");
9024 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9025         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9026                                 dstpool_id, UINT8);
9027 cmdline_parse_token_string_t cmd_mirror_mask_on =
9028         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9029                                 on, "on#off");
9030
9031 static void
9032 cmd_set_mirror_mask_parsed(void *parsed_result,
9033                        __attribute__((unused)) struct cmdline *cl,
9034                        __attribute__((unused)) void *data)
9035 {
9036         int ret,nb_item,i;
9037         struct cmd_set_mirror_mask_result *res = parsed_result;
9038         struct rte_eth_mirror_conf mr_conf;
9039
9040         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9041
9042         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9043
9044         mr_conf.dst_pool = res->dstpool_id;
9045
9046         if (!strcmp(res->what, "pool-mirror-up")) {
9047                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9048                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9049         } else if (!strcmp(res->what, "pool-mirror-down")) {
9050                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9051                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9052         } else if (!strcmp(res->what, "vlan-mirror")) {
9053                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9054                 nb_item = parse_item_list(res->value, "vlan",
9055                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9056                 if (nb_item <= 0)
9057                         return;
9058
9059                 for (i = 0; i < nb_item; i++) {
9060                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9061                                 printf("Invalid vlan_id: must be < 4096\n");
9062                                 return;
9063                         }
9064
9065                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9066                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9067                 }
9068         }
9069
9070         if (!strcmp(res->on, "on"))
9071                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9072                                                 res->rule_id, 1);
9073         else
9074                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9075                                                 res->rule_id, 0);
9076         if (ret < 0)
9077                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9078 }
9079
9080 cmdline_parse_inst_t cmd_set_mirror_mask = {
9081                 .f = cmd_set_mirror_mask_parsed,
9082                 .data = NULL,
9083                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9084                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9085                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9086                 .tokens = {
9087                         (void *)&cmd_mirror_mask_set,
9088                         (void *)&cmd_mirror_mask_port,
9089                         (void *)&cmd_mirror_mask_portid,
9090                         (void *)&cmd_mirror_mask_mirror,
9091                         (void *)&cmd_mirror_mask_ruleid,
9092                         (void *)&cmd_mirror_mask_what,
9093                         (void *)&cmd_mirror_mask_value,
9094                         (void *)&cmd_mirror_mask_dstpool,
9095                         (void *)&cmd_mirror_mask_poolid,
9096                         (void *)&cmd_mirror_mask_on,
9097                         NULL,
9098                 },
9099 };
9100
9101 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9102 struct cmd_set_mirror_link_result {
9103         cmdline_fixed_string_t set;
9104         cmdline_fixed_string_t port;
9105         portid_t port_id;
9106         cmdline_fixed_string_t mirror;
9107         uint8_t rule_id;
9108         cmdline_fixed_string_t what;
9109         cmdline_fixed_string_t dstpool;
9110         uint8_t dstpool_id;
9111         cmdline_fixed_string_t on;
9112 };
9113
9114 cmdline_parse_token_string_t cmd_mirror_link_set =
9115         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9116                                  set, "set");
9117 cmdline_parse_token_string_t cmd_mirror_link_port =
9118         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9119                                 port, "port");
9120 cmdline_parse_token_num_t cmd_mirror_link_portid =
9121         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9122                                 port_id, UINT16);
9123 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9124         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9125                                 mirror, "mirror-rule");
9126 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9127         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9128                             rule_id, UINT8);
9129 cmdline_parse_token_string_t cmd_mirror_link_what =
9130         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9131                                 what, "uplink-mirror#downlink-mirror");
9132 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9133         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9134                                 dstpool, "dst-pool");
9135 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9136         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9137                                 dstpool_id, UINT8);
9138 cmdline_parse_token_string_t cmd_mirror_link_on =
9139         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9140                                 on, "on#off");
9141
9142 static void
9143 cmd_set_mirror_link_parsed(void *parsed_result,
9144                        __attribute__((unused)) struct cmdline *cl,
9145                        __attribute__((unused)) void *data)
9146 {
9147         int ret;
9148         struct cmd_set_mirror_link_result *res = parsed_result;
9149         struct rte_eth_mirror_conf mr_conf;
9150
9151         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9152         if (!strcmp(res->what, "uplink-mirror"))
9153                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9154         else
9155                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9156
9157         mr_conf.dst_pool = res->dstpool_id;
9158
9159         if (!strcmp(res->on, "on"))
9160                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9161                                                 res->rule_id, 1);
9162         else
9163                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9164                                                 res->rule_id, 0);
9165
9166         /* check the return value and print it if is < 0 */
9167         if (ret < 0)
9168                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9169
9170 }
9171
9172 cmdline_parse_inst_t cmd_set_mirror_link = {
9173                 .f = cmd_set_mirror_link_parsed,
9174                 .data = NULL,
9175                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9176                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9177                 .tokens = {
9178                         (void *)&cmd_mirror_link_set,
9179                         (void *)&cmd_mirror_link_port,
9180                         (void *)&cmd_mirror_link_portid,
9181                         (void *)&cmd_mirror_link_mirror,
9182                         (void *)&cmd_mirror_link_ruleid,
9183                         (void *)&cmd_mirror_link_what,
9184                         (void *)&cmd_mirror_link_dstpool,
9185                         (void *)&cmd_mirror_link_poolid,
9186                         (void *)&cmd_mirror_link_on,
9187                         NULL,
9188                 },
9189 };
9190
9191 /* *** RESET VM MIRROR RULE *** */
9192 struct cmd_rm_mirror_rule_result {
9193         cmdline_fixed_string_t reset;
9194         cmdline_fixed_string_t port;
9195         portid_t port_id;
9196         cmdline_fixed_string_t mirror;
9197         uint8_t rule_id;
9198 };
9199
9200 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9201         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9202                                  reset, "reset");
9203 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9204         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9205                                 port, "port");
9206 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9207         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9208                                 port_id, UINT16);
9209 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9210         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9211                                 mirror, "mirror-rule");
9212 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9213         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9214                                 rule_id, UINT8);
9215
9216 static void
9217 cmd_reset_mirror_rule_parsed(void *parsed_result,
9218                        __attribute__((unused)) struct cmdline *cl,
9219                        __attribute__((unused)) void *data)
9220 {
9221         int ret;
9222         struct cmd_set_mirror_link_result *res = parsed_result;
9223         /* check rule_id */
9224         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9225         if(ret < 0)
9226                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9227 }
9228
9229 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9230                 .f = cmd_reset_mirror_rule_parsed,
9231                 .data = NULL,
9232                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9233                 .tokens = {
9234                         (void *)&cmd_rm_mirror_rule_reset,
9235                         (void *)&cmd_rm_mirror_rule_port,
9236                         (void *)&cmd_rm_mirror_rule_portid,
9237                         (void *)&cmd_rm_mirror_rule_mirror,
9238                         (void *)&cmd_rm_mirror_rule_ruleid,
9239                         NULL,
9240                 },
9241 };
9242
9243 /* ******************************************************************************** */
9244
9245 struct cmd_dump_result {
9246         cmdline_fixed_string_t dump;
9247 };
9248
9249 static void
9250 dump_struct_sizes(void)
9251 {
9252 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9253         DUMP_SIZE(struct rte_mbuf);
9254         DUMP_SIZE(struct rte_mempool);
9255         DUMP_SIZE(struct rte_ring);
9256 #undef DUMP_SIZE
9257 }
9258
9259 static void cmd_dump_parsed(void *parsed_result,
9260                             __attribute__((unused)) struct cmdline *cl,
9261                             __attribute__((unused)) void *data)
9262 {
9263         struct cmd_dump_result *res = parsed_result;
9264
9265         if (!strcmp(res->dump, "dump_physmem"))
9266                 rte_dump_physmem_layout(stdout);
9267         else if (!strcmp(res->dump, "dump_memzone"))
9268                 rte_memzone_dump(stdout);
9269         else if (!strcmp(res->dump, "dump_struct_sizes"))
9270                 dump_struct_sizes();
9271         else if (!strcmp(res->dump, "dump_ring"))
9272                 rte_ring_list_dump(stdout);
9273         else if (!strcmp(res->dump, "dump_mempool"))
9274                 rte_mempool_list_dump(stdout);
9275         else if (!strcmp(res->dump, "dump_devargs"))
9276                 rte_devargs_dump(stdout);
9277         else if (!strcmp(res->dump, "dump_log_types"))
9278                 rte_log_dump(stdout);
9279 }
9280
9281 cmdline_parse_token_string_t cmd_dump_dump =
9282         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9283                 "dump_physmem#"
9284                 "dump_memzone#"
9285                 "dump_struct_sizes#"
9286                 "dump_ring#"
9287                 "dump_mempool#"
9288                 "dump_devargs#"
9289                 "dump_log_types");
9290
9291 cmdline_parse_inst_t cmd_dump = {
9292         .f = cmd_dump_parsed,  /* function to call */
9293         .data = NULL,      /* 2nd arg of func */
9294         .help_str = "Dump status",
9295         .tokens = {        /* token list, NULL terminated */
9296                 (void *)&cmd_dump_dump,
9297                 NULL,
9298         },
9299 };
9300
9301 /* ******************************************************************************** */
9302
9303 struct cmd_dump_one_result {
9304         cmdline_fixed_string_t dump;
9305         cmdline_fixed_string_t name;
9306 };
9307
9308 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9309                                 __attribute__((unused)) void *data)
9310 {
9311         struct cmd_dump_one_result *res = parsed_result;
9312
9313         if (!strcmp(res->dump, "dump_ring")) {
9314                 struct rte_ring *r;
9315                 r = rte_ring_lookup(res->name);
9316                 if (r == NULL) {
9317                         cmdline_printf(cl, "Cannot find ring\n");
9318                         return;
9319                 }
9320                 rte_ring_dump(stdout, r);
9321         } else if (!strcmp(res->dump, "dump_mempool")) {
9322                 struct rte_mempool *mp;
9323                 mp = rte_mempool_lookup(res->name);
9324                 if (mp == NULL) {
9325                         cmdline_printf(cl, "Cannot find mempool\n");
9326                         return;
9327                 }
9328                 rte_mempool_dump(stdout, mp);
9329         }
9330 }
9331
9332 cmdline_parse_token_string_t cmd_dump_one_dump =
9333         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9334                                  "dump_ring#dump_mempool");
9335
9336 cmdline_parse_token_string_t cmd_dump_one_name =
9337         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9338
9339 cmdline_parse_inst_t cmd_dump_one = {
9340         .f = cmd_dump_one_parsed,  /* function to call */
9341         .data = NULL,      /* 2nd arg of func */
9342         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9343         .tokens = {        /* token list, NULL terminated */
9344                 (void *)&cmd_dump_one_dump,
9345                 (void *)&cmd_dump_one_name,
9346                 NULL,
9347         },
9348 };
9349
9350 /* *** Add/Del syn filter *** */
9351 struct cmd_syn_filter_result {
9352         cmdline_fixed_string_t filter;
9353         portid_t port_id;
9354         cmdline_fixed_string_t ops;
9355         cmdline_fixed_string_t priority;
9356         cmdline_fixed_string_t high;
9357         cmdline_fixed_string_t queue;
9358         uint16_t queue_id;
9359 };
9360
9361 static void
9362 cmd_syn_filter_parsed(void *parsed_result,
9363                         __attribute__((unused)) struct cmdline *cl,
9364                         __attribute__((unused)) void *data)
9365 {
9366         struct cmd_syn_filter_result *res = parsed_result;
9367         struct rte_eth_syn_filter syn_filter;
9368         int ret = 0;
9369
9370         ret = rte_eth_dev_filter_supported(res->port_id,
9371                                         RTE_ETH_FILTER_SYN);
9372         if (ret < 0) {
9373                 printf("syn filter is not supported on port %u.\n",
9374                                 res->port_id);
9375                 return;
9376         }
9377
9378         memset(&syn_filter, 0, sizeof(syn_filter));
9379
9380         if (!strcmp(res->ops, "add")) {
9381                 if (!strcmp(res->high, "high"))
9382                         syn_filter.hig_pri = 1;
9383                 else
9384                         syn_filter.hig_pri = 0;
9385
9386                 syn_filter.queue = res->queue_id;
9387                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9388                                                 RTE_ETH_FILTER_SYN,
9389                                                 RTE_ETH_FILTER_ADD,
9390                                                 &syn_filter);
9391         } else
9392                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9393                                                 RTE_ETH_FILTER_SYN,
9394                                                 RTE_ETH_FILTER_DELETE,
9395                                                 &syn_filter);
9396
9397         if (ret < 0)
9398                 printf("syn filter programming error: (%s)\n",
9399                                 strerror(-ret));
9400 }
9401
9402 cmdline_parse_token_string_t cmd_syn_filter_filter =
9403         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9404         filter, "syn_filter");
9405 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9406         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9407         port_id, UINT16);
9408 cmdline_parse_token_string_t cmd_syn_filter_ops =
9409         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9410         ops, "add#del");
9411 cmdline_parse_token_string_t cmd_syn_filter_priority =
9412         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9413                                 priority, "priority");
9414 cmdline_parse_token_string_t cmd_syn_filter_high =
9415         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9416                                 high, "high#low");
9417 cmdline_parse_token_string_t cmd_syn_filter_queue =
9418         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9419                                 queue, "queue");
9420 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9421         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9422                                 queue_id, UINT16);
9423
9424 cmdline_parse_inst_t cmd_syn_filter = {
9425         .f = cmd_syn_filter_parsed,
9426         .data = NULL,
9427         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9428                 "<queue_id>: Add/Delete syn filter",
9429         .tokens = {
9430                 (void *)&cmd_syn_filter_filter,
9431                 (void *)&cmd_syn_filter_port_id,
9432                 (void *)&cmd_syn_filter_ops,
9433                 (void *)&cmd_syn_filter_priority,
9434                 (void *)&cmd_syn_filter_high,
9435                 (void *)&cmd_syn_filter_queue,
9436                 (void *)&cmd_syn_filter_queue_id,
9437                 NULL,
9438         },
9439 };
9440
9441 /* *** queue region set *** */
9442 struct cmd_queue_region_result {
9443         cmdline_fixed_string_t set;
9444         cmdline_fixed_string_t port;
9445         portid_t port_id;
9446         cmdline_fixed_string_t cmd;
9447         cmdline_fixed_string_t region;
9448         uint8_t  region_id;
9449         cmdline_fixed_string_t queue_start_index;
9450         uint8_t  queue_id;
9451         cmdline_fixed_string_t queue_num;
9452         uint8_t  queue_num_value;
9453 };
9454
9455 static void
9456 cmd_queue_region_parsed(void *parsed_result,
9457                         __attribute__((unused)) struct cmdline *cl,
9458                         __attribute__((unused)) void *data)
9459 {
9460         struct cmd_queue_region_result *res = parsed_result;
9461         int ret = -ENOTSUP;
9462 #ifdef RTE_LIBRTE_I40E_PMD
9463         struct rte_pmd_i40e_queue_region_conf region_conf;
9464         enum rte_pmd_i40e_queue_region_op op_type;
9465 #endif
9466
9467         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9468                 return;
9469
9470 #ifdef RTE_LIBRTE_I40E_PMD
9471         memset(&region_conf, 0, sizeof(region_conf));
9472         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9473         region_conf.region_id = res->region_id;
9474         region_conf.queue_num = res->queue_num_value;
9475         region_conf.queue_start_index = res->queue_id;
9476
9477         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9478                                 op_type, &region_conf);
9479 #endif
9480
9481         switch (ret) {
9482         case 0:
9483                 break;
9484         case -ENOTSUP:
9485                 printf("function not implemented or supported\n");
9486                 break;
9487         default:
9488                 printf("queue region config error: (%s)\n", strerror(-ret));
9489         }
9490 }
9491
9492 cmdline_parse_token_string_t cmd_queue_region_set =
9493 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9494                 set, "set");
9495 cmdline_parse_token_string_t cmd_queue_region_port =
9496         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9497 cmdline_parse_token_num_t cmd_queue_region_port_id =
9498         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9499                                 port_id, UINT16);
9500 cmdline_parse_token_string_t cmd_queue_region_cmd =
9501         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9502                                  cmd, "queue-region");
9503 cmdline_parse_token_string_t cmd_queue_region_id =
9504         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9505                                 region, "region_id");
9506 cmdline_parse_token_num_t cmd_queue_region_index =
9507         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9508                                 region_id, UINT8);
9509 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9510         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9511                                 queue_start_index, "queue_start_index");
9512 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9513         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9514                                 queue_id, UINT8);
9515 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9516         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9517                                 queue_num, "queue_num");
9518 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9519         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9520                                 queue_num_value, UINT8);
9521
9522 cmdline_parse_inst_t cmd_queue_region = {
9523         .f = cmd_queue_region_parsed,
9524         .data = NULL,
9525         .help_str = "set port <port_id> queue-region region_id <value> "
9526                 "queue_start_index <value> queue_num <value>: Set a queue region",
9527         .tokens = {
9528                 (void *)&cmd_queue_region_set,
9529                 (void *)&cmd_queue_region_port,
9530                 (void *)&cmd_queue_region_port_id,
9531                 (void *)&cmd_queue_region_cmd,
9532                 (void *)&cmd_queue_region_id,
9533                 (void *)&cmd_queue_region_index,
9534                 (void *)&cmd_queue_region_queue_start_index,
9535                 (void *)&cmd_queue_region_queue_id,
9536                 (void *)&cmd_queue_region_queue_num,
9537                 (void *)&cmd_queue_region_queue_num_value,
9538                 NULL,
9539         },
9540 };
9541
9542 /* *** queue region and flowtype set *** */
9543 struct cmd_region_flowtype_result {
9544         cmdline_fixed_string_t set;
9545         cmdline_fixed_string_t port;
9546         portid_t port_id;
9547         cmdline_fixed_string_t cmd;
9548         cmdline_fixed_string_t region;
9549         uint8_t  region_id;
9550         cmdline_fixed_string_t flowtype;
9551         uint8_t  flowtype_id;
9552 };
9553
9554 static void
9555 cmd_region_flowtype_parsed(void *parsed_result,
9556                         __attribute__((unused)) struct cmdline *cl,
9557                         __attribute__((unused)) void *data)
9558 {
9559         struct cmd_region_flowtype_result *res = parsed_result;
9560         int ret = -ENOTSUP;
9561 #ifdef RTE_LIBRTE_I40E_PMD
9562         struct rte_pmd_i40e_queue_region_conf region_conf;
9563         enum rte_pmd_i40e_queue_region_op op_type;
9564 #endif
9565
9566         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9567                 return;
9568
9569 #ifdef RTE_LIBRTE_I40E_PMD
9570         memset(&region_conf, 0, sizeof(region_conf));
9571
9572         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9573         region_conf.region_id = res->region_id;
9574         region_conf.hw_flowtype = res->flowtype_id;
9575
9576         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9577                         op_type, &region_conf);
9578 #endif
9579
9580         switch (ret) {
9581         case 0:
9582                 break;
9583         case -ENOTSUP:
9584                 printf("function not implemented or supported\n");
9585                 break;
9586         default:
9587                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9588         }
9589 }
9590
9591 cmdline_parse_token_string_t cmd_region_flowtype_set =
9592 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9593                                 set, "set");
9594 cmdline_parse_token_string_t cmd_region_flowtype_port =
9595         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9596                                 port, "port");
9597 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9598         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9599                                 port_id, UINT16);
9600 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9601         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9602                                 cmd, "queue-region");
9603 cmdline_parse_token_string_t cmd_region_flowtype_index =
9604         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9605                                 region, "region_id");
9606 cmdline_parse_token_num_t cmd_region_flowtype_id =
9607         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9608                                 region_id, UINT8);
9609 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9610         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9611                                 flowtype, "flowtype");
9612 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9613         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9614                                 flowtype_id, UINT8);
9615 cmdline_parse_inst_t cmd_region_flowtype = {
9616         .f = cmd_region_flowtype_parsed,
9617         .data = NULL,
9618         .help_str = "set port <port_id> queue-region region_id <value> "
9619                 "flowtype <value>: Set a flowtype region index",
9620         .tokens = {
9621                 (void *)&cmd_region_flowtype_set,
9622                 (void *)&cmd_region_flowtype_port,
9623                 (void *)&cmd_region_flowtype_port_index,
9624                 (void *)&cmd_region_flowtype_cmd,
9625                 (void *)&cmd_region_flowtype_index,
9626                 (void *)&cmd_region_flowtype_id,
9627                 (void *)&cmd_region_flowtype_flow_index,
9628                 (void *)&cmd_region_flowtype_flow_id,
9629                 NULL,
9630         },
9631 };
9632
9633 /* *** User Priority (UP) to queue region (region_id) set *** */
9634 struct cmd_user_priority_region_result {
9635         cmdline_fixed_string_t set;
9636         cmdline_fixed_string_t port;
9637         portid_t port_id;
9638         cmdline_fixed_string_t cmd;
9639         cmdline_fixed_string_t user_priority;
9640         uint8_t  user_priority_id;
9641         cmdline_fixed_string_t region;
9642         uint8_t  region_id;
9643 };
9644
9645 static void
9646 cmd_user_priority_region_parsed(void *parsed_result,
9647                         __attribute__((unused)) struct cmdline *cl,
9648                         __attribute__((unused)) void *data)
9649 {
9650         struct cmd_user_priority_region_result *res = parsed_result;
9651         int ret = -ENOTSUP;
9652 #ifdef RTE_LIBRTE_I40E_PMD
9653         struct rte_pmd_i40e_queue_region_conf region_conf;
9654         enum rte_pmd_i40e_queue_region_op op_type;
9655 #endif
9656
9657         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9658                 return;
9659
9660 #ifdef RTE_LIBRTE_I40E_PMD
9661         memset(&region_conf, 0, sizeof(region_conf));
9662         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9663         region_conf.user_priority = res->user_priority_id;
9664         region_conf.region_id = res->region_id;
9665
9666         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9667                                 op_type, &region_conf);
9668 #endif
9669
9670         switch (ret) {
9671         case 0:
9672                 break;
9673         case -ENOTSUP:
9674                 printf("function not implemented or supported\n");
9675                 break;
9676         default:
9677                 printf("user_priority region config error: (%s)\n",
9678                                 strerror(-ret));
9679         }
9680 }
9681
9682 cmdline_parse_token_string_t cmd_user_priority_region_set =
9683         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9684                                 set, "set");
9685 cmdline_parse_token_string_t cmd_user_priority_region_port =
9686         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9687                                 port, "port");
9688 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9689         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9690                                 port_id, UINT16);
9691 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9692         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9693                                 cmd, "queue-region");
9694 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9695         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9696                                 user_priority, "UP");
9697 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9698         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9699                                 user_priority_id, UINT8);
9700 cmdline_parse_token_string_t cmd_user_priority_region_region =
9701         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9702                                 region, "region_id");
9703 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9704         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9705                                 region_id, UINT8);
9706
9707 cmdline_parse_inst_t cmd_user_priority_region = {
9708         .f = cmd_user_priority_region_parsed,
9709         .data = NULL,
9710         .help_str = "set port <port_id> queue-region UP <value> "
9711                 "region_id <value>: Set the mapping of User Priority (UP) "
9712                 "to queue region (region_id) ",
9713         .tokens = {
9714                 (void *)&cmd_user_priority_region_set,
9715                 (void *)&cmd_user_priority_region_port,
9716                 (void *)&cmd_user_priority_region_port_index,
9717                 (void *)&cmd_user_priority_region_cmd,
9718                 (void *)&cmd_user_priority_region_UP,
9719                 (void *)&cmd_user_priority_region_UP_id,
9720                 (void *)&cmd_user_priority_region_region,
9721                 (void *)&cmd_user_priority_region_region_id,
9722                 NULL,
9723         },
9724 };
9725
9726 /* *** flush all queue region related configuration *** */
9727 struct cmd_flush_queue_region_result {
9728         cmdline_fixed_string_t set;
9729         cmdline_fixed_string_t port;
9730         portid_t port_id;
9731         cmdline_fixed_string_t cmd;
9732         cmdline_fixed_string_t flush;
9733         cmdline_fixed_string_t what;
9734 };
9735
9736 static void
9737 cmd_flush_queue_region_parsed(void *parsed_result,
9738                         __attribute__((unused)) struct cmdline *cl,
9739                         __attribute__((unused)) void *data)
9740 {
9741         struct cmd_flush_queue_region_result *res = parsed_result;
9742         int ret = -ENOTSUP;
9743 #ifdef RTE_LIBRTE_I40E_PMD
9744         struct rte_pmd_i40e_queue_region_conf region_conf;
9745         enum rte_pmd_i40e_queue_region_op op_type;
9746 #endif
9747
9748         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9749                 return;
9750
9751 #ifdef RTE_LIBRTE_I40E_PMD
9752         memset(&region_conf, 0, sizeof(region_conf));
9753
9754         if (strcmp(res->what, "on") == 0)
9755                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9756         else
9757                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9758
9759         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9760                                 op_type, &region_conf);
9761 #endif
9762
9763         switch (ret) {
9764         case 0:
9765                 break;
9766         case -ENOTSUP:
9767                 printf("function not implemented or supported\n");
9768                 break;
9769         default:
9770                 printf("queue region config flush error: (%s)\n",
9771                                 strerror(-ret));
9772         }
9773 }
9774
9775 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9776         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9777                                 set, "set");
9778 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9779         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9780                                 port, "port");
9781 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9782         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9783                                 port_id, UINT16);
9784 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9785         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9786                                 cmd, "queue-region");
9787 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9788         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9789                                 flush, "flush");
9790 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9791         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9792                                 what, "on#off");
9793
9794 cmdline_parse_inst_t cmd_flush_queue_region = {
9795         .f = cmd_flush_queue_region_parsed,
9796         .data = NULL,
9797         .help_str = "set port <port_id> queue-region flush on|off"
9798                 ": flush all queue region related configuration",
9799         .tokens = {
9800                 (void *)&cmd_flush_queue_region_set,
9801                 (void *)&cmd_flush_queue_region_port,
9802                 (void *)&cmd_flush_queue_region_port_index,
9803                 (void *)&cmd_flush_queue_region_cmd,
9804                 (void *)&cmd_flush_queue_region_flush,
9805                 (void *)&cmd_flush_queue_region_what,
9806                 NULL,
9807         },
9808 };
9809
9810 /* *** get all queue region related configuration info *** */
9811 struct cmd_show_queue_region_info {
9812         cmdline_fixed_string_t show;
9813         cmdline_fixed_string_t port;
9814         portid_t port_id;
9815         cmdline_fixed_string_t cmd;
9816 };
9817
9818 static void
9819 cmd_show_queue_region_info_parsed(void *parsed_result,
9820                         __attribute__((unused)) struct cmdline *cl,
9821                         __attribute__((unused)) void *data)
9822 {
9823         struct cmd_show_queue_region_info *res = parsed_result;
9824         int ret = -ENOTSUP;
9825 #ifdef RTE_LIBRTE_I40E_PMD
9826         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9827         enum rte_pmd_i40e_queue_region_op op_type;
9828 #endif
9829
9830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9831                 return;
9832
9833 #ifdef RTE_LIBRTE_I40E_PMD
9834         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9835
9836         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9837
9838         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9839                                         op_type, &rte_pmd_regions);
9840
9841         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9842 #endif
9843
9844         switch (ret) {
9845         case 0:
9846                 break;
9847         case -ENOTSUP:
9848                 printf("function not implemented or supported\n");
9849                 break;
9850         default:
9851                 printf("queue region config info show error: (%s)\n",
9852                                 strerror(-ret));
9853         }
9854 }
9855
9856 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9857 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9858                                 show, "show");
9859 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9860         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9861                                 port, "port");
9862 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9863         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9864                                 port_id, UINT16);
9865 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9866         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9867                                 cmd, "queue-region");
9868
9869 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9870         .f = cmd_show_queue_region_info_parsed,
9871         .data = NULL,
9872         .help_str = "show port <port_id> queue-region"
9873                 ": show all queue region related configuration info",
9874         .tokens = {
9875                 (void *)&cmd_show_queue_region_info_get,
9876                 (void *)&cmd_show_queue_region_info_port,
9877                 (void *)&cmd_show_queue_region_info_port_index,
9878                 (void *)&cmd_show_queue_region_info_cmd,
9879                 NULL,
9880         },
9881 };
9882
9883 /* *** ADD/REMOVE A 2tuple FILTER *** */
9884 struct cmd_2tuple_filter_result {
9885         cmdline_fixed_string_t filter;
9886         portid_t port_id;
9887         cmdline_fixed_string_t ops;
9888         cmdline_fixed_string_t dst_port;
9889         uint16_t dst_port_value;
9890         cmdline_fixed_string_t protocol;
9891         uint8_t protocol_value;
9892         cmdline_fixed_string_t mask;
9893         uint8_t  mask_value;
9894         cmdline_fixed_string_t tcp_flags;
9895         uint8_t tcp_flags_value;
9896         cmdline_fixed_string_t priority;
9897         uint8_t  priority_value;
9898         cmdline_fixed_string_t queue;
9899         uint16_t  queue_id;
9900 };
9901
9902 static void
9903 cmd_2tuple_filter_parsed(void *parsed_result,
9904                         __attribute__((unused)) struct cmdline *cl,
9905                         __attribute__((unused)) void *data)
9906 {
9907         struct rte_eth_ntuple_filter filter;
9908         struct cmd_2tuple_filter_result *res = parsed_result;
9909         int ret = 0;
9910
9911         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9912         if (ret < 0) {
9913                 printf("ntuple filter is not supported on port %u.\n",
9914                         res->port_id);
9915                 return;
9916         }
9917
9918         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9919
9920         filter.flags = RTE_2TUPLE_FLAGS;
9921         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9922         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9923         filter.proto = res->protocol_value;
9924         filter.priority = res->priority_value;
9925         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9926                 printf("nonzero tcp_flags is only meaningful"
9927                         " when protocol is TCP.\n");
9928                 return;
9929         }
9930         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9931                 printf("invalid TCP flags.\n");
9932                 return;
9933         }
9934
9935         if (res->tcp_flags_value != 0) {
9936                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9937                 filter.tcp_flags = res->tcp_flags_value;
9938         }
9939
9940         /* need convert to big endian. */
9941         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9942         filter.queue = res->queue_id;
9943
9944         if (!strcmp(res->ops, "add"))
9945                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9946                                 RTE_ETH_FILTER_NTUPLE,
9947                                 RTE_ETH_FILTER_ADD,
9948                                 &filter);
9949         else
9950                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9951                                 RTE_ETH_FILTER_NTUPLE,
9952                                 RTE_ETH_FILTER_DELETE,
9953                                 &filter);
9954         if (ret < 0)
9955                 printf("2tuple filter programming error: (%s)\n",
9956                         strerror(-ret));
9957
9958 }
9959
9960 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9961         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9962                                  filter, "2tuple_filter");
9963 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9964         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9965                                 port_id, UINT16);
9966 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9967         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9968                                  ops, "add#del");
9969 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9970         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9971                                 dst_port, "dst_port");
9972 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9973         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9974                                 dst_port_value, UINT16);
9975 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9976         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9977                                 protocol, "protocol");
9978 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9979         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9980                                 protocol_value, UINT8);
9981 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9982         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9983                                 mask, "mask");
9984 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9985         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9986                                 mask_value, INT8);
9987 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9988         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9989                                 tcp_flags, "tcp_flags");
9990 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9991         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9992                                 tcp_flags_value, UINT8);
9993 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9994         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9995                                 priority, "priority");
9996 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9997         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9998                                 priority_value, UINT8);
9999 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10000         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10001                                 queue, "queue");
10002 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10003         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10004                                 queue_id, UINT16);
10005
10006 cmdline_parse_inst_t cmd_2tuple_filter = {
10007         .f = cmd_2tuple_filter_parsed,
10008         .data = NULL,
10009         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10010                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10011                 "<queue_id>: Add a 2tuple filter",
10012         .tokens = {
10013                 (void *)&cmd_2tuple_filter_filter,
10014                 (void *)&cmd_2tuple_filter_port_id,
10015                 (void *)&cmd_2tuple_filter_ops,
10016                 (void *)&cmd_2tuple_filter_dst_port,
10017                 (void *)&cmd_2tuple_filter_dst_port_value,
10018                 (void *)&cmd_2tuple_filter_protocol,
10019                 (void *)&cmd_2tuple_filter_protocol_value,
10020                 (void *)&cmd_2tuple_filter_mask,
10021                 (void *)&cmd_2tuple_filter_mask_value,
10022                 (void *)&cmd_2tuple_filter_tcp_flags,
10023                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10024                 (void *)&cmd_2tuple_filter_priority,
10025                 (void *)&cmd_2tuple_filter_priority_value,
10026                 (void *)&cmd_2tuple_filter_queue,
10027                 (void *)&cmd_2tuple_filter_queue_id,
10028                 NULL,
10029         },
10030 };
10031
10032 /* *** ADD/REMOVE A 5tuple FILTER *** */
10033 struct cmd_5tuple_filter_result {
10034         cmdline_fixed_string_t filter;
10035         portid_t port_id;
10036         cmdline_fixed_string_t ops;
10037         cmdline_fixed_string_t dst_ip;
10038         cmdline_ipaddr_t dst_ip_value;
10039         cmdline_fixed_string_t src_ip;
10040         cmdline_ipaddr_t src_ip_value;
10041         cmdline_fixed_string_t dst_port;
10042         uint16_t dst_port_value;
10043         cmdline_fixed_string_t src_port;
10044         uint16_t src_port_value;
10045         cmdline_fixed_string_t protocol;
10046         uint8_t protocol_value;
10047         cmdline_fixed_string_t mask;
10048         uint8_t  mask_value;
10049         cmdline_fixed_string_t tcp_flags;
10050         uint8_t tcp_flags_value;
10051         cmdline_fixed_string_t priority;
10052         uint8_t  priority_value;
10053         cmdline_fixed_string_t queue;
10054         uint16_t  queue_id;
10055 };
10056
10057 static void
10058 cmd_5tuple_filter_parsed(void *parsed_result,
10059                         __attribute__((unused)) struct cmdline *cl,
10060                         __attribute__((unused)) void *data)
10061 {
10062         struct rte_eth_ntuple_filter filter;
10063         struct cmd_5tuple_filter_result *res = parsed_result;
10064         int ret = 0;
10065
10066         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10067         if (ret < 0) {
10068                 printf("ntuple filter is not supported on port %u.\n",
10069                         res->port_id);
10070                 return;
10071         }
10072
10073         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10074
10075         filter.flags = RTE_5TUPLE_FLAGS;
10076         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10077         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10078         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10079         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10080         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10081         filter.proto = res->protocol_value;
10082         filter.priority = res->priority_value;
10083         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10084                 printf("nonzero tcp_flags is only meaningful"
10085                         " when protocol is TCP.\n");
10086                 return;
10087         }
10088         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10089                 printf("invalid TCP flags.\n");
10090                 return;
10091         }
10092
10093         if (res->tcp_flags_value != 0) {
10094                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10095                 filter.tcp_flags = res->tcp_flags_value;
10096         }
10097
10098         if (res->dst_ip_value.family == AF_INET)
10099                 /* no need to convert, already big endian. */
10100                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10101         else {
10102                 if (filter.dst_ip_mask == 0) {
10103                         printf("can not support ipv6 involved compare.\n");
10104                         return;
10105                 }
10106                 filter.dst_ip = 0;
10107         }
10108
10109         if (res->src_ip_value.family == AF_INET)
10110                 /* no need to convert, already big endian. */
10111                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10112         else {
10113                 if (filter.src_ip_mask == 0) {
10114                         printf("can not support ipv6 involved compare.\n");
10115                         return;
10116                 }
10117                 filter.src_ip = 0;
10118         }
10119         /* need convert to big endian. */
10120         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10121         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10122         filter.queue = res->queue_id;
10123
10124         if (!strcmp(res->ops, "add"))
10125                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10126                                 RTE_ETH_FILTER_NTUPLE,
10127                                 RTE_ETH_FILTER_ADD,
10128                                 &filter);
10129         else
10130                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10131                                 RTE_ETH_FILTER_NTUPLE,
10132                                 RTE_ETH_FILTER_DELETE,
10133                                 &filter);
10134         if (ret < 0)
10135                 printf("5tuple filter programming error: (%s)\n",
10136                         strerror(-ret));
10137 }
10138
10139 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10140         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10141                                  filter, "5tuple_filter");
10142 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10143         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10144                                 port_id, UINT16);
10145 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10146         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10147                                  ops, "add#del");
10148 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10149         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10150                                 dst_ip, "dst_ip");
10151 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10152         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10153                                 dst_ip_value);
10154 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10155         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10156                                 src_ip, "src_ip");
10157 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10158         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10159                                 src_ip_value);
10160 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10161         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10162                                 dst_port, "dst_port");
10163 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10165                                 dst_port_value, UINT16);
10166 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10167         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10168                                 src_port, "src_port");
10169 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10170         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10171                                 src_port_value, UINT16);
10172 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10173         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10174                                 protocol, "protocol");
10175 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10176         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10177                                 protocol_value, UINT8);
10178 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10179         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10180                                 mask, "mask");
10181 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10182         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10183                                 mask_value, INT8);
10184 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10185         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10186                                 tcp_flags, "tcp_flags");
10187 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10188         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10189                                 tcp_flags_value, UINT8);
10190 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10191         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10192                                 priority, "priority");
10193 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10194         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10195                                 priority_value, UINT8);
10196 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10197         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10198                                 queue, "queue");
10199 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10200         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10201                                 queue_id, UINT16);
10202
10203 cmdline_parse_inst_t cmd_5tuple_filter = {
10204         .f = cmd_5tuple_filter_parsed,
10205         .data = NULL,
10206         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10207                 "src_ip <value> dst_port <value> src_port <value> "
10208                 "protocol <value>  mask <value> tcp_flags <value> "
10209                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10210         .tokens = {
10211                 (void *)&cmd_5tuple_filter_filter,
10212                 (void *)&cmd_5tuple_filter_port_id,
10213                 (void *)&cmd_5tuple_filter_ops,
10214                 (void *)&cmd_5tuple_filter_dst_ip,
10215                 (void *)&cmd_5tuple_filter_dst_ip_value,
10216                 (void *)&cmd_5tuple_filter_src_ip,
10217                 (void *)&cmd_5tuple_filter_src_ip_value,
10218                 (void *)&cmd_5tuple_filter_dst_port,
10219                 (void *)&cmd_5tuple_filter_dst_port_value,
10220                 (void *)&cmd_5tuple_filter_src_port,
10221                 (void *)&cmd_5tuple_filter_src_port_value,
10222                 (void *)&cmd_5tuple_filter_protocol,
10223                 (void *)&cmd_5tuple_filter_protocol_value,
10224                 (void *)&cmd_5tuple_filter_mask,
10225                 (void *)&cmd_5tuple_filter_mask_value,
10226                 (void *)&cmd_5tuple_filter_tcp_flags,
10227                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10228                 (void *)&cmd_5tuple_filter_priority,
10229                 (void *)&cmd_5tuple_filter_priority_value,
10230                 (void *)&cmd_5tuple_filter_queue,
10231                 (void *)&cmd_5tuple_filter_queue_id,
10232                 NULL,
10233         },
10234 };
10235
10236 /* *** ADD/REMOVE A flex FILTER *** */
10237 struct cmd_flex_filter_result {
10238         cmdline_fixed_string_t filter;
10239         cmdline_fixed_string_t ops;
10240         portid_t port_id;
10241         cmdline_fixed_string_t len;
10242         uint8_t len_value;
10243         cmdline_fixed_string_t bytes;
10244         cmdline_fixed_string_t bytes_value;
10245         cmdline_fixed_string_t mask;
10246         cmdline_fixed_string_t mask_value;
10247         cmdline_fixed_string_t priority;
10248         uint8_t priority_value;
10249         cmdline_fixed_string_t queue;
10250         uint16_t queue_id;
10251 };
10252
10253 static int xdigit2val(unsigned char c)
10254 {
10255         int val;
10256         if (isdigit(c))
10257                 val = c - '0';
10258         else if (isupper(c))
10259                 val = c - 'A' + 10;
10260         else
10261                 val = c - 'a' + 10;
10262         return val;
10263 }
10264
10265 static void
10266 cmd_flex_filter_parsed(void *parsed_result,
10267                           __attribute__((unused)) struct cmdline *cl,
10268                           __attribute__((unused)) void *data)
10269 {
10270         int ret = 0;
10271         struct rte_eth_flex_filter filter;
10272         struct cmd_flex_filter_result *res = parsed_result;
10273         char *bytes_ptr, *mask_ptr;
10274         uint16_t len, i, j = 0;
10275         char c;
10276         int val;
10277         uint8_t byte = 0;
10278
10279         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10280                 printf("the len exceed the max length 128\n");
10281                 return;
10282         }
10283         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10284         filter.len = res->len_value;
10285         filter.priority = res->priority_value;
10286         filter.queue = res->queue_id;
10287         bytes_ptr = res->bytes_value;
10288         mask_ptr = res->mask_value;
10289
10290          /* translate bytes string to array. */
10291         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10292                 (bytes_ptr[1] == 'X')))
10293                 bytes_ptr += 2;
10294         len = strnlen(bytes_ptr, res->len_value * 2);
10295         if (len == 0 || (len % 8 != 0)) {
10296                 printf("please check len and bytes input\n");
10297                 return;
10298         }
10299         for (i = 0; i < len; i++) {
10300                 c = bytes_ptr[i];
10301                 if (isxdigit(c) == 0) {
10302                         /* invalid characters. */
10303                         printf("invalid input\n");
10304                         return;
10305                 }
10306                 val = xdigit2val(c);
10307                 if (i % 2) {
10308                         byte |= val;
10309                         filter.bytes[j] = byte;
10310                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10311                         j++;
10312                         byte = 0;
10313                 } else
10314                         byte |= val << 4;
10315         }
10316         printf("\n");
10317          /* translate mask string to uint8_t array. */
10318         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10319                 (mask_ptr[1] == 'X')))
10320                 mask_ptr += 2;
10321         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10322         if (len == 0) {
10323                 printf("invalid input\n");
10324                 return;
10325         }
10326         j = 0;
10327         byte = 0;
10328         for (i = 0; i < len; i++) {
10329                 c = mask_ptr[i];
10330                 if (isxdigit(c) == 0) {
10331                         /* invalid characters. */
10332                         printf("invalid input\n");
10333                         return;
10334                 }
10335                 val = xdigit2val(c);
10336                 if (i % 2) {
10337                         byte |= val;
10338                         filter.mask[j] = byte;
10339                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10340                         j++;
10341                         byte = 0;
10342                 } else
10343                         byte |= val << 4;
10344         }
10345         printf("\n");
10346
10347         if (!strcmp(res->ops, "add"))
10348                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10349                                 RTE_ETH_FILTER_FLEXIBLE,
10350                                 RTE_ETH_FILTER_ADD,
10351                                 &filter);
10352         else
10353                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10354                                 RTE_ETH_FILTER_FLEXIBLE,
10355                                 RTE_ETH_FILTER_DELETE,
10356                                 &filter);
10357
10358         if (ret < 0)
10359                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10360 }
10361
10362 cmdline_parse_token_string_t cmd_flex_filter_filter =
10363         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10364                                 filter, "flex_filter");
10365 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10366         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10367                                 port_id, UINT16);
10368 cmdline_parse_token_string_t cmd_flex_filter_ops =
10369         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10370                                 ops, "add#del");
10371 cmdline_parse_token_string_t cmd_flex_filter_len =
10372         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10373                                 len, "len");
10374 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10375         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10376                                 len_value, UINT8);
10377 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10378         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10379                                 bytes, "bytes");
10380 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10381         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10382                                 bytes_value, NULL);
10383 cmdline_parse_token_string_t cmd_flex_filter_mask =
10384         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10385                                 mask, "mask");
10386 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10387         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10388                                 mask_value, NULL);
10389 cmdline_parse_token_string_t cmd_flex_filter_priority =
10390         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10391                                 priority, "priority");
10392 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10393         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10394                                 priority_value, UINT8);
10395 cmdline_parse_token_string_t cmd_flex_filter_queue =
10396         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10397                                 queue, "queue");
10398 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10399         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10400                                 queue_id, UINT16);
10401 cmdline_parse_inst_t cmd_flex_filter = {
10402         .f = cmd_flex_filter_parsed,
10403         .data = NULL,
10404         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10405                 "<value> mask <value> priority <value> queue <queue_id>: "
10406                 "Add/Del a flex filter",
10407         .tokens = {
10408                 (void *)&cmd_flex_filter_filter,
10409                 (void *)&cmd_flex_filter_port_id,
10410                 (void *)&cmd_flex_filter_ops,
10411                 (void *)&cmd_flex_filter_len,
10412                 (void *)&cmd_flex_filter_len_value,
10413                 (void *)&cmd_flex_filter_bytes,
10414                 (void *)&cmd_flex_filter_bytes_value,
10415                 (void *)&cmd_flex_filter_mask,
10416                 (void *)&cmd_flex_filter_mask_value,
10417                 (void *)&cmd_flex_filter_priority,
10418                 (void *)&cmd_flex_filter_priority_value,
10419                 (void *)&cmd_flex_filter_queue,
10420                 (void *)&cmd_flex_filter_queue_id,
10421                 NULL,
10422         },
10423 };
10424
10425 /* *** Filters Control *** */
10426
10427 /* *** deal with ethertype filter *** */
10428 struct cmd_ethertype_filter_result {
10429         cmdline_fixed_string_t filter;
10430         portid_t port_id;
10431         cmdline_fixed_string_t ops;
10432         cmdline_fixed_string_t mac;
10433         struct ether_addr mac_addr;
10434         cmdline_fixed_string_t ethertype;
10435         uint16_t ethertype_value;
10436         cmdline_fixed_string_t drop;
10437         cmdline_fixed_string_t queue;
10438         uint16_t  queue_id;
10439 };
10440
10441 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10442         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10443                                  filter, "ethertype_filter");
10444 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10445         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10446                               port_id, UINT16);
10447 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10448         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10449                                  ops, "add#del");
10450 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10451         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10452                                  mac, "mac_addr#mac_ignr");
10453 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10454         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10455                                      mac_addr);
10456 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10457         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10458                                  ethertype, "ethertype");
10459 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10460         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10461                               ethertype_value, UINT16);
10462 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10463         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10464                                  drop, "drop#fwd");
10465 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10466         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10467                                  queue, "queue");
10468 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10469         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10470                               queue_id, UINT16);
10471
10472 static void
10473 cmd_ethertype_filter_parsed(void *parsed_result,
10474                           __attribute__((unused)) struct cmdline *cl,
10475                           __attribute__((unused)) void *data)
10476 {
10477         struct cmd_ethertype_filter_result *res = parsed_result;
10478         struct rte_eth_ethertype_filter filter;
10479         int ret = 0;
10480
10481         ret = rte_eth_dev_filter_supported(res->port_id,
10482                         RTE_ETH_FILTER_ETHERTYPE);
10483         if (ret < 0) {
10484                 printf("ethertype filter is not supported on port %u.\n",
10485                         res->port_id);
10486                 return;
10487         }
10488
10489         memset(&filter, 0, sizeof(filter));
10490         if (!strcmp(res->mac, "mac_addr")) {
10491                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10492                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10493                         sizeof(struct ether_addr));
10494         }
10495         if (!strcmp(res->drop, "drop"))
10496                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10497         filter.ether_type = res->ethertype_value;
10498         filter.queue = res->queue_id;
10499
10500         if (!strcmp(res->ops, "add"))
10501                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10502                                 RTE_ETH_FILTER_ETHERTYPE,
10503                                 RTE_ETH_FILTER_ADD,
10504                                 &filter);
10505         else
10506                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10507                                 RTE_ETH_FILTER_ETHERTYPE,
10508                                 RTE_ETH_FILTER_DELETE,
10509                                 &filter);
10510         if (ret < 0)
10511                 printf("ethertype filter programming error: (%s)\n",
10512                         strerror(-ret));
10513 }
10514
10515 cmdline_parse_inst_t cmd_ethertype_filter = {
10516         .f = cmd_ethertype_filter_parsed,
10517         .data = NULL,
10518         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10519                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10520                 "Add or delete an ethertype filter entry",
10521         .tokens = {
10522                 (void *)&cmd_ethertype_filter_filter,
10523                 (void *)&cmd_ethertype_filter_port_id,
10524                 (void *)&cmd_ethertype_filter_ops,
10525                 (void *)&cmd_ethertype_filter_mac,
10526                 (void *)&cmd_ethertype_filter_mac_addr,
10527                 (void *)&cmd_ethertype_filter_ethertype,
10528                 (void *)&cmd_ethertype_filter_ethertype_value,
10529                 (void *)&cmd_ethertype_filter_drop,
10530                 (void *)&cmd_ethertype_filter_queue,
10531                 (void *)&cmd_ethertype_filter_queue_id,
10532                 NULL,
10533         },
10534 };
10535
10536 /* *** deal with flow director filter *** */
10537 struct cmd_flow_director_result {
10538         cmdline_fixed_string_t flow_director_filter;
10539         portid_t port_id;
10540         cmdline_fixed_string_t mode;
10541         cmdline_fixed_string_t mode_value;
10542         cmdline_fixed_string_t ops;
10543         cmdline_fixed_string_t flow;
10544         cmdline_fixed_string_t flow_type;
10545         cmdline_fixed_string_t ether;
10546         uint16_t ether_type;
10547         cmdline_fixed_string_t src;
10548         cmdline_ipaddr_t ip_src;
10549         uint16_t port_src;
10550         cmdline_fixed_string_t dst;
10551         cmdline_ipaddr_t ip_dst;
10552         uint16_t port_dst;
10553         cmdline_fixed_string_t verify_tag;
10554         uint32_t verify_tag_value;
10555         cmdline_fixed_string_t tos;
10556         uint8_t tos_value;
10557         cmdline_fixed_string_t proto;
10558         uint8_t proto_value;
10559         cmdline_fixed_string_t ttl;
10560         uint8_t ttl_value;
10561         cmdline_fixed_string_t vlan;
10562         uint16_t vlan_value;
10563         cmdline_fixed_string_t flexbytes;
10564         cmdline_fixed_string_t flexbytes_value;
10565         cmdline_fixed_string_t pf_vf;
10566         cmdline_fixed_string_t drop;
10567         cmdline_fixed_string_t queue;
10568         uint16_t  queue_id;
10569         cmdline_fixed_string_t fd_id;
10570         uint32_t  fd_id_value;
10571         cmdline_fixed_string_t mac;
10572         struct ether_addr mac_addr;
10573         cmdline_fixed_string_t tunnel;
10574         cmdline_fixed_string_t tunnel_type;
10575         cmdline_fixed_string_t tunnel_id;
10576         uint32_t tunnel_id_value;
10577         cmdline_fixed_string_t packet;
10578         char filepath[];
10579 };
10580
10581 static inline int
10582 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10583 {
10584         char s[256];
10585         const char *p, *p0 = q_arg;
10586         char *end;
10587         unsigned long int_fld;
10588         char *str_fld[max_num];
10589         int i;
10590         unsigned size;
10591         int ret = -1;
10592
10593         p = strchr(p0, '(');
10594         if (p == NULL)
10595                 return -1;
10596         ++p;
10597         p0 = strchr(p, ')');
10598         if (p0 == NULL)
10599                 return -1;
10600
10601         size = p0 - p;
10602         if (size >= sizeof(s))
10603                 return -1;
10604
10605         snprintf(s, sizeof(s), "%.*s", size, p);
10606         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10607         if (ret < 0 || ret > max_num)
10608                 return -1;
10609         for (i = 0; i < ret; i++) {
10610                 errno = 0;
10611                 int_fld = strtoul(str_fld[i], &end, 0);
10612                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10613                         return -1;
10614                 flexbytes[i] = (uint8_t)int_fld;
10615         }
10616         return ret;
10617 }
10618
10619 static uint16_t
10620 str2flowtype(char *string)
10621 {
10622         uint8_t i = 0;
10623         static const struct {
10624                 char str[32];
10625                 uint16_t type;
10626         } flowtype_str[] = {
10627                 {"raw", RTE_ETH_FLOW_RAW},
10628                 {"ipv4", RTE_ETH_FLOW_IPV4},
10629                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10630                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10631                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10632                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10633                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10634                 {"ipv6", RTE_ETH_FLOW_IPV6},
10635                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10636                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10637                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10638                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10639                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10640                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10641         };
10642
10643         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10644                 if (!strcmp(flowtype_str[i].str, string))
10645                         return flowtype_str[i].type;
10646         }
10647
10648         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10649                 return (uint16_t)atoi(string);
10650
10651         return RTE_ETH_FLOW_UNKNOWN;
10652 }
10653
10654 static enum rte_eth_fdir_tunnel_type
10655 str2fdir_tunneltype(char *string)
10656 {
10657         uint8_t i = 0;
10658
10659         static const struct {
10660                 char str[32];
10661                 enum rte_eth_fdir_tunnel_type type;
10662         } tunneltype_str[] = {
10663                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10664                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10665         };
10666
10667         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10668                 if (!strcmp(tunneltype_str[i].str, string))
10669                         return tunneltype_str[i].type;
10670         }
10671         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10672 }
10673
10674 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10675 do { \
10676         if ((ip_addr).family == AF_INET) \
10677                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10678         else { \
10679                 printf("invalid parameter.\n"); \
10680                 return; \
10681         } \
10682 } while (0)
10683
10684 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10685 do { \
10686         if ((ip_addr).family == AF_INET6) \
10687                 rte_memcpy(&(ip), \
10688                                  &((ip_addr).addr.ipv6), \
10689                                  sizeof(struct in6_addr)); \
10690         else { \
10691                 printf("invalid parameter.\n"); \
10692                 return; \
10693         } \
10694 } while (0)
10695
10696 static void
10697 cmd_flow_director_filter_parsed(void *parsed_result,
10698                           __attribute__((unused)) struct cmdline *cl,
10699                           __attribute__((unused)) void *data)
10700 {
10701         struct cmd_flow_director_result *res = parsed_result;
10702         struct rte_eth_fdir_filter entry;
10703         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10704         char *end;
10705         unsigned long vf_id;
10706         int ret = 0;
10707
10708         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10709         if (ret < 0) {
10710                 printf("flow director is not supported on port %u.\n",
10711                         res->port_id);
10712                 return;
10713         }
10714         memset(flexbytes, 0, sizeof(flexbytes));
10715         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10716
10717         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10718                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10719                         printf("Please set mode to MAC-VLAN.\n");
10720                         return;
10721                 }
10722         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10723                 if (strcmp(res->mode_value, "Tunnel")) {
10724                         printf("Please set mode to Tunnel.\n");
10725                         return;
10726                 }
10727         } else {
10728                 if (!strcmp(res->mode_value, "raw")) {
10729 #ifdef RTE_LIBRTE_I40E_PMD
10730                         struct rte_pmd_i40e_flow_type_mapping
10731                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10732                         struct rte_pmd_i40e_pkt_template_conf conf;
10733                         uint16_t flow_type = str2flowtype(res->flow_type);
10734                         uint16_t i, port = res->port_id;
10735                         uint8_t add;
10736
10737                         memset(&conf, 0, sizeof(conf));
10738
10739                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10740                                 printf("Invalid flow type specified.\n");
10741                                 return;
10742                         }
10743                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10744                                                                  mapping);
10745                         if (ret)
10746                                 return;
10747                         if (mapping[flow_type].pctype == 0ULL) {
10748                                 printf("Invalid flow type specified.\n");
10749                                 return;
10750                         }
10751                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10752                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10753                                         conf.input.pctype = i;
10754                                         break;
10755                                 }
10756                         }
10757
10758                         conf.input.packet = open_file(res->filepath,
10759                                                 &conf.input.length);
10760                         if (!conf.input.packet)
10761                                 return;
10762                         if (!strcmp(res->drop, "drop"))
10763                                 conf.action.behavior =
10764                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10765                         else
10766                                 conf.action.behavior =
10767                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10768                         conf.action.report_status =
10769                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10770                         conf.action.rx_queue = res->queue_id;
10771                         conf.soft_id = res->fd_id_value;
10772                         add  = strcmp(res->ops, "del") ? 1 : 0;
10773                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10774                                                                         &conf,
10775                                                                         add);
10776                         if (ret < 0)
10777                                 printf("flow director config error: (%s)\n",
10778                                        strerror(-ret));
10779                         close_file(conf.input.packet);
10780 #endif
10781                         return;
10782                 } else if (strcmp(res->mode_value, "IP")) {
10783                         printf("Please set mode to IP or raw.\n");
10784                         return;
10785                 }
10786                 entry.input.flow_type = str2flowtype(res->flow_type);
10787         }
10788
10789         ret = parse_flexbytes(res->flexbytes_value,
10790                                         flexbytes,
10791                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10792         if (ret < 0) {
10793                 printf("error: Cannot parse flexbytes input.\n");
10794                 return;
10795         }
10796
10797         switch (entry.input.flow_type) {
10798         case RTE_ETH_FLOW_FRAG_IPV4:
10799         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10800                 entry.input.flow.ip4_flow.proto = res->proto_value;
10801                 /* fall-through */
10802         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10803         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10804                 IPV4_ADDR_TO_UINT(res->ip_dst,
10805                         entry.input.flow.ip4_flow.dst_ip);
10806                 IPV4_ADDR_TO_UINT(res->ip_src,
10807                         entry.input.flow.ip4_flow.src_ip);
10808                 entry.input.flow.ip4_flow.tos = res->tos_value;
10809                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10810                 /* need convert to big endian. */
10811                 entry.input.flow.udp4_flow.dst_port =
10812                                 rte_cpu_to_be_16(res->port_dst);
10813                 entry.input.flow.udp4_flow.src_port =
10814                                 rte_cpu_to_be_16(res->port_src);
10815                 break;
10816         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10817                 IPV4_ADDR_TO_UINT(res->ip_dst,
10818                         entry.input.flow.sctp4_flow.ip.dst_ip);
10819                 IPV4_ADDR_TO_UINT(res->ip_src,
10820                         entry.input.flow.sctp4_flow.ip.src_ip);
10821                 entry.input.flow.ip4_flow.tos = res->tos_value;
10822                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10823                 /* need convert to big endian. */
10824                 entry.input.flow.sctp4_flow.dst_port =
10825                                 rte_cpu_to_be_16(res->port_dst);
10826                 entry.input.flow.sctp4_flow.src_port =
10827                                 rte_cpu_to_be_16(res->port_src);
10828                 entry.input.flow.sctp4_flow.verify_tag =
10829                                 rte_cpu_to_be_32(res->verify_tag_value);
10830                 break;
10831         case RTE_ETH_FLOW_FRAG_IPV6:
10832         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10833                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10834                 /* fall-through */
10835         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10836         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10837                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10838                         entry.input.flow.ipv6_flow.dst_ip);
10839                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10840                         entry.input.flow.ipv6_flow.src_ip);
10841                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10842                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10843                 /* need convert to big endian. */
10844                 entry.input.flow.udp6_flow.dst_port =
10845                                 rte_cpu_to_be_16(res->port_dst);
10846                 entry.input.flow.udp6_flow.src_port =
10847                                 rte_cpu_to_be_16(res->port_src);
10848                 break;
10849         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10850                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10851                         entry.input.flow.sctp6_flow.ip.dst_ip);
10852                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10853                         entry.input.flow.sctp6_flow.ip.src_ip);
10854                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10855                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10856                 /* need convert to big endian. */
10857                 entry.input.flow.sctp6_flow.dst_port =
10858                                 rte_cpu_to_be_16(res->port_dst);
10859                 entry.input.flow.sctp6_flow.src_port =
10860                                 rte_cpu_to_be_16(res->port_src);
10861                 entry.input.flow.sctp6_flow.verify_tag =
10862                                 rte_cpu_to_be_32(res->verify_tag_value);
10863                 break;
10864         case RTE_ETH_FLOW_L2_PAYLOAD:
10865                 entry.input.flow.l2_flow.ether_type =
10866                         rte_cpu_to_be_16(res->ether_type);
10867                 break;
10868         default:
10869                 break;
10870         }
10871
10872         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10873                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10874                                  &res->mac_addr,
10875                                  sizeof(struct ether_addr));
10876
10877         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10878                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10879                                  &res->mac_addr,
10880                                  sizeof(struct ether_addr));
10881                 entry.input.flow.tunnel_flow.tunnel_type =
10882                         str2fdir_tunneltype(res->tunnel_type);
10883                 entry.input.flow.tunnel_flow.tunnel_id =
10884                         rte_cpu_to_be_32(res->tunnel_id_value);
10885         }
10886
10887         rte_memcpy(entry.input.flow_ext.flexbytes,
10888                    flexbytes,
10889                    RTE_ETH_FDIR_MAX_FLEXLEN);
10890
10891         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10892
10893         entry.action.flex_off = 0;  /*use 0 by default */
10894         if (!strcmp(res->drop, "drop"))
10895                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10896         else
10897                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10898
10899         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10900             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10901                 if (!strcmp(res->pf_vf, "pf"))
10902                         entry.input.flow_ext.is_vf = 0;
10903                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10904                         struct rte_eth_dev_info dev_info;
10905
10906                         memset(&dev_info, 0, sizeof(dev_info));
10907                         rte_eth_dev_info_get(res->port_id, &dev_info);
10908                         errno = 0;
10909                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10910                         if (errno != 0 || *end != '\0' ||
10911                             vf_id >= dev_info.max_vfs) {
10912                                 printf("invalid parameter %s.\n", res->pf_vf);
10913                                 return;
10914                         }
10915                         entry.input.flow_ext.is_vf = 1;
10916                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10917                 } else {
10918                         printf("invalid parameter %s.\n", res->pf_vf);
10919                         return;
10920                 }
10921         }
10922
10923         /* set to report FD ID by default */
10924         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10925         entry.action.rx_queue = res->queue_id;
10926         entry.soft_id = res->fd_id_value;
10927         if (!strcmp(res->ops, "add"))
10928                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10929                                              RTE_ETH_FILTER_ADD, &entry);
10930         else if (!strcmp(res->ops, "del"))
10931                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10932                                              RTE_ETH_FILTER_DELETE, &entry);
10933         else
10934                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10935                                              RTE_ETH_FILTER_UPDATE, &entry);
10936         if (ret < 0)
10937                 printf("flow director programming error: (%s)\n",
10938                         strerror(-ret));
10939 }
10940
10941 cmdline_parse_token_string_t cmd_flow_director_filter =
10942         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10943                                  flow_director_filter, "flow_director_filter");
10944 cmdline_parse_token_num_t cmd_flow_director_port_id =
10945         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10946                               port_id, UINT16);
10947 cmdline_parse_token_string_t cmd_flow_director_ops =
10948         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10949                                  ops, "add#del#update");
10950 cmdline_parse_token_string_t cmd_flow_director_flow =
10951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10952                                  flow, "flow");
10953 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10955                 flow_type, NULL);
10956 cmdline_parse_token_string_t cmd_flow_director_ether =
10957         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10958                                  ether, "ether");
10959 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10960         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10961                               ether_type, UINT16);
10962 cmdline_parse_token_string_t cmd_flow_director_src =
10963         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10964                                  src, "src");
10965 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10966         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10967                                  ip_src);
10968 cmdline_parse_token_num_t cmd_flow_director_port_src =
10969         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10970                               port_src, UINT16);
10971 cmdline_parse_token_string_t cmd_flow_director_dst =
10972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10973                                  dst, "dst");
10974 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10975         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10976                                  ip_dst);
10977 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10978         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10979                               port_dst, UINT16);
10980 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10981         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10982                                   verify_tag, "verify_tag");
10983 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10984         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10985                               verify_tag_value, UINT32);
10986 cmdline_parse_token_string_t cmd_flow_director_tos =
10987         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10988                                  tos, "tos");
10989 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10990         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10991                               tos_value, UINT8);
10992 cmdline_parse_token_string_t cmd_flow_director_proto =
10993         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10994                                  proto, "proto");
10995 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10996         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10997                               proto_value, UINT8);
10998 cmdline_parse_token_string_t cmd_flow_director_ttl =
10999         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11000                                  ttl, "ttl");
11001 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11002         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11003                               ttl_value, UINT8);
11004 cmdline_parse_token_string_t cmd_flow_director_vlan =
11005         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11006                                  vlan, "vlan");
11007 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11008         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11009                               vlan_value, UINT16);
11010 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11011         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11012                                  flexbytes, "flexbytes");
11013 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11015                               flexbytes_value, NULL);
11016 cmdline_parse_token_string_t cmd_flow_director_drop =
11017         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11018                                  drop, "drop#fwd");
11019 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11021                               pf_vf, NULL);
11022 cmdline_parse_token_string_t cmd_flow_director_queue =
11023         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11024                                  queue, "queue");
11025 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11026         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11027                               queue_id, UINT16);
11028 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11029         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11030                                  fd_id, "fd_id");
11031 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11032         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11033                               fd_id_value, UINT32);
11034
11035 cmdline_parse_token_string_t cmd_flow_director_mode =
11036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11037                                  mode, "mode");
11038 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11040                                  mode_value, "IP");
11041 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11043                                  mode_value, "MAC-VLAN");
11044 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11046                                  mode_value, "Tunnel");
11047 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11048         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11049                                  mode_value, "raw");
11050 cmdline_parse_token_string_t cmd_flow_director_mac =
11051         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11052                                  mac, "mac");
11053 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11054         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11055                                     mac_addr);
11056 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11058                                  tunnel, "tunnel");
11059 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11060         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11061                                  tunnel_type, "NVGRE#VxLAN");
11062 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11063         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11064                                  tunnel_id, "tunnel-id");
11065 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11066         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11067                               tunnel_id_value, UINT32);
11068 cmdline_parse_token_string_t cmd_flow_director_packet =
11069         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11070                                  packet, "packet");
11071 cmdline_parse_token_string_t cmd_flow_director_filepath =
11072         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11073                                  filepath, NULL);
11074
11075 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11076         .f = cmd_flow_director_filter_parsed,
11077         .data = NULL,
11078         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11079                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11080                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11081                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11082                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11083                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11084                 "fd_id <fd_id_value>: "
11085                 "Add or delete an ip flow director entry on NIC",
11086         .tokens = {
11087                 (void *)&cmd_flow_director_filter,
11088                 (void *)&cmd_flow_director_port_id,
11089                 (void *)&cmd_flow_director_mode,
11090                 (void *)&cmd_flow_director_mode_ip,
11091                 (void *)&cmd_flow_director_ops,
11092                 (void *)&cmd_flow_director_flow,
11093                 (void *)&cmd_flow_director_flow_type,
11094                 (void *)&cmd_flow_director_src,
11095                 (void *)&cmd_flow_director_ip_src,
11096                 (void *)&cmd_flow_director_dst,
11097                 (void *)&cmd_flow_director_ip_dst,
11098                 (void *)&cmd_flow_director_tos,
11099                 (void *)&cmd_flow_director_tos_value,
11100                 (void *)&cmd_flow_director_proto,
11101                 (void *)&cmd_flow_director_proto_value,
11102                 (void *)&cmd_flow_director_ttl,
11103                 (void *)&cmd_flow_director_ttl_value,
11104                 (void *)&cmd_flow_director_vlan,
11105                 (void *)&cmd_flow_director_vlan_value,
11106                 (void *)&cmd_flow_director_flexbytes,
11107                 (void *)&cmd_flow_director_flexbytes_value,
11108                 (void *)&cmd_flow_director_drop,
11109                 (void *)&cmd_flow_director_pf_vf,
11110                 (void *)&cmd_flow_director_queue,
11111                 (void *)&cmd_flow_director_queue_id,
11112                 (void *)&cmd_flow_director_fd_id,
11113                 (void *)&cmd_flow_director_fd_id_value,
11114                 NULL,
11115         },
11116 };
11117
11118 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11119         .f = cmd_flow_director_filter_parsed,
11120         .data = NULL,
11121         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11122                 "director entry on NIC",
11123         .tokens = {
11124                 (void *)&cmd_flow_director_filter,
11125                 (void *)&cmd_flow_director_port_id,
11126                 (void *)&cmd_flow_director_mode,
11127                 (void *)&cmd_flow_director_mode_ip,
11128                 (void *)&cmd_flow_director_ops,
11129                 (void *)&cmd_flow_director_flow,
11130                 (void *)&cmd_flow_director_flow_type,
11131                 (void *)&cmd_flow_director_src,
11132                 (void *)&cmd_flow_director_ip_src,
11133                 (void *)&cmd_flow_director_port_src,
11134                 (void *)&cmd_flow_director_dst,
11135                 (void *)&cmd_flow_director_ip_dst,
11136                 (void *)&cmd_flow_director_port_dst,
11137                 (void *)&cmd_flow_director_tos,
11138                 (void *)&cmd_flow_director_tos_value,
11139                 (void *)&cmd_flow_director_ttl,
11140                 (void *)&cmd_flow_director_ttl_value,
11141                 (void *)&cmd_flow_director_vlan,
11142                 (void *)&cmd_flow_director_vlan_value,
11143                 (void *)&cmd_flow_director_flexbytes,
11144                 (void *)&cmd_flow_director_flexbytes_value,
11145                 (void *)&cmd_flow_director_drop,
11146                 (void *)&cmd_flow_director_pf_vf,
11147                 (void *)&cmd_flow_director_queue,
11148                 (void *)&cmd_flow_director_queue_id,
11149                 (void *)&cmd_flow_director_fd_id,
11150                 (void *)&cmd_flow_director_fd_id_value,
11151                 NULL,
11152         },
11153 };
11154
11155 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11156         .f = cmd_flow_director_filter_parsed,
11157         .data = NULL,
11158         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11159                 "director entry on NIC",
11160         .tokens = {
11161                 (void *)&cmd_flow_director_filter,
11162                 (void *)&cmd_flow_director_port_id,
11163                 (void *)&cmd_flow_director_mode,
11164                 (void *)&cmd_flow_director_mode_ip,
11165                 (void *)&cmd_flow_director_ops,
11166                 (void *)&cmd_flow_director_flow,
11167                 (void *)&cmd_flow_director_flow_type,
11168                 (void *)&cmd_flow_director_src,
11169                 (void *)&cmd_flow_director_ip_src,
11170                 (void *)&cmd_flow_director_port_src,
11171                 (void *)&cmd_flow_director_dst,
11172                 (void *)&cmd_flow_director_ip_dst,
11173                 (void *)&cmd_flow_director_port_dst,
11174                 (void *)&cmd_flow_director_verify_tag,
11175                 (void *)&cmd_flow_director_verify_tag_value,
11176                 (void *)&cmd_flow_director_tos,
11177                 (void *)&cmd_flow_director_tos_value,
11178                 (void *)&cmd_flow_director_ttl,
11179                 (void *)&cmd_flow_director_ttl_value,
11180                 (void *)&cmd_flow_director_vlan,
11181                 (void *)&cmd_flow_director_vlan_value,
11182                 (void *)&cmd_flow_director_flexbytes,
11183                 (void *)&cmd_flow_director_flexbytes_value,
11184                 (void *)&cmd_flow_director_drop,
11185                 (void *)&cmd_flow_director_pf_vf,
11186                 (void *)&cmd_flow_director_queue,
11187                 (void *)&cmd_flow_director_queue_id,
11188                 (void *)&cmd_flow_director_fd_id,
11189                 (void *)&cmd_flow_director_fd_id_value,
11190                 NULL,
11191         },
11192 };
11193
11194 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11195         .f = cmd_flow_director_filter_parsed,
11196         .data = NULL,
11197         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11198                 "director entry on NIC",
11199         .tokens = {
11200                 (void *)&cmd_flow_director_filter,
11201                 (void *)&cmd_flow_director_port_id,
11202                 (void *)&cmd_flow_director_mode,
11203                 (void *)&cmd_flow_director_mode_ip,
11204                 (void *)&cmd_flow_director_ops,
11205                 (void *)&cmd_flow_director_flow,
11206                 (void *)&cmd_flow_director_flow_type,
11207                 (void *)&cmd_flow_director_ether,
11208                 (void *)&cmd_flow_director_ether_type,
11209                 (void *)&cmd_flow_director_flexbytes,
11210                 (void *)&cmd_flow_director_flexbytes_value,
11211                 (void *)&cmd_flow_director_drop,
11212                 (void *)&cmd_flow_director_pf_vf,
11213                 (void *)&cmd_flow_director_queue,
11214                 (void *)&cmd_flow_director_queue_id,
11215                 (void *)&cmd_flow_director_fd_id,
11216                 (void *)&cmd_flow_director_fd_id_value,
11217                 NULL,
11218         },
11219 };
11220
11221 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11222         .f = cmd_flow_director_filter_parsed,
11223         .data = NULL,
11224         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11225                 "director entry on NIC",
11226         .tokens = {
11227                 (void *)&cmd_flow_director_filter,
11228                 (void *)&cmd_flow_director_port_id,
11229                 (void *)&cmd_flow_director_mode,
11230                 (void *)&cmd_flow_director_mode_mac_vlan,
11231                 (void *)&cmd_flow_director_ops,
11232                 (void *)&cmd_flow_director_mac,
11233                 (void *)&cmd_flow_director_mac_addr,
11234                 (void *)&cmd_flow_director_vlan,
11235                 (void *)&cmd_flow_director_vlan_value,
11236                 (void *)&cmd_flow_director_flexbytes,
11237                 (void *)&cmd_flow_director_flexbytes_value,
11238                 (void *)&cmd_flow_director_drop,
11239                 (void *)&cmd_flow_director_queue,
11240                 (void *)&cmd_flow_director_queue_id,
11241                 (void *)&cmd_flow_director_fd_id,
11242                 (void *)&cmd_flow_director_fd_id_value,
11243                 NULL,
11244         },
11245 };
11246
11247 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11248         .f = cmd_flow_director_filter_parsed,
11249         .data = NULL,
11250         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11251                 "director entry on NIC",
11252         .tokens = {
11253                 (void *)&cmd_flow_director_filter,
11254                 (void *)&cmd_flow_director_port_id,
11255                 (void *)&cmd_flow_director_mode,
11256                 (void *)&cmd_flow_director_mode_tunnel,
11257                 (void *)&cmd_flow_director_ops,
11258                 (void *)&cmd_flow_director_mac,
11259                 (void *)&cmd_flow_director_mac_addr,
11260                 (void *)&cmd_flow_director_vlan,
11261                 (void *)&cmd_flow_director_vlan_value,
11262                 (void *)&cmd_flow_director_tunnel,
11263                 (void *)&cmd_flow_director_tunnel_type,
11264                 (void *)&cmd_flow_director_tunnel_id,
11265                 (void *)&cmd_flow_director_tunnel_id_value,
11266                 (void *)&cmd_flow_director_flexbytes,
11267                 (void *)&cmd_flow_director_flexbytes_value,
11268                 (void *)&cmd_flow_director_drop,
11269                 (void *)&cmd_flow_director_queue,
11270                 (void *)&cmd_flow_director_queue_id,
11271                 (void *)&cmd_flow_director_fd_id,
11272                 (void *)&cmd_flow_director_fd_id_value,
11273                 NULL,
11274         },
11275 };
11276
11277 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11278         .f = cmd_flow_director_filter_parsed,
11279         .data = NULL,
11280         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11281                 "director entry on NIC",
11282         .tokens = {
11283                 (void *)&cmd_flow_director_filter,
11284                 (void *)&cmd_flow_director_port_id,
11285                 (void *)&cmd_flow_director_mode,
11286                 (void *)&cmd_flow_director_mode_raw,
11287                 (void *)&cmd_flow_director_ops,
11288                 (void *)&cmd_flow_director_flow,
11289                 (void *)&cmd_flow_director_flow_type,
11290                 (void *)&cmd_flow_director_drop,
11291                 (void *)&cmd_flow_director_queue,
11292                 (void *)&cmd_flow_director_queue_id,
11293                 (void *)&cmd_flow_director_fd_id,
11294                 (void *)&cmd_flow_director_fd_id_value,
11295                 (void *)&cmd_flow_director_packet,
11296                 (void *)&cmd_flow_director_filepath,
11297                 NULL,
11298         },
11299 };
11300
11301 struct cmd_flush_flow_director_result {
11302         cmdline_fixed_string_t flush_flow_director;
11303         portid_t port_id;
11304 };
11305
11306 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11307         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11308                                  flush_flow_director, "flush_flow_director");
11309 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11310         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11311                               port_id, UINT16);
11312
11313 static void
11314 cmd_flush_flow_director_parsed(void *parsed_result,
11315                           __attribute__((unused)) struct cmdline *cl,
11316                           __attribute__((unused)) void *data)
11317 {
11318         struct cmd_flow_director_result *res = parsed_result;
11319         int ret = 0;
11320
11321         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11322         if (ret < 0) {
11323                 printf("flow director is not supported on port %u.\n",
11324                         res->port_id);
11325                 return;
11326         }
11327
11328         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11329                         RTE_ETH_FILTER_FLUSH, NULL);
11330         if (ret < 0)
11331                 printf("flow director table flushing error: (%s)\n",
11332                         strerror(-ret));
11333 }
11334
11335 cmdline_parse_inst_t cmd_flush_flow_director = {
11336         .f = cmd_flush_flow_director_parsed,
11337         .data = NULL,
11338         .help_str = "flush_flow_director <port_id>: "
11339                 "Flush all flow director entries of a device on NIC",
11340         .tokens = {
11341                 (void *)&cmd_flush_flow_director_flush,
11342                 (void *)&cmd_flush_flow_director_port_id,
11343                 NULL,
11344         },
11345 };
11346
11347 /* *** deal with flow director mask *** */
11348 struct cmd_flow_director_mask_result {
11349         cmdline_fixed_string_t flow_director_mask;
11350         portid_t port_id;
11351         cmdline_fixed_string_t mode;
11352         cmdline_fixed_string_t mode_value;
11353         cmdline_fixed_string_t vlan;
11354         uint16_t vlan_mask;
11355         cmdline_fixed_string_t src_mask;
11356         cmdline_ipaddr_t ipv4_src;
11357         cmdline_ipaddr_t ipv6_src;
11358         uint16_t port_src;
11359         cmdline_fixed_string_t dst_mask;
11360         cmdline_ipaddr_t ipv4_dst;
11361         cmdline_ipaddr_t ipv6_dst;
11362         uint16_t port_dst;
11363         cmdline_fixed_string_t mac;
11364         uint8_t mac_addr_byte_mask;
11365         cmdline_fixed_string_t tunnel_id;
11366         uint32_t tunnel_id_mask;
11367         cmdline_fixed_string_t tunnel_type;
11368         uint8_t tunnel_type_mask;
11369 };
11370
11371 static void
11372 cmd_flow_director_mask_parsed(void *parsed_result,
11373                           __attribute__((unused)) struct cmdline *cl,
11374                           __attribute__((unused)) void *data)
11375 {
11376         struct cmd_flow_director_mask_result *res = parsed_result;
11377         struct rte_eth_fdir_masks *mask;
11378         struct rte_port *port;
11379
11380         port = &ports[res->port_id];
11381         /** Check if the port is not started **/
11382         if (port->port_status != RTE_PORT_STOPPED) {
11383                 printf("Please stop port %d first\n", res->port_id);
11384                 return;
11385         }
11386
11387         mask = &port->dev_conf.fdir_conf.mask;
11388
11389         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11390                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11391                         printf("Please set mode to MAC-VLAN.\n");
11392                         return;
11393                 }
11394
11395                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11396         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11397                 if (strcmp(res->mode_value, "Tunnel")) {
11398                         printf("Please set mode to Tunnel.\n");
11399                         return;
11400                 }
11401
11402                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11403                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11404                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11405                 mask->tunnel_type_mask = res->tunnel_type_mask;
11406         } else {
11407                 if (strcmp(res->mode_value, "IP")) {
11408                         printf("Please set mode to IP.\n");
11409                         return;
11410                 }
11411
11412                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11413                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11414                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11415                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11416                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11417                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11418                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11419         }
11420
11421         cmd_reconfig_device_queue(res->port_id, 1, 1);
11422 }
11423
11424 cmdline_parse_token_string_t cmd_flow_director_mask =
11425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11426                                  flow_director_mask, "flow_director_mask");
11427 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11428         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11429                               port_id, UINT16);
11430 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11432                                  vlan, "vlan");
11433 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11434         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11435                               vlan_mask, UINT16);
11436 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11438                                  src_mask, "src_mask");
11439 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11440         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11441                                  ipv4_src);
11442 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11443         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11444                                  ipv6_src);
11445 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11446         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11447                               port_src, UINT16);
11448 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11449         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11450                                  dst_mask, "dst_mask");
11451 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11452         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11453                                  ipv4_dst);
11454 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11455         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11456                                  ipv6_dst);
11457 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11458         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11459                               port_dst, UINT16);
11460
11461 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11463                                  mode, "mode");
11464 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11465         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11466                                  mode_value, "IP");
11467 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11468         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11469                                  mode_value, "MAC-VLAN");
11470 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11471         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11472                                  mode_value, "Tunnel");
11473 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11474         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11475                                  mac, "mac");
11476 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11477         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11478                               mac_addr_byte_mask, UINT8);
11479 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11480         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11481                                  tunnel_type, "tunnel-type");
11482 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11483         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11484                               tunnel_type_mask, UINT8);
11485 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11486         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11487                                  tunnel_id, "tunnel-id");
11488 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11489         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11490                               tunnel_id_mask, UINT32);
11491
11492 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11493         .f = cmd_flow_director_mask_parsed,
11494         .data = NULL,
11495         .help_str = "flow_director_mask ... : "
11496                 "Set IP mode flow director's mask on NIC",
11497         .tokens = {
11498                 (void *)&cmd_flow_director_mask,
11499                 (void *)&cmd_flow_director_mask_port_id,
11500                 (void *)&cmd_flow_director_mask_mode,
11501                 (void *)&cmd_flow_director_mask_mode_ip,
11502                 (void *)&cmd_flow_director_mask_vlan,
11503                 (void *)&cmd_flow_director_mask_vlan_value,
11504                 (void *)&cmd_flow_director_mask_src,
11505                 (void *)&cmd_flow_director_mask_ipv4_src,
11506                 (void *)&cmd_flow_director_mask_ipv6_src,
11507                 (void *)&cmd_flow_director_mask_port_src,
11508                 (void *)&cmd_flow_director_mask_dst,
11509                 (void *)&cmd_flow_director_mask_ipv4_dst,
11510                 (void *)&cmd_flow_director_mask_ipv6_dst,
11511                 (void *)&cmd_flow_director_mask_port_dst,
11512                 NULL,
11513         },
11514 };
11515
11516 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11517         .f = cmd_flow_director_mask_parsed,
11518         .data = NULL,
11519         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11520                 "flow director's mask on NIC",
11521         .tokens = {
11522                 (void *)&cmd_flow_director_mask,
11523                 (void *)&cmd_flow_director_mask_port_id,
11524                 (void *)&cmd_flow_director_mask_mode,
11525                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11526                 (void *)&cmd_flow_director_mask_vlan,
11527                 (void *)&cmd_flow_director_mask_vlan_value,
11528                 NULL,
11529         },
11530 };
11531
11532 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11533         .f = cmd_flow_director_mask_parsed,
11534         .data = NULL,
11535         .help_str = "flow_director_mask ... : Set tunnel mode "
11536                 "flow director's mask on NIC",
11537         .tokens = {
11538                 (void *)&cmd_flow_director_mask,
11539                 (void *)&cmd_flow_director_mask_port_id,
11540                 (void *)&cmd_flow_director_mask_mode,
11541                 (void *)&cmd_flow_director_mask_mode_tunnel,
11542                 (void *)&cmd_flow_director_mask_vlan,
11543                 (void *)&cmd_flow_director_mask_vlan_value,
11544                 (void *)&cmd_flow_director_mask_mac,
11545                 (void *)&cmd_flow_director_mask_mac_value,
11546                 (void *)&cmd_flow_director_mask_tunnel_type,
11547                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11548                 (void *)&cmd_flow_director_mask_tunnel_id,
11549                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11550                 NULL,
11551         },
11552 };
11553
11554 /* *** deal with flow director mask on flexible payload *** */
11555 struct cmd_flow_director_flex_mask_result {
11556         cmdline_fixed_string_t flow_director_flexmask;
11557         portid_t port_id;
11558         cmdline_fixed_string_t flow;
11559         cmdline_fixed_string_t flow_type;
11560         cmdline_fixed_string_t mask;
11561 };
11562
11563 static void
11564 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11565                           __attribute__((unused)) struct cmdline *cl,
11566                           __attribute__((unused)) void *data)
11567 {
11568         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11569         struct rte_eth_fdir_info fdir_info;
11570         struct rte_eth_fdir_flex_mask flex_mask;
11571         struct rte_port *port;
11572         uint64_t flow_type_mask;
11573         uint16_t i;
11574         int ret;
11575
11576         port = &ports[res->port_id];
11577         /** Check if the port is not started **/
11578         if (port->port_status != RTE_PORT_STOPPED) {
11579                 printf("Please stop port %d first\n", res->port_id);
11580                 return;
11581         }
11582
11583         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11584         ret = parse_flexbytes(res->mask,
11585                         flex_mask.mask,
11586                         RTE_ETH_FDIR_MAX_FLEXLEN);
11587         if (ret < 0) {
11588                 printf("error: Cannot parse mask input.\n");
11589                 return;
11590         }
11591
11592         memset(&fdir_info, 0, sizeof(fdir_info));
11593         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11594                                 RTE_ETH_FILTER_INFO, &fdir_info);
11595         if (ret < 0) {
11596                 printf("Cannot get FDir filter info\n");
11597                 return;
11598         }
11599
11600         if (!strcmp(res->flow_type, "none")) {
11601                 /* means don't specify the flow type */
11602                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11603                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11604                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11605                                0, sizeof(struct rte_eth_fdir_flex_mask));
11606                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11607                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11608                                  &flex_mask,
11609                                  sizeof(struct rte_eth_fdir_flex_mask));
11610                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11611                 return;
11612         }
11613         flow_type_mask = fdir_info.flow_types_mask[0];
11614         if (!strcmp(res->flow_type, "all")) {
11615                 if (!flow_type_mask) {
11616                         printf("No flow type supported\n");
11617                         return;
11618                 }
11619                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11620                         if (flow_type_mask & (1ULL << i)) {
11621                                 flex_mask.flow_type = i;
11622                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11623                         }
11624                 }
11625                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11626                 return;
11627         }
11628         flex_mask.flow_type = str2flowtype(res->flow_type);
11629         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11630                 printf("Flow type %s not supported on port %d\n",
11631                                 res->flow_type, res->port_id);
11632                 return;
11633         }
11634         fdir_set_flex_mask(res->port_id, &flex_mask);
11635         cmd_reconfig_device_queue(res->port_id, 1, 1);
11636 }
11637
11638 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11639         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11640                                  flow_director_flexmask,
11641                                  "flow_director_flex_mask");
11642 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11643         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11644                               port_id, UINT16);
11645 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11647                                  flow, "flow");
11648 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11649         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11650                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11651                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11652 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11654                                  mask, NULL);
11655
11656 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11657         .f = cmd_flow_director_flex_mask_parsed,
11658         .data = NULL,
11659         .help_str = "flow_director_flex_mask ... : "
11660                 "Set flow director's flex mask on NIC",
11661         .tokens = {
11662                 (void *)&cmd_flow_director_flexmask,
11663                 (void *)&cmd_flow_director_flexmask_port_id,
11664                 (void *)&cmd_flow_director_flexmask_flow,
11665                 (void *)&cmd_flow_director_flexmask_flow_type,
11666                 (void *)&cmd_flow_director_flexmask_mask,
11667                 NULL,
11668         },
11669 };
11670
11671 /* *** deal with flow director flexible payload configuration *** */
11672 struct cmd_flow_director_flexpayload_result {
11673         cmdline_fixed_string_t flow_director_flexpayload;
11674         portid_t port_id;
11675         cmdline_fixed_string_t payload_layer;
11676         cmdline_fixed_string_t payload_cfg;
11677 };
11678
11679 static inline int
11680 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11681 {
11682         char s[256];
11683         const char *p, *p0 = q_arg;
11684         char *end;
11685         unsigned long int_fld;
11686         char *str_fld[max_num];
11687         int i;
11688         unsigned size;
11689         int ret = -1;
11690
11691         p = strchr(p0, '(');
11692         if (p == NULL)
11693                 return -1;
11694         ++p;
11695         p0 = strchr(p, ')');
11696         if (p0 == NULL)
11697                 return -1;
11698
11699         size = p0 - p;
11700         if (size >= sizeof(s))
11701                 return -1;
11702
11703         snprintf(s, sizeof(s), "%.*s", size, p);
11704         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11705         if (ret < 0 || ret > max_num)
11706                 return -1;
11707         for (i = 0; i < ret; i++) {
11708                 errno = 0;
11709                 int_fld = strtoul(str_fld[i], &end, 0);
11710                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11711                         return -1;
11712                 offsets[i] = (uint16_t)int_fld;
11713         }
11714         return ret;
11715 }
11716
11717 static void
11718 cmd_flow_director_flxpld_parsed(void *parsed_result,
11719                           __attribute__((unused)) struct cmdline *cl,
11720                           __attribute__((unused)) void *data)
11721 {
11722         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11723         struct rte_eth_flex_payload_cfg flex_cfg;
11724         struct rte_port *port;
11725         int ret = 0;
11726
11727         port = &ports[res->port_id];
11728         /** Check if the port is not started **/
11729         if (port->port_status != RTE_PORT_STOPPED) {
11730                 printf("Please stop port %d first\n", res->port_id);
11731                 return;
11732         }
11733
11734         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11735
11736         if (!strcmp(res->payload_layer, "raw"))
11737                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11738         else if (!strcmp(res->payload_layer, "l2"))
11739                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11740         else if (!strcmp(res->payload_layer, "l3"))
11741                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11742         else if (!strcmp(res->payload_layer, "l4"))
11743                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11744
11745         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11746                             RTE_ETH_FDIR_MAX_FLEXLEN);
11747         if (ret < 0) {
11748                 printf("error: Cannot parse flex payload input.\n");
11749                 return;
11750         }
11751
11752         fdir_set_flex_payload(res->port_id, &flex_cfg);
11753         cmd_reconfig_device_queue(res->port_id, 1, 1);
11754 }
11755
11756 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11757         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11758                                  flow_director_flexpayload,
11759                                  "flow_director_flex_payload");
11760 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11761         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11762                               port_id, UINT16);
11763 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11764         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11765                                  payload_layer, "raw#l2#l3#l4");
11766 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11768                                  payload_cfg, NULL);
11769
11770 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11771         .f = cmd_flow_director_flxpld_parsed,
11772         .data = NULL,
11773         .help_str = "flow_director_flexpayload ... : "
11774                 "Set flow director's flex payload on NIC",
11775         .tokens = {
11776                 (void *)&cmd_flow_director_flexpayload,
11777                 (void *)&cmd_flow_director_flexpayload_port_id,
11778                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11779                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11780                 NULL,
11781         },
11782 };
11783
11784 /* Generic flow interface command. */
11785 extern cmdline_parse_inst_t cmd_flow;
11786
11787 /* *** Classification Filters Control *** */
11788 /* *** Get symmetric hash enable per port *** */
11789 struct cmd_get_sym_hash_ena_per_port_result {
11790         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11791         portid_t port_id;
11792 };
11793
11794 static void
11795 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11796                                  __rte_unused struct cmdline *cl,
11797                                  __rte_unused void *data)
11798 {
11799         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11800         struct rte_eth_hash_filter_info info;
11801         int ret;
11802
11803         if (rte_eth_dev_filter_supported(res->port_id,
11804                                 RTE_ETH_FILTER_HASH) < 0) {
11805                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11806                                                         res->port_id);
11807                 return;
11808         }
11809
11810         memset(&info, 0, sizeof(info));
11811         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11812         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11813                                                 RTE_ETH_FILTER_GET, &info);
11814
11815         if (ret < 0) {
11816                 printf("Cannot get symmetric hash enable per port "
11817                                         "on port %u\n", res->port_id);
11818                 return;
11819         }
11820
11821         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11822                                 "enabled" : "disabled", res->port_id);
11823 }
11824
11825 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11826         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11827                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11828 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11829         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11830                 port_id, UINT16);
11831
11832 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11833         .f = cmd_get_sym_hash_per_port_parsed,
11834         .data = NULL,
11835         .help_str = "get_sym_hash_ena_per_port <port_id>",
11836         .tokens = {
11837                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11838                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11839                 NULL,
11840         },
11841 };
11842
11843 /* *** Set symmetric hash enable per port *** */
11844 struct cmd_set_sym_hash_ena_per_port_result {
11845         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11846         cmdline_fixed_string_t enable;
11847         portid_t port_id;
11848 };
11849
11850 static void
11851 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11852                                  __rte_unused struct cmdline *cl,
11853                                  __rte_unused void *data)
11854 {
11855         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11856         struct rte_eth_hash_filter_info info;
11857         int ret;
11858
11859         if (rte_eth_dev_filter_supported(res->port_id,
11860                                 RTE_ETH_FILTER_HASH) < 0) {
11861                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11862                                                         res->port_id);
11863                 return;
11864         }
11865
11866         memset(&info, 0, sizeof(info));
11867         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11868         if (!strcmp(res->enable, "enable"))
11869                 info.info.enable = 1;
11870         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11871                                         RTE_ETH_FILTER_SET, &info);
11872         if (ret < 0) {
11873                 printf("Cannot set symmetric hash enable per port on "
11874                                         "port %u\n", res->port_id);
11875                 return;
11876         }
11877         printf("Symmetric hash has been set to %s on port %u\n",
11878                                         res->enable, res->port_id);
11879 }
11880
11881 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11882         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11883                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11884 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11885         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11886                 port_id, UINT16);
11887 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11888         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11889                 enable, "enable#disable");
11890
11891 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11892         .f = cmd_set_sym_hash_per_port_parsed,
11893         .data = NULL,
11894         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11895         .tokens = {
11896                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11897                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11898                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11899                 NULL,
11900         },
11901 };
11902
11903 /* Get global config of hash function */
11904 struct cmd_get_hash_global_config_result {
11905         cmdline_fixed_string_t get_hash_global_config;
11906         portid_t port_id;
11907 };
11908
11909 static char *
11910 flowtype_to_str(uint16_t ftype)
11911 {
11912         uint16_t i;
11913         static struct {
11914                 char str[16];
11915                 uint16_t ftype;
11916         } ftype_table[] = {
11917                 {"ipv4", RTE_ETH_FLOW_IPV4},
11918                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11919                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11920                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11921                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11922                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11923                 {"ipv6", RTE_ETH_FLOW_IPV6},
11924                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11925                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11926                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11927                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11928                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11929                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11930                 {"port", RTE_ETH_FLOW_PORT},
11931                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11932                 {"geneve", RTE_ETH_FLOW_GENEVE},
11933                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11934         };
11935
11936         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11937                 if (ftype_table[i].ftype == ftype)
11938                         return ftype_table[i].str;
11939         }
11940
11941         return NULL;
11942 }
11943
11944 static void
11945 cmd_get_hash_global_config_parsed(void *parsed_result,
11946                                   __rte_unused struct cmdline *cl,
11947                                   __rte_unused void *data)
11948 {
11949         struct cmd_get_hash_global_config_result *res = parsed_result;
11950         struct rte_eth_hash_filter_info info;
11951         uint32_t idx, offset;
11952         uint16_t i;
11953         char *str;
11954         int ret;
11955
11956         if (rte_eth_dev_filter_supported(res->port_id,
11957                         RTE_ETH_FILTER_HASH) < 0) {
11958                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11959                                                         res->port_id);
11960                 return;
11961         }
11962
11963         memset(&info, 0, sizeof(info));
11964         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11965         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11966                                         RTE_ETH_FILTER_GET, &info);
11967         if (ret < 0) {
11968                 printf("Cannot get hash global configurations by port %d\n",
11969                                                         res->port_id);
11970                 return;
11971         }
11972
11973         switch (info.info.global_conf.hash_func) {
11974         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11975                 printf("Hash function is Toeplitz\n");
11976                 break;
11977         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11978                 printf("Hash function is Simple XOR\n");
11979                 break;
11980         default:
11981                 printf("Unknown hash function\n");
11982                 break;
11983         }
11984
11985         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11986                 idx = i / UINT64_BIT;
11987                 offset = i % UINT64_BIT;
11988                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11989                                                 (1ULL << offset)))
11990                         continue;
11991                 str = flowtype_to_str(i);
11992                 if (!str)
11993                         continue;
11994                 printf("Symmetric hash is %s globally for flow type %s "
11995                                                         "by port %d\n",
11996                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11997                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11998                                                         res->port_id);
11999         }
12000 }
12001
12002 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12003         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12004                 get_hash_global_config, "get_hash_global_config");
12005 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12006         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12007                 port_id, UINT16);
12008
12009 cmdline_parse_inst_t cmd_get_hash_global_config = {
12010         .f = cmd_get_hash_global_config_parsed,
12011         .data = NULL,
12012         .help_str = "get_hash_global_config <port_id>",
12013         .tokens = {
12014                 (void *)&cmd_get_hash_global_config_all,
12015                 (void *)&cmd_get_hash_global_config_port_id,
12016                 NULL,
12017         },
12018 };
12019
12020 /* Set global config of hash function */
12021 struct cmd_set_hash_global_config_result {
12022         cmdline_fixed_string_t set_hash_global_config;
12023         portid_t port_id;
12024         cmdline_fixed_string_t hash_func;
12025         cmdline_fixed_string_t flow_type;
12026         cmdline_fixed_string_t enable;
12027 };
12028
12029 static void
12030 cmd_set_hash_global_config_parsed(void *parsed_result,
12031                                   __rte_unused struct cmdline *cl,
12032                                   __rte_unused void *data)
12033 {
12034         struct cmd_set_hash_global_config_result *res = parsed_result;
12035         struct rte_eth_hash_filter_info info;
12036         uint32_t ftype, idx, offset;
12037         int ret;
12038
12039         if (rte_eth_dev_filter_supported(res->port_id,
12040                                 RTE_ETH_FILTER_HASH) < 0) {
12041                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12042                                                         res->port_id);
12043                 return;
12044         }
12045         memset(&info, 0, sizeof(info));
12046         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12047         if (!strcmp(res->hash_func, "toeplitz"))
12048                 info.info.global_conf.hash_func =
12049                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12050         else if (!strcmp(res->hash_func, "simple_xor"))
12051                 info.info.global_conf.hash_func =
12052                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12053         else if (!strcmp(res->hash_func, "default"))
12054                 info.info.global_conf.hash_func =
12055                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12056
12057         ftype = str2flowtype(res->flow_type);
12058         idx = ftype / UINT64_BIT;
12059         offset = ftype % UINT64_BIT;
12060         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12061         if (!strcmp(res->enable, "enable"))
12062                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12063                                                 (1ULL << offset);
12064         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12065                                         RTE_ETH_FILTER_SET, &info);
12066         if (ret < 0)
12067                 printf("Cannot set global hash configurations by port %d\n",
12068                                                         res->port_id);
12069         else
12070                 printf("Global hash configurations have been set "
12071                         "succcessfully by port %d\n", res->port_id);
12072 }
12073
12074 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12075         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12076                 set_hash_global_config, "set_hash_global_config");
12077 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12078         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12079                 port_id, UINT16);
12080 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12081         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12082                 hash_func, "toeplitz#simple_xor#default");
12083 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12084         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12085                 flow_type,
12086                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12087                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12088 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12089         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12090                 enable, "enable#disable");
12091
12092 cmdline_parse_inst_t cmd_set_hash_global_config = {
12093         .f = cmd_set_hash_global_config_parsed,
12094         .data = NULL,
12095         .help_str = "set_hash_global_config <port_id> "
12096                 "toeplitz|simple_xor|default "
12097                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12098                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12099                 "l2_payload enable|disable",
12100         .tokens = {
12101                 (void *)&cmd_set_hash_global_config_all,
12102                 (void *)&cmd_set_hash_global_config_port_id,
12103                 (void *)&cmd_set_hash_global_config_hash_func,
12104                 (void *)&cmd_set_hash_global_config_flow_type,
12105                 (void *)&cmd_set_hash_global_config_enable,
12106                 NULL,
12107         },
12108 };
12109
12110 /* Set hash input set */
12111 struct cmd_set_hash_input_set_result {
12112         cmdline_fixed_string_t set_hash_input_set;
12113         portid_t port_id;
12114         cmdline_fixed_string_t flow_type;
12115         cmdline_fixed_string_t inset_field;
12116         cmdline_fixed_string_t select;
12117 };
12118
12119 static enum rte_eth_input_set_field
12120 str2inset(char *string)
12121 {
12122         uint16_t i;
12123
12124         static const struct {
12125                 char str[32];
12126                 enum rte_eth_input_set_field inset;
12127         } inset_table[] = {
12128                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12129                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12130                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12131                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12132                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12133                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12134                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12135                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12136                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12137                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12138                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12139                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12140                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12141                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12142                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12143                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12144                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12145                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12146                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12147                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12148                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12149                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12150                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12151                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12152                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12153                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12154                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12155                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12156                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12157                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12158                 {"none", RTE_ETH_INPUT_SET_NONE},
12159         };
12160
12161         for (i = 0; i < RTE_DIM(inset_table); i++) {
12162                 if (!strcmp(string, inset_table[i].str))
12163                         return inset_table[i].inset;
12164         }
12165
12166         return RTE_ETH_INPUT_SET_UNKNOWN;
12167 }
12168
12169 static void
12170 cmd_set_hash_input_set_parsed(void *parsed_result,
12171                               __rte_unused struct cmdline *cl,
12172                               __rte_unused void *data)
12173 {
12174         struct cmd_set_hash_input_set_result *res = parsed_result;
12175         struct rte_eth_hash_filter_info info;
12176
12177         memset(&info, 0, sizeof(info));
12178         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12179         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12180         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12181         info.info.input_set_conf.inset_size = 1;
12182         if (!strcmp(res->select, "select"))
12183                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12184         else if (!strcmp(res->select, "add"))
12185                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12186         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12187                                 RTE_ETH_FILTER_SET, &info);
12188 }
12189
12190 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12191         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12192                 set_hash_input_set, "set_hash_input_set");
12193 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12194         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12195                 port_id, UINT16);
12196 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12197         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12198                 flow_type, NULL);
12199 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12200         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12201                 inset_field,
12202                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12203                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12204                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12205                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12206                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12207                 "fld-8th#none");
12208 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12209         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12210                 select, "select#add");
12211
12212 cmdline_parse_inst_t cmd_set_hash_input_set = {
12213         .f = cmd_set_hash_input_set_parsed,
12214         .data = NULL,
12215         .help_str = "set_hash_input_set <port_id> "
12216         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12217         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12218         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12219         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12220         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12221         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12222         "fld-7th|fld-8th|none select|add",
12223         .tokens = {
12224                 (void *)&cmd_set_hash_input_set_cmd,
12225                 (void *)&cmd_set_hash_input_set_port_id,
12226                 (void *)&cmd_set_hash_input_set_flow_type,
12227                 (void *)&cmd_set_hash_input_set_field,
12228                 (void *)&cmd_set_hash_input_set_select,
12229                 NULL,
12230         },
12231 };
12232
12233 /* Set flow director input set */
12234 struct cmd_set_fdir_input_set_result {
12235         cmdline_fixed_string_t set_fdir_input_set;
12236         portid_t port_id;
12237         cmdline_fixed_string_t flow_type;
12238         cmdline_fixed_string_t inset_field;
12239         cmdline_fixed_string_t select;
12240 };
12241
12242 static void
12243 cmd_set_fdir_input_set_parsed(void *parsed_result,
12244         __rte_unused struct cmdline *cl,
12245         __rte_unused void *data)
12246 {
12247         struct cmd_set_fdir_input_set_result *res = parsed_result;
12248         struct rte_eth_fdir_filter_info info;
12249
12250         memset(&info, 0, sizeof(info));
12251         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12252         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12253         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12254         info.info.input_set_conf.inset_size = 1;
12255         if (!strcmp(res->select, "select"))
12256                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12257         else if (!strcmp(res->select, "add"))
12258                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12259         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12260                 RTE_ETH_FILTER_SET, &info);
12261 }
12262
12263 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12264         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12265         set_fdir_input_set, "set_fdir_input_set");
12266 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12267         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12268         port_id, UINT16);
12269 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12270         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12271         flow_type,
12272         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12273         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12274 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12275         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12276         inset_field,
12277         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12278         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12279         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12280         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12281         "sctp-veri-tag#none");
12282 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12283         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12284         select, "select#add");
12285
12286 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12287         .f = cmd_set_fdir_input_set_parsed,
12288         .data = NULL,
12289         .help_str = "set_fdir_input_set <port_id> "
12290         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12291         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12292         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12293         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12294         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12295         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12296         "sctp-veri-tag|none select|add",
12297         .tokens = {
12298                 (void *)&cmd_set_fdir_input_set_cmd,
12299                 (void *)&cmd_set_fdir_input_set_port_id,
12300                 (void *)&cmd_set_fdir_input_set_flow_type,
12301                 (void *)&cmd_set_fdir_input_set_field,
12302                 (void *)&cmd_set_fdir_input_set_select,
12303                 NULL,
12304         },
12305 };
12306
12307 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12308 struct cmd_mcast_addr_result {
12309         cmdline_fixed_string_t mcast_addr_cmd;
12310         cmdline_fixed_string_t what;
12311         uint16_t port_num;
12312         struct ether_addr mc_addr;
12313 };
12314
12315 static void cmd_mcast_addr_parsed(void *parsed_result,
12316                 __attribute__((unused)) struct cmdline *cl,
12317                 __attribute__((unused)) void *data)
12318 {
12319         struct cmd_mcast_addr_result *res = parsed_result;
12320
12321         if (!is_multicast_ether_addr(&res->mc_addr)) {
12322                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12323                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12324                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12325                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12326                 return;
12327         }
12328         if (strcmp(res->what, "add") == 0)
12329                 mcast_addr_add(res->port_num, &res->mc_addr);
12330         else
12331                 mcast_addr_remove(res->port_num, &res->mc_addr);
12332 }
12333
12334 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12335         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12336                                  mcast_addr_cmd, "mcast_addr");
12337 cmdline_parse_token_string_t cmd_mcast_addr_what =
12338         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12339                                  "add#remove");
12340 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12341         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12342 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12343         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12344
12345 cmdline_parse_inst_t cmd_mcast_addr = {
12346         .f = cmd_mcast_addr_parsed,
12347         .data = (void *)0,
12348         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12349                 "Add/Remove multicast MAC address on port_id",
12350         .tokens = {
12351                 (void *)&cmd_mcast_addr_cmd,
12352                 (void *)&cmd_mcast_addr_what,
12353                 (void *)&cmd_mcast_addr_portnum,
12354                 (void *)&cmd_mcast_addr_addr,
12355                 NULL,
12356         },
12357 };
12358
12359 /* l2 tunnel config
12360  * only support E-tag now.
12361  */
12362
12363 /* Ether type config */
12364 struct cmd_config_l2_tunnel_eth_type_result {
12365         cmdline_fixed_string_t port;
12366         cmdline_fixed_string_t config;
12367         cmdline_fixed_string_t all;
12368         portid_t id;
12369         cmdline_fixed_string_t l2_tunnel;
12370         cmdline_fixed_string_t l2_tunnel_type;
12371         cmdline_fixed_string_t eth_type;
12372         uint16_t eth_type_val;
12373 };
12374
12375 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12376         TOKEN_STRING_INITIALIZER
12377                 (struct cmd_config_l2_tunnel_eth_type_result,
12378                  port, "port");
12379 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12380         TOKEN_STRING_INITIALIZER
12381                 (struct cmd_config_l2_tunnel_eth_type_result,
12382                  config, "config");
12383 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12384         TOKEN_STRING_INITIALIZER
12385                 (struct cmd_config_l2_tunnel_eth_type_result,
12386                  all, "all");
12387 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12388         TOKEN_NUM_INITIALIZER
12389                 (struct cmd_config_l2_tunnel_eth_type_result,
12390                  id, UINT16);
12391 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12392         TOKEN_STRING_INITIALIZER
12393                 (struct cmd_config_l2_tunnel_eth_type_result,
12394                  l2_tunnel, "l2-tunnel");
12395 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12396         TOKEN_STRING_INITIALIZER
12397                 (struct cmd_config_l2_tunnel_eth_type_result,
12398                  l2_tunnel_type, "E-tag");
12399 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12400         TOKEN_STRING_INITIALIZER
12401                 (struct cmd_config_l2_tunnel_eth_type_result,
12402                  eth_type, "ether-type");
12403 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12404         TOKEN_NUM_INITIALIZER
12405                 (struct cmd_config_l2_tunnel_eth_type_result,
12406                  eth_type_val, UINT16);
12407
12408 static enum rte_eth_tunnel_type
12409 str2fdir_l2_tunnel_type(char *string)
12410 {
12411         uint32_t i = 0;
12412
12413         static const struct {
12414                 char str[32];
12415                 enum rte_eth_tunnel_type type;
12416         } l2_tunnel_type_str[] = {
12417                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12418         };
12419
12420         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12421                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12422                         return l2_tunnel_type_str[i].type;
12423         }
12424         return RTE_TUNNEL_TYPE_NONE;
12425 }
12426
12427 /* ether type config for all ports */
12428 static void
12429 cmd_config_l2_tunnel_eth_type_all_parsed
12430         (void *parsed_result,
12431          __attribute__((unused)) struct cmdline *cl,
12432          __attribute__((unused)) void *data)
12433 {
12434         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12435         struct rte_eth_l2_tunnel_conf entry;
12436         portid_t pid;
12437
12438         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12439         entry.ether_type = res->eth_type_val;
12440
12441         RTE_ETH_FOREACH_DEV(pid) {
12442                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12443         }
12444 }
12445
12446 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12447         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12448         .data = NULL,
12449         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12450         .tokens = {
12451                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12452                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12453                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12454                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12455                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12456                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12457                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12458                 NULL,
12459         },
12460 };
12461
12462 /* ether type config for a specific port */
12463 static void
12464 cmd_config_l2_tunnel_eth_type_specific_parsed(
12465         void *parsed_result,
12466         __attribute__((unused)) struct cmdline *cl,
12467         __attribute__((unused)) void *data)
12468 {
12469         struct cmd_config_l2_tunnel_eth_type_result *res =
12470                  parsed_result;
12471         struct rte_eth_l2_tunnel_conf entry;
12472
12473         if (port_id_is_invalid(res->id, ENABLED_WARN))
12474                 return;
12475
12476         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12477         entry.ether_type = res->eth_type_val;
12478
12479         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12480 }
12481
12482 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12483         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12484         .data = NULL,
12485         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12486         .tokens = {
12487                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12488                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12489                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12490                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12491                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12492                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12493                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12494                 NULL,
12495         },
12496 };
12497
12498 /* Enable/disable l2 tunnel */
12499 struct cmd_config_l2_tunnel_en_dis_result {
12500         cmdline_fixed_string_t port;
12501         cmdline_fixed_string_t config;
12502         cmdline_fixed_string_t all;
12503         portid_t id;
12504         cmdline_fixed_string_t l2_tunnel;
12505         cmdline_fixed_string_t l2_tunnel_type;
12506         cmdline_fixed_string_t en_dis;
12507 };
12508
12509 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12510         TOKEN_STRING_INITIALIZER
12511                 (struct cmd_config_l2_tunnel_en_dis_result,
12512                  port, "port");
12513 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12514         TOKEN_STRING_INITIALIZER
12515                 (struct cmd_config_l2_tunnel_en_dis_result,
12516                  config, "config");
12517 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12518         TOKEN_STRING_INITIALIZER
12519                 (struct cmd_config_l2_tunnel_en_dis_result,
12520                  all, "all");
12521 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12522         TOKEN_NUM_INITIALIZER
12523                 (struct cmd_config_l2_tunnel_en_dis_result,
12524                  id, UINT16);
12525 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12526         TOKEN_STRING_INITIALIZER
12527                 (struct cmd_config_l2_tunnel_en_dis_result,
12528                  l2_tunnel, "l2-tunnel");
12529 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_config_l2_tunnel_en_dis_result,
12532                  l2_tunnel_type, "E-tag");
12533 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12534         TOKEN_STRING_INITIALIZER
12535                 (struct cmd_config_l2_tunnel_en_dis_result,
12536                  en_dis, "enable#disable");
12537
12538 /* enable/disable l2 tunnel for all ports */
12539 static void
12540 cmd_config_l2_tunnel_en_dis_all_parsed(
12541         void *parsed_result,
12542         __attribute__((unused)) struct cmdline *cl,
12543         __attribute__((unused)) void *data)
12544 {
12545         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12546         struct rte_eth_l2_tunnel_conf entry;
12547         portid_t pid;
12548         uint8_t en;
12549
12550         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12551
12552         if (!strcmp("enable", res->en_dis))
12553                 en = 1;
12554         else
12555                 en = 0;
12556
12557         RTE_ETH_FOREACH_DEV(pid) {
12558                 rte_eth_dev_l2_tunnel_offload_set(pid,
12559                                                   &entry,
12560                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12561                                                   en);
12562         }
12563 }
12564
12565 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12566         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12567         .data = NULL,
12568         .help_str = "port config all l2-tunnel E-tag enable|disable",
12569         .tokens = {
12570                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12571                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12572                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12573                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12574                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12575                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12576                 NULL,
12577         },
12578 };
12579
12580 /* enable/disable l2 tunnel for a port */
12581 static void
12582 cmd_config_l2_tunnel_en_dis_specific_parsed(
12583         void *parsed_result,
12584         __attribute__((unused)) struct cmdline *cl,
12585         __attribute__((unused)) void *data)
12586 {
12587         struct cmd_config_l2_tunnel_en_dis_result *res =
12588                 parsed_result;
12589         struct rte_eth_l2_tunnel_conf entry;
12590
12591         if (port_id_is_invalid(res->id, ENABLED_WARN))
12592                 return;
12593
12594         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12595
12596         if (!strcmp("enable", res->en_dis))
12597                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12598                                                   &entry,
12599                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12600                                                   1);
12601         else
12602                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12603                                                   &entry,
12604                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12605                                                   0);
12606 }
12607
12608 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12609         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12610         .data = NULL,
12611         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12612         .tokens = {
12613                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12614                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12615                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12616                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12617                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12618                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12619                 NULL,
12620         },
12621 };
12622
12623 /* E-tag configuration */
12624
12625 /* Common result structure for all E-tag configuration */
12626 struct cmd_config_e_tag_result {
12627         cmdline_fixed_string_t e_tag;
12628         cmdline_fixed_string_t set;
12629         cmdline_fixed_string_t insertion;
12630         cmdline_fixed_string_t stripping;
12631         cmdline_fixed_string_t forwarding;
12632         cmdline_fixed_string_t filter;
12633         cmdline_fixed_string_t add;
12634         cmdline_fixed_string_t del;
12635         cmdline_fixed_string_t on;
12636         cmdline_fixed_string_t off;
12637         cmdline_fixed_string_t on_off;
12638         cmdline_fixed_string_t port_tag_id;
12639         uint32_t port_tag_id_val;
12640         cmdline_fixed_string_t e_tag_id;
12641         uint16_t e_tag_id_val;
12642         cmdline_fixed_string_t dst_pool;
12643         uint8_t dst_pool_val;
12644         cmdline_fixed_string_t port;
12645         portid_t port_id;
12646         cmdline_fixed_string_t vf;
12647         uint8_t vf_id;
12648 };
12649
12650 /* Common CLI fields for all E-tag configuration */
12651 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12652         TOKEN_STRING_INITIALIZER
12653                 (struct cmd_config_e_tag_result,
12654                  e_tag, "E-tag");
12655 cmdline_parse_token_string_t cmd_config_e_tag_set =
12656         TOKEN_STRING_INITIALIZER
12657                 (struct cmd_config_e_tag_result,
12658                  set, "set");
12659 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12660         TOKEN_STRING_INITIALIZER
12661                 (struct cmd_config_e_tag_result,
12662                  insertion, "insertion");
12663 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12664         TOKEN_STRING_INITIALIZER
12665                 (struct cmd_config_e_tag_result,
12666                  stripping, "stripping");
12667 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12668         TOKEN_STRING_INITIALIZER
12669                 (struct cmd_config_e_tag_result,
12670                  forwarding, "forwarding");
12671 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_config_e_tag_result,
12674                  filter, "filter");
12675 cmdline_parse_token_string_t cmd_config_e_tag_add =
12676         TOKEN_STRING_INITIALIZER
12677                 (struct cmd_config_e_tag_result,
12678                  add, "add");
12679 cmdline_parse_token_string_t cmd_config_e_tag_del =
12680         TOKEN_STRING_INITIALIZER
12681                 (struct cmd_config_e_tag_result,
12682                  del, "del");
12683 cmdline_parse_token_string_t cmd_config_e_tag_on =
12684         TOKEN_STRING_INITIALIZER
12685                 (struct cmd_config_e_tag_result,
12686                  on, "on");
12687 cmdline_parse_token_string_t cmd_config_e_tag_off =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_config_e_tag_result,
12690                  off, "off");
12691 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12692         TOKEN_STRING_INITIALIZER
12693                 (struct cmd_config_e_tag_result,
12694                  on_off, "on#off");
12695 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12696         TOKEN_STRING_INITIALIZER
12697                 (struct cmd_config_e_tag_result,
12698                  port_tag_id, "port-tag-id");
12699 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12700         TOKEN_NUM_INITIALIZER
12701                 (struct cmd_config_e_tag_result,
12702                  port_tag_id_val, UINT32);
12703 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12704         TOKEN_STRING_INITIALIZER
12705                 (struct cmd_config_e_tag_result,
12706                  e_tag_id, "e-tag-id");
12707 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12708         TOKEN_NUM_INITIALIZER
12709                 (struct cmd_config_e_tag_result,
12710                  e_tag_id_val, UINT16);
12711 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12712         TOKEN_STRING_INITIALIZER
12713                 (struct cmd_config_e_tag_result,
12714                  dst_pool, "dst-pool");
12715 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12716         TOKEN_NUM_INITIALIZER
12717                 (struct cmd_config_e_tag_result,
12718                  dst_pool_val, UINT8);
12719 cmdline_parse_token_string_t cmd_config_e_tag_port =
12720         TOKEN_STRING_INITIALIZER
12721                 (struct cmd_config_e_tag_result,
12722                  port, "port");
12723 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12724         TOKEN_NUM_INITIALIZER
12725                 (struct cmd_config_e_tag_result,
12726                  port_id, UINT16);
12727 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12728         TOKEN_STRING_INITIALIZER
12729                 (struct cmd_config_e_tag_result,
12730                  vf, "vf");
12731 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12732         TOKEN_NUM_INITIALIZER
12733                 (struct cmd_config_e_tag_result,
12734                  vf_id, UINT8);
12735
12736 /* E-tag insertion configuration */
12737 static void
12738 cmd_config_e_tag_insertion_en_parsed(
12739         void *parsed_result,
12740         __attribute__((unused)) struct cmdline *cl,
12741         __attribute__((unused)) void *data)
12742 {
12743         struct cmd_config_e_tag_result *res =
12744                 parsed_result;
12745         struct rte_eth_l2_tunnel_conf entry;
12746
12747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12748                 return;
12749
12750         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12751         entry.tunnel_id = res->port_tag_id_val;
12752         entry.vf_id = res->vf_id;
12753         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12754                                           &entry,
12755                                           ETH_L2_TUNNEL_INSERTION_MASK,
12756                                           1);
12757 }
12758
12759 static void
12760 cmd_config_e_tag_insertion_dis_parsed(
12761         void *parsed_result,
12762         __attribute__((unused)) struct cmdline *cl,
12763         __attribute__((unused)) void *data)
12764 {
12765         struct cmd_config_e_tag_result *res =
12766                 parsed_result;
12767         struct rte_eth_l2_tunnel_conf entry;
12768
12769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12770                 return;
12771
12772         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12773         entry.vf_id = res->vf_id;
12774
12775         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12776                                           &entry,
12777                                           ETH_L2_TUNNEL_INSERTION_MASK,
12778                                           0);
12779 }
12780
12781 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12782         .f = cmd_config_e_tag_insertion_en_parsed,
12783         .data = NULL,
12784         .help_str = "E-tag ... : E-tag insertion enable",
12785         .tokens = {
12786                 (void *)&cmd_config_e_tag_e_tag,
12787                 (void *)&cmd_config_e_tag_set,
12788                 (void *)&cmd_config_e_tag_insertion,
12789                 (void *)&cmd_config_e_tag_on,
12790                 (void *)&cmd_config_e_tag_port_tag_id,
12791                 (void *)&cmd_config_e_tag_port_tag_id_val,
12792                 (void *)&cmd_config_e_tag_port,
12793                 (void *)&cmd_config_e_tag_port_id,
12794                 (void *)&cmd_config_e_tag_vf,
12795                 (void *)&cmd_config_e_tag_vf_id,
12796                 NULL,
12797         },
12798 };
12799
12800 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12801         .f = cmd_config_e_tag_insertion_dis_parsed,
12802         .data = NULL,
12803         .help_str = "E-tag ... : E-tag insertion disable",
12804         .tokens = {
12805                 (void *)&cmd_config_e_tag_e_tag,
12806                 (void *)&cmd_config_e_tag_set,
12807                 (void *)&cmd_config_e_tag_insertion,
12808                 (void *)&cmd_config_e_tag_off,
12809                 (void *)&cmd_config_e_tag_port,
12810                 (void *)&cmd_config_e_tag_port_id,
12811                 (void *)&cmd_config_e_tag_vf,
12812                 (void *)&cmd_config_e_tag_vf_id,
12813                 NULL,
12814         },
12815 };
12816
12817 /* E-tag stripping configuration */
12818 static void
12819 cmd_config_e_tag_stripping_parsed(
12820         void *parsed_result,
12821         __attribute__((unused)) struct cmdline *cl,
12822         __attribute__((unused)) void *data)
12823 {
12824         struct cmd_config_e_tag_result *res =
12825                 parsed_result;
12826         struct rte_eth_l2_tunnel_conf entry;
12827
12828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12829                 return;
12830
12831         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12832
12833         if (!strcmp(res->on_off, "on"))
12834                 rte_eth_dev_l2_tunnel_offload_set
12835                         (res->port_id,
12836                          &entry,
12837                          ETH_L2_TUNNEL_STRIPPING_MASK,
12838                          1);
12839         else
12840                 rte_eth_dev_l2_tunnel_offload_set
12841                         (res->port_id,
12842                          &entry,
12843                          ETH_L2_TUNNEL_STRIPPING_MASK,
12844                          0);
12845 }
12846
12847 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12848         .f = cmd_config_e_tag_stripping_parsed,
12849         .data = NULL,
12850         .help_str = "E-tag ... : E-tag stripping enable/disable",
12851         .tokens = {
12852                 (void *)&cmd_config_e_tag_e_tag,
12853                 (void *)&cmd_config_e_tag_set,
12854                 (void *)&cmd_config_e_tag_stripping,
12855                 (void *)&cmd_config_e_tag_on_off,
12856                 (void *)&cmd_config_e_tag_port,
12857                 (void *)&cmd_config_e_tag_port_id,
12858                 NULL,
12859         },
12860 };
12861
12862 /* E-tag forwarding configuration */
12863 static void
12864 cmd_config_e_tag_forwarding_parsed(
12865         void *parsed_result,
12866         __attribute__((unused)) struct cmdline *cl,
12867         __attribute__((unused)) void *data)
12868 {
12869         struct cmd_config_e_tag_result *res = parsed_result;
12870         struct rte_eth_l2_tunnel_conf entry;
12871
12872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12873                 return;
12874
12875         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12876
12877         if (!strcmp(res->on_off, "on"))
12878                 rte_eth_dev_l2_tunnel_offload_set
12879                         (res->port_id,
12880                          &entry,
12881                          ETH_L2_TUNNEL_FORWARDING_MASK,
12882                          1);
12883         else
12884                 rte_eth_dev_l2_tunnel_offload_set
12885                         (res->port_id,
12886                          &entry,
12887                          ETH_L2_TUNNEL_FORWARDING_MASK,
12888                          0);
12889 }
12890
12891 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12892         .f = cmd_config_e_tag_forwarding_parsed,
12893         .data = NULL,
12894         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12895         .tokens = {
12896                 (void *)&cmd_config_e_tag_e_tag,
12897                 (void *)&cmd_config_e_tag_set,
12898                 (void *)&cmd_config_e_tag_forwarding,
12899                 (void *)&cmd_config_e_tag_on_off,
12900                 (void *)&cmd_config_e_tag_port,
12901                 (void *)&cmd_config_e_tag_port_id,
12902                 NULL,
12903         },
12904 };
12905
12906 /* E-tag filter configuration */
12907 static void
12908 cmd_config_e_tag_filter_add_parsed(
12909         void *parsed_result,
12910         __attribute__((unused)) struct cmdline *cl,
12911         __attribute__((unused)) void *data)
12912 {
12913         struct cmd_config_e_tag_result *res = parsed_result;
12914         struct rte_eth_l2_tunnel_conf entry;
12915         int ret = 0;
12916
12917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12918                 return;
12919
12920         if (res->e_tag_id_val > 0x3fff) {
12921                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12922                 return;
12923         }
12924
12925         ret = rte_eth_dev_filter_supported(res->port_id,
12926                                            RTE_ETH_FILTER_L2_TUNNEL);
12927         if (ret < 0) {
12928                 printf("E-tag filter is not supported on port %u.\n",
12929                        res->port_id);
12930                 return;
12931         }
12932
12933         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12934         entry.tunnel_id = res->e_tag_id_val;
12935         entry.pool = res->dst_pool_val;
12936
12937         ret = rte_eth_dev_filter_ctrl(res->port_id,
12938                                       RTE_ETH_FILTER_L2_TUNNEL,
12939                                       RTE_ETH_FILTER_ADD,
12940                                       &entry);
12941         if (ret < 0)
12942                 printf("E-tag filter programming error: (%s)\n",
12943                        strerror(-ret));
12944 }
12945
12946 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12947         .f = cmd_config_e_tag_filter_add_parsed,
12948         .data = NULL,
12949         .help_str = "E-tag ... : E-tag filter add",
12950         .tokens = {
12951                 (void *)&cmd_config_e_tag_e_tag,
12952                 (void *)&cmd_config_e_tag_set,
12953                 (void *)&cmd_config_e_tag_filter,
12954                 (void *)&cmd_config_e_tag_add,
12955                 (void *)&cmd_config_e_tag_e_tag_id,
12956                 (void *)&cmd_config_e_tag_e_tag_id_val,
12957                 (void *)&cmd_config_e_tag_dst_pool,
12958                 (void *)&cmd_config_e_tag_dst_pool_val,
12959                 (void *)&cmd_config_e_tag_port,
12960                 (void *)&cmd_config_e_tag_port_id,
12961                 NULL,
12962         },
12963 };
12964
12965 static void
12966 cmd_config_e_tag_filter_del_parsed(
12967         void *parsed_result,
12968         __attribute__((unused)) struct cmdline *cl,
12969         __attribute__((unused)) void *data)
12970 {
12971         struct cmd_config_e_tag_result *res = parsed_result;
12972         struct rte_eth_l2_tunnel_conf entry;
12973         int ret = 0;
12974
12975         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12976                 return;
12977
12978         if (res->e_tag_id_val > 0x3fff) {
12979                 printf("e-tag-id must be less than 0x3fff.\n");
12980                 return;
12981         }
12982
12983         ret = rte_eth_dev_filter_supported(res->port_id,
12984                                            RTE_ETH_FILTER_L2_TUNNEL);
12985         if (ret < 0) {
12986                 printf("E-tag filter is not supported on port %u.\n",
12987                        res->port_id);
12988                 return;
12989         }
12990
12991         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12992         entry.tunnel_id = res->e_tag_id_val;
12993
12994         ret = rte_eth_dev_filter_ctrl(res->port_id,
12995                                       RTE_ETH_FILTER_L2_TUNNEL,
12996                                       RTE_ETH_FILTER_DELETE,
12997                                       &entry);
12998         if (ret < 0)
12999                 printf("E-tag filter programming error: (%s)\n",
13000                        strerror(-ret));
13001 }
13002
13003 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13004         .f = cmd_config_e_tag_filter_del_parsed,
13005         .data = NULL,
13006         .help_str = "E-tag ... : E-tag filter delete",
13007         .tokens = {
13008                 (void *)&cmd_config_e_tag_e_tag,
13009                 (void *)&cmd_config_e_tag_set,
13010                 (void *)&cmd_config_e_tag_filter,
13011                 (void *)&cmd_config_e_tag_del,
13012                 (void *)&cmd_config_e_tag_e_tag_id,
13013                 (void *)&cmd_config_e_tag_e_tag_id_val,
13014                 (void *)&cmd_config_e_tag_port,
13015                 (void *)&cmd_config_e_tag_port_id,
13016                 NULL,
13017         },
13018 };
13019
13020 /* vf vlan anti spoof configuration */
13021
13022 /* Common result structure for vf vlan anti spoof */
13023 struct cmd_vf_vlan_anti_spoof_result {
13024         cmdline_fixed_string_t set;
13025         cmdline_fixed_string_t vf;
13026         cmdline_fixed_string_t vlan;
13027         cmdline_fixed_string_t antispoof;
13028         portid_t port_id;
13029         uint32_t vf_id;
13030         cmdline_fixed_string_t on_off;
13031 };
13032
13033 /* Common CLI fields for vf vlan anti spoof enable disable */
13034 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13035         TOKEN_STRING_INITIALIZER
13036                 (struct cmd_vf_vlan_anti_spoof_result,
13037                  set, "set");
13038 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_vf_vlan_anti_spoof_result,
13041                  vf, "vf");
13042 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13043         TOKEN_STRING_INITIALIZER
13044                 (struct cmd_vf_vlan_anti_spoof_result,
13045                  vlan, "vlan");
13046 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_vf_vlan_anti_spoof_result,
13049                  antispoof, "antispoof");
13050 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13051         TOKEN_NUM_INITIALIZER
13052                 (struct cmd_vf_vlan_anti_spoof_result,
13053                  port_id, UINT16);
13054 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13055         TOKEN_NUM_INITIALIZER
13056                 (struct cmd_vf_vlan_anti_spoof_result,
13057                  vf_id, UINT32);
13058 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_vf_vlan_anti_spoof_result,
13061                  on_off, "on#off");
13062
13063 static void
13064 cmd_set_vf_vlan_anti_spoof_parsed(
13065         void *parsed_result,
13066         __attribute__((unused)) struct cmdline *cl,
13067         __attribute__((unused)) void *data)
13068 {
13069         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13070         int ret = -ENOTSUP;
13071
13072         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13073
13074         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13075                 return;
13076
13077 #ifdef RTE_LIBRTE_IXGBE_PMD
13078         if (ret == -ENOTSUP)
13079                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13080                                 res->vf_id, is_on);
13081 #endif
13082 #ifdef RTE_LIBRTE_I40E_PMD
13083         if (ret == -ENOTSUP)
13084                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13085                                 res->vf_id, is_on);
13086 #endif
13087 #ifdef RTE_LIBRTE_BNXT_PMD
13088         if (ret == -ENOTSUP)
13089                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13090                                 res->vf_id, is_on);
13091 #endif
13092
13093         switch (ret) {
13094         case 0:
13095                 break;
13096         case -EINVAL:
13097                 printf("invalid vf_id %d\n", res->vf_id);
13098                 break;
13099         case -ENODEV:
13100                 printf("invalid port_id %d\n", res->port_id);
13101                 break;
13102         case -ENOTSUP:
13103                 printf("function not implemented\n");
13104                 break;
13105         default:
13106                 printf("programming error: (%s)\n", strerror(-ret));
13107         }
13108 }
13109
13110 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13111         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13112         .data = NULL,
13113         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13114         .tokens = {
13115                 (void *)&cmd_vf_vlan_anti_spoof_set,
13116                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13117                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13118                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13119                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13120                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13121                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13122                 NULL,
13123         },
13124 };
13125
13126 /* vf mac anti spoof configuration */
13127
13128 /* Common result structure for vf mac anti spoof */
13129 struct cmd_vf_mac_anti_spoof_result {
13130         cmdline_fixed_string_t set;
13131         cmdline_fixed_string_t vf;
13132         cmdline_fixed_string_t mac;
13133         cmdline_fixed_string_t antispoof;
13134         portid_t port_id;
13135         uint32_t vf_id;
13136         cmdline_fixed_string_t on_off;
13137 };
13138
13139 /* Common CLI fields for vf mac anti spoof enable disable */
13140 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_vf_mac_anti_spoof_result,
13143                  set, "set");
13144 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13145         TOKEN_STRING_INITIALIZER
13146                 (struct cmd_vf_mac_anti_spoof_result,
13147                  vf, "vf");
13148 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_vf_mac_anti_spoof_result,
13151                  mac, "mac");
13152 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13153         TOKEN_STRING_INITIALIZER
13154                 (struct cmd_vf_mac_anti_spoof_result,
13155                  antispoof, "antispoof");
13156 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13157         TOKEN_NUM_INITIALIZER
13158                 (struct cmd_vf_mac_anti_spoof_result,
13159                  port_id, UINT16);
13160 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13161         TOKEN_NUM_INITIALIZER
13162                 (struct cmd_vf_mac_anti_spoof_result,
13163                  vf_id, UINT32);
13164 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13165         TOKEN_STRING_INITIALIZER
13166                 (struct cmd_vf_mac_anti_spoof_result,
13167                  on_off, "on#off");
13168
13169 static void
13170 cmd_set_vf_mac_anti_spoof_parsed(
13171         void *parsed_result,
13172         __attribute__((unused)) struct cmdline *cl,
13173         __attribute__((unused)) void *data)
13174 {
13175         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13176         int ret = -ENOTSUP;
13177
13178         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13179
13180         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13181                 return;
13182
13183 #ifdef RTE_LIBRTE_IXGBE_PMD
13184         if (ret == -ENOTSUP)
13185                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13186                         res->vf_id, is_on);
13187 #endif
13188 #ifdef RTE_LIBRTE_I40E_PMD
13189         if (ret == -ENOTSUP)
13190                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13191                         res->vf_id, is_on);
13192 #endif
13193 #ifdef RTE_LIBRTE_BNXT_PMD
13194         if (ret == -ENOTSUP)
13195                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13196                         res->vf_id, is_on);
13197 #endif
13198
13199         switch (ret) {
13200         case 0:
13201                 break;
13202         case -EINVAL:
13203                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13204                 break;
13205         case -ENODEV:
13206                 printf("invalid port_id %d\n", res->port_id);
13207                 break;
13208         case -ENOTSUP:
13209                 printf("function not implemented\n");
13210                 break;
13211         default:
13212                 printf("programming error: (%s)\n", strerror(-ret));
13213         }
13214 }
13215
13216 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13217         .f = cmd_set_vf_mac_anti_spoof_parsed,
13218         .data = NULL,
13219         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13220         .tokens = {
13221                 (void *)&cmd_vf_mac_anti_spoof_set,
13222                 (void *)&cmd_vf_mac_anti_spoof_vf,
13223                 (void *)&cmd_vf_mac_anti_spoof_mac,
13224                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13225                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13226                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13227                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13228                 NULL,
13229         },
13230 };
13231
13232 /* vf vlan strip queue configuration */
13233
13234 /* Common result structure for vf mac anti spoof */
13235 struct cmd_vf_vlan_stripq_result {
13236         cmdline_fixed_string_t set;
13237         cmdline_fixed_string_t vf;
13238         cmdline_fixed_string_t vlan;
13239         cmdline_fixed_string_t stripq;
13240         portid_t port_id;
13241         uint16_t vf_id;
13242         cmdline_fixed_string_t on_off;
13243 };
13244
13245 /* Common CLI fields for vf vlan strip enable disable */
13246 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13247         TOKEN_STRING_INITIALIZER
13248                 (struct cmd_vf_vlan_stripq_result,
13249                  set, "set");
13250 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13251         TOKEN_STRING_INITIALIZER
13252                 (struct cmd_vf_vlan_stripq_result,
13253                  vf, "vf");
13254 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13255         TOKEN_STRING_INITIALIZER
13256                 (struct cmd_vf_vlan_stripq_result,
13257                  vlan, "vlan");
13258 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_vf_vlan_stripq_result,
13261                  stripq, "stripq");
13262 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13263         TOKEN_NUM_INITIALIZER
13264                 (struct cmd_vf_vlan_stripq_result,
13265                  port_id, UINT16);
13266 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13267         TOKEN_NUM_INITIALIZER
13268                 (struct cmd_vf_vlan_stripq_result,
13269                  vf_id, UINT16);
13270 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13271         TOKEN_STRING_INITIALIZER
13272                 (struct cmd_vf_vlan_stripq_result,
13273                  on_off, "on#off");
13274
13275 static void
13276 cmd_set_vf_vlan_stripq_parsed(
13277         void *parsed_result,
13278         __attribute__((unused)) struct cmdline *cl,
13279         __attribute__((unused)) void *data)
13280 {
13281         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13282         int ret = -ENOTSUP;
13283
13284         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13285
13286         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13287                 return;
13288
13289 #ifdef RTE_LIBRTE_IXGBE_PMD
13290         if (ret == -ENOTSUP)
13291                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13292                         res->vf_id, is_on);
13293 #endif
13294 #ifdef RTE_LIBRTE_I40E_PMD
13295         if (ret == -ENOTSUP)
13296                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13297                         res->vf_id, is_on);
13298 #endif
13299 #ifdef RTE_LIBRTE_BNXT_PMD
13300         if (ret == -ENOTSUP)
13301                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13302                         res->vf_id, is_on);
13303 #endif
13304
13305         switch (ret) {
13306         case 0:
13307                 break;
13308         case -EINVAL:
13309                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13310                 break;
13311         case -ENODEV:
13312                 printf("invalid port_id %d\n", res->port_id);
13313                 break;
13314         case -ENOTSUP:
13315                 printf("function not implemented\n");
13316                 break;
13317         default:
13318                 printf("programming error: (%s)\n", strerror(-ret));
13319         }
13320 }
13321
13322 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13323         .f = cmd_set_vf_vlan_stripq_parsed,
13324         .data = NULL,
13325         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13326         .tokens = {
13327                 (void *)&cmd_vf_vlan_stripq_set,
13328                 (void *)&cmd_vf_vlan_stripq_vf,
13329                 (void *)&cmd_vf_vlan_stripq_vlan,
13330                 (void *)&cmd_vf_vlan_stripq_stripq,
13331                 (void *)&cmd_vf_vlan_stripq_port_id,
13332                 (void *)&cmd_vf_vlan_stripq_vf_id,
13333                 (void *)&cmd_vf_vlan_stripq_on_off,
13334                 NULL,
13335         },
13336 };
13337
13338 /* vf vlan insert configuration */
13339
13340 /* Common result structure for vf vlan insert */
13341 struct cmd_vf_vlan_insert_result {
13342         cmdline_fixed_string_t set;
13343         cmdline_fixed_string_t vf;
13344         cmdline_fixed_string_t vlan;
13345         cmdline_fixed_string_t insert;
13346         portid_t port_id;
13347         uint16_t vf_id;
13348         uint16_t vlan_id;
13349 };
13350
13351 /* Common CLI fields for vf vlan insert enable disable */
13352 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13353         TOKEN_STRING_INITIALIZER
13354                 (struct cmd_vf_vlan_insert_result,
13355                  set, "set");
13356 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_vf_vlan_insert_result,
13359                  vf, "vf");
13360 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_vf_vlan_insert_result,
13363                  vlan, "vlan");
13364 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_vf_vlan_insert_result,
13367                  insert, "insert");
13368 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13369         TOKEN_NUM_INITIALIZER
13370                 (struct cmd_vf_vlan_insert_result,
13371                  port_id, UINT16);
13372 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13373         TOKEN_NUM_INITIALIZER
13374                 (struct cmd_vf_vlan_insert_result,
13375                  vf_id, UINT16);
13376 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13377         TOKEN_NUM_INITIALIZER
13378                 (struct cmd_vf_vlan_insert_result,
13379                  vlan_id, UINT16);
13380
13381 static void
13382 cmd_set_vf_vlan_insert_parsed(
13383         void *parsed_result,
13384         __attribute__((unused)) struct cmdline *cl,
13385         __attribute__((unused)) void *data)
13386 {
13387         struct cmd_vf_vlan_insert_result *res = parsed_result;
13388         int ret = -ENOTSUP;
13389
13390         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13391                 return;
13392
13393 #ifdef RTE_LIBRTE_IXGBE_PMD
13394         if (ret == -ENOTSUP)
13395                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13396                         res->vlan_id);
13397 #endif
13398 #ifdef RTE_LIBRTE_I40E_PMD
13399         if (ret == -ENOTSUP)
13400                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13401                         res->vlan_id);
13402 #endif
13403 #ifdef RTE_LIBRTE_BNXT_PMD
13404         if (ret == -ENOTSUP)
13405                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13406                         res->vlan_id);
13407 #endif
13408
13409         switch (ret) {
13410         case 0:
13411                 break;
13412         case -EINVAL:
13413                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13414                 break;
13415         case -ENODEV:
13416                 printf("invalid port_id %d\n", res->port_id);
13417                 break;
13418         case -ENOTSUP:
13419                 printf("function not implemented\n");
13420                 break;
13421         default:
13422                 printf("programming error: (%s)\n", strerror(-ret));
13423         }
13424 }
13425
13426 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13427         .f = cmd_set_vf_vlan_insert_parsed,
13428         .data = NULL,
13429         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13430         .tokens = {
13431                 (void *)&cmd_vf_vlan_insert_set,
13432                 (void *)&cmd_vf_vlan_insert_vf,
13433                 (void *)&cmd_vf_vlan_insert_vlan,
13434                 (void *)&cmd_vf_vlan_insert_insert,
13435                 (void *)&cmd_vf_vlan_insert_port_id,
13436                 (void *)&cmd_vf_vlan_insert_vf_id,
13437                 (void *)&cmd_vf_vlan_insert_vlan_id,
13438                 NULL,
13439         },
13440 };
13441
13442 /* tx loopback configuration */
13443
13444 /* Common result structure for tx loopback */
13445 struct cmd_tx_loopback_result {
13446         cmdline_fixed_string_t set;
13447         cmdline_fixed_string_t tx;
13448         cmdline_fixed_string_t loopback;
13449         portid_t port_id;
13450         cmdline_fixed_string_t on_off;
13451 };
13452
13453 /* Common CLI fields for tx loopback enable disable */
13454 cmdline_parse_token_string_t cmd_tx_loopback_set =
13455         TOKEN_STRING_INITIALIZER
13456                 (struct cmd_tx_loopback_result,
13457                  set, "set");
13458 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13459         TOKEN_STRING_INITIALIZER
13460                 (struct cmd_tx_loopback_result,
13461                  tx, "tx");
13462 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13463         TOKEN_STRING_INITIALIZER
13464                 (struct cmd_tx_loopback_result,
13465                  loopback, "loopback");
13466 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13467         TOKEN_NUM_INITIALIZER
13468                 (struct cmd_tx_loopback_result,
13469                  port_id, UINT16);
13470 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_tx_loopback_result,
13473                  on_off, "on#off");
13474
13475 static void
13476 cmd_set_tx_loopback_parsed(
13477         void *parsed_result,
13478         __attribute__((unused)) struct cmdline *cl,
13479         __attribute__((unused)) void *data)
13480 {
13481         struct cmd_tx_loopback_result *res = parsed_result;
13482         int ret = -ENOTSUP;
13483
13484         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13485
13486         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13487                 return;
13488
13489 #ifdef RTE_LIBRTE_IXGBE_PMD
13490         if (ret == -ENOTSUP)
13491                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13492 #endif
13493 #ifdef RTE_LIBRTE_I40E_PMD
13494         if (ret == -ENOTSUP)
13495                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13496 #endif
13497 #ifdef RTE_LIBRTE_BNXT_PMD
13498         if (ret == -ENOTSUP)
13499                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13500 #endif
13501 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13502         if (ret == -ENOTSUP)
13503                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13504 #endif
13505
13506         switch (ret) {
13507         case 0:
13508                 break;
13509         case -EINVAL:
13510                 printf("invalid is_on %d\n", is_on);
13511                 break;
13512         case -ENODEV:
13513                 printf("invalid port_id %d\n", res->port_id);
13514                 break;
13515         case -ENOTSUP:
13516                 printf("function not implemented\n");
13517                 break;
13518         default:
13519                 printf("programming error: (%s)\n", strerror(-ret));
13520         }
13521 }
13522
13523 cmdline_parse_inst_t cmd_set_tx_loopback = {
13524         .f = cmd_set_tx_loopback_parsed,
13525         .data = NULL,
13526         .help_str = "set tx loopback <port_id> on|off",
13527         .tokens = {
13528                 (void *)&cmd_tx_loopback_set,
13529                 (void *)&cmd_tx_loopback_tx,
13530                 (void *)&cmd_tx_loopback_loopback,
13531                 (void *)&cmd_tx_loopback_port_id,
13532                 (void *)&cmd_tx_loopback_on_off,
13533                 NULL,
13534         },
13535 };
13536
13537 /* all queues drop enable configuration */
13538
13539 /* Common result structure for all queues drop enable */
13540 struct cmd_all_queues_drop_en_result {
13541         cmdline_fixed_string_t set;
13542         cmdline_fixed_string_t all;
13543         cmdline_fixed_string_t queues;
13544         cmdline_fixed_string_t drop;
13545         portid_t port_id;
13546         cmdline_fixed_string_t on_off;
13547 };
13548
13549 /* Common CLI fields for tx loopback enable disable */
13550 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13551         TOKEN_STRING_INITIALIZER
13552                 (struct cmd_all_queues_drop_en_result,
13553                  set, "set");
13554 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13555         TOKEN_STRING_INITIALIZER
13556                 (struct cmd_all_queues_drop_en_result,
13557                  all, "all");
13558 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_all_queues_drop_en_result,
13561                  queues, "queues");
13562 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_all_queues_drop_en_result,
13565                  drop, "drop");
13566 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13567         TOKEN_NUM_INITIALIZER
13568                 (struct cmd_all_queues_drop_en_result,
13569                  port_id, UINT16);
13570 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_all_queues_drop_en_result,
13573                  on_off, "on#off");
13574
13575 static void
13576 cmd_set_all_queues_drop_en_parsed(
13577         void *parsed_result,
13578         __attribute__((unused)) struct cmdline *cl,
13579         __attribute__((unused)) void *data)
13580 {
13581         struct cmd_all_queues_drop_en_result *res = parsed_result;
13582         int ret = -ENOTSUP;
13583         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13584
13585         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13586                 return;
13587
13588 #ifdef RTE_LIBRTE_IXGBE_PMD
13589         if (ret == -ENOTSUP)
13590                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13591 #endif
13592 #ifdef RTE_LIBRTE_BNXT_PMD
13593         if (ret == -ENOTSUP)
13594                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13595 #endif
13596         switch (ret) {
13597         case 0:
13598                 break;
13599         case -EINVAL:
13600                 printf("invalid is_on %d\n", is_on);
13601                 break;
13602         case -ENODEV:
13603                 printf("invalid port_id %d\n", res->port_id);
13604                 break;
13605         case -ENOTSUP:
13606                 printf("function not implemented\n");
13607                 break;
13608         default:
13609                 printf("programming error: (%s)\n", strerror(-ret));
13610         }
13611 }
13612
13613 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13614         .f = cmd_set_all_queues_drop_en_parsed,
13615         .data = NULL,
13616         .help_str = "set all queues drop <port_id> on|off",
13617         .tokens = {
13618                 (void *)&cmd_all_queues_drop_en_set,
13619                 (void *)&cmd_all_queues_drop_en_all,
13620                 (void *)&cmd_all_queues_drop_en_queues,
13621                 (void *)&cmd_all_queues_drop_en_drop,
13622                 (void *)&cmd_all_queues_drop_en_port_id,
13623                 (void *)&cmd_all_queues_drop_en_on_off,
13624                 NULL,
13625         },
13626 };
13627
13628 /* vf split drop enable configuration */
13629
13630 /* Common result structure for vf split drop enable */
13631 struct cmd_vf_split_drop_en_result {
13632         cmdline_fixed_string_t set;
13633         cmdline_fixed_string_t vf;
13634         cmdline_fixed_string_t split;
13635         cmdline_fixed_string_t drop;
13636         portid_t port_id;
13637         uint16_t vf_id;
13638         cmdline_fixed_string_t on_off;
13639 };
13640
13641 /* Common CLI fields for vf split drop enable disable */
13642 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13643         TOKEN_STRING_INITIALIZER
13644                 (struct cmd_vf_split_drop_en_result,
13645                  set, "set");
13646 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13647         TOKEN_STRING_INITIALIZER
13648                 (struct cmd_vf_split_drop_en_result,
13649                  vf, "vf");
13650 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_vf_split_drop_en_result,
13653                  split, "split");
13654 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_vf_split_drop_en_result,
13657                  drop, "drop");
13658 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13659         TOKEN_NUM_INITIALIZER
13660                 (struct cmd_vf_split_drop_en_result,
13661                  port_id, UINT16);
13662 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13663         TOKEN_NUM_INITIALIZER
13664                 (struct cmd_vf_split_drop_en_result,
13665                  vf_id, UINT16);
13666 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13667         TOKEN_STRING_INITIALIZER
13668                 (struct cmd_vf_split_drop_en_result,
13669                  on_off, "on#off");
13670
13671 static void
13672 cmd_set_vf_split_drop_en_parsed(
13673         void *parsed_result,
13674         __attribute__((unused)) struct cmdline *cl,
13675         __attribute__((unused)) void *data)
13676 {
13677         struct cmd_vf_split_drop_en_result *res = parsed_result;
13678         int ret = -ENOTSUP;
13679         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13680
13681         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13682                 return;
13683
13684 #ifdef RTE_LIBRTE_IXGBE_PMD
13685         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13686                         is_on);
13687 #endif
13688         switch (ret) {
13689         case 0:
13690                 break;
13691         case -EINVAL:
13692                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13693                 break;
13694         case -ENODEV:
13695                 printf("invalid port_id %d\n", res->port_id);
13696                 break;
13697         case -ENOTSUP:
13698                 printf("not supported on port %d\n", res->port_id);
13699                 break;
13700         default:
13701                 printf("programming error: (%s)\n", strerror(-ret));
13702         }
13703 }
13704
13705 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13706         .f = cmd_set_vf_split_drop_en_parsed,
13707         .data = NULL,
13708         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13709         .tokens = {
13710                 (void *)&cmd_vf_split_drop_en_set,
13711                 (void *)&cmd_vf_split_drop_en_vf,
13712                 (void *)&cmd_vf_split_drop_en_split,
13713                 (void *)&cmd_vf_split_drop_en_drop,
13714                 (void *)&cmd_vf_split_drop_en_port_id,
13715                 (void *)&cmd_vf_split_drop_en_vf_id,
13716                 (void *)&cmd_vf_split_drop_en_on_off,
13717                 NULL,
13718         },
13719 };
13720
13721 /* vf mac address configuration */
13722
13723 /* Common result structure for vf mac address */
13724 struct cmd_set_vf_mac_addr_result {
13725         cmdline_fixed_string_t set;
13726         cmdline_fixed_string_t vf;
13727         cmdline_fixed_string_t mac;
13728         cmdline_fixed_string_t addr;
13729         portid_t port_id;
13730         uint16_t vf_id;
13731         struct ether_addr mac_addr;
13732
13733 };
13734
13735 /* Common CLI fields for vf split drop enable disable */
13736 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13737         TOKEN_STRING_INITIALIZER
13738                 (struct cmd_set_vf_mac_addr_result,
13739                  set, "set");
13740 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13741         TOKEN_STRING_INITIALIZER
13742                 (struct cmd_set_vf_mac_addr_result,
13743                  vf, "vf");
13744 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_set_vf_mac_addr_result,
13747                  mac, "mac");
13748 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_set_vf_mac_addr_result,
13751                  addr, "addr");
13752 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13753         TOKEN_NUM_INITIALIZER
13754                 (struct cmd_set_vf_mac_addr_result,
13755                  port_id, UINT16);
13756 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13757         TOKEN_NUM_INITIALIZER
13758                 (struct cmd_set_vf_mac_addr_result,
13759                  vf_id, UINT16);
13760 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13761         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13762                  mac_addr);
13763
13764 static void
13765 cmd_set_vf_mac_addr_parsed(
13766         void *parsed_result,
13767         __attribute__((unused)) struct cmdline *cl,
13768         __attribute__((unused)) void *data)
13769 {
13770         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13771         int ret = -ENOTSUP;
13772
13773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13774                 return;
13775
13776 #ifdef RTE_LIBRTE_IXGBE_PMD
13777         if (ret == -ENOTSUP)
13778                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13779                                 &res->mac_addr);
13780 #endif
13781 #ifdef RTE_LIBRTE_I40E_PMD
13782         if (ret == -ENOTSUP)
13783                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13784                                 &res->mac_addr);
13785 #endif
13786 #ifdef RTE_LIBRTE_BNXT_PMD
13787         if (ret == -ENOTSUP)
13788                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13789                                 &res->mac_addr);
13790 #endif
13791
13792         switch (ret) {
13793         case 0:
13794                 break;
13795         case -EINVAL:
13796                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13797                 break;
13798         case -ENODEV:
13799                 printf("invalid port_id %d\n", res->port_id);
13800                 break;
13801         case -ENOTSUP:
13802                 printf("function not implemented\n");
13803                 break;
13804         default:
13805                 printf("programming error: (%s)\n", strerror(-ret));
13806         }
13807 }
13808
13809 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13810         .f = cmd_set_vf_mac_addr_parsed,
13811         .data = NULL,
13812         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13813         .tokens = {
13814                 (void *)&cmd_set_vf_mac_addr_set,
13815                 (void *)&cmd_set_vf_mac_addr_vf,
13816                 (void *)&cmd_set_vf_mac_addr_mac,
13817                 (void *)&cmd_set_vf_mac_addr_addr,
13818                 (void *)&cmd_set_vf_mac_addr_port_id,
13819                 (void *)&cmd_set_vf_mac_addr_vf_id,
13820                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13821                 NULL,
13822         },
13823 };
13824
13825 /* MACsec configuration */
13826
13827 /* Common result structure for MACsec offload enable */
13828 struct cmd_macsec_offload_on_result {
13829         cmdline_fixed_string_t set;
13830         cmdline_fixed_string_t macsec;
13831         cmdline_fixed_string_t offload;
13832         portid_t port_id;
13833         cmdline_fixed_string_t on;
13834         cmdline_fixed_string_t encrypt;
13835         cmdline_fixed_string_t en_on_off;
13836         cmdline_fixed_string_t replay_protect;
13837         cmdline_fixed_string_t rp_on_off;
13838 };
13839
13840 /* Common CLI fields for MACsec offload disable */
13841 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13842         TOKEN_STRING_INITIALIZER
13843                 (struct cmd_macsec_offload_on_result,
13844                  set, "set");
13845 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13846         TOKEN_STRING_INITIALIZER
13847                 (struct cmd_macsec_offload_on_result,
13848                  macsec, "macsec");
13849 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13850         TOKEN_STRING_INITIALIZER
13851                 (struct cmd_macsec_offload_on_result,
13852                  offload, "offload");
13853 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13854         TOKEN_NUM_INITIALIZER
13855                 (struct cmd_macsec_offload_on_result,
13856                  port_id, UINT16);
13857 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13858         TOKEN_STRING_INITIALIZER
13859                 (struct cmd_macsec_offload_on_result,
13860                  on, "on");
13861 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13862         TOKEN_STRING_INITIALIZER
13863                 (struct cmd_macsec_offload_on_result,
13864                  encrypt, "encrypt");
13865 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13866         TOKEN_STRING_INITIALIZER
13867                 (struct cmd_macsec_offload_on_result,
13868                  en_on_off, "on#off");
13869 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13870         TOKEN_STRING_INITIALIZER
13871                 (struct cmd_macsec_offload_on_result,
13872                  replay_protect, "replay-protect");
13873 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13874         TOKEN_STRING_INITIALIZER
13875                 (struct cmd_macsec_offload_on_result,
13876                  rp_on_off, "on#off");
13877
13878 static void
13879 cmd_set_macsec_offload_on_parsed(
13880         void *parsed_result,
13881         __attribute__((unused)) struct cmdline *cl,
13882         __attribute__((unused)) void *data)
13883 {
13884         struct cmd_macsec_offload_on_result *res = parsed_result;
13885         int ret = -ENOTSUP;
13886         portid_t port_id = res->port_id;
13887         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13888         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13889         struct rte_eth_dev_info dev_info;
13890
13891         if (port_id_is_invalid(port_id, ENABLED_WARN))
13892                 return;
13893         if (!port_is_stopped(port_id)) {
13894                 printf("Please stop port %d first\n", port_id);
13895                 return;
13896         }
13897
13898         rte_eth_dev_info_get(port_id, &dev_info);
13899         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13900 #ifdef RTE_LIBRTE_IXGBE_PMD
13901                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13902 #endif
13903         }
13904         RTE_SET_USED(en);
13905         RTE_SET_USED(rp);
13906
13907         switch (ret) {
13908         case 0:
13909                 ports[port_id].dev_conf.txmode.offloads |=
13910                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13911                 cmd_reconfig_device_queue(port_id, 1, 1);
13912                 break;
13913         case -ENODEV:
13914                 printf("invalid port_id %d\n", port_id);
13915                 break;
13916         case -ENOTSUP:
13917                 printf("not supported on port %d\n", port_id);
13918                 break;
13919         default:
13920                 printf("programming error: (%s)\n", strerror(-ret));
13921         }
13922 }
13923
13924 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13925         .f = cmd_set_macsec_offload_on_parsed,
13926         .data = NULL,
13927         .help_str = "set macsec offload <port_id> on "
13928                 "encrypt on|off replay-protect on|off",
13929         .tokens = {
13930                 (void *)&cmd_macsec_offload_on_set,
13931                 (void *)&cmd_macsec_offload_on_macsec,
13932                 (void *)&cmd_macsec_offload_on_offload,
13933                 (void *)&cmd_macsec_offload_on_port_id,
13934                 (void *)&cmd_macsec_offload_on_on,
13935                 (void *)&cmd_macsec_offload_on_encrypt,
13936                 (void *)&cmd_macsec_offload_on_en_on_off,
13937                 (void *)&cmd_macsec_offload_on_replay_protect,
13938                 (void *)&cmd_macsec_offload_on_rp_on_off,
13939                 NULL,
13940         },
13941 };
13942
13943 /* Common result structure for MACsec offload disable */
13944 struct cmd_macsec_offload_off_result {
13945         cmdline_fixed_string_t set;
13946         cmdline_fixed_string_t macsec;
13947         cmdline_fixed_string_t offload;
13948         portid_t port_id;
13949         cmdline_fixed_string_t off;
13950 };
13951
13952 /* Common CLI fields for MACsec offload disable */
13953 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13954         TOKEN_STRING_INITIALIZER
13955                 (struct cmd_macsec_offload_off_result,
13956                  set, "set");
13957 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13958         TOKEN_STRING_INITIALIZER
13959                 (struct cmd_macsec_offload_off_result,
13960                  macsec, "macsec");
13961 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13962         TOKEN_STRING_INITIALIZER
13963                 (struct cmd_macsec_offload_off_result,
13964                  offload, "offload");
13965 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13966         TOKEN_NUM_INITIALIZER
13967                 (struct cmd_macsec_offload_off_result,
13968                  port_id, UINT16);
13969 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13970         TOKEN_STRING_INITIALIZER
13971                 (struct cmd_macsec_offload_off_result,
13972                  off, "off");
13973
13974 static void
13975 cmd_set_macsec_offload_off_parsed(
13976         void *parsed_result,
13977         __attribute__((unused)) struct cmdline *cl,
13978         __attribute__((unused)) void *data)
13979 {
13980         struct cmd_macsec_offload_off_result *res = parsed_result;
13981         int ret = -ENOTSUP;
13982         struct rte_eth_dev_info dev_info;
13983         portid_t port_id = res->port_id;
13984
13985         if (port_id_is_invalid(port_id, ENABLED_WARN))
13986                 return;
13987         if (!port_is_stopped(port_id)) {
13988                 printf("Please stop port %d first\n", port_id);
13989                 return;
13990         }
13991
13992         rte_eth_dev_info_get(port_id, &dev_info);
13993         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13994 #ifdef RTE_LIBRTE_IXGBE_PMD
13995                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13996 #endif
13997         }
13998         switch (ret) {
13999         case 0:
14000                 ports[port_id].dev_conf.txmode.offloads &=
14001                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14002                 cmd_reconfig_device_queue(port_id, 1, 1);
14003                 break;
14004         case -ENODEV:
14005                 printf("invalid port_id %d\n", port_id);
14006                 break;
14007         case -ENOTSUP:
14008                 printf("not supported on port %d\n", port_id);
14009                 break;
14010         default:
14011                 printf("programming error: (%s)\n", strerror(-ret));
14012         }
14013 }
14014
14015 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14016         .f = cmd_set_macsec_offload_off_parsed,
14017         .data = NULL,
14018         .help_str = "set macsec offload <port_id> off",
14019         .tokens = {
14020                 (void *)&cmd_macsec_offload_off_set,
14021                 (void *)&cmd_macsec_offload_off_macsec,
14022                 (void *)&cmd_macsec_offload_off_offload,
14023                 (void *)&cmd_macsec_offload_off_port_id,
14024                 (void *)&cmd_macsec_offload_off_off,
14025                 NULL,
14026         },
14027 };
14028
14029 /* Common result structure for MACsec secure connection configure */
14030 struct cmd_macsec_sc_result {
14031         cmdline_fixed_string_t set;
14032         cmdline_fixed_string_t macsec;
14033         cmdline_fixed_string_t sc;
14034         cmdline_fixed_string_t tx_rx;
14035         portid_t port_id;
14036         struct ether_addr mac;
14037         uint16_t pi;
14038 };
14039
14040 /* Common CLI fields for MACsec secure connection configure */
14041 cmdline_parse_token_string_t cmd_macsec_sc_set =
14042         TOKEN_STRING_INITIALIZER
14043                 (struct cmd_macsec_sc_result,
14044                  set, "set");
14045 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14046         TOKEN_STRING_INITIALIZER
14047                 (struct cmd_macsec_sc_result,
14048                  macsec, "macsec");
14049 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14050         TOKEN_STRING_INITIALIZER
14051                 (struct cmd_macsec_sc_result,
14052                  sc, "sc");
14053 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14054         TOKEN_STRING_INITIALIZER
14055                 (struct cmd_macsec_sc_result,
14056                  tx_rx, "tx#rx");
14057 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14058         TOKEN_NUM_INITIALIZER
14059                 (struct cmd_macsec_sc_result,
14060                  port_id, UINT16);
14061 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14062         TOKEN_ETHERADDR_INITIALIZER
14063                 (struct cmd_macsec_sc_result,
14064                  mac);
14065 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14066         TOKEN_NUM_INITIALIZER
14067                 (struct cmd_macsec_sc_result,
14068                  pi, UINT16);
14069
14070 static void
14071 cmd_set_macsec_sc_parsed(
14072         void *parsed_result,
14073         __attribute__((unused)) struct cmdline *cl,
14074         __attribute__((unused)) void *data)
14075 {
14076         struct cmd_macsec_sc_result *res = parsed_result;
14077         int ret = -ENOTSUP;
14078         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14079
14080 #ifdef RTE_LIBRTE_IXGBE_PMD
14081         ret = is_tx ?
14082                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14083                                 res->mac.addr_bytes) :
14084                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14085                                 res->mac.addr_bytes, res->pi);
14086 #endif
14087         RTE_SET_USED(is_tx);
14088
14089         switch (ret) {
14090         case 0:
14091                 break;
14092         case -ENODEV:
14093                 printf("invalid port_id %d\n", res->port_id);
14094                 break;
14095         case -ENOTSUP:
14096                 printf("not supported on port %d\n", res->port_id);
14097                 break;
14098         default:
14099                 printf("programming error: (%s)\n", strerror(-ret));
14100         }
14101 }
14102
14103 cmdline_parse_inst_t cmd_set_macsec_sc = {
14104         .f = cmd_set_macsec_sc_parsed,
14105         .data = NULL,
14106         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14107         .tokens = {
14108                 (void *)&cmd_macsec_sc_set,
14109                 (void *)&cmd_macsec_sc_macsec,
14110                 (void *)&cmd_macsec_sc_sc,
14111                 (void *)&cmd_macsec_sc_tx_rx,
14112                 (void *)&cmd_macsec_sc_port_id,
14113                 (void *)&cmd_macsec_sc_mac,
14114                 (void *)&cmd_macsec_sc_pi,
14115                 NULL,
14116         },
14117 };
14118
14119 /* Common result structure for MACsec secure connection configure */
14120 struct cmd_macsec_sa_result {
14121         cmdline_fixed_string_t set;
14122         cmdline_fixed_string_t macsec;
14123         cmdline_fixed_string_t sa;
14124         cmdline_fixed_string_t tx_rx;
14125         portid_t port_id;
14126         uint8_t idx;
14127         uint8_t an;
14128         uint32_t pn;
14129         cmdline_fixed_string_t key;
14130 };
14131
14132 /* Common CLI fields for MACsec secure connection configure */
14133 cmdline_parse_token_string_t cmd_macsec_sa_set =
14134         TOKEN_STRING_INITIALIZER
14135                 (struct cmd_macsec_sa_result,
14136                  set, "set");
14137 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14138         TOKEN_STRING_INITIALIZER
14139                 (struct cmd_macsec_sa_result,
14140                  macsec, "macsec");
14141 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14142         TOKEN_STRING_INITIALIZER
14143                 (struct cmd_macsec_sa_result,
14144                  sa, "sa");
14145 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14146         TOKEN_STRING_INITIALIZER
14147                 (struct cmd_macsec_sa_result,
14148                  tx_rx, "tx#rx");
14149 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14150         TOKEN_NUM_INITIALIZER
14151                 (struct cmd_macsec_sa_result,
14152                  port_id, UINT16);
14153 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14154         TOKEN_NUM_INITIALIZER
14155                 (struct cmd_macsec_sa_result,
14156                  idx, UINT8);
14157 cmdline_parse_token_num_t cmd_macsec_sa_an =
14158         TOKEN_NUM_INITIALIZER
14159                 (struct cmd_macsec_sa_result,
14160                  an, UINT8);
14161 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14162         TOKEN_NUM_INITIALIZER
14163                 (struct cmd_macsec_sa_result,
14164                  pn, UINT32);
14165 cmdline_parse_token_string_t cmd_macsec_sa_key =
14166         TOKEN_STRING_INITIALIZER
14167                 (struct cmd_macsec_sa_result,
14168                  key, NULL);
14169
14170 static void
14171 cmd_set_macsec_sa_parsed(
14172         void *parsed_result,
14173         __attribute__((unused)) struct cmdline *cl,
14174         __attribute__((unused)) void *data)
14175 {
14176         struct cmd_macsec_sa_result *res = parsed_result;
14177         int ret = -ENOTSUP;
14178         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14179         uint8_t key[16] = { 0 };
14180         uint8_t xdgt0;
14181         uint8_t xdgt1;
14182         int key_len;
14183         int i;
14184
14185         key_len = strlen(res->key) / 2;
14186         if (key_len > 16)
14187                 key_len = 16;
14188
14189         for (i = 0; i < key_len; i++) {
14190                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14191                 if (xdgt0 == 0xFF)
14192                         return;
14193                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14194                 if (xdgt1 == 0xFF)
14195                         return;
14196                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14197         }
14198
14199 #ifdef RTE_LIBRTE_IXGBE_PMD
14200         ret = is_tx ?
14201                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14202                         res->idx, res->an, res->pn, key) :
14203                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14204                         res->idx, res->an, res->pn, key);
14205 #endif
14206         RTE_SET_USED(is_tx);
14207         RTE_SET_USED(key);
14208
14209         switch (ret) {
14210         case 0:
14211                 break;
14212         case -EINVAL:
14213                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14214                 break;
14215         case -ENODEV:
14216                 printf("invalid port_id %d\n", res->port_id);
14217                 break;
14218         case -ENOTSUP:
14219                 printf("not supported on port %d\n", res->port_id);
14220                 break;
14221         default:
14222                 printf("programming error: (%s)\n", strerror(-ret));
14223         }
14224 }
14225
14226 cmdline_parse_inst_t cmd_set_macsec_sa = {
14227         .f = cmd_set_macsec_sa_parsed,
14228         .data = NULL,
14229         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14230         .tokens = {
14231                 (void *)&cmd_macsec_sa_set,
14232                 (void *)&cmd_macsec_sa_macsec,
14233                 (void *)&cmd_macsec_sa_sa,
14234                 (void *)&cmd_macsec_sa_tx_rx,
14235                 (void *)&cmd_macsec_sa_port_id,
14236                 (void *)&cmd_macsec_sa_idx,
14237                 (void *)&cmd_macsec_sa_an,
14238                 (void *)&cmd_macsec_sa_pn,
14239                 (void *)&cmd_macsec_sa_key,
14240                 NULL,
14241         },
14242 };
14243
14244 /* VF unicast promiscuous mode configuration */
14245
14246 /* Common result structure for VF unicast promiscuous mode */
14247 struct cmd_vf_promisc_result {
14248         cmdline_fixed_string_t set;
14249         cmdline_fixed_string_t vf;
14250         cmdline_fixed_string_t promisc;
14251         portid_t port_id;
14252         uint32_t vf_id;
14253         cmdline_fixed_string_t on_off;
14254 };
14255
14256 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14257 cmdline_parse_token_string_t cmd_vf_promisc_set =
14258         TOKEN_STRING_INITIALIZER
14259                 (struct cmd_vf_promisc_result,
14260                  set, "set");
14261 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_vf_promisc_result,
14264                  vf, "vf");
14265 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14266         TOKEN_STRING_INITIALIZER
14267                 (struct cmd_vf_promisc_result,
14268                  promisc, "promisc");
14269 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14270         TOKEN_NUM_INITIALIZER
14271                 (struct cmd_vf_promisc_result,
14272                  port_id, UINT16);
14273 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14274         TOKEN_NUM_INITIALIZER
14275                 (struct cmd_vf_promisc_result,
14276                  vf_id, UINT32);
14277 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14278         TOKEN_STRING_INITIALIZER
14279                 (struct cmd_vf_promisc_result,
14280                  on_off, "on#off");
14281
14282 static void
14283 cmd_set_vf_promisc_parsed(
14284         void *parsed_result,
14285         __attribute__((unused)) struct cmdline *cl,
14286         __attribute__((unused)) void *data)
14287 {
14288         struct cmd_vf_promisc_result *res = parsed_result;
14289         int ret = -ENOTSUP;
14290
14291         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14292
14293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14294                 return;
14295
14296 #ifdef RTE_LIBRTE_I40E_PMD
14297         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14298                                                   res->vf_id, is_on);
14299 #endif
14300
14301         switch (ret) {
14302         case 0:
14303                 break;
14304         case -EINVAL:
14305                 printf("invalid vf_id %d\n", res->vf_id);
14306                 break;
14307         case -ENODEV:
14308                 printf("invalid port_id %d\n", res->port_id);
14309                 break;
14310         case -ENOTSUP:
14311                 printf("function not implemented\n");
14312                 break;
14313         default:
14314                 printf("programming error: (%s)\n", strerror(-ret));
14315         }
14316 }
14317
14318 cmdline_parse_inst_t cmd_set_vf_promisc = {
14319         .f = cmd_set_vf_promisc_parsed,
14320         .data = NULL,
14321         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14322                 "Set unicast promiscuous mode for a VF from the PF",
14323         .tokens = {
14324                 (void *)&cmd_vf_promisc_set,
14325                 (void *)&cmd_vf_promisc_vf,
14326                 (void *)&cmd_vf_promisc_promisc,
14327                 (void *)&cmd_vf_promisc_port_id,
14328                 (void *)&cmd_vf_promisc_vf_id,
14329                 (void *)&cmd_vf_promisc_on_off,
14330                 NULL,
14331         },
14332 };
14333
14334 /* VF multicast promiscuous mode configuration */
14335
14336 /* Common result structure for VF multicast promiscuous mode */
14337 struct cmd_vf_allmulti_result {
14338         cmdline_fixed_string_t set;
14339         cmdline_fixed_string_t vf;
14340         cmdline_fixed_string_t allmulti;
14341         portid_t port_id;
14342         uint32_t vf_id;
14343         cmdline_fixed_string_t on_off;
14344 };
14345
14346 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14347 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14348         TOKEN_STRING_INITIALIZER
14349                 (struct cmd_vf_allmulti_result,
14350                  set, "set");
14351 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14352         TOKEN_STRING_INITIALIZER
14353                 (struct cmd_vf_allmulti_result,
14354                  vf, "vf");
14355 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14356         TOKEN_STRING_INITIALIZER
14357                 (struct cmd_vf_allmulti_result,
14358                  allmulti, "allmulti");
14359 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14360         TOKEN_NUM_INITIALIZER
14361                 (struct cmd_vf_allmulti_result,
14362                  port_id, UINT16);
14363 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14364         TOKEN_NUM_INITIALIZER
14365                 (struct cmd_vf_allmulti_result,
14366                  vf_id, UINT32);
14367 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_vf_allmulti_result,
14370                  on_off, "on#off");
14371
14372 static void
14373 cmd_set_vf_allmulti_parsed(
14374         void *parsed_result,
14375         __attribute__((unused)) struct cmdline *cl,
14376         __attribute__((unused)) void *data)
14377 {
14378         struct cmd_vf_allmulti_result *res = parsed_result;
14379         int ret = -ENOTSUP;
14380
14381         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14382
14383         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14384                 return;
14385
14386 #ifdef RTE_LIBRTE_I40E_PMD
14387         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14388                                                     res->vf_id, is_on);
14389 #endif
14390
14391         switch (ret) {
14392         case 0:
14393                 break;
14394         case -EINVAL:
14395                 printf("invalid vf_id %d\n", res->vf_id);
14396                 break;
14397         case -ENODEV:
14398                 printf("invalid port_id %d\n", res->port_id);
14399                 break;
14400         case -ENOTSUP:
14401                 printf("function not implemented\n");
14402                 break;
14403         default:
14404                 printf("programming error: (%s)\n", strerror(-ret));
14405         }
14406 }
14407
14408 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14409         .f = cmd_set_vf_allmulti_parsed,
14410         .data = NULL,
14411         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14412                 "Set multicast promiscuous mode for a VF from the PF",
14413         .tokens = {
14414                 (void *)&cmd_vf_allmulti_set,
14415                 (void *)&cmd_vf_allmulti_vf,
14416                 (void *)&cmd_vf_allmulti_allmulti,
14417                 (void *)&cmd_vf_allmulti_port_id,
14418                 (void *)&cmd_vf_allmulti_vf_id,
14419                 (void *)&cmd_vf_allmulti_on_off,
14420                 NULL,
14421         },
14422 };
14423
14424 /* vf broadcast mode configuration */
14425
14426 /* Common result structure for vf broadcast */
14427 struct cmd_set_vf_broadcast_result {
14428         cmdline_fixed_string_t set;
14429         cmdline_fixed_string_t vf;
14430         cmdline_fixed_string_t broadcast;
14431         portid_t port_id;
14432         uint16_t vf_id;
14433         cmdline_fixed_string_t on_off;
14434 };
14435
14436 /* Common CLI fields for vf broadcast enable disable */
14437 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14438         TOKEN_STRING_INITIALIZER
14439                 (struct cmd_set_vf_broadcast_result,
14440                  set, "set");
14441 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14442         TOKEN_STRING_INITIALIZER
14443                 (struct cmd_set_vf_broadcast_result,
14444                  vf, "vf");
14445 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14446         TOKEN_STRING_INITIALIZER
14447                 (struct cmd_set_vf_broadcast_result,
14448                  broadcast, "broadcast");
14449 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14450         TOKEN_NUM_INITIALIZER
14451                 (struct cmd_set_vf_broadcast_result,
14452                  port_id, UINT16);
14453 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14454         TOKEN_NUM_INITIALIZER
14455                 (struct cmd_set_vf_broadcast_result,
14456                  vf_id, UINT16);
14457 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14458         TOKEN_STRING_INITIALIZER
14459                 (struct cmd_set_vf_broadcast_result,
14460                  on_off, "on#off");
14461
14462 static void
14463 cmd_set_vf_broadcast_parsed(
14464         void *parsed_result,
14465         __attribute__((unused)) struct cmdline *cl,
14466         __attribute__((unused)) void *data)
14467 {
14468         struct cmd_set_vf_broadcast_result *res = parsed_result;
14469         int ret = -ENOTSUP;
14470
14471         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14472
14473         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14474                 return;
14475
14476 #ifdef RTE_LIBRTE_I40E_PMD
14477         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14478                                             res->vf_id, is_on);
14479 #endif
14480
14481         switch (ret) {
14482         case 0:
14483                 break;
14484         case -EINVAL:
14485                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14486                 break;
14487         case -ENODEV:
14488                 printf("invalid port_id %d\n", res->port_id);
14489                 break;
14490         case -ENOTSUP:
14491                 printf("function not implemented\n");
14492                 break;
14493         default:
14494                 printf("programming error: (%s)\n", strerror(-ret));
14495         }
14496 }
14497
14498 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14499         .f = cmd_set_vf_broadcast_parsed,
14500         .data = NULL,
14501         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14502         .tokens = {
14503                 (void *)&cmd_set_vf_broadcast_set,
14504                 (void *)&cmd_set_vf_broadcast_vf,
14505                 (void *)&cmd_set_vf_broadcast_broadcast,
14506                 (void *)&cmd_set_vf_broadcast_port_id,
14507                 (void *)&cmd_set_vf_broadcast_vf_id,
14508                 (void *)&cmd_set_vf_broadcast_on_off,
14509                 NULL,
14510         },
14511 };
14512
14513 /* vf vlan tag configuration */
14514
14515 /* Common result structure for vf vlan tag */
14516 struct cmd_set_vf_vlan_tag_result {
14517         cmdline_fixed_string_t set;
14518         cmdline_fixed_string_t vf;
14519         cmdline_fixed_string_t vlan;
14520         cmdline_fixed_string_t tag;
14521         portid_t port_id;
14522         uint16_t vf_id;
14523         cmdline_fixed_string_t on_off;
14524 };
14525
14526 /* Common CLI fields for vf vlan tag enable disable */
14527 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14528         TOKEN_STRING_INITIALIZER
14529                 (struct cmd_set_vf_vlan_tag_result,
14530                  set, "set");
14531 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14532         TOKEN_STRING_INITIALIZER
14533                 (struct cmd_set_vf_vlan_tag_result,
14534                  vf, "vf");
14535 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14536         TOKEN_STRING_INITIALIZER
14537                 (struct cmd_set_vf_vlan_tag_result,
14538                  vlan, "vlan");
14539 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14540         TOKEN_STRING_INITIALIZER
14541                 (struct cmd_set_vf_vlan_tag_result,
14542                  tag, "tag");
14543 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14544         TOKEN_NUM_INITIALIZER
14545                 (struct cmd_set_vf_vlan_tag_result,
14546                  port_id, UINT16);
14547 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14548         TOKEN_NUM_INITIALIZER
14549                 (struct cmd_set_vf_vlan_tag_result,
14550                  vf_id, UINT16);
14551 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14552         TOKEN_STRING_INITIALIZER
14553                 (struct cmd_set_vf_vlan_tag_result,
14554                  on_off, "on#off");
14555
14556 static void
14557 cmd_set_vf_vlan_tag_parsed(
14558         void *parsed_result,
14559         __attribute__((unused)) struct cmdline *cl,
14560         __attribute__((unused)) void *data)
14561 {
14562         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14563         int ret = -ENOTSUP;
14564
14565         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14566
14567         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14568                 return;
14569
14570 #ifdef RTE_LIBRTE_I40E_PMD
14571         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14572                                            res->vf_id, is_on);
14573 #endif
14574
14575         switch (ret) {
14576         case 0:
14577                 break;
14578         case -EINVAL:
14579                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14580                 break;
14581         case -ENODEV:
14582                 printf("invalid port_id %d\n", res->port_id);
14583                 break;
14584         case -ENOTSUP:
14585                 printf("function not implemented\n");
14586                 break;
14587         default:
14588                 printf("programming error: (%s)\n", strerror(-ret));
14589         }
14590 }
14591
14592 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14593         .f = cmd_set_vf_vlan_tag_parsed,
14594         .data = NULL,
14595         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14596         .tokens = {
14597                 (void *)&cmd_set_vf_vlan_tag_set,
14598                 (void *)&cmd_set_vf_vlan_tag_vf,
14599                 (void *)&cmd_set_vf_vlan_tag_vlan,
14600                 (void *)&cmd_set_vf_vlan_tag_tag,
14601                 (void *)&cmd_set_vf_vlan_tag_port_id,
14602                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14603                 (void *)&cmd_set_vf_vlan_tag_on_off,
14604                 NULL,
14605         },
14606 };
14607
14608 /* Common definition of VF and TC TX bandwidth configuration */
14609 struct cmd_vf_tc_bw_result {
14610         cmdline_fixed_string_t set;
14611         cmdline_fixed_string_t vf;
14612         cmdline_fixed_string_t tc;
14613         cmdline_fixed_string_t tx;
14614         cmdline_fixed_string_t min_bw;
14615         cmdline_fixed_string_t max_bw;
14616         cmdline_fixed_string_t strict_link_prio;
14617         portid_t port_id;
14618         uint16_t vf_id;
14619         uint8_t tc_no;
14620         uint32_t bw;
14621         cmdline_fixed_string_t bw_list;
14622         uint8_t tc_map;
14623 };
14624
14625 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14626         TOKEN_STRING_INITIALIZER
14627                 (struct cmd_vf_tc_bw_result,
14628                  set, "set");
14629 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14630         TOKEN_STRING_INITIALIZER
14631                 (struct cmd_vf_tc_bw_result,
14632                  vf, "vf");
14633 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14634         TOKEN_STRING_INITIALIZER
14635                 (struct cmd_vf_tc_bw_result,
14636                  tc, "tc");
14637 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14638         TOKEN_STRING_INITIALIZER
14639                 (struct cmd_vf_tc_bw_result,
14640                  tx, "tx");
14641 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14642         TOKEN_STRING_INITIALIZER
14643                 (struct cmd_vf_tc_bw_result,
14644                  strict_link_prio, "strict-link-priority");
14645 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14646         TOKEN_STRING_INITIALIZER
14647                 (struct cmd_vf_tc_bw_result,
14648                  min_bw, "min-bandwidth");
14649 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14650         TOKEN_STRING_INITIALIZER
14651                 (struct cmd_vf_tc_bw_result,
14652                  max_bw, "max-bandwidth");
14653 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14654         TOKEN_NUM_INITIALIZER
14655                 (struct cmd_vf_tc_bw_result,
14656                  port_id, UINT16);
14657 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14658         TOKEN_NUM_INITIALIZER
14659                 (struct cmd_vf_tc_bw_result,
14660                  vf_id, UINT16);
14661 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14662         TOKEN_NUM_INITIALIZER
14663                 (struct cmd_vf_tc_bw_result,
14664                  tc_no, UINT8);
14665 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14666         TOKEN_NUM_INITIALIZER
14667                 (struct cmd_vf_tc_bw_result,
14668                  bw, UINT32);
14669 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_vf_tc_bw_result,
14672                  bw_list, NULL);
14673 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14674         TOKEN_NUM_INITIALIZER
14675                 (struct cmd_vf_tc_bw_result,
14676                  tc_map, UINT8);
14677
14678 /* VF max bandwidth setting */
14679 static void
14680 cmd_vf_max_bw_parsed(
14681         void *parsed_result,
14682         __attribute__((unused)) struct cmdline *cl,
14683         __attribute__((unused)) void *data)
14684 {
14685         struct cmd_vf_tc_bw_result *res = parsed_result;
14686         int ret = -ENOTSUP;
14687
14688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14689                 return;
14690
14691 #ifdef RTE_LIBRTE_I40E_PMD
14692         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14693                                          res->vf_id, res->bw);
14694 #endif
14695
14696         switch (ret) {
14697         case 0:
14698                 break;
14699         case -EINVAL:
14700                 printf("invalid vf_id %d or bandwidth %d\n",
14701                        res->vf_id, res->bw);
14702                 break;
14703         case -ENODEV:
14704                 printf("invalid port_id %d\n", res->port_id);
14705                 break;
14706         case -ENOTSUP:
14707                 printf("function not implemented\n");
14708                 break;
14709         default:
14710                 printf("programming error: (%s)\n", strerror(-ret));
14711         }
14712 }
14713
14714 cmdline_parse_inst_t cmd_vf_max_bw = {
14715         .f = cmd_vf_max_bw_parsed,
14716         .data = NULL,
14717         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14718         .tokens = {
14719                 (void *)&cmd_vf_tc_bw_set,
14720                 (void *)&cmd_vf_tc_bw_vf,
14721                 (void *)&cmd_vf_tc_bw_tx,
14722                 (void *)&cmd_vf_tc_bw_max_bw,
14723                 (void *)&cmd_vf_tc_bw_port_id,
14724                 (void *)&cmd_vf_tc_bw_vf_id,
14725                 (void *)&cmd_vf_tc_bw_bw,
14726                 NULL,
14727         },
14728 };
14729
14730 static int
14731 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14732                            uint8_t *tc_num,
14733                            char *str)
14734 {
14735         uint32_t size;
14736         const char *p, *p0 = str;
14737         char s[256];
14738         char *end;
14739         char *str_fld[16];
14740         uint16_t i;
14741         int ret;
14742
14743         p = strchr(p0, '(');
14744         if (p == NULL) {
14745                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14746                 return -1;
14747         }
14748         p++;
14749         p0 = strchr(p, ')');
14750         if (p0 == NULL) {
14751                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14752                 return -1;
14753         }
14754         size = p0 - p;
14755         if (size >= sizeof(s)) {
14756                 printf("The string size exceeds the internal buffer size\n");
14757                 return -1;
14758         }
14759         snprintf(s, sizeof(s), "%.*s", size, p);
14760         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14761         if (ret <= 0) {
14762                 printf("Failed to get the bandwidth list. ");
14763                 return -1;
14764         }
14765         *tc_num = ret;
14766         for (i = 0; i < ret; i++)
14767                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14768
14769         return 0;
14770 }
14771
14772 /* TC min bandwidth setting */
14773 static void
14774 cmd_vf_tc_min_bw_parsed(
14775         void *parsed_result,
14776         __attribute__((unused)) struct cmdline *cl,
14777         __attribute__((unused)) void *data)
14778 {
14779         struct cmd_vf_tc_bw_result *res = parsed_result;
14780         uint8_t tc_num;
14781         uint8_t bw[16];
14782         int ret = -ENOTSUP;
14783
14784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14785                 return;
14786
14787         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14788         if (ret)
14789                 return;
14790
14791 #ifdef RTE_LIBRTE_I40E_PMD
14792         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14793                                               tc_num, bw);
14794 #endif
14795
14796         switch (ret) {
14797         case 0:
14798                 break;
14799         case -EINVAL:
14800                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14801                 break;
14802         case -ENODEV:
14803                 printf("invalid port_id %d\n", res->port_id);
14804                 break;
14805         case -ENOTSUP:
14806                 printf("function not implemented\n");
14807                 break;
14808         default:
14809                 printf("programming error: (%s)\n", strerror(-ret));
14810         }
14811 }
14812
14813 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14814         .f = cmd_vf_tc_min_bw_parsed,
14815         .data = NULL,
14816         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14817                     " <bw1, bw2, ...>",
14818         .tokens = {
14819                 (void *)&cmd_vf_tc_bw_set,
14820                 (void *)&cmd_vf_tc_bw_vf,
14821                 (void *)&cmd_vf_tc_bw_tc,
14822                 (void *)&cmd_vf_tc_bw_tx,
14823                 (void *)&cmd_vf_tc_bw_min_bw,
14824                 (void *)&cmd_vf_tc_bw_port_id,
14825                 (void *)&cmd_vf_tc_bw_vf_id,
14826                 (void *)&cmd_vf_tc_bw_bw_list,
14827                 NULL,
14828         },
14829 };
14830
14831 static void
14832 cmd_tc_min_bw_parsed(
14833         void *parsed_result,
14834         __attribute__((unused)) struct cmdline *cl,
14835         __attribute__((unused)) void *data)
14836 {
14837         struct cmd_vf_tc_bw_result *res = parsed_result;
14838         struct rte_port *port;
14839         uint8_t tc_num;
14840         uint8_t bw[16];
14841         int ret = -ENOTSUP;
14842
14843         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14844                 return;
14845
14846         port = &ports[res->port_id];
14847         /** Check if the port is not started **/
14848         if (port->port_status != RTE_PORT_STOPPED) {
14849                 printf("Please stop port %d first\n", res->port_id);
14850                 return;
14851         }
14852
14853         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14854         if (ret)
14855                 return;
14856
14857 #ifdef RTE_LIBRTE_IXGBE_PMD
14858         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14859 #endif
14860
14861         switch (ret) {
14862         case 0:
14863                 break;
14864         case -EINVAL:
14865                 printf("invalid bandwidth\n");
14866                 break;
14867         case -ENODEV:
14868                 printf("invalid port_id %d\n", res->port_id);
14869                 break;
14870         case -ENOTSUP:
14871                 printf("function not implemented\n");
14872                 break;
14873         default:
14874                 printf("programming error: (%s)\n", strerror(-ret));
14875         }
14876 }
14877
14878 cmdline_parse_inst_t cmd_tc_min_bw = {
14879         .f = cmd_tc_min_bw_parsed,
14880         .data = NULL,
14881         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14882         .tokens = {
14883                 (void *)&cmd_vf_tc_bw_set,
14884                 (void *)&cmd_vf_tc_bw_tc,
14885                 (void *)&cmd_vf_tc_bw_tx,
14886                 (void *)&cmd_vf_tc_bw_min_bw,
14887                 (void *)&cmd_vf_tc_bw_port_id,
14888                 (void *)&cmd_vf_tc_bw_bw_list,
14889                 NULL,
14890         },
14891 };
14892
14893 /* TC max bandwidth setting */
14894 static void
14895 cmd_vf_tc_max_bw_parsed(
14896         void *parsed_result,
14897         __attribute__((unused)) struct cmdline *cl,
14898         __attribute__((unused)) void *data)
14899 {
14900         struct cmd_vf_tc_bw_result *res = parsed_result;
14901         int ret = -ENOTSUP;
14902
14903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14904                 return;
14905
14906 #ifdef RTE_LIBRTE_I40E_PMD
14907         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14908                                             res->tc_no, res->bw);
14909 #endif
14910
14911         switch (ret) {
14912         case 0:
14913                 break;
14914         case -EINVAL:
14915                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14916                        res->vf_id, res->tc_no, res->bw);
14917                 break;
14918         case -ENODEV:
14919                 printf("invalid port_id %d\n", res->port_id);
14920                 break;
14921         case -ENOTSUP:
14922                 printf("function not implemented\n");
14923                 break;
14924         default:
14925                 printf("programming error: (%s)\n", strerror(-ret));
14926         }
14927 }
14928
14929 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14930         .f = cmd_vf_tc_max_bw_parsed,
14931         .data = NULL,
14932         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14933                     " <bandwidth>",
14934         .tokens = {
14935                 (void *)&cmd_vf_tc_bw_set,
14936                 (void *)&cmd_vf_tc_bw_vf,
14937                 (void *)&cmd_vf_tc_bw_tc,
14938                 (void *)&cmd_vf_tc_bw_tx,
14939                 (void *)&cmd_vf_tc_bw_max_bw,
14940                 (void *)&cmd_vf_tc_bw_port_id,
14941                 (void *)&cmd_vf_tc_bw_vf_id,
14942                 (void *)&cmd_vf_tc_bw_tc_no,
14943                 (void *)&cmd_vf_tc_bw_bw,
14944                 NULL,
14945         },
14946 };
14947
14948
14949 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14950
14951 /* *** Set Port default Traffic Management Hierarchy *** */
14952 struct cmd_set_port_tm_hierarchy_default_result {
14953         cmdline_fixed_string_t set;
14954         cmdline_fixed_string_t port;
14955         cmdline_fixed_string_t tm;
14956         cmdline_fixed_string_t hierarchy;
14957         cmdline_fixed_string_t def;
14958         portid_t port_id;
14959 };
14960
14961 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14962         TOKEN_STRING_INITIALIZER(
14963                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14964 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14965         TOKEN_STRING_INITIALIZER(
14966                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14967 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14968         TOKEN_STRING_INITIALIZER(
14969                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14970 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14971         TOKEN_STRING_INITIALIZER(
14972                 struct cmd_set_port_tm_hierarchy_default_result,
14973                         hierarchy, "hierarchy");
14974 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14975         TOKEN_STRING_INITIALIZER(
14976                 struct cmd_set_port_tm_hierarchy_default_result,
14977                         def, "default");
14978 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14979         TOKEN_NUM_INITIALIZER(
14980                 struct cmd_set_port_tm_hierarchy_default_result,
14981                         port_id, UINT16);
14982
14983 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14984         __attribute__((unused)) struct cmdline *cl,
14985         __attribute__((unused)) void *data)
14986 {
14987         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14988         struct rte_port *p;
14989         portid_t port_id = res->port_id;
14990
14991         if (port_id_is_invalid(port_id, ENABLED_WARN))
14992                 return;
14993
14994         p = &ports[port_id];
14995
14996         /* Forward mode: tm */
14997         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14998                 printf("  softnicfwd mode not enabled(error)\n");
14999                 return;
15000         }
15001
15002         /* Set the default tm hierarchy */
15003         p->softport.default_tm_hierarchy_enable = 1;
15004 }
15005
15006 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15007         .f = cmd_set_port_tm_hierarchy_default_parsed,
15008         .data = NULL,
15009         .help_str = "set port tm hierarchy default <port_id>",
15010         .tokens = {
15011                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15012                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15013                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15014                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15015                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15016                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15017                 NULL,
15018         },
15019 };
15020 #endif
15021
15022 /** Set VXLAN encapsulation details */
15023 struct cmd_set_vxlan_result {
15024         cmdline_fixed_string_t set;
15025         cmdline_fixed_string_t vxlan;
15026         cmdline_fixed_string_t pos_token;
15027         cmdline_fixed_string_t ip_version;
15028         uint32_t vlan_present:1;
15029         uint32_t vni;
15030         uint16_t udp_src;
15031         uint16_t udp_dst;
15032         cmdline_ipaddr_t ip_src;
15033         cmdline_ipaddr_t ip_dst;
15034         uint16_t tci;
15035         struct ether_addr eth_src;
15036         struct ether_addr eth_dst;
15037 };
15038
15039 cmdline_parse_token_string_t cmd_set_vxlan_set =
15040         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15041 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15042         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15043 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15044         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15045                                  "vxlan-with-vlan");
15046 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15047         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15048                                  "ip-version");
15049 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15050         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15051                                  "ipv4#ipv6");
15052 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15053         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15054                                  "vni");
15055 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15056         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15057 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15058         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15059                                  "udp-src");
15060 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15061         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15062 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15063         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15064                                  "udp-dst");
15065 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15066         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15067 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15068         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15069                                  "ip-src");
15070 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15071         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15072 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15073         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15074                                  "ip-dst");
15075 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15076         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15077 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15078         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15079                                  "vlan-tci");
15080 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15081         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15082 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15083         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15084                                  "eth-src");
15085 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15086         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15087 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15088         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15089                                  "eth-dst");
15090 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15091         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15092
15093 static void cmd_set_vxlan_parsed(void *parsed_result,
15094         __attribute__((unused)) struct cmdline *cl,
15095         __attribute__((unused)) void *data)
15096 {
15097         struct cmd_set_vxlan_result *res = parsed_result;
15098         union {
15099                 uint32_t vxlan_id;
15100                 uint8_t vni[4];
15101         } id = {
15102                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15103         };
15104
15105         if (strcmp(res->vxlan, "vxlan") == 0)
15106                 vxlan_encap_conf.select_vlan = 0;
15107         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15108                 vxlan_encap_conf.select_vlan = 1;
15109         if (strcmp(res->ip_version, "ipv4") == 0)
15110                 vxlan_encap_conf.select_ipv4 = 1;
15111         else if (strcmp(res->ip_version, "ipv6") == 0)
15112                 vxlan_encap_conf.select_ipv4 = 0;
15113         else
15114                 return;
15115         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15116         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15117         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15118         if (vxlan_encap_conf.select_ipv4) {
15119                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15120                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15121         } else {
15122                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15123                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15124         }
15125         if (vxlan_encap_conf.select_vlan)
15126                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15127         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15128                    ETHER_ADDR_LEN);
15129         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15130                    ETHER_ADDR_LEN);
15131 }
15132
15133 cmdline_parse_inst_t cmd_set_vxlan = {
15134         .f = cmd_set_vxlan_parsed,
15135         .data = NULL,
15136         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15137                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15138                 " eth-src <eth-src> eth-dst <eth-dst>",
15139         .tokens = {
15140                 (void *)&cmd_set_vxlan_set,
15141                 (void *)&cmd_set_vxlan_vxlan,
15142                 (void *)&cmd_set_vxlan_ip_version,
15143                 (void *)&cmd_set_vxlan_ip_version_value,
15144                 (void *)&cmd_set_vxlan_vni,
15145                 (void *)&cmd_set_vxlan_vni_value,
15146                 (void *)&cmd_set_vxlan_udp_src,
15147                 (void *)&cmd_set_vxlan_udp_src_value,
15148                 (void *)&cmd_set_vxlan_udp_dst,
15149                 (void *)&cmd_set_vxlan_udp_dst_value,
15150                 (void *)&cmd_set_vxlan_ip_src,
15151                 (void *)&cmd_set_vxlan_ip_src_value,
15152                 (void *)&cmd_set_vxlan_ip_dst,
15153                 (void *)&cmd_set_vxlan_ip_dst_value,
15154                 (void *)&cmd_set_vxlan_eth_src,
15155                 (void *)&cmd_set_vxlan_eth_src_value,
15156                 (void *)&cmd_set_vxlan_eth_dst,
15157                 (void *)&cmd_set_vxlan_eth_dst_value,
15158                 NULL,
15159         },
15160 };
15161
15162 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15163         .f = cmd_set_vxlan_parsed,
15164         .data = NULL,
15165         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15166                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15167                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15168                 " <eth-dst>",
15169         .tokens = {
15170                 (void *)&cmd_set_vxlan_set,
15171                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15172                 (void *)&cmd_set_vxlan_ip_version,
15173                 (void *)&cmd_set_vxlan_ip_version_value,
15174                 (void *)&cmd_set_vxlan_vni,
15175                 (void *)&cmd_set_vxlan_vni_value,
15176                 (void *)&cmd_set_vxlan_udp_src,
15177                 (void *)&cmd_set_vxlan_udp_src_value,
15178                 (void *)&cmd_set_vxlan_udp_dst,
15179                 (void *)&cmd_set_vxlan_udp_dst_value,
15180                 (void *)&cmd_set_vxlan_ip_src,
15181                 (void *)&cmd_set_vxlan_ip_src_value,
15182                 (void *)&cmd_set_vxlan_ip_dst,
15183                 (void *)&cmd_set_vxlan_ip_dst_value,
15184                 (void *)&cmd_set_vxlan_vlan,
15185                 (void *)&cmd_set_vxlan_vlan_value,
15186                 (void *)&cmd_set_vxlan_eth_src,
15187                 (void *)&cmd_set_vxlan_eth_src_value,
15188                 (void *)&cmd_set_vxlan_eth_dst,
15189                 (void *)&cmd_set_vxlan_eth_dst_value,
15190                 NULL,
15191         },
15192 };
15193
15194 /** Set NVGRE encapsulation details */
15195 struct cmd_set_nvgre_result {
15196         cmdline_fixed_string_t set;
15197         cmdline_fixed_string_t nvgre;
15198         cmdline_fixed_string_t pos_token;
15199         cmdline_fixed_string_t ip_version;
15200         uint32_t tni;
15201         cmdline_ipaddr_t ip_src;
15202         cmdline_ipaddr_t ip_dst;
15203         uint16_t tci;
15204         struct ether_addr eth_src;
15205         struct ether_addr eth_dst;
15206 };
15207
15208 cmdline_parse_token_string_t cmd_set_nvgre_set =
15209         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15210 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15211         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15212 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15213         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15214                                  "nvgre-with-vlan");
15215 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15216         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15217                                  "ip-version");
15218 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15219         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15220                                  "ipv4#ipv6");
15221 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15222         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15223                                  "tni");
15224 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15225         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15226 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15227         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15228                                  "ip-src");
15229 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15230         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15231 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15232         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15233                                  "ip-dst");
15234 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15235         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15236 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15237         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15238                                  "vlan-tci");
15239 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15240         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15241 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15242         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15243                                  "eth-src");
15244 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15245         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15246 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15247         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15248                                  "eth-dst");
15249 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15250         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15251
15252 static void cmd_set_nvgre_parsed(void *parsed_result,
15253         __attribute__((unused)) struct cmdline *cl,
15254         __attribute__((unused)) void *data)
15255 {
15256         struct cmd_set_nvgre_result *res = parsed_result;
15257         union {
15258                 uint32_t nvgre_tni;
15259                 uint8_t tni[4];
15260         } id = {
15261                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15262         };
15263
15264         if (strcmp(res->nvgre, "nvgre") == 0)
15265                 nvgre_encap_conf.select_vlan = 0;
15266         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15267                 nvgre_encap_conf.select_vlan = 1;
15268         if (strcmp(res->ip_version, "ipv4") == 0)
15269                 nvgre_encap_conf.select_ipv4 = 1;
15270         else if (strcmp(res->ip_version, "ipv6") == 0)
15271                 nvgre_encap_conf.select_ipv4 = 0;
15272         else
15273                 return;
15274         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15275         if (nvgre_encap_conf.select_ipv4) {
15276                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15277                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15278         } else {
15279                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15280                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15281         }
15282         if (nvgre_encap_conf.select_vlan)
15283                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15284         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15285                    ETHER_ADDR_LEN);
15286         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15287                    ETHER_ADDR_LEN);
15288 }
15289
15290 cmdline_parse_inst_t cmd_set_nvgre = {
15291         .f = cmd_set_nvgre_parsed,
15292         .data = NULL,
15293         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15294                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15295                 " eth-dst <eth-dst>",
15296         .tokens = {
15297                 (void *)&cmd_set_nvgre_set,
15298                 (void *)&cmd_set_nvgre_nvgre,
15299                 (void *)&cmd_set_nvgre_ip_version,
15300                 (void *)&cmd_set_nvgre_ip_version_value,
15301                 (void *)&cmd_set_nvgre_tni,
15302                 (void *)&cmd_set_nvgre_tni_value,
15303                 (void *)&cmd_set_nvgre_ip_src,
15304                 (void *)&cmd_set_nvgre_ip_src_value,
15305                 (void *)&cmd_set_nvgre_ip_dst,
15306                 (void *)&cmd_set_nvgre_ip_dst_value,
15307                 (void *)&cmd_set_nvgre_eth_src,
15308                 (void *)&cmd_set_nvgre_eth_src_value,
15309                 (void *)&cmd_set_nvgre_eth_dst,
15310                 (void *)&cmd_set_nvgre_eth_dst_value,
15311                 NULL,
15312         },
15313 };
15314
15315 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15316         .f = cmd_set_nvgre_parsed,
15317         .data = NULL,
15318         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15319                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15320                 " eth-src <eth-src> eth-dst <eth-dst>",
15321         .tokens = {
15322                 (void *)&cmd_set_nvgre_set,
15323                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15324                 (void *)&cmd_set_nvgre_ip_version,
15325                 (void *)&cmd_set_nvgre_ip_version_value,
15326                 (void *)&cmd_set_nvgre_tni,
15327                 (void *)&cmd_set_nvgre_tni_value,
15328                 (void *)&cmd_set_nvgre_ip_src,
15329                 (void *)&cmd_set_nvgre_ip_src_value,
15330                 (void *)&cmd_set_nvgre_ip_dst,
15331                 (void *)&cmd_set_nvgre_ip_dst_value,
15332                 (void *)&cmd_set_nvgre_vlan,
15333                 (void *)&cmd_set_nvgre_vlan_value,
15334                 (void *)&cmd_set_nvgre_eth_src,
15335                 (void *)&cmd_set_nvgre_eth_src_value,
15336                 (void *)&cmd_set_nvgre_eth_dst,
15337                 (void *)&cmd_set_nvgre_eth_dst_value,
15338                 NULL,
15339         },
15340 };
15341
15342 /** Set L2 encapsulation details */
15343 struct cmd_set_l2_encap_result {
15344         cmdline_fixed_string_t set;
15345         cmdline_fixed_string_t l2_encap;
15346         cmdline_fixed_string_t pos_token;
15347         cmdline_fixed_string_t ip_version;
15348         uint32_t vlan_present:1;
15349         uint16_t tci;
15350         struct ether_addr eth_src;
15351         struct ether_addr eth_dst;
15352 };
15353
15354 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15355         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15356 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15357         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15358 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15359         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15360                                  "l2_encap-with-vlan");
15361 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15362         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15363                                  "ip-version");
15364 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15365         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15366                                  "ipv4#ipv6");
15367 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15368         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15369                                  "vlan-tci");
15370 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15371         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15372 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15373         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15374                                  "eth-src");
15375 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15376         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15377 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15378         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15379                                  "eth-dst");
15380 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15381         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15382
15383 static void cmd_set_l2_encap_parsed(void *parsed_result,
15384         __attribute__((unused)) struct cmdline *cl,
15385         __attribute__((unused)) void *data)
15386 {
15387         struct cmd_set_l2_encap_result *res = parsed_result;
15388
15389         if (strcmp(res->l2_encap, "l2_encap") == 0)
15390                 l2_encap_conf.select_vlan = 0;
15391         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15392                 l2_encap_conf.select_vlan = 1;
15393         if (strcmp(res->ip_version, "ipv4") == 0)
15394                 l2_encap_conf.select_ipv4 = 1;
15395         else if (strcmp(res->ip_version, "ipv6") == 0)
15396                 l2_encap_conf.select_ipv4 = 0;
15397         else
15398                 return;
15399         if (l2_encap_conf.select_vlan)
15400                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15401         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15402                    ETHER_ADDR_LEN);
15403         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15404                    ETHER_ADDR_LEN);
15405 }
15406
15407 cmdline_parse_inst_t cmd_set_l2_encap = {
15408         .f = cmd_set_l2_encap_parsed,
15409         .data = NULL,
15410         .help_str = "set l2_encap ip-version ipv4|ipv6"
15411                 " eth-src <eth-src> eth-dst <eth-dst>",
15412         .tokens = {
15413                 (void *)&cmd_set_l2_encap_set,
15414                 (void *)&cmd_set_l2_encap_l2_encap,
15415                 (void *)&cmd_set_l2_encap_ip_version,
15416                 (void *)&cmd_set_l2_encap_ip_version_value,
15417                 (void *)&cmd_set_l2_encap_eth_src,
15418                 (void *)&cmd_set_l2_encap_eth_src_value,
15419                 (void *)&cmd_set_l2_encap_eth_dst,
15420                 (void *)&cmd_set_l2_encap_eth_dst_value,
15421                 NULL,
15422         },
15423 };
15424
15425 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15426         .f = cmd_set_l2_encap_parsed,
15427         .data = NULL,
15428         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15429                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15430         .tokens = {
15431                 (void *)&cmd_set_l2_encap_set,
15432                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15433                 (void *)&cmd_set_l2_encap_ip_version,
15434                 (void *)&cmd_set_l2_encap_ip_version_value,
15435                 (void *)&cmd_set_l2_encap_vlan,
15436                 (void *)&cmd_set_l2_encap_vlan_value,
15437                 (void *)&cmd_set_l2_encap_eth_src,
15438                 (void *)&cmd_set_l2_encap_eth_src_value,
15439                 (void *)&cmd_set_l2_encap_eth_dst,
15440                 (void *)&cmd_set_l2_encap_eth_dst_value,
15441                 NULL,
15442         },
15443 };
15444
15445 /** Set L2 decapsulation details */
15446 struct cmd_set_l2_decap_result {
15447         cmdline_fixed_string_t set;
15448         cmdline_fixed_string_t l2_decap;
15449         cmdline_fixed_string_t pos_token;
15450         uint32_t vlan_present:1;
15451 };
15452
15453 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15454         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15455 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15457                                  "l2_decap");
15458 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15459         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15460                                  "l2_decap-with-vlan");
15461
15462 static void cmd_set_l2_decap_parsed(void *parsed_result,
15463         __attribute__((unused)) struct cmdline *cl,
15464         __attribute__((unused)) void *data)
15465 {
15466         struct cmd_set_l2_decap_result *res = parsed_result;
15467
15468         if (strcmp(res->l2_decap, "l2_decap") == 0)
15469                 l2_decap_conf.select_vlan = 0;
15470         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15471                 l2_decap_conf.select_vlan = 1;
15472 }
15473
15474 cmdline_parse_inst_t cmd_set_l2_decap = {
15475         .f = cmd_set_l2_decap_parsed,
15476         .data = NULL,
15477         .help_str = "set l2_decap",
15478         .tokens = {
15479                 (void *)&cmd_set_l2_decap_set,
15480                 (void *)&cmd_set_l2_decap_l2_decap,
15481                 NULL,
15482         },
15483 };
15484
15485 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15486         .f = cmd_set_l2_decap_parsed,
15487         .data = NULL,
15488         .help_str = "set l2_decap-with-vlan",
15489         .tokens = {
15490                 (void *)&cmd_set_l2_decap_set,
15491                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15492                 NULL,
15493         },
15494 };
15495
15496 /** Set MPLSoGRE encapsulation details */
15497 struct cmd_set_mplsogre_encap_result {
15498         cmdline_fixed_string_t set;
15499         cmdline_fixed_string_t mplsogre;
15500         cmdline_fixed_string_t pos_token;
15501         cmdline_fixed_string_t ip_version;
15502         uint32_t vlan_present:1;
15503         uint32_t label;
15504         cmdline_ipaddr_t ip_src;
15505         cmdline_ipaddr_t ip_dst;
15506         uint16_t tci;
15507         struct ether_addr eth_src;
15508         struct ether_addr eth_dst;
15509 };
15510
15511 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15512         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15513                                  "set");
15514 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15515         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15516                                  "mplsogre_encap");
15517 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15518         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15519                                  mplsogre, "mplsogre_encap-with-vlan");
15520 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15521         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15522                                  pos_token, "ip-version");
15523 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15524         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15525                                  ip_version, "ipv4#ipv6");
15526 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15527         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15528                                  pos_token, "label");
15529 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15530         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15531                               UINT32);
15532 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15533         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15534                                  pos_token, "ip-src");
15535 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15536         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15537 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15538         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15539                                  pos_token, "ip-dst");
15540 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15541         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15542 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15543         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15544                                  pos_token, "vlan-tci");
15545 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15546         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15547                               UINT16);
15548 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15549         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15550                                  pos_token, "eth-src");
15551 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15552         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15553                                     eth_src);
15554 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15555         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15556                                  pos_token, "eth-dst");
15557 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15558         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15559                                     eth_dst);
15560
15561 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15562         __attribute__((unused)) struct cmdline *cl,
15563         __attribute__((unused)) void *data)
15564 {
15565         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15566         union {
15567                 uint32_t mplsogre_label;
15568                 uint8_t label[3];
15569         } id = {
15570                 .mplsogre_label =
15571                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15572         };
15573
15574         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15575                 mplsogre_encap_conf.select_vlan = 0;
15576         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15577                 mplsogre_encap_conf.select_vlan = 1;
15578         if (strcmp(res->ip_version, "ipv4") == 0)
15579                 mplsogre_encap_conf.select_ipv4 = 1;
15580         else if (strcmp(res->ip_version, "ipv6") == 0)
15581                 mplsogre_encap_conf.select_ipv4 = 0;
15582         else
15583                 return;
15584         rte_memcpy(mplsogre_encap_conf.label, &id.label[1], 3);
15585         if (mplsogre_encap_conf.select_ipv4) {
15586                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15587                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15588         } else {
15589                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15590                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15591         }
15592         if (mplsogre_encap_conf.select_vlan)
15593                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15594         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15595                    ETHER_ADDR_LEN);
15596         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15597                    ETHER_ADDR_LEN);
15598 }
15599
15600 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15601         .f = cmd_set_mplsogre_encap_parsed,
15602         .data = NULL,
15603         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15604                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15605                 " eth-dst <eth-dst>",
15606         .tokens = {
15607                 (void *)&cmd_set_mplsogre_encap_set,
15608                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15609                 (void *)&cmd_set_mplsogre_encap_ip_version,
15610                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15611                 (void *)&cmd_set_mplsogre_encap_label,
15612                 (void *)&cmd_set_mplsogre_encap_label_value,
15613                 (void *)&cmd_set_mplsogre_encap_ip_src,
15614                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15615                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15616                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15617                 (void *)&cmd_set_mplsogre_encap_eth_src,
15618                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15619                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15620                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15621                 NULL,
15622         },
15623 };
15624
15625 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15626         .f = cmd_set_mplsogre_encap_parsed,
15627         .data = NULL,
15628         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15629                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15630                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15631         .tokens = {
15632                 (void *)&cmd_set_mplsogre_encap_set,
15633                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15634                 (void *)&cmd_set_mplsogre_encap_ip_version,
15635                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15636                 (void *)&cmd_set_mplsogre_encap_label,
15637                 (void *)&cmd_set_mplsogre_encap_label_value,
15638                 (void *)&cmd_set_mplsogre_encap_ip_src,
15639                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15640                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15641                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15642                 (void *)&cmd_set_mplsogre_encap_vlan,
15643                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15644                 (void *)&cmd_set_mplsogre_encap_eth_src,
15645                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15646                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15647                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15648                 NULL,
15649         },
15650 };
15651
15652 /** Set MPLSoGRE decapsulation details */
15653 struct cmd_set_mplsogre_decap_result {
15654         cmdline_fixed_string_t set;
15655         cmdline_fixed_string_t mplsogre;
15656         cmdline_fixed_string_t pos_token;
15657         cmdline_fixed_string_t ip_version;
15658         uint32_t vlan_present:1;
15659 };
15660
15661 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15662         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15663                                  "set");
15664 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15665         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15666                                  "mplsogre_decap");
15667 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15668         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15669                                  mplsogre, "mplsogre_decap-with-vlan");
15670 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15671         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15672                                  pos_token, "ip-version");
15673 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15674         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15675                                  ip_version, "ipv4#ipv6");
15676
15677 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15678         __attribute__((unused)) struct cmdline *cl,
15679         __attribute__((unused)) void *data)
15680 {
15681         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15682
15683         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15684                 mplsogre_decap_conf.select_vlan = 0;
15685         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15686                 mplsogre_decap_conf.select_vlan = 1;
15687         if (strcmp(res->ip_version, "ipv4") == 0)
15688                 mplsogre_decap_conf.select_ipv4 = 1;
15689         else if (strcmp(res->ip_version, "ipv6") == 0)
15690                 mplsogre_decap_conf.select_ipv4 = 0;
15691 }
15692
15693 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15694         .f = cmd_set_mplsogre_decap_parsed,
15695         .data = NULL,
15696         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15697         .tokens = {
15698                 (void *)&cmd_set_mplsogre_decap_set,
15699                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15700                 (void *)&cmd_set_mplsogre_decap_ip_version,
15701                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15702                 NULL,
15703         },
15704 };
15705
15706 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15707         .f = cmd_set_mplsogre_decap_parsed,
15708         .data = NULL,
15709         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15710         .tokens = {
15711                 (void *)&cmd_set_mplsogre_decap_set,
15712                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15713                 (void *)&cmd_set_mplsogre_decap_ip_version,
15714                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15715                 NULL,
15716         },
15717 };
15718
15719 /** Set MPLSoUDP encapsulation details */
15720 struct cmd_set_mplsoudp_encap_result {
15721         cmdline_fixed_string_t set;
15722         cmdline_fixed_string_t mplsoudp;
15723         cmdline_fixed_string_t pos_token;
15724         cmdline_fixed_string_t ip_version;
15725         uint32_t vlan_present:1;
15726         uint32_t label;
15727         uint16_t udp_src;
15728         uint16_t udp_dst;
15729         cmdline_ipaddr_t ip_src;
15730         cmdline_ipaddr_t ip_dst;
15731         uint16_t tci;
15732         struct ether_addr eth_src;
15733         struct ether_addr eth_dst;
15734 };
15735
15736 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15738                                  "set");
15739 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15741                                  "mplsoudp_encap");
15742 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15743         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15744                                  mplsoudp, "mplsoudp_encap-with-vlan");
15745 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15746         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15747                                  pos_token, "ip-version");
15748 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15749         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15750                                  ip_version, "ipv4#ipv6");
15751 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15752         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15753                                  pos_token, "label");
15754 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15755         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15756                               UINT32);
15757 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15758         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15759                                  pos_token, "udp-src");
15760 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15761         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15762                               UINT16);
15763 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15764         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15765                                  pos_token, "udp-dst");
15766 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15767         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15768                               UINT16);
15769 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15770         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15771                                  pos_token, "ip-src");
15772 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15773         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15774 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15775         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15776                                  pos_token, "ip-dst");
15777 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15778         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15779 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15780         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15781                                  pos_token, "vlan-tci");
15782 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15783         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15784                               UINT16);
15785 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15786         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15787                                  pos_token, "eth-src");
15788 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15789         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15790                                     eth_src);
15791 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
15792         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15793                                  pos_token, "eth-dst");
15794 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
15795         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15796                                     eth_dst);
15797
15798 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
15799         __attribute__((unused)) struct cmdline *cl,
15800         __attribute__((unused)) void *data)
15801 {
15802         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
15803         union {
15804                 uint32_t mplsoudp_label;
15805                 uint8_t label[3];
15806         } id = {
15807                 .mplsoudp_label =
15808                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15809         };
15810
15811         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
15812                 mplsoudp_encap_conf.select_vlan = 0;
15813         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
15814                 mplsoudp_encap_conf.select_vlan = 1;
15815         if (strcmp(res->ip_version, "ipv4") == 0)
15816                 mplsoudp_encap_conf.select_ipv4 = 1;
15817         else if (strcmp(res->ip_version, "ipv6") == 0)
15818                 mplsoudp_encap_conf.select_ipv4 = 0;
15819         else
15820                 return;
15821         rte_memcpy(mplsoudp_encap_conf.label, &id.label[1], 3);
15822         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15823         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15824         if (mplsoudp_encap_conf.select_ipv4) {
15825                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
15826                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
15827         } else {
15828                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
15829                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
15830         }
15831         if (mplsoudp_encap_conf.select_vlan)
15832                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15833         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
15834                    ETHER_ADDR_LEN);
15835         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15836                    ETHER_ADDR_LEN);
15837 }
15838
15839 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15840         .f = cmd_set_mplsoudp_encap_parsed,
15841         .data = NULL,
15842         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15843                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15844                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15845         .tokens = {
15846                 (void *)&cmd_set_mplsoudp_encap_set,
15847                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15848                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15849                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15850                 (void *)&cmd_set_mplsoudp_encap_label,
15851                 (void *)&cmd_set_mplsoudp_encap_label_value,
15852                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15853                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15854                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15855                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15856                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15857                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15858                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15859                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15860                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15861                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15862                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15863                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15864                 NULL,
15865         },
15866 };
15867
15868 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15869         .f = cmd_set_mplsoudp_encap_parsed,
15870         .data = NULL,
15871         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15872                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15873                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15874                 " eth-src <eth-src> eth-dst <eth-dst>",
15875         .tokens = {
15876                 (void *)&cmd_set_mplsoudp_encap_set,
15877                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15878                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15879                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15880                 (void *)&cmd_set_mplsoudp_encap_label,
15881                 (void *)&cmd_set_mplsoudp_encap_label_value,
15882                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15883                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15884                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15885                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15886                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15887                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15888                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15889                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15890                 (void *)&cmd_set_mplsoudp_encap_vlan,
15891                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
15892                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15893                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15894                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15895                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15896                 NULL,
15897         },
15898 };
15899
15900 /** Set MPLSoUDP decapsulation details */
15901 struct cmd_set_mplsoudp_decap_result {
15902         cmdline_fixed_string_t set;
15903         cmdline_fixed_string_t mplsoudp;
15904         cmdline_fixed_string_t pos_token;
15905         cmdline_fixed_string_t ip_version;
15906         uint32_t vlan_present:1;
15907 };
15908
15909 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15910         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15911                                  "set");
15912 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15913         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15914                                  "mplsoudp_decap");
15915 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15916         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15917                                  mplsoudp, "mplsoudp_decap-with-vlan");
15918 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15919         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15920                                  pos_token, "ip-version");
15921 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15922         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15923                                  ip_version, "ipv4#ipv6");
15924
15925 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15926         __attribute__((unused)) struct cmdline *cl,
15927         __attribute__((unused)) void *data)
15928 {
15929         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15930
15931         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15932                 mplsoudp_decap_conf.select_vlan = 0;
15933         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15934                 mplsoudp_decap_conf.select_vlan = 1;
15935         if (strcmp(res->ip_version, "ipv4") == 0)
15936                 mplsoudp_decap_conf.select_ipv4 = 1;
15937         else if (strcmp(res->ip_version, "ipv6") == 0)
15938                 mplsoudp_decap_conf.select_ipv4 = 0;
15939 }
15940
15941 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15942         .f = cmd_set_mplsoudp_decap_parsed,
15943         .data = NULL,
15944         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15945         .tokens = {
15946                 (void *)&cmd_set_mplsoudp_decap_set,
15947                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15948                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15949                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15950                 NULL,
15951         },
15952 };
15953
15954 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15955         .f = cmd_set_mplsoudp_decap_parsed,
15956         .data = NULL,
15957         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15958         .tokens = {
15959                 (void *)&cmd_set_mplsoudp_decap_set,
15960                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15961                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15962                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15963                 NULL,
15964         },
15965 };
15966
15967 /* Strict link priority scheduling mode setting */
15968 static void
15969 cmd_strict_link_prio_parsed(
15970         void *parsed_result,
15971         __attribute__((unused)) struct cmdline *cl,
15972         __attribute__((unused)) void *data)
15973 {
15974         struct cmd_vf_tc_bw_result *res = parsed_result;
15975         int ret = -ENOTSUP;
15976
15977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15978                 return;
15979
15980 #ifdef RTE_LIBRTE_I40E_PMD
15981         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15982 #endif
15983
15984         switch (ret) {
15985         case 0:
15986                 break;
15987         case -EINVAL:
15988                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15989                 break;
15990         case -ENODEV:
15991                 printf("invalid port_id %d\n", res->port_id);
15992                 break;
15993         case -ENOTSUP:
15994                 printf("function not implemented\n");
15995                 break;
15996         default:
15997                 printf("programming error: (%s)\n", strerror(-ret));
15998         }
15999 }
16000
16001 cmdline_parse_inst_t cmd_strict_link_prio = {
16002         .f = cmd_strict_link_prio_parsed,
16003         .data = NULL,
16004         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16005         .tokens = {
16006                 (void *)&cmd_vf_tc_bw_set,
16007                 (void *)&cmd_vf_tc_bw_tx,
16008                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16009                 (void *)&cmd_vf_tc_bw_port_id,
16010                 (void *)&cmd_vf_tc_bw_tc_map,
16011                 NULL,
16012         },
16013 };
16014
16015 /* Load dynamic device personalization*/
16016 struct cmd_ddp_add_result {
16017         cmdline_fixed_string_t ddp;
16018         cmdline_fixed_string_t add;
16019         portid_t port_id;
16020         char filepath[];
16021 };
16022
16023 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16024         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16025 cmdline_parse_token_string_t cmd_ddp_add_add =
16026         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16027 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16028         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16029 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16030         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16031
16032 static void
16033 cmd_ddp_add_parsed(
16034         void *parsed_result,
16035         __attribute__((unused)) struct cmdline *cl,
16036         __attribute__((unused)) void *data)
16037 {
16038         struct cmd_ddp_add_result *res = parsed_result;
16039         uint8_t *buff;
16040         uint32_t size;
16041         char *filepath;
16042         char *file_fld[2];
16043         int file_num;
16044         int ret = -ENOTSUP;
16045
16046         if (!all_ports_stopped()) {
16047                 printf("Please stop all ports first\n");
16048                 return;
16049         }
16050
16051         filepath = strdup(res->filepath);
16052         if (filepath == NULL) {
16053                 printf("Failed to allocate memory\n");
16054                 return;
16055         }
16056         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16057
16058         buff = open_file(file_fld[0], &size);
16059         if (!buff) {
16060                 free((void *)filepath);
16061                 return;
16062         }
16063
16064 #ifdef RTE_LIBRTE_I40E_PMD
16065         if (ret == -ENOTSUP)
16066                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16067                                                buff, size,
16068                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16069 #endif
16070
16071         if (ret == -EEXIST)
16072                 printf("Profile has already existed.\n");
16073         else if (ret < 0)
16074                 printf("Failed to load profile.\n");
16075         else if (file_num == 2)
16076                 save_file(file_fld[1], buff, size);
16077
16078         close_file(buff);
16079         free((void *)filepath);
16080 }
16081
16082 cmdline_parse_inst_t cmd_ddp_add = {
16083         .f = cmd_ddp_add_parsed,
16084         .data = NULL,
16085         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16086         .tokens = {
16087                 (void *)&cmd_ddp_add_ddp,
16088                 (void *)&cmd_ddp_add_add,
16089                 (void *)&cmd_ddp_add_port_id,
16090                 (void *)&cmd_ddp_add_filepath,
16091                 NULL,
16092         },
16093 };
16094
16095 /* Delete dynamic device personalization*/
16096 struct cmd_ddp_del_result {
16097         cmdline_fixed_string_t ddp;
16098         cmdline_fixed_string_t del;
16099         portid_t port_id;
16100         char filepath[];
16101 };
16102
16103 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16104         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16105 cmdline_parse_token_string_t cmd_ddp_del_del =
16106         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16107 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16108         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16109 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16110         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16111
16112 static void
16113 cmd_ddp_del_parsed(
16114         void *parsed_result,
16115         __attribute__((unused)) struct cmdline *cl,
16116         __attribute__((unused)) void *data)
16117 {
16118         struct cmd_ddp_del_result *res = parsed_result;
16119         uint8_t *buff;
16120         uint32_t size;
16121         int ret = -ENOTSUP;
16122
16123         if (!all_ports_stopped()) {
16124                 printf("Please stop all ports first\n");
16125                 return;
16126         }
16127
16128         buff = open_file(res->filepath, &size);
16129         if (!buff)
16130                 return;
16131
16132 #ifdef RTE_LIBRTE_I40E_PMD
16133         if (ret == -ENOTSUP)
16134                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16135                                                buff, size,
16136                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16137 #endif
16138
16139         if (ret == -EACCES)
16140                 printf("Profile does not exist.\n");
16141         else if (ret < 0)
16142                 printf("Failed to delete profile.\n");
16143
16144         close_file(buff);
16145 }
16146
16147 cmdline_parse_inst_t cmd_ddp_del = {
16148         .f = cmd_ddp_del_parsed,
16149         .data = NULL,
16150         .help_str = "ddp del <port_id> <backup_profile_path>",
16151         .tokens = {
16152                 (void *)&cmd_ddp_del_ddp,
16153                 (void *)&cmd_ddp_del_del,
16154                 (void *)&cmd_ddp_del_port_id,
16155                 (void *)&cmd_ddp_del_filepath,
16156                 NULL,
16157         },
16158 };
16159
16160 /* Get dynamic device personalization profile info */
16161 struct cmd_ddp_info_result {
16162         cmdline_fixed_string_t ddp;
16163         cmdline_fixed_string_t get;
16164         cmdline_fixed_string_t info;
16165         char filepath[];
16166 };
16167
16168 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16169         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16170 cmdline_parse_token_string_t cmd_ddp_info_get =
16171         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16172 cmdline_parse_token_string_t cmd_ddp_info_info =
16173         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16174 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16175         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16176
16177 static void
16178 cmd_ddp_info_parsed(
16179         void *parsed_result,
16180         __attribute__((unused)) struct cmdline *cl,
16181         __attribute__((unused)) void *data)
16182 {
16183         struct cmd_ddp_info_result *res = parsed_result;
16184         uint8_t *pkg;
16185         uint32_t pkg_size;
16186         int ret = -ENOTSUP;
16187 #ifdef RTE_LIBRTE_I40E_PMD
16188         uint32_t i, j, n;
16189         uint8_t *buff;
16190         uint32_t buff_size = 0;
16191         struct rte_pmd_i40e_profile_info info;
16192         uint32_t dev_num = 0;
16193         struct rte_pmd_i40e_ddp_device_id *devs;
16194         uint32_t proto_num = 0;
16195         struct rte_pmd_i40e_proto_info *proto = NULL;
16196         uint32_t pctype_num = 0;
16197         struct rte_pmd_i40e_ptype_info *pctype;
16198         uint32_t ptype_num = 0;
16199         struct rte_pmd_i40e_ptype_info *ptype;
16200         uint8_t proto_id;
16201
16202 #endif
16203
16204         pkg = open_file(res->filepath, &pkg_size);
16205         if (!pkg)
16206                 return;
16207
16208 #ifdef RTE_LIBRTE_I40E_PMD
16209         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16210                                 (uint8_t *)&info, sizeof(info),
16211                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16212         if (!ret) {
16213                 printf("Global Track id:       0x%x\n", info.track_id);
16214                 printf("Global Version:        %d.%d.%d.%d\n",
16215                         info.version.major,
16216                         info.version.minor,
16217                         info.version.update,
16218                         info.version.draft);
16219                 printf("Global Package name:   %s\n\n", info.name);
16220         }
16221
16222         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16223                                 (uint8_t *)&info, sizeof(info),
16224                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16225         if (!ret) {
16226                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16227                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16228                         info.version.major,
16229                         info.version.minor,
16230                         info.version.update,
16231                         info.version.draft);
16232                 printf("i40e Profile name:     %s\n\n", info.name);
16233         }
16234
16235         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16236                                 (uint8_t *)&buff_size, sizeof(buff_size),
16237                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16238         if (!ret && buff_size) {
16239                 buff = (uint8_t *)malloc(buff_size);
16240                 if (buff) {
16241                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16242                                                 buff, buff_size,
16243                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16244                         if (!ret)
16245                                 printf("Package Notes:\n%s\n\n", buff);
16246                         free(buff);
16247                 }
16248         }
16249
16250         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16251                                 (uint8_t *)&dev_num, sizeof(dev_num),
16252                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16253         if (!ret && dev_num) {
16254                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16255                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16256                 if (devs) {
16257                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16258                                                 (uint8_t *)devs, buff_size,
16259                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16260                         if (!ret) {
16261                                 printf("List of supported devices:\n");
16262                                 for (i = 0; i < dev_num; i++) {
16263                                         printf("  %04X:%04X %04X:%04X\n",
16264                                                 devs[i].vendor_dev_id >> 16,
16265                                                 devs[i].vendor_dev_id & 0xFFFF,
16266                                                 devs[i].sub_vendor_dev_id >> 16,
16267                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16268                                 }
16269                                 printf("\n");
16270                         }
16271                         free(devs);
16272                 }
16273         }
16274
16275         /* get information about protocols and packet types */
16276         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16277                 (uint8_t *)&proto_num, sizeof(proto_num),
16278                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16279         if (ret || !proto_num)
16280                 goto no_print_return;
16281
16282         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16283         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16284         if (!proto)
16285                 goto no_print_return;
16286
16287         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16288                                         buff_size,
16289                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16290         if (!ret) {
16291                 printf("List of used protocols:\n");
16292                 for (i = 0; i < proto_num; i++)
16293                         printf("  %2u: %s\n", proto[i].proto_id,
16294                                proto[i].name);
16295                 printf("\n");
16296         }
16297         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16298                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16299                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16300         if (ret || !pctype_num)
16301                 goto no_print_pctypes;
16302
16303         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16304         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16305         if (!pctype)
16306                 goto no_print_pctypes;
16307
16308         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16309                                         buff_size,
16310                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16311         if (ret) {
16312                 free(pctype);
16313                 goto no_print_pctypes;
16314         }
16315
16316         printf("List of defined packet classification types:\n");
16317         for (i = 0; i < pctype_num; i++) {
16318                 printf("  %2u:", pctype[i].ptype_id);
16319                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16320                         proto_id = pctype[i].protocols[j];
16321                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16322                                 for (n = 0; n < proto_num; n++) {
16323                                         if (proto[n].proto_id == proto_id) {
16324                                                 printf(" %s", proto[n].name);
16325                                                 break;
16326                                         }
16327                                 }
16328                         }
16329                 }
16330                 printf("\n");
16331         }
16332         printf("\n");
16333         free(pctype);
16334
16335 no_print_pctypes:
16336
16337         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16338                                         sizeof(ptype_num),
16339                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16340         if (ret || !ptype_num)
16341                 goto no_print_return;
16342
16343         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16344         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16345         if (!ptype)
16346                 goto no_print_return;
16347
16348         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16349                                         buff_size,
16350                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16351         if (ret) {
16352                 free(ptype);
16353                 goto no_print_return;
16354         }
16355         printf("List of defined packet types:\n");
16356         for (i = 0; i < ptype_num; i++) {
16357                 printf("  %2u:", ptype[i].ptype_id);
16358                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16359                         proto_id = ptype[i].protocols[j];
16360                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16361                                 for (n = 0; n < proto_num; n++) {
16362                                         if (proto[n].proto_id == proto_id) {
16363                                                 printf(" %s", proto[n].name);
16364                                                 break;
16365                                         }
16366                                 }
16367                         }
16368                 }
16369                 printf("\n");
16370         }
16371         free(ptype);
16372         printf("\n");
16373
16374         ret = 0;
16375 no_print_return:
16376         if (proto)
16377                 free(proto);
16378 #endif
16379         if (ret == -ENOTSUP)
16380                 printf("Function not supported in PMD driver\n");
16381         close_file(pkg);
16382 }
16383
16384 cmdline_parse_inst_t cmd_ddp_get_info = {
16385         .f = cmd_ddp_info_parsed,
16386         .data = NULL,
16387         .help_str = "ddp get info <profile_path>",
16388         .tokens = {
16389                 (void *)&cmd_ddp_info_ddp,
16390                 (void *)&cmd_ddp_info_get,
16391                 (void *)&cmd_ddp_info_info,
16392                 (void *)&cmd_ddp_info_filepath,
16393                 NULL,
16394         },
16395 };
16396
16397 /* Get dynamic device personalization profile info list*/
16398 #define PROFILE_INFO_SIZE 48
16399 #define MAX_PROFILE_NUM 16
16400
16401 struct cmd_ddp_get_list_result {
16402         cmdline_fixed_string_t ddp;
16403         cmdline_fixed_string_t get;
16404         cmdline_fixed_string_t list;
16405         portid_t port_id;
16406 };
16407
16408 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16409         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16410 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16411         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16412 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16413         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16414 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16415         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16416
16417 static void
16418 cmd_ddp_get_list_parsed(
16419         __attribute__((unused)) void *parsed_result,
16420         __attribute__((unused)) struct cmdline *cl,
16421         __attribute__((unused)) void *data)
16422 {
16423 #ifdef RTE_LIBRTE_I40E_PMD
16424         struct cmd_ddp_get_list_result *res = parsed_result;
16425         struct rte_pmd_i40e_profile_list *p_list;
16426         struct rte_pmd_i40e_profile_info *p_info;
16427         uint32_t p_num;
16428         uint32_t size;
16429         uint32_t i;
16430 #endif
16431         int ret = -ENOTSUP;
16432
16433 #ifdef RTE_LIBRTE_I40E_PMD
16434         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16435         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16436         if (!p_list)
16437                 printf("%s: Failed to malloc buffer\n", __func__);
16438
16439         if (ret == -ENOTSUP)
16440                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16441                                                 (uint8_t *)p_list, size);
16442
16443         if (!ret) {
16444                 p_num = p_list->p_count;
16445                 printf("Profile number is: %d\n\n", p_num);
16446
16447                 for (i = 0; i < p_num; i++) {
16448                         p_info = &p_list->p_info[i];
16449                         printf("Profile %d:\n", i);
16450                         printf("Track id:     0x%x\n", p_info->track_id);
16451                         printf("Version:      %d.%d.%d.%d\n",
16452                                p_info->version.major,
16453                                p_info->version.minor,
16454                                p_info->version.update,
16455                                p_info->version.draft);
16456                         printf("Profile name: %s\n\n", p_info->name);
16457                 }
16458         }
16459
16460         free(p_list);
16461 #endif
16462
16463         if (ret < 0)
16464                 printf("Failed to get ddp list\n");
16465 }
16466
16467 cmdline_parse_inst_t cmd_ddp_get_list = {
16468         .f = cmd_ddp_get_list_parsed,
16469         .data = NULL,
16470         .help_str = "ddp get list <port_id>",
16471         .tokens = {
16472                 (void *)&cmd_ddp_get_list_ddp,
16473                 (void *)&cmd_ddp_get_list_get,
16474                 (void *)&cmd_ddp_get_list_list,
16475                 (void *)&cmd_ddp_get_list_port_id,
16476                 NULL,
16477         },
16478 };
16479
16480 /* Configure input set */
16481 struct cmd_cfg_input_set_result {
16482         cmdline_fixed_string_t port;
16483         cmdline_fixed_string_t cfg;
16484         portid_t port_id;
16485         cmdline_fixed_string_t pctype;
16486         uint8_t pctype_id;
16487         cmdline_fixed_string_t inset_type;
16488         cmdline_fixed_string_t opt;
16489         cmdline_fixed_string_t field;
16490         uint8_t field_idx;
16491 };
16492
16493 static void
16494 cmd_cfg_input_set_parsed(
16495         __attribute__((unused)) void *parsed_result,
16496         __attribute__((unused)) struct cmdline *cl,
16497         __attribute__((unused)) void *data)
16498 {
16499 #ifdef RTE_LIBRTE_I40E_PMD
16500         struct cmd_cfg_input_set_result *res = parsed_result;
16501         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16502         struct rte_pmd_i40e_inset inset;
16503 #endif
16504         int ret = -ENOTSUP;
16505
16506         if (!all_ports_stopped()) {
16507                 printf("Please stop all ports first\n");
16508                 return;
16509         }
16510
16511 #ifdef RTE_LIBRTE_I40E_PMD
16512         if (!strcmp(res->inset_type, "hash_inset"))
16513                 inset_type = INSET_HASH;
16514         else if (!strcmp(res->inset_type, "fdir_inset"))
16515                 inset_type = INSET_FDIR;
16516         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16517                 inset_type = INSET_FDIR_FLX;
16518         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16519                                      &inset, inset_type);
16520         if (ret) {
16521                 printf("Failed to get input set.\n");
16522                 return;
16523         }
16524
16525         if (!strcmp(res->opt, "get")) {
16526                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16527                                                    res->field_idx);
16528                 if (ret)
16529                         printf("Field index %d is enabled.\n", res->field_idx);
16530                 else
16531                         printf("Field index %d is disabled.\n", res->field_idx);
16532                 return;
16533         } else if (!strcmp(res->opt, "set"))
16534                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16535                                                    res->field_idx);
16536         else if (!strcmp(res->opt, "clear"))
16537                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16538                                                      res->field_idx);
16539         if (ret) {
16540                 printf("Failed to configure input set field.\n");
16541                 return;
16542         }
16543
16544         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16545                                      &inset, inset_type);
16546         if (ret) {
16547                 printf("Failed to set input set.\n");
16548                 return;
16549         }
16550 #endif
16551
16552         if (ret == -ENOTSUP)
16553                 printf("Function not supported\n");
16554 }
16555
16556 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16557         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16558                                  port, "port");
16559 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16560         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16561                                  cfg, "config");
16562 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16563         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16564                               port_id, UINT16);
16565 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16566         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16567                                  pctype, "pctype");
16568 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16569         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16570                               pctype_id, UINT8);
16571 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16572         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16573                                  inset_type,
16574                                  "hash_inset#fdir_inset#fdir_flx_inset");
16575 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16576         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16577                                  opt, "get#set#clear");
16578 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16579         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16580                                  field, "field");
16581 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16582         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16583                               field_idx, UINT8);
16584
16585 cmdline_parse_inst_t cmd_cfg_input_set = {
16586         .f = cmd_cfg_input_set_parsed,
16587         .data = NULL,
16588         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16589                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16590         .tokens = {
16591                 (void *)&cmd_cfg_input_set_port,
16592                 (void *)&cmd_cfg_input_set_cfg,
16593                 (void *)&cmd_cfg_input_set_port_id,
16594                 (void *)&cmd_cfg_input_set_pctype,
16595                 (void *)&cmd_cfg_input_set_pctype_id,
16596                 (void *)&cmd_cfg_input_set_inset_type,
16597                 (void *)&cmd_cfg_input_set_opt,
16598                 (void *)&cmd_cfg_input_set_field,
16599                 (void *)&cmd_cfg_input_set_field_idx,
16600                 NULL,
16601         },
16602 };
16603
16604 /* Clear input set */
16605 struct cmd_clear_input_set_result {
16606         cmdline_fixed_string_t port;
16607         cmdline_fixed_string_t cfg;
16608         portid_t port_id;
16609         cmdline_fixed_string_t pctype;
16610         uint8_t pctype_id;
16611         cmdline_fixed_string_t inset_type;
16612         cmdline_fixed_string_t clear;
16613         cmdline_fixed_string_t all;
16614 };
16615
16616 static void
16617 cmd_clear_input_set_parsed(
16618         __attribute__((unused)) void *parsed_result,
16619         __attribute__((unused)) struct cmdline *cl,
16620         __attribute__((unused)) void *data)
16621 {
16622 #ifdef RTE_LIBRTE_I40E_PMD
16623         struct cmd_clear_input_set_result *res = parsed_result;
16624         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16625         struct rte_pmd_i40e_inset inset;
16626 #endif
16627         int ret = -ENOTSUP;
16628
16629         if (!all_ports_stopped()) {
16630                 printf("Please stop all ports first\n");
16631                 return;
16632         }
16633
16634 #ifdef RTE_LIBRTE_I40E_PMD
16635         if (!strcmp(res->inset_type, "hash_inset"))
16636                 inset_type = INSET_HASH;
16637         else if (!strcmp(res->inset_type, "fdir_inset"))
16638                 inset_type = INSET_FDIR;
16639         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16640                 inset_type = INSET_FDIR_FLX;
16641
16642         memset(&inset, 0, sizeof(inset));
16643
16644         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16645                                      &inset, inset_type);
16646         if (ret) {
16647                 printf("Failed to clear input set.\n");
16648                 return;
16649         }
16650
16651 #endif
16652
16653         if (ret == -ENOTSUP)
16654                 printf("Function not supported\n");
16655 }
16656
16657 cmdline_parse_token_string_t cmd_clear_input_set_port =
16658         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16659                                  port, "port");
16660 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16661         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16662                                  cfg, "config");
16663 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16664         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16665                               port_id, UINT16);
16666 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16667         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16668                                  pctype, "pctype");
16669 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16670         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16671                               pctype_id, UINT8);
16672 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16673         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16674                                  inset_type,
16675                                  "hash_inset#fdir_inset#fdir_flx_inset");
16676 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16677         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16678                                  clear, "clear");
16679 cmdline_parse_token_string_t cmd_clear_input_set_all =
16680         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16681                                  all, "all");
16682
16683 cmdline_parse_inst_t cmd_clear_input_set = {
16684         .f = cmd_clear_input_set_parsed,
16685         .data = NULL,
16686         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16687                     "fdir_inset|fdir_flx_inset clear all",
16688         .tokens = {
16689                 (void *)&cmd_clear_input_set_port,
16690                 (void *)&cmd_clear_input_set_cfg,
16691                 (void *)&cmd_clear_input_set_port_id,
16692                 (void *)&cmd_clear_input_set_pctype,
16693                 (void *)&cmd_clear_input_set_pctype_id,
16694                 (void *)&cmd_clear_input_set_inset_type,
16695                 (void *)&cmd_clear_input_set_clear,
16696                 (void *)&cmd_clear_input_set_all,
16697                 NULL,
16698         },
16699 };
16700
16701 /* show vf stats */
16702
16703 /* Common result structure for show vf stats */
16704 struct cmd_show_vf_stats_result {
16705         cmdline_fixed_string_t show;
16706         cmdline_fixed_string_t vf;
16707         cmdline_fixed_string_t stats;
16708         portid_t port_id;
16709         uint16_t vf_id;
16710 };
16711
16712 /* Common CLI fields show vf stats*/
16713 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16714         TOKEN_STRING_INITIALIZER
16715                 (struct cmd_show_vf_stats_result,
16716                  show, "show");
16717 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16718         TOKEN_STRING_INITIALIZER
16719                 (struct cmd_show_vf_stats_result,
16720                  vf, "vf");
16721 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16722         TOKEN_STRING_INITIALIZER
16723                 (struct cmd_show_vf_stats_result,
16724                  stats, "stats");
16725 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16726         TOKEN_NUM_INITIALIZER
16727                 (struct cmd_show_vf_stats_result,
16728                  port_id, UINT16);
16729 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16730         TOKEN_NUM_INITIALIZER
16731                 (struct cmd_show_vf_stats_result,
16732                  vf_id, UINT16);
16733
16734 static void
16735 cmd_show_vf_stats_parsed(
16736         void *parsed_result,
16737         __attribute__((unused)) struct cmdline *cl,
16738         __attribute__((unused)) void *data)
16739 {
16740         struct cmd_show_vf_stats_result *res = parsed_result;
16741         struct rte_eth_stats stats;
16742         int ret = -ENOTSUP;
16743         static const char *nic_stats_border = "########################";
16744
16745         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16746                 return;
16747
16748         memset(&stats, 0, sizeof(stats));
16749
16750 #ifdef RTE_LIBRTE_I40E_PMD
16751         if (ret == -ENOTSUP)
16752                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16753                                                 res->vf_id,
16754                                                 &stats);
16755 #endif
16756 #ifdef RTE_LIBRTE_BNXT_PMD
16757         if (ret == -ENOTSUP)
16758                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16759                                                 res->vf_id,
16760                                                 &stats);
16761 #endif
16762
16763         switch (ret) {
16764         case 0:
16765                 break;
16766         case -EINVAL:
16767                 printf("invalid vf_id %d\n", res->vf_id);
16768                 break;
16769         case -ENODEV:
16770                 printf("invalid port_id %d\n", res->port_id);
16771                 break;
16772         case -ENOTSUP:
16773                 printf("function not implemented\n");
16774                 break;
16775         default:
16776                 printf("programming error: (%s)\n", strerror(-ret));
16777         }
16778
16779         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16780                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16781
16782         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16783                "%-"PRIu64"\n",
16784                stats.ipackets, stats.imissed, stats.ibytes);
16785         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16786         printf("  RX-nombuf:  %-10"PRIu64"\n",
16787                stats.rx_nombuf);
16788         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16789                "%-"PRIu64"\n",
16790                stats.opackets, stats.oerrors, stats.obytes);
16791
16792         printf("  %s############################%s\n",
16793                                nic_stats_border, nic_stats_border);
16794 }
16795
16796 cmdline_parse_inst_t cmd_show_vf_stats = {
16797         .f = cmd_show_vf_stats_parsed,
16798         .data = NULL,
16799         .help_str = "show vf stats <port_id> <vf_id>",
16800         .tokens = {
16801                 (void *)&cmd_show_vf_stats_show,
16802                 (void *)&cmd_show_vf_stats_vf,
16803                 (void *)&cmd_show_vf_stats_stats,
16804                 (void *)&cmd_show_vf_stats_port_id,
16805                 (void *)&cmd_show_vf_stats_vf_id,
16806                 NULL,
16807         },
16808 };
16809
16810 /* clear vf stats */
16811
16812 /* Common result structure for clear vf stats */
16813 struct cmd_clear_vf_stats_result {
16814         cmdline_fixed_string_t clear;
16815         cmdline_fixed_string_t vf;
16816         cmdline_fixed_string_t stats;
16817         portid_t port_id;
16818         uint16_t vf_id;
16819 };
16820
16821 /* Common CLI fields clear vf stats*/
16822 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16823         TOKEN_STRING_INITIALIZER
16824                 (struct cmd_clear_vf_stats_result,
16825                  clear, "clear");
16826 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16827         TOKEN_STRING_INITIALIZER
16828                 (struct cmd_clear_vf_stats_result,
16829                  vf, "vf");
16830 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16831         TOKEN_STRING_INITIALIZER
16832                 (struct cmd_clear_vf_stats_result,
16833                  stats, "stats");
16834 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16835         TOKEN_NUM_INITIALIZER
16836                 (struct cmd_clear_vf_stats_result,
16837                  port_id, UINT16);
16838 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16839         TOKEN_NUM_INITIALIZER
16840                 (struct cmd_clear_vf_stats_result,
16841                  vf_id, UINT16);
16842
16843 static void
16844 cmd_clear_vf_stats_parsed(
16845         void *parsed_result,
16846         __attribute__((unused)) struct cmdline *cl,
16847         __attribute__((unused)) void *data)
16848 {
16849         struct cmd_clear_vf_stats_result *res = parsed_result;
16850         int ret = -ENOTSUP;
16851
16852         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16853                 return;
16854
16855 #ifdef RTE_LIBRTE_I40E_PMD
16856         if (ret == -ENOTSUP)
16857                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16858                                                   res->vf_id);
16859 #endif
16860 #ifdef RTE_LIBRTE_BNXT_PMD
16861         if (ret == -ENOTSUP)
16862                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16863                                                   res->vf_id);
16864 #endif
16865
16866         switch (ret) {
16867         case 0:
16868                 break;
16869         case -EINVAL:
16870                 printf("invalid vf_id %d\n", res->vf_id);
16871                 break;
16872         case -ENODEV:
16873                 printf("invalid port_id %d\n", res->port_id);
16874                 break;
16875         case -ENOTSUP:
16876                 printf("function not implemented\n");
16877                 break;
16878         default:
16879                 printf("programming error: (%s)\n", strerror(-ret));
16880         }
16881 }
16882
16883 cmdline_parse_inst_t cmd_clear_vf_stats = {
16884         .f = cmd_clear_vf_stats_parsed,
16885         .data = NULL,
16886         .help_str = "clear vf stats <port_id> <vf_id>",
16887         .tokens = {
16888                 (void *)&cmd_clear_vf_stats_clear,
16889                 (void *)&cmd_clear_vf_stats_vf,
16890                 (void *)&cmd_clear_vf_stats_stats,
16891                 (void *)&cmd_clear_vf_stats_port_id,
16892                 (void *)&cmd_clear_vf_stats_vf_id,
16893                 NULL,
16894         },
16895 };
16896
16897 /* port config pctype mapping reset */
16898
16899 /* Common result structure for port config pctype mapping reset */
16900 struct cmd_pctype_mapping_reset_result {
16901         cmdline_fixed_string_t port;
16902         cmdline_fixed_string_t config;
16903         portid_t port_id;
16904         cmdline_fixed_string_t pctype;
16905         cmdline_fixed_string_t mapping;
16906         cmdline_fixed_string_t reset;
16907 };
16908
16909 /* Common CLI fields for port config pctype mapping reset*/
16910 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16911         TOKEN_STRING_INITIALIZER
16912                 (struct cmd_pctype_mapping_reset_result,
16913                  port, "port");
16914 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16915         TOKEN_STRING_INITIALIZER
16916                 (struct cmd_pctype_mapping_reset_result,
16917                  config, "config");
16918 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16919         TOKEN_NUM_INITIALIZER
16920                 (struct cmd_pctype_mapping_reset_result,
16921                  port_id, UINT16);
16922 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16923         TOKEN_STRING_INITIALIZER
16924                 (struct cmd_pctype_mapping_reset_result,
16925                  pctype, "pctype");
16926 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16927         TOKEN_STRING_INITIALIZER
16928                 (struct cmd_pctype_mapping_reset_result,
16929                  mapping, "mapping");
16930 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16931         TOKEN_STRING_INITIALIZER
16932                 (struct cmd_pctype_mapping_reset_result,
16933                  reset, "reset");
16934
16935 static void
16936 cmd_pctype_mapping_reset_parsed(
16937         void *parsed_result,
16938         __attribute__((unused)) struct cmdline *cl,
16939         __attribute__((unused)) void *data)
16940 {
16941         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16942         int ret = -ENOTSUP;
16943
16944         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16945                 return;
16946
16947 #ifdef RTE_LIBRTE_I40E_PMD
16948         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16949 #endif
16950
16951         switch (ret) {
16952         case 0:
16953                 break;
16954         case -ENODEV:
16955                 printf("invalid port_id %d\n", res->port_id);
16956                 break;
16957         case -ENOTSUP:
16958                 printf("function not implemented\n");
16959                 break;
16960         default:
16961                 printf("programming error: (%s)\n", strerror(-ret));
16962         }
16963 }
16964
16965 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16966         .f = cmd_pctype_mapping_reset_parsed,
16967         .data = NULL,
16968         .help_str = "port config <port_id> pctype mapping reset",
16969         .tokens = {
16970                 (void *)&cmd_pctype_mapping_reset_port,
16971                 (void *)&cmd_pctype_mapping_reset_config,
16972                 (void *)&cmd_pctype_mapping_reset_port_id,
16973                 (void *)&cmd_pctype_mapping_reset_pctype,
16974                 (void *)&cmd_pctype_mapping_reset_mapping,
16975                 (void *)&cmd_pctype_mapping_reset_reset,
16976                 NULL,
16977         },
16978 };
16979
16980 /* show port pctype mapping */
16981
16982 /* Common result structure for show port pctype mapping */
16983 struct cmd_pctype_mapping_get_result {
16984         cmdline_fixed_string_t show;
16985         cmdline_fixed_string_t port;
16986         portid_t port_id;
16987         cmdline_fixed_string_t pctype;
16988         cmdline_fixed_string_t mapping;
16989 };
16990
16991 /* Common CLI fields for pctype mapping get */
16992 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16993         TOKEN_STRING_INITIALIZER
16994                 (struct cmd_pctype_mapping_get_result,
16995                  show, "show");
16996 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16997         TOKEN_STRING_INITIALIZER
16998                 (struct cmd_pctype_mapping_get_result,
16999                  port, "port");
17000 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17001         TOKEN_NUM_INITIALIZER
17002                 (struct cmd_pctype_mapping_get_result,
17003                  port_id, UINT16);
17004 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17005         TOKEN_STRING_INITIALIZER
17006                 (struct cmd_pctype_mapping_get_result,
17007                  pctype, "pctype");
17008 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17009         TOKEN_STRING_INITIALIZER
17010                 (struct cmd_pctype_mapping_get_result,
17011                  mapping, "mapping");
17012
17013 static void
17014 cmd_pctype_mapping_get_parsed(
17015         void *parsed_result,
17016         __attribute__((unused)) struct cmdline *cl,
17017         __attribute__((unused)) void *data)
17018 {
17019         struct cmd_pctype_mapping_get_result *res = parsed_result;
17020         int ret = -ENOTSUP;
17021 #ifdef RTE_LIBRTE_I40E_PMD
17022         struct rte_pmd_i40e_flow_type_mapping
17023                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17024         int i, j, first_pctype;
17025 #endif
17026
17027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17028                 return;
17029
17030 #ifdef RTE_LIBRTE_I40E_PMD
17031         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17032 #endif
17033
17034         switch (ret) {
17035         case 0:
17036                 break;
17037         case -ENODEV:
17038                 printf("invalid port_id %d\n", res->port_id);
17039                 return;
17040         case -ENOTSUP:
17041                 printf("function not implemented\n");
17042                 return;
17043         default:
17044                 printf("programming error: (%s)\n", strerror(-ret));
17045                 return;
17046         }
17047
17048 #ifdef RTE_LIBRTE_I40E_PMD
17049         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17050                 if (mapping[i].pctype != 0ULL) {
17051                         first_pctype = 1;
17052
17053                         printf("pctype: ");
17054                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17055                                 if (mapping[i].pctype & (1ULL << j)) {
17056                                         printf(first_pctype ?
17057                                                "%02d" : ",%02d", j);
17058                                         first_pctype = 0;
17059                                 }
17060                         }
17061                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17062                 }
17063         }
17064 #endif
17065 }
17066
17067 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17068         .f = cmd_pctype_mapping_get_parsed,
17069         .data = NULL,
17070         .help_str = "show port <port_id> pctype mapping",
17071         .tokens = {
17072                 (void *)&cmd_pctype_mapping_get_show,
17073                 (void *)&cmd_pctype_mapping_get_port,
17074                 (void *)&cmd_pctype_mapping_get_port_id,
17075                 (void *)&cmd_pctype_mapping_get_pctype,
17076                 (void *)&cmd_pctype_mapping_get_mapping,
17077                 NULL,
17078         },
17079 };
17080
17081 /* port config pctype mapping update */
17082
17083 /* Common result structure for port config pctype mapping update */
17084 struct cmd_pctype_mapping_update_result {
17085         cmdline_fixed_string_t port;
17086         cmdline_fixed_string_t config;
17087         portid_t port_id;
17088         cmdline_fixed_string_t pctype;
17089         cmdline_fixed_string_t mapping;
17090         cmdline_fixed_string_t update;
17091         cmdline_fixed_string_t pctype_list;
17092         uint16_t flow_type;
17093 };
17094
17095 /* Common CLI fields for pctype mapping update*/
17096 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17097         TOKEN_STRING_INITIALIZER
17098                 (struct cmd_pctype_mapping_update_result,
17099                  port, "port");
17100 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17101         TOKEN_STRING_INITIALIZER
17102                 (struct cmd_pctype_mapping_update_result,
17103                  config, "config");
17104 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17105         TOKEN_NUM_INITIALIZER
17106                 (struct cmd_pctype_mapping_update_result,
17107                  port_id, UINT16);
17108 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17109         TOKEN_STRING_INITIALIZER
17110                 (struct cmd_pctype_mapping_update_result,
17111                  pctype, "pctype");
17112 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17113         TOKEN_STRING_INITIALIZER
17114                 (struct cmd_pctype_mapping_update_result,
17115                  mapping, "mapping");
17116 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17117         TOKEN_STRING_INITIALIZER
17118                 (struct cmd_pctype_mapping_update_result,
17119                  update, "update");
17120 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17121         TOKEN_STRING_INITIALIZER
17122                 (struct cmd_pctype_mapping_update_result,
17123                  pctype_list, NULL);
17124 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17125         TOKEN_NUM_INITIALIZER
17126                 (struct cmd_pctype_mapping_update_result,
17127                  flow_type, UINT16);
17128
17129 static void
17130 cmd_pctype_mapping_update_parsed(
17131         void *parsed_result,
17132         __attribute__((unused)) struct cmdline *cl,
17133         __attribute__((unused)) void *data)
17134 {
17135         struct cmd_pctype_mapping_update_result *res = parsed_result;
17136         int ret = -ENOTSUP;
17137 #ifdef RTE_LIBRTE_I40E_PMD
17138         struct rte_pmd_i40e_flow_type_mapping mapping;
17139         unsigned int i;
17140         unsigned int nb_item;
17141         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17142 #endif
17143
17144         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17145                 return;
17146
17147 #ifdef RTE_LIBRTE_I40E_PMD
17148         nb_item = parse_item_list(res->pctype_list, "pctypes",
17149                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17150         mapping.flow_type = res->flow_type;
17151         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17152                 mapping.pctype |= (1ULL << pctype_list[i]);
17153         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17154                                                 &mapping,
17155                                                 1,
17156                                                 0);
17157 #endif
17158
17159         switch (ret) {
17160         case 0:
17161                 break;
17162         case -EINVAL:
17163                 printf("invalid pctype or flow type\n");
17164                 break;
17165         case -ENODEV:
17166                 printf("invalid port_id %d\n", res->port_id);
17167                 break;
17168         case -ENOTSUP:
17169                 printf("function not implemented\n");
17170                 break;
17171         default:
17172                 printf("programming error: (%s)\n", strerror(-ret));
17173         }
17174 }
17175
17176 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17177         .f = cmd_pctype_mapping_update_parsed,
17178         .data = NULL,
17179         .help_str = "port config <port_id> pctype mapping update"
17180         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17181         .tokens = {
17182                 (void *)&cmd_pctype_mapping_update_port,
17183                 (void *)&cmd_pctype_mapping_update_config,
17184                 (void *)&cmd_pctype_mapping_update_port_id,
17185                 (void *)&cmd_pctype_mapping_update_pctype,
17186                 (void *)&cmd_pctype_mapping_update_mapping,
17187                 (void *)&cmd_pctype_mapping_update_update,
17188                 (void *)&cmd_pctype_mapping_update_pc_type,
17189                 (void *)&cmd_pctype_mapping_update_flow_type,
17190                 NULL,
17191         },
17192 };
17193
17194 /* ptype mapping get */
17195
17196 /* Common result structure for ptype mapping get */
17197 struct cmd_ptype_mapping_get_result {
17198         cmdline_fixed_string_t ptype;
17199         cmdline_fixed_string_t mapping;
17200         cmdline_fixed_string_t get;
17201         portid_t port_id;
17202         uint8_t valid_only;
17203 };
17204
17205 /* Common CLI fields for ptype mapping get */
17206 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17207         TOKEN_STRING_INITIALIZER
17208                 (struct cmd_ptype_mapping_get_result,
17209                  ptype, "ptype");
17210 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_ptype_mapping_get_result,
17213                  mapping, "mapping");
17214 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17215         TOKEN_STRING_INITIALIZER
17216                 (struct cmd_ptype_mapping_get_result,
17217                  get, "get");
17218 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17219         TOKEN_NUM_INITIALIZER
17220                 (struct cmd_ptype_mapping_get_result,
17221                  port_id, UINT16);
17222 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17223         TOKEN_NUM_INITIALIZER
17224                 (struct cmd_ptype_mapping_get_result,
17225                  valid_only, UINT8);
17226
17227 static void
17228 cmd_ptype_mapping_get_parsed(
17229         void *parsed_result,
17230         __attribute__((unused)) struct cmdline *cl,
17231         __attribute__((unused)) void *data)
17232 {
17233         struct cmd_ptype_mapping_get_result *res = parsed_result;
17234         int ret = -ENOTSUP;
17235 #ifdef RTE_LIBRTE_I40E_PMD
17236         int max_ptype_num = 256;
17237         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17238         uint16_t count;
17239         int i;
17240 #endif
17241
17242         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17243                 return;
17244
17245 #ifdef RTE_LIBRTE_I40E_PMD
17246         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17247                                         mapping,
17248                                         max_ptype_num,
17249                                         &count,
17250                                         res->valid_only);
17251 #endif
17252
17253         switch (ret) {
17254         case 0:
17255                 break;
17256         case -ENODEV:
17257                 printf("invalid port_id %d\n", res->port_id);
17258                 break;
17259         case -ENOTSUP:
17260                 printf("function not implemented\n");
17261                 break;
17262         default:
17263                 printf("programming error: (%s)\n", strerror(-ret));
17264         }
17265
17266 #ifdef RTE_LIBRTE_I40E_PMD
17267         if (!ret) {
17268                 for (i = 0; i < count; i++)
17269                         printf("%3d\t0x%08x\n",
17270                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17271         }
17272 #endif
17273 }
17274
17275 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17276         .f = cmd_ptype_mapping_get_parsed,
17277         .data = NULL,
17278         .help_str = "ptype mapping get <port_id> <valid_only>",
17279         .tokens = {
17280                 (void *)&cmd_ptype_mapping_get_ptype,
17281                 (void *)&cmd_ptype_mapping_get_mapping,
17282                 (void *)&cmd_ptype_mapping_get_get,
17283                 (void *)&cmd_ptype_mapping_get_port_id,
17284                 (void *)&cmd_ptype_mapping_get_valid_only,
17285                 NULL,
17286         },
17287 };
17288
17289 /* ptype mapping replace */
17290
17291 /* Common result structure for ptype mapping replace */
17292 struct cmd_ptype_mapping_replace_result {
17293         cmdline_fixed_string_t ptype;
17294         cmdline_fixed_string_t mapping;
17295         cmdline_fixed_string_t replace;
17296         portid_t port_id;
17297         uint32_t target;
17298         uint8_t mask;
17299         uint32_t pkt_type;
17300 };
17301
17302 /* Common CLI fields for ptype mapping replace */
17303 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17304         TOKEN_STRING_INITIALIZER
17305                 (struct cmd_ptype_mapping_replace_result,
17306                  ptype, "ptype");
17307 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17308         TOKEN_STRING_INITIALIZER
17309                 (struct cmd_ptype_mapping_replace_result,
17310                  mapping, "mapping");
17311 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17312         TOKEN_STRING_INITIALIZER
17313                 (struct cmd_ptype_mapping_replace_result,
17314                  replace, "replace");
17315 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17316         TOKEN_NUM_INITIALIZER
17317                 (struct cmd_ptype_mapping_replace_result,
17318                  port_id, UINT16);
17319 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17320         TOKEN_NUM_INITIALIZER
17321                 (struct cmd_ptype_mapping_replace_result,
17322                  target, UINT32);
17323 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17324         TOKEN_NUM_INITIALIZER
17325                 (struct cmd_ptype_mapping_replace_result,
17326                  mask, UINT8);
17327 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17328         TOKEN_NUM_INITIALIZER
17329                 (struct cmd_ptype_mapping_replace_result,
17330                  pkt_type, UINT32);
17331
17332 static void
17333 cmd_ptype_mapping_replace_parsed(
17334         void *parsed_result,
17335         __attribute__((unused)) struct cmdline *cl,
17336         __attribute__((unused)) void *data)
17337 {
17338         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17339         int ret = -ENOTSUP;
17340
17341         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17342                 return;
17343
17344 #ifdef RTE_LIBRTE_I40E_PMD
17345         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17346                                         res->target,
17347                                         res->mask,
17348                                         res->pkt_type);
17349 #endif
17350
17351         switch (ret) {
17352         case 0:
17353                 break;
17354         case -EINVAL:
17355                 printf("invalid ptype 0x%8x or 0x%8x\n",
17356                                 res->target, res->pkt_type);
17357                 break;
17358         case -ENODEV:
17359                 printf("invalid port_id %d\n", res->port_id);
17360                 break;
17361         case -ENOTSUP:
17362                 printf("function not implemented\n");
17363                 break;
17364         default:
17365                 printf("programming error: (%s)\n", strerror(-ret));
17366         }
17367 }
17368
17369 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17370         .f = cmd_ptype_mapping_replace_parsed,
17371         .data = NULL,
17372         .help_str =
17373                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17374         .tokens = {
17375                 (void *)&cmd_ptype_mapping_replace_ptype,
17376                 (void *)&cmd_ptype_mapping_replace_mapping,
17377                 (void *)&cmd_ptype_mapping_replace_replace,
17378                 (void *)&cmd_ptype_mapping_replace_port_id,
17379                 (void *)&cmd_ptype_mapping_replace_target,
17380                 (void *)&cmd_ptype_mapping_replace_mask,
17381                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17382                 NULL,
17383         },
17384 };
17385
17386 /* ptype mapping reset */
17387
17388 /* Common result structure for ptype mapping reset */
17389 struct cmd_ptype_mapping_reset_result {
17390         cmdline_fixed_string_t ptype;
17391         cmdline_fixed_string_t mapping;
17392         cmdline_fixed_string_t reset;
17393         portid_t port_id;
17394 };
17395
17396 /* Common CLI fields for ptype mapping reset*/
17397 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17398         TOKEN_STRING_INITIALIZER
17399                 (struct cmd_ptype_mapping_reset_result,
17400                  ptype, "ptype");
17401 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17402         TOKEN_STRING_INITIALIZER
17403                 (struct cmd_ptype_mapping_reset_result,
17404                  mapping, "mapping");
17405 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17406         TOKEN_STRING_INITIALIZER
17407                 (struct cmd_ptype_mapping_reset_result,
17408                  reset, "reset");
17409 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17410         TOKEN_NUM_INITIALIZER
17411                 (struct cmd_ptype_mapping_reset_result,
17412                  port_id, UINT16);
17413
17414 static void
17415 cmd_ptype_mapping_reset_parsed(
17416         void *parsed_result,
17417         __attribute__((unused)) struct cmdline *cl,
17418         __attribute__((unused)) void *data)
17419 {
17420         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17421         int ret = -ENOTSUP;
17422
17423         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17424                 return;
17425
17426 #ifdef RTE_LIBRTE_I40E_PMD
17427         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17428 #endif
17429
17430         switch (ret) {
17431         case 0:
17432                 break;
17433         case -ENODEV:
17434                 printf("invalid port_id %d\n", res->port_id);
17435                 break;
17436         case -ENOTSUP:
17437                 printf("function not implemented\n");
17438                 break;
17439         default:
17440                 printf("programming error: (%s)\n", strerror(-ret));
17441         }
17442 }
17443
17444 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17445         .f = cmd_ptype_mapping_reset_parsed,
17446         .data = NULL,
17447         .help_str = "ptype mapping reset <port_id>",
17448         .tokens = {
17449                 (void *)&cmd_ptype_mapping_reset_ptype,
17450                 (void *)&cmd_ptype_mapping_reset_mapping,
17451                 (void *)&cmd_ptype_mapping_reset_reset,
17452                 (void *)&cmd_ptype_mapping_reset_port_id,
17453                 NULL,
17454         },
17455 };
17456
17457 /* ptype mapping update */
17458
17459 /* Common result structure for ptype mapping update */
17460 struct cmd_ptype_mapping_update_result {
17461         cmdline_fixed_string_t ptype;
17462         cmdline_fixed_string_t mapping;
17463         cmdline_fixed_string_t reset;
17464         portid_t port_id;
17465         uint8_t hw_ptype;
17466         uint32_t sw_ptype;
17467 };
17468
17469 /* Common CLI fields for ptype mapping update*/
17470 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17471         TOKEN_STRING_INITIALIZER
17472                 (struct cmd_ptype_mapping_update_result,
17473                  ptype, "ptype");
17474 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17475         TOKEN_STRING_INITIALIZER
17476                 (struct cmd_ptype_mapping_update_result,
17477                  mapping, "mapping");
17478 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17479         TOKEN_STRING_INITIALIZER
17480                 (struct cmd_ptype_mapping_update_result,
17481                  reset, "update");
17482 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17483         TOKEN_NUM_INITIALIZER
17484                 (struct cmd_ptype_mapping_update_result,
17485                  port_id, UINT16);
17486 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17487         TOKEN_NUM_INITIALIZER
17488                 (struct cmd_ptype_mapping_update_result,
17489                  hw_ptype, UINT8);
17490 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17491         TOKEN_NUM_INITIALIZER
17492                 (struct cmd_ptype_mapping_update_result,
17493                  sw_ptype, UINT32);
17494
17495 static void
17496 cmd_ptype_mapping_update_parsed(
17497         void *parsed_result,
17498         __attribute__((unused)) struct cmdline *cl,
17499         __attribute__((unused)) void *data)
17500 {
17501         struct cmd_ptype_mapping_update_result *res = parsed_result;
17502         int ret = -ENOTSUP;
17503 #ifdef RTE_LIBRTE_I40E_PMD
17504         struct rte_pmd_i40e_ptype_mapping mapping;
17505 #endif
17506         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17507                 return;
17508
17509 #ifdef RTE_LIBRTE_I40E_PMD
17510         mapping.hw_ptype = res->hw_ptype;
17511         mapping.sw_ptype = res->sw_ptype;
17512         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17513                                                 &mapping,
17514                                                 1,
17515                                                 0);
17516 #endif
17517
17518         switch (ret) {
17519         case 0:
17520                 break;
17521         case -EINVAL:
17522                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17523                 break;
17524         case -ENODEV:
17525                 printf("invalid port_id %d\n", res->port_id);
17526                 break;
17527         case -ENOTSUP:
17528                 printf("function not implemented\n");
17529                 break;
17530         default:
17531                 printf("programming error: (%s)\n", strerror(-ret));
17532         }
17533 }
17534
17535 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17536         .f = cmd_ptype_mapping_update_parsed,
17537         .data = NULL,
17538         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17539         .tokens = {
17540                 (void *)&cmd_ptype_mapping_update_ptype,
17541                 (void *)&cmd_ptype_mapping_update_mapping,
17542                 (void *)&cmd_ptype_mapping_update_update,
17543                 (void *)&cmd_ptype_mapping_update_port_id,
17544                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17545                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17546                 NULL,
17547         },
17548 };
17549
17550 /* Common result structure for file commands */
17551 struct cmd_cmdfile_result {
17552         cmdline_fixed_string_t load;
17553         cmdline_fixed_string_t filename;
17554 };
17555
17556 /* Common CLI fields for file commands */
17557 cmdline_parse_token_string_t cmd_load_cmdfile =
17558         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17559 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17560         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17561
17562 static void
17563 cmd_load_from_file_parsed(
17564         void *parsed_result,
17565         __attribute__((unused)) struct cmdline *cl,
17566         __attribute__((unused)) void *data)
17567 {
17568         struct cmd_cmdfile_result *res = parsed_result;
17569
17570         cmdline_read_from_file(res->filename);
17571 }
17572
17573 cmdline_parse_inst_t cmd_load_from_file = {
17574         .f = cmd_load_from_file_parsed,
17575         .data = NULL,
17576         .help_str = "load <filename>",
17577         .tokens = {
17578                 (void *)&cmd_load_cmdfile,
17579                 (void *)&cmd_load_cmdfile_filename,
17580                 NULL,
17581         },
17582 };
17583
17584 /* Get Rx offloads capabilities */
17585 struct cmd_rx_offload_get_capa_result {
17586         cmdline_fixed_string_t show;
17587         cmdline_fixed_string_t port;
17588         portid_t port_id;
17589         cmdline_fixed_string_t rx_offload;
17590         cmdline_fixed_string_t capabilities;
17591 };
17592
17593 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17594         TOKEN_STRING_INITIALIZER
17595                 (struct cmd_rx_offload_get_capa_result,
17596                  show, "show");
17597 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17598         TOKEN_STRING_INITIALIZER
17599                 (struct cmd_rx_offload_get_capa_result,
17600                  port, "port");
17601 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17602         TOKEN_NUM_INITIALIZER
17603                 (struct cmd_rx_offload_get_capa_result,
17604                  port_id, UINT16);
17605 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17606         TOKEN_STRING_INITIALIZER
17607                 (struct cmd_rx_offload_get_capa_result,
17608                  rx_offload, "rx_offload");
17609 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17610         TOKEN_STRING_INITIALIZER
17611                 (struct cmd_rx_offload_get_capa_result,
17612                  capabilities, "capabilities");
17613
17614 static void
17615 print_rx_offloads(uint64_t offloads)
17616 {
17617         uint64_t single_offload;
17618         int begin;
17619         int end;
17620         int bit;
17621
17622         if (offloads == 0)
17623                 return;
17624
17625         begin = __builtin_ctzll(offloads);
17626         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17627
17628         single_offload = 1 << begin;
17629         for (bit = begin; bit < end; bit++) {
17630                 if (offloads & single_offload)
17631                         printf(" %s",
17632                                rte_eth_dev_rx_offload_name(single_offload));
17633                 single_offload <<= 1;
17634         }
17635 }
17636
17637 static void
17638 cmd_rx_offload_get_capa_parsed(
17639         void *parsed_result,
17640         __attribute__((unused)) struct cmdline *cl,
17641         __attribute__((unused)) void *data)
17642 {
17643         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17644         struct rte_eth_dev_info dev_info;
17645         portid_t port_id = res->port_id;
17646         uint64_t queue_offloads;
17647         uint64_t port_offloads;
17648
17649         rte_eth_dev_info_get(port_id, &dev_info);
17650         queue_offloads = dev_info.rx_queue_offload_capa;
17651         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17652
17653         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17654         printf("  Per Queue :");
17655         print_rx_offloads(queue_offloads);
17656
17657         printf("\n");
17658         printf("  Per Port  :");
17659         print_rx_offloads(port_offloads);
17660         printf("\n\n");
17661 }
17662
17663 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17664         .f = cmd_rx_offload_get_capa_parsed,
17665         .data = NULL,
17666         .help_str = "show port <port_id> rx_offload capabilities",
17667         .tokens = {
17668                 (void *)&cmd_rx_offload_get_capa_show,
17669                 (void *)&cmd_rx_offload_get_capa_port,
17670                 (void *)&cmd_rx_offload_get_capa_port_id,
17671                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17672                 (void *)&cmd_rx_offload_get_capa_capabilities,
17673                 NULL,
17674         }
17675 };
17676
17677 /* Get Rx offloads configuration */
17678 struct cmd_rx_offload_get_configuration_result {
17679         cmdline_fixed_string_t show;
17680         cmdline_fixed_string_t port;
17681         portid_t port_id;
17682         cmdline_fixed_string_t rx_offload;
17683         cmdline_fixed_string_t configuration;
17684 };
17685
17686 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17687         TOKEN_STRING_INITIALIZER
17688                 (struct cmd_rx_offload_get_configuration_result,
17689                  show, "show");
17690 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17691         TOKEN_STRING_INITIALIZER
17692                 (struct cmd_rx_offload_get_configuration_result,
17693                  port, "port");
17694 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17695         TOKEN_NUM_INITIALIZER
17696                 (struct cmd_rx_offload_get_configuration_result,
17697                  port_id, UINT16);
17698 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17699         TOKEN_STRING_INITIALIZER
17700                 (struct cmd_rx_offload_get_configuration_result,
17701                  rx_offload, "rx_offload");
17702 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17703         TOKEN_STRING_INITIALIZER
17704                 (struct cmd_rx_offload_get_configuration_result,
17705                  configuration, "configuration");
17706
17707 static void
17708 cmd_rx_offload_get_configuration_parsed(
17709         void *parsed_result,
17710         __attribute__((unused)) struct cmdline *cl,
17711         __attribute__((unused)) void *data)
17712 {
17713         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17714         struct rte_eth_dev_info dev_info;
17715         portid_t port_id = res->port_id;
17716         struct rte_port *port = &ports[port_id];
17717         uint64_t port_offloads;
17718         uint64_t queue_offloads;
17719         uint16_t nb_rx_queues;
17720         int q;
17721
17722         printf("Rx Offloading Configuration of port %d :\n", port_id);
17723
17724         port_offloads = port->dev_conf.rxmode.offloads;
17725         printf("  Port :");
17726         print_rx_offloads(port_offloads);
17727         printf("\n");
17728
17729         rte_eth_dev_info_get(port_id, &dev_info);
17730         nb_rx_queues = dev_info.nb_rx_queues;
17731         for (q = 0; q < nb_rx_queues; q++) {
17732                 queue_offloads = port->rx_conf[q].offloads;
17733                 printf("  Queue[%2d] :", q);
17734                 print_rx_offloads(queue_offloads);
17735                 printf("\n");
17736         }
17737         printf("\n");
17738 }
17739
17740 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17741         .f = cmd_rx_offload_get_configuration_parsed,
17742         .data = NULL,
17743         .help_str = "show port <port_id> rx_offload configuration",
17744         .tokens = {
17745                 (void *)&cmd_rx_offload_get_configuration_show,
17746                 (void *)&cmd_rx_offload_get_configuration_port,
17747                 (void *)&cmd_rx_offload_get_configuration_port_id,
17748                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17749                 (void *)&cmd_rx_offload_get_configuration_configuration,
17750                 NULL,
17751         }
17752 };
17753
17754 /* Enable/Disable a per port offloading */
17755 struct cmd_config_per_port_rx_offload_result {
17756         cmdline_fixed_string_t port;
17757         cmdline_fixed_string_t config;
17758         portid_t port_id;
17759         cmdline_fixed_string_t rx_offload;
17760         cmdline_fixed_string_t offload;
17761         cmdline_fixed_string_t on_off;
17762 };
17763
17764 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17765         TOKEN_STRING_INITIALIZER
17766                 (struct cmd_config_per_port_rx_offload_result,
17767                  port, "port");
17768 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17769         TOKEN_STRING_INITIALIZER
17770                 (struct cmd_config_per_port_rx_offload_result,
17771                  config, "config");
17772 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17773         TOKEN_NUM_INITIALIZER
17774                 (struct cmd_config_per_port_rx_offload_result,
17775                  port_id, UINT16);
17776 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17777         TOKEN_STRING_INITIALIZER
17778                 (struct cmd_config_per_port_rx_offload_result,
17779                  rx_offload, "rx_offload");
17780 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17781         TOKEN_STRING_INITIALIZER
17782                 (struct cmd_config_per_port_rx_offload_result,
17783                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17784                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17785                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17786                            "crc_strip#scatter#timestamp#security#keep_crc");
17787 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17788         TOKEN_STRING_INITIALIZER
17789                 (struct cmd_config_per_port_rx_offload_result,
17790                  on_off, "on#off");
17791
17792 static uint64_t
17793 search_rx_offload(const char *name)
17794 {
17795         uint64_t single_offload;
17796         const char *single_name;
17797         int found = 0;
17798         unsigned int bit;
17799
17800         single_offload = 1;
17801         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17802                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17803                 if (!strcasecmp(single_name, name)) {
17804                         found = 1;
17805                         break;
17806                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17807                         break;
17808                 else if (single_name == NULL)
17809                         break;
17810                 single_offload <<= 1;
17811         }
17812
17813         if (found)
17814                 return single_offload;
17815
17816         return 0;
17817 }
17818
17819 static void
17820 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17821                                 __attribute__((unused)) struct cmdline *cl,
17822                                 __attribute__((unused)) void *data)
17823 {
17824         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17825         portid_t port_id = res->port_id;
17826         struct rte_eth_dev_info dev_info;
17827         struct rte_port *port = &ports[port_id];
17828         uint64_t single_offload;
17829         uint16_t nb_rx_queues;
17830         int q;
17831
17832         if (port->port_status != RTE_PORT_STOPPED) {
17833                 printf("Error: Can't config offload when Port %d "
17834                        "is not stopped\n", port_id);
17835                 return;
17836         }
17837
17838         single_offload = search_rx_offload(res->offload);
17839         if (single_offload == 0) {
17840                 printf("Unknown offload name: %s\n", res->offload);
17841                 return;
17842         }
17843
17844         rte_eth_dev_info_get(port_id, &dev_info);
17845         nb_rx_queues = dev_info.nb_rx_queues;
17846         if (!strcmp(res->on_off, "on")) {
17847                 port->dev_conf.rxmode.offloads |= single_offload;
17848                 for (q = 0; q < nb_rx_queues; q++)
17849                         port->rx_conf[q].offloads |= single_offload;
17850         } else {
17851                 port->dev_conf.rxmode.offloads &= ~single_offload;
17852                 for (q = 0; q < nb_rx_queues; q++)
17853                         port->rx_conf[q].offloads &= ~single_offload;
17854         }
17855
17856         cmd_reconfig_device_queue(port_id, 1, 1);
17857 }
17858
17859 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17860         .f = cmd_config_per_port_rx_offload_parsed,
17861         .data = NULL,
17862         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17863                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17864                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17865                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17866                     "on|off",
17867         .tokens = {
17868                 (void *)&cmd_config_per_port_rx_offload_result_port,
17869                 (void *)&cmd_config_per_port_rx_offload_result_config,
17870                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17871                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17872                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17873                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17874                 NULL,
17875         }
17876 };
17877
17878 /* Enable/Disable a per queue offloading */
17879 struct cmd_config_per_queue_rx_offload_result {
17880         cmdline_fixed_string_t port;
17881         portid_t port_id;
17882         cmdline_fixed_string_t rxq;
17883         uint16_t queue_id;
17884         cmdline_fixed_string_t rx_offload;
17885         cmdline_fixed_string_t offload;
17886         cmdline_fixed_string_t on_off;
17887 };
17888
17889 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17890         TOKEN_STRING_INITIALIZER
17891                 (struct cmd_config_per_queue_rx_offload_result,
17892                  port, "port");
17893 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17894         TOKEN_NUM_INITIALIZER
17895                 (struct cmd_config_per_queue_rx_offload_result,
17896                  port_id, UINT16);
17897 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17898         TOKEN_STRING_INITIALIZER
17899                 (struct cmd_config_per_queue_rx_offload_result,
17900                  rxq, "rxq");
17901 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17902         TOKEN_NUM_INITIALIZER
17903                 (struct cmd_config_per_queue_rx_offload_result,
17904                  queue_id, UINT16);
17905 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17906         TOKEN_STRING_INITIALIZER
17907                 (struct cmd_config_per_queue_rx_offload_result,
17908                  rx_offload, "rx_offload");
17909 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17910         TOKEN_STRING_INITIALIZER
17911                 (struct cmd_config_per_queue_rx_offload_result,
17912                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17913                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17914                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17915                            "crc_strip#scatter#timestamp#security#keep_crc");
17916 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17917         TOKEN_STRING_INITIALIZER
17918                 (struct cmd_config_per_queue_rx_offload_result,
17919                  on_off, "on#off");
17920
17921 static void
17922 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17923                                 __attribute__((unused)) struct cmdline *cl,
17924                                 __attribute__((unused)) void *data)
17925 {
17926         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17927         struct rte_eth_dev_info dev_info;
17928         portid_t port_id = res->port_id;
17929         uint16_t queue_id = res->queue_id;
17930         struct rte_port *port = &ports[port_id];
17931         uint64_t single_offload;
17932
17933         if (port->port_status != RTE_PORT_STOPPED) {
17934                 printf("Error: Can't config offload when Port %d "
17935                        "is not stopped\n", port_id);
17936                 return;
17937         }
17938
17939         rte_eth_dev_info_get(port_id, &dev_info);
17940         if (queue_id >= dev_info.nb_rx_queues) {
17941                 printf("Error: input queue_id should be 0 ... "
17942                        "%d\n", dev_info.nb_rx_queues - 1);
17943                 return;
17944         }
17945
17946         single_offload = search_rx_offload(res->offload);
17947         if (single_offload == 0) {
17948                 printf("Unknown offload name: %s\n", res->offload);
17949                 return;
17950         }
17951
17952         if (!strcmp(res->on_off, "on"))
17953                 port->rx_conf[queue_id].offloads |= single_offload;
17954         else
17955                 port->rx_conf[queue_id].offloads &= ~single_offload;
17956
17957         cmd_reconfig_device_queue(port_id, 1, 1);
17958 }
17959
17960 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17961         .f = cmd_config_per_queue_rx_offload_parsed,
17962         .data = NULL,
17963         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17964                     "vlan_strip|ipv4_cksum|"
17965                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17966                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17967                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17968                     "on|off",
17969         .tokens = {
17970                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17971                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17972                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17973                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17974                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17975                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17976                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17977                 NULL,
17978         }
17979 };
17980
17981 /* Get Tx offloads capabilities */
17982 struct cmd_tx_offload_get_capa_result {
17983         cmdline_fixed_string_t show;
17984         cmdline_fixed_string_t port;
17985         portid_t port_id;
17986         cmdline_fixed_string_t tx_offload;
17987         cmdline_fixed_string_t capabilities;
17988 };
17989
17990 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17991         TOKEN_STRING_INITIALIZER
17992                 (struct cmd_tx_offload_get_capa_result,
17993                  show, "show");
17994 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17995         TOKEN_STRING_INITIALIZER
17996                 (struct cmd_tx_offload_get_capa_result,
17997                  port, "port");
17998 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17999         TOKEN_NUM_INITIALIZER
18000                 (struct cmd_tx_offload_get_capa_result,
18001                  port_id, UINT16);
18002 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18003         TOKEN_STRING_INITIALIZER
18004                 (struct cmd_tx_offload_get_capa_result,
18005                  tx_offload, "tx_offload");
18006 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18007         TOKEN_STRING_INITIALIZER
18008                 (struct cmd_tx_offload_get_capa_result,
18009                  capabilities, "capabilities");
18010
18011 static void
18012 print_tx_offloads(uint64_t offloads)
18013 {
18014         uint64_t single_offload;
18015         int begin;
18016         int end;
18017         int bit;
18018
18019         if (offloads == 0)
18020                 return;
18021
18022         begin = __builtin_ctzll(offloads);
18023         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18024
18025         single_offload = 1 << begin;
18026         for (bit = begin; bit < end; bit++) {
18027                 if (offloads & single_offload)
18028                         printf(" %s",
18029                                rte_eth_dev_tx_offload_name(single_offload));
18030                 single_offload <<= 1;
18031         }
18032 }
18033
18034 static void
18035 cmd_tx_offload_get_capa_parsed(
18036         void *parsed_result,
18037         __attribute__((unused)) struct cmdline *cl,
18038         __attribute__((unused)) void *data)
18039 {
18040         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18041         struct rte_eth_dev_info dev_info;
18042         portid_t port_id = res->port_id;
18043         uint64_t queue_offloads;
18044         uint64_t port_offloads;
18045
18046         rte_eth_dev_info_get(port_id, &dev_info);
18047         queue_offloads = dev_info.tx_queue_offload_capa;
18048         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18049
18050         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18051         printf("  Per Queue :");
18052         print_tx_offloads(queue_offloads);
18053
18054         printf("\n");
18055         printf("  Per Port  :");
18056         print_tx_offloads(port_offloads);
18057         printf("\n\n");
18058 }
18059
18060 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18061         .f = cmd_tx_offload_get_capa_parsed,
18062         .data = NULL,
18063         .help_str = "show port <port_id> tx_offload capabilities",
18064         .tokens = {
18065                 (void *)&cmd_tx_offload_get_capa_show,
18066                 (void *)&cmd_tx_offload_get_capa_port,
18067                 (void *)&cmd_tx_offload_get_capa_port_id,
18068                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18069                 (void *)&cmd_tx_offload_get_capa_capabilities,
18070                 NULL,
18071         }
18072 };
18073
18074 /* Get Tx offloads configuration */
18075 struct cmd_tx_offload_get_configuration_result {
18076         cmdline_fixed_string_t show;
18077         cmdline_fixed_string_t port;
18078         portid_t port_id;
18079         cmdline_fixed_string_t tx_offload;
18080         cmdline_fixed_string_t configuration;
18081 };
18082
18083 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18084         TOKEN_STRING_INITIALIZER
18085                 (struct cmd_tx_offload_get_configuration_result,
18086                  show, "show");
18087 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18088         TOKEN_STRING_INITIALIZER
18089                 (struct cmd_tx_offload_get_configuration_result,
18090                  port, "port");
18091 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18092         TOKEN_NUM_INITIALIZER
18093                 (struct cmd_tx_offload_get_configuration_result,
18094                  port_id, UINT16);
18095 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18096         TOKEN_STRING_INITIALIZER
18097                 (struct cmd_tx_offload_get_configuration_result,
18098                  tx_offload, "tx_offload");
18099 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18100         TOKEN_STRING_INITIALIZER
18101                 (struct cmd_tx_offload_get_configuration_result,
18102                  configuration, "configuration");
18103
18104 static void
18105 cmd_tx_offload_get_configuration_parsed(
18106         void *parsed_result,
18107         __attribute__((unused)) struct cmdline *cl,
18108         __attribute__((unused)) void *data)
18109 {
18110         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18111         struct rte_eth_dev_info dev_info;
18112         portid_t port_id = res->port_id;
18113         struct rte_port *port = &ports[port_id];
18114         uint64_t port_offloads;
18115         uint64_t queue_offloads;
18116         uint16_t nb_tx_queues;
18117         int q;
18118
18119         printf("Tx Offloading Configuration of port %d :\n", port_id);
18120
18121         port_offloads = port->dev_conf.txmode.offloads;
18122         printf("  Port :");
18123         print_tx_offloads(port_offloads);
18124         printf("\n");
18125
18126         rte_eth_dev_info_get(port_id, &dev_info);
18127         nb_tx_queues = dev_info.nb_tx_queues;
18128         for (q = 0; q < nb_tx_queues; q++) {
18129                 queue_offloads = port->tx_conf[q].offloads;
18130                 printf("  Queue[%2d] :", q);
18131                 print_tx_offloads(queue_offloads);
18132                 printf("\n");
18133         }
18134         printf("\n");
18135 }
18136
18137 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18138         .f = cmd_tx_offload_get_configuration_parsed,
18139         .data = NULL,
18140         .help_str = "show port <port_id> tx_offload configuration",
18141         .tokens = {
18142                 (void *)&cmd_tx_offload_get_configuration_show,
18143                 (void *)&cmd_tx_offload_get_configuration_port,
18144                 (void *)&cmd_tx_offload_get_configuration_port_id,
18145                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18146                 (void *)&cmd_tx_offload_get_configuration_configuration,
18147                 NULL,
18148         }
18149 };
18150
18151 /* Enable/Disable a per port offloading */
18152 struct cmd_config_per_port_tx_offload_result {
18153         cmdline_fixed_string_t port;
18154         cmdline_fixed_string_t config;
18155         portid_t port_id;
18156         cmdline_fixed_string_t tx_offload;
18157         cmdline_fixed_string_t offload;
18158         cmdline_fixed_string_t on_off;
18159 };
18160
18161 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18162         TOKEN_STRING_INITIALIZER
18163                 (struct cmd_config_per_port_tx_offload_result,
18164                  port, "port");
18165 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18166         TOKEN_STRING_INITIALIZER
18167                 (struct cmd_config_per_port_tx_offload_result,
18168                  config, "config");
18169 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18170         TOKEN_NUM_INITIALIZER
18171                 (struct cmd_config_per_port_tx_offload_result,
18172                  port_id, UINT16);
18173 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18174         TOKEN_STRING_INITIALIZER
18175                 (struct cmd_config_per_port_tx_offload_result,
18176                  tx_offload, "tx_offload");
18177 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18178         TOKEN_STRING_INITIALIZER
18179                 (struct cmd_config_per_port_tx_offload_result,
18180                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18181                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18182                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18183                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18184                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18185                           "match_metadata");
18186 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18187         TOKEN_STRING_INITIALIZER
18188                 (struct cmd_config_per_port_tx_offload_result,
18189                  on_off, "on#off");
18190
18191 static uint64_t
18192 search_tx_offload(const char *name)
18193 {
18194         uint64_t single_offload;
18195         const char *single_name;
18196         int found = 0;
18197         unsigned int bit;
18198
18199         single_offload = 1;
18200         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18201                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18202                 if (!strcasecmp(single_name, name)) {
18203                         found = 1;
18204                         break;
18205                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18206                         break;
18207                 else if (single_name == NULL)
18208                         break;
18209                 single_offload <<= 1;
18210         }
18211
18212         if (found)
18213                 return single_offload;
18214
18215         return 0;
18216 }
18217
18218 static void
18219 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18220                                 __attribute__((unused)) struct cmdline *cl,
18221                                 __attribute__((unused)) void *data)
18222 {
18223         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18224         portid_t port_id = res->port_id;
18225         struct rte_eth_dev_info dev_info;
18226         struct rte_port *port = &ports[port_id];
18227         uint64_t single_offload;
18228         uint16_t nb_tx_queues;
18229         int q;
18230
18231         if (port->port_status != RTE_PORT_STOPPED) {
18232                 printf("Error: Can't config offload when Port %d "
18233                        "is not stopped\n", port_id);
18234                 return;
18235         }
18236
18237         single_offload = search_tx_offload(res->offload);
18238         if (single_offload == 0) {
18239                 printf("Unknown offload name: %s\n", res->offload);
18240                 return;
18241         }
18242
18243         rte_eth_dev_info_get(port_id, &dev_info);
18244         nb_tx_queues = dev_info.nb_tx_queues;
18245         if (!strcmp(res->on_off, "on")) {
18246                 port->dev_conf.txmode.offloads |= single_offload;
18247                 for (q = 0; q < nb_tx_queues; q++)
18248                         port->tx_conf[q].offloads |= single_offload;
18249         } else {
18250                 port->dev_conf.txmode.offloads &= ~single_offload;
18251                 for (q = 0; q < nb_tx_queues; q++)
18252                         port->tx_conf[q].offloads &= ~single_offload;
18253         }
18254
18255         cmd_reconfig_device_queue(port_id, 1, 1);
18256 }
18257
18258 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18259         .f = cmd_config_per_port_tx_offload_parsed,
18260         .data = NULL,
18261         .help_str = "port config <port_id> tx_offload "
18262                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18263                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18264                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18265                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18266                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18267                     "match_metadata on|off",
18268         .tokens = {
18269                 (void *)&cmd_config_per_port_tx_offload_result_port,
18270                 (void *)&cmd_config_per_port_tx_offload_result_config,
18271                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18272                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18273                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18274                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18275                 NULL,
18276         }
18277 };
18278
18279 /* Enable/Disable a per queue offloading */
18280 struct cmd_config_per_queue_tx_offload_result {
18281         cmdline_fixed_string_t port;
18282         portid_t port_id;
18283         cmdline_fixed_string_t txq;
18284         uint16_t queue_id;
18285         cmdline_fixed_string_t tx_offload;
18286         cmdline_fixed_string_t offload;
18287         cmdline_fixed_string_t on_off;
18288 };
18289
18290 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18291         TOKEN_STRING_INITIALIZER
18292                 (struct cmd_config_per_queue_tx_offload_result,
18293                  port, "port");
18294 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18295         TOKEN_NUM_INITIALIZER
18296                 (struct cmd_config_per_queue_tx_offload_result,
18297                  port_id, UINT16);
18298 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18299         TOKEN_STRING_INITIALIZER
18300                 (struct cmd_config_per_queue_tx_offload_result,
18301                  txq, "txq");
18302 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18303         TOKEN_NUM_INITIALIZER
18304                 (struct cmd_config_per_queue_tx_offload_result,
18305                  queue_id, UINT16);
18306 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18307         TOKEN_STRING_INITIALIZER
18308                 (struct cmd_config_per_queue_tx_offload_result,
18309                  tx_offload, "tx_offload");
18310 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18311         TOKEN_STRING_INITIALIZER
18312                 (struct cmd_config_per_queue_tx_offload_result,
18313                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18314                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18315                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18316                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18317                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18318 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18319         TOKEN_STRING_INITIALIZER
18320                 (struct cmd_config_per_queue_tx_offload_result,
18321                  on_off, "on#off");
18322
18323 static void
18324 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18325                                 __attribute__((unused)) struct cmdline *cl,
18326                                 __attribute__((unused)) void *data)
18327 {
18328         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18329         struct rte_eth_dev_info dev_info;
18330         portid_t port_id = res->port_id;
18331         uint16_t queue_id = res->queue_id;
18332         struct rte_port *port = &ports[port_id];
18333         uint64_t single_offload;
18334
18335         if (port->port_status != RTE_PORT_STOPPED) {
18336                 printf("Error: Can't config offload when Port %d "
18337                        "is not stopped\n", port_id);
18338                 return;
18339         }
18340
18341         rte_eth_dev_info_get(port_id, &dev_info);
18342         if (queue_id >= dev_info.nb_tx_queues) {
18343                 printf("Error: input queue_id should be 0 ... "
18344                        "%d\n", dev_info.nb_tx_queues - 1);
18345                 return;
18346         }
18347
18348         single_offload = search_tx_offload(res->offload);
18349         if (single_offload == 0) {
18350                 printf("Unknown offload name: %s\n", res->offload);
18351                 return;
18352         }
18353
18354         if (!strcmp(res->on_off, "on"))
18355                 port->tx_conf[queue_id].offloads |= single_offload;
18356         else
18357                 port->tx_conf[queue_id].offloads &= ~single_offload;
18358
18359         cmd_reconfig_device_queue(port_id, 1, 1);
18360 }
18361
18362 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18363         .f = cmd_config_per_queue_tx_offload_parsed,
18364         .data = NULL,
18365         .help_str = "port <port_id> txq <queue_id> tx_offload "
18366                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18367                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18368                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18369                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18370                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18371                     "on|off",
18372         .tokens = {
18373                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18374                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18375                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18376                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18377                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18378                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18379                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18380                 NULL,
18381         }
18382 };
18383
18384 /* *** configure tx_metadata for specific port *** */
18385 struct cmd_config_tx_metadata_specific_result {
18386         cmdline_fixed_string_t port;
18387         cmdline_fixed_string_t keyword;
18388         uint16_t port_id;
18389         cmdline_fixed_string_t item;
18390         uint32_t value;
18391 };
18392
18393 static void
18394 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18395                                 __attribute__((unused)) struct cmdline *cl,
18396                                 __attribute__((unused)) void *data)
18397 {
18398         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18399
18400         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18401                 return;
18402         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18403         /* Add/remove callback to insert valid metadata in every Tx packet. */
18404         if (ports[res->port_id].tx_metadata)
18405                 add_tx_md_callback(res->port_id);
18406         else
18407                 remove_tx_md_callback(res->port_id);
18408 }
18409
18410 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18411         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18412                         port, "port");
18413 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18414         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18415                         keyword, "config");
18416 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18417         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18418                         port_id, UINT16);
18419 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18420         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18421                         item, "tx_metadata");
18422 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18423         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18424                         value, UINT32);
18425
18426 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18427         .f = cmd_config_tx_metadata_specific_parsed,
18428         .data = NULL,
18429         .help_str = "port config <port_id> tx_metadata <value>",
18430         .tokens = {
18431                 (void *)&cmd_config_tx_metadata_specific_port,
18432                 (void *)&cmd_config_tx_metadata_specific_keyword,
18433                 (void *)&cmd_config_tx_metadata_specific_id,
18434                 (void *)&cmd_config_tx_metadata_specific_item,
18435                 (void *)&cmd_config_tx_metadata_specific_value,
18436                 NULL,
18437         },
18438 };
18439
18440 /* *** display tx_metadata per port configuration *** */
18441 struct cmd_show_tx_metadata_result {
18442         cmdline_fixed_string_t cmd_show;
18443         cmdline_fixed_string_t cmd_port;
18444         cmdline_fixed_string_t cmd_keyword;
18445         portid_t cmd_pid;
18446 };
18447
18448 static void
18449 cmd_show_tx_metadata_parsed(void *parsed_result,
18450                 __attribute__((unused)) struct cmdline *cl,
18451                 __attribute__((unused)) void *data)
18452 {
18453         struct cmd_show_tx_metadata_result *res = parsed_result;
18454
18455         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18456                 printf("invalid port id %u\n", res->cmd_pid);
18457                 return;
18458         }
18459         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18460                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18461                                 ports[res->cmd_pid].tx_metadata);
18462         }
18463 }
18464
18465 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18466         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18467                         cmd_show, "show");
18468 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18469         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18470                         cmd_port, "port");
18471 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18472         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18473                         cmd_pid, UINT16);
18474 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18475         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18476                         cmd_keyword, "tx_metadata");
18477
18478 cmdline_parse_inst_t cmd_show_tx_metadata = {
18479         .f = cmd_show_tx_metadata_parsed,
18480         .data = NULL,
18481         .help_str = "show port <port_id> tx_metadata",
18482         .tokens = {
18483                 (void *)&cmd_show_tx_metadata_show,
18484                 (void *)&cmd_show_tx_metadata_port,
18485                 (void *)&cmd_show_tx_metadata_pid,
18486                 (void *)&cmd_show_tx_metadata_keyword,
18487                 NULL,
18488         },
18489 };
18490
18491 /* ******************************************************************************** */
18492
18493 /* list of instructions */
18494 cmdline_parse_ctx_t main_ctx[] = {
18495         (cmdline_parse_inst_t *)&cmd_help_brief,
18496         (cmdline_parse_inst_t *)&cmd_help_long,
18497         (cmdline_parse_inst_t *)&cmd_quit,
18498         (cmdline_parse_inst_t *)&cmd_load_from_file,
18499         (cmdline_parse_inst_t *)&cmd_showport,
18500         (cmdline_parse_inst_t *)&cmd_showqueue,
18501         (cmdline_parse_inst_t *)&cmd_showportall,
18502         (cmdline_parse_inst_t *)&cmd_showcfg,
18503         (cmdline_parse_inst_t *)&cmd_start,
18504         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18505         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18506         (cmdline_parse_inst_t *)&cmd_set_link_up,
18507         (cmdline_parse_inst_t *)&cmd_set_link_down,
18508         (cmdline_parse_inst_t *)&cmd_reset,
18509         (cmdline_parse_inst_t *)&cmd_set_numbers,
18510         (cmdline_parse_inst_t *)&cmd_set_log,
18511         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18512         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18513         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18514         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18515         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18516         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18517         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18518         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18519         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18520         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18521         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18522         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18523         (cmdline_parse_inst_t *)&cmd_set_link_check,
18524         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18525         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18526         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18527         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18528 #ifdef RTE_LIBRTE_PMD_BOND
18529         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18530         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18531         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18532         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18533         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18534         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18535         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18536         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18537         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18538         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18539         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18540 #endif
18541         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18542         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18543         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18544         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18545         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18546         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18547         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18548         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18549         (cmdline_parse_inst_t *)&cmd_csum_set,
18550         (cmdline_parse_inst_t *)&cmd_csum_show,
18551         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18552         (cmdline_parse_inst_t *)&cmd_tso_set,
18553         (cmdline_parse_inst_t *)&cmd_tso_show,
18554         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18555         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18556         (cmdline_parse_inst_t *)&cmd_gro_enable,
18557         (cmdline_parse_inst_t *)&cmd_gro_flush,
18558         (cmdline_parse_inst_t *)&cmd_gro_show,
18559         (cmdline_parse_inst_t *)&cmd_gso_enable,
18560         (cmdline_parse_inst_t *)&cmd_gso_size,
18561         (cmdline_parse_inst_t *)&cmd_gso_show,
18562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18570         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18571         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18572         (cmdline_parse_inst_t *)&cmd_config_dcb,
18573         (cmdline_parse_inst_t *)&cmd_read_reg,
18574         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18575         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18576         (cmdline_parse_inst_t *)&cmd_write_reg,
18577         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18578         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18579         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18580         (cmdline_parse_inst_t *)&cmd_stop,
18581         (cmdline_parse_inst_t *)&cmd_mac_addr,
18582         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18583         (cmdline_parse_inst_t *)&cmd_set_qmap,
18584         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18585         (cmdline_parse_inst_t *)&cmd_operate_port,
18586         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18587         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18588         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18589         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18590         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18591         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18592         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18593         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18594         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18595         (cmdline_parse_inst_t *)&cmd_config_mtu,
18596         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18597         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18598         (cmdline_parse_inst_t *)&cmd_config_rss,
18599         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18600         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18601         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18602         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18603         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18604         (cmdline_parse_inst_t *)&cmd_showport_reta,
18605         (cmdline_parse_inst_t *)&cmd_config_burst,
18606         (cmdline_parse_inst_t *)&cmd_config_thresh,
18607         (cmdline_parse_inst_t *)&cmd_config_threshold,
18608         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18609         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18610         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18611         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18612         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18613         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18614         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18615         (cmdline_parse_inst_t *)&cmd_global_config,
18616         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18617         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18618         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18619         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18620         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18621         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18622         (cmdline_parse_inst_t *)&cmd_dump,
18623         (cmdline_parse_inst_t *)&cmd_dump_one,
18624         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18625         (cmdline_parse_inst_t *)&cmd_syn_filter,
18626         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18627         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18628         (cmdline_parse_inst_t *)&cmd_flex_filter,
18629         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18630         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18631         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18632         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18633         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18634         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18635         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18636         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18637         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18638         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18639         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18640         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18641         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18642         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18643         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18644         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18645         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18646         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18647         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18648         (cmdline_parse_inst_t *)&cmd_flow,
18649         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18650         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18651         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18652         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18653         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18654         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18655         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18656         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18657         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18658         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18659         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18660         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18661         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18662         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18663         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18664         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18665         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18666         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18667         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18668         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18669         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18670         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18671         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18672         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18673         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18674         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18675         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18676         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18677         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18678         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18679         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18680         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18681         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18682         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18683         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18684         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18685         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18686         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18687         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18688         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18689         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18690         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18691         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18692         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18693         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18694         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18695         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18696         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18697         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18698 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18699         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18700 #endif
18701         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18702         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18703         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18704         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18705         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18706         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18707         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18708         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18709         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18710         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18711         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18712         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18713         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18714         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18715         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18716         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18717         (cmdline_parse_inst_t *)&cmd_ddp_add,
18718         (cmdline_parse_inst_t *)&cmd_ddp_del,
18719         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18720         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18721         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18722         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18723         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18724         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18725         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18726         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18727         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18728         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18729
18730         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18731         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18732         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18733         (cmdline_parse_inst_t *)&cmd_queue_region,
18734         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18735         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18736         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18737         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18738         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18739         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18740         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18741         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18742         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18743         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18744         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18745         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18746         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18747         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18748         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18749         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18750         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18751         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18752         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18753         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18754         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18755         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18756         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18757         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18758         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18759         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18760         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18761         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18762         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18763         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18764         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18765         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18766         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18767         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18768         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18769 #ifdef RTE_LIBRTE_BPF
18770         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18771         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18772 #endif
18773         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18774         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18775         NULL,
18776 };
18777
18778 /* read cmdline commands from file */
18779 void
18780 cmdline_read_from_file(const char *filename)
18781 {
18782         struct cmdline *cl;
18783
18784         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18785         if (cl == NULL) {
18786                 printf("Failed to create file based cmdline context: %s\n",
18787                        filename);
18788                 return;
18789         }
18790
18791         cmdline_interact(cl);
18792         cmdline_quit(cl);
18793
18794         cmdline_free(cl);
18795
18796         printf("Read CLI commands from %s\n", filename);
18797 }
18798
18799 /* prompt function, called from main on MASTER lcore */
18800 void
18801 prompt(void)
18802 {
18803         /* initialize non-constant commands */
18804         cmd_set_fwd_mode_init();
18805         cmd_set_fwd_retry_mode_init();
18806
18807         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18808         if (testpmd_cl == NULL)
18809                 return;
18810         cmdline_interact(testpmd_cl);
18811         cmdline_stdin_exit(testpmd_cl);
18812 }
18813
18814 void
18815 prompt_exit(void)
18816 {
18817         if (testpmd_cl != NULL)
18818                 cmdline_quit(testpmd_cl);
18819 }
18820
18821 static void
18822 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18823 {
18824         if (id == (portid_t)RTE_PORT_ALL) {
18825                 portid_t pid;
18826
18827                 RTE_ETH_FOREACH_DEV(pid) {
18828                         /* check if need_reconfig has been set to 1 */
18829                         if (ports[pid].need_reconfig == 0)
18830                                 ports[pid].need_reconfig = dev;
18831                         /* check if need_reconfig_queues has been set to 1 */
18832                         if (ports[pid].need_reconfig_queues == 0)
18833                                 ports[pid].need_reconfig_queues = queue;
18834                 }
18835         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18836                 /* check if need_reconfig has been set to 1 */
18837                 if (ports[id].need_reconfig == 0)
18838                         ports[id].need_reconfig = dev;
18839                 /* check if need_reconfig_queues has been set to 1 */
18840                 if (ports[id].need_reconfig_queues == 0)
18841                         ports[id].need_reconfig_queues = queue;
18842         }
18843 }